File tree Expand file tree Collapse file tree
packages/neuron-wallet/src Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff line change @@ -5,7 +5,9 @@ import IndexerQueue from 'services/indexer/queue'
55
66import { 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}
You can’t perform that action at this time.
0 commit comments