Skip to content

Commit d1987fe

Browse files
authored
Feature: WalletLink (#344)
* Initial implementation * Remove commented out code * Update interface * Modify interface * Update interfaces * Remove from default wallets Closes #345
1 parent ce6443a commit d1987fe

File tree

9 files changed

+156
-8
lines changed

9 files changed

+156
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"regenerator-runtime": "^0.13.3",
6464
"squarelink": "^1.1.4",
6565
"trezor-connect": "^8.1.2",
66+
"walletlink": "^2.0.2",
6667
"web3-provider-engine": "^15.0.4"
6768
},
6869
"scripts": {

rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export default {
6464
'squarelink',
6565
'authereum',
6666
'@toruslabs/torus-embed',
67+
'walletlink',
6768
'@unilogin/provider',
6869
'regenerator-runtime/runtime',
6970
'trezor-connect',

src/interfaces.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export interface TorusOptions extends CommonWalletOptions {
198198
showTorusButton?: boolean
199199
buttonPosition?: 'top-left' | 'top-right' | 'bottom-right' | 'bottom-left'
200200
enableLogging?: boolean
201-
enabledVerifiers: TorusVerifierStatus
201+
enabledVerifiers?: TorusVerifierStatus
202202
}
203203

204204
interface TorusVerifierStatus {
@@ -213,6 +213,12 @@ export interface AuthereumOptions extends CommonWalletOptions {
213213
disableNotifications?: boolean
214214
}
215215

216+
export interface WalletLinkOptions extends CommonWalletOptions {
217+
appName: string
218+
appLogoUrl?: string
219+
rpcUrl: string
220+
}
221+
216222
export interface ImTokenOptions extends CommonWalletOptions {
217223
rpcUrl?: string
218224
}
@@ -239,6 +245,7 @@ export type AllWalletInitOptions = CommonWalletOptions &
239245
TrezorOptions &
240246
AuthereumOptions &
241247
LedgerOptions &
248+
WalletLinkOptions &
242249
ImTokenOptions &
243250
TrustWalletOptions & { networkId: number }
244251

src/modules/select/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { WalletModule, WalletInitOptions } from '../../interfaces'
22
import { isWalletInit } from '../../validation'
33

4+
// wallets that qualify for default wallets need to have no
5+
// init parameters that are required
46
const defaultWalletNames = [
57
'metamask',
68
'dapper',
@@ -82,6 +84,8 @@ function getModule(name: string): Promise<any> | undefined {
8284
return import('./wallets/trezor')
8385
case 'ledger':
8486
return import('./wallets/ledger')
87+
case 'walletLink':
88+
return import('./wallets/wallet-link')
8589
case 'imToken':
8690
return import('./wallets/imtoken')
8791
case 'unilogin':
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const coinbaseIcon = `
2+
<svg width="40" height="40" viewBox="0 0 383 383" fill="none" xmlns="http://www.w3.org/2000/svg">
3+
<g clip-path="url(#clip0)">
4+
<g filter="url(#filter0_dd)">
5+
<path d="M0.998047 0.572266L382.78 0.572266V382.354H0.998047L0.998047 0.572266Z" fill="url(#paint0_linear)"/>
6+
<path fill-rule="evenodd" clip-rule="evenodd" d="M59.1074 191.572C59.1074 264.966 118.605 324.463 191.998 324.463C265.392 324.463 324.889 264.966 324.889 191.572C324.889 118.179 265.392 58.6816 191.998 58.6816C118.605 58.6816 59.1074 118.179 59.1074 191.572ZM158.037 148.752C153.144 148.752 149.178 152.718 149.178 157.611V225.533C149.178 230.426 153.144 234.393 158.037 234.393H225.959C230.852 234.393 234.818 230.426 234.818 225.533V157.611C234.818 152.718 230.852 148.752 225.959 148.752H158.037Z" fill="white"/>
7+
</g>
8+
</g>
9+
<defs>
10+
<filter id="filter0_dd" x="-23.002" y="-7.42773" width="429.782" height="429.782" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
11+
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
12+
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"/>
13+
<feOffset dy="16"/>
14+
<feGaussianBlur stdDeviation="12"/>
15+
<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.06 0"/>
16+
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow"/>
17+
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"/>
18+
<feOffset/>
19+
<feGaussianBlur stdDeviation="4"/>
20+
<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.04 0"/>
21+
<feBlend mode="normal" in2="effect1_dropShadow" result="effect2_dropShadow"/>
22+
<feBlend mode="normal" in="SourceGraphic" in2="effect2_dropShadow" result="shape"/>
23+
</filter>
24+
<linearGradient id="paint0_linear" x1="191.889" y1="0.572266" x2="191.889" y2="382.354" gradientUnits="userSpaceOnUse">
25+
<stop stop-color="#2E66F8"/>
26+
<stop offset="1" stop-color="#124ADB"/>
27+
</linearGradient>
28+
<clipPath id="clip0">
29+
<rect width="381.782" height="381.782" fill="white" transform="translate(0.998047 0.572266)"/>
30+
</clipPath>
31+
</defs>
32+
</svg>
33+
`
34+
35+
export default coinbaseIcon

src/modules/select/wallets/coinbase.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { mobileWalletInstallMessage } from '../content'
22
import { WalletModule, Helpers, CommonWalletOptions } from '../../../interfaces'
33

4+
import coinbaseIcon from '../wallet-icons/icon-coinbase'
5+
46
function coinbase(options: CommonWalletOptions): WalletModule {
57
const { preferred, label, iconSrc, svg } = options
68

79
return {
810
name: label || 'Coinbase',
9-
iconSrc:
10-
iconSrc ||
11-
'https://cdn-images-1.medium.com/max/1200/1*7ywNS48PnonfsvvMu1tTsA.png',
11+
iconSrc: iconSrc || coinbaseIcon,
1212
svg,
1313
wallet: async (helpers: Helpers) => {
1414
const { getProviderName, createLegacyProviderInterface } = helpers
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { WalletLinkOptions, WalletModule, Helpers } from '../../../interfaces'
2+
3+
import coinbaseIcon from '../wallet-icons/icon-coinbase'
4+
5+
function walletLink(
6+
options: WalletLinkOptions & { networkId: number }
7+
): WalletModule {
8+
const {
9+
rpcUrl,
10+
appName,
11+
appLogoUrl,
12+
networkId,
13+
preferred,
14+
label,
15+
iconSrc,
16+
svg
17+
} = options
18+
19+
return {
20+
name: label || 'WalletLink',
21+
svg: svg || coinbaseIcon,
22+
iconSrc,
23+
wallet: async (helpers: Helpers) => {
24+
const { getBalance, getAddress, getNetwork } = helpers
25+
26+
const { default: WalletLink } = await import('walletlink')
27+
28+
const instance = new WalletLink({
29+
appName,
30+
appLogoUrl
31+
})
32+
33+
const provider = instance.makeWeb3Provider(rpcUrl, networkId)
34+
35+
return {
36+
provider,
37+
interface: {
38+
name: 'WalletConnect',
39+
connect: () =>
40+
new Promise((resolve, reject) => {
41+
provider
42+
.enable()
43+
.then((res: any) => resolve(res))
44+
.catch(() =>
45+
reject({
46+
message:
47+
'This dapp needs access to your account information.'
48+
})
49+
)
50+
}),
51+
disconnect: () => {
52+
provider.disconnect()
53+
},
54+
address: {
55+
get: () => getAddress(provider)
56+
},
57+
network: {
58+
get: () => getNetwork(provider)
59+
},
60+
balance: {
61+
get: () => getBalance(provider)
62+
}
63+
}
64+
}
65+
},
66+
type: 'sdk',
67+
desktop: true,
68+
preferred
69+
}
70+
}
71+
72+
export default walletLink

src/validation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ export function validateWalletInit(
583583
'enableLogging',
584584
'loginMethod',
585585
'showTorusButton',
586+
'appName',
587+
'appLogoUrl',
586588
'enabledVerifiers',
587589
'disableNotifications'
588590
],

yarn.lock

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,11 @@ binary-extensions@^1.0.0:
20642064
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.1.tgz#598afe54755b2868a5330d2aff9d4ebb53209b65"
20652065
integrity sha512-Un7MIEDdUC5gNpcGDV97op1Ywk748MpHcFTHoYs6qnj1Z3j7I53VG3nwZhKzoBZmbdRNnb6WRdFlwl7tSDuZGw==
20662066

2067+
bind-decorator@^1.0.11:
2068+
version "1.0.11"
2069+
resolved "https://registry.yarnpkg.com/bind-decorator/-/bind-decorator-1.0.11.tgz#e41bc06a1f65dd9cec476c91c5daf3978488252f"
2070+
integrity sha1-5BvAah9l3ZzsR2yRxdrzl4SIJS8=
2071+
20672072
bindings@^1.2.1, bindings@^1.5.0:
20682073
version "1.5.0"
20692074
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df"
@@ -2249,9 +2254,9 @@ camelcase@^4.1.0:
22492254
integrity sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=
22502255

22512256
caniuse-lite@^1.0.30000844, caniuse-lite@^1.0.30001043:
2252-
version "1.0.30001054"
2253-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001054.tgz#7e82fc42d927980b0ce1426c4813df12381e1a75"
2254-
integrity sha512-jiKlTI6Ur8Kjfj8z0muGrV6FscpRvefcQVPSuMuXnvRCfExU7zlVLNjmOz1TnurWgUrAY7MMmjyy+uTgIl1XHw==
2257+
version "1.0.30001055"
2258+
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001055.tgz#7b52c3537f7a8c0408aca867e83d2b04268b54cd"
2259+
integrity sha512-MbwsBmKrBSKIWldfdIagO5OJWZclpJtS4h0Jrk/4HFrXJxTdVdH23Fd+xCiHriVGvYcWyW8mR/CPsYajlH8Iuw==
22552260

22562261
caseless@~0.12.0:
22572262
version "0.12.0"
@@ -2352,6 +2357,11 @@ clone@^2.0.0, clone@^2.1.1:
23522357
resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f"
23532358
integrity sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18=
23542359

2360+
clsx@^1.1.0:
2361+
version "1.1.0"
2362+
resolved "https://registry.yarnpkg.com/clsx/-/clsx-1.1.0.tgz#62937c6adfea771247c34b54d320fb99624f5702"
2363+
integrity sha512-3avwM37fSK5oP6M5rQ9CNe99lwxhXDOeSWVPAOYF6OazUTgZCMb0yWlJpmdD74REy1gkEaFiub2ULv4fq9GUhA==
2364+
23552365
collection-visit@^1.0.0:
23562366
version "1.0.0"
23572367
resolved "https://registry.yarnpkg.com/collection-visit/-/collection-visit-1.0.0.tgz#4bc0373c164bc3291b4d368c829cf1a80a59dca0"
@@ -5122,6 +5132,11 @@ post-message-stream@^3.0.0:
51225132
dependencies:
51235133
readable-stream "^2.1.4"
51245134

5135+
preact@^10.3.3:
5136+
version "10.4.1"
5137+
resolved "https://registry.yarnpkg.com/preact/-/preact-10.4.1.tgz#9b3ba020547673a231c6cf16f0fbaef0e8863431"
5138+
integrity sha512-WKrRpCSwL2t3tpOOGhf2WfTpcmbpxaWtDbdJdKdjd0aEiTkvOmS4NBkG6kzlaAHI9AkQ3iVqbFWM3Ei7mZ4o1Q==
5139+
51255140
precond@0.2:
51265141
version "0.2.3"
51275142
resolved "https://registry.yarnpkg.com/precond/-/precond-0.2.3.tgz#aa9591bcaa24923f1e0f4849d240f47efc1075ac"
@@ -5629,7 +5644,7 @@ rustbn.js@~0.2.0:
56295644
resolved "https://registry.yarnpkg.com/rustbn.js/-/rustbn.js-0.2.0.tgz#8082cb886e707155fd1cb6f23bd591ab8d55d0ca"
56305645
integrity sha512-4VlvkRUuCJvr2J6Y0ImW7NvTCriMi7ErOAqWk1y69vAdoNIzCF3yPmgeNzx+RQTLEDFq5sHfscn1MwHxP9hNfA==
56315646

5632-
rxjs@^6.5.3, rxjs@^6.5.5:
5647+
rxjs@^6.5.3, rxjs@^6.5.4, rxjs@^6.5.5:
56335648
version "6.5.5"
56345649
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.5.5.tgz#c5c884e3094c8cfee31bf27eb87e54ccfc87f9ec"
56355650
integrity sha512-WfQI+1gohdf0Dai/Bbmk5L5ItH5tYqm3ki2c5GdWhKjalzjg93N3avFjVStyZZz+A2Em+ZxKH5bNghw9UeylGQ==
@@ -6514,6 +6529,17 @@ verror@1.10.0:
65146529
core-util-is "1.0.2"
65156530
extsprintf "^1.2.0"
65166531

6532+
walletlink@^2.0.2:
6533+
version "2.0.2"
6534+
resolved "https://registry.yarnpkg.com/walletlink/-/walletlink-2.0.2.tgz#8640e42d3df49b4661019287ab9789e94b72db98"
6535+
integrity sha512-4MIctCHAjcPHSQUHpHuU9leUAvYqRF+/4kCq7x9AngZQ2Jd74dbpC8dfZ55uOwW8TXc7z9XYeSyzRrGHbv5ZXg==
6536+
dependencies:
6537+
bind-decorator "^1.0.11"
6538+
bn.js "^5.1.1"
6539+
clsx "^1.1.0"
6540+
preact "^10.3.3"
6541+
rxjs "^6.5.4"
6542+
65176543
web3-core-helpers@1.2.7:
65186544
version "1.2.7"
65196545
resolved "https://registry.yarnpkg.com/web3-core-helpers/-/web3-core-helpers-1.2.7.tgz#522f859775ea0d15e7e40359c46d4efc5da92aee"

0 commit comments

Comments
 (0)