Skip to content

Commit

Permalink
fix: also clean lock/dao info in renderer process
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Nov 22, 2019
1 parent 60ec486 commit a0b2470
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
18 changes: 2 additions & 16 deletions packages/neuron-wallet/src/models/lock-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,16 @@ export interface SystemScript {
hashType: ScriptHashType
}

const subscribed = (target: any, propertyName: string) => {
let value: any
Object.defineProperty(target, propertyName, {
get: () => value,
set: (info: SystemScript | undefined) => {
value = info
if (info) {
SystemScriptSubject.next({ codeHash: info.codeHash })
}
},
})
}

export default class LockUtils {
systemScript: SystemScript

constructor(systemScript: SystemScript) {
this.systemScript = systemScript
}

@subscribed
static systemScriptInfo: SystemScript | undefined
private static systemScriptInfo: SystemScript | undefined

static previousURL: string | undefined
private static previousURL: string | undefined

static async loadSystemScript(nodeURL: string): Promise<SystemScript> {
const core = new Core(nodeURL)
Expand Down
5 changes: 5 additions & 0 deletions packages/neuron-wallet/src/startup/sync-block-task/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import IndexerQueue, { LockHashInfo } from 'services/indexer/queue'
import { Address } from 'database/address/address-dao'

import initConnection from 'database/chain/ormconfig'
import DaoUtils from 'models/dao-utils'

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

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

// clean LockUtils info and DaoUtils info
LockUtils.cleanInfoWhenSwitchNetwork()
DaoUtils.cleanInfoWhenSwitchNetwork()

// disconnect old connection and connect to new database
await initConnection(genesisBlockHash)
// load lockHashes
Expand Down
7 changes: 6 additions & 1 deletion packages/neuron-wallet/src/startup/sync-block-task/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import LockUtils from 'models/lock-utils'
import BlockListener from 'services/sync/block-listener'
import { Address } from 'database/address/address-dao'
import initConnection from 'database/chain/ormconfig'
import DaoUtils from 'models/dao-utils'

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

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

// clean LockUtils info and DaoUtils info
LockUtils.cleanInfoWhenSwitchNetwork()
DaoUtils.cleanInfoWhenSwitchNetwork()

// disconnect old connection and connect to new database
await initConnection(genesisBlockHash)
// load lockHashes
Expand Down Expand Up @@ -79,4 +84,4 @@ export const switchNetwork = async (url: string, genesisBlockHash: string, _chai
})

blockListener.start()
}
}

0 comments on commit a0b2470

Please sign in to comment.