Skip to content

Commit 3cc280f

Browse files
author
wanghao
committed
Add huobiwallet
1 parent 8a9f127 commit 3cc280f

File tree

5 files changed

+96
-1
lines changed

5 files changed

+96
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules
33
dist/
44
package-lock.json
55
.rpt2_cache
6-
.vscode
6+
.vscode
7+
*.patch

src/modules/select/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ function getModule(name: string): Promise<any> | undefined {
9494
return import('./wallets/unilogin')
9595
case 'mykey':
9696
return import('./wallets/mykey')
97+
case 'huobiwallet':
98+
return import('./wallets/huobiwallet')
9799
default:
98100
return
99101
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const huobiwalletIcon = `
2+
<svg id="图层_1" data-name="图层 1" xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 1024 1024">
3+
<defs>
4+
<style>.cls-1{fill:#2d65f8;}.cls-1,.cls-2{fill-rule:evenodd;}.cls-2{fill:#173fff;}.cls-3{fill:#fcfcff;}.cls-4{fill:#fff;}</style>
5+
</defs>
6+
<title>huobi wallet icon</title>
7+
<path class="cls-1" d="M292.28,0H552Q742.79,27,858.24,122.88T1024,392V731.72c0,101.63-10.58,138.48-30.45,175.64a207.13,207.13,0,0,1-86.19,86.19c-37.16,19.87-74,30.45-175.64,30.45H292.28c-101.63,0-138.48-10.58-175.64-30.45a207.13,207.13,0,0,1-86.19-86.19C10.58,870.2,0,833.35,0,731.72V292.28C0,190.65,10.58,153.8,30.45,116.64a207.13,207.13,0,0,1,86.19-86.19C153.8,10.58,190.65,0,292.28,0Z"/>
8+
<path class="cls-2" d="M993.55,116.64a207.13,207.13,0,0,0-86.19-86.19C870.21,10.58,833.35,0,731.72,0H552Q742.79,27,858.24,122.88T1024,392V292.28C1024,190.65,1013.42,153.8,993.55,116.64Z"/>
9+
<path class="cls-3" d="M591.8,382.71c0-97.43-48-181.13-84.48-208.41,0,0-2.78-1.53-2.59,2.3-3,188-100.19,239-153.65,307.63-123.27,158.45-8.6,332.23,108.14,364.18,65.35,18-15.06-31.95-25.4-136.86C421.21,584.73,591.8,487.81,591.8,382.71Z"/>
10+
<path class="cls-4" d="M643.64,445.69c-.78-.51-1.81-.9-2.53.32-2.07,23.74-26.56,74.42-57.67,121C478.07,725,538.08,801.1,571.91,842.18c19.44,23.74,0,0,49-24.25,60.52-36.26,99.8-98.95,105.62-168.62A242.5,242.5,0,0,0,643.64,445.69Z"/>
11+
</svg>`
12+
13+
export default huobiwalletIcon
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { mobileWalletInstallMessage } from '../content'
2+
import {
3+
WalletModule,
4+
Helpers,
5+
InjectedWithBalanceOptions
6+
} from '../../../interfaces'
7+
8+
import huobiwalletIcon from '../wallet-icons/icon-huobiwallet'
9+
10+
function huobiwallet(options: InjectedWithBalanceOptions): WalletModule {
11+
const { preferred, label, svg, rpcUrl } = options
12+
13+
return {
14+
name: label || 'Huobi Wallet',
15+
svg: svg || huobiwalletIcon,
16+
wallet: async (helpers: Helpers) => {
17+
const { getProviderName, getAddress, getNetwork, getBalance } = helpers
18+
const huobiwalletProvider =
19+
(window as any).ethereum ||
20+
((window as any).web3 && (window as any).web3.currentProvider)
21+
22+
const isHuobiWallet = getProviderName(huobiwalletProvider) === 'huobiwallet'
23+
let createProvider
24+
25+
if (isHuobiWallet && rpcUrl) {
26+
createProvider = (await import('./providerEngine')).default
27+
}
28+
29+
const provider = createProvider ? createProvider({ rpcUrl }) : null
30+
31+
let warned = false
32+
33+
return {
34+
provider: huobiwalletProvider,
35+
interface: isHuobiWallet
36+
? {
37+
address: {
38+
get: () => getAddress(huobiwalletProvider)
39+
},
40+
network: {
41+
get: () => getNetwork(huobiwalletProvider)
42+
},
43+
balance: {
44+
get: async () => {
45+
if (!provider) {
46+
if (!warned) {
47+
console.warn(
48+
'The Huobi Wallet provider does not allow rpc calls preventing Onboard.js from getting the balance. You can pass in a "rpcUrl" to the Huobi Wallet initialization object to get the balance.'
49+
)
50+
warned = true
51+
}
52+
53+
return null
54+
}
55+
56+
const address = await getAddress(huobiwalletProvider)
57+
58+
return getBalance(provider, address)
59+
}
60+
},
61+
name: getProviderName(huobiwalletProvider)
62+
}
63+
: null
64+
}
65+
},
66+
type: 'injected',
67+
link: 'https://www.huobiwallet.com',
68+
installMessage: mobileWalletInstallMessage,
69+
mobile: true,
70+
preferred
71+
}
72+
}
73+
74+
export default huobiwallet

src/utilities.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ export function getProviderName(provider: any): string | undefined {
215215
return 'MYKEY'
216216
}
217217

218+
if (provider.isHuobiWallet) {
219+
return 'huobiwallet'
220+
}
221+
222+
218223
if (provider.host && provider.host.indexOf('localhost') !== -1) {
219224
return 'localhost'
220225
}

0 commit comments

Comments
 (0)