1
- import { writable , derived } from 'svelte/store'
1
+ import { writable , derived , get } from 'svelte/store'
2
2
import { getBlocknative } from './services'
3
3
import { wait , makeQuerablePromise } from './utilities'
4
4
import { validateWalletInterface , validateType } from './validation'
@@ -168,7 +168,8 @@ function createBalanceStore(initialState: string | null): BalanceStore {
168
168
syncStateWithTimeout ( {
169
169
getState : stateSyncer . get ,
170
170
setState : set ,
171
- timeout : 2000
171
+ timeout : 4000 ,
172
+ currentBalance : get ( balance )
172
173
} )
173
174
174
175
if ( emitterAddress !== $address ) {
@@ -180,7 +181,8 @@ function createBalanceStore(initialState: string | null): BalanceStore {
180
181
syncStateWithTimeout ( {
181
182
getState : stateSyncer . get ,
182
183
setState : set ,
183
- timeout : 2000
184
+ timeout : 4000 ,
185
+ currentBalance : get ( balance )
184
186
} )
185
187
186
188
return false
@@ -229,9 +231,10 @@ function createBalanceStore(initialState: string | null): BalanceStore {
229
231
function syncStateWithTimeout ( options : {
230
232
getState : ( ) => Promise < string | number | null >
231
233
setState : ( newState : string ) => void
232
- timeout : number
234
+ timeout : number ,
235
+ currentBalance : string
233
236
} ) {
234
- const { getState, setState, timeout } = options
237
+ const { getState, setState, timeout, currentBalance } = options
235
238
const prom = makeQuerablePromise (
236
239
new Cancelable (
237
240
(
@@ -253,7 +256,9 @@ function syncStateWithTimeout(options: {
253
256
254
257
prom
255
258
. then ( ( result : string ) => {
256
- if ( result ) {
259
+ if ( result === currentBalance ) {
260
+ syncStateWithTimeout ( ( options ) )
261
+ } else {
257
262
setState ( result )
258
263
}
259
264
} )
0 commit comments