From 78c9fc822718fdbb43797b338409e8cd666b4665 Mon Sep 17 00:00:00 2001 From: Wenty Li <105278450+wenty22@users.noreply.github.com> Date: Mon, 4 Dec 2023 12:38:42 +0800 Subject: [PATCH] fix: Fixed multiple wallets conficts resulting in undetectable issues. (#51) * docs: Add test result table to PULL_REQUEST_TEMPLATE * fix: fixed multiple wallet conflicts resulting in undetectable issues * chore: Add changeset log --- .changeset/honest-numbers-hug.md | 5 +++++ .github/PULL_REQUEST_TEMPLATE.md | 22 ++++++++++--------- .../src/wallets/coinbaseWallet/index.tsx | 2 +- .../walletkit/src/wallets/metaMask/index.tsx | 14 ++++++------ .../src/wallets/tokenPocket/index.tsx | 8 +++++-- 5 files changed, 31 insertions(+), 20 deletions(-) create mode 100644 .changeset/honest-numbers-hug.md diff --git a/.changeset/honest-numbers-hug.md b/.changeset/honest-numbers-hug.md new file mode 100644 index 00000000..12669d36 --- /dev/null +++ b/.changeset/honest-numbers-hug.md @@ -0,0 +1,5 @@ +--- +'@totejs/walletkit': patch +--- + +Fixed multiple wallets conficts resulting in undetectable issues. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index b2c9088c..15fd1e6f 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -33,17 +33,19 @@ ## For adding a new wallet +For more detail, please click [here](../CONTRIBUTING.md#notice-test-cases-for-adding-a-new-wallet) + |test case|support?|connected?|switch networks?|support testnet?| |-|-|-|-|-| -|PC, browser extension|[ ]|[ ]|[ ]|[ ]| -|Android, in system browser|[ ]|[ ]|[ ]|[ ]| -|Android, in wallet dapp browser|[ ]|[ ]|[ ]|[ ]| -|iOS, in system browser|[ ]|[ ]|[ ]|[ ]| -|iOS, in wallet dapp browser|[ ]|[ ]|[ ]|[ ]| -|WalletConnect, PC|[ ]|[ ]|[ ]|[ ]| -|WalletConnect, Android, in system browser|[ ]|[ ]|[ ]|[ ]| -|WalletConnect, Android, in wallet dapp browser|[ ]|[ ]|[ ]|[ ]| -|WalletConnect, iOS, in system browser|[ ]|[ ]|[ ]|[ ]| -|WalletConnect, iOS, in wallet dapp browser|[ ]|[ ]|[ ]|[ ]| +|PC, browser extension| ✔️ | ✔️ | ❌ | ❌ | +|Android, in system browser| | | | | +|Android, in wallet dapp browser| | | | | +|iOS, in system browser| | | | | +|iOS, in wallet dapp browser| | | | | +|WalletConnect, PC| | | | | +|WalletConnect, Android, in system browser| | | | | +|WalletConnect, Android, in wallet dapp browser| | | | | +|WalletConnect, iOS, in system browser| | | | | +|WalletConnect, iOS, in wallet dapp browser| | | | | diff --git a/packages/walletkit/src/wallets/coinbaseWallet/index.tsx b/packages/walletkit/src/wallets/coinbaseWallet/index.tsx index 76ea185a..d944b39f 100644 --- a/packages/walletkit/src/wallets/coinbaseWallet/index.tsx +++ b/packages/walletkit/src/wallets/coinbaseWallet/index.tsx @@ -56,5 +56,5 @@ export function coinbaseWallet(props: CoinbaseWalletProps = {}): WalletProps { export function isCoinbaseWallet() { if (typeof window === 'undefined') return false; - return hasInjectedProvider('isCoinbaseWallet'); + return hasInjectedProvider('isCoinbaseWallet') || !!window.coinbaseWalletExtension; } diff --git a/packages/walletkit/src/wallets/metaMask/index.tsx b/packages/walletkit/src/wallets/metaMask/index.tsx index e3bfb8c8..a1348078 100644 --- a/packages/walletkit/src/wallets/metaMask/index.tsx +++ b/packages/walletkit/src/wallets/metaMask/index.tsx @@ -1,7 +1,8 @@ import { Chain, Connector } from 'wagmi'; import { MetaMaskConnector } from 'wagmi/connectors/metaMask'; -import { PartialWalletProps, WalletProps, isTokenPocket } from '..'; +import { PartialWalletProps, WalletProps } from '..'; import { MetaMaskIcon, MetaMaskTransparentIcon } from './icon'; +import { getInjectedProvider, hasInjectedProvider } from '../utils'; export const META_MASK_ID = 'metaMask'; @@ -35,8 +36,11 @@ export function metaMask(props: MetaMaskProps = {}): WalletProps { options: { shimDisconnect: true, UNSTABLE_shimOnConnectSelectAccount: false, + getProvider() { + return getInjectedProvider('isMetaMask'); + }, ...connectorOptions, - }, + } as any, }); }, getDeepLink: () => { @@ -51,11 +55,7 @@ export function metaMask(props: MetaMaskProps = {}): WalletProps { } export function isMetaMask() { - if (typeof window === 'undefined') return false; - - if (isTokenPocket()) return false; - - return window?.ethereum?.isMetaMask; + return hasInjectedProvider('isMetaMask'); } export function isMetaMaskConnector(connector?: Connector) { diff --git a/packages/walletkit/src/wallets/tokenPocket/index.tsx b/packages/walletkit/src/wallets/tokenPocket/index.tsx index b5db07d9..dde6e139 100644 --- a/packages/walletkit/src/wallets/tokenPocket/index.tsx +++ b/packages/walletkit/src/wallets/tokenPocket/index.tsx @@ -32,7 +32,11 @@ export function tokenPocket(props: PartialCustomProps = {}): WalletProps { getProvider() { if (typeof window === 'undefined') return; - const provider = getInjectedProvider('isTokenPocket') ?? window.tokenpocket; + const provider = + getInjectedProvider('isTokenPocket') ?? + window.tokenpocket?.ethereum ?? + window.tokenpocket; + return provider; }, ...connectorOptions, @@ -55,5 +59,5 @@ export function tokenPocket(props: PartialCustomProps = {}): WalletProps { export function isTokenPocket() { if (typeof window === 'undefined') return false; - return hasInjectedProvider('isTokenPocket') || window.tokenpocket; + return hasInjectedProvider('isTokenPocket') || window.tokenpocket?.ethereum || window.tokenpocket; }