Skip to content

Commit

Permalink
feat: add support for trust wallet browser extension (#1250)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm authored Nov 7, 2022
1 parent 696d39e commit ce2e0f4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 27 deletions.
6 changes: 6 additions & 0 deletions .changeset/chilled-dogs-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@wagmi/core': patch
'wagmi': patch
---

Added support for Trust Wallet browser extension.
6 changes: 3 additions & 3 deletions packages/core/src/connectors/metaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ export class MetaMaskConnector extends InjectedConnector {
// Brave tries to make itself look like MetaMask
// Could also try RPC `web3_clientVersion` if following is unreliable
if (ethereum.isBraveWallet && !ethereum._events && !ethereum._state) return
if (ethereum.isTokenPocket) return
if (ethereum.isTokenary) return
if (ethereum.isAvalanche) return
if (ethereum.isPortal) return
if (ethereum.isKuCoinWallet) return
if (ethereum.isPortal) return
if (ethereum.isTokenPocket) return
if (ethereum.isTokenary) return
return ethereum
}

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/connectors/walletConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import { Connector } from './base'
* - imToken (token.im)
* - MetaMask (metamask.io)
* - Rainbow (rainbow.me)
* - Trust Wallet (trustwallet.com)
*/
const switchChainAllowedRegex = /(imtoken|metamask|rainbow)/i
const switchChainAllowedRegex = /(imtoken|metamask|rainbow|trust wallet)/i

type WalletConnectOptions = ConstructorParameters<
typeof WalletConnectProvider
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,13 @@ type WatchAssetParams = {
}

type InjectedProviderFlags = {
isAvalanche?: true
isBitKeep?: true
isBraveWallet?: true
isCoinbaseWallet?: true
isExodus?: true
isFrame?: true
isKuCoinWallet?: true
isMathWallet?: true
isMetaMask?: true
isOneInchAndroidWallet?: true
Expand All @@ -173,8 +175,7 @@ type InjectedProviderFlags = {
isTokenPocket?: true
isTokenary?: true
isTrust?: true
isAvalanche?: true
isKuCoinWallet?: true
isTrustWallet?: true
}

type InjectedProviders = InjectedProviderFlags & {
Expand Down
35 changes: 18 additions & 17 deletions packages/core/src/utils/getInjectedName.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { getInjectedName } from './getInjectedName'

describe.each([
{ ethereum: undefined, expected: 'Injected' },
{ ethereum: { isAvalanche: true }, expected: 'Core Wallet' },
{
ethereum: { isAvalanche: true, isMetaMask: true },
expected: 'Core Wallet',
},
{ ethereum: { isBitKeep: true }, expected: 'BitKeep' },
{ ethereum: { isBraveWallet: true }, expected: 'Brave Wallet' },
{
Expand All @@ -13,20 +18,26 @@ describe.each([
{ ethereum: { isCoinbaseWallet: true }, expected: 'Coinbase Wallet' },
{ ethereum: { isExodus: true }, expected: 'Exodus' },
{ ethereum: { isFrame: true }, expected: 'Frame' },
{ ethereum: { isTally: true }, expected: 'Tally' },
{ ethereum: { isKuCoinWallet: true }, expected: 'KuCoin Wallet' },
{
ethereum: { isTokenPocket: true, isMetaMask: true },
expected: 'TokenPocket',
ethereum: { isKuCoinWallet: true, isMetaMask: true },
expected: 'KuCoin Wallet',
},
{
ethereum: { isMathWallet: true, isMetaMask: true },
expected: 'MathWallet',
},
{ ethereum: { isTokenary: true, isMetaMask: true }, expected: 'Tokenary' },
{ ethereum: { isTrust: true }, expected: 'Trust Wallet' },
{ ethereum: { isOneInchIOSWallet: true }, expected: '1inch Wallet' },
{ ethereum: { isOneInchAndroidWallet: true }, expected: '1inch Wallet' },
{ ethereum: { isPortal: true }, expected: 'Ripio Portal' },
{ ethereum: { isTally: true }, expected: 'Tally' },
{
ethereum: { isMathWallet: true, isMetaMask: true },
expected: 'MathWallet',
ethereum: { isTokenPocket: true, isMetaMask: true },
expected: 'TokenPocket',
},
{ ethereum: { isTokenary: true, isMetaMask: true }, expected: 'Tokenary' },
{ ethereum: { isTrust: true }, expected: 'Trust Wallet' },
{ ethereum: { isTrustWallet: true }, expected: 'Trust Wallet' },
{ ethereum: { isMetaMask: true }, expected: 'MetaMask' },
{
ethereum: { providers: [{ isMetaMask: true }, { isCoinbaseWallet: true }] },
Expand All @@ -47,16 +58,6 @@ describe.each([
expected: ['MetaMask', 'Unknown Wallet #1', 'Unknown Wallet #2'],
},
{ ethereum: {}, expected: 'Injected' },
{ ethereum: { isAvalanche: true }, expected: 'Core Wallet' },
{
ethereum: { isAvalanche: true, isMetaMask: true },
expected: 'Core Wallet',
},
{ ethereum: { isKuCoinWallet: true }, expected: 'KuCoin Wallet' },
{
ethereum: { isKuCoinWallet: true, isMetaMask: true },
expected: 'KuCoin Wallet',
},
])('getInjectedName($ethereum)', ({ ethereum, expected }) => {
it(`returns ${expected}`, () => {
expect(getInjectedName(<any>ethereum)).toEqual(expected)
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/utils/getInjectedName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ export function getInjectedName(ethereum?: Ethereum) {
if (!ethereum) return 'Injected'

const getName = (provider: Ethereum) => {
if (provider.isKuCoinWallet) return 'KuCoin Wallet'
if (provider.isAvalanche) return 'Core Wallet'
if (provider.isBitKeep) return 'BitKeep'
if (provider.isBraveWallet) return 'Brave Wallet'
if (provider.isCoinbaseWallet) return 'Coinbase Wallet'
if (provider.isExodus) return 'Exodus'
if (provider.isFrame) return 'Frame'
if (provider.isKuCoinWallet) return 'KuCoin Wallet'
if (provider.isMathWallet) return 'MathWallet'
if (provider.isOneInchIOSWallet || provider.isOneInchAndroidWallet)
return '1inch Wallet'
if (provider.isOpera) return 'Opera'
if (provider.isPortal) return 'Ripio Portal'
if (provider.isTally) return 'Tally'
if (provider.isTokenPocket) return 'TokenPocket'
if (provider.isTokenary) return 'Tokenary'
if (provider.isTrust) return 'Trust Wallet'
if (provider.isOneInchIOSWallet || provider.isOneInchAndroidWallet)
return '1inch Wallet'
if (provider.isTrust || provider.isTrustWallet) return 'Trust Wallet'
if (provider.isMetaMask) return 'MetaMask'
}

Expand Down

1 comment on commit ce2e0f4

@vercel
Copy link

@vercel vercel bot commented on ce2e0f4 Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.