Skip to content

Commit

Permalink
feat: tokenPocket support (#1283)
Browse files Browse the repository at this point in the history
* feat: add TokenPocket wallet

* chore: changeset

* fix: tokenpocket example

* docs: fix name consistency

* fix: walletconnect v2 support

---------

Co-authored-by: Daniel Sinclair <d@niel.nyc>
  • Loading branch information
chendatony31 and DanielSinclair committed Jul 13, 2023
1 parent 66e8423 commit e089ab9
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .changeset/ten-teachers-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'@rainbow-me/rainbowkit': patch
---

TokenPocket Support

**Example usage**

```ts
import {
getDefaultWallets,
connectorsForWallets,
} from '@rainbow-me/rainbowkit';
import { tokenPocketWallet } from '@rainbow-me/rainbowkit/wallets';
const { wallets } = getDefaultWallets({ appName, projectId, chains });
const connectors = connectorsForWallets([
...wallets,
{
groupName: 'Other',
wallets: [tokenPocketWallet({ projectId, chains })],
},
]);
```
2 changes: 2 additions & 0 deletions packages/example/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
safeheronWallet,
tahoWallet,
talismanWallet,
tokenPocketWallet,
trustWallet,
xdefiWallet,
zerionWallet,
Expand Down Expand Up @@ -109,6 +110,7 @@ const connectors = connectorsForWallets([
safeheronWallet({ chains }),
tahoWallet({ chains }),
talismanWallet({ chains }),
tokenPocketWallet({ chains, projectId }),
trustWallet({ chains, projectId }),
xdefiWallet({ chains }),
zerionWallet({ chains, projectId }),
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 @@ -19,6 +19,7 @@ import { safeWallet } from './safeWallet/safeWallet';
import { safeheronWallet } from './safeheronWallet/safeheronWallet';
import { tahoWallet } from './tahoWallet/tahoWallet';
import { talismanWallet } from './talismanWallet/talismanWallet';
import { tokenPocketWallet } from './tokenPocketWallet/tokenPocketWallet';
import { trustWallet } from './trustWallet/trustWallet';
import { walletConnectWallet } from './walletConnectWallet/walletConnectWallet';
import { xdefiWallet } from './xdefiWallet/xdefiWallet';
Expand All @@ -45,6 +46,7 @@ export {
safeheronWallet,
tahoWallet,
talismanWallet,
tokenPocketWallet,
trustWallet,
okxWallet,
walletConnectWallet,
Expand Down
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,135 @@
/* eslint-disable sort-keys-fix/sort-keys-fix */
import type { InjectedConnectorOptions } from '@wagmi/core/connectors/injected';
import { InjectedConnector } from 'wagmi/connectors/injected';
import type { Chain } from '../../../components/RainbowKitProvider/RainbowKitChainContext';
import { getWalletConnectUri } from '../../../utils/getWalletConnectUri';
import { isMobile } from '../../../utils/isMobile';
import type { Wallet } from '../../Wallet';
import type {
WalletConnectConnectorOptions,
WalletConnectLegacyConnectorOptions,
} from '../../getWalletConnectConnector';
import { getWalletConnectConnector } from '../../getWalletConnectConnector';

export interface TokenPocketWalletLegacyOptions {
projectId?: string;
chains: Chain[];
walletConnectVersion: '1';
walletConnectOptions?: WalletConnectLegacyConnectorOptions;
}

export interface TokenPocketWalletOptions {
projectId: string;
chains: Chain[];
walletConnectVersion?: '2';
walletConnectOptions?: WalletConnectConnectorOptions;
}

export const tokenPocketWallet = ({
chains,
projectId,
walletConnectOptions,
walletConnectVersion = '2',
}: (TokenPocketWalletLegacyOptions | TokenPocketWalletOptions) &
InjectedConnectorOptions): Wallet => {
const isTokenPocketInjected =
typeof window !== 'undefined' && window.ethereum?.isTokenPocket === true;

const shouldUseWalletConnect = !isTokenPocketInjected;

return {
id: 'tokenPocket',
name: 'TokenPocket',
iconUrl: async () => (await import('./tokenPocketWallet.svg')).default,
iconBackground: '#2980FE',
installed: !shouldUseWalletConnect ? isTokenPocketInjected : undefined,
downloadUrls: {
chrome:
'https://chrome.google.com/webstore/detail/tokenpocket/mfgccjchihfkkindfppnaooecgfneiii',
browserExtension: 'https://extension.tokenpocket.pro/',
android:
'https://play.google.com/store/apps/details?id=vip.mytokenpocket',
ios: 'https://apps.apple.com/us/app/tp-global-wallet/id6444625622',
qrCode: 'https://tokenpocket.pro/en/download/app',
mobile: 'https://tokenpocket.pro/en/download/app',
},
createConnector: () => {
const connector = shouldUseWalletConnect
? getWalletConnectConnector({
chains,
projectId,
options: walletConnectOptions,
version: walletConnectVersion,
})
: new InjectedConnector({ chains });

const getUri = async () => {
const uri = await getWalletConnectUri(connector, walletConnectVersion);
return isMobile()
? `tpoutside://wc?uri=${encodeURIComponent(uri)}`
: uri;
};

return {
connector,
mobile: {
getUri: shouldUseWalletConnect ? getUri : undefined,
},
qrCode: shouldUseWalletConnect
? {
getUri,
instructions: {
learnMoreUrl: 'https://help.tokenpocket.pro/en/',
steps: [
{
description:
'We recommend putting TokenPocket on your home screen for quicker access.',
step: 'install',
title: 'Open the TokenPocket app',
},
{
description:
'Be sure to back up your wallet using a secure method. Never share your secret phrase with anyone.',
step: 'create',
title: 'Create or Import a Wallet',
},
{
description:
'After you scan, a connection prompt will appear for you to connect your wallet.',
step: 'scan',
title: 'Tap the scan button',
},
],
},
}
: undefined,
extension: {
instructions: {
learnMoreUrl:
'https://help.tokenpocket.pro/en/extension-wallet/faq/installation-tutorial',
steps: [
{
description:
'We recommend pinning TokenPocket to your taskbar for quicker access to your wallet.',
step: 'install',
title: 'Install the TokenPocket extension',
},
{
description:
'Be sure to back up your wallet using a secure method. Never share your secret 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',
},
],
},
},
};
},
};
};
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 @@ -324,6 +324,17 @@ talismanWallet(options: {
});
```

#### TokenPocket

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

tokenPocketWallet(options: {
projectId: string;
chains: Chain[];
});
```

#### Trust Wallet

```tsx
Expand Down

2 comments on commit e089ab9

@vercel
Copy link

@vercel vercel bot commented on e089ab9 Jul 13, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on e089ab9 Jul 13, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.