Skip to content

Commit 6be360e

Browse files
committed
fix: reset when import wallet
1 parent a087114 commit 6be360e

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

packages/neuron-wallet/src/services/indexer/queue.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export default class Queue {
3232

3333
private inProcess = false
3434

35+
private resetFlag = false
36+
3537
constructor(url: string, lockHashes: string[], tipNumberSubject: Subject<string | undefined>) {
3638
this.lockHashes = lockHashes
3739
this.indexerRPC = new IndexerRPC(url)
@@ -49,12 +51,20 @@ export default class Queue {
4951
this.indexed = false
5052
}
5153

54+
public reset = () => {
55+
this.resetFlag = true
56+
}
57+
5258
/* eslint no-await-in-loop: "off" */
5359
/* eslint no-restricted-syntax: "off" */
5460
public start = async () => {
5561
while (!this.stopped) {
5662
try {
5763
this.inProcess = true
64+
if (this.resetFlag) {
65+
await this.blockNumberService.updateCurrent(BigInt(0))
66+
this.resetFlag = false
67+
}
5868
const { lockHashes } = this
5969
const currentBlockNumber: bigint = await this.blockNumberService.getCurrent()
6070
if (!this.indexed || currentBlockNumber !== this.tipBlockNumber) {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import IndexerQueue from 'services/indexer/queue'
55

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

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

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

45+
walletCreatedSubject.subscribe(async (type: string) => {
46+
if (type === 'import') {
47+
if (indexerQueue) {
48+
indexerQueue.reset()
49+
}
50+
}
51+
})
52+
4353
indexerQueue.start()
4454
indexerQueue.processFork()
4555
}

0 commit comments

Comments
 (0)