Skip to content

Commit 9b7ac34

Browse files
1.34.2-0.0.3: Refactor the balance syncer to not start polling (#686)
* 1.34.2-0.0.3: Refactor the balance syncer to not start polling * Fix formatting * Remove console.log
1 parent 301dd91 commit 9b7ac34

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bnc-onboard",
3-
"version": "1.34.2-0.0.2",
3+
"version": "1.34.2-0.0.3",
44
"description": "Onboard users to web3 by allowing them to select a wallet, get that wallet ready to transact and have access to synced wallet state.",
55
"keywords": [
66
"ethereum",

src/interfaces.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,18 +507,15 @@ export interface WalletInterfaceStore {
507507

508508
export interface WalletStateSliceStore {
509509
subscribe: (subscriber: (store: any) => void) => () => void
510-
reset: () => void
511510
setStateSyncer: (
512511
stateSyncer: StateSyncer
513512
) => { clear: () => void } | undefined
513+
reset: () => void
514514
get: () => any
515515
}
516516

517-
export interface BalanceStore {
518-
subscribe: (subscriber: (store: any) => void) => () => void
517+
export interface BalanceStore extends WalletStateSliceStore {
519518
setStateSyncer: (stateSyncer: StateSyncer) => undefined
520-
reset: () => void
521-
get: () => any
522519
}
523520

524521
export type Browser = {

src/stores.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,28 @@ export function initializeStores() {
7575
initialState: null
7676
})
7777

78-
balance = get(app).dappId
79-
? createBalanceStore(null)
80-
: createWalletStateSliceStore({
81-
parameter: 'balance',
82-
initialState: null,
83-
intervalSetting: 1000
84-
})
78+
balance = get(
79+
derived<WalletStateSliceStore, BalanceStore | WalletStateSliceStore>(
80+
address,
81+
$address => {
82+
if (!$address) {
83+
return {
84+
subscribe: () => () => {},
85+
setStateSyncer: (stateSyncer: StateSyncer) => undefined,
86+
reset: () => {},
87+
get: () => {}
88+
}
89+
}
90+
return get(app).dappId
91+
? createBalanceStore(null)
92+
: createWalletStateSliceStore({
93+
parameter: 'balance',
94+
initialState: null,
95+
intervalSetting: 1000
96+
})
97+
}
98+
)
99+
)
85100

86101
wallet = writable({
87102
name: null,

0 commit comments

Comments
 (0)