|
| 1 | +// Copied from https://github.com/celo-org/rainbowkit-celo/blob/a1b547840cedb48839fd8d0d72c81d9763c1f84c/packages/rainbowkit-celo/wallets/* |
| 2 | +// and modified to fix support for WalletConnect v2 |
| 3 | +import { Alfajores, Baklava, Celo } from '@celo/rainbowkit-celo/chains' |
| 4 | +import type { Chain, Wallet } from '@rainbow-me/rainbowkit' |
| 5 | +import { getWalletConnectConnector } from '@rainbow-me/rainbowkit' |
| 6 | +import { toast } from 'react-toastify' |
| 7 | +import { tryClipboardSet } from 'src/utils/clipboard' |
| 8 | +import { WalletConnectConnector } from 'wagmi/dist/connectors/walletConnect' |
| 9 | + |
| 10 | +async function getWalletConnectUri(connector: WalletConnectConnector): Promise<string> { |
| 11 | + const provider = await connector.getProvider() |
| 12 | + return new Promise((resolve) => provider.once('display_uri', resolve)) |
| 13 | +} |
| 14 | + |
| 15 | +// rainbowkit utils has it but doesn't export it :/ |
| 16 | +function isAndroid(): boolean { |
| 17 | + return typeof navigator !== 'undefined' && /android/i.test(navigator.userAgent) |
| 18 | +} |
| 19 | + |
| 20 | +interface WalletOptions { |
| 21 | + chains: Chain[] |
| 22 | + projectId: string |
| 23 | +} |
| 24 | + |
| 25 | +export const Valora = ({ |
| 26 | + chains = [Alfajores, Baklava, Celo], |
| 27 | + projectId, |
| 28 | +}: WalletOptions): Wallet => ({ |
| 29 | + id: 'valora', |
| 30 | + name: 'Valora', |
| 31 | + iconUrl: './wallets/valora.svg', |
| 32 | + iconBackground: '#FFF', |
| 33 | + downloadUrls: { |
| 34 | + android: 'https://play.google.com/store/apps/details?id=co.clabs.valora', |
| 35 | + ios: 'https://apps.apple.com/app/id1520414263?mt=8', |
| 36 | + qrCode: 'https://valoraapp.com/', |
| 37 | + }, |
| 38 | + createConnector: () => { |
| 39 | + const connector = getWalletConnectConnector({ |
| 40 | + chains, |
| 41 | + projectId, |
| 42 | + }) |
| 43 | + return { |
| 44 | + connector, |
| 45 | + mobile: { |
| 46 | + getUri: async () => { |
| 47 | + const uri = await getWalletConnectUri(connector) |
| 48 | + return isAndroid() |
| 49 | + ? uri |
| 50 | + : // ideally this would use the WalletConnect registry, but this will do for now |
| 51 | + `https://valoraapp.com/wc?uri=${encodeURIComponent(uri)}` |
| 52 | + }, |
| 53 | + }, |
| 54 | + qrCode: { |
| 55 | + getUri: () => getWalletConnectUri(connector), |
| 56 | + instructions: { |
| 57 | + learnMoreUrl: 'https://valoraapp.com/learn', |
| 58 | + steps: [ |
| 59 | + { |
| 60 | + description: |
| 61 | + 'The crypto wallet to buy, send, spend, earn, and collect NFTs on the Celo blockchain.', |
| 62 | + step: 'install', |
| 63 | + title: 'Open the Valora app', |
| 64 | + }, |
| 65 | + { |
| 66 | + description: |
| 67 | + 'After you scan, a connection prompt will appear for you to connect your wallet.', |
| 68 | + step: 'scan', |
| 69 | + title: 'Tap the scan button', |
| 70 | + }, |
| 71 | + ], |
| 72 | + }, |
| 73 | + }, |
| 74 | + } |
| 75 | + }, |
| 76 | +}) |
| 77 | + |
| 78 | +export const CeloTerminal = ({ |
| 79 | + chains = [Alfajores, Baklava, Celo], |
| 80 | + projectId, |
| 81 | +}: WalletOptions): Wallet => ({ |
| 82 | + id: 'celo-terminal', |
| 83 | + name: 'Celo Terminal', |
| 84 | + iconUrl: './wallets/celo-terminal.svg', |
| 85 | + iconBackground: '#FFF', |
| 86 | + createConnector: () => { |
| 87 | + const connector = getWalletConnectConnector({ |
| 88 | + chains, |
| 89 | + projectId, |
| 90 | + }) |
| 91 | + |
| 92 | + return { |
| 93 | + connector, |
| 94 | + qrCode: { |
| 95 | + getUri: async () => { |
| 96 | + const uri = await getWalletConnectUri(connector) |
| 97 | + await tryClipboardSet(uri) |
| 98 | + toast.success('WalletConnect URL copied to clipboard') |
| 99 | + return uri |
| 100 | + }, |
| 101 | + }, |
| 102 | + } |
| 103 | + }, |
| 104 | +}) |
| 105 | + |
| 106 | +export const CeloWallet = ({ |
| 107 | + chains = [Alfajores, Baklava, Celo], |
| 108 | + projectId, |
| 109 | +}: WalletOptions): Wallet => ({ |
| 110 | + id: 'celo-wallet', |
| 111 | + name: 'Celo Wallet', |
| 112 | + iconUrl: './wallets/celo-wallet.svg', |
| 113 | + iconBackground: '#FFF', |
| 114 | + createConnector: () => { |
| 115 | + const connector = getWalletConnectConnector({ |
| 116 | + chains, |
| 117 | + projectId, |
| 118 | + }) |
| 119 | + |
| 120 | + return { |
| 121 | + connector, |
| 122 | + mobile: { |
| 123 | + getUri: () => getWalletConnectUri(connector), |
| 124 | + }, |
| 125 | + desktop: { |
| 126 | + getUri: async () => { |
| 127 | + const uri = await getWalletConnectUri(connector) |
| 128 | + await tryClipboardSet(uri) |
| 129 | + toast.success('WalletConnect URL copied to clipboard') |
| 130 | + return `celowallet://wc?uri=${encodeURIComponent(uri)}` |
| 131 | + }, |
| 132 | + }, |
| 133 | + } |
| 134 | + }, |
| 135 | +}) |
0 commit comments