diff --git a/.changeset/gold-doors-check.md b/.changeset/gold-doors-check.md new file mode 100644 index 00000000..f6500031 --- /dev/null +++ b/.changeset/gold-doors-check.md @@ -0,0 +1,5 @@ +--- +"@node-real/walletkit": patch +--- + +Fixed binance web3 wallet disconnect after refresh page. diff --git a/.changeset/nervous-badgers-raise.md b/.changeset/nervous-badgers-raise.md new file mode 100644 index 00000000..69b22284 --- /dev/null +++ b/.changeset/nervous-badgers-raise.md @@ -0,0 +1,5 @@ +--- +"@node-real/walletkit": patch +--- + +Remove unused code diff --git a/.changeset/pre.json b/.changeset/pre.json new file mode 100644 index 00000000..52710ef6 --- /dev/null +++ b/.changeset/pre.json @@ -0,0 +1,14 @@ +{ + "mode": "pre", + "tag": "alpha", + "initialVersions": { + "example-nextjs": "0.0.1", + "example-vite": "0.0.1", + "@node-real/walletkit": "1.0.12", + "website": "0.0.1" + }, + "changesets": [ + "gold-doors-check", + "nervous-badgers-raise" + ] +} diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 28aae0eb..6976b5c8 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -4,6 +4,7 @@ on: branches: - main - alpha + - dev jobs: release: diff --git a/package.json b/package.json index 183f0573..d657e7e6 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "author": "node-real", "private": true, - "packageManager": "pnpm@8.9.2", + "packageManager": "pnpm@9.1.1", "description": "Toolkit for connecting wallets.", "license": "MIT", "scripts": { diff --git a/packages/walletkit/CHANGELOG.md b/packages/walletkit/CHANGELOG.md index f94d6641..c3107412 100644 --- a/packages/walletkit/CHANGELOG.md +++ b/packages/walletkit/CHANGELOG.md @@ -1,5 +1,12 @@ # @node-real/walletkit +## 1.0.13-alpha.0 + +### Patch Changes + +- 237726b: Fixed binance web3 wallet disconnect after refresh page. +- 8b9e4fe: Remove unused code + ## 1.0.12 ### Patch Changes diff --git a/packages/walletkit/package.json b/packages/walletkit/package.json index e9d0a7d1..8d66e929 100644 --- a/packages/walletkit/package.json +++ b/packages/walletkit/package.json @@ -1,6 +1,6 @@ { "name": "@node-real/walletkit", - "version": "1.0.12", + "version": "1.0.13-alpha.0", "author": "node-real", "private": false, "description": "WalletKit is a React component library for easily connecting a wallet to your dApp.", diff --git a/packages/walletkit/src/wallets/binanceWeb3Wallet/connector.ts b/packages/walletkit/src/wallets/binanceWeb3Wallet/connector.ts new file mode 100644 index 00000000..14a6f65c --- /dev/null +++ b/packages/walletkit/src/wallets/binanceWeb3Wallet/connector.ts @@ -0,0 +1,52 @@ +import { sleep } from '@/utils/common'; +import { Chain } from 'wagmi'; +import { InjectedConnector } from 'wagmi/connectors/injected'; +import { BINANCE_WEB3_WALLET_ID, BINANCE_WEB3_WALLET_NAME } 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') { + (window.ethereum as any)?.enable?.(); + } + + super({ + chains, + options, + }); + } + + public async getProvider() { + 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 57ae4fb7..232487ca 100644 --- a/packages/walletkit/src/wallets/binanceWeb3Wallet/index.tsx +++ b/packages/walletkit/src/wallets/binanceWeb3Wallet/index.tsx @@ -1,18 +1,18 @@ import { Chain } from 'wagmi'; import { PartialCustomProps, WalletProps } from '..'; -import { CustomConnector } from '../custom/connector'; import { BinanceWeb3WalletIcon, BinanceWeb3WalletTransparentIcon } from './icon'; -import { isMobile } from '@/base/utils/mobile'; import { hasInjectedProvider } from '../utils'; +import { BinanceWeb3WalletConnector } from './connector'; export const BINANCE_WEB3_WALLET_ID = 'binanceWeb3Wallet'; +export const BINANCE_WEB3_WALLET_NAME = 'Binance Web3 Wallet'; export function binanceWeb3Wallet(props: PartialCustomProps = {}): WalletProps { const { connectorOptions, ...restProps } = props; return { id: BINANCE_WEB3_WALLET_ID, - name: 'Binance Web3 Wallet', + name: BINANCE_WEB3_WALLET_NAME, logos: { default: , transparent: , @@ -24,19 +24,10 @@ export function binanceWeb3Wallet(props: PartialCustomProps = {}): WalletProps { showQRCode: true, isInstalled: isBinanceWeb3Wallet, createConnector: (chains: Chain[]) => { - return new CustomConnector({ - id: BINANCE_WEB3_WALLET_ID, + return new BinanceWeb3WalletConnector({ chains, options: { - name: 'Binance Web3 Wallet', shimDisconnect: true, - getProvider() { - if (typeof window === 'undefined') return; - - if (isMobile()) { - return window.ethereum; - } - }, ...connectorOptions, }, }); diff --git a/packages/walletkit/src/wallets/custom/connector.ts b/packages/walletkit/src/wallets/custom/connector.ts index f2eda2f7..631020b8 100644 --- a/packages/walletkit/src/wallets/custom/connector.ts +++ b/packages/walletkit/src/wallets/custom/connector.ts @@ -26,4 +26,8 @@ export class CustomConnector extends InjectedConnector { this.id = id; this.shimDisconnectKey = `${this.id}.shimDisconnect`; } + + public async getProvider() { + return this.options.getProvider(); + } } diff --git a/website/.env.example b/website/.env.example deleted file mode 100644 index ce359ce6..00000000 --- a/website/.env.example +++ /dev/null @@ -1,4 +0,0 @@ -# https://dashboard.particle.network -VITE_PARTICLE_APP_APP_ID= -VITE_PARTICLE_APP_PROJECT_ID= -VITE_PARTICLE_APP_CLIENT_KEY= \ No newline at end of file diff --git a/website/src/playground/index.tsx b/website/src/playground/index.tsx index 5f67fcbb..ecfe66ba 100644 --- a/website/src/playground/index.tsx +++ b/website/src/playground/index.tsx @@ -20,7 +20,7 @@ const config = createConfig( getDefaultConfig({ appName: 'WalletKit', chains, - autoConnect: false, + autoConnect: true, connectors: [ binanceWeb3Wallet(), bitgetWallet(),