Skip to content

Commit 39d8edb

Browse files
committed
feat: integrate binance wallet
1 parent 65cf1a7 commit 39d8edb

File tree

17 files changed

+341
-1
lines changed

17 files changed

+341
-1
lines changed

global-wallets-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ declare global {
88
braveEthereum?: any;
99
braveSolana?: any;
1010
BinanceChain?: any;
11+
binancew3w?: any;
1112
clover?: any;
1213
clover_solana?: any;
1314
cosmostation?: any;

wallets/provider-all/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lint": "eslint \"**/*.{ts,tsx}\""
2222
},
2323
"dependencies": {
24+
"@rango-dev/provider-binance": "^0.0.1",
2425
"@rango-dev/provider-bitget": "^0.52.0",
2526
"@rango-dev/provider-braavos": "^0.49.0",
2627
"@rango-dev/provider-brave": "^0.57.0",
@@ -64,4 +65,4 @@
6465
"publishConfig": {
6566
"access": "public"
6667
}
67-
}
68+
}

wallets/provider-all/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Environments as WalletConnectEnvironments } from '@rango-dev/provi
44
import type { Provider } from '@rango-dev/wallets-core';
55
import type { ProviderInterface } from '@rango-dev/wallets-react';
66

7+
import { versions as binance } from '@rango-dev/provider-binance';
78
import { versions as bitget } from '@rango-dev/provider-bitget';
89
import * as braavos from '@rango-dev/provider-braavos';
910
import { versions as brave } from '@rango-dev/provider-brave';
@@ -110,6 +111,7 @@ export const allProviders = (
110111
trustwallet,
111112
enkrypt,
112113
bitget,
114+
binance,
113115
lazyProvider(legacyProviderImportsToVersionsInterface(xdefi)),
114116
xverse,
115117
lazyProvider(legacyProviderImportsToVersionsInterface(clover)),

wallets/provider-binance/CHANGELOG.md

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@rango-dev/provider-binance",
3+
"version": "0.0.1",
4+
"license": "MIT",
5+
"type": "module",
6+
"source": "./src/mod.ts",
7+
"main": "./dist/mod.js",
8+
"exports": {
9+
".": "./dist/mod.js"
10+
},
11+
"typings": "dist/mod.d.ts",
12+
"files": [
13+
"dist",
14+
"src"
15+
],
16+
"scripts": {
17+
"build": "node ../../scripts/build/command.mjs --path wallets/provider-binance --inputs src/mod.ts",
18+
"ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json",
19+
"clean": "rimraf dist",
20+
"format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
21+
"lint": "eslint \"**/*.{ts,tsx}\""
22+
},
23+
"dependencies": {
24+
"@rango-dev/signer-evm": "^0.40.0",
25+
"@rango-dev/wallets-core": "^0.54.0",
26+
"@rango-dev/wallets-shared": "^0.55.0",
27+
"rango-types": "^0.1.89"
28+
},
29+
"publishConfig": {
30+
"access": "public"
31+
}
32+
}

wallets/provider-binance/readme.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Binance Wallet
2+
Binance Wallet integration for hub.
3+
[Homepage](https://www.binance.com/en/binancewallet) | [Docs](https://developers.binance.com/docs/binance-w3w/introduction)
4+
5+
More about implementation status can be found [here](../readme.md).
6+
7+
## Implementation notes/limitations
8+
9+
### Group
10+
11+
#### EVM
12+
Binance Wallet supports following EVM chains:
13+
14+
- `ETHEREUM`
15+
- `OPTIMISM`
16+
- `LINEA`
17+
- `METIS`
18+
- `BLAST`
19+
- `CELO`
20+
- `FANTOM`
21+
- `MONAD`
22+
- `SONIC`
23+
- `BERACHAIN`
24+
- `BASE`
25+
- `ZETA_CHAIN`
26+
- `ARBITRUM`
27+
- `BSC`
28+
- `SCROLL`
29+
- `AVAX_CCHAIN`
30+
31+
### Feature
32+
33+
#### ❌ Auto Connect
34+
Binance Wallet does **not provide a functional eager-connect (silent connect) mechanism**.
35+
36+
All other supported features—connect, switch account, signing, and network handling—work without known issues.
37+
38+
---
39+
40+
More wallet information can be found in [readme.md](../readme.md).
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { type ProviderMetadata } from '@rango-dev/wallets-core';
2+
import { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
3+
import { type BlockchainMeta } from 'rango-types';
4+
5+
import getSigners from './signer.js';
6+
import { getInstanceOrThrow } from './utils.js';
7+
8+
export const WALLET_ID = 'binance';
9+
export const EVM_SUPPORTED_CHAINS = [
10+
LegacyNetworks.OPTIMISM,
11+
LegacyNetworks.ETHEREUM,
12+
LegacyNetworks.LINEA,
13+
LegacyNetworks.METIS,
14+
LegacyNetworks.BLAST,
15+
LegacyNetworks.CELO,
16+
LegacyNetworks.FANTOM,
17+
LegacyNetworks.MONAD,
18+
LegacyNetworks.SONIC,
19+
LegacyNetworks.BERACHAIN,
20+
LegacyNetworks.BASE,
21+
LegacyNetworks.ZETA_CHAIN,
22+
LegacyNetworks.ARBITRUM,
23+
LegacyNetworks.BSC,
24+
LegacyNetworks.SCROLL,
25+
LegacyNetworks.AVAX_CCHAIN,
26+
];
27+
28+
export const metadata: ProviderMetadata = {
29+
name: 'Binance Wallet',
30+
icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/binance/icon.svg',
31+
extensions: {
32+
chrome:
33+
'https://chromewebstore.google.com/detail/rabby-wallet/acmacodkjbdgmoleebolmdjonilkdbch',
34+
brave:
35+
'https://chromewebstore.google.com/detail/rabby-wallet/acmacodkjbdgmoleebolmdjonilkdbch',
36+
homepage: 'https://www.binance.com/binancewallet',
37+
},
38+
properties: [
39+
{
40+
name: 'namespaces',
41+
value: {
42+
selection: 'multiple',
43+
data: [
44+
{
45+
label: 'EVM',
46+
value: 'EVM',
47+
id: 'ETH',
48+
getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
49+
allBlockchains.filter((blockchainMeta) =>
50+
EVM_SUPPORTED_CHAINS.includes(
51+
blockchainMeta.name as LegacyNetworks
52+
)
53+
),
54+
},
55+
],
56+
},
57+
},
58+
{
59+
name: 'signers',
60+
value: { getSigners: async () => getSigners(getInstanceOrThrow()) },
61+
},
62+
],
63+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineVersions } from '@rango-dev/wallets-core/utils';
2+
3+
import { buildProvider } from './provider.js';
4+
5+
const versions = () =>
6+
defineVersions().version('1.0.0', buildProvider()).build();
7+
8+
export { versions };
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import type { EvmActions } from '@rango-dev/wallets-core/namespaces/evm';
2+
3+
import { NamespaceBuilder } from '@rango-dev/wallets-core';
4+
import {
5+
builders as commonBuilders,
6+
standardizeAndThrowError,
7+
} from '@rango-dev/wallets-core/namespaces/common';
8+
import {
9+
actions,
10+
builders,
11+
utils,
12+
} from '@rango-dev/wallets-core/namespaces/evm';
13+
14+
import { WALLET_ID } from '../constants.js';
15+
import { evmBinance, getEvmAccounts } from '../utils.js';
16+
17+
const [changeAccountSubscriber, changeAccountCleanup] = builders
18+
.changeAccountSubscriber(evmBinance)
19+
/*
20+
* Binance returns an array of connected accounts with the active one first.
21+
* Since we only need the active account, we take the first element as a workaround.
22+
*/
23+
.format(async (instance, accounts) => {
24+
const chainId = await instance.request({ method: 'eth_chainId' });
25+
return utils.formatAccountsToCAIP([accounts[0]], chainId);
26+
})
27+
.build();
28+
29+
const connect = builders
30+
.connect()
31+
.action(
32+
actions.connect(evmBinance, {
33+
getAccounts: getEvmAccounts,
34+
})
35+
)
36+
.before(changeAccountSubscriber)
37+
.or(changeAccountCleanup)
38+
.or(standardizeAndThrowError)
39+
.build();
40+
41+
const disconnect = commonBuilders
42+
.disconnect<EvmActions>()
43+
.after(changeAccountCleanup)
44+
.build();
45+
46+
const canSwitchNetwork = builders
47+
.canSwitchNetwork()
48+
.action(actions.canSwitchNetwork())
49+
.build();
50+
51+
const getChainId = builders
52+
.getChainId()
53+
.action(actions.getChainId(evmBinance))
54+
.build();
55+
56+
const evm = new NamespaceBuilder<EvmActions>('EVM', WALLET_ID)
57+
.action(connect)
58+
.action(disconnect)
59+
.action(canSwitchNetwork)
60+
.action(getChainId)
61+
.build();
62+
63+
export { evm };
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ProviderBuilder } from '@rango-dev/wallets-core';
2+
3+
import { metadata, WALLET_ID } from './constants.js';
4+
import { evm } from './namespaces/evm.js';
5+
import { binance as rabbyInstance } from './utils.js';
6+
7+
const buildProvider = () =>
8+
new ProviderBuilder(WALLET_ID)
9+
.init(function (context) {
10+
const [, setState] = context.state();
11+
if (rabbyInstance()) {
12+
setState('installed', true);
13+
console.debug('[binance-wallet] instance detected.', context);
14+
}
15+
})
16+
.config('metadata', metadata)
17+
.add('evm', evm)
18+
.build();
19+
20+
export { buildProvider };

0 commit comments

Comments
 (0)