Skip to content

Commit

Permalink
Enable Trust Wallet connector option (#242)
Browse files Browse the repository at this point in the history
* Enable Trust Wallet connector option

* display trust wallet injected connector

* update isTrust check

* isTrust check + comment

---------

Co-authored-by: chris <[email protected]>
Co-authored-by: Lochie Axon <[email protected]>
  • Loading branch information
3 people authored Jul 17, 2023
1 parent ffc1c15 commit 24ed760
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
13 changes: 8 additions & 5 deletions packages/connectkit/src/components/Pages/Connectors/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
isWalletConnectConnector,
isInjectedConnector,
isMetaMaskConnector,
isTrust,
} from './../../../utils';

import { useConnect } from '../../../hooks/useConnect';
Expand Down Expand Up @@ -83,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
25 changes: 24 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 @@ -187,12 +196,25 @@ const isRabby = () => {
);
};

const isTrust = () => {
if (typeof window === 'undefined') return false;
const { ethereum } = window;

return !!(
ethereum?.isTrust ||
(ethereum?.providers &&
ethereum?.providers.find((provider) => provider.isTrust)) ||
window.trustWallet?.isTrust ||
window.trustwallet?.isTrust
);
};

const isTokenPocket = () => {
if (typeof window === 'undefined') return false;
const { ethereum } = window;

return Boolean(ethereum?.isTokenPocket);
}
};

type ReactChildArray = ReturnType<typeof React.Children.toArray>;
function flattenChildren(children: React.ReactNode): ReactChildArray {
Expand Down Expand Up @@ -241,6 +263,7 @@ export {
isFrame,
isPhantom,
isRabby,
isTrust,
isTokenPocket,
flattenChildren,
};
5 changes: 3 additions & 2 deletions packages/connectkit/src/wallets/connectors/trust.tsx
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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
Expand Down

4 comments on commit 24ed760

@vercel
Copy link

@vercel vercel bot commented on 24ed760 Jul 17, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

connectkit-cra – ./

connectkit-cra.vercel.app
connectkit-cra-lfe.vercel.app
connectkit-cra-git-main-lfe.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 24ed760 Jul 17, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

connectkit-nextjs – ./

connectkit-nextjs-lfe.vercel.app
connectkit-nextjs-git-main-lfe.vercel.app
connectkit-nextjs.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 24ed760 Jul 17, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

connectkit-vite – ./

connectkit-vite.vercel.app
connectkit-vite-git-main-lfe.vercel.app
connectkit-vite-lfe.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 24ed760 Jul 17, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

connectkit-testbench – ./

connectkit-testbench-lfe.vercel.app
connectkit-testbench.vercel.app
connectkit-testbench-git-main-lfe.vercel.app

Please sign in to comment.