diff --git a/packages/demo/package.json b/packages/demo/package.json index 6b61e9c83..96027624b 100644 --- a/packages/demo/package.json +++ b/packages/demo/package.json @@ -27,7 +27,7 @@ "@web3-onboard/dcent": "^2.0.5", "@web3-onboard/fortmatic": "^2.0.6", "@web3-onboard/gnosis": "^2.0.5", - "@web3-onboard/injected-wallets": "^2.0.12", + "@web3-onboard/injected-wallets": "^2.0.15-alpha.2", "@web3-onboard/keepkey": "^2.1.4", "@web3-onboard/keystone": "^2.1.5", "@web3-onboard/ledger": "^2.1.4", diff --git a/packages/demo/src/App.svelte b/packages/demo/src/App.svelte index 643be364a..8ecd45536 100644 --- a/packages/demo/src/App.svelte +++ b/packages/demo/src/App.svelte @@ -13,6 +13,7 @@ import coinbaseModule from '@web3-onboard/coinbase' import magicModule from '@web3-onboard/magic' import web3authModule from '@web3-onboard/web3auth' + import dcentModule from '@web3-onboard/dcent' import { recoverAddress, diff --git a/packages/injected/package.json b/packages/injected/package.json index daa31f24c..870db7102 100644 --- a/packages/injected/package.json +++ b/packages/injected/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/injected-wallets", - "version": "2.0.15-alpha.1", + "version": "2.0.15-alpha.2", "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.", "keywords": [ "Ethereum", diff --git a/packages/injected/src/wallets.ts b/packages/injected/src/wallets.ts index 7be24561a..7b18ea852 100644 --- a/packages/injected/src/wallets.ts +++ b/packages/injected/src/wallets.ts @@ -1,11 +1,16 @@ import type { EIP1193Provider, ChainListener, - SimpleEventEmitter + SimpleEventEmitter, + ChainId } from '@web3-onboard/common' import { createEIP1193Provider } from '@web3-onboard/common' -import type { InjectedWalletModule, CustomWindow } from './types.js' +import type { + InjectedWalletModule, + CustomWindow, + BinanceProvider +} from './types.js' import { InjectedNameSpace, @@ -65,11 +70,11 @@ const binance: InjectedWalletModule = { !!provider && !!provider[ProviderIdentityFlag.Binance], getIcon: async () => (await import('./icons/binance.js')).default, getInterface: async () => { - // We add this to the BinanceChain provider as there is currently - // no way to determine if the wallet is unlocked - if (window.BinanceChain) { - window.BinanceChain.isUnlocked = false + // Replace the provider as the BNB provider is readonly + let tempBNBProvider: BinanceProvider = { + ...window.BinanceChain } + window.BinanceChain = tempBNBProvider const addListener: SimpleEventEmitter['on'] = window.BinanceChain.on.bind( window.BinanceChain @@ -78,9 +83,9 @@ const binance: InjectedWalletModule = { window.BinanceChain.on = (event, func) => { // intercept chainChanged event and format string if (event === 'chainChanged') { - addListener(event, (chainId: string) => { + addListener(event, (chainId: ChainId) => { const cb = func as ChainListener - cb(`0x${parseInt(chainId).toString(16)}`) + cb(`0x${parseInt(chainId as string).toString(16)}`) }) } else { addListener(event, func) @@ -88,21 +93,12 @@ const binance: InjectedWalletModule = { } const provider = createEIP1193Provider(window.BinanceChain, { - // If the wallet is unlocked then we don't need to patch this request - ...(!window.BinanceChain.isUnlocked && { - eth_accounts: () => Promise.resolve([]) - }), - eth_requestAccounts: ({ baseRequest }) => - baseRequest({ method: 'eth_requestAccounts' }).then(accts => { - window.BinanceChain.isUnlocked = true - return accts - }), - eth_selectAccounts: UNSUPPORTED_METHOD, eth_chainId: ({ baseRequest }) => - baseRequest({ method: 'eth_chainId' }).then( - id => `0x${parseInt(id).toString(16)}` - ), + baseRequest({ method: 'eth_chainId' }).then(id => { + return `0x${parseInt(id as string).toString(16)}` + }), // Unsupported method -- will throw error + eth_selectAccounts: UNSUPPORTED_METHOD, wallet_switchEthereumChain: UNSUPPORTED_METHOD }) diff --git a/yarn.lock b/yarn.lock index 953b7bbb0..798020d45 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2564,15 +2564,6 @@ "@gnosis.pm/safe-apps-sdk" "^6.1.1" "@web3-onboard/common" "^2.1.5" -"@web3-onboard/injected-wallets@^2.0.12": - version "2.0.13" - resolved "https://registry.yarnpkg.com/@web3-onboard/injected-wallets/-/injected-wallets-2.0.13.tgz#dc7d67e3b9efd4f7bd09f075d6ef6399322d5146" - integrity sha512-UtPA26+yn02+lLmiwI404DKMIzLM/fhClQTyR9cc4ZcM+YHwGW3kb/NKtxxhKWNtQbXCp8nPTPfHgKW2Y9mggA== - dependencies: - "@web3-onboard/common" "^2.1.5" - joi "^17.4.2" - lodash.uniqby "^4.7.0" - "@web3-onboard/keepkey@^2.1.4": version "2.1.5" resolved "https://registry.yarnpkg.com/@web3-onboard/keepkey/-/keepkey-2.1.5.tgz#7903f1824dca0af981fd771e63495cda85d9ee0a"