@metamask/connect-multichain 0.13.0 → 0.15.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 +24 -1
- package/README.md +20 -19
- package/dist/browser/es/connect-multichain.d.mts +62 -6
- package/dist/browser/es/connect-multichain.mjs +286 -124
- 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 +62 -6
- package/dist/browser/iife/connect-multichain.js +304 -124
- 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 +62 -6
- package/dist/browser/umd/connect-multichain.js +286 -124
- 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 +62 -6
- package/dist/node/cjs/connect-multichain.js +287 -124
- 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 +62 -6
- package/dist/node/es/connect-multichain.mjs +286 -124
- 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 +62 -6
- package/dist/react-native/es/connect-multichain.mjs +286 -124
- 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/index.d.ts +1 -1
- 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 -3
- package/dist/src/domain/multichain/types.d.ts.map +1 -1
- package/dist/src/domain/utils/index.d.ts +2 -1
- package/dist/src/domain/utils/index.d.ts.map +1 -1
- package/dist/src/domain/utils/index.js +1 -1
- package/dist/src/domain/utils/index.js.map +1 -1
- package/dist/src/multichain/index.d.ts.map +1 -1
- package/dist/src/multichain/index.js +109 -63
- package/dist/src/multichain/index.js.map +1 -1
- package/dist/src/multichain/rpc/requestRouter.d.ts.map +1 -1
- package/dist/src/multichain/rpc/requestRouter.js +27 -9
- package/dist/src/multichain/rpc/requestRouter.js.map +1 -1
- package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/mwp/index.js +17 -5
- package/dist/src/multichain/transports/mwp/index.js.map +1 -1
- package/dist/src/multichain/utils/analytics.d.ts +82 -1
- package/dist/src/multichain/utils/analytics.d.ts.map +1 -1
- package/dist/src/multichain/utils/analytics.js +252 -17
- package/dist/src/multichain/utils/analytics.js.map +1 -1
- package/dist/types/connect-multichain.d.ts +62 -6
- package/package.json +2 -2
|
@@ -472,7 +472,7 @@ var init_multichain = __esm({
|
|
|
472
472
|
}
|
|
473
473
|
/**
|
|
474
474
|
* Merges the given options into the current instance options.
|
|
475
|
-
* Only the mergeable keys are updated (api.supportedNetworks, versions, ui.*, mobile.*, transport.extensionId, debug).
|
|
475
|
+
* Only the mergeable keys are updated (api.supportedNetworks, analytics, versions, ui.*, mobile.*, transport.extensionId, debug).
|
|
476
476
|
* The main thing to note is that the value for `dapp` is not merged as it does not make sense for
|
|
477
477
|
* subsequent calls to `createMultichainClient` to have a different `dapp` value.
|
|
478
478
|
* Used when createMultichainClient is called with an existing singleton.
|
|
@@ -480,23 +480,28 @@ var init_multichain = __esm({
|
|
|
480
480
|
* @param partial - Options to merge/overwrite onto the current instance
|
|
481
481
|
*/
|
|
482
482
|
mergeOptions(partial) {
|
|
483
|
-
var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
483
|
+
var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
484
484
|
const opts = this.options;
|
|
485
|
+
const analytics3 = __spreadValues(__spreadValues({}, opts.analytics), (_a3 = partial.analytics) != null ? _a3 : {});
|
|
486
|
+
if (((_b = opts.analytics) == null ? void 0 : _b.enabled) === false) {
|
|
487
|
+
analytics3.enabled = false;
|
|
488
|
+
}
|
|
485
489
|
this.options = __spreadProps(__spreadValues({}, opts), {
|
|
486
490
|
api: __spreadProps(__spreadValues({}, opts.api), {
|
|
487
|
-
supportedNetworks: __spreadValues(__spreadValues({}, opts.api.supportedNetworks), (
|
|
491
|
+
supportedNetworks: __spreadValues(__spreadValues({}, opts.api.supportedNetworks), (_d = (_c = partial.api) == null ? void 0 : _c.supportedNetworks) != null ? _d : {})
|
|
488
492
|
}),
|
|
489
|
-
versions: __spreadValues(__spreadValues({}, opts.versions), (
|
|
493
|
+
versions: __spreadValues(__spreadValues({}, opts.versions), (_e = partial.versions) != null ? _e : {}),
|
|
494
|
+
analytics: __spreadValues({}, analytics3),
|
|
490
495
|
ui: __spreadProps(__spreadValues({}, opts.ui), {
|
|
491
|
-
headless: (
|
|
492
|
-
preferExtension: (
|
|
493
|
-
showInstallModal: (
|
|
496
|
+
headless: (_g = (_f = partial.ui) == null ? void 0 : _f.headless) != null ? _g : opts.ui.headless,
|
|
497
|
+
preferExtension: (_i = (_h = partial.ui) == null ? void 0 : _h.preferExtension) != null ? _i : opts.ui.preferExtension,
|
|
498
|
+
showInstallModal: (_k = (_j = partial.ui) == null ? void 0 : _j.showInstallModal) != null ? _k : opts.ui.showInstallModal
|
|
494
499
|
}),
|
|
495
|
-
mobile: __spreadValues(__spreadValues({}, opts.mobile), (
|
|
496
|
-
transport: __spreadProps(__spreadValues({}, (
|
|
497
|
-
extensionId: (
|
|
500
|
+
mobile: __spreadValues(__spreadValues({}, opts.mobile), (_l = partial.mobile) != null ? _l : {}),
|
|
501
|
+
transport: __spreadProps(__spreadValues({}, (_m = opts.transport) != null ? _m : {}), {
|
|
502
|
+
extensionId: (_p = (_n = partial.transport) == null ? void 0 : _n.extensionId) != null ? _p : (_o = opts.transport) == null ? void 0 : _o.extensionId
|
|
498
503
|
}),
|
|
499
|
-
debug: (
|
|
504
|
+
debug: (_q = partial.debug) != null ? _q : opts.debug
|
|
500
505
|
});
|
|
501
506
|
}
|
|
502
507
|
};
|
|
@@ -679,17 +684,94 @@ var init_ui = __esm({
|
|
|
679
684
|
});
|
|
680
685
|
|
|
681
686
|
// src/multichain/utils/analytics.ts
|
|
687
|
+
function sanitiseErrorMessage(message) {
|
|
688
|
+
if (!message) {
|
|
689
|
+
return void 0;
|
|
690
|
+
}
|
|
691
|
+
let sanitised = message;
|
|
692
|
+
for (const { pattern, replacement } of SANITISE_PATTERNS) {
|
|
693
|
+
sanitised = sanitised.replace(pattern, replacement);
|
|
694
|
+
}
|
|
695
|
+
if (sanitised.length > ERROR_MESSAGE_SAMPLE_MAX_LENGTH) {
|
|
696
|
+
sanitised = `${sanitised.slice(0, ERROR_MESSAGE_SAMPLE_MAX_LENGTH - 1)}\u2026`;
|
|
697
|
+
}
|
|
698
|
+
return sanitised;
|
|
699
|
+
}
|
|
700
|
+
function getUnwrappedErrorDetails(error) {
|
|
701
|
+
var _a3, _b, _c, _d;
|
|
702
|
+
if (typeof error !== "object" || error === null) {
|
|
703
|
+
return { code: void 0, message: "" };
|
|
704
|
+
}
|
|
705
|
+
if (error instanceof RPCInvokeMethodErr) {
|
|
706
|
+
return {
|
|
707
|
+
code: (_a3 = error.rpcCode) != null ? _a3 : error.code,
|
|
708
|
+
message: (_c = (_b = error.rpcMessage) != null ? _b : error.message) != null ? _c : ""
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
const errorObj = error;
|
|
712
|
+
return {
|
|
713
|
+
code: errorObj.code,
|
|
714
|
+
message: (_d = errorObj.message) != null ? _d : ""
|
|
715
|
+
};
|
|
716
|
+
}
|
|
682
717
|
function isRejectionError(error) {
|
|
683
|
-
var _a3, _b;
|
|
684
718
|
if (typeof error !== "object" || error === null) {
|
|
685
719
|
return false;
|
|
686
720
|
}
|
|
721
|
+
const { code, message } = getUnwrappedErrorDetails(error);
|
|
722
|
+
const errorMessage = message.toLowerCase();
|
|
723
|
+
return code === 4001 || errorMessage.includes("reject") || errorMessage.includes("denied") || errorMessage.includes("cancel") || // Narrow "user …" matches — bare "user" is too greedy (catches Account
|
|
724
|
+
// Abstraction errors like "user operation reverted").
|
|
725
|
+
errorMessage.includes("user rejected") || errorMessage.includes("user denied") || errorMessage.includes("user cancelled") || errorMessage.includes("user canceled");
|
|
726
|
+
}
|
|
727
|
+
function classifyFailureReason(error) {
|
|
728
|
+
var _a3, _b;
|
|
729
|
+
if (typeof error !== "object" || error === null) {
|
|
730
|
+
return "unknown";
|
|
731
|
+
}
|
|
687
732
|
const errorObj = error;
|
|
688
|
-
const
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
733
|
+
const errorName = (_a3 = errorObj.name) != null ? _a3 : "";
|
|
734
|
+
const errorMessageRaw = (_b = errorObj.message) != null ? _b : "";
|
|
735
|
+
const errorMessage = errorMessageRaw.toLowerCase();
|
|
736
|
+
const { code } = getUnwrappedErrorDetails(error);
|
|
737
|
+
if (typeof code === "number") {
|
|
738
|
+
if (code === -32601) {
|
|
739
|
+
return "wallet_method_unsupported";
|
|
740
|
+
}
|
|
741
|
+
if (code === -32602) {
|
|
742
|
+
return "wallet_invalid_params";
|
|
743
|
+
}
|
|
744
|
+
if (code === -32603) {
|
|
745
|
+
return "wallet_internal_error";
|
|
746
|
+
}
|
|
747
|
+
if (code <= -32e3 && code >= -32099) {
|
|
748
|
+
return "wallet_internal_error";
|
|
749
|
+
}
|
|
750
|
+
if (code === 4100) {
|
|
751
|
+
return "wallet_unauthorized";
|
|
752
|
+
}
|
|
753
|
+
if (code === 4200) {
|
|
754
|
+
return "wallet_method_unsupported";
|
|
755
|
+
}
|
|
756
|
+
if (code === 4902) {
|
|
757
|
+
return "unrecognized_chain";
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
if (errorName === "TransportTimeoutError" || errorMessageRaw === "Request timeout" || errorMessage.includes("timed out") || errorMessage.includes("timeout")) {
|
|
761
|
+
return "transport_timeout";
|
|
762
|
+
}
|
|
763
|
+
if (errorName === "TransportError" || errorMessage.includes("not connected") || errorMessage.includes("transport disconnect") || errorMessage.includes("connection lost") || errorMessage.includes("socket closed")) {
|
|
764
|
+
return "transport_disconnect";
|
|
765
|
+
}
|
|
766
|
+
return "unknown";
|
|
767
|
+
}
|
|
768
|
+
function extractErrorDiagnostics(error) {
|
|
769
|
+
const failureReason = classifyFailureReason(error);
|
|
770
|
+
const { code, message } = getUnwrappedErrorDetails(error);
|
|
771
|
+
const messageSample = sanitiseErrorMessage(message);
|
|
772
|
+
return __spreadValues(__spreadValues({
|
|
773
|
+
failure_reason: failureReason
|
|
774
|
+
}, typeof code === "number" ? { error_code: code } : {}), messageSample ? { error_message_sample: messageSample } : {});
|
|
693
775
|
}
|
|
694
776
|
function getBaseAnalyticsProperties(options, storage) {
|
|
695
777
|
return __async(this, null, function* () {
|
|
@@ -705,26 +787,61 @@ function getBaseAnalyticsProperties(options, storage) {
|
|
|
705
787
|
};
|
|
706
788
|
});
|
|
707
789
|
}
|
|
708
|
-
function getWalletActionAnalyticsProperties(options, storage, invokeOptions, transportType) {
|
|
790
|
+
function getWalletActionAnalyticsProperties(options, storage, invokeOptions, transportType, extra) {
|
|
709
791
|
return __async(this, null, function* () {
|
|
710
792
|
var _a3;
|
|
711
793
|
const dappId = getDappId(options.dapp);
|
|
712
794
|
const anonId = yield storage.getAnonId();
|
|
713
|
-
return {
|
|
795
|
+
return __spreadValues(__spreadValues(__spreadValues({
|
|
714
796
|
mmconnect_versions: (_a3 = options.versions) != null ? _a3 : {},
|
|
715
797
|
dapp_id: dappId,
|
|
716
798
|
method: invokeOptions.request.method,
|
|
717
799
|
caip_chain_id: invokeOptions.scope,
|
|
718
800
|
anon_id: anonId,
|
|
719
801
|
transport_type: transportType
|
|
720
|
-
};
|
|
802
|
+
}, (extra == null ? void 0 : extra.failure_reason) ? { failure_reason: extra.failure_reason } : {}), typeof (extra == null ? void 0 : extra.error_code) === "number" ? { error_code: extra.error_code } : {}), (extra == null ? void 0 : extra.error_message_sample) ? { error_message_sample: extra.error_message_sample } : {});
|
|
721
803
|
});
|
|
722
804
|
}
|
|
805
|
+
var ERROR_MESSAGE_SAMPLE_MAX_LENGTH, SANITISE_PATTERNS;
|
|
723
806
|
var init_analytics = __esm({
|
|
724
807
|
"src/multichain/utils/analytics.ts"() {
|
|
725
808
|
"use strict";
|
|
726
809
|
init_utils2();
|
|
727
810
|
init_domain();
|
|
811
|
+
ERROR_MESSAGE_SAMPLE_MAX_LENGTH = 200;
|
|
812
|
+
SANITISE_PATTERNS = [
|
|
813
|
+
// EVM-style 20-byte hex addresses (e.g. `0x` + 40 hex chars).
|
|
814
|
+
{ pattern: /0x[a-fA-F0-9]{40}/gu, replacement: "<addr>" },
|
|
815
|
+
// Other long hex blobs: tx hashes, signatures, raw byte strings, large
|
|
816
|
+
// hex amounts. 16+ hex chars catches 32-byte hashes/signatures without
|
|
817
|
+
// snagging EVM method selectors (8 chars) or short hex codes.
|
|
818
|
+
{ pattern: /(?:0x)?[a-fA-F0-9]{16,}/gu, replacement: "<hex>" },
|
|
819
|
+
// URLs of any scheme up to the first whitespace / quote / closing paren.
|
|
820
|
+
// Catches RPC endpoints, dapp deeplinks, query strings with secrets.
|
|
821
|
+
{ pattern: /https?:\/\/[^\s"')]+/gu, replacement: "<url>" },
|
|
822
|
+
// Bech32 addresses: short HRP (1-10 lowercase chars) + `1` separator +
|
|
823
|
+
// ≥38 chars of Bech32 data alphabet `[ac-hj-np-z02-9]` (excludes the
|
|
824
|
+
// look-alike chars `b`, `i`, `o`, `1`). Covers Bitcoin SegWit
|
|
825
|
+
// (`bc1…`/`tb1…`) and Cosmos-SDK chains (`cosmos1…`, `osmo1…`,
|
|
826
|
+
// `juno1…`, `inj1…`, etc.) without enumerating every HRP. Runs before
|
|
827
|
+
// the Base58 pattern below — see header comment for why.
|
|
828
|
+
{
|
|
829
|
+
pattern: /\b[a-z]{1,10}1[ac-hj-np-z02-9]{38,}\b/gu,
|
|
830
|
+
replacement: "<addr>"
|
|
831
|
+
},
|
|
832
|
+
// Base58 tokens (32+ chars, Base58 alphabet `[1-9A-HJ-NP-Za-km-z]`).
|
|
833
|
+
// Covers Solana pubkeys (32-44 chars), Solana tx signatures (~88 chars),
|
|
834
|
+
// and Bitcoin Base58 addresses ≥32 chars. The 32-char floor and `\b`
|
|
835
|
+
// word boundary keep English words and shorter alphanumerics safe.
|
|
836
|
+
{
|
|
837
|
+
pattern: /\b[1-9A-HJ-NP-Za-km-z]{32,}\b/gu,
|
|
838
|
+
replacement: "<addr>"
|
|
839
|
+
},
|
|
840
|
+
// Long decimal numbers — token amounts, gas units, timestamps, lamports.
|
|
841
|
+
// 10+ digits catches typical chain quantities without affecting JSON-RPC
|
|
842
|
+
// codes (-32601, 4001, etc.) or short numeric IDs.
|
|
843
|
+
{ pattern: /\d{10,}/gu, replacement: "<num>" }
|
|
844
|
+
];
|
|
728
845
|
}
|
|
729
846
|
});
|
|
730
847
|
|
|
@@ -1386,13 +1503,24 @@ var init_mwp = __esm({
|
|
|
1386
1503
|
return resolveConnection();
|
|
1387
1504
|
});
|
|
1388
1505
|
this.dappClient.on("message", initialConnectionMessageHandler);
|
|
1506
|
+
const platformType = getPlatformType();
|
|
1507
|
+
const isQRCodeFlow = [
|
|
1508
|
+
"web-desktop" /* DesktopWeb */,
|
|
1509
|
+
"nodejs" /* NonBrowser */
|
|
1510
|
+
].includes(platformType);
|
|
1511
|
+
const initialPayload = {
|
|
1512
|
+
name: MULTICHAIN_PROVIDER_STREAM_NAME,
|
|
1513
|
+
data: request
|
|
1514
|
+
};
|
|
1389
1515
|
dappClient.connect({
|
|
1390
1516
|
mode: "trusted",
|
|
1391
|
-
initialPayload:
|
|
1392
|
-
|
|
1393
|
-
|
|
1517
|
+
initialPayload: isQRCodeFlow ? void 0 : initialPayload
|
|
1518
|
+
}).then(() => __async(this, null, function* () {
|
|
1519
|
+
if (isQRCodeFlow) {
|
|
1520
|
+
return dappClient.sendRequest(initialPayload);
|
|
1394
1521
|
}
|
|
1395
|
-
|
|
1522
|
+
return void 0;
|
|
1523
|
+
})).catch((error) => {
|
|
1396
1524
|
if (initialConnectionMessageHandler) {
|
|
1397
1525
|
this.dappClient.off(
|
|
1398
1526
|
"message",
|
|
@@ -2083,6 +2211,17 @@ import { analytics } from "@metamask/analytics";
|
|
|
2083
2211
|
init_domain();
|
|
2084
2212
|
init_utils2();
|
|
2085
2213
|
init_analytics();
|
|
2214
|
+
function toRPCInvokeMethodErr(error) {
|
|
2215
|
+
var _a3;
|
|
2216
|
+
if (error instanceof RPCInvokeMethodErr) {
|
|
2217
|
+
return error;
|
|
2218
|
+
}
|
|
2219
|
+
const castError = error;
|
|
2220
|
+
return new RPCInvokeMethodErr(
|
|
2221
|
+
(_a3 = castError.message) != null ? _a3 : "Unknown error",
|
|
2222
|
+
castError.code
|
|
2223
|
+
);
|
|
2224
|
+
}
|
|
2086
2225
|
var _RequestRouter_instances, withAnalyticsTracking_fn, trackWalletActionRequested_fn, trackWalletActionSucceeded_fn, trackWalletActionFailed_fn, trackWalletActionRejected_fn;
|
|
2087
2226
|
var RequestRouter = class {
|
|
2088
2227
|
constructor(transport, rpcClient, config, transportType) {
|
|
@@ -2189,6 +2328,13 @@ _RequestRouter_instances = new WeakSet();
|
|
|
2189
2328
|
withAnalyticsTracking_fn = function(options, execute) {
|
|
2190
2329
|
return __async(this, null, function* () {
|
|
2191
2330
|
var _a3;
|
|
2331
|
+
if (((_a3 = this.config.analytics) == null ? void 0 : _a3.enabled) === false) {
|
|
2332
|
+
try {
|
|
2333
|
+
return yield execute();
|
|
2334
|
+
} catch (error) {
|
|
2335
|
+
throw toRPCInvokeMethodErr(error);
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2192
2338
|
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRequested_fn).call(this, options);
|
|
2193
2339
|
try {
|
|
2194
2340
|
const result = yield execute();
|
|
@@ -2199,16 +2345,9 @@ withAnalyticsTracking_fn = function(options, execute) {
|
|
|
2199
2345
|
if (isRejection) {
|
|
2200
2346
|
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRejected_fn).call(this, options);
|
|
2201
2347
|
} else {
|
|
2202
|
-
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options);
|
|
2203
|
-
}
|
|
2204
|
-
if (error instanceof RPCInvokeMethodErr) {
|
|
2205
|
-
throw error;
|
|
2348
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options, error);
|
|
2206
2349
|
}
|
|
2207
|
-
|
|
2208
|
-
throw new RPCInvokeMethodErr(
|
|
2209
|
-
(_a3 = castError.message) != null ? _a3 : "Unknown error",
|
|
2210
|
-
castError.code
|
|
2211
|
-
);
|
|
2350
|
+
throw toRPCInvokeMethodErr(error);
|
|
2212
2351
|
}
|
|
2213
2352
|
});
|
|
2214
2353
|
};
|
|
@@ -2234,13 +2373,14 @@ trackWalletActionSucceeded_fn = function(options) {
|
|
|
2234
2373
|
analytics.track("mmconnect_wallet_action_succeeded", props);
|
|
2235
2374
|
});
|
|
2236
2375
|
};
|
|
2237
|
-
trackWalletActionFailed_fn = function(options) {
|
|
2376
|
+
trackWalletActionFailed_fn = function(options, error) {
|
|
2238
2377
|
return __async(this, null, function* () {
|
|
2239
2378
|
const props = yield getWalletActionAnalyticsProperties(
|
|
2240
2379
|
this.config,
|
|
2241
2380
|
this.config.storage,
|
|
2242
2381
|
options,
|
|
2243
|
-
this.transportType
|
|
2382
|
+
this.transportType,
|
|
2383
|
+
extractErrorDiagnostics(error)
|
|
2244
2384
|
);
|
|
2245
2385
|
analytics.track("mmconnect_wallet_action_failed", props);
|
|
2246
2386
|
});
|
|
@@ -2668,26 +2808,65 @@ walletInvokeMethod_fn = function(request) {
|
|
|
2668
2808
|
init_utils2();
|
|
2669
2809
|
var logger2 = createLogger("metamask-sdk:core");
|
|
2670
2810
|
var SINGLETON_KEY = "__METAMASK_CONNECT_MULTICHAIN_SINGLETON__";
|
|
2811
|
+
function normalizeAnalyticsOptions(analyticsOptions) {
|
|
2812
|
+
var _a3;
|
|
2813
|
+
return __spreadProps(__spreadValues({}, analyticsOptions != null ? analyticsOptions : {}), {
|
|
2814
|
+
enabled: (_a3 = analyticsOptions == null ? void 0 : analyticsOptions.enabled) != null ? _a3 : true,
|
|
2815
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
2816
|
+
integrationType: (analyticsOptions == null ? void 0 : analyticsOptions.integrationType) || "direct"
|
|
2817
|
+
});
|
|
2818
|
+
}
|
|
2819
|
+
function isAnalyticsEnabled(options) {
|
|
2820
|
+
var _a3;
|
|
2821
|
+
return ((_a3 = options.analytics) == null ? void 0 : _a3.enabled) !== false;
|
|
2822
|
+
}
|
|
2823
|
+
function setupAnalyticsGlobals(options, storage, setAnonId) {
|
|
2824
|
+
return __async(this, null, function* () {
|
|
2825
|
+
var _a3, _b;
|
|
2826
|
+
if (!isAnalyticsEnabled(options)) {
|
|
2827
|
+
setAnonId == null ? void 0 : setAnonId(void 0);
|
|
2828
|
+
analytics2.disable();
|
|
2829
|
+
return;
|
|
2830
|
+
}
|
|
2831
|
+
const platform = getPlatformType();
|
|
2832
|
+
const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
|
|
2833
|
+
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
2834
|
+
if (!isBrowser && !isReactNative2) {
|
|
2835
|
+
return;
|
|
2836
|
+
}
|
|
2837
|
+
const dappId = getDappId(options.dapp);
|
|
2838
|
+
const anonId = yield storage.getAnonId();
|
|
2839
|
+
setAnonId == null ? void 0 : setAnonId(anonId);
|
|
2840
|
+
const { integrationType } = (_a3 = options.analytics) != null ? _a3 : {
|
|
2841
|
+
integrationType: ""
|
|
2842
|
+
};
|
|
2843
|
+
analytics2.setGlobalProperty("mmconnect_versions", (_b = options.versions) != null ? _b : {});
|
|
2844
|
+
analytics2.setGlobalProperty("dapp_id", dappId);
|
|
2845
|
+
analytics2.setGlobalProperty("anon_id", anonId);
|
|
2846
|
+
analytics2.setGlobalProperty("platform", platform);
|
|
2847
|
+
if (integrationType) {
|
|
2848
|
+
analytics2.setGlobalProperty("integration_types", [integrationType]);
|
|
2849
|
+
}
|
|
2850
|
+
analytics2.enable();
|
|
2851
|
+
});
|
|
2852
|
+
}
|
|
2671
2853
|
var _a2, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _transportType, _listener, _anonId, _sdkInfo, _MetaMaskConnectMultichain_instances, 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;
|
|
2672
2854
|
var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
|
|
2673
2855
|
constructor(options) {
|
|
2674
|
-
var _a3, _b, _c, _d
|
|
2856
|
+
var _a3, _b, _c, _d;
|
|
2675
2857
|
const withDappMetadata = setupDappMetadata(options);
|
|
2676
|
-
const integrationType = ((_a3 = options.analytics) == null ? void 0 : _a3.integrationType) || "direct";
|
|
2677
2858
|
const allOptions = __spreadProps(__spreadValues({}, withDappMetadata), {
|
|
2678
2859
|
ui: __spreadProps(__spreadValues({}, withDappMetadata.ui), {
|
|
2679
|
-
preferExtension: (
|
|
2680
|
-
showInstallModal: (
|
|
2681
|
-
headless: (
|
|
2682
|
-
}),
|
|
2683
|
-
analytics: __spreadProps(__spreadValues({}, (_e = options.analytics) != null ? _e : {}), {
|
|
2684
|
-
integrationType
|
|
2860
|
+
preferExtension: (_a3 = withDappMetadata.ui.preferExtension) != null ? _a3 : true,
|
|
2861
|
+
showInstallModal: (_b = withDappMetadata.ui.showInstallModal) != null ? _b : false,
|
|
2862
|
+
headless: (_c = withDappMetadata.ui.headless) != null ? _c : false
|
|
2685
2863
|
}),
|
|
2864
|
+
analytics: normalizeAnalyticsOptions(options.analytics),
|
|
2686
2865
|
versions: __spreadValues({
|
|
2687
2866
|
// typeof guard needed: Metro (React Native) bundles TS source directly,
|
|
2688
2867
|
// bypassing the tsup build that substitutes __PACKAGE_VERSION__.
|
|
2689
|
-
"connect-multichain": false ? "unknown" : "0.
|
|
2690
|
-
}, (
|
|
2868
|
+
"connect-multichain": false ? "unknown" : "0.15.0"
|
|
2869
|
+
}, (_d = options.versions) != null ? _d : {})
|
|
2691
2870
|
});
|
|
2692
2871
|
super(allOptions);
|
|
2693
2872
|
__privateAdd(this, _MetaMaskConnectMultichain_instances);
|
|
@@ -2743,25 +2922,22 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2743
2922
|
// Creates a singleton instance of MetaMaskConnectMultichain.
|
|
2744
2923
|
// If the singleton already exists, it merges the incoming options with the
|
|
2745
2924
|
// existing singleton options for the following keys: `api.supportedNetworks`,
|
|
2746
|
-
// `versions`, `ui.*`, `mobile.*`, `transport.extensionId`,
|
|
2747
|
-
// that the value for `dapp` is not merged as it does not
|
|
2748
|
-
// subsequent calls to `createMultichainClient` to have a
|
|
2925
|
+
// `analytics`, `versions`, `ui.*`, `mobile.*`, `transport.extensionId`,
|
|
2926
|
+
// `debug`. Take note that the value for `dapp` is not merged as it does not
|
|
2927
|
+
// make sense for subsequent calls to `createMultichainClient` to have a
|
|
2928
|
+
// different `dapp` value.
|
|
2749
2929
|
static create(options) {
|
|
2750
2930
|
return __async(this, null, function* () {
|
|
2751
|
-
var _a3
|
|
2931
|
+
var _a3;
|
|
2752
2932
|
const globalObject = getGlobalObject();
|
|
2753
2933
|
const existing = globalObject[SINGLETON_KEY];
|
|
2754
2934
|
if (existing) {
|
|
2755
2935
|
const instance = yield existing;
|
|
2756
2936
|
instance.mergeOptions(options);
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
if ((_b = options.analytics) == null ? void 0 : _b.integrationType) {
|
|
2762
|
-
analytics2.setGlobalProperty("integration_types", [
|
|
2763
|
-
options.analytics.integrationType
|
|
2764
|
-
]);
|
|
2937
|
+
if (instance instanceof _MetaMaskConnectMultichain) {
|
|
2938
|
+
yield __privateMethod(_a3 = instance, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(_a3);
|
|
2939
|
+
} else {
|
|
2940
|
+
yield setupAnalyticsGlobals(instance.options, instance.storage);
|
|
2765
2941
|
}
|
|
2766
2942
|
if (options.debug) {
|
|
2767
2943
|
enableDebug("metamask-sdk:*");
|
|
@@ -2811,21 +2987,23 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2811
2987
|
} else {
|
|
2812
2988
|
transportType = "mwp" /* MWP */;
|
|
2813
2989
|
}
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2990
|
+
if (isAnalyticsEnabled(this.options)) {
|
|
2991
|
+
try {
|
|
2992
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2993
|
+
this.options,
|
|
2994
|
+
this.storage
|
|
2995
|
+
);
|
|
2996
|
+
const dappConfiguredChains = Object.keys(
|
|
2997
|
+
this.options.api.supportedNetworks
|
|
2998
|
+
);
|
|
2999
|
+
analytics2.track("mmconnect_connection_initiated", __spreadProps(__spreadValues({}, baseProps), {
|
|
3000
|
+
transport_type: transportType,
|
|
3001
|
+
dapp_configured_chains: dappConfiguredChains,
|
|
3002
|
+
dapp_requested_chains: scopes
|
|
3003
|
+
}));
|
|
3004
|
+
} catch (error) {
|
|
3005
|
+
logger2("Error tracking connection_initiated event", error);
|
|
3006
|
+
}
|
|
2829
3007
|
}
|
|
2830
3008
|
const sessionData = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getCaipSession_fn).call(this);
|
|
2831
3009
|
const { mergedScopes, mergedCaipAccountIds, mergedSessionProperties } = mergeRequestedSessionWithExisting(
|
|
@@ -2968,30 +3146,9 @@ _sdkInfo = new WeakMap();
|
|
|
2968
3146
|
_MetaMaskConnectMultichain_instances = new WeakSet();
|
|
2969
3147
|
setupAnalytics_fn = function() {
|
|
2970
3148
|
return __async(this, null, function* () {
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
2975
|
-
if (!isBrowser && !isReactNative2) {
|
|
2976
|
-
return;
|
|
2977
|
-
}
|
|
2978
|
-
const dappId = getDappId(this.options.dapp);
|
|
2979
|
-
const anonId = yield this.storage.getAnonId();
|
|
2980
|
-
__privateSet(this, _anonId, anonId);
|
|
2981
|
-
const { integrationType } = (_a3 = this.options.analytics) != null ? _a3 : {
|
|
2982
|
-
integrationType: ""
|
|
2983
|
-
};
|
|
2984
|
-
analytics2.setGlobalProperty(
|
|
2985
|
-
"mmconnect_versions",
|
|
2986
|
-
(_b = this.options.versions) != null ? _b : {}
|
|
2987
|
-
);
|
|
2988
|
-
analytics2.setGlobalProperty("dapp_id", dappId);
|
|
2989
|
-
analytics2.setGlobalProperty("anon_id", anonId);
|
|
2990
|
-
analytics2.setGlobalProperty("platform", platform);
|
|
2991
|
-
if (integrationType) {
|
|
2992
|
-
analytics2.setGlobalProperty("integration_types", [integrationType]);
|
|
2993
|
-
}
|
|
2994
|
-
analytics2.enable();
|
|
3149
|
+
yield setupAnalyticsGlobals(this.options, this.storage, (anonId) => {
|
|
3150
|
+
__privateSet(this, _anonId, anonId);
|
|
3151
|
+
});
|
|
2995
3152
|
});
|
|
2996
3153
|
};
|
|
2997
3154
|
onTransportNotification_fn = function(payload) {
|
|
@@ -3080,7 +3237,7 @@ buildConnectionMetadata_fn = function() {
|
|
|
3080
3237
|
dapp: this.options.dapp,
|
|
3081
3238
|
sdk: { version: getVersion(), platform: getPlatformType() }
|
|
3082
3239
|
};
|
|
3083
|
-
if (__privateGet(this, _anonId)) {
|
|
3240
|
+
if (isAnalyticsEnabled(this.options) && __privateGet(this, _anonId)) {
|
|
3084
3241
|
metadata.analytics = { remote_session_id: __privateGet(this, _anonId) };
|
|
3085
3242
|
}
|
|
3086
3243
|
return metadata;
|
|
@@ -3362,38 +3519,42 @@ handleConnection_fn = function(promise, scopes, transportType) {
|
|
|
3362
3519
|
this.status = "connecting";
|
|
3363
3520
|
return promise.then(() => __async(this, null, function* () {
|
|
3364
3521
|
this.status = "connected";
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3522
|
+
if (isAnalyticsEnabled(this.options)) {
|
|
3523
|
+
try {
|
|
3524
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
3525
|
+
this.options,
|
|
3526
|
+
this.storage
|
|
3527
|
+
);
|
|
3528
|
+
analytics2.track("mmconnect_connection_established", __spreadProps(__spreadValues({}, baseProps), {
|
|
3529
|
+
transport_type: transportType,
|
|
3530
|
+
user_permissioned_chains: scopes
|
|
3531
|
+
}));
|
|
3532
|
+
} catch (error) {
|
|
3533
|
+
logger2("Error tracking connection_established event", error);
|
|
3534
|
+
}
|
|
3376
3535
|
}
|
|
3377
3536
|
return void 0;
|
|
3378
3537
|
})).catch((error) => __async(this, null, function* () {
|
|
3379
3538
|
this.status = "disconnected";
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3539
|
+
if (isAnalyticsEnabled(this.options)) {
|
|
3540
|
+
try {
|
|
3541
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
3542
|
+
this.options,
|
|
3543
|
+
this.storage
|
|
3544
|
+
);
|
|
3545
|
+
const isRejection = isRejectionError(error);
|
|
3546
|
+
if (isRejection) {
|
|
3547
|
+
analytics2.track("mmconnect_connection_rejected", __spreadProps(__spreadValues({}, baseProps), {
|
|
3548
|
+
transport_type: transportType
|
|
3549
|
+
}));
|
|
3550
|
+
} else {
|
|
3551
|
+
analytics2.track("mmconnect_connection_failed", __spreadValues(__spreadProps(__spreadValues({}, baseProps), {
|
|
3552
|
+
transport_type: transportType
|
|
3553
|
+
}), extractErrorDiagnostics(error)));
|
|
3554
|
+
}
|
|
3555
|
+
} catch (e) {
|
|
3556
|
+
logger2("Error tracking connection failed/rejected event", error);
|
|
3394
3557
|
}
|
|
3395
|
-
} catch (e) {
|
|
3396
|
-
logger2("Error tracking connection failed/rejected event", error);
|
|
3397
3558
|
}
|
|
3398
3559
|
throw error;
|
|
3399
3560
|
}));
|
|
@@ -3830,6 +3991,7 @@ export {
|
|
|
3830
3991
|
StoreAdapter,
|
|
3831
3992
|
StoreClient,
|
|
3832
3993
|
TransportType,
|
|
3994
|
+
classifyFailureReason,
|
|
3833
3995
|
createLogger,
|
|
3834
3996
|
createMultichainClient,
|
|
3835
3997
|
enableDebug,
|