Skip to content

Commit 1e6097c

Browse files
committed
Set initial state to null and don't call subscription callback unless not null
1 parent 2ee1a9e commit 1e6097c

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/@types/libraries.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
declare module "promise-cancelable" {
22
export default class Cancelable extends Promise<any> {
33
constructor(executor: any)
4-
cancel(): any
4+
cancel(func: () => void): any
55
isFulfilled(): any
66
isResolved(): any
77
isRejected(): any

src/onboard.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ function init(initialization: Initialization): API {
5656
if (subscriptions) {
5757
if (subscriptions.address) {
5858
address.subscribe((address: string | null) => {
59-
address && subscriptions.address(address)
59+
if (address !== null) {
60+
subscriptions.address(address)
61+
}
6062
})
6163
}
6264

@@ -68,7 +70,9 @@ function init(initialization: Initialization): API {
6870

6971
if (subscriptions.balance) {
7072
balance.subscribe((balance: string) => {
71-
balance && subscriptions.balance(balance)
73+
if (balance !== null) {
74+
subscriptions.balance(balance)
75+
}
7276
})
7377
}
7478

src/stores.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const network: WalletStateSliceStore = createWalletStateSliceStore({
4141
parameter: "network",
4242
initialState: null
4343
})
44-
export const balance: BalanceStore = createBalanceStore("")
44+
export const balance: BalanceStore = createBalanceStore(null)
4545
export const wallet: WritableStore = writable({
4646
name: null,
4747
provider: null,
@@ -106,14 +106,14 @@ function createWalletInterfaceStore(
106106

107107
function createWalletStateSliceStore(options: {
108108
parameter: string
109-
initialState: string | number | null
109+
initialState: string | number | null | undefined
110110
}): WalletStateSliceStore {
111111
const { parameter, initialState } = options
112112
const { subscribe, set } = writable(initialState)
113113

114114
return {
115115
subscribe,
116-
reset: () => set(initialState),
116+
reset: () => set(undefined),
117117
setStateSyncer: (stateSyncer: StateSyncer) => {
118118
validateType({ name: "stateSyncer", value: stateSyncer, type: "object" })
119119

@@ -155,7 +155,7 @@ function createWalletStateSliceStore(options: {
155155
}
156156
}
157157

158-
function createBalanceStore(initialState: string): BalanceStore {
158+
function createBalanceStore(initialState: string | null): BalanceStore {
159159
let stateSyncer: StateSyncer
160160
let emitter
161161

@@ -181,7 +181,7 @@ function createBalanceStore(initialState: string): BalanceStore {
181181
emitter.on("all", () => false)
182182
} else {
183183
// no address, so set balance back to null
184-
set && set(initialState)
184+
set && set(undefined)
185185
}
186186
}
187187
})
@@ -234,7 +234,7 @@ function syncStateWithTimeout(options: {
234234
"There was a problem getting the balance of this wallet"
235235
})
236236
}
237-
)
237+
).catch(() => {})
238238
)
239239

240240
balanceSyncStatus.syncing = prom
@@ -251,7 +251,7 @@ function syncStateWithTimeout(options: {
251251

252252
timedOut.then(() => {
253253
if (!prom.isFulfilled()) {
254-
prom.cancel()
254+
prom.cancel(() => {})
255255
}
256256
})
257257
}

0 commit comments

Comments
 (0)