Skip to content

Commit fe11c73

Browse files
authored
[walletconnect-2.3.0-alpha.3] - Feat: Walletconnect URI handler + bump wc package version (#1552)
* accept handleUri prop * Update docs * Rename wc prop to handleUri * Bump wc pakcage version for walletconnect/ethereum-provider * merge in dev * Revert unintended change * Update prop in docs * Cleanup semicolon * Yarn it!
1 parent df817dc commit fe11c73

File tree

9 files changed

+103
-68
lines changed

9 files changed

+103
-68
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ type WalletConnectOptions = {
3434
mobileLinks: string[] // set the order and list of mobile linking wallets
3535
}
3636
connectFirstChainId?: boolean // if true, connects to the first network chain provided
37+
/**
38+
* Optional function to handle WalletConnect URI when it becomes available
39+
*/
40+
handleUri?: (uri: string) => Promise<unknown>
3741
} & (
3842
| {
3943
/**
@@ -74,7 +78,11 @@ const wcV2InitOptions = {
7478
/**
7579
* Project ID associated with [WalletConnect account](https://cloud.walletconnect.com)
7680
*/
77-
projectId: 'abc123...'
81+
projectId: 'abc123...',
82+
/**
83+
* Optional function to handle WalletConnect URI when it becomes available
84+
*/
85+
handleUri: (uri) => console.log(uri)
7886
}
7987

8088
// initialize the module with options

packages/demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@web3-onboard/torus": "^2.2.1",
4646
"@web3-onboard/tallyho": "^2.0.1",
4747
"@web3-onboard/web3auth": "^2.1.4",
48-
"@web3-onboard/walletconnect": "^2.3.0-alpha.2",
48+
"@web3-onboard/walletconnect": "^2.3.0-alpha.3",
4949
"@web3-onboard/enkrypt": "^2.0.0",
5050
"@web3-onboard/mew-wallet": "^2.0.0",
5151
"@web3-onboard/xdefi": "^2.0.0",

packages/demo/src/App.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
import { ethers } from 'ethers'
3737
import { share } from 'rxjs/operators'
3838
import VConsole from 'vconsole'
39-
import blocknativeIcon from './blocknative-icon'
40-
import blocknativeLogo from './blocknative-logo'
4139
4240
if (window.innerWidth < 700) {
4341
new VConsole()
@@ -107,6 +105,7 @@
107105
const walletConnect = walletConnectModule({
108106
connectFirstChainId: true,
109107
version: 2,
108+
handleUri: (uri) => console.log(uri),
110109
projectId: 'f6bd6e2911b56f5ac3bc8b2d0e2d7ad5',
111110
qrcodeModalOptions: {
112111
mobileLinks: ['rainbow', 'metamask', 'argent', 'trust', 'imtoken', 'pillar']

packages/walletconnect/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ type WalletConnectOptions = {
1818
mobileLinks: string[] // set the order and list of mobile linking wallets
1919
}
2020
connectFirstChainId?: boolean // if true, connects to the first network chain provided
21+
/**
22+
* Optional function to handle WalletConnect URI when it becomes available
23+
*/
24+
handleUri?: (uri: string) => Promise<unknown>
2125
} & (
2226
| {
2327
/**

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.0-alpha.2",
3+
"version": "2.3.0-alpha.3",
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.3",
63+
"@walletconnect/ethereum-provider": "2.4.6",
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import v1 from './v1'
33
import v2 from './v2'
44

55
export type WalletConnectOptions = {
6+
/**
7+
* Optional function to handle WalletConnect URI when it becomes available
8+
*/
9+
handleUri?: (uri: string) => Promise<unknown>
610
connectFirstChainId?: boolean
711
bridge?: string
812
qrcodeModalOptions?: {

packages/walletconnect/src/v1.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ function walletConnect(
1313
const {
1414
bridge = 'https://bridge.walletconnect.org',
1515
qrcodeModalOptions,
16-
connectFirstChainId
16+
connectFirstChainId,
17+
handleUri
1718
} = options || {}
1819

1920
return () => {
@@ -48,6 +49,14 @@ function walletConnect(
4849
bridge
4950
})
5051

52+
if (handleUri) {
53+
try {
54+
await handleUri(connector.uri || '')
55+
} catch (error) {
56+
throw `An error occurred when handling the URI. Error: ${error}`
57+
}
58+
}
59+
5160
const emitter = new EventEmitter()
5261

5362
class EthProvider {

packages/walletconnect/src/v2.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
WalletInit,
66
EIP1193Provider
77
} from '@web3-onboard/common'
8+
import { JQueryStyleEventEmitter } from 'rxjs/internal/observable/fromEvent'
89
import { isHexString, WalletConnectOptions } from './index.js'
910

1011
// methods that require user interaction
@@ -18,7 +19,8 @@ const methods = [
1819
]
1920

2021
function walletConnect(options?: WalletConnectOptions): WalletInit {
21-
const projectId = options?.version == 2 ? options.projectId : undefined
22+
const projectId =
23+
options && options.version == 2 ? options.projectId : undefined
2224
if (!projectId) {
2325
throw new Error(
2426
'WalletConnect requires a projectId. Please visit https://cloud.walletconnect.com to get one.'
@@ -82,9 +84,9 @@ function walletConnect(options?: WalletConnectOptions): WalletInit {
8284
public connector: InstanceType<typeof EthereumProvider>
8385
public chains: Chain[]
8486
public disconnect: EIP1193Provider['disconnect']
85-
public emit: (typeof EventEmitter)['emit']
86-
public on: (typeof EventEmitter)['on']
87-
public removeListener: (typeof EventEmitter)['removeListener']
87+
public emit: typeof EventEmitter['emit']
88+
public on: typeof EventEmitter['on']
89+
public removeListener: typeof EventEmitter['removeListener']
8890

8991
private disconnected$: InstanceType<typeof Subject>
9092

@@ -115,7 +117,7 @@ function walletConnect(options?: WalletConnectOptions): WalletInit {
115117

116118
// listen for chainChanged
117119
fromEvent(
118-
this.connector,
120+
this.connector as JQueryStyleEventEmitter<any, number>,
119121
'chainChanged',
120122
(payload: number) => payload
121123
)
@@ -130,7 +132,7 @@ function walletConnect(options?: WalletConnectOptions): WalletInit {
130132

131133
// listen for disconnect event
132134
fromEvent(
133-
this.connector,
135+
this.connector as JQueryStyleEventEmitter<any, string>,
134136
'session_delete',
135137
(payload: string) => payload
136138
)
@@ -149,7 +151,23 @@ function walletConnect(options?: WalletConnectOptions): WalletInit {
149151
if (this.connector.session) this.connector.disconnect()
150152
}
151153

152-
// load the session if it exists
154+
if (options && options.handleUri) {
155+
// listen for uri event
156+
fromEvent(
157+
this.connector as JQueryStyleEventEmitter<any, string>,
158+
'display_uri',
159+
(payload: string) => payload
160+
)
161+
.pipe(takeUntil(this.disconnected$))
162+
.subscribe(async uri => {
163+
try {
164+
options.handleUri && (await options.handleUri(uri))
165+
} catch (error) {
166+
throw `An error occurred when handling the URI. Error: ${error}`
167+
}
168+
})
169+
}
170+
153171
(() => {
154172
const session = this.connector.session
155173
if (session) {
@@ -189,7 +207,10 @@ function walletConnect(options?: WalletConnectOptions): WalletInit {
189207
}
190208
// Subscribe to connection events
191209
fromEvent(
192-
this.connector,
210+
this.connector as JQueryStyleEventEmitter<
211+
any,
212+
{ accounts: string[]; chainId: number }
213+
>,
193214
'connect',
194215
(payload: { accounts: string[]; chainId: number }) =>
195216
payload

yarn.lock

Lines changed: 43 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,23 +2961,23 @@
29612961
"@walletconnect/types" "^1.8.0"
29622962
"@walletconnect/utils" "^1.8.0"
29632963

2964-
"@walletconnect/[email protected].3":
2965-
version "2.4.3"
2966-
resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.4.3.tgz#e5dc4c24a67632e6c92098750ebcd13b20cd5ef4"
2967-
integrity sha512-k2lE2VMC/kroSJyrvrz9rHdRsRn3tMyUp2x1iy6b0IcLlVC1jjfFgH5MUxS+XB9L9O6+gAFnpTM/rKM9fYpPCA==
2964+
"@walletconnect/[email protected].6":
2965+
version "2.4.6"
2966+
resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.4.6.tgz#77072bf3a523b8fa26c93d085af55a5ea88cb48a"
2967+
integrity sha512-IPjS3dZvLQ2ZjuVKpel6NHIoW1bkCayh5W8XFC7nhLj5GHou5Gy2FsGgGbRknvCEVWH85AlFKFAvLZCe+TJ2VA==
29682968
dependencies:
29692969
"@walletconnect/heartbeat" "1.2.0"
29702970
"@walletconnect/jsonrpc-provider" "^1.0.6"
29712971
"@walletconnect/jsonrpc-utils" "^1.0.4"
29722972
"@walletconnect/jsonrpc-ws-connection" "^1.0.7"
29732973
"@walletconnect/keyvaluestorage" "^1.0.2"
29742974
"@walletconnect/logger" "^2.0.1"
2975-
"@walletconnect/relay-api" "^1.0.7"
2975+
"@walletconnect/relay-api" "^1.0.9"
29762976
"@walletconnect/relay-auth" "^1.0.4"
29772977
"@walletconnect/safe-json" "^1.0.1"
29782978
"@walletconnect/time" "^1.0.2"
2979-
"@walletconnect/types" "2.4.3"
2980-
"@walletconnect/utils" "2.4.3"
2979+
"@walletconnect/types" "2.4.6"
2980+
"@walletconnect/utils" "2.4.6"
29812981
events "^3.3.0"
29822982
lodash.isequal "4.5.0"
29832983
pino "7.11.0"
@@ -3051,21 +3051,20 @@
30513051
dependencies:
30523052
tslib "1.14.1"
30533053

3054-
"@walletconnect/[email protected].3":
3055-
version "2.4.3"
3056-
resolved "https://registry.yarnpkg.com/@walletconnect/ethereum-provider/-/ethereum-provider-2.4.3.tgz#9a5f75b463f2bb7ace049b2fa3afcd2f0d092d22"
3057-
integrity sha512-NXTQwh/wFzbAh2wTxkL+WxaYJdWoGMCFn40NgWiXo9D84Y5WEQdJQvP2Bnvn79ZXyIicjzQxFBXoNnctGOmyYg==
3054+
"@walletconnect/[email protected].6":
3055+
version "2.4.6"
3056+
resolved "https://registry.yarnpkg.com/@walletconnect/ethereum-provider/-/ethereum-provider-2.4.6.tgz#f05c76092ec3dda3667a6b7522518375eafc6e38"
3057+
integrity sha512-o7UJ7EBzFSTqNAwGcVpqNv5qqaFW6Vi3nOoXPHtcrwYew8TKAcW/OQFHPcm0LeKfE15OvVI+GMHnPBRZ2Ih2RA==
30583058
dependencies:
30593059
"@walletconnect/jsonrpc-http-connection" "^1.0.4"
30603060
"@walletconnect/jsonrpc-provider" "^1.0.6"
30613061
"@walletconnect/jsonrpc-types" "^1.0.2"
30623062
"@walletconnect/jsonrpc-utils" "^1.0.4"
3063-
"@walletconnect/sign-client" "2.4.3"
3064-
"@walletconnect/types" "2.4.3"
3065-
"@walletconnect/universal-provider" "2.4.3"
3066-
"@walletconnect/utils" "2.4.3"
3063+
"@walletconnect/sign-client" "2.4.6"
3064+
"@walletconnect/types" "2.4.6"
3065+
"@walletconnect/universal-provider" "2.4.6"
3066+
"@walletconnect/utils" "2.4.6"
30673067
"@web3modal/standalone" "2.1.1"
3068-
eip1193-provider "1.0.1"
30693068
events "^3.3.0"
30703069

30713070
"@walletconnect/events@^1.0.1":
@@ -3229,10 +3228,10 @@
32293228
"@walletconnect/environment" "^1.0.0"
32303229
randombytes "^2.1.0"
32313230

3232-
"@walletconnect/relay-api@^1.0.7":
3233-
version "1.0.7"
3234-
resolved "https://registry.yarnpkg.com/@walletconnect/relay-api/-/relay-api-1.0.7.tgz#e7aed03cbaff99ecdf2c8d32280c0b5d673bb419"
3235-
integrity sha512-Mf/Ql7Z0waZzAuondHS9bbUi12Kyvl95ihxVDM7mPO8o7Ke7S1ffpujCUhXbSacSKcw9aV2+7bKADlsBjQLR5Q==
3231+
"@walletconnect/relay-api@^1.0.9":
3232+
version "1.0.9"
3233+
resolved "https://registry.yarnpkg.com/@walletconnect/relay-api/-/relay-api-1.0.9.tgz#f8c2c3993dddaa9f33ed42197fc9bfebd790ecaf"
3234+
integrity sha512-Q3+rylJOqRkO1D9Su0DPE3mmznbAalYapJ9qmzDgK28mYF9alcP3UwG/og5V7l7CFOqzCLi7B8BvcBUrpDj0Rg==
32363235
dependencies:
32373236
"@walletconnect/jsonrpc-types" "^1.0.2"
32383237
tslib "1.14.1"
@@ -3261,20 +3260,20 @@
32613260
dependencies:
32623261
tslib "1.14.1"
32633262

3264-
"@walletconnect/[email protected].3":
3265-
version "2.4.3"
3266-
resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.4.3.tgz#f18aa998928b2b7ae57231e29791d6b44e46c389"
3267-
integrity sha512-ztAqFxCbj/kPVDJfFE47hBlOkLn/4xDHejAm+mYOOQjZ7qzGKSOciPz25k4uDIy60Z5sSR84gmmkjTIES18hzw==
3263+
"@walletconnect/[email protected].6":
3264+
version "2.4.6"
3265+
resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.4.6.tgz#6dff6a4683a44d5ac88c3f570c743016d814d878"
3266+
integrity sha512-Dt5p4g105/1EFXFCTvdJiqtRGRgyWPzIJ8MSsTlYSoeJiTYwUC+mlBh4Y+Io/cxtc5hUuguaj0MyovIMiL4KkA==
32683267
dependencies:
3269-
"@walletconnect/core" "2.4.3"
3268+
"@walletconnect/core" "2.4.6"
32703269
"@walletconnect/events" "^1.0.1"
32713270
"@walletconnect/heartbeat" "1.2.0"
32723271
"@walletconnect/jsonrpc-provider" "^1.0.6"
32733272
"@walletconnect/jsonrpc-utils" "^1.0.4"
32743273
"@walletconnect/logger" "^2.0.1"
32753274
"@walletconnect/time" "^1.0.2"
3276-
"@walletconnect/types" "2.4.3"
3277-
"@walletconnect/utils" "2.4.3"
3275+
"@walletconnect/types" "2.4.6"
3276+
"@walletconnect/utils" "2.4.6"
32783277
events "^3.3.0"
32793278
pino "7.11.0"
32803279

@@ -3303,10 +3302,10 @@
33033302
dependencies:
33043303
tslib "1.14.1"
33053304

3306-
"@walletconnect/[email protected].3":
3307-
version "2.4.3"
3308-
resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.4.3.tgz#32492b3865624de31c4f91eb80383a91d96370e2"
3309-
integrity sha512-AX/mlUpdigD0CrP+9ScXBzggH/oHHr89JZOXmzmGavhFZLPmt0gQN9Jvo/DxTK8vV5FZUOzKZTscygAOLfIrXQ==
3305+
"@walletconnect/[email protected].6":
3306+
version "2.4.6"
3307+
resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.4.6.tgz#45707ba774686f39a542c8cc1e9ca37c4a36691f"
3308+
integrity sha512-0ck2VvTRT4pTMQbop2Dku8YuOdNhebyJlXjtHN4naFgu73rXiw7Yml4N4hKjV4cwJoOBepWD2f9Dvl9cDFQ/Wg==
33103309
dependencies:
33113310
"@walletconnect/events" "^1.0.1"
33123311
"@walletconnect/heartbeat" "1.2.0"
@@ -3337,38 +3336,38 @@
33373336
"@walletconnect/logger" "^2.0.1"
33383337
events "^3.3.0"
33393338

3340-
"@walletconnect/[email protected].3":
3341-
version "2.4.3"
3342-
resolved "https://registry.yarnpkg.com/@walletconnect/universal-provider/-/universal-provider-2.4.3.tgz#c23ef5158eeb1531b3a888270e33e33b474df4bc"
3343-
integrity sha512-51tikF6VxpWOMskCbjlBj8cE243r9VogJudbQ5ZsgSlPjeyurxBllQg6YJQ87fhNlbQrEdo58lQCPzZWlp8XOw==
3339+
"@walletconnect/[email protected].6":
3340+
version "2.4.6"
3341+
resolved "https://registry.yarnpkg.com/@walletconnect/universal-provider/-/universal-provider-2.4.6.tgz#336ad48e2159f9a32fb2f8e5bb5ed29712ebbcbc"
3342+
integrity sha512-FvuCCoQ00kYK3M6wYpaK9goCTa8kK5DQPTrsXYeitfXcJccQHxJahpEzIadLc6sj5+uK06WuLGGSObfpjSG3IA==
33443343
dependencies:
33453344
"@walletconnect/jsonrpc-http-connection" "^1.0.4"
33463345
"@walletconnect/jsonrpc-provider" "^1.0.6"
33473346
"@walletconnect/jsonrpc-types" "^1.0.2"
33483347
"@walletconnect/jsonrpc-utils" "^1.0.4"
33493348
"@walletconnect/logger" "^2.0.1"
3350-
"@walletconnect/sign-client" "2.4.3"
3351-
"@walletconnect/types" "2.4.3"
3352-
"@walletconnect/utils" "2.4.3"
3349+
"@walletconnect/sign-client" "2.4.6"
3350+
"@walletconnect/types" "2.4.6"
3351+
"@walletconnect/utils" "2.4.6"
33533352
eip1193-provider "1.0.1"
33543353
events "^3.3.0"
33553354
pino "7.11.0"
33563355

3357-
"@walletconnect/[email protected].3":
3358-
version "2.4.3"
3359-
resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.4.3.tgz#7d6ab2b5f4062966b674f846b2f7989426eac110"
3360-
integrity sha512-tEQPo+qrvQyXWDXuTwA5s4mnoUClUlOc4Kd6gCIadDN7wUWVHGxQ+XPGiao6lu89FZAcGwHG0l52IP0BPVbMFg==
3356+
"@walletconnect/[email protected].6":
3357+
version "2.4.6"
3358+
resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.4.6.tgz#2bd192bfcc019d19929be2881f8e4f54fc9b56a0"
3359+
integrity sha512-SowRdiR3TTGeb3ikMP7ucOafgmu58Nh1pCjCff2666gQjVzT9qO1Y9aJ7eS3g3URJtLGzYCEIYohnUYOidvpgA==
33613360
dependencies:
33623361
"@stablelib/chacha20poly1305" "1.0.1"
33633362
"@stablelib/hkdf" "1.0.1"
33643363
"@stablelib/random" "^1.0.2"
33653364
"@stablelib/sha256" "1.0.1"
33663365
"@stablelib/x25519" "^1.0.3"
33673366
"@walletconnect/jsonrpc-utils" "^1.0.4"
3368-
"@walletconnect/relay-api" "^1.0.7"
3367+
"@walletconnect/relay-api" "^1.0.9"
33693368
"@walletconnect/safe-json" "^1.0.1"
33703369
"@walletconnect/time" "^1.0.2"
3371-
"@walletconnect/types" "2.4.3"
3370+
"@walletconnect/types" "2.4.6"
33723371
"@walletconnect/window-getters" "^1.0.1"
33733372
"@walletconnect/window-metadata" "^1.0.1"
33743373
detect-browser "5.3.0"
@@ -3428,15 +3427,6 @@
34283427
"@walletconnect/window-getters" "^1.0.1"
34293428
tslib "1.14.1"
34303429

3431-
"@web3-onboard/injected-wallets@^2.8.0":
3432-
version "2.8.0"
3433-
resolved "https://registry.yarnpkg.com/@web3-onboard/injected-wallets/-/injected-wallets-2.8.0.tgz#6cec9ae8c834aaa2e82ffdf968d3b42d736adcfd"
3434-
integrity sha512-Rq3uyRfeTLwxXqKmDV/nHBaEbFRGrEMqmpkEHM8PDxmN9/94ahUrhNMeVfJNcpJnG5cin9/GR4ZYPAqlSrlyCA==
3435-
dependencies:
3436-
"@web3-onboard/common" "^2.2.3"
3437-
joi "^17.6.1"
3438-
lodash.uniqby "^4.7.0"
3439-
34403430
"@web3-react/abstract-connector@^6.0.7":
34413431
version "6.0.7"
34423432
resolved "https://registry.yarnpkg.com/@web3-react/abstract-connector/-/abstract-connector-6.0.7.tgz#401b3c045f1e0fab04256311be49d5144e9badc6"

0 commit comments

Comments
 (0)