Skip to content

Commit

Permalink
isTrust check + comment
Browse files Browse the repository at this point in the history
  • Loading branch information
lochie committed Jul 17, 2023
1 parent 5cb2be4 commit 678eef5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
12 changes: 7 additions & 5 deletions packages/connectkit/src/components/Pages/Connectors/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
19 changes: 18 additions & 1 deletion packages/connectkit/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '••••') => {
Expand Down Expand Up @@ -133,6 +140,8 @@ const isMetaMask = () => {

if (isPhantom()) return false;

if (isTrust()) return false;

return true;
};

Expand Down Expand Up @@ -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 = () => {
Expand Down

0 comments on commit 678eef5

Please sign in to comment.