-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
66e8423
commit e089ab9
Showing
6 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 })], | ||
}, | ||
]); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...rainbowkit/src/wallets/walletConnectors/tokenPocketWallet/tokenPocketWallet.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
135 changes: 135 additions & 0 deletions
135
packages/rainbowkit/src/wallets/walletConnectors/tokenPocketWallet/tokenPocketWallet.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e089ab9
There was a problem hiding this comment.
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:
rainbowkit-example – ./
rainbowkit-example-rainbowdotme.vercel.app
rainbowkit-example-git-main-rainbowdotme.vercel.app
rainbowkit-example.vercel.app
e089ab9
There was a problem hiding this comment.
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:
rainbowkit-site – ./
rainbowkit.vercel.app
rainbowkit-site-git-main-rainbowdotme.vercel.app
rainbowkit.com
www.rainbowkit.com
rainbowkit-site-rainbowdotme.vercel.app