Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Trust Wallet connector option #242

Merged
merged 6 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading