Skip to content

Commit

Permalink
fix: clean lock utils info and dao utils info when switch network
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Nov 22, 2019
1 parent 528ce00 commit 60ec486
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/neuron-wallet/src/database/chain/cleaner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export default class ChainCleaner {
}
})
}
}
}
4 changes: 4 additions & 0 deletions packages/neuron-wallet/src/models/dao-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export default class DaoUtils {
return DaoUtils.daoScriptInfo
}

static cleanInfoWhenSwitchNetwork(): void {
DaoUtils.daoScriptInfo = undefined
}

static setDaoScript(info: SystemScript) {
DaoUtils.daoScriptInfo = info
DaoUtils.previousURL = NodeService.getInstance().core.rpc.node.url
Expand Down
10 changes: 8 additions & 2 deletions packages/neuron-wallet/src/models/lock-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ const subscribed = (target: any, propertyName: string) => {
let value: any
Object.defineProperty(target, propertyName, {
get: () => value,
set: (info: { codeHash: string }) => {
SystemScriptSubject.next({ codeHash: info.codeHash })
set: (info: SystemScript | undefined) => {
value = info
if (info) {
SystemScriptSubject.next({ codeHash: info.codeHash })
}
},
})
}
Expand Down Expand Up @@ -75,6 +77,10 @@ export default class LockUtils {
return LockUtils.systemScriptInfo
}

static cleanInfoWhenSwitchNetwork(): void {
LockUtils.systemScriptInfo = undefined
}

static setSystemScript(info: SystemScript) {
LockUtils.systemScriptInfo = info
LockUtils.previousURL = NodeService.getInstance().core.rpc.node.url
Expand Down
5 changes: 5 additions & 0 deletions packages/neuron-wallet/src/startup/sync-block-task/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import logger from 'utils/logger'
import NodeService from 'services/node'
import NetworksService from 'services/networks'
import { distinctUntilChanged } from 'rxjs/operators'
import LockUtils from 'models/lock-utils'
import DaoUtils from 'models/dao-utils'

export { genesisBlockHash }

Expand All @@ -29,6 +31,9 @@ export interface DatabaseInitParams {
// network switch or network connect
const networkChange = async (network: NetworkWithID) => {
await InitDatabase.getInstance().stopAndWait()
// clean LockUtils info and DaoUtils info
LockUtils.cleanInfoWhenSwitchNetwork()
DaoUtils.cleanInfoWhenSwitchNetwork()
const info = await InitDatabase.getInstance().init(network)

DataUpdateSubject.next({
Expand Down

0 comments on commit 60ec486

Please sign in to comment.