@metamask/connect-multichain 0.14.0 → 1.0.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 +35 -1
- package/README.md +19 -19
- package/dist/browser/es/connect-multichain.d.mts +23 -10
- package/dist/browser/es/connect-multichain.mjs +595 -475
- package/dist/browser/es/connect-multichain.mjs.map +1 -1
- package/dist/browser/es/metafile-esm.json +1 -1
- package/dist/browser/iife/connect-multichain.d.ts +23 -10
- package/dist/browser/iife/connect-multichain.js +626 -475
- package/dist/browser/iife/connect-multichain.js.map +1 -1
- package/dist/browser/iife/metafile-iife.json +1 -1
- package/dist/browser/umd/connect-multichain.d.ts +23 -10
- package/dist/browser/umd/connect-multichain.js +595 -475
- package/dist/browser/umd/connect-multichain.js.map +1 -1
- package/dist/browser/umd/metafile-cjs.json +1 -1
- package/dist/node/cjs/connect-multichain.d.ts +23 -10
- package/dist/node/cjs/connect-multichain.js +597 -473
- package/dist/node/cjs/connect-multichain.js.map +1 -1
- package/dist/node/cjs/metafile-cjs.json +1 -1
- package/dist/node/es/connect-multichain.d.mts +23 -10
- package/dist/node/es/connect-multichain.mjs +594 -472
- package/dist/node/es/connect-multichain.mjs.map +1 -1
- package/dist/node/es/metafile-esm.json +1 -1
- package/dist/react-native/es/connect-multichain.d.mts +23 -10
- package/dist/react-native/es/connect-multichain.mjs +593 -471
- package/dist/react-native/es/connect-multichain.mjs.map +1 -1
- package/dist/react-native/es/metafile-esm.json +1 -1
- package/dist/src/domain/multichain/api/constants.d.ts +1 -0
- package/dist/src/domain/multichain/api/constants.d.ts.map +1 -1
- package/dist/src/domain/multichain/api/constants.js +13 -0
- package/dist/src/domain/multichain/api/constants.js.map +1 -1
- package/dist/src/domain/multichain/index.d.ts +3 -3
- package/dist/src/domain/multichain/index.d.ts.map +1 -1
- package/dist/src/domain/multichain/index.js +7 -3
- package/dist/src/domain/multichain/index.js.map +1 -1
- package/dist/src/domain/multichain/types.d.ts +15 -4
- package/dist/src/domain/multichain/types.d.ts.map +1 -1
- package/dist/src/domain/platform/index.d.ts.map +1 -1
- package/dist/src/domain/platform/index.js +27 -5
- package/dist/src/domain/platform/index.js.map +1 -1
- package/dist/src/domain/store/client.d.ts +3 -3
- package/dist/src/domain/store/client.d.ts.map +1 -1
- package/dist/src/domain/utils/index.d.ts +1 -0
- package/dist/src/domain/utils/index.d.ts.map +1 -1
- package/dist/src/domain/utils/index.js +5 -1
- package/dist/src/domain/utils/index.js.map +1 -1
- package/dist/src/multichain/index.d.ts +2 -3
- package/dist/src/multichain/index.d.ts.map +1 -1
- package/dist/src/multichain/index.js +248 -207
- package/dist/src/multichain/index.js.map +1 -1
- package/dist/src/multichain/rpc/requestRouter.d.ts +15 -0
- package/dist/src/multichain/rpc/requestRouter.d.ts.map +1 -1
- package/dist/src/multichain/rpc/requestRouter.js +54 -10
- package/dist/src/multichain/rpc/requestRouter.js.map +1 -1
- package/dist/src/multichain/transports/default/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/default/index.js +16 -10
- package/dist/src/multichain/transports/default/index.js.map +1 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts +2 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js +25 -17
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js.map +1 -1
- package/dist/src/multichain/transports/mwp/index.d.ts +3 -1
- package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/mwp/index.js +227 -170
- package/dist/src/multichain/transports/mwp/index.js.map +1 -1
- package/dist/src/store/index.d.ts +3 -3
- package/dist/src/store/index.d.ts.map +1 -1
- package/dist/src/store/index.js +8 -8
- package/dist/src/store/index.js.map +1 -1
- package/dist/src/ui/ModalFactory.d.ts.map +1 -1
- package/dist/src/ui/ModalFactory.js +5 -1
- package/dist/src/ui/ModalFactory.js.map +1 -1
- package/dist/src/ui/index.js +1 -1
- package/dist/src/ui/index.js.map +1 -1
- package/dist/src/ui/modals/web/install.d.ts.map +1 -1
- package/dist/src/ui/modals/web/install.js.map +1 -1
- package/dist/types/connect-multichain.d.ts +23 -10
- package/package.json +3 -3
|
@@ -273,7 +273,7 @@ var init_logger = __esm({
|
|
|
273
273
|
});
|
|
274
274
|
|
|
275
275
|
// src/domain/multichain/api/constants.ts
|
|
276
|
-
var infuraRpcUrls, RPC_HANDLED_METHODS, SDK_HANDLED_METHODS;
|
|
276
|
+
var infuraRpcUrls, RPC_HANDLED_METHODS, SDK_HANDLED_METHODS, EIP1193_PASSTHROUGH_METHODS;
|
|
277
277
|
var init_constants = __esm({
|
|
278
278
|
"src/domain/multichain/api/constants.ts"() {
|
|
279
279
|
"use strict";
|
|
@@ -438,6 +438,11 @@ var init_constants = __esm({
|
|
|
438
438
|
"eth_uninstallFilter"
|
|
439
439
|
]);
|
|
440
440
|
SDK_HANDLED_METHODS = /* @__PURE__ */ new Set(["eth_accounts", "eth_chainId"]);
|
|
441
|
+
EIP1193_PASSTHROUGH_METHODS = /* @__PURE__ */ new Set([
|
|
442
|
+
"wallet_addEthereumChain",
|
|
443
|
+
"wallet_switchEthereumChain",
|
|
444
|
+
"eth_accounts"
|
|
445
|
+
]);
|
|
441
446
|
}
|
|
442
447
|
});
|
|
443
448
|
|
|
@@ -493,7 +498,7 @@ var init_multichain = __esm({
|
|
|
493
498
|
}
|
|
494
499
|
/**
|
|
495
500
|
* Merges the given options into the current instance options.
|
|
496
|
-
* Only the mergeable keys are updated (api.supportedNetworks, versions, ui.*, mobile.*, transport.extensionId, debug).
|
|
501
|
+
* Only the mergeable keys are updated (api.supportedNetworks, analytics, versions, ui.*, mobile.*, transport.extensionId, debug).
|
|
497
502
|
* The main thing to note is that the value for `dapp` is not merged as it does not make sense for
|
|
498
503
|
* subsequent calls to `createMultichainClient` to have a different `dapp` value.
|
|
499
504
|
* Used when createMultichainClient is called with an existing singleton.
|
|
@@ -501,23 +506,28 @@ var init_multichain = __esm({
|
|
|
501
506
|
* @param partial - Options to merge/overwrite onto the current instance
|
|
502
507
|
*/
|
|
503
508
|
mergeOptions(partial) {
|
|
504
|
-
var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
509
|
+
var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
505
510
|
const opts = this.options;
|
|
511
|
+
const analytics3 = __spreadValues(__spreadValues({}, opts.analytics), (_a3 = partial.analytics) != null ? _a3 : {});
|
|
512
|
+
if (((_b = opts.analytics) == null ? void 0 : _b.enabled) === false) {
|
|
513
|
+
analytics3.enabled = false;
|
|
514
|
+
}
|
|
506
515
|
this.options = __spreadProps(__spreadValues({}, opts), {
|
|
507
516
|
api: __spreadProps(__spreadValues({}, opts.api), {
|
|
508
|
-
supportedNetworks: __spreadValues(__spreadValues({}, opts.api.supportedNetworks), (
|
|
517
|
+
supportedNetworks: __spreadValues(__spreadValues({}, opts.api.supportedNetworks), (_d = (_c = partial.api) == null ? void 0 : _c.supportedNetworks) != null ? _d : {})
|
|
509
518
|
}),
|
|
510
|
-
versions: __spreadValues(__spreadValues({}, opts.versions), (
|
|
519
|
+
versions: __spreadValues(__spreadValues({}, opts.versions), (_e = partial.versions) != null ? _e : {}),
|
|
520
|
+
analytics: __spreadValues({}, analytics3),
|
|
511
521
|
ui: __spreadProps(__spreadValues({}, opts.ui), {
|
|
512
|
-
headless: (
|
|
513
|
-
preferExtension: (
|
|
514
|
-
showInstallModal: (
|
|
522
|
+
headless: (_g = (_f = partial.ui) == null ? void 0 : _f.headless) != null ? _g : opts.ui.headless,
|
|
523
|
+
preferExtension: (_i = (_h = partial.ui) == null ? void 0 : _h.preferExtension) != null ? _i : opts.ui.preferExtension,
|
|
524
|
+
showInstallModal: (_k = (_j = partial.ui) == null ? void 0 : _j.showInstallModal) != null ? _k : opts.ui.showInstallModal
|
|
515
525
|
}),
|
|
516
|
-
mobile: __spreadValues(__spreadValues({}, opts.mobile), (
|
|
517
|
-
transport: __spreadProps(__spreadValues({}, (
|
|
518
|
-
extensionId: (
|
|
526
|
+
mobile: __spreadValues(__spreadValues({}, opts.mobile), (_l = partial.mobile) != null ? _l : {}),
|
|
527
|
+
transport: __spreadProps(__spreadValues({}, (_m = opts.transport) != null ? _m : {}), {
|
|
528
|
+
extensionId: (_p = (_n = partial.transport) == null ? void 0 : _n.extensionId) != null ? _p : (_o = opts.transport) == null ? void 0 : _o.extensionId
|
|
519
529
|
}),
|
|
520
|
-
debug: (
|
|
530
|
+
debug: (_q = partial.debug) != null ? _q : opts.debug
|
|
521
531
|
});
|
|
522
532
|
}
|
|
523
533
|
};
|
|
@@ -582,7 +592,7 @@ function hasExtension() {
|
|
|
582
592
|
return detectionPromise;
|
|
583
593
|
});
|
|
584
594
|
}
|
|
585
|
-
var import_bowser, PlatformType, detectionPromise;
|
|
595
|
+
var import_bowser, PlatformType, NATIVE_METAMASK_EIP6963_RDNS, detectionPromise;
|
|
586
596
|
var init_platform = __esm({
|
|
587
597
|
"src/domain/platform/index.ts"() {
|
|
588
598
|
"use strict";
|
|
@@ -595,6 +605,10 @@ var init_platform = __esm({
|
|
|
595
605
|
PlatformType2["ReactNative"] = "react-native";
|
|
596
606
|
return PlatformType2;
|
|
597
607
|
})(PlatformType || {});
|
|
608
|
+
NATIVE_METAMASK_EIP6963_RDNS = /* @__PURE__ */ new Set([
|
|
609
|
+
"io.metamask",
|
|
610
|
+
"io.metamask.mobile"
|
|
611
|
+
]);
|
|
598
612
|
detectionPromise = (() => __async(null, null, function* () {
|
|
599
613
|
const pt = getPlatformType();
|
|
600
614
|
if (pt === "nodejs" /* NonBrowser */ || pt === "react-native" /* ReactNative */) {
|
|
@@ -602,23 +616,30 @@ var init_platform = __esm({
|
|
|
602
616
|
}
|
|
603
617
|
return new Promise((resolve) => {
|
|
604
618
|
const providers = [];
|
|
619
|
+
const targetWindow = window;
|
|
605
620
|
const handler = (event) => {
|
|
606
621
|
var _a3, _b;
|
|
607
622
|
if ((_b = (_a3 = event == null ? void 0 : event.detail) == null ? void 0 : _a3.info) == null ? void 0 : _b.rdns) {
|
|
608
623
|
providers.push(event.detail);
|
|
609
624
|
}
|
|
610
625
|
};
|
|
611
|
-
|
|
612
|
-
|
|
626
|
+
targetWindow.addEventListener("eip6963:announceProvider", handler);
|
|
627
|
+
targetWindow.dispatchEvent(new Event("eip6963:requestProvider"));
|
|
613
628
|
setTimeout(() => {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
var _a3, _b;
|
|
618
|
-
return (_b = (_a3 = provider == null ? void 0 : provider.info) == null ? void 0 : _a3.rdns) == null ? void 0 : _b.startsWith("io.metamask");
|
|
629
|
+
try {
|
|
630
|
+
if (typeof (targetWindow == null ? void 0 : targetWindow.removeEventListener) === "function") {
|
|
631
|
+
targetWindow.removeEventListener("eip6963:announceProvider", handler);
|
|
619
632
|
}
|
|
620
|
-
|
|
621
|
-
|
|
633
|
+
const hasMetaMask = providers.some(
|
|
634
|
+
(provider) => {
|
|
635
|
+
var _a3;
|
|
636
|
+
return typeof ((_a3 = provider == null ? void 0 : provider.info) == null ? void 0 : _a3.rdns) === "string" && NATIVE_METAMASK_EIP6963_RDNS.has(provider.info.rdns);
|
|
637
|
+
}
|
|
638
|
+
);
|
|
639
|
+
resolve(hasMetaMask);
|
|
640
|
+
} catch (e) {
|
|
641
|
+
resolve(false);
|
|
642
|
+
}
|
|
622
643
|
}, 300);
|
|
623
644
|
});
|
|
624
645
|
}))();
|
|
@@ -863,12 +884,14 @@ var init_analytics = __esm({
|
|
|
863
884
|
|
|
864
885
|
// src/domain/utils/index.ts
|
|
865
886
|
function getVersion() {
|
|
866
|
-
return
|
|
887
|
+
return packageVersion;
|
|
867
888
|
}
|
|
889
|
+
var packageVersion;
|
|
868
890
|
var init_utils = __esm({
|
|
869
891
|
"src/domain/utils/index.ts"() {
|
|
870
892
|
"use strict";
|
|
871
893
|
init_analytics();
|
|
894
|
+
packageVersion = false ? "unknown" : "1.0.0";
|
|
872
895
|
}
|
|
873
896
|
});
|
|
874
897
|
|
|
@@ -1168,12 +1191,13 @@ var mwp_exports = {};
|
|
|
1168
1191
|
__export(mwp_exports, {
|
|
1169
1192
|
MWPTransport: () => MWPTransport
|
|
1170
1193
|
});
|
|
1171
|
-
var import_multichain_api_client2, import_rpc_errors2, DEFAULT_REQUEST_TIMEOUT2, CONNECTION_GRACE_PERIOD, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_RESUME_TIMEOUT, SESSION_STORE_KEY, ACCOUNTS_STORE_KEY, CHAIN_STORE_KEY, PENDING_SESSION_REQUEST_KEY, CACHED_METHOD_LIST, CACHED_RESET_METHOD_LIST, logger, MWPTransport;
|
|
1194
|
+
var import_multichain_api_client2, import_rpc_errors2, import_utils6, DEFAULT_REQUEST_TIMEOUT2, CONNECTION_GRACE_PERIOD, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_RESUME_TIMEOUT, SESSION_STORE_KEY, ACCOUNTS_STORE_KEY, CHAIN_STORE_KEY, PENDING_SESSION_REQUEST_KEY, CACHED_METHOD_LIST, CACHED_RESET_METHOD_LIST, logger, _MWPTransport_instances, onResumeHandler_fn, resumeSession_fn, startSession_fn, MWPTransport;
|
|
1172
1195
|
var init_mwp = __esm({
|
|
1173
1196
|
"src/multichain/transports/mwp/index.ts"() {
|
|
1174
1197
|
"use strict";
|
|
1175
1198
|
import_multichain_api_client2 = require("@metamask/multichain-api-client");
|
|
1176
1199
|
import_rpc_errors2 = require("@metamask/rpc-errors");
|
|
1200
|
+
import_utils6 = require("@metamask/utils");
|
|
1177
1201
|
init_domain();
|
|
1178
1202
|
init_utils2();
|
|
1179
1203
|
init_constants2();
|
|
@@ -1204,6 +1228,7 @@ var init_mwp = __esm({
|
|
|
1204
1228
|
this.dappClient = dappClient;
|
|
1205
1229
|
this.kvstore = kvstore;
|
|
1206
1230
|
this.options = options;
|
|
1231
|
+
__privateAdd(this, _MWPTransport_instances);
|
|
1207
1232
|
this.__pendingRequests = /* @__PURE__ */ new Map();
|
|
1208
1233
|
this.notificationCallbacks = /* @__PURE__ */ new Set();
|
|
1209
1234
|
this.dappClient.on("message", this.handleMessage.bind(this));
|
|
@@ -1283,6 +1308,23 @@ var init_mwp = __esm({
|
|
|
1283
1308
|
const message = errorPayload instanceof Error ? errorPayload.message : JSON.stringify(errorPayload);
|
|
1284
1309
|
return import_rpc_errors2.rpcErrors.internal({ message });
|
|
1285
1310
|
}
|
|
1311
|
+
getResponseError(messagePayload) {
|
|
1312
|
+
if ("error" in messagePayload && messagePayload.error) {
|
|
1313
|
+
return messagePayload.error;
|
|
1314
|
+
}
|
|
1315
|
+
const { result } = messagePayload;
|
|
1316
|
+
if (typeof result === "object" && result !== null && "error" in result && result.error && this.isErrorPayload(result.error)) {
|
|
1317
|
+
return result.error;
|
|
1318
|
+
}
|
|
1319
|
+
return void 0;
|
|
1320
|
+
}
|
|
1321
|
+
isErrorPayload(errorPayload) {
|
|
1322
|
+
if (errorPayload instanceof Error) {
|
|
1323
|
+
return true;
|
|
1324
|
+
}
|
|
1325
|
+
const errorData = errorPayload;
|
|
1326
|
+
return typeof (errorData == null ? void 0 : errorData.code) === "number" && typeof (errorData == null ? void 0 : errorData.message) === "string";
|
|
1327
|
+
}
|
|
1286
1328
|
handleMessage(message) {
|
|
1287
1329
|
if (typeof message === "object" && message !== null) {
|
|
1288
1330
|
if ("data" in message) {
|
|
@@ -1291,9 +1333,10 @@ var init_mwp = __esm({
|
|
|
1291
1333
|
const request = this.pendingRequests.get(messagePayload.id);
|
|
1292
1334
|
if (request) {
|
|
1293
1335
|
clearTimeout(request.timeout);
|
|
1294
|
-
|
|
1336
|
+
const responseError = this.getResponseError(messagePayload);
|
|
1337
|
+
if (responseError) {
|
|
1295
1338
|
this.pendingRequests.delete(messagePayload.id);
|
|
1296
|
-
request.reject(this.parseWalletError(
|
|
1339
|
+
request.reject(this.parseWalletError(responseError));
|
|
1297
1340
|
return;
|
|
1298
1341
|
}
|
|
1299
1342
|
const requestWithName = __spreadProps(__spreadValues({}, messagePayload), {
|
|
@@ -1336,73 +1379,6 @@ var init_mwp = __esm({
|
|
|
1336
1379
|
}
|
|
1337
1380
|
}
|
|
1338
1381
|
}
|
|
1339
|
-
onResumeSuccess(resumeResolve, resumeReject, options) {
|
|
1340
|
-
return __async(this, null, function* () {
|
|
1341
|
-
var _a3, _b, _c, _d, _e, _f, _g;
|
|
1342
|
-
try {
|
|
1343
|
-
yield this.waitForWalletSessionIfNotCached();
|
|
1344
|
-
const sessionRequest = yield this.request({
|
|
1345
|
-
method: "wallet_getSession"
|
|
1346
|
-
});
|
|
1347
|
-
if (sessionRequest.error) {
|
|
1348
|
-
return resumeReject(new Error(sessionRequest.error.message));
|
|
1349
|
-
}
|
|
1350
|
-
let walletSession = sessionRequest.result;
|
|
1351
|
-
if (walletSession && options) {
|
|
1352
|
-
const currentScopes = Object.keys(
|
|
1353
|
-
(_a3 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a3 : {}
|
|
1354
|
-
);
|
|
1355
|
-
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
1356
|
-
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
1357
|
-
const hasSameScopesAndAccounts = isSameScopesAndAccounts(
|
|
1358
|
-
currentScopes,
|
|
1359
|
-
proposedScopes,
|
|
1360
|
-
walletSession,
|
|
1361
|
-
proposedCaipAccountIds
|
|
1362
|
-
);
|
|
1363
|
-
if (options.forceRequest || !hasSameScopesAndAccounts) {
|
|
1364
|
-
const optionalScopes = addValidAccounts(
|
|
1365
|
-
getOptionalScopes((_d = options == null ? void 0 : options.scopes) != null ? _d : []),
|
|
1366
|
-
getValidAccounts((_e = options == null ? void 0 : options.caipAccountIds) != null ? _e : [])
|
|
1367
|
-
);
|
|
1368
|
-
const sessionRequest2 = {
|
|
1369
|
-
optionalScopes
|
|
1370
|
-
};
|
|
1371
|
-
const response = yield this.request({
|
|
1372
|
-
method: "wallet_createSession",
|
|
1373
|
-
params: sessionRequest2
|
|
1374
|
-
});
|
|
1375
|
-
if (response.error) {
|
|
1376
|
-
return resumeReject(new Error(response.error.message));
|
|
1377
|
-
}
|
|
1378
|
-
walletSession = response.result;
|
|
1379
|
-
}
|
|
1380
|
-
} else if (!walletSession) {
|
|
1381
|
-
const optionalScopes = addValidAccounts(
|
|
1382
|
-
getOptionalScopes((_f = options == null ? void 0 : options.scopes) != null ? _f : []),
|
|
1383
|
-
getValidAccounts((_g = options == null ? void 0 : options.caipAccountIds) != null ? _g : [])
|
|
1384
|
-
);
|
|
1385
|
-
const sessionRequest2 = { optionalScopes };
|
|
1386
|
-
const response = yield this.request({
|
|
1387
|
-
method: "wallet_createSession",
|
|
1388
|
-
params: sessionRequest2
|
|
1389
|
-
});
|
|
1390
|
-
if (response.error) {
|
|
1391
|
-
return resumeReject(new Error(response.error.message));
|
|
1392
|
-
}
|
|
1393
|
-
walletSession = response.result;
|
|
1394
|
-
}
|
|
1395
|
-
yield this.removeStoredPendingSessionRequest();
|
|
1396
|
-
this.notifyCallbacks({
|
|
1397
|
-
method: "wallet_sessionChanged",
|
|
1398
|
-
params: walletSession
|
|
1399
|
-
});
|
|
1400
|
-
return resumeResolve();
|
|
1401
|
-
} catch (err) {
|
|
1402
|
-
return resumeReject(err);
|
|
1403
|
-
}
|
|
1404
|
-
});
|
|
1405
|
-
}
|
|
1406
1382
|
init() {
|
|
1407
1383
|
return __async(this, null, function* () {
|
|
1408
1384
|
});
|
|
@@ -1443,7 +1419,6 @@ var init_mwp = __esm({
|
|
|
1443
1419
|
}
|
|
1444
1420
|
connect(options) {
|
|
1445
1421
|
return __async(this, null, function* () {
|
|
1446
|
-
const { dappClient } = this;
|
|
1447
1422
|
const session = yield this.getActiveSession();
|
|
1448
1423
|
if (session) {
|
|
1449
1424
|
logger("active session found", {
|
|
@@ -1452,116 +1427,11 @@ var init_mwp = __esm({
|
|
|
1452
1427
|
expiresAt: session.expiresAt
|
|
1453
1428
|
});
|
|
1454
1429
|
}
|
|
1455
|
-
const
|
|
1456
|
-
|
|
1457
|
-
let initialConnectionMessageHandler;
|
|
1458
|
-
const connectionPromise = new Promise((resolve, reject) => __async(this, null, function* () {
|
|
1459
|
-
let connection;
|
|
1460
|
-
if (session) {
|
|
1461
|
-
connection = new Promise((resumeResolve, resumeReject) => {
|
|
1462
|
-
var _a3;
|
|
1463
|
-
if (this.dappClient.state === "CONNECTED") {
|
|
1464
|
-
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
1465
|
-
} else {
|
|
1466
|
-
this.dappClient.once("connected", () => __async(this, null, function* () {
|
|
1467
|
-
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
1468
|
-
}));
|
|
1469
|
-
dappClient.resume((_a3 = session == null ? void 0 : session.id) != null ? _a3 : "");
|
|
1470
|
-
}
|
|
1471
|
-
});
|
|
1472
|
-
} else {
|
|
1473
|
-
connection = new Promise(
|
|
1474
|
-
(resolveConnection, rejectConnection) => {
|
|
1475
|
-
var _a3, _b;
|
|
1476
|
-
const optionalScopes = addValidAccounts(
|
|
1477
|
-
getOptionalScopes((_a3 = options == null ? void 0 : options.scopes) != null ? _a3 : []),
|
|
1478
|
-
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
1479
|
-
);
|
|
1480
|
-
const sessionRequest = {
|
|
1481
|
-
optionalScopes,
|
|
1482
|
-
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
1483
|
-
};
|
|
1484
|
-
const request = {
|
|
1485
|
-
jsonrpc: "2.0",
|
|
1486
|
-
id: String(getUniqueRequestId()),
|
|
1487
|
-
method: "wallet_createSession",
|
|
1488
|
-
params: sessionRequest
|
|
1489
|
-
};
|
|
1490
|
-
initialConnectionMessageHandler = (message) => __async(this, null, function* () {
|
|
1491
|
-
if (typeof message !== "object" || message === null) {
|
|
1492
|
-
return;
|
|
1493
|
-
}
|
|
1494
|
-
if (!("data" in message)) {
|
|
1495
|
-
return;
|
|
1496
|
-
}
|
|
1497
|
-
const messagePayload = message.data;
|
|
1498
|
-
const isMatchingId = messagePayload.id === request.id;
|
|
1499
|
-
const isMatchingMethod = messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged";
|
|
1500
|
-
if (!isMatchingId && !isMatchingMethod) {
|
|
1501
|
-
return;
|
|
1502
|
-
}
|
|
1503
|
-
if (messagePayload.error) {
|
|
1504
|
-
return rejectConnection(
|
|
1505
|
-
this.parseWalletError(messagePayload.error)
|
|
1506
|
-
);
|
|
1507
|
-
}
|
|
1508
|
-
yield this.storeWalletSession(
|
|
1509
|
-
request,
|
|
1510
|
-
messagePayload
|
|
1511
|
-
);
|
|
1512
|
-
yield this.removeStoredPendingSessionRequest();
|
|
1513
|
-
this.notifyCallbacks(messagePayload);
|
|
1514
|
-
return resolveConnection();
|
|
1515
|
-
});
|
|
1516
|
-
this.dappClient.on("message", initialConnectionMessageHandler);
|
|
1517
|
-
const platformType = getPlatformType();
|
|
1518
|
-
const isQRCodeFlow = [
|
|
1519
|
-
"web-desktop" /* DesktopWeb */,
|
|
1520
|
-
"nodejs" /* NonBrowser */
|
|
1521
|
-
].includes(platformType);
|
|
1522
|
-
const initialPayload = {
|
|
1523
|
-
name: MULTICHAIN_PROVIDER_STREAM_NAME,
|
|
1524
|
-
data: request
|
|
1525
|
-
};
|
|
1526
|
-
dappClient.connect({
|
|
1527
|
-
mode: "trusted",
|
|
1528
|
-
initialPayload: isQRCodeFlow ? void 0 : initialPayload
|
|
1529
|
-
}).then(() => __async(this, null, function* () {
|
|
1530
|
-
if (isQRCodeFlow) {
|
|
1531
|
-
return dappClient.sendRequest(initialPayload);
|
|
1532
|
-
}
|
|
1533
|
-
return void 0;
|
|
1534
|
-
})).catch((error) => {
|
|
1535
|
-
if (initialConnectionMessageHandler) {
|
|
1536
|
-
this.dappClient.off(
|
|
1537
|
-
"message",
|
|
1538
|
-
initialConnectionMessageHandler
|
|
1539
|
-
);
|
|
1540
|
-
}
|
|
1541
|
-
rejectConnection(error);
|
|
1542
|
-
});
|
|
1543
|
-
}
|
|
1544
|
-
);
|
|
1545
|
-
}
|
|
1546
|
-
timeout = setTimeout(
|
|
1547
|
-
() => {
|
|
1548
|
-
reject(new import_multichain_api_client2.TransportTimeoutError());
|
|
1549
|
-
},
|
|
1550
|
-
storedSessionRequestBeforeConnectionAttempt ? this.options.resumeTimeout : this.options.connectionTimeout
|
|
1551
|
-
);
|
|
1552
|
-
connection.then(resolve).catch(reject);
|
|
1553
|
-
}));
|
|
1554
|
-
return connectionPromise.catch((error) => __async(this, null, function* () {
|
|
1430
|
+
const connection = session ? __privateMethod(this, _MWPTransport_instances, resumeSession_fn).call(this, session, options) : __privateMethod(this, _MWPTransport_instances, startSession_fn).call(this, options);
|
|
1431
|
+
return connection.catch((error) => __async(this, null, function* () {
|
|
1555
1432
|
yield this.dappClient.disconnect();
|
|
1556
1433
|
throw error;
|
|
1557
1434
|
})).finally(() => {
|
|
1558
|
-
if (timeout) {
|
|
1559
|
-
clearTimeout(timeout);
|
|
1560
|
-
}
|
|
1561
|
-
if (initialConnectionMessageHandler) {
|
|
1562
|
-
this.dappClient.off("message", initialConnectionMessageHandler);
|
|
1563
|
-
initialConnectionMessageHandler = void 0;
|
|
1564
|
-
}
|
|
1565
1435
|
this.removeStoredPendingSessionRequest();
|
|
1566
1436
|
});
|
|
1567
1437
|
});
|
|
@@ -1820,6 +1690,188 @@ var init_mwp = __esm({
|
|
|
1820
1690
|
});
|
|
1821
1691
|
}
|
|
1822
1692
|
};
|
|
1693
|
+
_MWPTransport_instances = new WeakSet();
|
|
1694
|
+
onResumeHandler_fn = function(options) {
|
|
1695
|
+
return __async(this, null, function* () {
|
|
1696
|
+
var _a3, _b, _c, _d, _e, _f, _g;
|
|
1697
|
+
yield this.waitForWalletSessionIfNotCached();
|
|
1698
|
+
const sessionResponse = yield this.request({ method: "wallet_getSession" });
|
|
1699
|
+
if (sessionResponse.error) {
|
|
1700
|
+
throw new Error(sessionResponse.error.message);
|
|
1701
|
+
}
|
|
1702
|
+
let walletSession = sessionResponse.result;
|
|
1703
|
+
if (walletSession && options) {
|
|
1704
|
+
const currentScopes = Object.keys(
|
|
1705
|
+
(_a3 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a3 : {}
|
|
1706
|
+
);
|
|
1707
|
+
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
1708
|
+
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
1709
|
+
const hasSameScopesAndAccounts = isSameScopesAndAccounts(
|
|
1710
|
+
currentScopes,
|
|
1711
|
+
proposedScopes,
|
|
1712
|
+
walletSession,
|
|
1713
|
+
proposedCaipAccountIds
|
|
1714
|
+
);
|
|
1715
|
+
if (options.forceRequest || !hasSameScopesAndAccounts) {
|
|
1716
|
+
const optionalScopes = addValidAccounts(
|
|
1717
|
+
getOptionalScopes((_d = options == null ? void 0 : options.scopes) != null ? _d : []),
|
|
1718
|
+
getValidAccounts((_e = options == null ? void 0 : options.caipAccountIds) != null ? _e : [])
|
|
1719
|
+
);
|
|
1720
|
+
const sessionRequest = {
|
|
1721
|
+
optionalScopes
|
|
1722
|
+
};
|
|
1723
|
+
const response = yield this.request({
|
|
1724
|
+
method: "wallet_createSession",
|
|
1725
|
+
params: sessionRequest
|
|
1726
|
+
});
|
|
1727
|
+
if (response.error) {
|
|
1728
|
+
throw new Error(response.error.message);
|
|
1729
|
+
}
|
|
1730
|
+
walletSession = response.result;
|
|
1731
|
+
}
|
|
1732
|
+
} else if (!walletSession) {
|
|
1733
|
+
const optionalScopes = addValidAccounts(
|
|
1734
|
+
getOptionalScopes((_f = options == null ? void 0 : options.scopes) != null ? _f : []),
|
|
1735
|
+
getValidAccounts((_g = options == null ? void 0 : options.caipAccountIds) != null ? _g : [])
|
|
1736
|
+
);
|
|
1737
|
+
const sessionRequest = {
|
|
1738
|
+
optionalScopes
|
|
1739
|
+
};
|
|
1740
|
+
const response = yield this.request({
|
|
1741
|
+
method: "wallet_createSession",
|
|
1742
|
+
params: sessionRequest
|
|
1743
|
+
});
|
|
1744
|
+
if (response.error) {
|
|
1745
|
+
throw new Error(response.error.message);
|
|
1746
|
+
}
|
|
1747
|
+
walletSession = response.result;
|
|
1748
|
+
}
|
|
1749
|
+
yield this.removeStoredPendingSessionRequest();
|
|
1750
|
+
this.notifyCallbacks({
|
|
1751
|
+
method: "wallet_sessionChanged",
|
|
1752
|
+
params: walletSession
|
|
1753
|
+
});
|
|
1754
|
+
});
|
|
1755
|
+
};
|
|
1756
|
+
resumeSession_fn = function(session, options) {
|
|
1757
|
+
return __async(this, null, function* () {
|
|
1758
|
+
var _a3;
|
|
1759
|
+
const isContinuingPriorAttempt = (yield this.getStoredPendingSessionRequest()) !== null;
|
|
1760
|
+
const resumeDeferred = (0, import_utils6.createDeferredPromise)();
|
|
1761
|
+
const runOnResumeHandler = () => __async(this, null, function* () {
|
|
1762
|
+
try {
|
|
1763
|
+
resumeDeferred.resolve(yield __privateMethod(this, _MWPTransport_instances, onResumeHandler_fn).call(this, options));
|
|
1764
|
+
} catch (err) {
|
|
1765
|
+
resumeDeferred.reject(err);
|
|
1766
|
+
}
|
|
1767
|
+
});
|
|
1768
|
+
if (this.dappClient.state === "CONNECTED") {
|
|
1769
|
+
runOnResumeHandler();
|
|
1770
|
+
} else {
|
|
1771
|
+
this.dappClient.once("connected", runOnResumeHandler);
|
|
1772
|
+
this.dappClient.resume((_a3 = session.id) != null ? _a3 : "").catch((err) => resumeDeferred.reject(err));
|
|
1773
|
+
}
|
|
1774
|
+
const timeoutDeferred = (0, import_utils6.createDeferredPromise)();
|
|
1775
|
+
const timeout = setTimeout(
|
|
1776
|
+
() => timeoutDeferred.reject(new import_multichain_api_client2.TransportTimeoutError()),
|
|
1777
|
+
isContinuingPriorAttempt ? this.options.resumeTimeout : this.options.connectionTimeout
|
|
1778
|
+
);
|
|
1779
|
+
const cleanup = () => this.dappClient.off("connected", runOnResumeHandler);
|
|
1780
|
+
return Promise.race([
|
|
1781
|
+
resumeDeferred.promise,
|
|
1782
|
+
timeoutDeferred.promise
|
|
1783
|
+
]).finally(() => {
|
|
1784
|
+
clearTimeout(timeout);
|
|
1785
|
+
cleanup();
|
|
1786
|
+
});
|
|
1787
|
+
});
|
|
1788
|
+
};
|
|
1789
|
+
startSession_fn = function(options) {
|
|
1790
|
+
return __async(this, null, function* () {
|
|
1791
|
+
var _a3, _b;
|
|
1792
|
+
const { dappClient } = this;
|
|
1793
|
+
const isContinuingPriorAttempt = (yield this.getStoredPendingSessionRequest()) !== null;
|
|
1794
|
+
const connDeferred = (0, import_utils6.createDeferredPromise)();
|
|
1795
|
+
const optionalScopes = addValidAccounts(
|
|
1796
|
+
getOptionalScopes((_a3 = options == null ? void 0 : options.scopes) != null ? _a3 : []),
|
|
1797
|
+
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
1798
|
+
);
|
|
1799
|
+
const sessionRequest = {
|
|
1800
|
+
optionalScopes,
|
|
1801
|
+
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
1802
|
+
};
|
|
1803
|
+
const request = {
|
|
1804
|
+
jsonrpc: "2.0",
|
|
1805
|
+
id: String(getUniqueRequestId()),
|
|
1806
|
+
method: "wallet_createSession",
|
|
1807
|
+
params: sessionRequest
|
|
1808
|
+
};
|
|
1809
|
+
let handler;
|
|
1810
|
+
const removeHandler = () => {
|
|
1811
|
+
if (handler) {
|
|
1812
|
+
this.dappClient.off("message", handler);
|
|
1813
|
+
handler = void 0;
|
|
1814
|
+
}
|
|
1815
|
+
};
|
|
1816
|
+
handler = (message) => __async(this, null, function* () {
|
|
1817
|
+
if (typeof message !== "object" || message === null) {
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1820
|
+
if (!("data" in message)) {
|
|
1821
|
+
return;
|
|
1822
|
+
}
|
|
1823
|
+
const messagePayload = message.data;
|
|
1824
|
+
const isMatchingId = messagePayload.id === request.id;
|
|
1825
|
+
const isMatchingMethod = messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged";
|
|
1826
|
+
if (!isMatchingId && !isMatchingMethod) {
|
|
1827
|
+
return;
|
|
1828
|
+
}
|
|
1829
|
+
const responseError = this.getResponseError(messagePayload);
|
|
1830
|
+
if (responseError) {
|
|
1831
|
+
connDeferred.reject(this.parseWalletError(responseError));
|
|
1832
|
+
return;
|
|
1833
|
+
}
|
|
1834
|
+
yield this.storeWalletSession(
|
|
1835
|
+
request,
|
|
1836
|
+
messagePayload
|
|
1837
|
+
);
|
|
1838
|
+
yield this.removeStoredPendingSessionRequest();
|
|
1839
|
+
this.notifyCallbacks(messagePayload);
|
|
1840
|
+
connDeferred.resolve();
|
|
1841
|
+
});
|
|
1842
|
+
this.dappClient.on("message", handler);
|
|
1843
|
+
const platformType = getPlatformType();
|
|
1844
|
+
const isQRCodeFlow = [
|
|
1845
|
+
"web-desktop" /* DesktopWeb */,
|
|
1846
|
+
"nodejs" /* NonBrowser */
|
|
1847
|
+
].includes(platformType);
|
|
1848
|
+
const initialPayload = {
|
|
1849
|
+
name: MULTICHAIN_PROVIDER_STREAM_NAME,
|
|
1850
|
+
data: request
|
|
1851
|
+
};
|
|
1852
|
+
dappClient.connect({
|
|
1853
|
+
mode: "trusted",
|
|
1854
|
+
initialPayload: isQRCodeFlow ? void 0 : initialPayload
|
|
1855
|
+
}).then(() => __async(this, null, function* () {
|
|
1856
|
+
if (isQRCodeFlow) {
|
|
1857
|
+
return dappClient.sendRequest(initialPayload);
|
|
1858
|
+
}
|
|
1859
|
+
return void 0;
|
|
1860
|
+
})).catch((error) => connDeferred.reject(error));
|
|
1861
|
+
const timeoutDeferred = (0, import_utils6.createDeferredPromise)();
|
|
1862
|
+
const timeout = setTimeout(
|
|
1863
|
+
() => timeoutDeferred.reject(new import_multichain_api_client2.TransportTimeoutError()),
|
|
1864
|
+
isContinuingPriorAttempt ? this.options.resumeTimeout : this.options.connectionTimeout
|
|
1865
|
+
);
|
|
1866
|
+
return Promise.race([
|
|
1867
|
+
connDeferred.promise,
|
|
1868
|
+
timeoutDeferred.promise
|
|
1869
|
+
]).finally(() => {
|
|
1870
|
+
clearTimeout(timeout);
|
|
1871
|
+
removeHandler();
|
|
1872
|
+
});
|
|
1873
|
+
});
|
|
1874
|
+
};
|
|
1823
1875
|
}
|
|
1824
1876
|
});
|
|
1825
1877
|
|
|
@@ -1992,9 +2044,7 @@ var init_install = __esm({
|
|
|
1992
2044
|
mount() {
|
|
1993
2045
|
var _a3;
|
|
1994
2046
|
const { options } = this;
|
|
1995
|
-
const modal = document.createElement(
|
|
1996
|
-
"mm-install-modal"
|
|
1997
|
-
);
|
|
2047
|
+
const modal = document.createElement("mm-install-modal");
|
|
1998
2048
|
modal.showInstallModal = options.showInstallModal;
|
|
1999
2049
|
modal.addEventListener("close", (ev) => {
|
|
2000
2050
|
const { detail } = ev;
|
|
@@ -2178,6 +2228,7 @@ var init_web2 = __esm({
|
|
|
2178
2228
|
// src/index.browser.ts
|
|
2179
2229
|
var index_browser_exports = {};
|
|
2180
2230
|
__export(index_browser_exports, {
|
|
2231
|
+
EIP1193_PASSTHROUGH_METHODS: () => EIP1193_PASSTHROUGH_METHODS,
|
|
2181
2232
|
EventEmitter: () => EventEmitter,
|
|
2182
2233
|
Modal: () => Modal,
|
|
2183
2234
|
MultichainCore: () => MultichainCore,
|
|
@@ -2205,7 +2256,8 @@ __export(index_browser_exports, {
|
|
|
2205
2256
|
isEnabled: () => isEnabled,
|
|
2206
2257
|
isMetamaskExtensionInstalled: () => isMetamaskExtensionInstalled,
|
|
2207
2258
|
isRejectionError: () => isRejectionError,
|
|
2208
|
-
isSecure: () => isSecure
|
|
2259
|
+
isSecure: () => isSecure,
|
|
2260
|
+
packageVersion: () => packageVersion
|
|
2209
2261
|
});
|
|
2210
2262
|
module.exports = __toCommonJS(index_browser_exports);
|
|
2211
2263
|
|
|
@@ -2222,6 +2274,7 @@ init_domain();
|
|
|
2222
2274
|
// src/multichain/index.ts
|
|
2223
2275
|
var import_analytics4 = require("@metamask/analytics");
|
|
2224
2276
|
var import_multichain_api_client3 = require("@metamask/multichain-api-client");
|
|
2277
|
+
var import_utils8 = require("@metamask/utils");
|
|
2225
2278
|
|
|
2226
2279
|
// src/config/index.ts
|
|
2227
2280
|
var MWP_RELAY_URL = "wss://mm-sdk-relay.api.cx.metamask.io/connection/websocket";
|
|
@@ -2345,6 +2398,17 @@ var import_analytics2 = require("@metamask/analytics");
|
|
|
2345
2398
|
init_domain();
|
|
2346
2399
|
init_utils2();
|
|
2347
2400
|
init_analytics();
|
|
2401
|
+
function toRPCInvokeMethodErr(error) {
|
|
2402
|
+
var _a3;
|
|
2403
|
+
if (error instanceof RPCInvokeMethodErr) {
|
|
2404
|
+
return error;
|
|
2405
|
+
}
|
|
2406
|
+
const castError = error;
|
|
2407
|
+
return new RPCInvokeMethodErr(
|
|
2408
|
+
(_a3 = castError.message) != null ? _a3 : "Unknown error",
|
|
2409
|
+
castError.code
|
|
2410
|
+
);
|
|
2411
|
+
}
|
|
2348
2412
|
var _RequestRouter_instances, withAnalyticsTracking_fn, trackWalletActionRequested_fn, trackWalletActionSucceeded_fn, trackWalletActionFailed_fn, trackWalletActionRejected_fn;
|
|
2349
2413
|
var RequestRouter = class {
|
|
2350
2414
|
constructor(transport, rpcClient, config, transportType) {
|
|
@@ -2364,6 +2428,9 @@ var RequestRouter = class {
|
|
|
2364
2428
|
invokeMethod(options) {
|
|
2365
2429
|
return __async(this, null, function* () {
|
|
2366
2430
|
const { method } = options.request;
|
|
2431
|
+
if (EIP1193_PASSTHROUGH_METHODS.has(method)) {
|
|
2432
|
+
return this.handleWithEip1193Passthrough(options);
|
|
2433
|
+
}
|
|
2367
2434
|
if (RPC_HANDLED_METHODS.has(method)) {
|
|
2368
2435
|
return this.handleWithRpcNode(options);
|
|
2369
2436
|
}
|
|
@@ -2373,6 +2440,29 @@ var RequestRouter = class {
|
|
|
2373
2440
|
return this.handleWithWallet(options);
|
|
2374
2441
|
});
|
|
2375
2442
|
}
|
|
2443
|
+
/**
|
|
2444
|
+
* Forwards EIP-1193 / legacy provider methods (e.g. `wallet_addEthereumChain`,
|
|
2445
|
+
* `wallet_switchEthereumChain`, `eth_accounts`) directly to the underlying
|
|
2446
|
+
* transport's `sendEip1193Message`, bypassing the multichain
|
|
2447
|
+
* `wallet_invokeMethod` envelope. These methods are wallet-side concerns the
|
|
2448
|
+
* Multichain API does not model, so we forward the raw `{ method, params }`
|
|
2449
|
+
* payload and return the wallet's full JSON-RPC response envelope unchanged.
|
|
2450
|
+
*
|
|
2451
|
+
* Analytics tracking is intentionally skipped here: ecosystem clients
|
|
2452
|
+
* (e.g. `connect-evm`) emit their own `wallet_action_*` events around these
|
|
2453
|
+
* passthrough calls, and adding router-level tracking would double-count.
|
|
2454
|
+
*
|
|
2455
|
+
* @param options
|
|
2456
|
+
*/
|
|
2457
|
+
handleWithEip1193Passthrough(options) {
|
|
2458
|
+
return __async(this, null, function* () {
|
|
2459
|
+
const response = yield this.transport.sendEip1193Message({
|
|
2460
|
+
method: options.request.method,
|
|
2461
|
+
params: options.request.params
|
|
2462
|
+
});
|
|
2463
|
+
return response.result;
|
|
2464
|
+
});
|
|
2465
|
+
}
|
|
2376
2466
|
/**
|
|
2377
2467
|
* Forwards the request directly to the wallet via the transport.
|
|
2378
2468
|
*
|
|
@@ -2404,14 +2494,6 @@ var RequestRouter = class {
|
|
|
2404
2494
|
}), 10);
|
|
2405
2495
|
}
|
|
2406
2496
|
const response = yield request;
|
|
2407
|
-
if (response.error) {
|
|
2408
|
-
const { error } = response;
|
|
2409
|
-
throw new RPCInvokeMethodErr(
|
|
2410
|
-
`RPC Request failed with code ${error.code}: ${error.message}`,
|
|
2411
|
-
error.code,
|
|
2412
|
-
error.message
|
|
2413
|
-
);
|
|
2414
|
-
}
|
|
2415
2497
|
return response.result;
|
|
2416
2498
|
}));
|
|
2417
2499
|
});
|
|
@@ -2451,6 +2533,13 @@ _RequestRouter_instances = new WeakSet();
|
|
|
2451
2533
|
withAnalyticsTracking_fn = function(options, execute) {
|
|
2452
2534
|
return __async(this, null, function* () {
|
|
2453
2535
|
var _a3;
|
|
2536
|
+
if (((_a3 = this.config.analytics) == null ? void 0 : _a3.enabled) === false) {
|
|
2537
|
+
try {
|
|
2538
|
+
return yield execute();
|
|
2539
|
+
} catch (error) {
|
|
2540
|
+
throw toRPCInvokeMethodErr(error);
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2454
2543
|
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRequested_fn).call(this, options);
|
|
2455
2544
|
try {
|
|
2456
2545
|
const result = yield execute();
|
|
@@ -2463,14 +2552,7 @@ withAnalyticsTracking_fn = function(options, execute) {
|
|
|
2463
2552
|
} else {
|
|
2464
2553
|
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options, error);
|
|
2465
2554
|
}
|
|
2466
|
-
|
|
2467
|
-
throw error;
|
|
2468
|
-
}
|
|
2469
|
-
const castError = error;
|
|
2470
|
-
throw new RPCInvokeMethodErr(
|
|
2471
|
-
(_a3 = castError.message) != null ? _a3 : "Unknown error",
|
|
2472
|
-
castError.code
|
|
2473
|
-
);
|
|
2555
|
+
throw toRPCInvokeMethodErr(error);
|
|
2474
2556
|
}
|
|
2475
2557
|
});
|
|
2476
2558
|
};
|
|
@@ -2524,7 +2606,7 @@ trackWalletActionRejected_fn = function(options) {
|
|
|
2524
2606
|
var import_multichain_api_client = require("@metamask/multichain-api-client");
|
|
2525
2607
|
init_utils2();
|
|
2526
2608
|
var DEFAULT_REQUEST_TIMEOUT = 60 * 1e3;
|
|
2527
|
-
var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn, init_fn;
|
|
2609
|
+
var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, parseWalletError_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn, init_fn;
|
|
2528
2610
|
var DefaultTransport = class {
|
|
2529
2611
|
constructor() {
|
|
2530
2612
|
__privateAdd(this, _DefaultTransport_instances);
|
|
@@ -2660,7 +2742,11 @@ var DefaultTransport = class {
|
|
|
2660
2742
|
}
|
|
2661
2743
|
request(_0) {
|
|
2662
2744
|
return __async(this, arguments, function* (request, options = __privateGet(this, _defaultRequestOptions)) {
|
|
2663
|
-
|
|
2745
|
+
const response = yield __privateGet(this, _transport).request(request, options);
|
|
2746
|
+
if (response.error) {
|
|
2747
|
+
throw __privateMethod(this, _DefaultTransport_instances, parseWalletError_fn).call(this, response.error);
|
|
2748
|
+
}
|
|
2749
|
+
return response;
|
|
2664
2750
|
});
|
|
2665
2751
|
}
|
|
2666
2752
|
onNotification(callback) {
|
|
@@ -2704,6 +2790,16 @@ notifyCallbacks_fn = function(data) {
|
|
|
2704
2790
|
}
|
|
2705
2791
|
}
|
|
2706
2792
|
};
|
|
2793
|
+
parseWalletError_fn = function(errorPayload) {
|
|
2794
|
+
const errorData = errorPayload;
|
|
2795
|
+
const error = new Error(
|
|
2796
|
+
typeof errorData.message === "string" ? errorData.message : "Request failed"
|
|
2797
|
+
);
|
|
2798
|
+
if (typeof errorData.code === "number") {
|
|
2799
|
+
error.code = errorData.code;
|
|
2800
|
+
}
|
|
2801
|
+
return error;
|
|
2802
|
+
};
|
|
2707
2803
|
isMetamaskProviderEvent_fn = function(event) {
|
|
2708
2804
|
var _a3, _b;
|
|
2709
2805
|
return ((_b = (_a3 = event == null ? void 0 : event.data) == null ? void 0 : _a3.data) == null ? void 0 : _b.name) === "metamask-provider" && // eslint-disable-next-line no-restricted-globals
|
|
@@ -2726,13 +2822,7 @@ handleResponse_fn = function(event) {
|
|
|
2726
2822
|
__privateGet(this, _pendingRequests).delete(responseId);
|
|
2727
2823
|
const response = responseData;
|
|
2728
2824
|
if ("error" in response && response.error) {
|
|
2729
|
-
|
|
2730
|
-
response.error.message || "Request failed"
|
|
2731
|
-
);
|
|
2732
|
-
if (typeof response.error.code === "number") {
|
|
2733
|
-
error.code = response.error.code;
|
|
2734
|
-
}
|
|
2735
|
-
pendingRequest.reject(error);
|
|
2825
|
+
pendingRequest.reject(__privateMethod(this, _DefaultTransport_instances, parseWalletError_fn).call(this, response.error));
|
|
2736
2826
|
} else {
|
|
2737
2827
|
pendingRequest.resolve(response);
|
|
2738
2828
|
}
|
|
@@ -2770,22 +2860,21 @@ init_fn = function() {
|
|
|
2770
2860
|
// src/multichain/transports/multichainApiClientWrapper/index.ts
|
|
2771
2861
|
var import_rpc_errors = require("@metamask/rpc-errors");
|
|
2772
2862
|
init_utils2();
|
|
2773
|
-
var _notificationCallbacks2, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
2863
|
+
var _notificationCallbacks2, _getTransport, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
2774
2864
|
var MultichainApiClientWrapperTransport = class {
|
|
2775
|
-
constructor(metamaskConnectMultichain) {
|
|
2865
|
+
constructor(metamaskConnectMultichain, getTransport) {
|
|
2776
2866
|
this.metamaskConnectMultichain = metamaskConnectMultichain;
|
|
2777
2867
|
__privateAdd(this, _MultichainApiClientWrapperTransport_instances);
|
|
2778
2868
|
__privateAdd(this, _notificationCallbacks2, /* @__PURE__ */ new Set());
|
|
2869
|
+
__privateAdd(this, _getTransport);
|
|
2870
|
+
__privateSet(this, _getTransport, getTransport);
|
|
2779
2871
|
}
|
|
2780
2872
|
isTransportDefined() {
|
|
2781
|
-
|
|
2782
|
-
return Boolean(this.metamaskConnectMultichain.transport);
|
|
2783
|
-
} catch (_error) {
|
|
2784
|
-
return false;
|
|
2785
|
-
}
|
|
2873
|
+
return __privateGet(this, _getTransport).call(this) !== void 0;
|
|
2786
2874
|
}
|
|
2787
2875
|
isTransportConnected() {
|
|
2788
|
-
|
|
2876
|
+
var _a3, _b;
|
|
2877
|
+
return (_b = (_a3 = __privateGet(this, _getTransport).call(this)) == null ? void 0 : _a3.isConnected()) != null ? _b : false;
|
|
2789
2878
|
}
|
|
2790
2879
|
clearNotificationCallbacks() {
|
|
2791
2880
|
__privateGet(this, _notificationCallbacks2).clear();
|
|
@@ -2801,10 +2890,11 @@ var MultichainApiClientWrapperTransport = class {
|
|
|
2801
2890
|
this.notificationListener = void 0;
|
|
2802
2891
|
}
|
|
2803
2892
|
setupTransportNotificationListener() {
|
|
2804
|
-
|
|
2893
|
+
const transport = __privateGet(this, _getTransport).call(this);
|
|
2894
|
+
if (!transport || this.notificationListener) {
|
|
2805
2895
|
return;
|
|
2806
2896
|
}
|
|
2807
|
-
this.notificationListener =
|
|
2897
|
+
this.notificationListener = transport.onNotification(
|
|
2808
2898
|
this.notifyCallbacks.bind(this)
|
|
2809
2899
|
);
|
|
2810
2900
|
}
|
|
@@ -2854,6 +2944,7 @@ var MultichainApiClientWrapperTransport = class {
|
|
|
2854
2944
|
}
|
|
2855
2945
|
};
|
|
2856
2946
|
_notificationCallbacks2 = new WeakMap();
|
|
2947
|
+
_getTransport = new WeakMap();
|
|
2857
2948
|
_MultichainApiClientWrapperTransport_instances = new WeakSet();
|
|
2858
2949
|
walletCreateSession_fn = function(request) {
|
|
2859
2950
|
return __async(this, null, function* () {
|
|
@@ -2877,14 +2968,19 @@ walletCreateSession_fn = function(request) {
|
|
|
2877
2968
|
accounts,
|
|
2878
2969
|
createSessionParams.sessionProperties
|
|
2879
2970
|
);
|
|
2880
|
-
|
|
2971
|
+
const transport = __privateGet(this, _getTransport).call(this);
|
|
2972
|
+
if (!transport) {
|
|
2973
|
+
throw new Error("Transport not initialized after connect");
|
|
2974
|
+
}
|
|
2975
|
+
return transport.request({
|
|
2881
2976
|
method: "wallet_getSession"
|
|
2882
2977
|
});
|
|
2883
2978
|
});
|
|
2884
2979
|
};
|
|
2885
2980
|
walletGetSession_fn = function(request) {
|
|
2886
2981
|
return __async(this, null, function* () {
|
|
2887
|
-
|
|
2982
|
+
const transport = __privateGet(this, _getTransport).call(this);
|
|
2983
|
+
if (!(transport == null ? void 0 : transport.isConnected())) {
|
|
2888
2984
|
return {
|
|
2889
2985
|
jsonrpc: "2.0",
|
|
2890
2986
|
id: request.id,
|
|
@@ -2893,7 +2989,7 @@ walletGetSession_fn = function(request) {
|
|
|
2893
2989
|
}
|
|
2894
2990
|
};
|
|
2895
2991
|
}
|
|
2896
|
-
return
|
|
2992
|
+
return transport.request({
|
|
2897
2993
|
method: "wallet_getSession"
|
|
2898
2994
|
});
|
|
2899
2995
|
});
|
|
@@ -2929,26 +3025,63 @@ walletInvokeMethod_fn = function(request) {
|
|
|
2929
3025
|
init_utils2();
|
|
2930
3026
|
var logger2 = createLogger("metamask-sdk:core");
|
|
2931
3027
|
var SINGLETON_KEY = "__METAMASK_CONNECT_MULTICHAIN_SINGLETON__";
|
|
2932
|
-
|
|
3028
|
+
function normalizeAnalyticsOptions(analyticsOptions) {
|
|
3029
|
+
var _a3;
|
|
3030
|
+
return __spreadProps(__spreadValues({}, analyticsOptions != null ? analyticsOptions : {}), {
|
|
3031
|
+
enabled: (_a3 = analyticsOptions == null ? void 0 : analyticsOptions.enabled) != null ? _a3 : true,
|
|
3032
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
3033
|
+
integrationType: (analyticsOptions == null ? void 0 : analyticsOptions.integrationType) || "direct"
|
|
3034
|
+
});
|
|
3035
|
+
}
|
|
3036
|
+
function isAnalyticsEnabled(options) {
|
|
3037
|
+
var _a3;
|
|
3038
|
+
return ((_a3 = options.analytics) == null ? void 0 : _a3.enabled) !== false;
|
|
3039
|
+
}
|
|
3040
|
+
function setupAnalyticsGlobals(options, storage, setAnonId) {
|
|
3041
|
+
return __async(this, null, function* () {
|
|
3042
|
+
var _a3, _b;
|
|
3043
|
+
if (!isAnalyticsEnabled(options)) {
|
|
3044
|
+
setAnonId == null ? void 0 : setAnonId(void 0);
|
|
3045
|
+
import_analytics4.analytics.disable();
|
|
3046
|
+
return;
|
|
3047
|
+
}
|
|
3048
|
+
const platform = getPlatformType();
|
|
3049
|
+
const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
|
|
3050
|
+
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
3051
|
+
if (!isBrowser && !isReactNative2) {
|
|
3052
|
+
return;
|
|
3053
|
+
}
|
|
3054
|
+
const dappId = getDappId(options.dapp);
|
|
3055
|
+
const anonId = yield storage.getAnonId();
|
|
3056
|
+
setAnonId == null ? void 0 : setAnonId(anonId);
|
|
3057
|
+
const { integrationType } = (_a3 = options.analytics) != null ? _a3 : {
|
|
3058
|
+
integrationType: ""
|
|
3059
|
+
};
|
|
3060
|
+
import_analytics4.analytics.setGlobalProperty("mmconnect_versions", (_b = options.versions) != null ? _b : {});
|
|
3061
|
+
import_analytics4.analytics.setGlobalProperty("dapp_id", dappId);
|
|
3062
|
+
import_analytics4.analytics.setGlobalProperty("anon_id", anonId);
|
|
3063
|
+
import_analytics4.analytics.setGlobalProperty("platform", platform);
|
|
3064
|
+
if (integrationType) {
|
|
3065
|
+
import_analytics4.analytics.setGlobalProperty("integration_types", [integrationType]);
|
|
3066
|
+
}
|
|
3067
|
+
import_analytics4.analytics.enable();
|
|
3068
|
+
});
|
|
3069
|
+
}
|
|
3070
|
+
var _a2, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _transportType, _listener, _anonId, _MetaMaskConnectMultichain_instances, transportOrThrow_fn, _sdkInfo, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn, buildConnectionMetadata_fn, init_fn2, createDappClient_fn, setupMWP_fn, onBeforeUnload_fn, createBeforeUnloadListener_fn, renderInstallModalAsync_fn, showInstallModal_fn, headlessConnect_fn, setupDefaultTransport_fn, deeplinkConnect_fn, handleConnection_fn, getCaipSession_fn, openConnectDeeplinkIfNeeded_fn;
|
|
2933
3071
|
var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
|
|
2934
3072
|
constructor(options) {
|
|
2935
|
-
var _a3, _b, _c, _d
|
|
3073
|
+
var _a3, _b, _c, _d;
|
|
2936
3074
|
const withDappMetadata = setupDappMetadata(options);
|
|
2937
|
-
const integrationType = ((_a3 = options.analytics) == null ? void 0 : _a3.integrationType) || "direct";
|
|
2938
3075
|
const allOptions = __spreadProps(__spreadValues({}, withDappMetadata), {
|
|
2939
3076
|
ui: __spreadProps(__spreadValues({}, withDappMetadata.ui), {
|
|
2940
|
-
preferExtension: (
|
|
2941
|
-
showInstallModal: (
|
|
2942
|
-
headless: (
|
|
2943
|
-
}),
|
|
2944
|
-
analytics: __spreadProps(__spreadValues({}, (_e = options.analytics) != null ? _e : {}), {
|
|
2945
|
-
integrationType
|
|
3077
|
+
preferExtension: (_a3 = withDappMetadata.ui.preferExtension) != null ? _a3 : true,
|
|
3078
|
+
showInstallModal: (_b = withDappMetadata.ui.showInstallModal) != null ? _b : false,
|
|
3079
|
+
headless: (_c = withDappMetadata.ui.headless) != null ? _c : false
|
|
2946
3080
|
}),
|
|
3081
|
+
analytics: normalizeAnalyticsOptions(options.analytics),
|
|
2947
3082
|
versions: __spreadValues({
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
"connect-multichain": false ? "unknown" : "0.14.0"
|
|
2951
|
-
}, (_f = options.versions) != null ? _f : {})
|
|
3083
|
+
"connect-multichain": getVersion()
|
|
3084
|
+
}, (_d = options.versions) != null ? _d : {})
|
|
2952
3085
|
});
|
|
2953
3086
|
super(allOptions);
|
|
2954
3087
|
__privateAdd(this, _MetaMaskConnectMultichain_instances);
|
|
@@ -2963,7 +3096,8 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2963
3096
|
__privateAdd(this, _anonId);
|
|
2964
3097
|
__privateAdd(this, _sdkInfo, `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(_a2 = this.options.dapp.url) != null ? _a2 : this.options.dapp.name} dAppTitle/${this.options.dapp.name}`);
|
|
2965
3098
|
__privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(
|
|
2966
|
-
this
|
|
3099
|
+
this,
|
|
3100
|
+
() => __privateGet(this, _transport2)
|
|
2967
3101
|
));
|
|
2968
3102
|
__privateSet(this, _provider, (0, import_multichain_api_client3.getMultichainClient)({
|
|
2969
3103
|
transport: __privateGet(this, _providerTransportWrapper)
|
|
@@ -2982,12 +3116,6 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2982
3116
|
get provider() {
|
|
2983
3117
|
return __privateGet(this, _provider);
|
|
2984
3118
|
}
|
|
2985
|
-
get transport() {
|
|
2986
|
-
if (!__privateGet(this, _transport2)) {
|
|
2987
|
-
throw new Error("Transport not initialized, establish connection first");
|
|
2988
|
-
}
|
|
2989
|
-
return __privateGet(this, _transport2);
|
|
2990
|
-
}
|
|
2991
3119
|
get dappClient() {
|
|
2992
3120
|
if (!__privateGet(this, _dappClient)) {
|
|
2993
3121
|
throw new Error("DappClient not initialized, establish connection first");
|
|
@@ -3001,28 +3129,33 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3001
3129
|
get storage() {
|
|
3002
3130
|
return this.options.storage;
|
|
3003
3131
|
}
|
|
3132
|
+
get version() {
|
|
3133
|
+
return getVersion();
|
|
3134
|
+
}
|
|
3004
3135
|
// Creates a singleton instance of MetaMaskConnectMultichain.
|
|
3005
3136
|
// If the singleton already exists, it merges the incoming options with the
|
|
3006
3137
|
// existing singleton options for the following keys: `api.supportedNetworks`,
|
|
3007
|
-
// `versions`, `ui.*`, `mobile.*`, `transport.extensionId`,
|
|
3008
|
-
// that the value for `dapp` is not merged as it does not
|
|
3009
|
-
// subsequent calls to `createMultichainClient` to have a
|
|
3138
|
+
// `analytics`, `versions`, `ui.*`, `mobile.*`, `transport.extensionId`,
|
|
3139
|
+
// `debug`. Take note that the value for `dapp` is not merged as it does not
|
|
3140
|
+
// make sense for subsequent calls to `createMultichainClient` to have a
|
|
3141
|
+
// different `dapp` value.
|
|
3010
3142
|
static create(options) {
|
|
3011
3143
|
return __async(this, null, function* () {
|
|
3012
|
-
var _a3
|
|
3144
|
+
var _a3;
|
|
3013
3145
|
const globalObject = getGlobalObject();
|
|
3014
3146
|
const existing = globalObject[SINGLETON_KEY];
|
|
3015
3147
|
if (existing) {
|
|
3016
3148
|
const instance = yield existing;
|
|
3149
|
+
if (instance.version !== getVersion()) {
|
|
3150
|
+
console.warn(
|
|
3151
|
+
`MetaMask Connect does not support using multiple versions of @metamask/connect-multichain. Attempted to create a new instance with version ${getVersion()}, but an existing ${instance.version} singleton was already initialized. Using the existing ${instance.version} singleton. This is NOT supported and may lead to unexpected behavior. Please ensure there is only one version of @metamask/connect-multichain package resolved in your application.`
|
|
3152
|
+
);
|
|
3153
|
+
}
|
|
3017
3154
|
instance.mergeOptions(options);
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
if ((_b = options.analytics) == null ? void 0 : _b.integrationType) {
|
|
3023
|
-
import_analytics4.analytics.setGlobalProperty("integration_types", [
|
|
3024
|
-
options.analytics.integrationType
|
|
3025
|
-
]);
|
|
3155
|
+
if (instance instanceof _MetaMaskConnectMultichain) {
|
|
3156
|
+
yield __privateMethod(_a3 = instance, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(_a3);
|
|
3157
|
+
} else {
|
|
3158
|
+
yield setupAnalyticsGlobals(instance.options, instance.storage);
|
|
3026
3159
|
}
|
|
3027
3160
|
if (options.debug) {
|
|
3028
3161
|
enableDebug("metamask-sdk:*");
|
|
@@ -3041,12 +3174,12 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3041
3174
|
}
|
|
3042
3175
|
yield __privateMethod(_a4 = instance, _MetaMaskConnectMultichain_instances, init_fn2).call(_a4);
|
|
3043
3176
|
return instance;
|
|
3044
|
-
}))()
|
|
3045
|
-
globalObject[SINGLETON_KEY] = instancePromise;
|
|
3046
|
-
instancePromise.catch((error) => {
|
|
3177
|
+
}))().catch((error) => {
|
|
3047
3178
|
globalObject[SINGLETON_KEY] = void 0;
|
|
3048
3179
|
console.error("Error initializing MetaMaskConnectMultichain", error);
|
|
3180
|
+
throw error;
|
|
3049
3181
|
});
|
|
3182
|
+
globalObject[SINGLETON_KEY] = instancePromise;
|
|
3050
3183
|
return instancePromise;
|
|
3051
3184
|
});
|
|
3052
3185
|
}
|
|
@@ -3072,21 +3205,23 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3072
3205
|
} else {
|
|
3073
3206
|
transportType = "mwp" /* MWP */;
|
|
3074
3207
|
}
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3208
|
+
if (isAnalyticsEnabled(this.options)) {
|
|
3209
|
+
try {
|
|
3210
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
3211
|
+
this.options,
|
|
3212
|
+
this.storage
|
|
3213
|
+
);
|
|
3214
|
+
const dappConfiguredChains = Object.keys(
|
|
3215
|
+
this.options.api.supportedNetworks
|
|
3216
|
+
);
|
|
3217
|
+
import_analytics4.analytics.track("mmconnect_connection_initiated", __spreadProps(__spreadValues({}, baseProps), {
|
|
3218
|
+
transport_type: transportType,
|
|
3219
|
+
dapp_configured_chains: dappConfiguredChains,
|
|
3220
|
+
dapp_requested_chains: scopes
|
|
3221
|
+
}));
|
|
3222
|
+
} catch (error) {
|
|
3223
|
+
logger2("Error tracking connection_initiated event", error);
|
|
3224
|
+
}
|
|
3090
3225
|
}
|
|
3091
3226
|
const sessionData = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getCaipSession_fn).call(this);
|
|
3092
3227
|
const { mergedScopes, mergedCaipAccountIds, mergedSessionProperties } = mergeRequestedSessionWithExisting(
|
|
@@ -3104,9 +3239,9 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3104
3239
|
forceRequest
|
|
3105
3240
|
}).then(() => __async(this, null, function* () {
|
|
3106
3241
|
if (__privateGet(this, _transportType) === "mwp" /* MWP */) {
|
|
3107
|
-
return this.storage.
|
|
3242
|
+
return this.storage.setTransportType("mwp" /* MWP */);
|
|
3108
3243
|
}
|
|
3109
|
-
return this.storage.
|
|
3244
|
+
return this.storage.setTransportType("browser" /* Browser */);
|
|
3110
3245
|
})), scopes, transportType);
|
|
3111
3246
|
}
|
|
3112
3247
|
if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
|
|
@@ -3135,11 +3270,6 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3135
3270
|
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, showInstallModal_fn).call(this, shouldShowInstallModal, mergedScopes, mergedCaipAccountIds, nonEmptySessionProperties), scopes, transportType);
|
|
3136
3271
|
});
|
|
3137
3272
|
}
|
|
3138
|
-
emit(event, args) {
|
|
3139
|
-
var _a3, _b;
|
|
3140
|
-
(_b = (_a3 = this.options.transport) == null ? void 0 : _a3.onNotification) == null ? void 0 : _b.call(_a3, { method: event, params: args });
|
|
3141
|
-
super.emit(event, args);
|
|
3142
|
-
}
|
|
3143
3273
|
disconnect() {
|
|
3144
3274
|
return __async(this, arguments, function* (scopes = []) {
|
|
3145
3275
|
var _a3, _b, _c;
|
|
@@ -3149,7 +3279,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3149
3279
|
);
|
|
3150
3280
|
yield (_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.disconnect(scopes);
|
|
3151
3281
|
if (remainingScopes.length === 0) {
|
|
3152
|
-
yield this.storage.
|
|
3282
|
+
yield this.storage.removeTransportType();
|
|
3153
3283
|
if (__privateGet(this, _transportType) !== "browser" /* Browser */) {
|
|
3154
3284
|
yield (_b = __privateGet(this, _listener)) == null ? void 0 : _b.call(this);
|
|
3155
3285
|
(_c = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _c.call(this);
|
|
@@ -3167,7 +3297,8 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3167
3297
|
invokeMethod(request) {
|
|
3168
3298
|
return __async(this, null, function* () {
|
|
3169
3299
|
var _a3;
|
|
3170
|
-
const
|
|
3300
|
+
const transport = __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this);
|
|
3301
|
+
const { options } = this;
|
|
3171
3302
|
const rpcClient = new RpcClient(options, __privateGet(this, _sdkInfo));
|
|
3172
3303
|
const requestRouter = new RequestRouter(
|
|
3173
3304
|
transport,
|
|
@@ -3186,7 +3317,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3186
3317
|
const shouldOpenDeeplink = secure && !showInstallModal;
|
|
3187
3318
|
if (shouldOpenDeeplink) {
|
|
3188
3319
|
setTimeout(() => __async(this, null, function* () {
|
|
3189
|
-
const session = yield this.
|
|
3320
|
+
const session = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).getActiveSession();
|
|
3190
3321
|
if (!session) {
|
|
3191
3322
|
throw new Error("No active session found");
|
|
3192
3323
|
}
|
|
@@ -3210,10 +3341,13 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3210
3341
|
this.emit("wallet_sessionChanged", emptySession);
|
|
3211
3342
|
return;
|
|
3212
3343
|
}
|
|
3213
|
-
const response = yield this.
|
|
3344
|
+
const response = yield __privateGet(this, _transport2).request({
|
|
3214
3345
|
method: "wallet_getSession"
|
|
3215
3346
|
});
|
|
3216
|
-
this.emit(
|
|
3347
|
+
this.emit(
|
|
3348
|
+
"wallet_sessionChanged",
|
|
3349
|
+
(_b = response.result) != null ? _b : emptySession
|
|
3350
|
+
);
|
|
3217
3351
|
});
|
|
3218
3352
|
}
|
|
3219
3353
|
};
|
|
@@ -3225,34 +3359,19 @@ _beforeUnloadListener = new WeakMap();
|
|
|
3225
3359
|
_transportType = new WeakMap();
|
|
3226
3360
|
_listener = new WeakMap();
|
|
3227
3361
|
_anonId = new WeakMap();
|
|
3228
|
-
_sdkInfo = new WeakMap();
|
|
3229
3362
|
_MetaMaskConnectMultichain_instances = new WeakSet();
|
|
3363
|
+
transportOrThrow_fn = function() {
|
|
3364
|
+
if (!__privateGet(this, _transport2)) {
|
|
3365
|
+
throw new Error("Transport not initialized, establish connection first");
|
|
3366
|
+
}
|
|
3367
|
+
return __privateGet(this, _transport2);
|
|
3368
|
+
};
|
|
3369
|
+
_sdkInfo = new WeakMap();
|
|
3230
3370
|
setupAnalytics_fn = function() {
|
|
3231
3371
|
return __async(this, null, function* () {
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
3236
|
-
if (!isBrowser && !isReactNative2) {
|
|
3237
|
-
return;
|
|
3238
|
-
}
|
|
3239
|
-
const dappId = getDappId(this.options.dapp);
|
|
3240
|
-
const anonId = yield this.storage.getAnonId();
|
|
3241
|
-
__privateSet(this, _anonId, anonId);
|
|
3242
|
-
const { integrationType } = (_a3 = this.options.analytics) != null ? _a3 : {
|
|
3243
|
-
integrationType: ""
|
|
3244
|
-
};
|
|
3245
|
-
import_analytics4.analytics.setGlobalProperty(
|
|
3246
|
-
"mmconnect_versions",
|
|
3247
|
-
(_b = this.options.versions) != null ? _b : {}
|
|
3248
|
-
);
|
|
3249
|
-
import_analytics4.analytics.setGlobalProperty("dapp_id", dappId);
|
|
3250
|
-
import_analytics4.analytics.setGlobalProperty("anon_id", anonId);
|
|
3251
|
-
import_analytics4.analytics.setGlobalProperty("platform", platform);
|
|
3252
|
-
if (integrationType) {
|
|
3253
|
-
import_analytics4.analytics.setGlobalProperty("integration_types", [integrationType]);
|
|
3254
|
-
}
|
|
3255
|
-
import_analytics4.analytics.enable();
|
|
3372
|
+
yield setupAnalyticsGlobals(this.options, this.storage, (anonId) => {
|
|
3373
|
+
__privateSet(this, _anonId, anonId);
|
|
3374
|
+
});
|
|
3256
3375
|
});
|
|
3257
3376
|
};
|
|
3258
3377
|
onTransportNotification_fn = function(payload) {
|
|
@@ -3273,7 +3392,7 @@ onTransportNotification_fn = function(payload) {
|
|
|
3273
3392
|
};
|
|
3274
3393
|
getStoredTransport_fn = function() {
|
|
3275
3394
|
return __async(this, null, function* () {
|
|
3276
|
-
const transportType = yield this.storage.
|
|
3395
|
+
const transportType = yield this.storage.getTransportType();
|
|
3277
3396
|
const hasExtensionInstalled = yield hasExtension();
|
|
3278
3397
|
if (transportType) {
|
|
3279
3398
|
if (transportType === "browser" /* Browser */) {
|
|
@@ -3301,7 +3420,7 @@ getStoredTransport_fn = function() {
|
|
|
3301
3420
|
));
|
|
3302
3421
|
return apiTransport;
|
|
3303
3422
|
}
|
|
3304
|
-
yield this.storage.
|
|
3423
|
+
yield this.storage.removeTransportType();
|
|
3305
3424
|
}
|
|
3306
3425
|
return void 0;
|
|
3307
3426
|
});
|
|
@@ -3311,15 +3430,15 @@ setupTransport_fn = function() {
|
|
|
3311
3430
|
var _a3;
|
|
3312
3431
|
const transport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getStoredTransport_fn).call(this);
|
|
3313
3432
|
if (transport) {
|
|
3314
|
-
if (!
|
|
3433
|
+
if (!transport.isConnected()) {
|
|
3315
3434
|
this.status = "connecting";
|
|
3316
|
-
yield
|
|
3435
|
+
yield transport.connect();
|
|
3317
3436
|
}
|
|
3318
3437
|
this.status = "connected";
|
|
3319
3438
|
if (__privateGet(this, _transportType) === "mwp" /* MWP */) {
|
|
3320
|
-
yield this.storage.
|
|
3439
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
3321
3440
|
} else {
|
|
3322
|
-
yield this.storage.
|
|
3441
|
+
yield this.storage.setTransportType("browser" /* Browser */);
|
|
3323
3442
|
}
|
|
3324
3443
|
} else {
|
|
3325
3444
|
this.status = "loaded";
|
|
@@ -3328,7 +3447,7 @@ setupTransport_fn = function() {
|
|
|
3328
3447
|
if (hasExtensionInstalled && preferExtension) {
|
|
3329
3448
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this, { persist: false });
|
|
3330
3449
|
try {
|
|
3331
|
-
yield this.
|
|
3450
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).init();
|
|
3332
3451
|
} catch (error) {
|
|
3333
3452
|
console.error("Passive init failed:", error);
|
|
3334
3453
|
}
|
|
@@ -3341,7 +3460,7 @@ buildConnectionMetadata_fn = function() {
|
|
|
3341
3460
|
dapp: this.options.dapp,
|
|
3342
3461
|
sdk: { version: getVersion(), platform: getPlatformType() }
|
|
3343
3462
|
};
|
|
3344
|
-
if (__privateGet(this, _anonId)) {
|
|
3463
|
+
if (isAnalyticsEnabled(this.options) && __privateGet(this, _anonId)) {
|
|
3345
3464
|
metadata.analytics = { remote_session_id: __privateGet(this, _anonId) };
|
|
3346
3465
|
}
|
|
3347
3466
|
return metadata;
|
|
@@ -3352,7 +3471,7 @@ init_fn2 = function() {
|
|
|
3352
3471
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(this);
|
|
3353
3472
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupTransport_fn).call(this);
|
|
3354
3473
|
} catch (error) {
|
|
3355
|
-
yield this.storage.
|
|
3474
|
+
yield this.storage.removeTransportType();
|
|
3356
3475
|
this.status = "pending";
|
|
3357
3476
|
logger2("MetaMaskSDK error during initialization", error);
|
|
3358
3477
|
}
|
|
@@ -3398,17 +3517,17 @@ setupMWP_fn = function() {
|
|
|
3398
3517
|
__privateSet(this, _transport2, apiTransport);
|
|
3399
3518
|
__privateSet(this, _transportType, "mwp" /* MWP */);
|
|
3400
3519
|
__privateGet(this, _providerTransportWrapper).setupTransportNotificationListener();
|
|
3401
|
-
__privateSet(this, _listener,
|
|
3520
|
+
__privateSet(this, _listener, apiTransport.onNotification(
|
|
3402
3521
|
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
3403
3522
|
));
|
|
3404
|
-
yield this.storage.
|
|
3523
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
3405
3524
|
});
|
|
3406
3525
|
};
|
|
3407
3526
|
onBeforeUnload_fn = function() {
|
|
3408
3527
|
return __async(this, null, function* () {
|
|
3409
3528
|
var _a3;
|
|
3410
3529
|
if ((_a3 = this.options.ui.factory.modal) == null ? void 0 : _a3.isMounted) {
|
|
3411
|
-
yield this.storage.
|
|
3530
|
+
yield this.storage.removeTransportType();
|
|
3412
3531
|
}
|
|
3413
3532
|
});
|
|
3414
3533
|
};
|
|
@@ -3425,70 +3544,65 @@ createBeforeUnloadListener_fn = function() {
|
|
|
3425
3544
|
};
|
|
3426
3545
|
renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
3427
3546
|
return __async(this, null, function* () {
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
sessionRequest,
|
|
3441
|
-
metadata: __privateMethod(this, _MetaMaskConnectMultichain_instances, buildConnectionMetadata_fn).call(this)
|
|
3442
|
-
});
|
|
3443
|
-
}
|
|
3444
|
-
);
|
|
3445
|
-
(() => __async(this, null, function* () {
|
|
3446
|
-
var _a3;
|
|
3447
|
-
try {
|
|
3448
|
-
yield this.transport.connect({
|
|
3449
|
-
scopes,
|
|
3450
|
-
caipAccountIds,
|
|
3451
|
-
sessionProperties
|
|
3452
|
-
});
|
|
3453
|
-
yield this.options.ui.factory.unload();
|
|
3454
|
-
(_a3 = this.options.ui.factory.modal) == null ? void 0 : _a3.unmount();
|
|
3455
|
-
this.status = "connected";
|
|
3456
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
3457
|
-
} catch (error) {
|
|
3458
|
-
const { ProtocolError, ErrorCode } = yield import("@metamask/mobile-wallet-protocol-core");
|
|
3459
|
-
if (error instanceof ProtocolError) {
|
|
3460
|
-
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
3461
|
-
this.status = "disconnected";
|
|
3462
|
-
yield this.options.ui.factory.unload(error);
|
|
3463
|
-
reject(error);
|
|
3464
|
-
}
|
|
3465
|
-
} else {
|
|
3466
|
-
this.status = "disconnected";
|
|
3467
|
-
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
3468
|
-
yield this.options.ui.factory.unload(normalizedError);
|
|
3469
|
-
reject(normalizedError);
|
|
3470
|
-
}
|
|
3471
|
-
}
|
|
3472
|
-
}))().catch(() => {
|
|
3473
|
-
});
|
|
3547
|
+
const completion = (0, import_utils8.createDeferredPromise)();
|
|
3548
|
+
const createConnectionRequest = () => __async(this, null, function* () {
|
|
3549
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
3550
|
+
yield this.dappClient.disconnect();
|
|
3551
|
+
}
|
|
3552
|
+
const sessionRequestDeferred = (0, import_utils8.createDeferredPromise)();
|
|
3553
|
+
this.dappClient.on(
|
|
3554
|
+
"session_request",
|
|
3555
|
+
(sessionRequest) => {
|
|
3556
|
+
sessionRequestDeferred.resolve({
|
|
3557
|
+
sessionRequest,
|
|
3558
|
+
metadata: __privateMethod(this, _MetaMaskConnectMultichain_instances, buildConnectionMetadata_fn).call(this)
|
|
3474
3559
|
});
|
|
3475
|
-
}
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3560
|
+
}
|
|
3561
|
+
);
|
|
3562
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).connect({ scopes, caipAccountIds, sessionProperties }).then(() => __async(this, null, function* () {
|
|
3563
|
+
var _a3;
|
|
3564
|
+
yield this.options.ui.factory.unload();
|
|
3565
|
+
(_a3 = this.options.ui.factory.modal) == null ? void 0 : _a3.unmount();
|
|
3566
|
+
this.status = "connected";
|
|
3567
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
3568
|
+
})).catch((error) => __async(this, null, function* () {
|
|
3569
|
+
const { ProtocolError, ErrorCode } = yield import("@metamask/mobile-wallet-protocol-core");
|
|
3570
|
+
if (error instanceof ProtocolError) {
|
|
3571
|
+
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
3572
|
+
this.status = "disconnected";
|
|
3573
|
+
yield this.options.ui.factory.unload(error);
|
|
3574
|
+
completion.reject(error);
|
|
3483
3575
|
}
|
|
3484
|
-
}
|
|
3485
|
-
|
|
3486
|
-
|
|
3576
|
+
} else {
|
|
3577
|
+
this.status = "disconnected";
|
|
3578
|
+
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
3579
|
+
yield this.options.ui.factory.unload(normalizedError);
|
|
3580
|
+
completion.reject(normalizedError);
|
|
3487
3581
|
}
|
|
3488
|
-
)
|
|
3489
|
-
|
|
3490
|
-
});
|
|
3582
|
+
}));
|
|
3583
|
+
return sessionRequestDeferred.promise;
|
|
3491
3584
|
});
|
|
3585
|
+
this.options.ui.factory.renderInstallModal(
|
|
3586
|
+
desktopPreferred,
|
|
3587
|
+
createConnectionRequest,
|
|
3588
|
+
(error) => __async(this, null, function* () {
|
|
3589
|
+
if (error) {
|
|
3590
|
+
yield this.storage.removeTransportType();
|
|
3591
|
+
completion.reject(error);
|
|
3592
|
+
} else {
|
|
3593
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
3594
|
+
completion.resolve();
|
|
3595
|
+
}
|
|
3596
|
+
}),
|
|
3597
|
+
(uri) => {
|
|
3598
|
+
this.emit("display_uri", uri);
|
|
3599
|
+
}
|
|
3600
|
+
).catch((error) => {
|
|
3601
|
+
completion.reject(
|
|
3602
|
+
error instanceof Error ? error : new Error(String(error))
|
|
3603
|
+
);
|
|
3604
|
+
});
|
|
3605
|
+
return completion.promise;
|
|
3492
3606
|
});
|
|
3493
3607
|
};
|
|
3494
3608
|
showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
@@ -3504,39 +3618,37 @@ showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds, session
|
|
|
3504
3618
|
};
|
|
3505
3619
|
headlessConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
3506
3620
|
return __async(this, null, function* () {
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3621
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
3622
|
+
yield this.dappClient.disconnect().catch(() => void 0);
|
|
3623
|
+
}
|
|
3624
|
+
const onSessionRequest = (sessionRequest) => {
|
|
3625
|
+
const connectionRequest = {
|
|
3626
|
+
sessionRequest,
|
|
3627
|
+
metadata: __privateMethod(this, _MetaMaskConnectMultichain_instances, buildConnectionMetadata_fn).call(this)
|
|
3628
|
+
};
|
|
3629
|
+
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
3630
|
+
this.emit("display_uri", deeplink);
|
|
3631
|
+
};
|
|
3632
|
+
this.dappClient.on("session_request", onSessionRequest);
|
|
3633
|
+
try {
|
|
3634
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).connect({
|
|
3635
|
+
scopes,
|
|
3636
|
+
caipAccountIds,
|
|
3637
|
+
sessionProperties
|
|
3638
|
+
});
|
|
3639
|
+
this.status = "connected";
|
|
3640
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
3641
|
+
} catch (error) {
|
|
3642
|
+
const { ProtocolError } = yield import("@metamask/mobile-wallet-protocol-core");
|
|
3643
|
+
this.status = "disconnected";
|
|
3644
|
+
yield this.storage.removeTransportType();
|
|
3645
|
+
if (error instanceof ProtocolError || error instanceof Error) {
|
|
3646
|
+
throw error;
|
|
3511
3647
|
}
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
sessionRequest,
|
|
3517
|
-
metadata: __privateMethod(this, _MetaMaskConnectMultichain_instances, buildConnectionMetadata_fn).call(this)
|
|
3518
|
-
};
|
|
3519
|
-
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
3520
|
-
this.emit("display_uri", deeplink);
|
|
3521
|
-
}
|
|
3522
|
-
);
|
|
3523
|
-
this.transport.connect({ scopes, caipAccountIds, sessionProperties }).then(() => __async(this, null, function* () {
|
|
3524
|
-
this.status = "connected";
|
|
3525
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
3526
|
-
resolve();
|
|
3527
|
-
})).catch((error) => __async(this, null, function* () {
|
|
3528
|
-
const { ProtocolError } = yield import("@metamask/mobile-wallet-protocol-core");
|
|
3529
|
-
if (error instanceof ProtocolError) {
|
|
3530
|
-
this.status = "disconnected";
|
|
3531
|
-
yield this.storage.removeTransport();
|
|
3532
|
-
reject(error);
|
|
3533
|
-
} else {
|
|
3534
|
-
this.status = "disconnected";
|
|
3535
|
-
yield this.storage.removeTransport();
|
|
3536
|
-
reject(error instanceof Error ? error : new Error(String(error)));
|
|
3537
|
-
}
|
|
3538
|
-
}));
|
|
3539
|
-
});
|
|
3648
|
+
throw new Error(String(error));
|
|
3649
|
+
} finally {
|
|
3650
|
+
this.dappClient.off("session_request", onSessionRequest);
|
|
3651
|
+
}
|
|
3540
3652
|
});
|
|
3541
3653
|
};
|
|
3542
3654
|
setupDefaultTransport_fn = function() {
|
|
@@ -3545,7 +3657,7 @@ setupDefaultTransport_fn = function() {
|
|
|
3545
3657
|
return __privateGet(this, _transport2);
|
|
3546
3658
|
}
|
|
3547
3659
|
if (options == null ? void 0 : options.persist) {
|
|
3548
|
-
yield this.storage.
|
|
3660
|
+
yield this.storage.setTransportType("browser" /* Browser */);
|
|
3549
3661
|
}
|
|
3550
3662
|
const transport = new DefaultTransport();
|
|
3551
3663
|
__privateSet(this, _listener, transport.onNotification(
|
|
@@ -3578,7 +3690,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
|
3578
3690
|
};
|
|
3579
3691
|
this.dappClient.on("message", dappClientMessageHandler);
|
|
3580
3692
|
let timeout;
|
|
3581
|
-
if (this.
|
|
3693
|
+
if (__privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).isConnected()) {
|
|
3582
3694
|
timeout = setTimeout(() => {
|
|
3583
3695
|
this.openSimpleDeeplinkIfNeeded();
|
|
3584
3696
|
}, 250);
|
|
@@ -3606,8 +3718,8 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
|
3606
3718
|
}
|
|
3607
3719
|
);
|
|
3608
3720
|
}
|
|
3609
|
-
return this.
|
|
3610
|
-
yield this.storage.
|
|
3721
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).connect({ scopes, caipAccountIds, sessionProperties }).then(resolve).catch((error) => __async(this, null, function* () {
|
|
3722
|
+
yield this.storage.removeTransportType();
|
|
3611
3723
|
this.dappClient.off("message", dappClientMessageHandler);
|
|
3612
3724
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
3613
3725
|
})).finally(() => {
|
|
@@ -3623,38 +3735,42 @@ handleConnection_fn = function(promise, scopes, transportType) {
|
|
|
3623
3735
|
this.status = "connecting";
|
|
3624
3736
|
return promise.then(() => __async(this, null, function* () {
|
|
3625
3737
|
this.status = "connected";
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3738
|
+
if (isAnalyticsEnabled(this.options)) {
|
|
3739
|
+
try {
|
|
3740
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
3741
|
+
this.options,
|
|
3742
|
+
this.storage
|
|
3743
|
+
);
|
|
3744
|
+
import_analytics4.analytics.track("mmconnect_connection_established", __spreadProps(__spreadValues({}, baseProps), {
|
|
3745
|
+
transport_type: transportType,
|
|
3746
|
+
user_permissioned_chains: scopes
|
|
3747
|
+
}));
|
|
3748
|
+
} catch (error) {
|
|
3749
|
+
logger2("Error tracking connection_established event", error);
|
|
3750
|
+
}
|
|
3637
3751
|
}
|
|
3638
3752
|
return void 0;
|
|
3639
3753
|
})).catch((error) => __async(this, null, function* () {
|
|
3640
3754
|
this.status = "disconnected";
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3755
|
+
if (isAnalyticsEnabled(this.options)) {
|
|
3756
|
+
try {
|
|
3757
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
3758
|
+
this.options,
|
|
3759
|
+
this.storage
|
|
3760
|
+
);
|
|
3761
|
+
const isRejection = isRejectionError(error);
|
|
3762
|
+
if (isRejection) {
|
|
3763
|
+
import_analytics4.analytics.track("mmconnect_connection_rejected", __spreadProps(__spreadValues({}, baseProps), {
|
|
3764
|
+
transport_type: transportType
|
|
3765
|
+
}));
|
|
3766
|
+
} else {
|
|
3767
|
+
import_analytics4.analytics.track("mmconnect_connection_failed", __spreadValues(__spreadProps(__spreadValues({}, baseProps), {
|
|
3768
|
+
transport_type: transportType
|
|
3769
|
+
}), extractErrorDiagnostics(error)));
|
|
3770
|
+
}
|
|
3771
|
+
} catch (e) {
|
|
3772
|
+
logger2("Error tracking connection failed/rejected event", error);
|
|
3655
3773
|
}
|
|
3656
|
-
} catch (e) {
|
|
3657
|
-
logger2("Error tracking connection failed/rejected event", error);
|
|
3658
3774
|
}
|
|
3659
3775
|
throw error;
|
|
3660
3776
|
}));
|
|
@@ -3669,7 +3785,7 @@ getCaipSession_fn = function() {
|
|
|
3669
3785
|
};
|
|
3670
3786
|
if ((_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.isConnected()) {
|
|
3671
3787
|
try {
|
|
3672
|
-
const response = yield this.
|
|
3788
|
+
const response = yield __privateGet(this, _transport2).request({
|
|
3673
3789
|
method: "wallet_getSession"
|
|
3674
3790
|
});
|
|
3675
3791
|
if (response.result) {
|
|
@@ -3763,14 +3879,14 @@ var Store = class extends StoreClient {
|
|
|
3763
3879
|
super();
|
|
3764
3880
|
this.adapter = adapter;
|
|
3765
3881
|
}
|
|
3766
|
-
|
|
3882
|
+
getTransportType() {
|
|
3767
3883
|
return __async(this, null, function* () {
|
|
3768
3884
|
try {
|
|
3769
|
-
const
|
|
3770
|
-
if (!
|
|
3885
|
+
const transportType = yield this.adapter.get("multichain-transport");
|
|
3886
|
+
if (!transportType) {
|
|
3771
3887
|
return null;
|
|
3772
3888
|
}
|
|
3773
|
-
return getTransportType(
|
|
3889
|
+
return getTransportType(transportType);
|
|
3774
3890
|
} catch (err) {
|
|
3775
3891
|
throw new StorageGetErr(
|
|
3776
3892
|
this.adapter.platform,
|
|
@@ -3780,10 +3896,10 @@ var Store = class extends StoreClient {
|
|
|
3780
3896
|
}
|
|
3781
3897
|
});
|
|
3782
3898
|
}
|
|
3783
|
-
|
|
3899
|
+
setTransportType(transportType) {
|
|
3784
3900
|
return __async(this, null, function* () {
|
|
3785
3901
|
try {
|
|
3786
|
-
yield this.adapter.set("multichain-transport",
|
|
3902
|
+
yield this.adapter.set("multichain-transport", transportType);
|
|
3787
3903
|
} catch (err) {
|
|
3788
3904
|
throw new StorageSetErr(
|
|
3789
3905
|
this.adapter.platform,
|
|
@@ -3793,7 +3909,7 @@ var Store = class extends StoreClient {
|
|
|
3793
3909
|
}
|
|
3794
3910
|
});
|
|
3795
3911
|
}
|
|
3796
|
-
|
|
3912
|
+
removeTransportType() {
|
|
3797
3913
|
return __async(this, null, function* () {
|
|
3798
3914
|
try {
|
|
3799
3915
|
yield this.adapter.delete("multichain-transport");
|
|
@@ -4007,7 +4123,11 @@ var BaseModalFactory = class {
|
|
|
4007
4123
|
(_a4 = this.displayUriCallback) == null ? void 0 : _a4.call(this, newLink);
|
|
4008
4124
|
return newLink;
|
|
4009
4125
|
}),
|
|
4010
|
-
onClose:
|
|
4126
|
+
onClose: (shouldTerminate) => {
|
|
4127
|
+
this.onCloseModal(shouldTerminate).catch((error) => {
|
|
4128
|
+
console.error("Failed to close modal:", error);
|
|
4129
|
+
});
|
|
4130
|
+
},
|
|
4011
4131
|
startDesktopOnboarding: this.onStartDesktopOnboarding.bind(this),
|
|
4012
4132
|
createConnectionRequest,
|
|
4013
4133
|
onDisplayUri: this.displayUriCallback
|
|
@@ -4045,7 +4165,7 @@ function preload() {
|
|
|
4045
4165
|
}
|
|
4046
4166
|
try {
|
|
4047
4167
|
const { defineCustomElements } = yield import("@metamask/multichain-ui/loader");
|
|
4048
|
-
|
|
4168
|
+
defineCustomElements();
|
|
4049
4169
|
} catch (error) {
|
|
4050
4170
|
console.error("Failed to load customElements:", error);
|
|
4051
4171
|
}
|