Skip to content

Commit a0fa47e

Browse files
authored
Merge pull request #428 from muchenshou/develop
Add wallet.io support
2 parents f7df5a1 + de18258 commit a0fa47e

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

src/modules/select/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ function getModule(name: string): Promise<any> | undefined {
9797
return import('./wallets/mykey')
9898
case 'huobiwallet':
9999
return import('./wallets/huobiwallet')
100+
case 'wallet.io':
101+
return import('./wallets/wallet-io')
100102
case 'hyperpay':
101103
return import('./wallets/hyperpay')
102104
default:
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const walletIoIcon = `
2+
<svg width="40" height="40" viewBox="0 0 1025 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3+
<!-- Generator: Sketch 61 (89581) - https://sketch.com -->
4+
<title>io</title>
5+
<desc>Created with Sketch.</desc>
6+
<defs>
7+
<linearGradient x1="0%" y1="100%" x2="100%" y2="0%" id="linearGradient-1">
8+
<stop stop-color="#1550FF" offset="0%"></stop>
9+
<stop stop-color="#0D8DFF" offset="100%"></stop>
10+
</linearGradient>
11+
</defs>
12+
<g id="io" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" transform="translate(0.000000, 0.000000)">
13+
<g id="编组">
14+
<rect id="矩形" fill="url(#linearGradient-1)" x="0" y="0" width="1024" height="1024" rx="192"></rect>
15+
<g id="2" transform="translate(142.000000, 354.000000)" fill="#FFFFFF" fill-rule="nonzero">
16+
<path d="M731.739038,157.885431 L653.658027,240.742988 C643.041073,252.009426 625.301078,252.535937 614.03464,241.918982 C612.84708,240.799883 611.75951,239.579221 610.784322,238.270905 L529.136156,128.731487 C521.006704,117.824991 521.881341,102.656017 531.210479,92.7561767 L609.29149,9.89862053 C619.908444,-1.36781768 637.648439,-1.89432843 648.914877,8.72262585 C650.102437,9.84172546 651.190007,11.0623873 652.165195,12.3707028 L733.813361,121.910121 C741.942813,132.816618 741.068176,147.985591 731.739038,157.885431 Z" id="路径"></path>
17+
<path d="M586.491167,312.367718 L508.410156,395.225274 C497.793202,406.491713 480.053207,407.018223 468.786769,396.401269 C467.599209,395.282169 466.511639,394.061508 465.536451,392.753192 L268.220049,128.032931 C260.090597,117.126435 260.965235,101.957461 270.294372,92.0576207 L348.375384,9.20006454 C358.992338,-2.06637367 376.732333,-2.59288442 387.998771,8.02406986 C389.18633,9.14316947 390.2739,10.3638313 391.249089,11.6721468 L588.56549,276.392408 C596.694942,287.298904 595.820305,302.467878 586.491167,312.367718 Z" id="路径" opacity="0.75"></path>
18+
<path d="M586.345922,312.172858 L508.264911,395.030414 C497.647957,406.296852 479.907962,406.823363 468.641524,396.206409 C467.453965,395.087309 466.366395,393.866647 465.391206,392.558332 L369.686767,264.160976 L486.808283,139.874642 L588.420246,276.197548 C596.549698,287.104044 595.67506,302.273017 586.345922,312.172858 Z" id="路径"></path>
19+
<path d="M128.683329,11.9400119 L325.99973,276.660273 C334.129182,287.566769 333.254545,302.735743 323.925407,312.635583 L245.844396,395.493139 C235.227442,406.759578 217.487447,407.286088 206.221009,396.669134 C205.033449,395.550035 203.945879,394.329373 202.970691,393.021057 L5.65428933,128.300796 C-2.47516249,117.3943 -1.60052498,102.225326 7.72861266,92.3254858 L85.8096237,9.46792962 C96.426578,-1.79850858 114.166573,-2.32501933 125.433011,8.29193494 C126.620571,9.41103455 127.708141,10.6316964 128.683329,11.9400119 Z" id="路径" opacity="0.5"></path>
20+
<path d="M224.568875,140.58034 L326.180837,276.903246 C334.310289,287.809742 333.435651,302.978716 324.106514,312.878556 L246.025503,395.736112 C235.408548,407.002551 217.668554,407.529061 206.402115,396.912107 C205.214556,395.793008 204.126986,394.572346 203.151797,393.26403 L107.447358,264.866675 L224.568875,140.58034 Z" id="路径" opacity="0.5"></path>
21+
</g>
22+
</g>
23+
</g>
24+
</svg>
25+
`
26+
27+
export default walletIoIcon
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { mobileWalletInstallMessage } from '../content'
2+
import {
3+
WalletModule,
4+
Helpers,
5+
InjectedWithBalanceOptions
6+
} from '../../../interfaces'
7+
8+
import walletIoIcon from '../wallet-icons/icon-wallet-io'
9+
10+
function walletIoWallet(options: InjectedWithBalanceOptions): WalletModule {
11+
const { preferred, label, svg, rpcUrl } = options
12+
13+
return {
14+
name: label || 'wallet.io',
15+
svg: svg || walletIoIcon,
16+
wallet: async (helpers: Helpers) => {
17+
const { getProviderName, getAddress, getNetwork, getBalance } = helpers
18+
const walletIoProvider =
19+
(window as any).ethereum ||
20+
((window as any).web3 && (window as any).web3.currentProvider)
21+
22+
const isWalleIoWallet =
23+
getProviderName(walletIoProvider) === 'wallet.io'
24+
let createProvider
25+
26+
if (isWalleIoWallet && rpcUrl) {
27+
createProvider = (await import('./providerEngine')).default
28+
}
29+
30+
const provider = createProvider ? createProvider({ rpcUrl }) : null
31+
32+
let warned = false
33+
34+
return {
35+
provider: walletIoProvider,
36+
interface: isWalleIoWallet
37+
? {
38+
address: {
39+
get: () => getAddress(walletIoProvider)
40+
},
41+
network: {
42+
get: () => getNetwork(walletIoProvider)
43+
},
44+
balance: {
45+
get: async () => {
46+
if (!provider) {
47+
if (!warned) {
48+
console.warn(
49+
'The wallet.io Wallet provider does not allow rpc calls preventing Onboard.js from getting the balance. You can pass in a "rpcUrl" to the wallet.io Wallet initialization object to get the balance.'
50+
)
51+
warned = true
52+
}
53+
54+
return null
55+
}
56+
57+
const address = await getAddress(walletIoProvider)
58+
59+
return getBalance(provider, address)
60+
}
61+
},
62+
name: getProviderName(walletIoProvider)
63+
}
64+
: null
65+
}
66+
},
67+
type: 'injected',
68+
link: 'http://wallet.io/',
69+
installMessage: mobileWalletInstallMessage,
70+
mobile: true,
71+
preferred
72+
}
73+
}
74+
75+
export default walletIoWallet

src/utilities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ export function createLegacyProviderInterface(provider: any): WalletInterface {
163163
export function getProviderName(provider: any): string | undefined {
164164
if (!provider) return
165165

166+
if (provider.isWalletIO) {
167+
return 'wallet.io';
168+
}
169+
166170
if (provider.wallet === 'MEETONE') {
167171
return 'MEETONE'
168172
}

0 commit comments

Comments
 (0)