Skip to content

Commit fbb2648

Browse files
authored
Merge pull request #283 from node-real/feat/binance-web3-wallet-extension-support
feat(binanceWallet): add Solana and Tron chain support
2 parents f778f39 + e216b50 commit fbb2648

12 files changed

Lines changed: 217 additions & 61 deletions

File tree

.changeset/five-beds-begin.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@node-real/walletkit': minor
3+
---
4+
5+
feat(binanceWallet): add Solana and Tron chain support
6+

.claude/settings.local.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@
44
"Bash(pnpm install:*)",
55
"Bash(export:*)",
66
"Bash(source:*)",
7-
"Bash(find:*)"
7+
"Bash(find:*)",
8+
"Bash(grep:*)",
9+
"WebFetch(domain:developers.binance.com)",
10+
"WebSearch",
11+
"WebFetch(domain:binance-wallet.gitbook.io)",
12+
"WebFetch(domain:www.npmjs.com)",
13+
"WebFetch(domain:registry.npmjs.org)",
14+
"Bash(npm view:*)",
15+
"WebFetch(domain:raw.githubusercontent.com)",
16+
"Bash(git log:*)",
17+
"Bash(pnpm build:*)",
18+
"Bash(git status:*)"
819
]
920
}
1021
}

packages/walletkit/__dev__/App.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
walletConnect,
1515
} from '@/evm/index';
1616
import {
17+
binanceWallet as solanaBinanceWallet,
1718
trustWallet as solanaTrustWallet,
1819
phantomWallet as solanaPhantomWallet,
1920
defaultSolanaConfig,
@@ -22,7 +23,12 @@ import {
2223
import { bsc, mainnet, dfk } from 'viem/chains';
2324
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
2425
import { useAccount, useDisconnect } from 'wagmi';
25-
import { defaultTronConfig, tronLink, useTronWallet } from '@/tron/index';
26+
import {
27+
binanceWallet as tronBinanceWallet,
28+
defaultTronConfig,
29+
tronLink,
30+
useTronWallet,
31+
} from '@/tron/index';
2632
import { uxuyWallet } from '@/evm/wallets/uxuyWallet';
2733
import { useEvmSwitchChain } from '@/evm/hooks/useEvmSwitchChain';
2834
import { codexFieldWallet } from '@/evm/wallets/codexFieldWallet';
@@ -67,12 +73,12 @@ const config: WalletKitConfig = {
6773
solanaConfig: defaultSolanaConfig({
6874
autoConnect: true,
6975
rpcUrl: 'https://solana-rpc.debridge.finance',
70-
wallets: [solanaTrustWallet(), solanaPhantomWallet()],
76+
wallets: [solanaBinanceWallet(), solanaTrustWallet(), solanaPhantomWallet()],
7177
}),
7278
tronConfig: defaultTronConfig({
7379
autoConnect: true,
7480
initialChainId: '0xcd8690dc',
75-
wallets: [tronLink()],
81+
wallets: [tronBinanceWallet(), tronLink()],
7682
}),
7783
};
7884

packages/walletkit/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"@solana/web3.js": "^1",
6262
"@tronweb3/tronwallet-abstract-adapter": "^1",
6363
"@tronweb3/tronwallet-adapter-react-hooks": "^1",
64+
"@tronweb3/tronwallet-adapter-binance": "^1.0.2",
6465
"@tronweb3/tronwallet-adapter-tronlink": "^1.1.11",
6566
"@uxuycom/web3-tg-sdk": "^0.1.5",
6667
"buffer": "^6.0.3",
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Detect if running inside the Binance App in-app browser.
3+
* The Binance App sets window.isBinance = true.
4+
*/
5+
export function isInBinanceApp(): boolean {
6+
if (typeof window === 'undefined') return false;
7+
return Boolean(window.isBinance);
8+
}
9+
10+
/**
11+
* Detect if the Binance Web3 Wallet browser extension is installed.
12+
* The extension injects window.binancew3w.
13+
*/
14+
export function isBinanceExtensionInstalled(): boolean {
15+
if (typeof window === 'undefined') return false;
16+
return Boolean(window.binancew3w);
17+
}
18+
19+
/**
20+
* Returns true if any Binance wallet source is available.
21+
*/
22+
export function isBinanceInstalled(): boolean {
23+
return isInBinanceApp() || isBinanceExtensionInstalled();
24+
}
25+
26+
/**
27+
* Generate Binance App deep link for the current page.
28+
*/
29+
export function getBinanceAppLink(): string {
30+
const url = window.location.href;
31+
const base = 'bnc://app.binance.com/mp/app';
32+
const appId = 'yFK5FCqYprrXDiVFbhyRx7';
33+
const startPagePath = window.btoa('/pages/browser/index');
34+
const startPageQuery = window.btoa(`url=${url}`);
35+
const deeplink = `${base}?appId=${appId}&startPagePath=${startPagePath}&startPageQuery=${startPageQuery}`;
36+
const dp = window.btoa(deeplink);
37+
return `https://app.binance.com/en/download?_dp=${dp}`;
38+
}

packages/walletkit/src/evm/wallets/binanceWallet/index.tsx

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BinanceW3WParameters, getWagmiConnectorV2 } from '@binance/w3w-wagmi-connector-v2';
22
import { isMobile, isTMA } from '@/core/base/utils/mobile';
33
import { binanceWalletConfig } from '@/core/configs/binanceWallet';
4+
import { isBinanceInstalled, getBinanceAppLink } from '@/core/utils/binance';
45
import { EvmWallet } from '../types';
56
import { getEvmInjectedProvider } from '../../utils/getEvmInjectedProvider';
67
import { sleep } from '@/core/utils/common';
@@ -10,42 +11,22 @@ export interface BinanceWalletOptions extends Partial<EvmWallet> {
1011
connectorOptions?: BinanceW3WParameters;
1112
}
1213

13-
/**
14-
* Detect if running inside the Binance App in-app browser.
15-
* The Binance App sets window.isBinance = true.
16-
*/
17-
function isInBinanceApp(): boolean {
18-
if (typeof window === 'undefined') return false;
19-
return Boolean(window.isBinance);
20-
}
21-
22-
/**
23-
* Detect if the Binance Web3 Wallet browser extension is installed.
24-
* The extension injects window.binancew3w.
25-
*/
26-
function isBinanceExtensionInstalled(): boolean {
27-
if (typeof window === 'undefined') return false;
28-
return Boolean(window.binancew3w);
29-
}
30-
3114
/**
3215
* Get the Binance EVM provider.
3316
* Priority: window.ethereum.isBinance > window.binancew3w.ethereum
3417
*/
3518
function getBinanceProvider(): any {
3619
if (typeof window === 'undefined') return undefined;
37-
// Standard EIP-1193: injected by Binance App or extension via window.ethereum
3820
const injectedProvider = getEvmInjectedProvider('isBinance');
3921
if (injectedProvider) return injectedProvider;
40-
// Fallback: standalone provider from extension
4122
return window.binancew3w?.ethereum;
4223
}
4324

4425
/**
45-
* Returns true if any Binance wallet source is available.
26+
* Returns true if any Binance EVM wallet source is available.
4627
*/
47-
function isBinanceInstalled(): boolean {
48-
return isInBinanceApp() || isBinanceExtensionInstalled() || Boolean(getBinanceProvider());
28+
function isBinanceEvmInstalled(): boolean {
29+
return isBinanceInstalled() || Boolean(getBinanceProvider());
4930
}
5031

5132
export function binanceWallet(props: BinanceWalletOptions = {}): EvmWallet {
@@ -84,9 +65,9 @@ export function binanceWallet(props: BinanceWalletOptions = {}): EvmWallet {
8465
{
8566
platforms: ['browser-pc'],
8667
connectType: 'default' as const,
87-
isInstalled: isBinanceInstalled,
68+
isInstalled: isBinanceEvmInstalled,
8869
getCreateConnectorFn() {
89-
if (isBinanceInstalled()) {
70+
if (isBinanceEvmInstalled()) {
9071
return injected({
9172
shimDisconnect: true,
9273
target: {
@@ -109,16 +90,9 @@ export function binanceWallet(props: BinanceWalletOptions = {}): EvmWallet {
10990
{
11091
platforms: ['browser-android', 'browser-ios'],
11192
connectType: 'default' as const,
112-
isInstalled: isBinanceInstalled,
93+
isInstalled: isBinanceEvmInstalled,
11394
getAppLink() {
114-
const url = window.location.href;
115-
const base = 'bnc://app.binance.com/mp/app';
116-
const appId = 'yFK5FCqYprrXDiVFbhyRx7';
117-
const startPagePath = window.btoa('/pages/browser/index');
118-
const startPageQuery = window.btoa(`url=${url}`);
119-
const deeplink = `${base}?appId=${appId}&startPagePath=${startPagePath}&startPageQuery=${startPageQuery}`;
120-
const dp = window.btoa(deeplink);
121-
return `https://app.binance.com/en/download?_dp=${dp}`;
95+
return getBinanceAppLink();
12296
},
12397
getCreateConnectorFn() {
12498
let isReady = false;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { SolanaWallet } from '../types';
2+
import { binanceWalletConfig } from '@/core/configs/binanceWallet';
3+
import { isBinanceInstalled, getBinanceAppLink } from '@/core/utils/binance';
4+
5+
type BinanceWalletOptions = Partial<SolanaWallet>
6+
7+
export function binanceWallet(props: BinanceWalletOptions = {}): SolanaWallet {
8+
const { ...restProps } = props;
9+
10+
return {
11+
...binanceWalletConfig,
12+
id: 'solana:binanceWallet',
13+
walletType: 'solana',
14+
adapterName: 'Binance Wallet',
15+
behaviors: [
16+
{
17+
platforms: ['browser-android', 'browser-ios', 'browser-pc'],
18+
connectType: 'default',
19+
isInstalled() {
20+
return isBinanceInstalled();
21+
},
22+
getAppLink() {
23+
return getBinanceAppLink();
24+
},
25+
},
26+
],
27+
...restProps,
28+
};
29+
}

packages/walletkit/src/solana/wallets/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './types';
44
// wallets
55
export * from './trustWallet';
66
export * from './phantomWallet';
7+
export * from './binanceWallet';
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { BinanceWalletAdapter } from '@tronweb3/tronwallet-adapter-binance';
2+
import { TronWallet } from '../types';
3+
import { binanceWalletConfig } from '@/core/configs/binanceWallet';
4+
import { isBinanceInstalled, getBinanceAppLink } from '@/core/utils/binance';
5+
6+
interface BinanceWalletOptions extends Partial<TronWallet> {
7+
adapterOptions?: ConstructorParameters<typeof BinanceWalletAdapter>[0];
8+
}
9+
10+
export function binanceWallet(props: BinanceWalletOptions = {}): TronWallet {
11+
const { adapterOptions, ...restProps } = props;
12+
13+
return {
14+
...binanceWalletConfig,
15+
id: 'tron:binanceWallet',
16+
walletType: 'tron',
17+
adapterName: 'Binance Wallet',
18+
behaviors: [
19+
{
20+
platforms: ['browser-android', 'browser-ios', 'browser-pc'],
21+
connectType: 'default',
22+
isInstalled() {
23+
return isBinanceInstalled();
24+
},
25+
getAppLink() {
26+
return getBinanceAppLink();
27+
},
28+
getAdapter() {
29+
return new BinanceWalletAdapter(adapterOptions);
30+
},
31+
},
32+
],
33+
...restProps,
34+
};
35+
}

packages/walletkit/src/tron/wallets/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './types';
33

44
// wallets
55
export * from './tronLink';
6+
export * from './binanceWallet';

0 commit comments

Comments
 (0)