@metamask/connect-evm 0.1.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.0]
11
+
12
+ ### Added
13
+
14
+ - Add `ConnectEvm.status` property which exposes the current `ConnectionStatus` ([#136](https://github.com/MetaMask/connect-monorepo/pull/136))
15
+
16
+ ### Fixed
17
+
18
+ - Fix `eth_chainId` requests not being resolved from local cached state when using the EIP-1193 Provider `request()` method over the `MwpTransport` ([#124](https://github.com/MetaMask/connect-monorepo/pull/124))
19
+
20
+ ## [0.2.0]
21
+
22
+ ### Added
23
+
24
+ - Add `display_uri` event support for custom QR code UI implementations ([#130](https://github.com/MetaMask/connect-monorepo/pull/130))
25
+ - `display_uri` event on `EIP1193Provider` emitted when QR code link is available
26
+ - `displayUri` callback in `EventHandlers` for event-based subscriptions
27
+ - Forwarded from `@metamask/connect-multichain` core to EIP-1193 provider layer
28
+ - Add `mobile.preferredOpenLink` option support for React Native deeplink handling in wagmi connector ([#118](https://github.com/MetaMask/connect-monorepo/pull/118))
29
+ - Allows React Native apps to use `Linking.openURL()` instead of `window.location.href` for opening MetaMask deeplinks
30
+ - Required for wagmi connector usage in React Native environments
31
+ - Add legacy compatibility methods to `EIP1193Provider` for broader ecosystem compatibility ([#102](https://github.com/MetaMask/connect-monorepo/pull/102))
32
+ - `chainId` getter (alias for `selectedChainId`)
33
+ - `sendAsync()` for callback/promise-based JSON-RPC requests
34
+ - `send()` for callback-based JSON-RPC requests
35
+
36
+ ### Changed
37
+
38
+ - **BREAKING** Rename `createMetamaskConnectEVM` to `createEVMClient` for a cleaner naming convention ([#114](https://github.com/MetaMask/connect-monorepo/pull/114))
39
+
40
+ ### Removed
41
+
42
+ - Revert: Fix local state not correctly being reset when establishing a new connection when there is an existing active session ([#119](https://github.com/MetaMask/connect-monorepo/pull/119))
43
+
44
+ ### Fixed
45
+
46
+ - Fix selected chainId incorrectly reverting to Ethereum Mainnet after page refresh by caching the selected chainId and retrieving it from storage instead of assuming the first permitted chain is selected ([#113](https://github.com/MetaMask/connect-monorepo/pull/113))
47
+ - Update `#attemptSessionRecovery()` to check to state before attempting recovery ([#107](https://github.com/MetaMask/connect-monorepo/pull/107))
48
+ - Bind all public methods in `EIP1193Provider` constructor to ensure stable `this` context when methods are extracted or passed as callbacks ([#102](https://github.com/MetaMask/connect-monorepo/pull/102))
49
+
10
50
  ## [0.1.2]
11
51
 
12
52
  ### Added
@@ -24,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
24
64
 
25
65
  - Fix duplicate `onNotification` listener ([#81](https://github.com/MetaMask/connect-monorepo/pull/81))
26
66
  - Fixed `addEthereumChain` not being prompted on mobile native browsers after a switch chain failure ([#79](https://github.com/MetaMask/connect-monorepo/pull/79))
67
+ - Fix local state not correctly being reset when establishing a new connection when there is an existing active session ([#88](https://github.com/MetaMask/connect-monorepo/pull/88))
27
68
 
28
69
  ## [0.1.1]
29
70
 
@@ -39,7 +80,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
39
80
 
40
81
  - Initial release ([#58](https://github.com/MetaMask/connect-monorepo/pull/58))
41
82
 
42
- [Unreleased]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-evm@0.1.2...HEAD
83
+ [Unreleased]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-evm@0.3.0...HEAD
84
+ [0.3.0]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-evm@0.2.0...@metamask/connect-evm@0.3.0
85
+ [0.2.0]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-evm@0.1.2...@metamask/connect-evm@0.2.0
43
86
  [0.1.2]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-evm@0.1.1...@metamask/connect-evm@0.1.2
44
87
  [0.1.1]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-evm@0.1.0...@metamask/connect-evm@0.1.1
45
88
  [0.1.0]: https://github.com/MetaMask/connect-monorepo/releases/tag/@metamask/connect-evm@0.1.0
package/README.md CHANGED
@@ -8,6 +8,7 @@
8
8
 
9
9
  - **EIP-1193 Provider Interface** - Seamless integration with existing dapp code using the standard Ethereum provider interface
10
10
  - **Cross-Platform Support** - Works with browser extensions and mobile applications
11
+ - **React Native Support** - Native mobile deeplink handling via `preferredOpenLink` option
11
12
 
12
13
  ## Installation
13
14
 
@@ -24,10 +25,10 @@ npm install @metamask/connect-evm
24
25
  ## Quick Start
25
26
 
26
27
  ```typescript
27
- import { createMetamaskConnectEVM } from '@metamask/connect-evm';
28
+ import { createEVMClient } from '@metamask/connect-evm';
28
29
 
29
30
  // Create an SDK instance
30
- const sdk = await createMetamaskConnectEVM({
31
+ const sdk = await createEVMClient({
31
32
  dapp: {
32
33
  name: 'My DApp',
33
34
  url: 'https://mydapp.com',
@@ -51,9 +52,9 @@ const accounts = await provider.request({
51
52
  ### Basic Connection
52
53
 
53
54
  ```typescript
54
- import { createMetamaskConnectEVM } from '@metamask/connect-evm';
55
+ import { createEVMClient } from '@metamask/connect-evm';
55
56
 
56
- const sdk = await createMetamaskConnectEVM({
57
+ const sdk = await createEVMClient({
57
58
  dapp: {
58
59
  name: 'My DApp',
59
60
  url: 'https://mydapp.com',
@@ -70,6 +71,37 @@ await sdk.connect({ chainId: 137 }); // Polygon
70
71
  await sdk.connect({ chainId: 1, account: '0x...' });
71
72
  ```
72
73
 
74
+ ### React Native Support
75
+
76
+ When using `@metamask/connect-evm` in React Native, the standard browser deeplink mechanism (`window.location.href`) doesn't work. Instead, you can provide a custom `preferredOpenLink` function via the `mobile` option to handle deeplinks using React Native's `Linking` API.
77
+
78
+ ```typescript
79
+ import { Linking } from 'react-native';
80
+ import { createEVMClient } from '@metamask/connect-evm';
81
+
82
+ const sdk = await createEVMClient({
83
+ dapp: {
84
+ name: 'My React Native DApp',
85
+ url: 'https://mydapp.com',
86
+ },
87
+ api: {
88
+ supportedNetworks: {
89
+ 'eip155:1': 'https://mainnet.infura.io/v3/YOUR_KEY',
90
+ },
91
+ },
92
+ // React Native: use Linking.openURL for deeplinks
93
+ mobile: {
94
+ preferredOpenLink: (deeplink: string) => {
95
+ Linking.openURL(deeplink).catch((err) => {
96
+ console.error('Failed to open deeplink:', err);
97
+ });
98
+ },
99
+ },
100
+ } as any); // Note: mobile option is passed through to connect-multichain
101
+ ```
102
+
103
+ The `mobile.preferredOpenLink` option is checked before falling back to browser-based deeplink methods, making it the recommended approach for React Native applications.
104
+
73
105
  ### Using the Provider Directly
74
106
 
75
107
  ```typescript
@@ -101,7 +133,7 @@ const result = await provider.request({
101
133
 
102
134
  ## Examples
103
135
 
104
- Check out the [playground examples](../../playground/legacy-evm-react-vite-playground) for a complete React implementation.
136
+ Check out the [playground examples](../../playground/browser-playground) for a complete React implementation.
105
137
 
106
138
  ## TypeScript
107
139
 
@@ -52,7 +52,7 @@ import { getInfuraRpcUrls } from "@metamask/connect-multichain";
52
52
  // src/connect.ts
53
53
  import { analytics } from "@metamask/analytics";
54
54
  import {
55
- createMetamaskConnect,
55
+ createMultichainClient,
56
56
  getWalletActionAnalyticsProperties,
57
57
  isRejectionError,
58
58
  TransportType
@@ -77,10 +77,12 @@ var CONNECT_METHODS = [
77
77
  "eth_requestAccounts"
78
78
  ];
79
79
  var ACCOUNTS_METHODS = ["eth_accounts", "eth_coinbase"];
80
+ var CHAIN_METHODS = ["eth_chainId"];
80
81
  var INTERCEPTABLE_METHODS = [
81
82
  ...ACCOUNTS_METHODS,
82
83
  ...IGNORED_METHODS,
83
84
  ...CONNECT_METHODS,
85
+ ...CHAIN_METHODS,
84
86
  // These have bespoke handlers
85
87
  "wallet_revokePermissions",
86
88
  "wallet_switchEthereumChain",
@@ -117,6 +119,15 @@ var EIP1193Provider = class extends EventEmitter {
117
119
  __privateAdd(this, _selectedChainId);
118
120
  __privateSet(this, _core, core);
119
121
  __privateSet(this, _requestInterceptor, interceptor);
122
+ this.request = this.request.bind(this);
123
+ this.sendAsync = this.sendAsync.bind(this);
124
+ this.send = this.send.bind(this);
125
+ this.on = this.on.bind(this);
126
+ this.off = this.off.bind(this);
127
+ this.emit = this.emit.bind(this);
128
+ this.once = this.once.bind(this);
129
+ this.removeListener = this.removeListener.bind(this);
130
+ this.listenerCount = this.listenerCount.bind(this);
120
131
  }
121
132
  /**
122
133
  * Performs a EIP-1193 request.
@@ -175,6 +186,74 @@ var EIP1193Provider = class extends EventEmitter {
175
186
  }
176
187
  __privateSet(this, _selectedChainId, hexChainId);
177
188
  }
189
+ // ==========================================
190
+ // Legacy compatibility methods
191
+ // ==========================================
192
+ /**
193
+ * Alias for selectedChainId for legacy compatibility.
194
+ * Many dApps expect a `chainId` property on the provider.
195
+ */
196
+ get chainId() {
197
+ return this.selectedChainId;
198
+ }
199
+ /**
200
+ * Legacy method for sending JSON-RPC requests.
201
+ * @deprecated Use `request` instead. This method is provided for backwards compatibility.
202
+ * @param request - The JSON-RPC request object
203
+ * @param callback - Optional callback function. If provided, the method returns void.
204
+ * @returns A promise resolving to the JSON-RPC response, or void if a callback is provided.
205
+ */
206
+ sendAsync(request, callback) {
207
+ return __async(this, null, function* () {
208
+ var _a;
209
+ const id = (_a = request.id) != null ? _a : 1;
210
+ const promise = this.request({
211
+ method: request.method,
212
+ params: request.params
213
+ }).then(
214
+ (result) => ({
215
+ id,
216
+ jsonrpc: "2.0",
217
+ result
218
+ })
219
+ ).catch(
220
+ (error) => {
221
+ var _a2, _b;
222
+ return {
223
+ id,
224
+ jsonrpc: "2.0",
225
+ error: {
226
+ code: (_a2 = error.code) != null ? _a2 : -32603,
227
+ message: (_b = error.message) != null ? _b : "Internal error",
228
+ data: error.data
229
+ }
230
+ };
231
+ }
232
+ );
233
+ if (callback) {
234
+ promise.then((response) => {
235
+ if (response.error) {
236
+ callback(new Error(response.error.message), response);
237
+ } else {
238
+ callback(null, response);
239
+ }
240
+ }).catch((error) => {
241
+ callback(error, null);
242
+ });
243
+ return;
244
+ }
245
+ return promise;
246
+ });
247
+ }
248
+ /**
249
+ * Legacy method for sending JSON-RPC requests synchronously (callback-based).
250
+ * @deprecated Use `request` instead. This method is provided for backwards compatibility.
251
+ * @param request - The JSON-RPC request object
252
+ * @param callback - The callback function to receive the response
253
+ */
254
+ send(request, callback) {
255
+ this.sendAsync(request, callback);
256
+ }
178
257
  };
179
258
  _core = new WeakMap();
180
259
  _requestInterceptor = new WeakMap();
@@ -209,6 +288,9 @@ function isAddChainRequest(req) {
209
288
  function isAccountsRequest(req) {
210
289
  return req.method === "eth_accounts" || req.method === "eth_coinbase";
211
290
  }
291
+ function isChainIdRequest(req) {
292
+ return req.method === "eth_chainId";
293
+ }
212
294
  function validSupportedChainsUrls(record, recordName) {
213
295
  const invalidUrls = [];
214
296
  for (const [key, url] of Object.entries(record)) {
@@ -228,7 +310,8 @@ ${invalidUrls.join("\n")}`
228
310
 
229
311
  // src/connect.ts
230
312
  var DEFAULT_CHAIN_ID = 1;
231
- var _core2, _provider, _sessionScopes, _eventHandlers, _sessionChangedHandler, _removeNotificationHandler, _MetamaskConnectEVM_instances, getCoreOptions_fn, createInvokeOptions_fn, trackWalletActionRequested_fn, trackWalletActionSucceeded_fn, trackWalletActionFailed_fn, requestInterceptor_fn, clearConnectionState_fn, addEthereumChain_fn, request_fn, onChainChanged_fn, onAccountsChanged_fn, onConnect_fn, onDisconnect_fn, attemptSessionRecovery_fn;
313
+ var CHAIN_STORE_KEY = "cache_eth_chainId";
314
+ var _core2, _provider, _sessionScopes, _eventHandlers, _sessionChangedHandler, _displayUriHandler, _removeNotificationHandler, _MetamaskConnectEVM_instances, getCoreOptions_fn, createInvokeOptions_fn, trackWalletActionRequested_fn, trackWalletActionSucceeded_fn, trackWalletActionFailed_fn, getSelectedChainId_fn, requestInterceptor_fn, clearConnectionState_fn, addEthereumChain_fn, request_fn, cacheChainId_fn, onChainChanged_fn, onAccountsChanged_fn, onConnect_fn, onDisconnect_fn, onDisplayUri_fn, attemptSessionRecovery_fn;
232
315
  var MetamaskConnectEVM = class {
233
316
  /**
234
317
  * Creates a new MetamaskConnectEVM instance.
@@ -249,6 +332,8 @@ var MetamaskConnectEVM = class {
249
332
  __privateAdd(this, _eventHandlers);
250
333
  /** The handler for the wallet_sessionChanged event */
251
334
  __privateAdd(this, _sessionChangedHandler);
335
+ /** The handler for the display_uri event */
336
+ __privateAdd(this, _displayUriHandler);
252
337
  /** The clean-up function for the notification handler */
253
338
  __privateAdd(this, _removeNotificationHandler);
254
339
  __privateSet(this, _core2, core);
@@ -266,6 +351,8 @@ var MetamaskConnectEVM = class {
266
351
  "wallet_sessionChanged",
267
352
  __privateGet(this, _sessionChangedHandler).bind(this)
268
353
  );
354
+ __privateSet(this, _displayUriHandler, __privateMethod(this, _MetamaskConnectEVM_instances, onDisplayUri_fn).bind(this));
355
+ __privateGet(this, _core2).on("display_uri", __privateGet(this, _displayUriHandler));
269
356
  __privateMethod(this, _MetamaskConnectEVM_instances, attemptSessionRecovery_fn).call(this).catch((error) => {
270
357
  console.error("Error attempting session recovery", error);
271
358
  });
@@ -296,13 +383,14 @@ var MetamaskConnectEVM = class {
296
383
  yield __privateGet(this, _core2).connect(
297
384
  caipChainIds,
298
385
  caipAccountIds,
386
+ {},
299
387
  forceRequest
300
388
  );
301
389
  const hexPermittedChainIds = getPermittedEthChainIds(__privateGet(this, _sessionScopes));
302
- const initialChainId = hexPermittedChainIds[0];
303
390
  const initialAccounts = yield __privateGet(this, _core2).transport.sendEip1193Message({ method: "eth_accounts", params: [] });
391
+ const chainId = yield __privateMethod(this, _MetamaskConnectEVM_instances, getSelectedChainId_fn).call(this, hexPermittedChainIds);
304
392
  __privateMethod(this, _MetamaskConnectEVM_instances, onConnect_fn).call(this, {
305
- chainId: initialChainId,
393
+ chainId,
306
394
  accounts: initialAccounts.result
307
395
  });
308
396
  (_b = __privateGet(this, _removeNotificationHandler)) == null ? void 0 : _b.call(this);
@@ -317,6 +405,9 @@ var MetamaskConnectEVM = class {
317
405
  if ((notification == null ? void 0 : notification.method) === "metamask_chainChanged") {
318
406
  const notificationChainId = Number((_a2 = notification == null ? void 0 : notification.params) == null ? void 0 : _a2.chainId);
319
407
  logger("transport-event: chainChanged", notificationChainId);
408
+ __privateMethod(this, _MetamaskConnectEVM_instances, cacheChainId_fn).call(this, notificationChainId).catch((error) => {
409
+ logger("Error caching chainId in notification handler", error);
410
+ });
320
411
  __privateMethod(this, _MetamaskConnectEVM_instances, onChainChanged_fn).call(this, notificationChainId);
321
412
  }
322
413
  }
@@ -327,7 +418,7 @@ var MetamaskConnectEVM = class {
327
418
  });
328
419
  return {
329
420
  accounts: __privateGet(this, _provider).accounts,
330
- chainId: hexToNumber2(initialChainId)
421
+ chainId: hexToNumber2(chainId)
331
422
  };
332
423
  });
333
424
  }
@@ -412,6 +503,7 @@ var MetamaskConnectEVM = class {
412
503
  __privateMethod(this, _MetamaskConnectEVM_instances, onDisconnect_fn).call(this);
413
504
  __privateMethod(this, _MetamaskConnectEVM_instances, clearConnectionState_fn).call(this);
414
505
  __privateGet(this, _core2).off("wallet_sessionChanged", __privateGet(this, _sessionChangedHandler));
506
+ __privateGet(this, _core2).off("display_uri", __privateGet(this, _displayUriHandler));
415
507
  if (__privateGet(this, _removeNotificationHandler)) {
416
508
  __privateGet(this, _removeNotificationHandler).call(this);
417
509
  __privateSet(this, _removeNotificationHandler, void 0);
@@ -442,6 +534,7 @@ var MetamaskConnectEVM = class {
442
534
  }
443
535
  const permittedChainIds = getPermittedEthChainIds(__privateGet(this, _sessionScopes));
444
536
  if (permittedChainIds.includes(hexChainId) && __privateGet(this, _core2).transportType === TransportType.MWP) {
537
+ yield __privateMethod(this, _MetamaskConnectEVM_instances, cacheChainId_fn).call(this, hexChainId);
445
538
  __privateMethod(this, _MetamaskConnectEVM_instances, onChainChanged_fn).call(this, hexChainId);
446
539
  yield __privateMethod(this, _MetamaskConnectEVM_instances, trackWalletActionSucceeded_fn).call(this, method, scope, params);
447
540
  return Promise.resolve();
@@ -457,6 +550,7 @@ var MetamaskConnectEVM = class {
457
550
  }
458
551
  yield __privateMethod(this, _MetamaskConnectEVM_instances, trackWalletActionSucceeded_fn).call(this, method, scope, params);
459
552
  if (result.result === null) {
553
+ yield __privateMethod(this, _MetamaskConnectEVM_instances, cacheChainId_fn).call(this, hexChainId);
460
554
  __privateMethod(this, _MetamaskConnectEVM_instances, onChainChanged_fn).call(this, hexChainId);
461
555
  }
462
556
  return result;
@@ -518,12 +612,21 @@ var MetamaskConnectEVM = class {
518
612
  get selectedChainId() {
519
613
  return __privateGet(this, _provider).selectedChainId;
520
614
  }
615
+ /**
616
+ * Gets the current connection status
617
+ *
618
+ * @returns The current connection status
619
+ */
620
+ get status() {
621
+ return __privateGet(this, _core2).status;
622
+ }
521
623
  };
522
624
  _core2 = new WeakMap();
523
625
  _provider = new WeakMap();
524
626
  _sessionScopes = new WeakMap();
525
627
  _eventHandlers = new WeakMap();
526
628
  _sessionChangedHandler = new WeakMap();
629
+ _displayUriHandler = new WeakMap();
527
630
  _removeNotificationHandler = new WeakMap();
528
631
  _MetamaskConnectEVM_instances = new WeakSet();
529
632
  /**
@@ -601,6 +704,22 @@ trackWalletActionFailed_fn = function(method, scope, params, error) {
601
704
  }
602
705
  });
603
706
  };
707
+ getSelectedChainId_fn = function(permittedChainIds) {
708
+ return __async(this, null, function* () {
709
+ try {
710
+ const cachedChainId = yield __privateGet(this, _core2).storage.adapter.get(CHAIN_STORE_KEY);
711
+ if (cachedChainId) {
712
+ const chainId = JSON.parse(cachedChainId);
713
+ if (permittedChainIds.includes(chainId)) {
714
+ return chainId;
715
+ }
716
+ }
717
+ } catch (error) {
718
+ logger("Error retrieving cached chainId", error);
719
+ }
720
+ return permittedChainIds[0];
721
+ });
722
+ };
604
723
  requestInterceptor_fn = function(request) {
605
724
  return __async(this, null, function* () {
606
725
  logger(`Intercepting request for method: ${request.method}`);
@@ -649,6 +768,9 @@ requestInterceptor_fn = function(request) {
649
768
  yield __privateMethod(this, _MetamaskConnectEVM_instances, trackWalletActionSucceeded_fn).call(this, method, scope, params);
650
769
  return __privateGet(this, _provider).accounts;
651
770
  }
771
+ if (isChainIdRequest(request)) {
772
+ return __privateGet(this, _provider).selectedChainId;
773
+ }
652
774
  logger("Request not intercepted, forwarding to default handler", request);
653
775
  return Promise.resolve();
654
776
  });
@@ -678,6 +800,7 @@ addEthereumChain_fn = function(chainConfiguration) {
678
800
  params
679
801
  });
680
802
  if (result.result === null) {
803
+ yield __privateMethod(this, _MetamaskConnectEVM_instances, cacheChainId_fn).call(this, chainId);
681
804
  __privateMethod(this, _MetamaskConnectEVM_instances, onChainChanged_fn).call(this, chainId);
682
805
  }
683
806
  yield __privateMethod(this, _MetamaskConnectEVM_instances, trackWalletActionSucceeded_fn).call(this, method, scope, params);
@@ -697,6 +820,19 @@ request_fn = function(request) {
697
820
  return result;
698
821
  });
699
822
  };
823
+ cacheChainId_fn = function(chainId) {
824
+ return __async(this, null, function* () {
825
+ try {
826
+ const hexChainId = isHex(chainId) ? chainId : numberToHex2(chainId);
827
+ yield __privateGet(this, _core2).storage.adapter.set(
828
+ CHAIN_STORE_KEY,
829
+ JSON.stringify(hexChainId)
830
+ );
831
+ } catch (error) {
832
+ logger("Error caching chainId", error);
833
+ }
834
+ });
835
+ };
700
836
  /**
701
837
  * Handles chain change events and updates the provider's selected chain ID.
702
838
  *
@@ -758,8 +894,23 @@ onDisconnect_fn = function() {
758
894
  (_b = (_a = __privateGet(this, _eventHandlers)) == null ? void 0 : _a.disconnect) == null ? void 0 : _b.call(_a);
759
895
  __privateMethod(this, _MetamaskConnectEVM_instances, onAccountsChanged_fn).call(this, []);
760
896
  };
897
+ /**
898
+ * Handles display_uri events and emits them to the provider.
899
+ * This allows consumers to display their own custom QR code UI.
900
+ *
901
+ * @param uri - The deeplink URI to be displayed as a QR code
902
+ */
903
+ onDisplayUri_fn = function(uri) {
904
+ var _a, _b;
905
+ logger("handler: display_uri", uri);
906
+ __privateGet(this, _provider).emit("display_uri", uri);
907
+ (_b = (_a = __privateGet(this, _eventHandlers)) == null ? void 0 : _a.displayUri) == null ? void 0 : _b.call(_a, uri);
908
+ };
761
909
  attemptSessionRecovery_fn = function() {
762
910
  return __async(this, null, function* () {
911
+ if (__privateGet(this, _core2).status !== "connected" && __privateGet(this, _core2).status !== "connecting") {
912
+ return;
913
+ }
763
914
  try {
764
915
  const response = yield __privateGet(this, _core2).transport.request({
765
916
  method: "wallet_getSession"
@@ -767,13 +918,11 @@ attemptSessionRecovery_fn = function() {
767
918
  const { sessionScopes } = response.result;
768
919
  __privateSet(this, _sessionScopes, sessionScopes);
769
920
  const permittedChainIds = getPermittedEthChainIds(sessionScopes);
770
- const permittedAccounts = yield __privateGet(this, _core2).transport.sendEip1193Message({
771
- method: "eth_accounts",
772
- params: []
773
- });
921
+ const permittedAccounts = yield __privateGet(this, _core2).transport.sendEip1193Message({ method: "eth_accounts", params: [] });
922
+ const chainId = yield __privateMethod(this, _MetamaskConnectEVM_instances, getSelectedChainId_fn).call(this, permittedChainIds);
774
923
  if (permittedChainIds.length && permittedAccounts.result) {
775
924
  __privateMethod(this, _MetamaskConnectEVM_instances, onConnect_fn).call(this, {
776
- chainId: permittedChainIds[0],
925
+ chainId,
777
926
  accounts: permittedAccounts.result
778
927
  });
779
928
  }
@@ -782,7 +931,7 @@ attemptSessionRecovery_fn = function() {
782
931
  }
783
932
  });
784
933
  };
785
- function createMetamaskConnectEVM(options) {
934
+ function createEVMClient(options) {
786
935
  return __async(this, null, function* () {
787
936
  var _a;
788
937
  enableDebug(options.debug);
@@ -794,7 +943,7 @@ function createMetamaskConnectEVM(options) {
794
943
  }
795
944
  validSupportedChainsUrls(options.api.supportedNetworks, "supportedNetworks");
796
945
  try {
797
- const core = yield createMetamaskConnect(__spreadProps(__spreadValues({}, options), {
946
+ const core = yield createMultichainClient(__spreadProps(__spreadValues({}, options), {
798
947
  api: {
799
948
  supportedNetworks: options.api.supportedNetworks
800
949
  }
@@ -811,7 +960,7 @@ function createMetamaskConnectEVM(options) {
811
960
  });
812
961
  }
813
962
  export {
814
- createMetamaskConnectEVM,
963
+ createEVMClient,
815
964
  getInfuraRpcUrls
816
965
  };
817
966
  //# sourceMappingURL=connect-evm.mjs.map