From d8de4b4800a304fe2c1f9a53ff017f6325e6f5fd Mon Sep 17 00:00:00 2001 From: aidencao <104969608+aiden-cao@users.noreply.github.com> Date: Fri, 6 Mar 2026 11:33:21 +0800 Subject: [PATCH 1/3] feat: add desktop extension support for Binance Web3 Wallet --- .changeset/moody-shrimps-melt.md | 5 ++ .claude/settings.local.json | 13 +++++ examples/nextjs/pages/_app.tsx | 9 +++- examples/vite/src/App.tsx | 9 +++- packages/walletkit/src/typings.d.ts | 1 + .../wallets/binanceWeb3Wallet/connector.ts | 52 ------------------- .../src/wallets/binanceWeb3Wallet/index.tsx | 21 ++++++-- website/src/pages/index.mdx | 9 +++- 8 files changed, 57 insertions(+), 62 deletions(-) create mode 100644 .changeset/moody-shrimps-melt.md create mode 100644 .claude/settings.local.json delete mode 100644 packages/walletkit/src/wallets/binanceWeb3Wallet/connector.ts diff --git a/.changeset/moody-shrimps-melt.md b/.changeset/moody-shrimps-melt.md new file mode 100644 index 00000000..5faf1d72 --- /dev/null +++ b/.changeset/moody-shrimps-melt.md @@ -0,0 +1,5 @@ +--- +'@node-real/walletkit': minor +--- + +feat: add desktop extension support for Binance Web3 Wallet diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 00000000..c6c298f3 --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,13 @@ +{ + "permissions": { + "allow": [ + "Bash(/tmp/comparison.txt:*)", + "Read(//tmp/**)", + "WebFetch(domain:developers.binance.com)", + "Bash(npm run:*)", + "Bash(git stash:*)", + "Bash(grep \"\"version\"\":*)", + "Bash(npx tsc:*)" + ] + } +} diff --git a/examples/nextjs/pages/_app.tsx b/examples/nextjs/pages/_app.tsx index f4bb463e..2a9c3671 100644 --- a/examples/nextjs/pages/_app.tsx +++ b/examples/nextjs/pages/_app.tsx @@ -10,7 +10,12 @@ import { WalletKitProvider, getDefaultConfig, } from '@node-real/walletkit'; -import { trustWallet, metaMask, walletConnect } from '@node-real/walletkit/wallets'; +import { + binanceWeb3Wallet, + trustWallet, + metaMask, + walletConnect, +} from '@node-real/walletkit/wallets'; const config = createConfig( getDefaultConfig({ @@ -22,7 +27,7 @@ const config = createConfig( walletConnectProjectId: 'e68a1816d39726c2afabf05661a32767', chains, - connectors: [trustWallet(), metaMask(), walletConnect()], + connectors: [binanceWeb3Wallet(), trustWallet(), metaMask(), walletConnect()], }), ); diff --git a/examples/vite/src/App.tsx b/examples/vite/src/App.tsx index 0b236fe8..7f32195c 100644 --- a/examples/vite/src/App.tsx +++ b/examples/vite/src/App.tsx @@ -8,7 +8,12 @@ import { WalletKitOptions, SwitchNetworkModal, } from '@node-real/walletkit'; -import { trustWallet, metaMask, walletConnect } from '@node-real/walletkit/wallets'; +import { + binanceWeb3Wallet, + trustWallet, + metaMask, + walletConnect, +} from '@node-real/walletkit/wallets'; const config = createConfig( getDefaultConfig({ @@ -20,7 +25,7 @@ const config = createConfig( walletConnectProjectId: 'e68a1816d39726c2afabf05661a32767', chains, - connectors: [trustWallet(), metaMask(), walletConnect()], + connectors: [binanceWeb3Wallet(), trustWallet(), metaMask(), walletConnect()], }), ); diff --git a/packages/walletkit/src/typings.d.ts b/packages/walletkit/src/typings.d.ts index 665739dd..af68a23c 100644 --- a/packages/walletkit/src/typings.d.ts +++ b/packages/walletkit/src/typings.d.ts @@ -12,6 +12,7 @@ declare global { tokenpocket: any; okexchain: any; bitkeep: any; + binancew3w: any; } } diff --git a/packages/walletkit/src/wallets/binanceWeb3Wallet/connector.ts b/packages/walletkit/src/wallets/binanceWeb3Wallet/connector.ts deleted file mode 100644 index 707eed20..00000000 --- a/packages/walletkit/src/wallets/binanceWeb3Wallet/connector.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { sleep } from '@/utils/common'; -import { Chain, WindowProvider } from 'wagmi'; -import { InjectedConnector } from 'wagmi/connectors/injected'; -import { BINANCE_WEB3_WALLET_ID, BINANCE_WEB3_WALLET_NAME, isBinanceWeb3Wallet } from '.'; -import { isMobile } from '@/base/utils/mobile'; - -export type BinanceWeb3WalletConnectorOptions = Required< - ConstructorParameters ->[0]['options']; - -export interface CustomConstructorParams { - chains?: Chain[]; - options?: BinanceWeb3WalletConnectorOptions; -} - -export class BinanceWeb3WalletConnector extends InjectedConnector { - public id = BINANCE_WEB3_WALLET_ID; - protected shimDisconnectKey = `${this.id}.shimDisconnect`; - - constructor(props: CustomConstructorParams) { - const { chains, options: _options } = props ?? {}; - - const options = { - name: BINANCE_WEB3_WALLET_NAME, - shimDisconnect: true, - getProvider, - ..._options, - }; - - if (typeof window !== 'undefined' && isMobile() && isBinanceWeb3Wallet()) { - (window.ethereum as any)?.enable?.(); - } - - super({ - chains, - options, - }); - } - - public async getProvider(): Promise { - await sleep(); - return this.options.getProvider(); - } -} - -function getProvider() { - if (typeof window === 'undefined') return; - - if (isMobile()) { - return window.ethereum; - } -} diff --git a/packages/walletkit/src/wallets/binanceWeb3Wallet/index.tsx b/packages/walletkit/src/wallets/binanceWeb3Wallet/index.tsx index 232487ca..a152d8ac 100644 --- a/packages/walletkit/src/wallets/binanceWeb3Wallet/index.tsx +++ b/packages/walletkit/src/wallets/binanceWeb3Wallet/index.tsx @@ -2,7 +2,8 @@ import { Chain } from 'wagmi'; import { PartialCustomProps, WalletProps } from '..'; import { BinanceWeb3WalletIcon, BinanceWeb3WalletTransparentIcon } from './icon'; import { hasInjectedProvider } from '../utils'; -import { BinanceWeb3WalletConnector } from './connector'; +import { CustomConnector } from '../custom/connector'; +import { isMobile } from '@/base/utils/mobile'; export const BINANCE_WEB3_WALLET_ID = 'binanceWeb3Wallet'; export const BINANCE_WEB3_WALLET_NAME = 'Binance Web3 Wallet'; @@ -21,13 +22,24 @@ export function binanceWeb3Wallet(props: PartialCustomProps = {}): WalletProps { default: 'https://www.binance.com/en/web3wallet', }, spinnerColor: undefined, - showQRCode: true, + showQRCode: false, isInstalled: isBinanceWeb3Wallet, createConnector: (chains: Chain[]) => { - return new BinanceWeb3WalletConnector({ + return new CustomConnector({ + id: BINANCE_WEB3_WALLET_ID, chains, options: { + name: BINANCE_WEB3_WALLET_NAME, shimDisconnect: true, + getProvider() { + if (typeof window === 'undefined') return; + + if (isMobile()) { + return window.ethereum; + } + + return window.binancew3w?.ethereum; + }, ...connectorOptions, }, }); @@ -44,7 +56,8 @@ export function binanceWeb3Wallet(props: PartialCustomProps = {}): WalletProps { } export function isBinanceWeb3Wallet() { - return hasInjectedProvider('isBinance' as any); + if (typeof window === 'undefined') return false; + return !!window.binancew3w?.ethereum || hasInjectedProvider('isBinance' as any); } const getDeepLink = (url: string) => { diff --git a/website/src/pages/index.mdx b/website/src/pages/index.mdx index 9bf9d500..5324ef82 100644 --- a/website/src/pages/index.mdx +++ b/website/src/pages/index.mdx @@ -96,7 +96,12 @@ import { WalletKitOptions, SwitchNetworkModal, } from '@node-real/walletkit'; -import { metaMask, trustWallet, walletConnect } from '@node-real/walletkit/wallets'; +import { + binanceWeb3Wallet, + metaMask, + trustWallet, + walletConnect, +} from '@node-real/walletkit/wallets'; const config = createConfig( getDefaultConfig({ @@ -108,7 +113,7 @@ const config = createConfig( walletConnectProjectId: 'xxx', chains, - connectors: [trustWallet(), metaMask(), walletConnect()], + connectors: [binanceWeb3Wallet(), trustWallet(), metaMask(), walletConnect()], }), ); From 2ceef87336f5fd7fe0e48558b2c97ddae3378727 Mon Sep 17 00:00:00 2001 From: aidencao <104969608+aiden-cao@users.noreply.github.com> Date: Fri, 6 Mar 2026 11:56:42 +0800 Subject: [PATCH 2/3] feat: update website --- website/src/pages/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/src/pages/index.mdx b/website/src/pages/index.mdx index 5324ef82..cdb8dffd 100644 --- a/website/src/pages/index.mdx +++ b/website/src/pages/index.mdx @@ -18,7 +18,7 @@ npm i @node-real/walletkit@^1 wagmi@^1 viem@^1 | wallet | mainnet | testnet | | ------------------- | ------- | ------- | -| binanceWeb3Wallet() | ✅ | ❌ | +| binanceWeb3Wallet() | ✅ | ✅ | | bitgetWallet() | ✅ | ❌ | | coinbaseWallet() | ✅ | ✅ | | metaMask() | ✅ | ✅ | From 908d2cb10177785b943771875bb9d5ea93b77c29 Mon Sep 17 00:00:00 2001 From: aidencao <104969608+aiden-cao@users.noreply.github.com> Date: Mon, 9 Mar 2026 16:56:23 +0800 Subject: [PATCH 3/3] fix: restore BinanceWeb3WalletConnector for mobile in-app browser compatibility Commit d8de4b4 replaced BinanceWeb3WalletConnector with generic CustomConnector, which lost two critical mobile behaviors: - window.ethereum?.enable?.() activation in Binance's in-app browser - sleep() delay in getProvider() for provider availability Restores the dedicated connector while keeping desktop extension support (window.binancew3w?.ethereum) and showQRCode: false from the previous commit. --- .changeset/lemon-bugs-try.md | 6 ++ .../wallets/binanceWeb3Wallet/connector.ts | 55 +++++++++++++++++++ .../src/wallets/binanceWeb3Wallet/index.tsx | 17 +----- 3 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 .changeset/lemon-bugs-try.md create mode 100644 packages/walletkit/src/wallets/binanceWeb3Wallet/connector.ts diff --git a/.changeset/lemon-bugs-try.md b/.changeset/lemon-bugs-try.md new file mode 100644 index 00000000..07fbcb20 --- /dev/null +++ b/.changeset/lemon-bugs-try.md @@ -0,0 +1,6 @@ +--- +'@node-real/walletkit': minor +--- + +fix: restore BinanceWeb3WalletConnector for mobile in-app browser compatibility + diff --git a/packages/walletkit/src/wallets/binanceWeb3Wallet/connector.ts b/packages/walletkit/src/wallets/binanceWeb3Wallet/connector.ts new file mode 100644 index 00000000..10b280ce --- /dev/null +++ b/packages/walletkit/src/wallets/binanceWeb3Wallet/connector.ts @@ -0,0 +1,55 @@ +import { sleep } from '@/utils/common'; +import { Chain, WindowProvider } from 'wagmi'; +import { InjectedConnector } from 'wagmi/connectors/injected'; +import { BINANCE_WEB3_WALLET_ID, BINANCE_WEB3_WALLET_NAME, isBinanceWeb3Wallet } from '.'; +import { isMobile } from '@/base/utils/mobile'; + +export type BinanceWeb3WalletConnectorOptions = Required< + ConstructorParameters +>[0]['options']; + +export interface CustomConstructorParams { + chains?: Chain[]; + options?: BinanceWeb3WalletConnectorOptions; +} + +export class BinanceWeb3WalletConnector extends InjectedConnector { + public id = BINANCE_WEB3_WALLET_ID; + protected shimDisconnectKey = `${this.id}.shimDisconnect`; + + constructor(props: CustomConstructorParams) { + const { chains, options: _options } = props ?? {}; + + const options = { + name: BINANCE_WEB3_WALLET_NAME, + shimDisconnect: true, + getProvider, + ..._options, + }; + + if (typeof window !== 'undefined' && isMobile() && isBinanceWeb3Wallet()) { + (window.ethereum as any)?.enable?.(); + } + + super({ + chains, + options, + }); + } + + public async getProvider(): Promise { + await sleep(); + return this.options.getProvider(); + } +} + +function getProvider() { + if (typeof window === 'undefined') return; + + if (isMobile()) { + return window.ethereum; + } + + // Desktop: use Binance Web3 Wallet browser extension + return window.binancew3w?.ethereum; +} diff --git a/packages/walletkit/src/wallets/binanceWeb3Wallet/index.tsx b/packages/walletkit/src/wallets/binanceWeb3Wallet/index.tsx index a152d8ac..e92e1a04 100644 --- a/packages/walletkit/src/wallets/binanceWeb3Wallet/index.tsx +++ b/packages/walletkit/src/wallets/binanceWeb3Wallet/index.tsx @@ -2,8 +2,7 @@ import { Chain } from 'wagmi'; import { PartialCustomProps, WalletProps } from '..'; import { BinanceWeb3WalletIcon, BinanceWeb3WalletTransparentIcon } from './icon'; import { hasInjectedProvider } from '../utils'; -import { CustomConnector } from '../custom/connector'; -import { isMobile } from '@/base/utils/mobile'; +import { BinanceWeb3WalletConnector } from './connector'; export const BINANCE_WEB3_WALLET_ID = 'binanceWeb3Wallet'; export const BINANCE_WEB3_WALLET_NAME = 'Binance Web3 Wallet'; @@ -25,21 +24,9 @@ export function binanceWeb3Wallet(props: PartialCustomProps = {}): WalletProps { showQRCode: false, isInstalled: isBinanceWeb3Wallet, createConnector: (chains: Chain[]) => { - return new CustomConnector({ - id: BINANCE_WEB3_WALLET_ID, + return new BinanceWeb3WalletConnector({ chains, options: { - name: BINANCE_WEB3_WALLET_NAME, - shimDisconnect: true, - getProvider() { - if (typeof window === 'undefined') return; - - if (isMobile()) { - return window.ethereum; - } - - return window.binancew3w?.ethereum; - }, ...connectorOptions, }, });