@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
|
@@ -16286,7 +16286,7 @@ var MetaMaskSDK = (() => {
|
|
|
16286
16286
|
}
|
|
16287
16287
|
/**
|
|
16288
16288
|
* Merges the given options into the current instance options.
|
|
16289
|
-
* Only the mergeable keys are updated (api.supportedNetworks, versions, ui.*, mobile.*, transport.extensionId, debug).
|
|
16289
|
+
* Only the mergeable keys are updated (api.supportedNetworks, analytics, versions, ui.*, mobile.*, transport.extensionId, debug).
|
|
16290
16290
|
* The main thing to note is that the value for `dapp` is not merged as it does not make sense for
|
|
16291
16291
|
* subsequent calls to `createMultichainClient` to have a different `dapp` value.
|
|
16292
16292
|
* Used when createMultichainClient is called with an existing singleton.
|
|
@@ -16294,23 +16294,28 @@ var MetaMaskSDK = (() => {
|
|
|
16294
16294
|
* @param partial - Options to merge/overwrite onto the current instance
|
|
16295
16295
|
*/
|
|
16296
16296
|
mergeOptions(partial) {
|
|
16297
|
-
var _a4, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
16297
|
+
var _a4, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
16298
16298
|
const opts = this.options;
|
|
16299
|
+
const analytics2 = __spreadValues(__spreadValues({}, opts.analytics), (_a4 = partial.analytics) != null ? _a4 : {});
|
|
16300
|
+
if (((_b = opts.analytics) == null ? void 0 : _b.enabled) === false) {
|
|
16301
|
+
analytics2.enabled = false;
|
|
16302
|
+
}
|
|
16299
16303
|
this.options = __spreadProps(__spreadValues({}, opts), {
|
|
16300
16304
|
api: __spreadProps(__spreadValues({}, opts.api), {
|
|
16301
|
-
supportedNetworks: __spreadValues(__spreadValues({}, opts.api.supportedNetworks), (
|
|
16305
|
+
supportedNetworks: __spreadValues(__spreadValues({}, opts.api.supportedNetworks), (_d = (_c = partial.api) == null ? void 0 : _c.supportedNetworks) != null ? _d : {})
|
|
16302
16306
|
}),
|
|
16303
|
-
versions: __spreadValues(__spreadValues({}, opts.versions), (
|
|
16307
|
+
versions: __spreadValues(__spreadValues({}, opts.versions), (_e = partial.versions) != null ? _e : {}),
|
|
16308
|
+
analytics: __spreadValues({}, analytics2),
|
|
16304
16309
|
ui: __spreadProps(__spreadValues({}, opts.ui), {
|
|
16305
|
-
headless: (
|
|
16306
|
-
preferExtension: (
|
|
16307
|
-
showInstallModal: (
|
|
16310
|
+
headless: (_g = (_f = partial.ui) == null ? void 0 : _f.headless) != null ? _g : opts.ui.headless,
|
|
16311
|
+
preferExtension: (_i = (_h = partial.ui) == null ? void 0 : _h.preferExtension) != null ? _i : opts.ui.preferExtension,
|
|
16312
|
+
showInstallModal: (_k = (_j = partial.ui) == null ? void 0 : _j.showInstallModal) != null ? _k : opts.ui.showInstallModal
|
|
16308
16313
|
}),
|
|
16309
|
-
mobile: __spreadValues(__spreadValues({}, opts.mobile), (
|
|
16310
|
-
transport: __spreadProps(__spreadValues({}, (
|
|
16311
|
-
extensionId: (
|
|
16314
|
+
mobile: __spreadValues(__spreadValues({}, opts.mobile), (_l = partial.mobile) != null ? _l : {}),
|
|
16315
|
+
transport: __spreadProps(__spreadValues({}, (_m = opts.transport) != null ? _m : {}), {
|
|
16316
|
+
extensionId: (_p = (_n = partial.transport) == null ? void 0 : _n.extensionId) != null ? _p : (_o = opts.transport) == null ? void 0 : _o.extensionId
|
|
16312
16317
|
}),
|
|
16313
|
-
debug: (
|
|
16318
|
+
debug: (_q = partial.debug) != null ? _q : opts.debug
|
|
16314
16319
|
});
|
|
16315
16320
|
}
|
|
16316
16321
|
};
|
|
@@ -17129,17 +17134,94 @@ var MetaMaskSDK = (() => {
|
|
|
17129
17134
|
});
|
|
17130
17135
|
|
|
17131
17136
|
// src/multichain/utils/analytics.ts
|
|
17137
|
+
function sanitiseErrorMessage(message) {
|
|
17138
|
+
if (!message) {
|
|
17139
|
+
return void 0;
|
|
17140
|
+
}
|
|
17141
|
+
let sanitised = message;
|
|
17142
|
+
for (const { pattern: pattern2, replacement } of SANITISE_PATTERNS) {
|
|
17143
|
+
sanitised = sanitised.replace(pattern2, replacement);
|
|
17144
|
+
}
|
|
17145
|
+
if (sanitised.length > ERROR_MESSAGE_SAMPLE_MAX_LENGTH) {
|
|
17146
|
+
sanitised = `${sanitised.slice(0, ERROR_MESSAGE_SAMPLE_MAX_LENGTH - 1)}\u2026`;
|
|
17147
|
+
}
|
|
17148
|
+
return sanitised;
|
|
17149
|
+
}
|
|
17150
|
+
function getUnwrappedErrorDetails(error) {
|
|
17151
|
+
var _a4, _b, _c, _d;
|
|
17152
|
+
if (typeof error !== "object" || error === null) {
|
|
17153
|
+
return { code: void 0, message: "" };
|
|
17154
|
+
}
|
|
17155
|
+
if (error instanceof RPCInvokeMethodErr) {
|
|
17156
|
+
return {
|
|
17157
|
+
code: (_a4 = error.rpcCode) != null ? _a4 : error.code,
|
|
17158
|
+
message: (_c = (_b = error.rpcMessage) != null ? _b : error.message) != null ? _c : ""
|
|
17159
|
+
};
|
|
17160
|
+
}
|
|
17161
|
+
const errorObj = error;
|
|
17162
|
+
return {
|
|
17163
|
+
code: errorObj.code,
|
|
17164
|
+
message: (_d = errorObj.message) != null ? _d : ""
|
|
17165
|
+
};
|
|
17166
|
+
}
|
|
17132
17167
|
function isRejectionError(error) {
|
|
17133
|
-
var _a4, _b;
|
|
17134
17168
|
if (typeof error !== "object" || error === null) {
|
|
17135
17169
|
return false;
|
|
17136
17170
|
}
|
|
17171
|
+
const { code, message } = getUnwrappedErrorDetails(error);
|
|
17172
|
+
const errorMessage = message.toLowerCase();
|
|
17173
|
+
return code === 4001 || errorMessage.includes("reject") || errorMessage.includes("denied") || errorMessage.includes("cancel") || // Narrow "user …" matches — bare "user" is too greedy (catches Account
|
|
17174
|
+
// Abstraction errors like "user operation reverted").
|
|
17175
|
+
errorMessage.includes("user rejected") || errorMessage.includes("user denied") || errorMessage.includes("user cancelled") || errorMessage.includes("user canceled");
|
|
17176
|
+
}
|
|
17177
|
+
function classifyFailureReason(error) {
|
|
17178
|
+
var _a4, _b;
|
|
17179
|
+
if (typeof error !== "object" || error === null) {
|
|
17180
|
+
return "unknown";
|
|
17181
|
+
}
|
|
17137
17182
|
const errorObj = error;
|
|
17138
|
-
const
|
|
17139
|
-
const
|
|
17140
|
-
|
|
17141
|
-
|
|
17142
|
-
|
|
17183
|
+
const errorName = (_a4 = errorObj.name) != null ? _a4 : "";
|
|
17184
|
+
const errorMessageRaw = (_b = errorObj.message) != null ? _b : "";
|
|
17185
|
+
const errorMessage = errorMessageRaw.toLowerCase();
|
|
17186
|
+
const { code } = getUnwrappedErrorDetails(error);
|
|
17187
|
+
if (typeof code === "number") {
|
|
17188
|
+
if (code === -32601) {
|
|
17189
|
+
return "wallet_method_unsupported";
|
|
17190
|
+
}
|
|
17191
|
+
if (code === -32602) {
|
|
17192
|
+
return "wallet_invalid_params";
|
|
17193
|
+
}
|
|
17194
|
+
if (code === -32603) {
|
|
17195
|
+
return "wallet_internal_error";
|
|
17196
|
+
}
|
|
17197
|
+
if (code <= -32e3 && code >= -32099) {
|
|
17198
|
+
return "wallet_internal_error";
|
|
17199
|
+
}
|
|
17200
|
+
if (code === 4100) {
|
|
17201
|
+
return "wallet_unauthorized";
|
|
17202
|
+
}
|
|
17203
|
+
if (code === 4200) {
|
|
17204
|
+
return "wallet_method_unsupported";
|
|
17205
|
+
}
|
|
17206
|
+
if (code === 4902) {
|
|
17207
|
+
return "unrecognized_chain";
|
|
17208
|
+
}
|
|
17209
|
+
}
|
|
17210
|
+
if (errorName === "TransportTimeoutError" || errorMessageRaw === "Request timeout" || errorMessage.includes("timed out") || errorMessage.includes("timeout")) {
|
|
17211
|
+
return "transport_timeout";
|
|
17212
|
+
}
|
|
17213
|
+
if (errorName === "TransportError" || errorMessage.includes("not connected") || errorMessage.includes("transport disconnect") || errorMessage.includes("connection lost") || errorMessage.includes("socket closed")) {
|
|
17214
|
+
return "transport_disconnect";
|
|
17215
|
+
}
|
|
17216
|
+
return "unknown";
|
|
17217
|
+
}
|
|
17218
|
+
function extractErrorDiagnostics(error) {
|
|
17219
|
+
const failureReason = classifyFailureReason(error);
|
|
17220
|
+
const { code, message } = getUnwrappedErrorDetails(error);
|
|
17221
|
+
const messageSample = sanitiseErrorMessage(message);
|
|
17222
|
+
return __spreadValues(__spreadValues({
|
|
17223
|
+
failure_reason: failureReason
|
|
17224
|
+
}, typeof code === "number" ? { error_code: code } : {}), messageSample ? { error_message_sample: messageSample } : {});
|
|
17143
17225
|
}
|
|
17144
17226
|
function getBaseAnalyticsProperties(options, storage) {
|
|
17145
17227
|
return __async(this, null, function* () {
|
|
@@ -17155,26 +17237,61 @@ var MetaMaskSDK = (() => {
|
|
|
17155
17237
|
};
|
|
17156
17238
|
});
|
|
17157
17239
|
}
|
|
17158
|
-
function getWalletActionAnalyticsProperties(options, storage, invokeOptions, transportType) {
|
|
17240
|
+
function getWalletActionAnalyticsProperties(options, storage, invokeOptions, transportType, extra) {
|
|
17159
17241
|
return __async(this, null, function* () {
|
|
17160
17242
|
var _a4;
|
|
17161
17243
|
const dappId = getDappId(options.dapp);
|
|
17162
17244
|
const anonId = yield storage.getAnonId();
|
|
17163
|
-
return {
|
|
17245
|
+
return __spreadValues(__spreadValues(__spreadValues({
|
|
17164
17246
|
mmconnect_versions: (_a4 = options.versions) != null ? _a4 : {},
|
|
17165
17247
|
dapp_id: dappId,
|
|
17166
17248
|
method: invokeOptions.request.method,
|
|
17167
17249
|
caip_chain_id: invokeOptions.scope,
|
|
17168
17250
|
anon_id: anonId,
|
|
17169
17251
|
transport_type: transportType
|
|
17170
|
-
};
|
|
17252
|
+
}, (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 } : {});
|
|
17171
17253
|
});
|
|
17172
17254
|
}
|
|
17255
|
+
var ERROR_MESSAGE_SAMPLE_MAX_LENGTH, SANITISE_PATTERNS;
|
|
17173
17256
|
var init_analytics = __esm({
|
|
17174
17257
|
"src/multichain/utils/analytics.ts"() {
|
|
17175
17258
|
"use strict";
|
|
17176
17259
|
init_utils4();
|
|
17177
17260
|
init_domain();
|
|
17261
|
+
ERROR_MESSAGE_SAMPLE_MAX_LENGTH = 200;
|
|
17262
|
+
SANITISE_PATTERNS = [
|
|
17263
|
+
// EVM-style 20-byte hex addresses (e.g. `0x` + 40 hex chars).
|
|
17264
|
+
{ pattern: /0x[a-fA-F0-9]{40}/gu, replacement: "<addr>" },
|
|
17265
|
+
// Other long hex blobs: tx hashes, signatures, raw byte strings, large
|
|
17266
|
+
// hex amounts. 16+ hex chars catches 32-byte hashes/signatures without
|
|
17267
|
+
// snagging EVM method selectors (8 chars) or short hex codes.
|
|
17268
|
+
{ pattern: /(?:0x)?[a-fA-F0-9]{16,}/gu, replacement: "<hex>" },
|
|
17269
|
+
// URLs of any scheme up to the first whitespace / quote / closing paren.
|
|
17270
|
+
// Catches RPC endpoints, dapp deeplinks, query strings with secrets.
|
|
17271
|
+
{ pattern: /https?:\/\/[^\s"')]+/gu, replacement: "<url>" },
|
|
17272
|
+
// Bech32 addresses: short HRP (1-10 lowercase chars) + `1` separator +
|
|
17273
|
+
// ≥38 chars of Bech32 data alphabet `[ac-hj-np-z02-9]` (excludes the
|
|
17274
|
+
// look-alike chars `b`, `i`, `o`, `1`). Covers Bitcoin SegWit
|
|
17275
|
+
// (`bc1…`/`tb1…`) and Cosmos-SDK chains (`cosmos1…`, `osmo1…`,
|
|
17276
|
+
// `juno1…`, `inj1…`, etc.) without enumerating every HRP. Runs before
|
|
17277
|
+
// the Base58 pattern below — see header comment for why.
|
|
17278
|
+
{
|
|
17279
|
+
pattern: /\b[a-z]{1,10}1[ac-hj-np-z02-9]{38,}\b/gu,
|
|
17280
|
+
replacement: "<addr>"
|
|
17281
|
+
},
|
|
17282
|
+
// Base58 tokens (32+ chars, Base58 alphabet `[1-9A-HJ-NP-Za-km-z]`).
|
|
17283
|
+
// Covers Solana pubkeys (32-44 chars), Solana tx signatures (~88 chars),
|
|
17284
|
+
// and Bitcoin Base58 addresses ≥32 chars. The 32-char floor and `\b`
|
|
17285
|
+
// word boundary keep English words and shorter alphanumerics safe.
|
|
17286
|
+
{
|
|
17287
|
+
pattern: /\b[1-9A-HJ-NP-Za-km-z]{32,}\b/gu,
|
|
17288
|
+
replacement: "<addr>"
|
|
17289
|
+
},
|
|
17290
|
+
// Long decimal numbers — token amounts, gas units, timestamps, lamports.
|
|
17291
|
+
// 10+ digits catches typical chain quantities without affecting JSON-RPC
|
|
17292
|
+
// codes (-32601, 4001, etc.) or short numeric IDs.
|
|
17293
|
+
{ pattern: /\d{10,}/gu, replacement: "<num>" }
|
|
17294
|
+
];
|
|
17178
17295
|
}
|
|
17179
17296
|
});
|
|
17180
17297
|
|
|
@@ -25977,13 +26094,24 @@ var MetaMaskSDK = (() => {
|
|
|
25977
26094
|
return resolveConnection();
|
|
25978
26095
|
});
|
|
25979
26096
|
this.dappClient.on("message", initialConnectionMessageHandler);
|
|
26097
|
+
const platformType = getPlatformType();
|
|
26098
|
+
const isQRCodeFlow = [
|
|
26099
|
+
"web-desktop" /* DesktopWeb */,
|
|
26100
|
+
"nodejs" /* NonBrowser */
|
|
26101
|
+
].includes(platformType);
|
|
26102
|
+
const initialPayload = {
|
|
26103
|
+
name: MULTICHAIN_PROVIDER_STREAM_NAME,
|
|
26104
|
+
data: request2
|
|
26105
|
+
};
|
|
25980
26106
|
dappClient.connect({
|
|
25981
26107
|
mode: "trusted",
|
|
25982
|
-
initialPayload:
|
|
25983
|
-
|
|
25984
|
-
|
|
26108
|
+
initialPayload: isQRCodeFlow ? void 0 : initialPayload
|
|
26109
|
+
}).then(() => __async(this, null, function* () {
|
|
26110
|
+
if (isQRCodeFlow) {
|
|
26111
|
+
return dappClient.sendRequest(initialPayload);
|
|
25985
26112
|
}
|
|
25986
|
-
|
|
26113
|
+
return void 0;
|
|
26114
|
+
})).catch((error) => {
|
|
25987
26115
|
if (initialConnectionMessageHandler) {
|
|
25988
26116
|
this.dappClient.off(
|
|
25989
26117
|
"message",
|
|
@@ -37771,6 +37899,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
37771
37899
|
StoreAdapter: () => StoreAdapter,
|
|
37772
37900
|
StoreClient: () => StoreClient,
|
|
37773
37901
|
TransportType: () => TransportType,
|
|
37902
|
+
classifyFailureReason: () => classifyFailureReason,
|
|
37774
37903
|
createLogger: () => createLogger,
|
|
37775
37904
|
createMultichainClient: () => createMultichainClient,
|
|
37776
37905
|
enableDebug: () => enableDebug,
|
|
@@ -38298,6 +38427,17 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
38298
38427
|
this.batch.push(item);
|
|
38299
38428
|
this.schedule();
|
|
38300
38429
|
}
|
|
38430
|
+
/**
|
|
38431
|
+
* Clears queued items and cancels the scheduled flush.
|
|
38432
|
+
*/
|
|
38433
|
+
clear() {
|
|
38434
|
+
this.batch = [];
|
|
38435
|
+
this.currentTimeoutMs = this.baseTimeoutMs;
|
|
38436
|
+
if (this.timeoutId) {
|
|
38437
|
+
clearTimeout(this.timeoutId);
|
|
38438
|
+
this.timeoutId = null;
|
|
38439
|
+
}
|
|
38440
|
+
}
|
|
38301
38441
|
schedule() {
|
|
38302
38442
|
if (this.batch.length > 0 && !this.timeoutId) {
|
|
38303
38443
|
this.timeoutId = setTimeout(() => {
|
|
@@ -38349,6 +38489,13 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
38349
38489
|
enable() {
|
|
38350
38490
|
this.enabled = true;
|
|
38351
38491
|
}
|
|
38492
|
+
/**
|
|
38493
|
+
* Disables analytics and drops queued events.
|
|
38494
|
+
*/
|
|
38495
|
+
disable() {
|
|
38496
|
+
this.enabled = false;
|
|
38497
|
+
this.sender.clear();
|
|
38498
|
+
}
|
|
38352
38499
|
setGlobalProperty(key, value) {
|
|
38353
38500
|
if (key === "integration_types") {
|
|
38354
38501
|
const existing = Array.isArray(this.properties.integration_types) ? this.properties.integration_types : [];
|
|
@@ -38506,6 +38653,17 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
38506
38653
|
init_domain();
|
|
38507
38654
|
init_utils4();
|
|
38508
38655
|
init_analytics();
|
|
38656
|
+
function toRPCInvokeMethodErr(error) {
|
|
38657
|
+
var _a4;
|
|
38658
|
+
if (error instanceof RPCInvokeMethodErr) {
|
|
38659
|
+
return error;
|
|
38660
|
+
}
|
|
38661
|
+
const castError = error;
|
|
38662
|
+
return new RPCInvokeMethodErr(
|
|
38663
|
+
(_a4 = castError.message) != null ? _a4 : "Unknown error",
|
|
38664
|
+
castError.code
|
|
38665
|
+
);
|
|
38666
|
+
}
|
|
38509
38667
|
var _RequestRouter_instances, withAnalyticsTracking_fn, trackWalletActionRequested_fn, trackWalletActionSucceeded_fn, trackWalletActionFailed_fn, trackWalletActionRejected_fn;
|
|
38510
38668
|
var RequestRouter = class {
|
|
38511
38669
|
constructor(transport, rpcClient, config, transportType) {
|
|
@@ -38612,6 +38770,13 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
38612
38770
|
withAnalyticsTracking_fn = function(options, execute) {
|
|
38613
38771
|
return __async(this, null, function* () {
|
|
38614
38772
|
var _a4;
|
|
38773
|
+
if (((_a4 = this.config.analytics) == null ? void 0 : _a4.enabled) === false) {
|
|
38774
|
+
try {
|
|
38775
|
+
return yield execute();
|
|
38776
|
+
} catch (error) {
|
|
38777
|
+
throw toRPCInvokeMethodErr(error);
|
|
38778
|
+
}
|
|
38779
|
+
}
|
|
38615
38780
|
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRequested_fn).call(this, options);
|
|
38616
38781
|
try {
|
|
38617
38782
|
const result = yield execute();
|
|
@@ -38622,16 +38787,9 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
38622
38787
|
if (isRejection) {
|
|
38623
38788
|
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRejected_fn).call(this, options);
|
|
38624
38789
|
} else {
|
|
38625
|
-
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options);
|
|
38790
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options, error);
|
|
38626
38791
|
}
|
|
38627
|
-
|
|
38628
|
-
throw error;
|
|
38629
|
-
}
|
|
38630
|
-
const castError = error;
|
|
38631
|
-
throw new RPCInvokeMethodErr(
|
|
38632
|
-
(_a4 = castError.message) != null ? _a4 : "Unknown error",
|
|
38633
|
-
castError.code
|
|
38634
|
-
);
|
|
38792
|
+
throw toRPCInvokeMethodErr(error);
|
|
38635
38793
|
}
|
|
38636
38794
|
});
|
|
38637
38795
|
};
|
|
@@ -38657,13 +38815,14 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
38657
38815
|
analytics.track("mmconnect_wallet_action_succeeded", props);
|
|
38658
38816
|
});
|
|
38659
38817
|
};
|
|
38660
|
-
trackWalletActionFailed_fn = function(options) {
|
|
38818
|
+
trackWalletActionFailed_fn = function(options, error) {
|
|
38661
38819
|
return __async(this, null, function* () {
|
|
38662
38820
|
const props = yield getWalletActionAnalyticsProperties(
|
|
38663
38821
|
this.config,
|
|
38664
38822
|
this.config.storage,
|
|
38665
38823
|
options,
|
|
38666
|
-
this.transportType
|
|
38824
|
+
this.transportType,
|
|
38825
|
+
extractErrorDiagnostics(error)
|
|
38667
38826
|
);
|
|
38668
38827
|
analytics.track("mmconnect_wallet_action_failed", props);
|
|
38669
38828
|
});
|
|
@@ -39089,26 +39248,65 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39089
39248
|
init_utils4();
|
|
39090
39249
|
var logger2 = createLogger("metamask-sdk:core");
|
|
39091
39250
|
var SINGLETON_KEY = "__METAMASK_CONNECT_MULTICHAIN_SINGLETON__";
|
|
39251
|
+
function normalizeAnalyticsOptions(analyticsOptions) {
|
|
39252
|
+
var _a4;
|
|
39253
|
+
return __spreadProps(__spreadValues({}, analyticsOptions != null ? analyticsOptions : {}), {
|
|
39254
|
+
enabled: (_a4 = analyticsOptions == null ? void 0 : analyticsOptions.enabled) != null ? _a4 : true,
|
|
39255
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
39256
|
+
integrationType: (analyticsOptions == null ? void 0 : analyticsOptions.integrationType) || "direct"
|
|
39257
|
+
});
|
|
39258
|
+
}
|
|
39259
|
+
function isAnalyticsEnabled(options) {
|
|
39260
|
+
var _a4;
|
|
39261
|
+
return ((_a4 = options.analytics) == null ? void 0 : _a4.enabled) !== false;
|
|
39262
|
+
}
|
|
39263
|
+
function setupAnalyticsGlobals(options, storage, setAnonId) {
|
|
39264
|
+
return __async(this, null, function* () {
|
|
39265
|
+
var _a4, _b;
|
|
39266
|
+
if (!isAnalyticsEnabled(options)) {
|
|
39267
|
+
setAnonId == null ? void 0 : setAnonId(void 0);
|
|
39268
|
+
analytics.disable();
|
|
39269
|
+
return;
|
|
39270
|
+
}
|
|
39271
|
+
const platform = getPlatformType();
|
|
39272
|
+
const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
|
|
39273
|
+
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
39274
|
+
if (!isBrowser && !isReactNative2) {
|
|
39275
|
+
return;
|
|
39276
|
+
}
|
|
39277
|
+
const dappId = getDappId(options.dapp);
|
|
39278
|
+
const anonId = yield storage.getAnonId();
|
|
39279
|
+
setAnonId == null ? void 0 : setAnonId(anonId);
|
|
39280
|
+
const { integrationType } = (_a4 = options.analytics) != null ? _a4 : {
|
|
39281
|
+
integrationType: ""
|
|
39282
|
+
};
|
|
39283
|
+
analytics.setGlobalProperty("mmconnect_versions", (_b = options.versions) != null ? _b : {});
|
|
39284
|
+
analytics.setGlobalProperty("dapp_id", dappId);
|
|
39285
|
+
analytics.setGlobalProperty("anon_id", anonId);
|
|
39286
|
+
analytics.setGlobalProperty("platform", platform);
|
|
39287
|
+
if (integrationType) {
|
|
39288
|
+
analytics.setGlobalProperty("integration_types", [integrationType]);
|
|
39289
|
+
}
|
|
39290
|
+
analytics.enable();
|
|
39291
|
+
});
|
|
39292
|
+
}
|
|
39092
39293
|
var _a3, _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;
|
|
39093
39294
|
var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
|
|
39094
39295
|
constructor(options) {
|
|
39095
|
-
var _a4, _b, _c, _d
|
|
39296
|
+
var _a4, _b, _c, _d;
|
|
39096
39297
|
const withDappMetadata = setupDappMetadata(options);
|
|
39097
|
-
const integrationType = ((_a4 = options.analytics) == null ? void 0 : _a4.integrationType) || "direct";
|
|
39098
39298
|
const allOptions = __spreadProps(__spreadValues({}, withDappMetadata), {
|
|
39099
39299
|
ui: __spreadProps(__spreadValues({}, withDappMetadata.ui), {
|
|
39100
|
-
preferExtension: (
|
|
39101
|
-
showInstallModal: (
|
|
39102
|
-
headless: (
|
|
39103
|
-
}),
|
|
39104
|
-
analytics: __spreadProps(__spreadValues({}, (_e = options.analytics) != null ? _e : {}), {
|
|
39105
|
-
integrationType
|
|
39300
|
+
preferExtension: (_a4 = withDappMetadata.ui.preferExtension) != null ? _a4 : true,
|
|
39301
|
+
showInstallModal: (_b = withDappMetadata.ui.showInstallModal) != null ? _b : false,
|
|
39302
|
+
headless: (_c = withDappMetadata.ui.headless) != null ? _c : false
|
|
39106
39303
|
}),
|
|
39304
|
+
analytics: normalizeAnalyticsOptions(options.analytics),
|
|
39107
39305
|
versions: __spreadValues({
|
|
39108
39306
|
// typeof guard needed: Metro (React Native) bundles TS source directly,
|
|
39109
39307
|
// bypassing the tsup build that substitutes __PACKAGE_VERSION__.
|
|
39110
|
-
"connect-multichain": false ? "unknown" : "0.
|
|
39111
|
-
}, (
|
|
39308
|
+
"connect-multichain": false ? "unknown" : "0.15.0"
|
|
39309
|
+
}, (_d = options.versions) != null ? _d : {})
|
|
39112
39310
|
});
|
|
39113
39311
|
super(allOptions);
|
|
39114
39312
|
__privateAdd(this, _MetaMaskConnectMultichain_instances);
|
|
@@ -39164,25 +39362,22 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39164
39362
|
// Creates a singleton instance of MetaMaskConnectMultichain.
|
|
39165
39363
|
// If the singleton already exists, it merges the incoming options with the
|
|
39166
39364
|
// existing singleton options for the following keys: `api.supportedNetworks`,
|
|
39167
|
-
// `versions`, `ui.*`, `mobile.*`, `transport.extensionId`,
|
|
39168
|
-
// that the value for `dapp` is not merged as it does not
|
|
39169
|
-
// subsequent calls to `createMultichainClient` to have a
|
|
39365
|
+
// `analytics`, `versions`, `ui.*`, `mobile.*`, `transport.extensionId`,
|
|
39366
|
+
// `debug`. Take note that the value for `dapp` is not merged as it does not
|
|
39367
|
+
// make sense for subsequent calls to `createMultichainClient` to have a
|
|
39368
|
+
// different `dapp` value.
|
|
39170
39369
|
static create(options) {
|
|
39171
39370
|
return __async(this, null, function* () {
|
|
39172
|
-
var _a4
|
|
39371
|
+
var _a4;
|
|
39173
39372
|
const globalObject = getGlobalObject();
|
|
39174
39373
|
const existing = globalObject[SINGLETON_KEY];
|
|
39175
39374
|
if (existing) {
|
|
39176
39375
|
const instance2 = yield existing;
|
|
39177
39376
|
instance2.mergeOptions(options);
|
|
39178
|
-
|
|
39179
|
-
|
|
39180
|
-
|
|
39181
|
-
|
|
39182
|
-
if ((_b = options.analytics) == null ? void 0 : _b.integrationType) {
|
|
39183
|
-
analytics.setGlobalProperty("integration_types", [
|
|
39184
|
-
options.analytics.integrationType
|
|
39185
|
-
]);
|
|
39377
|
+
if (instance2 instanceof _MetaMaskConnectMultichain) {
|
|
39378
|
+
yield __privateMethod(_a4 = instance2, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(_a4);
|
|
39379
|
+
} else {
|
|
39380
|
+
yield setupAnalyticsGlobals(instance2.options, instance2.storage);
|
|
39186
39381
|
}
|
|
39187
39382
|
if (options.debug) {
|
|
39188
39383
|
enableDebug("metamask-sdk:*");
|
|
@@ -39232,21 +39427,23 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39232
39427
|
} else {
|
|
39233
39428
|
transportType = "mwp" /* MWP */;
|
|
39234
39429
|
}
|
|
39235
|
-
|
|
39236
|
-
|
|
39237
|
-
|
|
39238
|
-
|
|
39239
|
-
|
|
39240
|
-
|
|
39241
|
-
|
|
39242
|
-
|
|
39243
|
-
|
|
39244
|
-
|
|
39245
|
-
|
|
39246
|
-
|
|
39247
|
-
|
|
39248
|
-
|
|
39249
|
-
|
|
39430
|
+
if (isAnalyticsEnabled(this.options)) {
|
|
39431
|
+
try {
|
|
39432
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
39433
|
+
this.options,
|
|
39434
|
+
this.storage
|
|
39435
|
+
);
|
|
39436
|
+
const dappConfiguredChains = Object.keys(
|
|
39437
|
+
this.options.api.supportedNetworks
|
|
39438
|
+
);
|
|
39439
|
+
analytics.track("mmconnect_connection_initiated", __spreadProps(__spreadValues({}, baseProps), {
|
|
39440
|
+
transport_type: transportType,
|
|
39441
|
+
dapp_configured_chains: dappConfiguredChains,
|
|
39442
|
+
dapp_requested_chains: scopes
|
|
39443
|
+
}));
|
|
39444
|
+
} catch (error) {
|
|
39445
|
+
logger2("Error tracking connection_initiated event", error);
|
|
39446
|
+
}
|
|
39250
39447
|
}
|
|
39251
39448
|
const sessionData = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getCaipSession_fn).call(this);
|
|
39252
39449
|
const { mergedScopes, mergedCaipAccountIds, mergedSessionProperties } = mergeRequestedSessionWithExisting(
|
|
@@ -39389,30 +39586,9 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39389
39586
|
_MetaMaskConnectMultichain_instances = new WeakSet();
|
|
39390
39587
|
setupAnalytics_fn = function() {
|
|
39391
39588
|
return __async(this, null, function* () {
|
|
39392
|
-
|
|
39393
|
-
|
|
39394
|
-
|
|
39395
|
-
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
39396
|
-
if (!isBrowser && !isReactNative2) {
|
|
39397
|
-
return;
|
|
39398
|
-
}
|
|
39399
|
-
const dappId = getDappId(this.options.dapp);
|
|
39400
|
-
const anonId = yield this.storage.getAnonId();
|
|
39401
|
-
__privateSet(this, _anonId, anonId);
|
|
39402
|
-
const { integrationType } = (_a4 = this.options.analytics) != null ? _a4 : {
|
|
39403
|
-
integrationType: ""
|
|
39404
|
-
};
|
|
39405
|
-
analytics.setGlobalProperty(
|
|
39406
|
-
"mmconnect_versions",
|
|
39407
|
-
(_b = this.options.versions) != null ? _b : {}
|
|
39408
|
-
);
|
|
39409
|
-
analytics.setGlobalProperty("dapp_id", dappId);
|
|
39410
|
-
analytics.setGlobalProperty("anon_id", anonId);
|
|
39411
|
-
analytics.setGlobalProperty("platform", platform);
|
|
39412
|
-
if (integrationType) {
|
|
39413
|
-
analytics.setGlobalProperty("integration_types", [integrationType]);
|
|
39414
|
-
}
|
|
39415
|
-
analytics.enable();
|
|
39589
|
+
yield setupAnalyticsGlobals(this.options, this.storage, (anonId) => {
|
|
39590
|
+
__privateSet(this, _anonId, anonId);
|
|
39591
|
+
});
|
|
39416
39592
|
});
|
|
39417
39593
|
};
|
|
39418
39594
|
onTransportNotification_fn = function(payload) {
|
|
@@ -39501,7 +39677,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39501
39677
|
dapp: this.options.dapp,
|
|
39502
39678
|
sdk: { version: getVersion(), platform: getPlatformType() }
|
|
39503
39679
|
};
|
|
39504
|
-
if (__privateGet(this, _anonId)) {
|
|
39680
|
+
if (isAnalyticsEnabled(this.options) && __privateGet(this, _anonId)) {
|
|
39505
39681
|
metadata.analytics = { remote_session_id: __privateGet(this, _anonId) };
|
|
39506
39682
|
}
|
|
39507
39683
|
return metadata;
|
|
@@ -39783,38 +39959,42 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39783
39959
|
this.status = "connecting";
|
|
39784
39960
|
return promise.then(() => __async(this, null, function* () {
|
|
39785
39961
|
this.status = "connected";
|
|
39786
|
-
|
|
39787
|
-
|
|
39788
|
-
|
|
39789
|
-
|
|
39790
|
-
|
|
39791
|
-
|
|
39792
|
-
|
|
39793
|
-
|
|
39794
|
-
|
|
39795
|
-
|
|
39796
|
-
|
|
39962
|
+
if (isAnalyticsEnabled(this.options)) {
|
|
39963
|
+
try {
|
|
39964
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
39965
|
+
this.options,
|
|
39966
|
+
this.storage
|
|
39967
|
+
);
|
|
39968
|
+
analytics.track("mmconnect_connection_established", __spreadProps(__spreadValues({}, baseProps), {
|
|
39969
|
+
transport_type: transportType,
|
|
39970
|
+
user_permissioned_chains: scopes
|
|
39971
|
+
}));
|
|
39972
|
+
} catch (error) {
|
|
39973
|
+
logger2("Error tracking connection_established event", error);
|
|
39974
|
+
}
|
|
39797
39975
|
}
|
|
39798
39976
|
return void 0;
|
|
39799
39977
|
})).catch((error) => __async(this, null, function* () {
|
|
39800
39978
|
this.status = "disconnected";
|
|
39801
|
-
|
|
39802
|
-
|
|
39803
|
-
|
|
39804
|
-
|
|
39805
|
-
|
|
39806
|
-
|
|
39807
|
-
|
|
39808
|
-
|
|
39809
|
-
|
|
39810
|
-
|
|
39811
|
-
|
|
39812
|
-
|
|
39813
|
-
|
|
39814
|
-
|
|
39979
|
+
if (isAnalyticsEnabled(this.options)) {
|
|
39980
|
+
try {
|
|
39981
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
39982
|
+
this.options,
|
|
39983
|
+
this.storage
|
|
39984
|
+
);
|
|
39985
|
+
const isRejection = isRejectionError(error);
|
|
39986
|
+
if (isRejection) {
|
|
39987
|
+
analytics.track("mmconnect_connection_rejected", __spreadProps(__spreadValues({}, baseProps), {
|
|
39988
|
+
transport_type: transportType
|
|
39989
|
+
}));
|
|
39990
|
+
} else {
|
|
39991
|
+
analytics.track("mmconnect_connection_failed", __spreadValues(__spreadProps(__spreadValues({}, baseProps), {
|
|
39992
|
+
transport_type: transportType
|
|
39993
|
+
}), extractErrorDiagnostics(error)));
|
|
39994
|
+
}
|
|
39995
|
+
} catch (e) {
|
|
39996
|
+
logger2("Error tracking connection failed/rejected event", error);
|
|
39815
39997
|
}
|
|
39816
|
-
} catch (e) {
|
|
39817
|
-
logger2("Error tracking connection failed/rejected event", error);
|
|
39818
39998
|
}
|
|
39819
39999
|
throw error;
|
|
39820
40000
|
}));
|