Skip to content

Commit 25707f8

Browse files
SednaouileightktAdamj1232
authored
Feat/add additional required methods props to wc (#1883)
* add ability to pass additionalRequiredMethods in WalletConnectOptions * bump minor version to alpha.1 * add documentation for additionalRequiredMethods * bump @walletconnect/ethereum-provider to ^2.10.0 * Add to internal demo and docs, update readme --------- Co-authored-by: Kat Leight <33187102+leightkt@users.noreply.github.com> Co-authored-by: Adam Carpenter <adamcarpenter86@gmail.com>
1 parent 9877d59 commit 25707f8

File tree

10 files changed

+326
-81
lines changed

10 files changed

+326
-81
lines changed

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"@web3-onboard/trust": "^2.0.4",
8181
"@web3-onboard/uauth": "^2.1.1",
8282
"@web3-onboard/venly": "^2.0.0",
83-
"@web3-onboard/walletconnect": "^2.4.2",
83+
"@web3-onboard/walletconnect": "^2.4.6-alpha.1",
8484
"@web3-onboard/web3auth": "^2.2.3",
8585
"@web3-onboard/xdefi": "^2.0.4",
8686
"@web3-onboard/zeal": "^2.0.4",

docs/src/routes/docs/[...4]wallets/[...26]walletconnect/+page.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ type WalletConnectOptions = {
8787
* `undefined` by default, see https://docs.walletconnect.com/2.0/web/walletConnectModal/options
8888
*/
8989
qrModalOptions?: EthereumProviderOptions['qrModalOptions']
90+
/**
91+
* Additional required methods to be added to the default list of ['eth_sendTransaction', 'personal_sign']
92+
* Passed methods to be included along with the defaults methods - see https://docs.walletconnect.com/2.0/advanced/providers/ethereum#required-and-optional-methods
93+
*/
94+
additionalRequiredMethods?: string[] | undefined
9095
/**
9196
* Additional methods to be added to the default list of ['eth_sendTransaction', 'eth_signTransaction', 'personal_sign', 'eth_sign', 'eth_signTypedData', 'eth_signTypedData_v4']
9297
* Passed methods to be included along with the defaults methods - see https://docs.walletconnect.com/2.0/web/walletConnectModal/options

packages/demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@web3-onboard/trust": "^2.0.3",
5757
"@web3-onboard/uauth": "^2.1.2",
5858
"@web3-onboard/venly": "^2.0.0",
59-
"@web3-onboard/walletconnect": "^2.4.5",
59+
"@web3-onboard/walletconnect": "^2.4.6-alpha.1",
6060
"@web3-onboard/web3auth": "^2.2.2",
6161
"@web3-onboard/xdefi": "^2.0.5-alpha.1",
6262
"@web3-onboard/zeal": "^2.0.3",

packages/demo/src/App.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@
117117
118118
const walletConnect = walletConnectModule({
119119
handleUri: uri => console.log(uri),
120-
projectId: 'f6bd6e2911b56f5ac3bc8b2d0e2d7ad5'
120+
projectId: 'f6bd6e2911b56f5ac3bc8b2d0e2d7ad5',
121+
additionalOptionalMethods: ['someSillyShit']
121122
})
122123
const portis = portisModule({
123124
apiKey: 'b2b7586f-2b1e-4c30-a7fb-c2d1533b153b'

packages/walletconnect/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ type WalletConnectOptions = {
6868
* `undefined` by default, see https://docs.walletconnect.com/2.0/web/walletConnectModal/options
6969
*/
7070
qrModalOptions?: EthereumProviderOptions['qrModalOptions']
71+
/**
72+
* Additional required methods to be added to the default list of ['eth_sendTransaction', 'personal_sign']
73+
* Passed methods to be included along with the defaults methods - see https://docs.walletconnect.com/2.0/advanced/providers/ethereum#required-and-optional-methods
74+
*/
75+
additionalRequiredMethods?: string[] | undefined
7176
/**
7277
* Additional methods to be added to the default list of ['eth_sendTransaction', 'eth_signTransaction', 'personal_sign', 'eth_sign', 'eth_signTypedData', 'eth_signTypedData_v4']
7378
* Passed methods to be included along with the defaults methods - see https://docs.walletconnect.com/2.0/web/walletConnectModal/options

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.4.5",
3+
"version": "2.4.6-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",
@@ -61,7 +61,7 @@
6161
"dependencies": {
6262
"@ethersproject/providers": "5.5.0",
6363
"@walletconnect/client": "^1.8.0",
64-
"@walletconnect/ethereum-provider": "2.9.2",
64+
"@walletconnect/ethereum-provider": "^2.10.0",
6565
"@walletconnect/modal": "2.6.1",
6666
"@walletconnect/qrcode-modal": "^1.8.0",
6767
"@web3-onboard/common": "^2.3.3",

packages/walletconnect/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ export type WalletConnectOptions = {
5959
* `undefined` by default, see https://docs.walletconnect.com/2.0/web/walletConnectModal/options
6060
*/
6161
qrModalOptions?: EthereumProviderOptions['qrModalOptions']
62+
/**
63+
* Additional required methods to be added to the default list of ['eth_sendTransaction', 'personal_sign']
64+
* Passed methods to be included along with the defaults methods - see https://docs.walletconnect.com/2.0/advanced/providers/ethereum#required-and-optional-methods
65+
*/
66+
additionalRequiredMethods?: string[] | undefined
6267
/**
6368
* Additional methods to be added to the default list of ['eth_sendTransaction', 'eth_signTransaction', 'personal_sign', 'eth_sign', 'eth_signTypedData', 'eth_signTypedData_v4']
6469
* Passed methods to be included along with the defaults methods - see https://docs.walletconnect.com/2.0/web/walletConnectModal/options

packages/walletconnect/src/v2.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { CoreTypes } from '@walletconnect/types'
2-
import type { EthereumProvider } from '@walletconnect/ethereum-provider'
1+
import { REQUIRED_METHODS } from '@walletconnect/ethereum-provider'
32
import type { EthereumProviderOptions } from '@walletconnect/ethereum-provider/dist/types/EthereumProvider'
3+
import type { EthereumProvider } from '@walletconnect/ethereum-provider'
4+
import type { CoreTypes } from '@walletconnect/types'
45

56
import type {
67
Chain,
@@ -34,6 +35,7 @@ function walletConnect(options: WalletConnectOptions): WalletInit {
3435
requiredChains,
3536
optionalChains,
3637
qrModalOptions,
38+
additionalRequiredMethods,
3739
additionalOptionalMethods,
3840
dappUrl
3941
} = options
@@ -56,10 +58,7 @@ function walletConnect(options: WalletConnectOptions): WalletInit {
5658

5759
const getMetaData = (): CoreTypes.Metadata | undefined => {
5860
if (!appMetadata) return undefined
59-
const url =
60-
dappUrl ||
61-
appMetadata.explore ||
62-
''
61+
const url = dappUrl || appMetadata.explore || ''
6362

6463
!url &&
6564
!url.length &&
@@ -105,6 +104,13 @@ function walletConnect(options: WalletConnectOptions): WalletInit {
105104
optionalChains.map(chainID => parseInt(chainID))
106105
: chains.map(({ id }) => parseInt(id, 16))
107106

107+
const requiredMethodsSet = new Set(
108+
additionalRequiredMethods && Array.isArray(additionalRequiredMethods)
109+
? [...additionalRequiredMethods, ...REQUIRED_METHODS]
110+
: REQUIRED_METHODS
111+
)
112+
const requiredMethods = Array.from(requiredMethodsSet)
113+
108114
const optionalMethods =
109115
additionalOptionalMethods && Array.isArray(additionalOptionalMethods)
110116
? [...additionalOptionalMethods, ...methods]
@@ -113,6 +119,7 @@ function walletConnect(options: WalletConnectOptions): WalletInit {
113119
const connector = await EthereumProvider.init({
114120
projectId,
115121
chains: requiredChainsParsed, // default to mainnet
122+
methods: requiredMethods,
116123
optionalChains: optionalChainsParsed,
117124
optionalMethods,
118125
showQrModal: true,

packages/walletconnect/src/validation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const wcOptions = Joi.object({
3030
requiredChains: Joi.array().items(Joi.number()).optional(),
3131
optionalChains: Joi.array().items(Joi.number()).optional(),
3232
qrModalOptions: Joi.object().optional(),
33+
additionalRequiredMethods: Joi.array().items(Joi.string()).optional(),
3334
additionalOptionalMethods: Joi.array().items(Joi.string()).optional()
3435
})
3536

0 commit comments

Comments
 (0)