Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/demo/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/injected/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
38 changes: 17 additions & 21 deletions packages/injected/src/wallets.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -78,31 +83,22 @@ 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)
}
}

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
})

Expand Down
9 changes: 0 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down