From d07166512e1ea5c1956781c498d7e5d761fcc9f2 Mon Sep 17 00:00:00 2001 From: Ivan Grachev Date: Fri, 6 May 2022 02:44:02 +0300 Subject: [PATCH] Add Tokenary (#415) --- packages/core/src/connectors/metaMask.ts | 5 +++-- packages/core/src/types/index.ts | 1 + packages/core/src/utils/getInjectedName.test.ts | 5 +++-- packages/core/src/utils/getInjectedName.ts | 5 +++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/core/src/connectors/metaMask.ts b/packages/core/src/connectors/metaMask.ts index 661296d951..a0ccaad99d 100644 --- a/packages/core/src/connectors/metaMask.ts +++ b/packages/core/src/connectors/metaMask.ts @@ -35,8 +35,9 @@ export class MetaMaskConnector extends InjectedConnector { #getReady(ethereum?: Ethereum) { const isMetaMask = !!ethereum?.isMetaMask - // Brave Wallet tries to make itself look like MetaMask - if (isMetaMask && !ethereum.isBraveWallet) return ethereum + // Some wallets (e.g. Brave Wallet) try to make themselves look like MetaMask + const notOtherWallet = !ethereum?.isBraveWallet && !ethereum?.isTokenary + if (isMetaMask && notOtherWallet) return ethereum } #findProvider(ethereum?: Ethereum) { diff --git a/packages/core/src/types/index.ts b/packages/core/src/types/index.ts index 80324c9826..b0c6213f87 100644 --- a/packages/core/src/types/index.ts +++ b/packages/core/src/types/index.ts @@ -63,6 +63,7 @@ declare global { isFrame?: true isMetaMask?: true isTally?: true + isTokenary?: true isTrust?: true } diff --git a/packages/core/src/utils/getInjectedName.test.ts b/packages/core/src/utils/getInjectedName.test.ts index d2e49dd4b8..0dfc9abef9 100644 --- a/packages/core/src/utils/getInjectedName.test.ts +++ b/packages/core/src/utils/getInjectedName.test.ts @@ -3,13 +3,14 @@ import { getInjectedName } from './getInjectedName' describe.each` ethereum | expected ${undefined} | ${'Injected'} - ${{ isBraveWallet: true, isMetaMask: true }} | ${'Brave Wallet'} - ${{ isMetaMask: true }} | ${'MetaMask'} ${{ isBraveWallet: true }} | ${'Brave Wallet'} + ${{ isBraveWallet: true, isMetaMask: true }} | ${'Brave Wallet'} ${{ isCoinbaseWallet: true }} | ${'Coinbase Wallet'} ${{ isFrame: true }} | ${'Frame'} ${{ isTally: true }} | ${'Tally'} + ${{ isTokenary: true, isMetaMask: true }} | ${'Tokenary'} ${{ isTrust: true }} | ${'Trust Wallet'} + ${{ isMetaMask: true }} | ${'MetaMask'} ${{ providers: [{ isMetaMask: true }, { isCoinbaseWallet: true }] }} | ${['MetaMask', 'Coinbase Wallet']} ${{ providers: [{ isMetaMask: true }, { isFooWallet: true }, {}] }} | ${['MetaMask', 'Unknown Wallet #1', 'Unknown Wallet #2']} ${{}} | ${'Injected'} diff --git a/packages/core/src/utils/getInjectedName.ts b/packages/core/src/utils/getInjectedName.ts index 1ac484e371..98264a62ab 100644 --- a/packages/core/src/utils/getInjectedName.ts +++ b/packages/core/src/utils/getInjectedName.ts @@ -2,16 +2,17 @@ export function getInjectedName(ethereum?: Window['ethereum']) { if (!ethereum) return 'Injected' const getName = (provider: Ethereum) => { - if (provider.isMetaMask && !provider.isBraveWallet) return 'MetaMask' if (provider.isBraveWallet) return 'Brave Wallet' if (provider.isCoinbaseWallet) return 'Coinbase Wallet' if (provider.isFrame) return 'Frame' if (provider.isTally) return 'Tally' + if (provider.isTokenary) return 'Tokenary' if (provider.isTrust) return 'Trust Wallet' + if (provider.isMetaMask) return 'MetaMask' } if (ethereum.providers?.length) { - // Deduplicated names using Set + // Deduplicate names using Set // Coinbase Wallet puts multiple providers in `ethereum.providers` const nameSet = new Set() let unknownCount = 1