Skip to content

Commit d8de4b4

Browse files
committed
feat: add desktop extension support for Binance Web3 Wallet
1 parent e10812a commit d8de4b4

File tree

8 files changed

+57
-62
lines changed

8 files changed

+57
-62
lines changed

.changeset/moody-shrimps-melt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@node-real/walletkit': minor
3+
---
4+
5+
feat: add desktop extension support for Binance Web3 Wallet

.claude/settings.local.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(/tmp/comparison.txt:*)",
5+
"Read(//tmp/**)",
6+
"WebFetch(domain:developers.binance.com)",
7+
"Bash(npm run:*)",
8+
"Bash(git stash:*)",
9+
"Bash(grep \"\"version\"\":*)",
10+
"Bash(npx tsc:*)"
11+
]
12+
}
13+
}

examples/nextjs/pages/_app.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import {
1010
WalletKitProvider,
1111
getDefaultConfig,
1212
} from '@node-real/walletkit';
13-
import { trustWallet, metaMask, walletConnect } from '@node-real/walletkit/wallets';
13+
import {
14+
binanceWeb3Wallet,
15+
trustWallet,
16+
metaMask,
17+
walletConnect,
18+
} from '@node-real/walletkit/wallets';
1419

1520
const config = createConfig(
1621
getDefaultConfig({
@@ -22,7 +27,7 @@ const config = createConfig(
2227
walletConnectProjectId: 'e68a1816d39726c2afabf05661a32767',
2328

2429
chains,
25-
connectors: [trustWallet(), metaMask(), walletConnect()],
30+
connectors: [binanceWeb3Wallet(), trustWallet(), metaMask(), walletConnect()],
2631
}),
2732
);
2833

examples/vite/src/App.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import {
88
WalletKitOptions,
99
SwitchNetworkModal,
1010
} from '@node-real/walletkit';
11-
import { trustWallet, metaMask, walletConnect } from '@node-real/walletkit/wallets';
11+
import {
12+
binanceWeb3Wallet,
13+
trustWallet,
14+
metaMask,
15+
walletConnect,
16+
} from '@node-real/walletkit/wallets';
1217

1318
const config = createConfig(
1419
getDefaultConfig({
@@ -20,7 +25,7 @@ const config = createConfig(
2025
walletConnectProjectId: 'e68a1816d39726c2afabf05661a32767',
2126

2227
chains,
23-
connectors: [trustWallet(), metaMask(), walletConnect()],
28+
connectors: [binanceWeb3Wallet(), trustWallet(), metaMask(), walletConnect()],
2429
}),
2530
);
2631

packages/walletkit/src/typings.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ declare global {
1212
tokenpocket: any;
1313
okexchain: any;
1414
bitkeep: any;
15+
binancew3w: any;
1516
}
1617
}
1718

packages/walletkit/src/wallets/binanceWeb3Wallet/connector.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

packages/walletkit/src/wallets/binanceWeb3Wallet/index.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { Chain } from 'wagmi';
22
import { PartialCustomProps, WalletProps } from '..';
33
import { BinanceWeb3WalletIcon, BinanceWeb3WalletTransparentIcon } from './icon';
44
import { hasInjectedProvider } from '../utils';
5-
import { BinanceWeb3WalletConnector } from './connector';
5+
import { CustomConnector } from '../custom/connector';
6+
import { isMobile } from '@/base/utils/mobile';
67

78
export const BINANCE_WEB3_WALLET_ID = 'binanceWeb3Wallet';
89
export const BINANCE_WEB3_WALLET_NAME = 'Binance Web3 Wallet';
@@ -21,13 +22,24 @@ export function binanceWeb3Wallet(props: PartialCustomProps = {}): WalletProps {
2122
default: 'https://www.binance.com/en/web3wallet',
2223
},
2324
spinnerColor: undefined,
24-
showQRCode: true,
25+
showQRCode: false,
2526
isInstalled: isBinanceWeb3Wallet,
2627
createConnector: (chains: Chain[]) => {
27-
return new BinanceWeb3WalletConnector({
28+
return new CustomConnector({
29+
id: BINANCE_WEB3_WALLET_ID,
2830
chains,
2931
options: {
32+
name: BINANCE_WEB3_WALLET_NAME,
3033
shimDisconnect: true,
34+
getProvider() {
35+
if (typeof window === 'undefined') return;
36+
37+
if (isMobile()) {
38+
return window.ethereum;
39+
}
40+
41+
return window.binancew3w?.ethereum;
42+
},
3143
...connectorOptions,
3244
},
3345
});
@@ -44,7 +56,8 @@ export function binanceWeb3Wallet(props: PartialCustomProps = {}): WalletProps {
4456
}
4557

4658
export function isBinanceWeb3Wallet() {
47-
return hasInjectedProvider('isBinance' as any);
59+
if (typeof window === 'undefined') return false;
60+
return !!window.binancew3w?.ethereum || hasInjectedProvider('isBinance' as any);
4861
}
4962

5063
const getDeepLink = (url: string) => {

website/src/pages/index.mdx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ import {
9696
WalletKitOptions,
9797
SwitchNetworkModal,
9898
} from '@node-real/walletkit';
99-
import { metaMask, trustWallet, walletConnect } from '@node-real/walletkit/wallets';
99+
import {
100+
binanceWeb3Wallet,
101+
metaMask,
102+
trustWallet,
103+
walletConnect,
104+
} from '@node-real/walletkit/wallets';
100105

101106
const config = createConfig(
102107
getDefaultConfig({
@@ -108,7 +113,7 @@ const config = createConfig(
108113
walletConnectProjectId: 'xxx',
109114

110115
chains,
111-
connectors: [trustWallet(), metaMask(), walletConnect()],
116+
connectors: [binanceWeb3Wallet(), trustWallet(), metaMask(), walletConnect()],
112117
}),
113118
);
114119

0 commit comments

Comments
 (0)