Skip to content

Commit a0b2470

Browse files
committed
fix: also clean lock/dao info in renderer process
1 parent 60ec486 commit a0b2470

3 files changed

Lines changed: 13 additions & 17 deletions

File tree

packages/neuron-wallet/src/models/lock-utils.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,16 @@ export interface SystemScript {
1717
hashType: ScriptHashType
1818
}
1919

20-
const subscribed = (target: any, propertyName: string) => {
21-
let value: any
22-
Object.defineProperty(target, propertyName, {
23-
get: () => value,
24-
set: (info: SystemScript | undefined) => {
25-
value = info
26-
if (info) {
27-
SystemScriptSubject.next({ codeHash: info.codeHash })
28-
}
29-
},
30-
})
31-
}
32-
3320
export default class LockUtils {
3421
systemScript: SystemScript
3522

3623
constructor(systemScript: SystemScript) {
3724
this.systemScript = systemScript
3825
}
3926

40-
@subscribed
41-
static systemScriptInfo: SystemScript | undefined
27+
private static systemScriptInfo: SystemScript | undefined
4228

43-
static previousURL: string | undefined
29+
private static previousURL: string | undefined
4430

4531
static async loadSystemScript(nodeURL: string): Promise<SystemScript> {
4632
const core = new Core(nodeURL)

packages/neuron-wallet/src/startup/sync-block-task/indexer.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import IndexerQueue, { LockHashInfo } from 'services/indexer/queue'
55
import { Address } from 'database/address/address-dao'
66

77
import initConnection from 'database/chain/ormconfig'
8+
import DaoUtils from 'models/dao-utils'
89

910
const { nodeService, addressCreatedSubject, walletCreatedSubject } = remote.require('./startup/sync-block-task/params')
1011

@@ -24,6 +25,10 @@ export const switchNetwork = async (nodeURL: string, genesisBlockHash: string, _
2425
await indexerQueue.stopAndWait()
2526
}
2627

28+
// clean LockUtils info and DaoUtils info
29+
LockUtils.cleanInfoWhenSwitchNetwork()
30+
DaoUtils.cleanInfoWhenSwitchNetwork()
31+
2732
// disconnect old connection and connect to new database
2833
await initConnection(genesisBlockHash)
2934
// load lockHashes

packages/neuron-wallet/src/startup/sync-block-task/sync.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import LockUtils from 'models/lock-utils'
44
import BlockListener from 'services/sync/block-listener'
55
import { Address } from 'database/address/address-dao'
66
import initConnection from 'database/chain/ormconfig'
7+
import DaoUtils from 'models/dao-utils'
78

89
const { nodeService, addressCreatedSubject, walletCreatedSubject } = remote.require('./startup/sync-block-task/params')
910

@@ -31,6 +32,10 @@ export const switchNetwork = async (url: string, genesisBlockHash: string, _chai
3132
await blockListener.stopAndWait()
3233
}
3334

35+
// clean LockUtils info and DaoUtils info
36+
LockUtils.cleanInfoWhenSwitchNetwork()
37+
DaoUtils.cleanInfoWhenSwitchNetwork()
38+
3439
// disconnect old connection and connect to new database
3540
await initConnection(genesisBlockHash)
3641
// load lockHashes
@@ -79,4 +84,4 @@ export const switchNetwork = async (url: string, genesisBlockHash: string, _chai
7984
})
8085

8186
blockListener.start()
82-
}
87+
}

0 commit comments

Comments
 (0)