|
1 | 1 | import { WalletInit } from '@web3-onboard/common'
|
2 | 2 |
|
3 |
| -function coinbaseWallet(options?: { darkMode?: boolean }): WalletInit { |
4 |
| - const { darkMode = false } = options || {} |
5 |
| - |
6 |
| - return () => { |
7 |
| - return { |
8 |
| - label: 'Coinbase', |
9 |
| - getIcon: async () => (await import('./icon.js')).default, |
10 |
| - getInterface: async ({ chains, appMetadata }) => { |
11 |
| - const [chain] = chains |
12 |
| - const { name, icon } = appMetadata || {} |
13 |
| - |
14 |
| - const { CoinbaseWalletSDK } = await import('@coinbase/wallet-sdk') |
15 |
| - |
16 |
| - const base64 = window.btoa(icon || '') |
17 |
| - const appLogoUrl = `data:image/svg+xml;base64,${base64}` |
18 |
| - |
19 |
| - const instance = new CoinbaseWalletSDK({ |
20 |
| - appName: name || '', |
21 |
| - appLogoUrl, |
22 |
| - darkMode |
23 |
| - }) |
24 |
| - |
25 |
| - const coinbaseWalletProvider = instance.makeWeb3Provider( |
26 |
| - chain.rpcUrl, |
27 |
| - parseInt(chain.id) |
28 |
| - ) |
29 |
| - |
30 |
| - // patch the chainChanged event |
31 |
| - const on = coinbaseWalletProvider.on.bind(coinbaseWalletProvider) |
32 |
| - coinbaseWalletProvider.on = (event, listener) => { |
33 |
| - on(event, val => { |
34 |
| - if (event === 'chainChanged') { |
35 |
| - listener(`0x${(val as number).toString(16)}`) |
36 |
| - return |
| 3 | +function coinbaseWallet({ |
| 4 | + darkMode = false |
| 5 | +}: { |
| 6 | + darkMode?: boolean |
| 7 | +}): WalletInit { |
| 8 | + return ({ device }) => |
| 9 | + device.type === 'mobile' |
| 10 | + ? { |
| 11 | + label: 'Coinbase', |
| 12 | + getIcon: async () => (await import('./icon.js')).default, |
| 13 | + getInterface: async ({ chains, appMetadata }) => { |
| 14 | + const [chain] = chains |
| 15 | + const { name, icon } = appMetadata || {} |
| 16 | + |
| 17 | + const { CoinbaseWalletSDK } = await import('@coinbase/wallet-sdk') |
| 18 | + |
| 19 | + const base64 = window.btoa(icon || '') |
| 20 | + const appLogoUrl = `data:image/svg+xml;base64,${base64}` |
| 21 | + |
| 22 | + const instance = new CoinbaseWalletSDK({ |
| 23 | + appName: name || '', |
| 24 | + appLogoUrl, |
| 25 | + darkMode |
| 26 | + }) |
| 27 | + |
| 28 | + const coinbaseWalletProvider = instance.makeWeb3Provider( |
| 29 | + chain.rpcUrl, |
| 30 | + parseInt(chain.id) |
| 31 | + ) |
| 32 | + |
| 33 | + // patch the chainChanged event |
| 34 | + const on = coinbaseWalletProvider.on.bind(coinbaseWalletProvider) |
| 35 | + coinbaseWalletProvider.on = (event, listener) => { |
| 36 | + on(event, val => { |
| 37 | + if (event === 'chainChanged') { |
| 38 | + listener(`0x${(val as number).toString(16)}`) |
| 39 | + return |
| 40 | + } |
| 41 | + |
| 42 | + listener(val) |
| 43 | + }) |
| 44 | + |
| 45 | + return coinbaseWalletProvider |
37 | 46 | }
|
38 | 47 |
|
39 |
| - listener(val) |
40 |
| - }) |
41 |
| - |
42 |
| - return coinbaseWalletProvider |
43 |
| - } |
44 |
| - |
45 |
| - return { |
46 |
| - provider: coinbaseWalletProvider, |
47 |
| - instance |
| 48 | + return { |
| 49 | + provider: coinbaseWalletProvider, |
| 50 | + instance |
| 51 | + } |
| 52 | + } |
48 | 53 | }
|
49 |
| - } |
50 |
| - } |
51 |
| - } |
| 54 | + : null |
52 | 55 | }
|
53 | 56 |
|
54 | 57 | export default coinbaseWallet
|
0 commit comments