Skip to content

Commit

Permalink
feat: Binance web3 wallet rename to binance wallet (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
wenty22 authored Jan 7, 2025
1 parent 6882cec commit 880c9b2
Show file tree
Hide file tree
Showing 16 changed files with 203 additions and 62 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-islands-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': patch
---

Binance web3 wallet rename to binance wallet
28 changes: 15 additions & 13 deletions examples/vite/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WalletKit Vite Example</title>
<script src="https://unpkg.com/vconsole/dist/vconsole.min.js"></script>
<script>
var vConsole = new window.VConsole();
</script>
</head>

<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WalletKit Vite Example</title>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>

</html>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
10 changes: 8 additions & 2 deletions examples/vite/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import {
WalletKitConfig,
WalletKitProvider,
} from '@node-real/walletkit';
import { defaultEvmConfig, metaMask, trustWallet, walletConnect } from '@node-real/walletkit/evm';
import {
defaultEvmConfig,
metaMask,
trustWallet,
binanceWallet,
walletConnect,
} from '@node-real/walletkit/evm';
import { mainnet } from 'viem/chains';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { useAccount, useDisconnect } from 'wagmi';
Expand All @@ -19,7 +25,7 @@ const config: WalletKitConfig = {
autoConnect: true,
initialChainId: 1,
walletConnectProjectId: 'e68a1816d39726c2afabf05661a32767',
wallets: [metaMask(), trustWallet(), walletConnect()],
wallets: [binanceWallet(), metaMask(), trustWallet(), walletConnect()],
chains: [mainnet] as any,
}),
};
Expand Down
1 change: 1 addition & 0 deletions examples/vite/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import react from '@vitejs/plugin-react';

// https://vitejs.dev/config/
export default defineConfig({
base: './',
plugins: [react()],
build: {
minify: false,
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"ci:version": "pnpm changeset version && cp README.md packages/walletkit/README.md",
"ci:publish": "pnpm changeset publish",
"ci:alpha-version": "pnpm ci:enter && pnpm ci:version",
"ci:stable-version": "pnpm ci:exit && pnpm ci:version"
"ci:stable-version": "pnpm ci:exit && pnpm ci:version",
"gh-pages": "pnpm build && pnpm --F example-vite build && gh-pages -d examples/vite/dist"
},
"devDependencies": {
"@changesets/cli": "^2.27.10",
Expand All @@ -30,6 +31,7 @@
"eslint-plugin-react-refresh": "^0.3.5",
"husky": "^8.0.3",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3"
"prettier": "^3.3.3",
"gh-pages": "~6.2.0"
}
}
4 changes: 2 additions & 2 deletions packages/walletkit/__dev__/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@/core/index';
import VConsole from 'vconsole';
import {
binanceWeb3Wallet,
binanceWallet,
bitgetWallet,
coinbaseWallet,
defaultEvmConfig,
Expand Down Expand Up @@ -54,7 +54,7 @@ const config: WalletKitConfig = {
trustWallet(),
bitgetWallet(),
coinbaseWallet(),
binanceWeb3Wallet(),
binanceWallet(),

tokenPocket(),
okxWallet(),
Expand Down
6 changes: 3 additions & 3 deletions packages/walletkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"tronweb": "~6.0.0"
},
"devDependencies": {
"@tanstack/react-query": "catalog:",
"@types/qrcode": "^1.5.5",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
Expand All @@ -75,11 +76,10 @@
"rollup-plugin-peer-deps-external": "^2.2.4",
"typescript": "^5.5.3",
"vconsole": "^3.15.1",
"viem": "catalog:",
"vite": "^4.5.3",
"vite-plugin-dts": "^3.9.1",
"vite-plugin-mkcert": "^1.17.6",
"wagmi": "catalog:",
"viem": "catalog:",
"@tanstack/react-query": "catalog:"
"wagmi": "catalog:"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const BinanceWeb3WalletTransparentIcon = (props: SVGIconProps) => {
return <BinanceWeb3WalletIcon width={40} height={40} {...props} />;
export const BinanceWalletTransparentIcon = (props: SVGIconProps) => {
return <BinanceWalletIcon width={40} height={40} {...props} />;
};

export const BinanceWeb3WalletIcon = (props: SVGIconProps) => {
export const BinanceWalletIcon = (props: SVGIconProps) => {
return (
<svg width="40" height="40" viewBox="0 0 68 68" fill="none" {...props}>
<path
Expand Down
14 changes: 14 additions & 0 deletions packages/walletkit/src/core/configs/binanceWallet/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { WalletConfig } from '../types';
import { BinanceWalletIcon, BinanceWalletTransparentIcon } from './icon';

export const binanceWalletConfig: WalletConfig = {
name: 'Binance Wallet',
logos: {
default: <BinanceWalletIcon />,
transparent: <BinanceWalletTransparentIcon />,
},
downloadUrls: {
default: 'https://www.binance.com/en/web3wallet',
},
spinnerColor: undefined,
};
14 changes: 0 additions & 14 deletions packages/walletkit/src/core/configs/binanceWeb3Wallet/index.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions packages/walletkit/src/evm/utils/evmCommonErrorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isIOS, isMobile } from '@/core/base/utils/mobile';
import { binanceWeb3Wallet, trustWallet } from '../wallets';
import { binanceWallet, trustWallet } from '../wallets';

export function evmCommonErrorHandler(props: { log: any; handler: any; error: any }) {
const { log, handler, error } = props;
Expand All @@ -23,7 +23,7 @@ export function evmCommonErrorHandler(props: { log: any; handler: any; error: an
description = undefined;
}

if (isMobile() && binanceWeb3Wallet().isInstalled()) {
if (isMobile() && binanceWallet().isInstalled()) {
if (
description?.includes('Request failed: The JSON sent is not a valid Request object.') ||
description?.includes('Adaptor not found: eip155')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { binanceWeb3WalletConfig } from '@/core/configs/binanceWeb3Wallet';
import { binanceWalletConfig } from '@/core/configs/binanceWallet';
import { EvmWallet, InjectedEvmWalletOptions } from '../types';
import { injected } from '../injected';
import { isMobile } from '@/core/base/utils/mobile';
import { sleep } from '@/core/utils/common';
import { getEvmInjectedProvider } from '../utils';

export function binanceWeb3Wallet(props: InjectedEvmWalletOptions = {}): EvmWallet {
export function binanceWallet(props: InjectedEvmWalletOptions = {}): EvmWallet {
const { connectorOptions, ...restProps } = props;

return {
...binanceWeb3WalletConfig,
id: 'binanceWeb3Wallet',
...binanceWalletConfig,
id: 'binanceWallet',
walletType: 'evm',
showQRCode: true,
isInstalled() {
Expand Down Expand Up @@ -38,11 +38,11 @@ export function binanceWeb3Wallet(props: InjectedEvmWalletOptions = {}): EvmWall
return injected({
shimDisconnect: true,
target: {
id: binanceWeb3Wallet().id,
name: binanceWeb3Wallet().name,
id: binanceWallet().id,
name: binanceWallet().name,
async provider() {
if (isMobile() && binanceWeb3Wallet().isInstalled() && !isReady) {
await sleep();
if (isMobile() && binanceWallet().isInstalled() && !isReady) {
await sleep(3000);
}
isReady = true;
return getProvider();
Expand All @@ -55,6 +55,14 @@ export function binanceWeb3Wallet(props: InjectedEvmWalletOptions = {}): EvmWall
};
}

// binance web3 wallet changes its name to `binance wallet`, retaining the previous wallet id
export function binanceWeb3Wallet(props: InjectedEvmWalletOptions = {}): EvmWallet {
return {
...binanceWallet(props),
id: 'binanceWeb3Wallet',
};
}

function getProvider() {
if (typeof window === 'undefined') return;
return getEvmInjectedProvider('isBinance');
Expand Down
2 changes: 1 addition & 1 deletion packages/walletkit/src/evm/wallets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export * from './trustWallet';
export * from './walletConnect';
export * from './okxWallet';
export * from './mathWallet';
export * from './binanceWeb3Wallet';
export * from './binanceWallet';
export * from './coinbaseWallet';
export * from './bitgetWallet';
export * from './safe';
Loading

0 comments on commit 880c9b2

Please sign in to comment.