Skip to content

Commit 5d6dda0

Browse files
committed
Make sure balance updates
1 parent 07a6d2e commit 5d6dda0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/stores.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { writable, derived } from 'svelte/store'
1+
import { writable, derived, get } from 'svelte/store'
22
import { getBlocknative } from './services'
33
import { wait, makeQuerablePromise } from './utilities'
44
import { validateWalletInterface, validateType } from './validation'
@@ -168,7 +168,8 @@ function createBalanceStore(initialState: string | null): BalanceStore {
168168
syncStateWithTimeout({
169169
getState: stateSyncer.get,
170170
setState: set,
171-
timeout: 2000
171+
timeout: 4000,
172+
currentBalance: get(balance)
172173
})
173174

174175
if (emitterAddress !== $address) {
@@ -180,7 +181,8 @@ function createBalanceStore(initialState: string | null): BalanceStore {
180181
syncStateWithTimeout({
181182
getState: stateSyncer.get,
182183
setState: set,
183-
timeout: 2000
184+
timeout: 4000,
185+
currentBalance: get(balance)
184186
})
185187

186188
return false
@@ -229,9 +231,10 @@ function createBalanceStore(initialState: string | null): BalanceStore {
229231
function syncStateWithTimeout(options: {
230232
getState: () => Promise<string | number | null>
231233
setState: (newState: string) => void
232-
timeout: number
234+
timeout: number,
235+
currentBalance: string
233236
}) {
234-
const { getState, setState, timeout } = options
237+
const { getState, setState, timeout, currentBalance } = options
235238
const prom = makeQuerablePromise(
236239
new Cancelable(
237240
(
@@ -253,7 +256,9 @@ function syncStateWithTimeout(options: {
253256

254257
prom
255258
.then((result: string) => {
256-
if (result) {
259+
if (result === currentBalance) {
260+
syncStateWithTimeout((options))
261+
} else {
257262
setState(result)
258263
}
259264
})

0 commit comments

Comments
 (0)