Skip to content

Commit 5156975

Browse files
1.34.2-0.0.6: [fix] BSC wallet balance polling (#698)
* Reverts the original fix to the polling issue * Implements a fix isolated to BSC wallet module * Fix now won't allow call to get balance until an address is defined
1 parent 7a0fcf1 commit 5156975

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
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.5",
3+
"version": "1.34.2-0.0.6",
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/modules/select/wallets/binance-chain-wallet.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,43 @@ function binanceChainWallet(
1818
// Ref: https://binance-wallet.gitbook.io/binance-chain-extension-wallet
1919
const provider = (window as any).BinanceChain
2020

21+
// The following code is necessary as when polling BSC wallet for a balance causes it to
22+
// relaunch the login prompt indefinitely
23+
24+
let providerInterface = null
25+
let address: string | number | null | undefined
26+
27+
if (provider) {
28+
providerInterface = createModernProviderInterface(provider)
29+
30+
if (providerInterface.balance.get) {
31+
if (providerInterface.address.get) {
32+
// Save and override the address `get` method
33+
// Enables us to save the address used below to determine when to get the balance
34+
// We only want to get the balance after we get the address
35+
const addressGet = providerInterface.address.get
36+
providerInterface.address.get = async () => {
37+
address = await addressGet()
38+
return address
39+
}
40+
} else if (providerInterface.address.onChange) {
41+
// Intercept the onChange event to save the address internally
42+
providerInterface.address.onChange(updatedAddress => {
43+
address = updatedAddress
44+
})
45+
}
46+
// Save and override the balance `get` method -- only call the original method
47+
// if we have an address from BSC
48+
const balanceGet = providerInterface.balance.get
49+
providerInterface.balance.get = () => {
50+
return address ? balanceGet() : Promise.resolve(null)
51+
}
52+
}
53+
}
54+
2155
return {
2256
provider,
23-
interface: provider && createModernProviderInterface(provider)
57+
interface: providerInterface
2458
}
2559
},
2660
type: 'injected',

src/stores.ts

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

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-
)
78+
balance = get(app).dappId
79+
? createBalanceStore(null)
80+
: createWalletStateSliceStore({
81+
parameter: 'balance',
82+
initialState: null,
83+
intervalSetting: 1000
84+
})
10085

10186
wallet = writable({
10287
name: null,

0 commit comments

Comments
 (0)