Skip to content

Commit

Permalink
fix: reset when import wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Aug 14, 2019
1 parent a087114 commit 6be360e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/neuron-wallet/src/services/indexer/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export default class Queue {

private inProcess = false

private resetFlag = false

constructor(url: string, lockHashes: string[], tipNumberSubject: Subject<string | undefined>) {
this.lockHashes = lockHashes
this.indexerRPC = new IndexerRPC(url)
Expand All @@ -49,12 +51,20 @@ export default class Queue {
this.indexed = false
}

public reset = () => {
this.resetFlag = true
}

/* eslint no-await-in-loop: "off" */
/* eslint no-restricted-syntax: "off" */
public start = async () => {
while (!this.stopped) {
try {
this.inProcess = true
if (this.resetFlag) {
await this.blockNumberService.updateCurrent(BigInt(0))
this.resetFlag = false
}
const { lockHashes } = this
const currentBlockNumber: bigint = await this.blockNumberService.getCurrent()
if (!this.indexed || currentBlockNumber !== this.tipBlockNumber) {
Expand Down
12 changes: 11 additions & 1 deletion packages/neuron-wallet/src/startup/sync-block-task/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import IndexerQueue from 'services/indexer/queue'

import { initDatabase } from './init-database'

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

// maybe should call this every time when new address generated
// load all addresses and convert to lockHashes
Expand Down Expand Up @@ -40,6 +42,14 @@ export const switchNetwork = async (nodeURL: string) => {
}
})

walletCreatedSubject.subscribe(async (type: string) => {
if (type === 'import') {
if (indexerQueue) {
indexerQueue.reset()
}
}
})

indexerQueue.start()
indexerQueue.processFork()
}

0 comments on commit 6be360e

Please sign in to comment.