Skip to content

Commit 1b3fc9e

Browse files
authored
Updated Binance Wallet provider patch and version bump (#1174)
1 parent 6813beb commit 1b3fc9e

File tree

5 files changed

+20
-32
lines changed

5 files changed

+20
-32
lines changed

packages/demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@web3-onboard/dcent": "^2.0.5",
2828
"@web3-onboard/fortmatic": "^2.0.6",
2929
"@web3-onboard/gnosis": "^2.0.5",
30-
"@web3-onboard/injected-wallets": "^2.0.12",
30+
"@web3-onboard/injected-wallets": "^2.0.15-alpha.2",
3131
"@web3-onboard/keepkey": "^2.1.4",
3232
"@web3-onboard/keystone": "^2.1.5",
3333
"@web3-onboard/ledger": "^2.1.4",

packages/demo/src/App.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import coinbaseModule from '@web3-onboard/coinbase'
1414
import magicModule from '@web3-onboard/magic'
1515
import web3authModule from '@web3-onboard/web3auth'
16+
1617
import dcentModule from '@web3-onboard/dcent'
1718
import {
1819
recoverAddress,

packages/injected/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/injected-wallets",
3-
"version": "2.0.15-alpha.1",
3+
"version": "2.0.15-alpha.2",
44
"description": "Injected wallet module for connecting browser extension and mobile wallets to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
55
"keywords": [
66
"Ethereum",

packages/injected/src/wallets.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import type {
22
EIP1193Provider,
33
ChainListener,
4-
SimpleEventEmitter
4+
SimpleEventEmitter,
5+
ChainId
56
} from '@web3-onboard/common'
67

78
import { createEIP1193Provider } from '@web3-onboard/common'
8-
import type { InjectedWalletModule, CustomWindow } from './types.js'
9+
import type {
10+
InjectedWalletModule,
11+
CustomWindow,
12+
BinanceProvider
13+
} from './types.js'
914

1015
import {
1116
InjectedNameSpace,
@@ -65,11 +70,11 @@ const binance: InjectedWalletModule = {
6570
!!provider && !!provider[ProviderIdentityFlag.Binance],
6671
getIcon: async () => (await import('./icons/binance.js')).default,
6772
getInterface: async () => {
68-
// We add this to the BinanceChain provider as there is currently
69-
// no way to determine if the wallet is unlocked
70-
if (window.BinanceChain) {
71-
window.BinanceChain.isUnlocked = false
73+
// Replace the provider as the BNB provider is readonly
74+
let tempBNBProvider: BinanceProvider = {
75+
...window.BinanceChain
7276
}
77+
window.BinanceChain = tempBNBProvider
7378

7479
const addListener: SimpleEventEmitter['on'] = window.BinanceChain.on.bind(
7580
window.BinanceChain
@@ -78,31 +83,22 @@ const binance: InjectedWalletModule = {
7883
window.BinanceChain.on = (event, func) => {
7984
// intercept chainChanged event and format string
8085
if (event === 'chainChanged') {
81-
addListener(event, (chainId: string) => {
86+
addListener(event, (chainId: ChainId) => {
8287
const cb = func as ChainListener
83-
cb(`0x${parseInt(chainId).toString(16)}`)
88+
cb(`0x${parseInt(chainId as string).toString(16)}`)
8489
})
8590
} else {
8691
addListener(event, func)
8792
}
8893
}
8994

9095
const provider = createEIP1193Provider(window.BinanceChain, {
91-
// If the wallet is unlocked then we don't need to patch this request
92-
...(!window.BinanceChain.isUnlocked && {
93-
eth_accounts: () => Promise.resolve([])
94-
}),
95-
eth_requestAccounts: ({ baseRequest }) =>
96-
baseRequest({ method: 'eth_requestAccounts' }).then(accts => {
97-
window.BinanceChain.isUnlocked = true
98-
return accts
99-
}),
100-
eth_selectAccounts: UNSUPPORTED_METHOD,
10196
eth_chainId: ({ baseRequest }) =>
102-
baseRequest({ method: 'eth_chainId' }).then(
103-
id => `0x${parseInt(id).toString(16)}`
104-
),
97+
baseRequest({ method: 'eth_chainId' }).then(id => {
98+
return `0x${parseInt(id as string).toString(16)}`
99+
}),
105100
// Unsupported method -- will throw error
101+
eth_selectAccounts: UNSUPPORTED_METHOD,
106102
wallet_switchEthereumChain: UNSUPPORTED_METHOD
107103
})
108104

yarn.lock

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,15 +2564,6 @@
25642564
"@gnosis.pm/safe-apps-sdk" "^6.1.1"
25652565
"@web3-onboard/common" "^2.1.5"
25662566

2567-
"@web3-onboard/injected-wallets@^2.0.12":
2568-
version "2.0.13"
2569-
resolved "https://registry.yarnpkg.com/@web3-onboard/injected-wallets/-/injected-wallets-2.0.13.tgz#dc7d67e3b9efd4f7bd09f075d6ef6399322d5146"
2570-
integrity sha512-UtPA26+yn02+lLmiwI404DKMIzLM/fhClQTyR9cc4ZcM+YHwGW3kb/NKtxxhKWNtQbXCp8nPTPfHgKW2Y9mggA==
2571-
dependencies:
2572-
"@web3-onboard/common" "^2.1.5"
2573-
joi "^17.4.2"
2574-
lodash.uniqby "^4.7.0"
2575-
25762567
"@web3-onboard/keepkey@^2.1.4":
25772568
version "2.1.5"
25782569
resolved "https://registry.yarnpkg.com/@web3-onboard/keepkey/-/keepkey-2.1.5.tgz#7903f1824dca0af981fd771e63495cda85d9ee0a"

0 commit comments

Comments
 (0)