From b1811852041a4aa5dab2dd80ca9857c4dc469dde Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 16 Jun 2023 10:00:39 +1000 Subject: [PATCH 1/4] Enable Trust Wallet connector option --- packages/connectkit/src/utils/index.ts | 16 ++++++++++++++-- .../connectkit/src/wallets/connectors/trust.tsx | 5 +++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/connectkit/src/utils/index.ts b/packages/connectkit/src/utils/index.ts index 7e240e10..733cacd2 100644 --- a/packages/connectkit/src/utils/index.ts +++ b/packages/connectkit/src/utils/index.ts @@ -2,6 +2,13 @@ import { detect } from 'detect-browser'; import React from 'react'; import supportedConnectors from '../constants/supportedConnectors'; +declare global { + interface Window { + trustWallet: any; + trustwallet: any; + } +} + const truncateRegex = /^(0x[a-zA-Z0-9]{4})[a-zA-Z0-9]+([a-zA-Z0-9]{4})$/; const truncateEthAddress = (address?: string, separator: string = '••••') => { @@ -128,7 +135,7 @@ const isDawn = () => { const isDawn = Boolean(ethereum.isDawn); if (isDawn) return true; -} +}; const isCoinbaseWallet = () => { if (typeof window === 'undefined') return false; @@ -150,7 +157,7 @@ const isFrame = () => { (ethereum?.providers && ethereum?.providers.find((provider) => provider.isFrame)) ); -} +}; const isPhantom = () => { if (typeof window === 'undefined') return false; @@ -191,6 +198,11 @@ export const isSafeConnector = (connectorId?: string) => connectorId === 'safe'; export const isInjectedConnector = (connectorId?: string) => connectorId === 'injected'; +export const isTrust = () => { + if (typeof window === 'undefined') return false; + return !!(window?.trustWallet?.isTrust || window?.trustwallet?.isTrust); +}; + export { nFormatter, truncateEthAddress, diff --git a/packages/connectkit/src/wallets/connectors/trust.tsx b/packages/connectkit/src/wallets/connectors/trust.tsx index 7a8add45..3b30d852 100644 --- a/packages/connectkit/src/wallets/connectors/trust.tsx +++ b/packages/connectkit/src/wallets/connectors/trust.tsx @@ -1,9 +1,9 @@ import { WalletProps } from './../wallet'; -import { isAndroid } from '../../utils'; +import { isAndroid, isTrust } from '../../utils'; import Logos from './../../assets/logos'; - export const trust = (): WalletProps => { + const isInstalled = isTrust(); return { id: 'trust', name: 'Trust Wallet', @@ -19,6 +19,7 @@ export const trust = (): WalletProps => { 'https://play.google.com/store/apps/details?id=com.wallet.crypto.trustapp', ios: 'https://apps.apple.com/app/trust-crypto-bitcoin-wallet/id1288339409', }, + installed: isInstalled, createUri: (uri: string) => { return isAndroid() ? uri From c7ca907bcce39d182758d04630516271d64633ef Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 20 Jun 2023 21:05:08 +1000 Subject: [PATCH 2/4] display trust wallet injected connector --- .../src/components/Pages/Connectors/index.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/connectkit/src/components/Pages/Connectors/index.tsx b/packages/connectkit/src/components/Pages/Connectors/index.tsx index b9e50e2d..7d211648 100644 --- a/packages/connectkit/src/components/Pages/Connectors/index.tsx +++ b/packages/connectkit/src/components/Pages/Connectors/index.tsx @@ -7,6 +7,7 @@ import { isWalletConnectConnector, isInjectedConnector, isMetaMaskConnector, + isTrust, } from './../../../utils'; import { useConnect } from '../../../hooks/useConnect'; @@ -78,15 +79,16 @@ const Wallets: React.FC = () => { * Some injected connectors pretend to be metamask, this helps avoid that issue. */ - const shouldShowInjectedConnector = () => { + const shouldShowInjectedConnector = (connector?: any) => { // Only display if an injected connector is detected const { ethereum } = window; const needsInjectedWalletFallback = - typeof window !== 'undefined' && - ethereum && - !isMetaMask() && - !isCoinbaseWallet(); + (typeof window !== 'undefined' && + ethereum && + !isMetaMask() && + !isCoinbaseWallet()) || + (connector && isTrust() && /trust wallet/i.test(connector?.name)); //!ethereum?.isBraveWallet; // TODO: Add this line when Brave is supported return needsInjectedWalletFallback; @@ -219,7 +221,7 @@ const Wallets: React.FC = () => { } if (isInjectedConnector(info.id)) { - if (!shouldShowInjectedConnector()) return null; + if (!shouldShowInjectedConnector(connector)) return null; const foundInjector = findInjectedConnectorInfo(connector.name); if (foundInjector) { From 5cb2be445e6bbbfb084d877d9e482a169619d42a Mon Sep 17 00:00:00 2001 From: Lochie Axon Date: Mon, 17 Jul 2023 23:31:53 +1000 Subject: [PATCH 3/4] update isTrust check --- .../src/components/Pages/Connectors/index.tsx | 13 ++++++------ packages/connectkit/src/utils/index.ts | 20 +++++++------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/packages/connectkit/src/components/Pages/Connectors/index.tsx b/packages/connectkit/src/components/Pages/Connectors/index.tsx index 381eae2d..ef82e9dd 100644 --- a/packages/connectkit/src/components/Pages/Connectors/index.tsx +++ b/packages/connectkit/src/components/Pages/Connectors/index.tsx @@ -79,16 +79,15 @@ const Wallets: React.FC = () => { * Some injected connectors pretend to be metamask, this helps avoid that issue. */ - const shouldShowInjectedConnector = (connector?: any) => { + const shouldShowInjectedConnector = () => { // Only display if an injected connector is detected const { ethereum } = window; const needsInjectedWalletFallback = - (typeof window !== 'undefined' && - ethereum && - !isMetaMask() && - !isCoinbaseWallet()) || - (connector && isTrust() && /trust wallet/i.test(connector?.name)); + typeof window !== 'undefined' && + ethereum && + !isMetaMask() && + !isCoinbaseWallet(); //!ethereum?.isBraveWallet; // TODO: Add this line when Brave is supported return needsInjectedWalletFallback; @@ -230,7 +229,7 @@ const Wallets: React.FC = () => { } if (isInjectedConnector(info.id)) { - if (!shouldShowInjectedConnector(connector)) return null; + if (!shouldShowInjectedConnector()) return null; const foundInjector = findInjectedConnectorInfo(connector.name); if (foundInjector) { diff --git a/packages/connectkit/src/utils/index.ts b/packages/connectkit/src/utils/index.ts index c7854ec8..2618f2f5 100644 --- a/packages/connectkit/src/utils/index.ts +++ b/packages/connectkit/src/utils/index.ts @@ -2,13 +2,6 @@ import { detect } from 'detect-browser'; import React from 'react'; import supportedConnectors from '../constants/supportedConnectors'; -declare global { - interface Window { - trustWallet: any; - trustwallet: any; - } -} - const truncateRegex = /^(0x[a-zA-Z0-9]{4})[a-zA-Z0-9]+([a-zA-Z0-9]{4})$/; const truncateEthAddress = (address?: string, separator: string = '••••') => { @@ -194,12 +187,17 @@ const isRabby = () => { ); }; +const isTrust = () => { + if (typeof window === 'undefined') return false; + return window?.ethereum?.isTrust; +}; + const isTokenPocket = () => { if (typeof window === 'undefined') return false; const { ethereum } = window; return Boolean(ethereum?.isTokenPocket); -} +}; type ReactChildArray = ReturnType; function flattenChildren(children: React.ReactNode): ReactChildArray { @@ -232,11 +230,6 @@ export const isSafeConnector = (connectorId?: string) => connectorId === 'safe'; export const isInjectedConnector = (connectorId?: string) => connectorId === 'injected'; -export const isTrust = () => { - if (typeof window === 'undefined') return false; - return !!(window?.trustWallet?.isTrust || window?.trustwallet?.isTrust); -}; - export { nFormatter, truncateEthAddress, @@ -253,6 +246,7 @@ export { isFrame, isPhantom, isRabby, + isTrust, isTokenPocket, flattenChildren, }; From 678eef5632cb1b5f494b6717ecb3914c9eca1934 Mon Sep 17 00:00:00 2001 From: Lochie Axon Date: Mon, 17 Jul 2023 23:55:48 +1000 Subject: [PATCH 4/4] isTrust check + comment --- .../src/components/Pages/Connectors/index.tsx | 12 +++++++----- packages/connectkit/src/utils/index.ts | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/packages/connectkit/src/components/Pages/Connectors/index.tsx b/packages/connectkit/src/components/Pages/Connectors/index.tsx index ef82e9dd..41990add 100644 --- a/packages/connectkit/src/components/Pages/Connectors/index.tsx +++ b/packages/connectkit/src/components/Pages/Connectors/index.tsx @@ -84,11 +84,13 @@ const Wallets: React.FC = () => { const { ethereum } = window; const needsInjectedWalletFallback = - typeof window !== 'undefined' && - ethereum && - !isMetaMask() && - !isCoinbaseWallet(); - //!ethereum?.isBraveWallet; // TODO: Add this line when Brave is supported + (typeof window !== 'undefined' && + ethereum && + !isMetaMask() && + !isCoinbaseWallet()) || + // Trust wallet is a special case that requires further debugging to fix. + // For now, we'll just show the injected wallet option if it's available. + isTrust(); return needsInjectedWalletFallback; }; diff --git a/packages/connectkit/src/utils/index.ts b/packages/connectkit/src/utils/index.ts index 2618f2f5..87a36ef1 100644 --- a/packages/connectkit/src/utils/index.ts +++ b/packages/connectkit/src/utils/index.ts @@ -2,6 +2,13 @@ import { detect } from 'detect-browser'; import React from 'react'; import supportedConnectors from '../constants/supportedConnectors'; +declare global { + interface Window { + trustWallet: any; + trustwallet: any; + } +} + const truncateRegex = /^(0x[a-zA-Z0-9]{4})[a-zA-Z0-9]+([a-zA-Z0-9]{4})$/; const truncateEthAddress = (address?: string, separator: string = '••••') => { @@ -133,6 +140,8 @@ const isMetaMask = () => { if (isPhantom()) return false; + if (isTrust()) return false; + return true; }; @@ -189,7 +198,15 @@ const isRabby = () => { const isTrust = () => { if (typeof window === 'undefined') return false; - return window?.ethereum?.isTrust; + const { ethereum } = window; + + return !!( + ethereum?.isTrust || + (ethereum?.providers && + ethereum?.providers.find((provider) => provider.isTrust)) || + window.trustWallet?.isTrust || + window.trustwallet?.isTrust + ); }; const isTokenPocket = () => {