Skip to content

Commit 7e207f9

Browse files
authored
[walletconnect-v2.3.1-alpha.1]: Update - walletConnect params to include requiredChains and updated WC deps (#1574)
* Update wc package to the latest and parameterize required chains * Update WC module to allow req chains as parameter * Update docs * Update docs
1 parent dc50c34 commit 7e207f9

File tree

9 files changed

+130
-82
lines changed

9 files changed

+130
-82
lines changed

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"@web3-onboard/trezor": "^2.3.3",
7878
"@web3-onboard/trust": "^2.0.0",
7979
"@web3-onboard/uauth": "^2.0.1",
80-
"@web3-onboard/walletconnect": "^2.3.1",
80+
"@web3-onboard/walletconnect": "^2.3.1-alpha.1",
8181
"@web3-onboard/web3auth": "^2.1.4",
8282
"@web3-onboard/xdefi": "^2.0.0",
8383
"animejs": "^3.2.1",

docs/src/routes/docs/[...4]wallets/walletconnect.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ type WalletConnectOptions = {
5555
* Defaults to version: 1 - this behavior will be deprecated after the WalletConnect v1 sunset
5656
*/
5757
version: 2
58+
/**
59+
* List of Required Chain(s) ID for wallets to support in number format (integer or hex)
60+
* Defaults to [1] - Ethereum
61+
* The chains defined within the web3-onboard config will define the
62+
* optional chains for the WalletConnect module
63+
*/
64+
requiredChains?: number[] | undefined
5865
}
5966
)
6067
```
@@ -106,4 +113,5 @@ console.log(connectedWallets)
106113
```
107114

108115
## Build Environments
109-
For build env configurations and setups please see the Build Env section [here](/docs/modules/core#build-environments)
116+
117+
For build env configurations and setups please see the Build Env section [here](/docs/modules/core#build-environments)

packages/demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@web3-onboard/tallyho": "^2.0.2-alpha.1",
4747
"@web3-onboard/taho": "^2.0.0-alpha.1",
4848
"@web3-onboard/web3auth": "^2.1.4",
49-
"@web3-onboard/walletconnect": "^2.3.1",
49+
"@web3-onboard/walletconnect": "^2.3.1-alpha.1",
5050
"@web3-onboard/enkrypt": "^2.0.0",
5151
"@web3-onboard/mew-wallet": "^2.0.0",
5252
"@web3-onboard/xdefi": "^2.0.0",

packages/demo/src/App.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@
109109
projectId: 'f6bd6e2911b56f5ac3bc8b2d0e2d7ad5',
110110
qrcodeModalOptions: {
111111
mobileLinks: ['rainbow', 'metamask', 'argent', 'trust', 'imtoken', 'pillar']
112-
}
112+
},
113+
requiredChains: [1]
113114
})
114115
const portis = portisModule({
115116
apiKey: 'b2b7586f-2b1e-4c30-a7fb-c2d1533b153b'

packages/walletconnect/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
`npm i @web3-onboard/core @web3-onboard/walletconnect`
88

99
## Not all Wallets support WalletConnect V2 currently
10+
1011
_For an up to date list please see the [WalletConnect Explorer](https://explorer.walletconnect.com/?version=2)_
1112

1213
## Options
@@ -39,6 +40,13 @@ type WalletConnectOptions = {
3940
* Defaults to version: 1 - this behavior will be deprecated after the WalletConnect v1 sunset
4041
*/
4142
version: 2
43+
/**
44+
* List of Required Chain(s) ID for wallets to support in number format (integer or hex)
45+
* Defaults to [1] - Ethereum
46+
* The chains defined within the web3-onboard config will define the
47+
* optional chains for the WalletConnect module
48+
*/
49+
requiredChains?: number[] | undefined
4250
}
4351
)
4452
```
@@ -52,7 +60,7 @@ import walletConnectModule from '@web3-onboard/walletconnect'
5260
const wcV1InitOptions = {
5361
bridge: 'YOUR_CUSTOM_BRIDGE_SERVER',
5462
qrcodeModalOptions: {
55-
mobileLinks: ['metamask', 'argent', 'trust',]
63+
mobileLinks: ['metamask', 'argent', 'trust']
5664
},
5765
connectFirstChainId: true
5866
}

packages/walletconnect/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/walletconnect",
3-
"version": "2.3.1",
3+
"version": "2.3.1-alpha.1",
44
"description": "WalletConnect SDK module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
55
"keywords": [
66
"Ethereum",
@@ -60,7 +60,7 @@
6060
},
6161
"dependencies": {
6262
"@ethersproject/providers": "^5.5.0",
63-
"@walletconnect/ethereum-provider": "2.4.6",
63+
"@walletconnect/ethereum-provider": "2.4.10",
6464
"@walletconnect/client": "^1.8.0",
6565
"@walletconnect/qrcode-modal": "^1.8.0",
6666
"@web3-onboard/common": "^2.2.3",

packages/walletconnect/src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ export type WalletConnectOptions = {
2929
* Defaults to version: 1 - this behavior will be deprecated after the WalletConnect v1 sunset
3030
*/
3131
version: 2
32+
/**
33+
* List of Required Chain(s) ID for wallets to support in number format (integer or hex)
34+
* Defaults to [1] - Ethereum
35+
* The chains defined within the web3-onboard config will define the
36+
* optional chains for the WalletConnect module
37+
*/
38+
requiredChains?: number[] | undefined
3239
}
3340
)
3441

@@ -41,7 +48,7 @@ export const isHexString = (value: string | number) => {
4148
}
4249

4350
function walletConnect(options?: WalletConnectOptions): WalletInit {
44-
const version = options?.version || 1
51+
const version = options && options.version || 1
4552
return version === 1 ? v1(options) : v2(options)
4653
}
4754

packages/walletconnect/src/v2.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const methods = [
2020

2121
function walletConnect(options?: WalletConnectOptions): WalletInit {
2222
const projectId =
23-
options && options.version == 2 ? options.projectId : undefined
23+
options && options.version === 2 ? options.projectId : undefined
2424
if (!projectId) {
2525
throw new Error(
2626
'WalletConnect requires a projectId. Please visit https://cloud.walletconnect.com to get one.'
@@ -64,10 +64,22 @@ function walletConnect(options?: WalletConnectOptions): WalletInit {
6464
return wcMetaData
6565
}
6666

67+
// default to mainnet
68+
const requiredChains =
69+
options &&
70+
options.version === 2 &&
71+
Array.isArray(options.requiredChains) &&
72+
options.requiredChains.length &&
73+
options.requiredChains.every(num => !isNaN(num) )
74+
// @ts-ignore
75+
// Required as WC package does not support hex numbers
76+
? options.requiredChains.map(chainID => parseInt(chainID))
77+
: [1]
78+
6779
const connector = await EthereumProvider.init({
6880
projectId,
6981
metadata: getMetaData(),
70-
chains: [1], // default to mainnet
82+
chains: requiredChains, // default to mainnet
7183
optionalChains: chains.map(({ id }) => parseInt(id, 16)),
7284
optionalMethods: methods,
7385
rpcMap: chains
@@ -168,7 +180,7 @@ function walletConnect(options?: WalletConnectOptions): WalletInit {
168180
})
169181
}
170182

171-
(() => {
183+
;(() => {
172184
const session = this.connector.session
173185
if (session) {
174186
this.emit('accountsChanged', this.connector.accounts)

0 commit comments

Comments
 (0)