Skip to content

Commit

Permalink
Merge pull request #1 from tian000/noah
Browse files Browse the repository at this point in the history
Noah
  • Loading branch information
nheingit authored Jan 31, 2023
2 parents a920c2e + d79fba5 commit ae948e4
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .changeset/funny-suns-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'example': patch
'@rainbow-me/rainbowkit': patch
'site': patch
---

Add Phantom wallet support
2 changes: 2 additions & 0 deletions examples/with-next/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
argentWallet,
trustWallet,
ledgerWallet,
phantomWallet,
} from '@rainbow-me/rainbowkit/wallets';
import { configureChains, createClient, WagmiConfig } from 'wagmi';
import { mainnet, polygon, optimism, arbitrum, goerli } from 'wagmi/chains';
Expand Down Expand Up @@ -43,6 +44,7 @@ const connectors = connectorsForWallets([
argentWallet({ chains }),
trustWallet({ chains }),
ledgerWallet({ chains }),
phantomWallet({ chains }),
],
},
]);
Expand Down
2 changes: 2 additions & 0 deletions packages/example/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
imTokenWallet,
ledgerWallet,
omniWallet,
phantomWallet,
trustWallet,
} from '@rainbow-me/rainbowkit/wallets';

Expand Down Expand Up @@ -106,6 +107,7 @@ const connectors = connectorsForWallets([
argentWallet({ chains }),
imTokenWallet({ chains }),
ledgerWallet({ chains }),
phantomWallet({ chains }),
omniWallet({ chains }),
trustWallet({ chains }),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactNode, useContext, useEffect } from 'react';
import React, { ReactNode, useContext, useEffect, useState } from 'react';
import { touchableStyles } from '../../css/touchableStyles';
import { useWindowSize } from '../../hooks/useWindowSize';
import { BrowserType, getBrowser, isSafari } from '../../utils/browsers';
Expand Down Expand Up @@ -171,7 +171,7 @@ export function ConnectDetail({
iconUrl,
name,
qrCode,
ready,
ready: wasReady,
showWalletConnectModal,
} = wallet;
const getDesktopDeepLink = wallet.desktop?.getUri;
Expand All @@ -181,6 +181,22 @@ export function ConnectDetail({
downloadUrls?.qrCode && downloadUrls?.browserExtension;
const hasQrCode = qrCode && qrCodeUri;

const [isReady, setIsReady] = useState<boolean>(false);

// Check on component mount if the wallet is ready.
useEffect(() => {
wallet.connector.getProvider().then(provider => {
const isReady = provider;
if (!wasReady && isReady) {
// If the wallet was not ready, but now is ready attempt to connect
reconnect(wallet);
}
setIsReady(isReady);
});
}, [wallet.connector, reconnect, wallet, wasReady]);

const ready = wasReady || isReady;

const secondaryAction: {
description: string;
label: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,17 @@ export function DesktopOptions({ onClose }: { onClose: () => void }) {

const connectToWallet = (wallet: WalletConnector) => {
setConnectionError(false);
if (wallet.ready) {
wallet?.connect?.()?.catch(() => {
setConnectionError(true);
});
wallet?.connect?.()?.catch(() => {
setConnectionError(true);
});

const getDesktopDeepLink = wallet.desktop?.getUri;
if (getDesktopDeepLink) {
// if desktop deep link, wait for uri
setTimeout(async () => {
const uri = await getDesktopDeepLink();
window.open(uri, safari ? '_blank' : '_self');
}, 0);
}
const getDesktopDeepLink = wallet.desktop?.getUri;
if (getDesktopDeepLink) {
// if desktop deep link, wait for uri
setTimeout(async () => {
const uri = await getDesktopDeepLink();
window.open(uri, safari ? '_blank' : '_self');
}, 0);
}
};

Expand Down
2 changes: 2 additions & 0 deletions packages/rainbowkit/src/wallets/walletConnectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { injectedWallet } from './injectedWallet/injectedWallet';
import { ledgerWallet } from './ledgerWallet/ledgerWallet';
import { metaMaskWallet } from './metaMaskWallet/metaMaskWallet';
import { omniWallet } from './omniWallet/omniWallet';
import { phantomWallet } from './phantomWallet/phantomWallet';
import { rainbowWallet } from './rainbowWallet/rainbowWallet';
import { trustWallet } from './trustWallet/trustWallet';
import { walletConnectWallet } from './walletConnectWallet/walletConnectWallet';
Expand All @@ -19,6 +20,7 @@ export {
ledgerWallet,
metaMaskWallet,
omniWallet,
phantomWallet,
rainbowWallet,
trustWallet,
walletConnectWallet,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { InjectedConnector } from 'wagmi/connectors/injected';
import { Chain } from '../../../components/RainbowKitProvider/RainbowKitChainContext';
import { Wallet } from '../../Wallet';

export interface PhantomWalletOptions {
chains: Chain[];
shimDisconnect?: boolean;
}

export const phantomWallet = ({
chains,
shimDisconnect,
}: PhantomWalletOptions): Wallet => {
return {
createConnector: () => {
const getProvider = () =>
typeof window !== 'undefined'
? ((window as any).phantom as any)?.ethereum
: undefined;

const connector = new InjectedConnector({
chains,
options: { getProvider, shimDisconnect },
});

return {
connector,
extension: {
instructions: {
steps: [
{
description:
'We recommend pinning Phantom to your taskbar for easier access to your wallet.',
step: 'install',
title: 'Install the Phantom extension',
},
{
description:
'Be sure to back up your wallet using a secure method. Never share your secret recovery phrase with anyone.',
step: 'create',
title: 'Create or Import a Wallet',
},
{
description:
'Once you set up your wallet, click below to refresh the browser and load up the extension.',
step: 'refresh',
title: 'Refresh your browser',
},
],
},
learnMoreUrl: 'https://help.phantom.app',
},
};
},
downloadUrls: {
android: 'https://play.google.com/store/apps/details?id=app.phantom',
browserExtension: 'https://phantom.app/download',
ios: 'https://apps.apple.com/app/phantom-solana-wallet/1598432977',
},
iconBackground: '#551BF9',
iconUrl: async () => (await import('./phantomWallet.svg')).default,
id: 'phantom',
installed:
(typeof window !== 'undefined' &&
!!((window as any).phantom as any)?.ethereum) ||
undefined,
name: 'Phantom',
};
};
2 changes: 2 additions & 0 deletions site/components/Provider/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
imTokenWallet,
ledgerWallet,
omniWallet,
phantomWallet,
trustWallet,
} from '@rainbow-me/rainbowkit/wallets';
import React from 'react';
Expand Down Expand Up @@ -38,6 +39,7 @@ const connectors = connectorsForWallets([
omniWallet({ chains }),
imTokenWallet({ chains }),
ledgerWallet({ chains }),
phantomWallet({ chains }),
],
},
]);
Expand Down
11 changes: 11 additions & 0 deletions site/data/docs/custom-wallet-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ omniWallet(options: {
});
```

#### Phantom

```tsx
import { phantomWallet } from '@rainbow-me/rainbowkit/wallets';

phantomWallet(options: {
chains: Chain[];
shimDisconnect?: boolean;
});
```

#### Rainbow

```tsx
Expand Down

0 comments on commit ae948e4

Please sign in to comment.