@metamask/connect-evm 0.1.2 → 0.2.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 +33 -1
- package/README.md +37 -5
- package/dist/browser/es/connect-evm.mjs +146 -13
- package/dist/browser/es/connect-evm.mjs.map +1 -1
- package/dist/src/connect.d.ts +2 -2
- package/dist/src/connect.d.ts.map +1 -1
- package/dist/src/connect.js +69 -15
- package/dist/src/connect.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/provider.d.ts +21 -1
- package/dist/src/provider.d.ts.map +1 -1
- package/dist/src/provider.js +82 -0
- package/dist/src/provider.js.map +1 -1
- package/dist/src/types.d.ts +23 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +46 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,36 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `display_uri` event support for custom QR code UI implementations ([#130](https://github.com/MetaMask/connect-monorepo/pull/130))
|
|
15
|
+
- `display_uri` event on `EIP1193Provider` emitted when QR code link is available
|
|
16
|
+
- `displayUri` callback in `EventHandlers` for event-based subscriptions
|
|
17
|
+
- Forwarded from `@metamask/connect-multichain` core to EIP-1193 provider layer
|
|
18
|
+
- Add `mobile.preferredOpenLink` option support for React Native deeplink handling in wagmi connector ([#118](https://github.com/MetaMask/connect-monorepo/pull/118))
|
|
19
|
+
- Allows React Native apps to use `Linking.openURL()` instead of `window.location.href` for opening MetaMask deeplinks
|
|
20
|
+
- Required for wagmi connector usage in React Native environments
|
|
21
|
+
- Add legacy compatibility methods to `EIP1193Provider` for broader ecosystem compatibility ([#102](https://github.com/MetaMask/connect-monorepo/pull/102))
|
|
22
|
+
- `chainId` getter (alias for `selectedChainId`)
|
|
23
|
+
- `sendAsync()` for callback/promise-based JSON-RPC requests
|
|
24
|
+
- `send()` for callback-based JSON-RPC requests
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- **BREAKING** Rename `createMetamaskConnectEVM` to `createEVMClient` for a cleaner naming convention ([#114](https://github.com/MetaMask/connect-monorepo/pull/114))
|
|
29
|
+
|
|
30
|
+
### Removed
|
|
31
|
+
|
|
32
|
+
- 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))
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
|
|
36
|
+
- 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))
|
|
37
|
+
- Update `#attemptSessionRecovery()` to check to state before attempting recovery ([#107](https://github.com/MetaMask/connect-monorepo/pull/107))
|
|
38
|
+
- 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))
|
|
39
|
+
|
|
10
40
|
## [0.1.2]
|
|
11
41
|
|
|
12
42
|
### Added
|
|
@@ -24,6 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
24
54
|
|
|
25
55
|
- Fix duplicate `onNotification` listener ([#81](https://github.com/MetaMask/connect-monorepo/pull/81))
|
|
26
56
|
- Fixed `addEthereumChain` not being prompted on mobile native browsers after a switch chain failure ([#79](https://github.com/MetaMask/connect-monorepo/pull/79))
|
|
57
|
+
- 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
58
|
|
|
28
59
|
## [0.1.1]
|
|
29
60
|
|
|
@@ -39,7 +70,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
39
70
|
|
|
40
71
|
- Initial release ([#58](https://github.com/MetaMask/connect-monorepo/pull/58))
|
|
41
72
|
|
|
42
|
-
[Unreleased]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-evm@0.
|
|
73
|
+
[Unreleased]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-evm@0.2.0...HEAD
|
|
74
|
+
[0.2.0]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-evm@0.1.2...@metamask/connect-evm@0.2.0
|
|
43
75
|
[0.1.2]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-evm@0.1.1...@metamask/connect-evm@0.1.2
|
|
44
76
|
[0.1.1]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/connect-evm@0.1.0...@metamask/connect-evm@0.1.1
|
|
45
77
|
[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 {
|
|
28
|
+
import { createEVMClient } from '@metamask/connect-evm';
|
|
28
29
|
|
|
29
30
|
// Create an SDK instance
|
|
30
|
-
const sdk = await
|
|
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 {
|
|
55
|
+
import { createEVMClient } from '@metamask/connect-evm';
|
|
55
56
|
|
|
56
|
-
const sdk = await
|
|
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/
|
|
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
|
-
|
|
55
|
+
createMultichainClient,
|
|
56
56
|
getWalletActionAnalyticsProperties,
|
|
57
57
|
isRejectionError,
|
|
58
58
|
TransportType
|
|
@@ -117,6 +117,15 @@ var EIP1193Provider = class extends EventEmitter {
|
|
|
117
117
|
__privateAdd(this, _selectedChainId);
|
|
118
118
|
__privateSet(this, _core, core);
|
|
119
119
|
__privateSet(this, _requestInterceptor, interceptor);
|
|
120
|
+
this.request = this.request.bind(this);
|
|
121
|
+
this.sendAsync = this.sendAsync.bind(this);
|
|
122
|
+
this.send = this.send.bind(this);
|
|
123
|
+
this.on = this.on.bind(this);
|
|
124
|
+
this.off = this.off.bind(this);
|
|
125
|
+
this.emit = this.emit.bind(this);
|
|
126
|
+
this.once = this.once.bind(this);
|
|
127
|
+
this.removeListener = this.removeListener.bind(this);
|
|
128
|
+
this.listenerCount = this.listenerCount.bind(this);
|
|
120
129
|
}
|
|
121
130
|
/**
|
|
122
131
|
* Performs a EIP-1193 request.
|
|
@@ -175,6 +184,74 @@ var EIP1193Provider = class extends EventEmitter {
|
|
|
175
184
|
}
|
|
176
185
|
__privateSet(this, _selectedChainId, hexChainId);
|
|
177
186
|
}
|
|
187
|
+
// ==========================================
|
|
188
|
+
// Legacy compatibility methods
|
|
189
|
+
// ==========================================
|
|
190
|
+
/**
|
|
191
|
+
* Alias for selectedChainId for legacy compatibility.
|
|
192
|
+
* Many dApps expect a `chainId` property on the provider.
|
|
193
|
+
*/
|
|
194
|
+
get chainId() {
|
|
195
|
+
return this.selectedChainId;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Legacy method for sending JSON-RPC requests.
|
|
199
|
+
* @deprecated Use `request` instead. This method is provided for backwards compatibility.
|
|
200
|
+
* @param request - The JSON-RPC request object
|
|
201
|
+
* @param callback - Optional callback function. If provided, the method returns void.
|
|
202
|
+
* @returns A promise resolving to the JSON-RPC response, or void if a callback is provided.
|
|
203
|
+
*/
|
|
204
|
+
sendAsync(request, callback) {
|
|
205
|
+
return __async(this, null, function* () {
|
|
206
|
+
var _a;
|
|
207
|
+
const id = (_a = request.id) != null ? _a : 1;
|
|
208
|
+
const promise = this.request({
|
|
209
|
+
method: request.method,
|
|
210
|
+
params: request.params
|
|
211
|
+
}).then(
|
|
212
|
+
(result) => ({
|
|
213
|
+
id,
|
|
214
|
+
jsonrpc: "2.0",
|
|
215
|
+
result
|
|
216
|
+
})
|
|
217
|
+
).catch(
|
|
218
|
+
(error) => {
|
|
219
|
+
var _a2, _b;
|
|
220
|
+
return {
|
|
221
|
+
id,
|
|
222
|
+
jsonrpc: "2.0",
|
|
223
|
+
error: {
|
|
224
|
+
code: (_a2 = error.code) != null ? _a2 : -32603,
|
|
225
|
+
message: (_b = error.message) != null ? _b : "Internal error",
|
|
226
|
+
data: error.data
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
);
|
|
231
|
+
if (callback) {
|
|
232
|
+
promise.then((response) => {
|
|
233
|
+
if (response.error) {
|
|
234
|
+
callback(new Error(response.error.message), response);
|
|
235
|
+
} else {
|
|
236
|
+
callback(null, response);
|
|
237
|
+
}
|
|
238
|
+
}).catch((error) => {
|
|
239
|
+
callback(error, null);
|
|
240
|
+
});
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
return promise;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Legacy method for sending JSON-RPC requests synchronously (callback-based).
|
|
248
|
+
* @deprecated Use `request` instead. This method is provided for backwards compatibility.
|
|
249
|
+
* @param request - The JSON-RPC request object
|
|
250
|
+
* @param callback - The callback function to receive the response
|
|
251
|
+
*/
|
|
252
|
+
send(request, callback) {
|
|
253
|
+
this.sendAsync(request, callback);
|
|
254
|
+
}
|
|
178
255
|
};
|
|
179
256
|
_core = new WeakMap();
|
|
180
257
|
_requestInterceptor = new WeakMap();
|
|
@@ -228,7 +305,8 @@ ${invalidUrls.join("\n")}`
|
|
|
228
305
|
|
|
229
306
|
// src/connect.ts
|
|
230
307
|
var DEFAULT_CHAIN_ID = 1;
|
|
231
|
-
var
|
|
308
|
+
var CHAIN_STORE_KEY = "cache_eth_chainId";
|
|
309
|
+
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
310
|
var MetamaskConnectEVM = class {
|
|
233
311
|
/**
|
|
234
312
|
* Creates a new MetamaskConnectEVM instance.
|
|
@@ -249,6 +327,8 @@ var MetamaskConnectEVM = class {
|
|
|
249
327
|
__privateAdd(this, _eventHandlers);
|
|
250
328
|
/** The handler for the wallet_sessionChanged event */
|
|
251
329
|
__privateAdd(this, _sessionChangedHandler);
|
|
330
|
+
/** The handler for the display_uri event */
|
|
331
|
+
__privateAdd(this, _displayUriHandler);
|
|
252
332
|
/** The clean-up function for the notification handler */
|
|
253
333
|
__privateAdd(this, _removeNotificationHandler);
|
|
254
334
|
__privateSet(this, _core2, core);
|
|
@@ -266,6 +346,8 @@ var MetamaskConnectEVM = class {
|
|
|
266
346
|
"wallet_sessionChanged",
|
|
267
347
|
__privateGet(this, _sessionChangedHandler).bind(this)
|
|
268
348
|
);
|
|
349
|
+
__privateSet(this, _displayUriHandler, __privateMethod(this, _MetamaskConnectEVM_instances, onDisplayUri_fn).bind(this));
|
|
350
|
+
__privateGet(this, _core2).on("display_uri", __privateGet(this, _displayUriHandler));
|
|
269
351
|
__privateMethod(this, _MetamaskConnectEVM_instances, attemptSessionRecovery_fn).call(this).catch((error) => {
|
|
270
352
|
console.error("Error attempting session recovery", error);
|
|
271
353
|
});
|
|
@@ -296,13 +378,14 @@ var MetamaskConnectEVM = class {
|
|
|
296
378
|
yield __privateGet(this, _core2).connect(
|
|
297
379
|
caipChainIds,
|
|
298
380
|
caipAccountIds,
|
|
381
|
+
{},
|
|
299
382
|
forceRequest
|
|
300
383
|
);
|
|
301
384
|
const hexPermittedChainIds = getPermittedEthChainIds(__privateGet(this, _sessionScopes));
|
|
302
|
-
const initialChainId = hexPermittedChainIds[0];
|
|
303
385
|
const initialAccounts = yield __privateGet(this, _core2).transport.sendEip1193Message({ method: "eth_accounts", params: [] });
|
|
386
|
+
const chainId = yield __privateMethod(this, _MetamaskConnectEVM_instances, getSelectedChainId_fn).call(this, hexPermittedChainIds);
|
|
304
387
|
__privateMethod(this, _MetamaskConnectEVM_instances, onConnect_fn).call(this, {
|
|
305
|
-
chainId
|
|
388
|
+
chainId,
|
|
306
389
|
accounts: initialAccounts.result
|
|
307
390
|
});
|
|
308
391
|
(_b = __privateGet(this, _removeNotificationHandler)) == null ? void 0 : _b.call(this);
|
|
@@ -317,6 +400,9 @@ var MetamaskConnectEVM = class {
|
|
|
317
400
|
if ((notification == null ? void 0 : notification.method) === "metamask_chainChanged") {
|
|
318
401
|
const notificationChainId = Number((_a2 = notification == null ? void 0 : notification.params) == null ? void 0 : _a2.chainId);
|
|
319
402
|
logger("transport-event: chainChanged", notificationChainId);
|
|
403
|
+
__privateMethod(this, _MetamaskConnectEVM_instances, cacheChainId_fn).call(this, notificationChainId).catch((error) => {
|
|
404
|
+
logger("Error caching chainId in notification handler", error);
|
|
405
|
+
});
|
|
320
406
|
__privateMethod(this, _MetamaskConnectEVM_instances, onChainChanged_fn).call(this, notificationChainId);
|
|
321
407
|
}
|
|
322
408
|
}
|
|
@@ -327,7 +413,7 @@ var MetamaskConnectEVM = class {
|
|
|
327
413
|
});
|
|
328
414
|
return {
|
|
329
415
|
accounts: __privateGet(this, _provider).accounts,
|
|
330
|
-
chainId: hexToNumber2(
|
|
416
|
+
chainId: hexToNumber2(chainId)
|
|
331
417
|
};
|
|
332
418
|
});
|
|
333
419
|
}
|
|
@@ -412,6 +498,7 @@ var MetamaskConnectEVM = class {
|
|
|
412
498
|
__privateMethod(this, _MetamaskConnectEVM_instances, onDisconnect_fn).call(this);
|
|
413
499
|
__privateMethod(this, _MetamaskConnectEVM_instances, clearConnectionState_fn).call(this);
|
|
414
500
|
__privateGet(this, _core2).off("wallet_sessionChanged", __privateGet(this, _sessionChangedHandler));
|
|
501
|
+
__privateGet(this, _core2).off("display_uri", __privateGet(this, _displayUriHandler));
|
|
415
502
|
if (__privateGet(this, _removeNotificationHandler)) {
|
|
416
503
|
__privateGet(this, _removeNotificationHandler).call(this);
|
|
417
504
|
__privateSet(this, _removeNotificationHandler, void 0);
|
|
@@ -442,6 +529,7 @@ var MetamaskConnectEVM = class {
|
|
|
442
529
|
}
|
|
443
530
|
const permittedChainIds = getPermittedEthChainIds(__privateGet(this, _sessionScopes));
|
|
444
531
|
if (permittedChainIds.includes(hexChainId) && __privateGet(this, _core2).transportType === TransportType.MWP) {
|
|
532
|
+
yield __privateMethod(this, _MetamaskConnectEVM_instances, cacheChainId_fn).call(this, hexChainId);
|
|
445
533
|
__privateMethod(this, _MetamaskConnectEVM_instances, onChainChanged_fn).call(this, hexChainId);
|
|
446
534
|
yield __privateMethod(this, _MetamaskConnectEVM_instances, trackWalletActionSucceeded_fn).call(this, method, scope, params);
|
|
447
535
|
return Promise.resolve();
|
|
@@ -457,6 +545,7 @@ var MetamaskConnectEVM = class {
|
|
|
457
545
|
}
|
|
458
546
|
yield __privateMethod(this, _MetamaskConnectEVM_instances, trackWalletActionSucceeded_fn).call(this, method, scope, params);
|
|
459
547
|
if (result.result === null) {
|
|
548
|
+
yield __privateMethod(this, _MetamaskConnectEVM_instances, cacheChainId_fn).call(this, hexChainId);
|
|
460
549
|
__privateMethod(this, _MetamaskConnectEVM_instances, onChainChanged_fn).call(this, hexChainId);
|
|
461
550
|
}
|
|
462
551
|
return result;
|
|
@@ -524,6 +613,7 @@ _provider = new WeakMap();
|
|
|
524
613
|
_sessionScopes = new WeakMap();
|
|
525
614
|
_eventHandlers = new WeakMap();
|
|
526
615
|
_sessionChangedHandler = new WeakMap();
|
|
616
|
+
_displayUriHandler = new WeakMap();
|
|
527
617
|
_removeNotificationHandler = new WeakMap();
|
|
528
618
|
_MetamaskConnectEVM_instances = new WeakSet();
|
|
529
619
|
/**
|
|
@@ -601,6 +691,22 @@ trackWalletActionFailed_fn = function(method, scope, params, error) {
|
|
|
601
691
|
}
|
|
602
692
|
});
|
|
603
693
|
};
|
|
694
|
+
getSelectedChainId_fn = function(permittedChainIds) {
|
|
695
|
+
return __async(this, null, function* () {
|
|
696
|
+
try {
|
|
697
|
+
const cachedChainId = yield __privateGet(this, _core2).storage.adapter.get(CHAIN_STORE_KEY);
|
|
698
|
+
if (cachedChainId) {
|
|
699
|
+
const chainId = JSON.parse(cachedChainId);
|
|
700
|
+
if (permittedChainIds.includes(chainId)) {
|
|
701
|
+
return chainId;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
} catch (error) {
|
|
705
|
+
logger("Error retrieving cached chainId", error);
|
|
706
|
+
}
|
|
707
|
+
return permittedChainIds[0];
|
|
708
|
+
});
|
|
709
|
+
};
|
|
604
710
|
requestInterceptor_fn = function(request) {
|
|
605
711
|
return __async(this, null, function* () {
|
|
606
712
|
logger(`Intercepting request for method: ${request.method}`);
|
|
@@ -678,6 +784,7 @@ addEthereumChain_fn = function(chainConfiguration) {
|
|
|
678
784
|
params
|
|
679
785
|
});
|
|
680
786
|
if (result.result === null) {
|
|
787
|
+
yield __privateMethod(this, _MetamaskConnectEVM_instances, cacheChainId_fn).call(this, chainId);
|
|
681
788
|
__privateMethod(this, _MetamaskConnectEVM_instances, onChainChanged_fn).call(this, chainId);
|
|
682
789
|
}
|
|
683
790
|
yield __privateMethod(this, _MetamaskConnectEVM_instances, trackWalletActionSucceeded_fn).call(this, method, scope, params);
|
|
@@ -697,6 +804,19 @@ request_fn = function(request) {
|
|
|
697
804
|
return result;
|
|
698
805
|
});
|
|
699
806
|
};
|
|
807
|
+
cacheChainId_fn = function(chainId) {
|
|
808
|
+
return __async(this, null, function* () {
|
|
809
|
+
try {
|
|
810
|
+
const hexChainId = isHex(chainId) ? chainId : numberToHex2(chainId);
|
|
811
|
+
yield __privateGet(this, _core2).storage.adapter.set(
|
|
812
|
+
CHAIN_STORE_KEY,
|
|
813
|
+
JSON.stringify(hexChainId)
|
|
814
|
+
);
|
|
815
|
+
} catch (error) {
|
|
816
|
+
logger("Error caching chainId", error);
|
|
817
|
+
}
|
|
818
|
+
});
|
|
819
|
+
};
|
|
700
820
|
/**
|
|
701
821
|
* Handles chain change events and updates the provider's selected chain ID.
|
|
702
822
|
*
|
|
@@ -758,8 +878,23 @@ onDisconnect_fn = function() {
|
|
|
758
878
|
(_b = (_a = __privateGet(this, _eventHandlers)) == null ? void 0 : _a.disconnect) == null ? void 0 : _b.call(_a);
|
|
759
879
|
__privateMethod(this, _MetamaskConnectEVM_instances, onAccountsChanged_fn).call(this, []);
|
|
760
880
|
};
|
|
881
|
+
/**
|
|
882
|
+
* Handles display_uri events and emits them to the provider.
|
|
883
|
+
* This allows consumers to display their own custom QR code UI.
|
|
884
|
+
*
|
|
885
|
+
* @param uri - The deeplink URI to be displayed as a QR code
|
|
886
|
+
*/
|
|
887
|
+
onDisplayUri_fn = function(uri) {
|
|
888
|
+
var _a, _b;
|
|
889
|
+
logger("handler: display_uri", uri);
|
|
890
|
+
__privateGet(this, _provider).emit("display_uri", uri);
|
|
891
|
+
(_b = (_a = __privateGet(this, _eventHandlers)) == null ? void 0 : _a.displayUri) == null ? void 0 : _b.call(_a, uri);
|
|
892
|
+
};
|
|
761
893
|
attemptSessionRecovery_fn = function() {
|
|
762
894
|
return __async(this, null, function* () {
|
|
895
|
+
if (__privateGet(this, _core2).status !== "connected" && __privateGet(this, _core2).status !== "connecting") {
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
763
898
|
try {
|
|
764
899
|
const response = yield __privateGet(this, _core2).transport.request({
|
|
765
900
|
method: "wallet_getSession"
|
|
@@ -767,13 +902,11 @@ attemptSessionRecovery_fn = function() {
|
|
|
767
902
|
const { sessionScopes } = response.result;
|
|
768
903
|
__privateSet(this, _sessionScopes, sessionScopes);
|
|
769
904
|
const permittedChainIds = getPermittedEthChainIds(sessionScopes);
|
|
770
|
-
const permittedAccounts = yield __privateGet(this, _core2).transport.sendEip1193Message({
|
|
771
|
-
|
|
772
|
-
params: []
|
|
773
|
-
});
|
|
905
|
+
const permittedAccounts = yield __privateGet(this, _core2).transport.sendEip1193Message({ method: "eth_accounts", params: [] });
|
|
906
|
+
const chainId = yield __privateMethod(this, _MetamaskConnectEVM_instances, getSelectedChainId_fn).call(this, permittedChainIds);
|
|
774
907
|
if (permittedChainIds.length && permittedAccounts.result) {
|
|
775
908
|
__privateMethod(this, _MetamaskConnectEVM_instances, onConnect_fn).call(this, {
|
|
776
|
-
chainId
|
|
909
|
+
chainId,
|
|
777
910
|
accounts: permittedAccounts.result
|
|
778
911
|
});
|
|
779
912
|
}
|
|
@@ -782,7 +915,7 @@ attemptSessionRecovery_fn = function() {
|
|
|
782
915
|
}
|
|
783
916
|
});
|
|
784
917
|
};
|
|
785
|
-
function
|
|
918
|
+
function createEVMClient(options) {
|
|
786
919
|
return __async(this, null, function* () {
|
|
787
920
|
var _a;
|
|
788
921
|
enableDebug(options.debug);
|
|
@@ -794,7 +927,7 @@ function createMetamaskConnectEVM(options) {
|
|
|
794
927
|
}
|
|
795
928
|
validSupportedChainsUrls(options.api.supportedNetworks, "supportedNetworks");
|
|
796
929
|
try {
|
|
797
|
-
const core = yield
|
|
930
|
+
const core = yield createMultichainClient(__spreadProps(__spreadValues({}, options), {
|
|
798
931
|
api: {
|
|
799
932
|
supportedNetworks: options.api.supportedNetworks
|
|
800
933
|
}
|
|
@@ -811,7 +944,7 @@ function createMetamaskConnectEVM(options) {
|
|
|
811
944
|
});
|
|
812
945
|
}
|
|
813
946
|
export {
|
|
814
|
-
|
|
947
|
+
createEVMClient,
|
|
815
948
|
getInfuraRpcUrls
|
|
816
949
|
};
|
|
817
950
|
//# sourceMappingURL=connect-evm.mjs.map
|