Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[walletconnect-v2.3.2-alpha.1]: Update - walletConnect params to include requiredChains and updated WC deps #1574

Merged
merged 4 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@web3-onboard/trezor": "^2.3.3",
"@web3-onboard/trust": "^2.0.0",
"@web3-onboard/uauth": "^2.0.1",
"@web3-onboard/walletconnect": "^2.3.1",
"@web3-onboard/walletconnect": "^2.3.1-alpha.1",
"@web3-onboard/web3auth": "^2.1.4",
"@web3-onboard/xdefi": "^2.0.0",
"animejs": "^3.2.1",
Expand Down
10 changes: 9 additions & 1 deletion docs/src/routes/docs/[...4]wallets/walletconnect.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ type WalletConnectOptions = {
* Defaults to version: 1 - this behavior will be deprecated after the WalletConnect v1 sunset
*/
version: 2
/**
* List of Required Chain(s) ID for wallets to support in number format (integer or hex)
* Defaults to [1] - Ethereum
* The chains defined within the web3-onboard config will define the
* optional chains for the WalletConnect module
*/
requiredChains?: number[] | undefined
}
)
```
Expand Down Expand Up @@ -106,4 +113,5 @@ console.log(connectedWallets)
```

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

For build env configurations and setups please see the Build Env section [here](/docs/modules/core#build-environments)
2 changes: 1 addition & 1 deletion packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@web3-onboard/tallyho": "^2.0.2-alpha.1",
"@web3-onboard/taho": "^2.0.0-alpha.1",
"@web3-onboard/web3auth": "^2.1.4",
"@web3-onboard/walletconnect": "^2.3.1",
"@web3-onboard/walletconnect": "^2.3.1-alpha.1",
"@web3-onboard/enkrypt": "^2.0.0",
"@web3-onboard/mew-wallet": "^2.0.0",
"@web3-onboard/xdefi": "^2.0.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/demo/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
projectId: 'f6bd6e2911b56f5ac3bc8b2d0e2d7ad5',
qrcodeModalOptions: {
mobileLinks: ['rainbow', 'metamask', 'argent', 'trust', 'imtoken', 'pillar']
}
},
requiredChains: [1]
})
const portis = portisModule({
apiKey: 'b2b7586f-2b1e-4c30-a7fb-c2d1533b153b'
Expand Down
10 changes: 9 additions & 1 deletion packages/walletconnect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
`npm i @web3-onboard/core @web3-onboard/walletconnect`

## Not all Wallets support WalletConnect V2 currently

_For an up to date list please see the [WalletConnect Explorer](https://explorer.walletconnect.com/?version=2)_

## Options
Expand Down Expand Up @@ -39,6 +40,13 @@ type WalletConnectOptions = {
* Defaults to version: 1 - this behavior will be deprecated after the WalletConnect v1 sunset
*/
version: 2
/**
* List of Required Chain(s) ID for wallets to support in number format (integer or hex)
* Defaults to [1] - Ethereum
* The chains defined within the web3-onboard config will define the
* optional chains for the WalletConnect module
*/
requiredChains?: number[] | undefined
}
)
```
Expand All @@ -52,7 +60,7 @@ import walletConnectModule from '@web3-onboard/walletconnect'
const wcV1InitOptions = {
bridge: 'YOUR_CUSTOM_BRIDGE_SERVER',
qrcodeModalOptions: {
mobileLinks: ['metamask', 'argent', 'trust',]
mobileLinks: ['metamask', 'argent', 'trust']
},
connectFirstChainId: true
}
Expand Down
4 changes: 2 additions & 2 deletions packages/walletconnect/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-onboard/walletconnect",
"version": "2.3.1",
"version": "2.3.1-alpha.1",
"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.",
"keywords": [
"Ethereum",
Expand Down Expand Up @@ -60,7 +60,7 @@
},
"dependencies": {
"@ethersproject/providers": "^5.5.0",
"@walletconnect/ethereum-provider": "2.4.6",
"@walletconnect/ethereum-provider": "2.4.10",
"@walletconnect/client": "^1.8.0",
"@walletconnect/qrcode-modal": "^1.8.0",
"@web3-onboard/common": "^2.2.3",
Expand Down
9 changes: 8 additions & 1 deletion packages/walletconnect/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export type WalletConnectOptions = {
* Defaults to version: 1 - this behavior will be deprecated after the WalletConnect v1 sunset
*/
version: 2
/**
* List of Required Chain(s) ID for wallets to support in number format (integer or hex)
* Defaults to [1] - Ethereum
* The chains defined within the web3-onboard config will define the
* optional chains for the WalletConnect module
*/
requiredChains?: number[] | undefined
}
)

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

function walletConnect(options?: WalletConnectOptions): WalletInit {
const version = options?.version || 1
const version = options && options.version || 1
return version === 1 ? v1(options) : v2(options)
}

Expand Down
18 changes: 15 additions & 3 deletions packages/walletconnect/src/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const methods = [

function walletConnect(options?: WalletConnectOptions): WalletInit {
const projectId =
options && options.version == 2 ? options.projectId : undefined
options && options.version === 2 ? options.projectId : undefined
if (!projectId) {
throw new Error(
'WalletConnect requires a projectId. Please visit https://cloud.walletconnect.com to get one.'
Expand Down Expand Up @@ -64,10 +64,22 @@ function walletConnect(options?: WalletConnectOptions): WalletInit {
return wcMetaData
}

// default to mainnet
const requiredChains =
options &&
options.version === 2 &&
Array.isArray(options.requiredChains) &&
options.requiredChains.length &&
options.requiredChains.every(num => !isNaN(num) )
// @ts-ignore
// Required as WC package does not support hex numbers
? options.requiredChains.map(chainID => parseInt(chainID))
: [1]

const connector = await EthereumProvider.init({
projectId,
metadata: getMetaData(),
chains: [1], // default to mainnet
chains: requiredChains, // default to mainnet
optionalChains: chains.map(({ id }) => parseInt(id, 16)),
optionalMethods: methods,
rpcMap: chains
Expand Down Expand Up @@ -168,7 +180,7 @@ function walletConnect(options?: WalletConnectOptions): WalletInit {
})
}

(() => {
;(() => {
const session = this.connector.session
if (session) {
this.emit('accountsChanged', this.connector.accounts)
Expand Down
Loading