@metamask/connect-multichain 0.3.1 → 0.4.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 -13
- package/README.md +1 -1
- package/dist/browser/es/connect-multichain.d.mts +4 -6
- package/dist/browser/es/connect-multichain.mjs +593 -588
- 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 +4 -6
- package/dist/browser/iife/connect-multichain.js +3821 -2109
- 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 +4 -6
- package/dist/browser/umd/connect-multichain.js +593 -588
- 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 +4 -6
- package/dist/node/cjs/connect-multichain.js +594 -600
- 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 +4 -6
- package/dist/node/es/connect-multichain.mjs +593 -599
- 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 +4 -6
- package/dist/react-native/es/connect-multichain.mjs +580 -584
- 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/types.d.ts +2 -4
- package/dist/src/domain/multichain/types.d.ts.map +1 -1
- package/dist/src/multichain/index.d.ts +3 -22
- package/dist/src/multichain/index.d.ts.map +1 -1
- package/dist/src/multichain/index.js +422 -424
- package/dist/src/multichain/index.js.map +1 -1
- package/dist/src/multichain/rpc/requestRouter.js +17 -19
- package/dist/src/multichain/rpc/requestRouter.js.map +1 -1
- package/dist/src/multichain/transports/default/index.d.ts +2 -0
- package/dist/src/multichain/transports/default/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/default/index.js +6 -0
- package/dist/src/multichain/transports/default/index.js.map +1 -1
- package/dist/src/multichain/transports/mwp/index.d.ts +2 -1
- package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/mwp/index.js +41 -16
- package/dist/src/multichain/transports/mwp/index.js.map +1 -1
- package/dist/src/ui/index.d.ts +2 -6
- package/dist/src/ui/index.d.ts.map +1 -1
- package/dist/src/ui/index.js +8 -49
- package/dist/src/ui/index.js.map +1 -1
- package/dist/src/ui/modals/node/install.js +2 -2
- package/dist/src/ui/modals/node/install.js.map +1 -1
- package/dist/src/ui/preload.native.d.ts +5 -0
- package/dist/src/ui/preload.native.d.ts.map +1 -0
- package/dist/src/ui/preload.native.js +18 -0
- package/dist/src/ui/preload.native.js.map +1 -0
- package/dist/src/ui/preload.web.d.ts +5 -0
- package/dist/src/ui/preload.web.d.ts.map +1 -0
- package/dist/src/ui/{qr.js → preload.web.js} +13 -18
- package/dist/src/ui/preload.web.js.map +1 -0
- package/dist/types/connect-multichain.d.ts +4 -6
- package/package.json +7 -7
- package/dist/src/ui/qr.d.ts +0 -3
- package/dist/src/ui/qr.d.ts.map +0 -1
- package/dist/src/ui/qr.js.map +0 -1
|
@@ -235,8 +235,8 @@ var init_logger = __esm({
|
|
|
235
235
|
debug.enable(namespace);
|
|
236
236
|
};
|
|
237
237
|
isEnabled = (namespace, storage) => __async(null, null, function* () {
|
|
238
|
-
var
|
|
239
|
-
if ("process" in globalThis && ((
|
|
238
|
+
var _a2;
|
|
239
|
+
if ("process" in globalThis && ((_a2 = process == null ? void 0 : process.env) == null ? void 0 : _a2.DEBUG)) {
|
|
240
240
|
const { DEBUG } = process.env;
|
|
241
241
|
return isNamespaceEnabled(DEBUG, namespace);
|
|
242
242
|
}
|
|
@@ -406,35 +406,35 @@ var init_multichain = __esm({
|
|
|
406
406
|
// src/domain/platform/index.ts
|
|
407
407
|
import Bowser from "bowser";
|
|
408
408
|
function isNotBrowser() {
|
|
409
|
-
var
|
|
409
|
+
var _a2;
|
|
410
410
|
if (typeof window === "undefined") {
|
|
411
411
|
return true;
|
|
412
412
|
}
|
|
413
413
|
if (!(window == null ? void 0 : window.navigator)) {
|
|
414
414
|
return true;
|
|
415
415
|
}
|
|
416
|
-
if (typeof global !== "undefined" && ((
|
|
416
|
+
if (typeof global !== "undefined" && ((_a2 = global == null ? void 0 : global.navigator) == null ? void 0 : _a2.product) === "ReactNative") {
|
|
417
417
|
return true;
|
|
418
418
|
}
|
|
419
419
|
return (navigator == null ? void 0 : navigator.product) === "ReactNative";
|
|
420
420
|
}
|
|
421
421
|
function isReactNative() {
|
|
422
|
-
var
|
|
422
|
+
var _a2;
|
|
423
423
|
const hasWindowNavigator = typeof window !== "undefined" && window.navigator !== void 0;
|
|
424
424
|
const nav = hasWindowNavigator ? window.navigator : void 0;
|
|
425
425
|
if (!nav) {
|
|
426
426
|
return false;
|
|
427
427
|
}
|
|
428
|
-
return hasWindowNavigator && ((
|
|
428
|
+
return hasWindowNavigator && ((_a2 = window.navigator) == null ? void 0 : _a2.product) === "ReactNative";
|
|
429
429
|
}
|
|
430
430
|
function isMetaMaskMobileWebView() {
|
|
431
431
|
return typeof window !== "undefined" && // @ts-expect-error ReactNativeWebView should be defined
|
|
432
432
|
Boolean(window.ReactNativeWebView) && Boolean(window.navigator.userAgent.endsWith("MetaMaskMobile"));
|
|
433
433
|
}
|
|
434
434
|
function isMobile() {
|
|
435
|
-
var
|
|
435
|
+
var _a2, _b;
|
|
436
436
|
const browser = Bowser.parse(window.navigator.userAgent);
|
|
437
|
-
return ((
|
|
437
|
+
return ((_a2 = browser == null ? void 0 : browser.platform) == null ? void 0 : _a2.type) === "mobile" || ((_b = browser == null ? void 0 : browser.platform) == null ? void 0 : _b.type) === "tablet";
|
|
438
438
|
}
|
|
439
439
|
function getPlatformType() {
|
|
440
440
|
if (isReactNative()) {
|
|
@@ -452,11 +452,11 @@ function getPlatformType() {
|
|
|
452
452
|
return "web-desktop" /* DesktopWeb */;
|
|
453
453
|
}
|
|
454
454
|
function isMetamaskExtensionInstalled() {
|
|
455
|
-
var
|
|
455
|
+
var _a2;
|
|
456
456
|
if (typeof window === "undefined") {
|
|
457
457
|
return false;
|
|
458
458
|
}
|
|
459
|
-
return Boolean((
|
|
459
|
+
return Boolean((_a2 = window.ethereum) == null ? void 0 : _a2.isMetaMask);
|
|
460
460
|
}
|
|
461
461
|
function isSecure() {
|
|
462
462
|
const platformType = getPlatformType();
|
|
@@ -487,8 +487,8 @@ var init_platform = __esm({
|
|
|
487
487
|
return new Promise((resolve) => {
|
|
488
488
|
const providers = [];
|
|
489
489
|
const handler = (event) => {
|
|
490
|
-
var
|
|
491
|
-
if ((_b = (
|
|
490
|
+
var _a2, _b;
|
|
491
|
+
if ((_b = (_a2 = event == null ? void 0 : event.detail) == null ? void 0 : _a2.info) == null ? void 0 : _b.rdns) {
|
|
492
492
|
providers.push(event.detail);
|
|
493
493
|
}
|
|
494
494
|
};
|
|
@@ -498,8 +498,8 @@ var init_platform = __esm({
|
|
|
498
498
|
window.removeEventListener("eip6963:announceProvider", handler);
|
|
499
499
|
const hasMetaMask = providers.some(
|
|
500
500
|
(provider) => {
|
|
501
|
-
var
|
|
502
|
-
return (_b = (
|
|
501
|
+
var _a2, _b;
|
|
502
|
+
return (_b = (_a2 = provider == null ? void 0 : provider.info) == null ? void 0 : _a2.rdns) == null ? void 0 : _b.startsWith("io.metamask");
|
|
503
503
|
}
|
|
504
504
|
);
|
|
505
505
|
resolve(hasMetaMask);
|
|
@@ -603,8 +603,8 @@ function compressString(str) {
|
|
|
603
603
|
return base64Encode(binaryString);
|
|
604
604
|
}
|
|
605
605
|
function getDappId(dapp) {
|
|
606
|
-
var
|
|
607
|
-
return (
|
|
606
|
+
var _a2;
|
|
607
|
+
return (_a2 = dapp.url) != null ? _a2 : dapp.name;
|
|
608
608
|
}
|
|
609
609
|
function openDeeplink(options, deeplink, universalLink) {
|
|
610
610
|
const { mobile } = options;
|
|
@@ -634,10 +634,10 @@ function getOptionalScopes(scopes) {
|
|
|
634
634
|
);
|
|
635
635
|
}
|
|
636
636
|
function setupDappMetadata(options) {
|
|
637
|
-
var
|
|
637
|
+
var _a2, _b;
|
|
638
638
|
const platform = getPlatformType();
|
|
639
639
|
const isBrowser = platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */ || platform === "in-app-browser" /* MetaMaskMobileWebview */;
|
|
640
|
-
if (!((
|
|
640
|
+
if (!((_a2 = options.dapp) == null ? void 0 : _a2.name)) {
|
|
641
641
|
throw new Error("You must provide dapp name");
|
|
642
642
|
}
|
|
643
643
|
if (isBrowser) {
|
|
@@ -708,17 +708,17 @@ function getValidAccounts(caipAccountIds) {
|
|
|
708
708
|
);
|
|
709
709
|
}
|
|
710
710
|
function addValidAccounts(optionalScopes, validAccounts) {
|
|
711
|
-
var
|
|
711
|
+
var _a2;
|
|
712
712
|
if (!optionalScopes || !(validAccounts == null ? void 0 : validAccounts.length)) {
|
|
713
713
|
return optionalScopes;
|
|
714
714
|
}
|
|
715
715
|
const result = Object.fromEntries(
|
|
716
716
|
Object.entries(optionalScopes).map(([scope, scopeData]) => {
|
|
717
|
-
var
|
|
717
|
+
var _a3, _b, _c;
|
|
718
718
|
return [
|
|
719
719
|
scope,
|
|
720
720
|
{
|
|
721
|
-
methods: [...(
|
|
721
|
+
methods: [...(_a3 = scopeData == null ? void 0 : scopeData.methods) != null ? _a3 : []],
|
|
722
722
|
notifications: [...(_b = scopeData == null ? void 0 : scopeData.notifications) != null ? _b : []],
|
|
723
723
|
accounts: [...(_c = scopeData == null ? void 0 : scopeData.accounts) != null ? _c : []]
|
|
724
724
|
}
|
|
@@ -732,7 +732,7 @@ function addValidAccounts(optionalScopes, validAccounts) {
|
|
|
732
732
|
if (!accountsByChain.has(chainKey)) {
|
|
733
733
|
accountsByChain.set(chainKey, []);
|
|
734
734
|
}
|
|
735
|
-
(
|
|
735
|
+
(_a2 = accountsByChain.get(chainKey)) == null ? void 0 : _a2.push(accountId);
|
|
736
736
|
}
|
|
737
737
|
for (const [scopeKey, scopeData] of Object.entries(result)) {
|
|
738
738
|
if (!(scopeData == null ? void 0 : scopeData.accounts)) {
|
|
@@ -762,7 +762,7 @@ var init_utils = __esm({
|
|
|
762
762
|
"use strict";
|
|
763
763
|
init_domain();
|
|
764
764
|
extractFavicon = () => {
|
|
765
|
-
var
|
|
765
|
+
var _a2;
|
|
766
766
|
if (typeof document === "undefined") {
|
|
767
767
|
return void 0;
|
|
768
768
|
}
|
|
@@ -770,7 +770,7 @@ var init_utils = __esm({
|
|
|
770
770
|
const nodeList = document.getElementsByTagName("link");
|
|
771
771
|
for (let i = 0; i < nodeList.length; i++) {
|
|
772
772
|
if (nodeList[i].getAttribute("rel") === "icon" || nodeList[i].getAttribute("rel") === "shortcut icon") {
|
|
773
|
-
favicon = (
|
|
773
|
+
favicon = (_a2 = nodeList[i].getAttribute("href")) != null ? _a2 : void 0;
|
|
774
774
|
}
|
|
775
775
|
}
|
|
776
776
|
return favicon;
|
|
@@ -780,25 +780,25 @@ var init_utils = __esm({
|
|
|
780
780
|
|
|
781
781
|
// src/multichain/utils/analytics.ts
|
|
782
782
|
function isRejectionError(error) {
|
|
783
|
-
var
|
|
783
|
+
var _a2, _b;
|
|
784
784
|
if (typeof error !== "object" || error === null) {
|
|
785
785
|
return false;
|
|
786
786
|
}
|
|
787
787
|
const errorObj = error;
|
|
788
788
|
const errorCode = errorObj.code;
|
|
789
|
-
const errorMessage = (_b = (
|
|
789
|
+
const errorMessage = (_b = (_a2 = errorObj.message) == null ? void 0 : _a2.toLowerCase()) != null ? _b : "";
|
|
790
790
|
return errorCode === 4001 || // User rejected request (common EIP-1193 code)
|
|
791
791
|
errorCode === 4100 || // Unauthorized (common rejection code)
|
|
792
792
|
errorMessage.includes("reject") || errorMessage.includes("denied") || errorMessage.includes("cancel") || errorMessage.includes("user");
|
|
793
793
|
}
|
|
794
794
|
function getBaseAnalyticsProperties(options, storage) {
|
|
795
795
|
return __async(this, null, function* () {
|
|
796
|
-
var
|
|
796
|
+
var _a2, _b;
|
|
797
797
|
const version = getVersion();
|
|
798
798
|
const dappId = getDappId(options.dapp);
|
|
799
799
|
const platform = getPlatformType();
|
|
800
800
|
const anonId = yield storage.getAnonId();
|
|
801
|
-
const integrationType = (_b = (
|
|
801
|
+
const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "unknown" /* UNKNOWN */;
|
|
802
802
|
return {
|
|
803
803
|
mmconnect_version: version,
|
|
804
804
|
dapp_id: dappId,
|
|
@@ -810,11 +810,11 @@ function getBaseAnalyticsProperties(options, storage) {
|
|
|
810
810
|
}
|
|
811
811
|
function getWalletActionAnalyticsProperties(options, storage, invokeOptions) {
|
|
812
812
|
return __async(this, null, function* () {
|
|
813
|
-
var
|
|
813
|
+
var _a2, _b;
|
|
814
814
|
const version = getVersion();
|
|
815
815
|
const dappId = getDappId(options.dapp);
|
|
816
816
|
const anonId = yield storage.getAnonId();
|
|
817
|
-
const integrationType = (_b = (
|
|
817
|
+
const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "unknown";
|
|
818
818
|
return {
|
|
819
819
|
mmconnect_version: version,
|
|
820
820
|
dapp_id: dappId,
|
|
@@ -859,30 +859,6 @@ var init_domain = __esm({
|
|
|
859
859
|
}
|
|
860
860
|
});
|
|
861
861
|
|
|
862
|
-
// src/ui/qr.ts
|
|
863
|
-
function preloadQR() {
|
|
864
|
-
return __async(this, null, function* () {
|
|
865
|
-
if (encodeQRImpl) {
|
|
866
|
-
return;
|
|
867
|
-
}
|
|
868
|
-
const mod = yield import("@paulmillr/qr");
|
|
869
|
-
encodeQRImpl = mod.default;
|
|
870
|
-
});
|
|
871
|
-
}
|
|
872
|
-
function encodeQRSync(input) {
|
|
873
|
-
if (!encodeQRImpl) {
|
|
874
|
-
throw new Error("QR module not preloaded. Call preloadQR() first.");
|
|
875
|
-
}
|
|
876
|
-
return encodeQRImpl(input, "ascii");
|
|
877
|
-
}
|
|
878
|
-
var encodeQRImpl;
|
|
879
|
-
var init_qr = __esm({
|
|
880
|
-
"src/ui/qr.ts"() {
|
|
881
|
-
"use strict";
|
|
882
|
-
encodeQRImpl = null;
|
|
883
|
-
}
|
|
884
|
-
});
|
|
885
|
-
|
|
886
862
|
// src/ui/modals/base/utils.ts
|
|
887
863
|
function formatRemainingTime(milliseconds) {
|
|
888
864
|
if (milliseconds <= 0) return "EXPIRED";
|
|
@@ -1001,12 +977,12 @@ var init_AbstractInstallModal = __esm({
|
|
|
1001
977
|
});
|
|
1002
978
|
|
|
1003
979
|
// src/ui/modals/node/install.ts
|
|
980
|
+
import encodeQR from "@paulmillr/qr";
|
|
1004
981
|
var logger4, InstallModal;
|
|
1005
982
|
var init_install = __esm({
|
|
1006
983
|
"src/ui/modals/node/install.ts"() {
|
|
1007
984
|
"use strict";
|
|
1008
985
|
init_domain();
|
|
1009
|
-
init_qr();
|
|
1010
986
|
init_AbstractInstallModal();
|
|
1011
987
|
init_utils3();
|
|
1012
988
|
logger4 = createLogger("metamask-sdk:ui");
|
|
@@ -1014,7 +990,7 @@ var init_install = __esm({
|
|
|
1014
990
|
displayQRWithCountdown(qrCodeLink, expiresInMs) {
|
|
1015
991
|
const isExpired = expiresInMs <= 0;
|
|
1016
992
|
const formattedTime = formatRemainingTime(expiresInMs);
|
|
1017
|
-
const qrCode =
|
|
993
|
+
const qrCode = encodeQR(qrCodeLink, "ascii");
|
|
1018
994
|
console.clear();
|
|
1019
995
|
console.log(qrCode);
|
|
1020
996
|
if (isExpired) {
|
|
@@ -1122,8 +1098,8 @@ var init_node2 = __esm({
|
|
|
1122
1098
|
}
|
|
1123
1099
|
get(key) {
|
|
1124
1100
|
return __async(this, null, function* () {
|
|
1125
|
-
var
|
|
1126
|
-
return (
|
|
1101
|
+
var _a2;
|
|
1102
|
+
return (_a2 = this.storage.get(key)) != null ? _a2 : null;
|
|
1127
1103
|
});
|
|
1128
1104
|
}
|
|
1129
1105
|
set(key, value) {
|
|
@@ -1200,8 +1176,8 @@ var RpcClient = class {
|
|
|
1200
1176
|
});
|
|
1201
1177
|
}
|
|
1202
1178
|
getRpcEndpoint(scope) {
|
|
1203
|
-
var
|
|
1204
|
-
const supportedNetworks = (_c = (_b = (
|
|
1179
|
+
var _a2, _b, _c;
|
|
1180
|
+
const supportedNetworks = (_c = (_b = (_a2 = this.config) == null ? void 0 : _a2.api) == null ? void 0 : _b.supportedNetworks) != null ? _c : {};
|
|
1205
1181
|
const rpcEndpoint = supportedNetworks[scope];
|
|
1206
1182
|
if (!rpcEndpoint) {
|
|
1207
1183
|
throw new MissingRpcEndpointErr(`No RPC endpoint found for scope ${scope}`);
|
|
@@ -1305,13 +1281,18 @@ var RequestRouter = class {
|
|
|
1305
1281
|
const secure = isSecure();
|
|
1306
1282
|
const shouldOpenDeeplink = secure && !showInstallModal;
|
|
1307
1283
|
if (shouldOpenDeeplink) {
|
|
1308
|
-
setTimeout(() => {
|
|
1284
|
+
setTimeout(() => __async(this, null, function* () {
|
|
1285
|
+
const session = yield this.transport.getActiveSession();
|
|
1286
|
+
if (!session) {
|
|
1287
|
+
throw new Error("No active session found");
|
|
1288
|
+
}
|
|
1289
|
+
const url = `${METAMASK_DEEPLINK_BASE}/mwp?id=${encodeURIComponent(session.id)}`;
|
|
1309
1290
|
if (mobile == null ? void 0 : mobile.preferredOpenLink) {
|
|
1310
|
-
mobile.preferredOpenLink(
|
|
1291
|
+
mobile.preferredOpenLink(url, "_self");
|
|
1311
1292
|
} else {
|
|
1312
|
-
openDeeplink(this.config,
|
|
1293
|
+
openDeeplink(this.config, url, METAMASK_CONNECT_BASE_URL);
|
|
1313
1294
|
}
|
|
1314
|
-
}, 10);
|
|
1295
|
+
}), 10);
|
|
1315
1296
|
}
|
|
1316
1297
|
const response = yield request;
|
|
1317
1298
|
if (response.error) {
|
|
@@ -1351,24 +1332,17 @@ var RequestRouter = class {
|
|
|
1351
1332
|
_RequestRouter_instances = new WeakSet();
|
|
1352
1333
|
withAnalyticsTracking_fn = function(options, execute) {
|
|
1353
1334
|
return __async(this, null, function* () {
|
|
1354
|
-
|
|
1355
|
-
if ((_a = this.config.analytics) == null ? void 0 : _a.enabled) {
|
|
1356
|
-
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRequested_fn).call(this, options);
|
|
1357
|
-
}
|
|
1335
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRequested_fn).call(this, options);
|
|
1358
1336
|
try {
|
|
1359
1337
|
const result = yield execute();
|
|
1360
|
-
|
|
1361
|
-
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionSucceeded_fn).call(this, options);
|
|
1362
|
-
}
|
|
1338
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionSucceeded_fn).call(this, options);
|
|
1363
1339
|
return result;
|
|
1364
1340
|
} catch (error) {
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options);
|
|
1371
|
-
}
|
|
1341
|
+
const isRejection = isRejectionError(error);
|
|
1342
|
+
if (isRejection) {
|
|
1343
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRejected_fn).call(this, options);
|
|
1344
|
+
} else {
|
|
1345
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options);
|
|
1372
1346
|
}
|
|
1373
1347
|
throw new RPCInvokeMethodErr(error.message);
|
|
1374
1348
|
}
|
|
@@ -1430,11 +1404,11 @@ var DefaultTransport = class {
|
|
|
1430
1404
|
id: requestId
|
|
1431
1405
|
}, payload);
|
|
1432
1406
|
return new Promise((resolve, reject) => {
|
|
1433
|
-
var
|
|
1407
|
+
var _a2;
|
|
1434
1408
|
const timeout = setTimeout(() => {
|
|
1435
1409
|
__privateGet(this, _pendingRequests).delete(requestId);
|
|
1436
1410
|
reject(new Error("Request timeout"));
|
|
1437
|
-
}, (
|
|
1411
|
+
}, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : __privateGet(this, _defaultRequestOptions).timeout);
|
|
1438
1412
|
__privateGet(this, _pendingRequests).set(requestId, {
|
|
1439
1413
|
resolve: (response) => {
|
|
1440
1414
|
resolve(response);
|
|
@@ -1458,7 +1432,7 @@ var DefaultTransport = class {
|
|
|
1458
1432
|
}
|
|
1459
1433
|
connect(options) {
|
|
1460
1434
|
return __async(this, null, function* () {
|
|
1461
|
-
var
|
|
1435
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1462
1436
|
__privateMethod(this, _DefaultTransport_instances, setupMessageListener_fn).call(this);
|
|
1463
1437
|
yield __privateGet(this, _transport).connect();
|
|
1464
1438
|
const sessionRequest = yield this.request(
|
|
@@ -1471,7 +1445,7 @@ var DefaultTransport = class {
|
|
|
1471
1445
|
let walletSession = sessionRequest.result;
|
|
1472
1446
|
if (walletSession && options && !options.forceRequest) {
|
|
1473
1447
|
const currentScopes = Object.keys(
|
|
1474
|
-
(
|
|
1448
|
+
(_a2 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a2 : {}
|
|
1475
1449
|
);
|
|
1476
1450
|
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
1477
1451
|
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
@@ -1560,6 +1534,9 @@ var DefaultTransport = class {
|
|
|
1560
1534
|
__privateGet(this, _notificationCallbacks).delete(callback);
|
|
1561
1535
|
};
|
|
1562
1536
|
}
|
|
1537
|
+
getActiveSession() {
|
|
1538
|
+
throw new Error("getActiveSession is purposely not implemented for the DefaultTransport");
|
|
1539
|
+
}
|
|
1563
1540
|
};
|
|
1564
1541
|
_notificationCallbacks = new WeakMap();
|
|
1565
1542
|
_transport = new WeakMap();
|
|
@@ -1582,16 +1559,16 @@ notifyCallbacks_fn = function(data) {
|
|
|
1582
1559
|
}
|
|
1583
1560
|
};
|
|
1584
1561
|
isMetamaskProviderEvent_fn = function(event) {
|
|
1585
|
-
var
|
|
1586
|
-
return ((_b = (
|
|
1562
|
+
var _a2, _b;
|
|
1563
|
+
return ((_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.name) === "metamask-provider" && // eslint-disable-next-line no-restricted-globals
|
|
1587
1564
|
event.origin === location.origin;
|
|
1588
1565
|
};
|
|
1589
1566
|
handleResponse_fn = function(event) {
|
|
1590
|
-
var
|
|
1567
|
+
var _a2, _b;
|
|
1591
1568
|
if (!__privateMethod(this, _DefaultTransport_instances, isMetamaskProviderEvent_fn).call(this, event)) {
|
|
1592
1569
|
return;
|
|
1593
1570
|
}
|
|
1594
|
-
const responseData = (_b = (
|
|
1571
|
+
const responseData = (_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.data;
|
|
1595
1572
|
if (typeof responseData === "object" && responseData !== null && "method" in responseData) {
|
|
1596
1573
|
return;
|
|
1597
1574
|
}
|
|
@@ -1613,11 +1590,11 @@ handleResponse_fn = function(event) {
|
|
|
1613
1590
|
}
|
|
1614
1591
|
};
|
|
1615
1592
|
handleNotification_fn = function(event) {
|
|
1616
|
-
var
|
|
1593
|
+
var _a2, _b;
|
|
1617
1594
|
if (!__privateMethod(this, _DefaultTransport_instances, isMetamaskProviderEvent_fn).call(this, event)) {
|
|
1618
1595
|
return;
|
|
1619
1596
|
}
|
|
1620
|
-
const responseData = (_b = (
|
|
1597
|
+
const responseData = (_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.data;
|
|
1621
1598
|
if (typeof responseData === "object" && responseData.method === "metamask_chainChanged" || responseData.method === "metamask_accountsChanged") {
|
|
1622
1599
|
__privateMethod(this, _DefaultTransport_instances, notifyCallbacks_fn).call(this, responseData);
|
|
1623
1600
|
}
|
|
@@ -1745,7 +1722,7 @@ var MWPTransport = class {
|
|
|
1745
1722
|
}
|
|
1746
1723
|
onResumeSuccess(resumeResolve, resumeReject, options) {
|
|
1747
1724
|
return __async(this, null, function* () {
|
|
1748
|
-
var
|
|
1725
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1749
1726
|
try {
|
|
1750
1727
|
const sessionRequest = yield this.request({
|
|
1751
1728
|
method: "wallet_getSession"
|
|
@@ -1756,7 +1733,7 @@ var MWPTransport = class {
|
|
|
1756
1733
|
let walletSession = sessionRequest.result;
|
|
1757
1734
|
if (walletSession && options) {
|
|
1758
1735
|
const currentScopes = Object.keys(
|
|
1759
|
-
(
|
|
1736
|
+
(_a2 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a2 : {}
|
|
1760
1737
|
);
|
|
1761
1738
|
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
1762
1739
|
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
@@ -1821,10 +1798,10 @@ var MWPTransport = class {
|
|
|
1821
1798
|
return cachedWalletSession;
|
|
1822
1799
|
}
|
|
1823
1800
|
return new Promise((resolve, reject) => {
|
|
1824
|
-
var
|
|
1801
|
+
var _a2;
|
|
1825
1802
|
const timeout = setTimeout(() => {
|
|
1826
1803
|
this.rejectRequest(request.id, new TransportTimeoutError());
|
|
1827
|
-
}, (
|
|
1804
|
+
}, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : this.options.requestTimeout);
|
|
1828
1805
|
this.pendingRequests.set(request.id, {
|
|
1829
1806
|
request,
|
|
1830
1807
|
method: request.method,
|
|
@@ -1844,38 +1821,33 @@ var MWPTransport = class {
|
|
|
1844
1821
|
}
|
|
1845
1822
|
connect(options) {
|
|
1846
1823
|
return __async(this, null, function* () {
|
|
1847
|
-
const { dappClient
|
|
1848
|
-
const
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
const [activeSession] = yield sessionStore.list();
|
|
1852
|
-
if (activeSession) {
|
|
1853
|
-
logger("active session found", activeSession);
|
|
1854
|
-
session = activeSession;
|
|
1855
|
-
}
|
|
1856
|
-
} catch (e) {
|
|
1824
|
+
const { dappClient } = this;
|
|
1825
|
+
const session = yield this.getActiveSession();
|
|
1826
|
+
if (session) {
|
|
1827
|
+
logger("active session found", session);
|
|
1857
1828
|
}
|
|
1858
1829
|
let timeout;
|
|
1830
|
+
let initialConnectionMessageHandler;
|
|
1859
1831
|
const connectionPromise = new Promise((resolve, reject) => {
|
|
1860
1832
|
let connection;
|
|
1861
1833
|
if (session) {
|
|
1862
1834
|
connection = new Promise((resumeResolve, resumeReject) => {
|
|
1863
|
-
var
|
|
1835
|
+
var _a2;
|
|
1864
1836
|
if (this.dappClient.state === "CONNECTED") {
|
|
1865
1837
|
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
1866
1838
|
} else {
|
|
1867
1839
|
this.dappClient.once("connected", () => __async(this, null, function* () {
|
|
1868
1840
|
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
1869
1841
|
}));
|
|
1870
|
-
dappClient.resume((
|
|
1842
|
+
dappClient.resume((_a2 = session == null ? void 0 : session.id) != null ? _a2 : "");
|
|
1871
1843
|
}
|
|
1872
1844
|
});
|
|
1873
1845
|
} else {
|
|
1874
1846
|
connection = new Promise(
|
|
1875
1847
|
(resolveConnection, rejectConnection) => {
|
|
1876
|
-
var
|
|
1848
|
+
var _a2, _b;
|
|
1877
1849
|
const optionalScopes = addValidAccounts(
|
|
1878
|
-
getOptionalScopes((
|
|
1850
|
+
getOptionalScopes((_a2 = options == null ? void 0 : options.scopes) != null ? _a2 : []),
|
|
1879
1851
|
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
1880
1852
|
);
|
|
1881
1853
|
const sessionRequest = {
|
|
@@ -1887,12 +1859,18 @@ var MWPTransport = class {
|
|
|
1887
1859
|
method: "wallet_createSession",
|
|
1888
1860
|
params: sessionRequest
|
|
1889
1861
|
};
|
|
1890
|
-
|
|
1862
|
+
initialConnectionMessageHandler = (message) => __async(this, null, function* () {
|
|
1891
1863
|
if (typeof message === "object" && message !== null) {
|
|
1892
1864
|
if ("data" in message) {
|
|
1893
1865
|
const messagePayload = message.data;
|
|
1894
1866
|
if (messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged") {
|
|
1895
1867
|
if (messagePayload.error) {
|
|
1868
|
+
if (initialConnectionMessageHandler) {
|
|
1869
|
+
this.dappClient.off(
|
|
1870
|
+
"message",
|
|
1871
|
+
initialConnectionMessageHandler
|
|
1872
|
+
);
|
|
1873
|
+
}
|
|
1896
1874
|
return rejectConnection(messagePayload.error);
|
|
1897
1875
|
}
|
|
1898
1876
|
yield this.storeWalletSession(
|
|
@@ -1904,14 +1882,23 @@ var MWPTransport = class {
|
|
|
1904
1882
|
}
|
|
1905
1883
|
}
|
|
1906
1884
|
}
|
|
1907
|
-
})
|
|
1885
|
+
});
|
|
1886
|
+
this.dappClient.on("message", initialConnectionMessageHandler);
|
|
1908
1887
|
dappClient.connect({
|
|
1909
1888
|
mode: "trusted",
|
|
1910
1889
|
initialPayload: {
|
|
1911
1890
|
name: MULTICHAIN_PROVIDER_STREAM_NAME,
|
|
1912
1891
|
data: request
|
|
1913
1892
|
}
|
|
1914
|
-
}).catch(
|
|
1893
|
+
}).catch((error) => {
|
|
1894
|
+
if (initialConnectionMessageHandler) {
|
|
1895
|
+
this.dappClient.off(
|
|
1896
|
+
"message",
|
|
1897
|
+
initialConnectionMessageHandler
|
|
1898
|
+
);
|
|
1899
|
+
}
|
|
1900
|
+
rejectConnection(error);
|
|
1901
|
+
});
|
|
1915
1902
|
}
|
|
1916
1903
|
);
|
|
1917
1904
|
}
|
|
@@ -1920,10 +1907,16 @@ var MWPTransport = class {
|
|
|
1920
1907
|
}, this.options.connectionTimeout);
|
|
1921
1908
|
connection.then(resolve).catch(reject);
|
|
1922
1909
|
});
|
|
1923
|
-
return connectionPromise.
|
|
1910
|
+
return connectionPromise.catch((error) => {
|
|
1911
|
+
throw error;
|
|
1912
|
+
}).finally(() => {
|
|
1924
1913
|
if (timeout) {
|
|
1925
1914
|
clearTimeout(timeout);
|
|
1926
1915
|
}
|
|
1916
|
+
if (initialConnectionMessageHandler) {
|
|
1917
|
+
this.dappClient.off("message", initialConnectionMessageHandler);
|
|
1918
|
+
initialConnectionMessageHandler = void 0;
|
|
1919
|
+
}
|
|
1927
1920
|
});
|
|
1928
1921
|
});
|
|
1929
1922
|
}
|
|
@@ -1986,7 +1979,7 @@ var MWPTransport = class {
|
|
|
1986
1979
|
}
|
|
1987
1980
|
getCachedResponse(request) {
|
|
1988
1981
|
return __async(this, null, function* () {
|
|
1989
|
-
var
|
|
1982
|
+
var _a2;
|
|
1990
1983
|
if (request.method === "wallet_getSession") {
|
|
1991
1984
|
const walletGetSession = yield this.kvstore.get(SESSION_STORE_KEY);
|
|
1992
1985
|
if (walletGetSession) {
|
|
@@ -1994,7 +1987,7 @@ var MWPTransport = class {
|
|
|
1994
1987
|
return {
|
|
1995
1988
|
id: request.id,
|
|
1996
1989
|
jsonrpc: "2.0",
|
|
1997
|
-
result: (
|
|
1990
|
+
result: (_a2 = walletSession.params) != null ? _a2 : walletSession.result,
|
|
1998
1991
|
// "what?... why walletSession.params?.."
|
|
1999
1992
|
method: request.method
|
|
2000
1993
|
};
|
|
@@ -2058,10 +2051,10 @@ var MWPTransport = class {
|
|
|
2058
2051
|
yield this.attemptResumeSession();
|
|
2059
2052
|
}
|
|
2060
2053
|
return new Promise((resolve, reject) => {
|
|
2061
|
-
var
|
|
2054
|
+
var _a2;
|
|
2062
2055
|
const timeout = setTimeout(() => {
|
|
2063
2056
|
this.rejectRequest(request.id, new TransportTimeoutError());
|
|
2064
|
-
}, (
|
|
2057
|
+
}, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : this.options.requestTimeout);
|
|
2065
2058
|
this.pendingRequests.set(request.id, {
|
|
2066
2059
|
request,
|
|
2067
2060
|
method: request.method,
|
|
@@ -2085,6 +2078,19 @@ var MWPTransport = class {
|
|
|
2085
2078
|
this.notificationCallbacks.delete(callback);
|
|
2086
2079
|
};
|
|
2087
2080
|
}
|
|
2081
|
+
getActiveSession() {
|
|
2082
|
+
return __async(this, null, function* () {
|
|
2083
|
+
const { kvstore } = this;
|
|
2084
|
+
const sessionStore = new SessionStore(kvstore);
|
|
2085
|
+
try {
|
|
2086
|
+
const [activeSession] = yield sessionStore.list();
|
|
2087
|
+
return activeSession;
|
|
2088
|
+
} catch (error) {
|
|
2089
|
+
logger("error getting active session", error);
|
|
2090
|
+
return void 0;
|
|
2091
|
+
}
|
|
2092
|
+
});
|
|
2093
|
+
}
|
|
2088
2094
|
};
|
|
2089
2095
|
|
|
2090
2096
|
// src/multichain/transports/mwp/KeyManager.ts
|
|
@@ -2117,73 +2123,74 @@ var keymanager = new KeyManager();
|
|
|
2117
2123
|
// src/multichain/index.ts
|
|
2118
2124
|
init_utils();
|
|
2119
2125
|
var logger2 = createLogger("metamask-sdk:core");
|
|
2120
|
-
var
|
|
2126
|
+
var _a, _provider, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo, _MultichainSDK_instances, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn, init_fn, createDappClient_fn, setupMWP_fn, onBeforeUnload_fn, createBeforeUnloadListener_fn, renderInstallModalAsync_fn, showInstallModal_fn, setupDefaultTransport_fn, deeplinkConnect_fn, handleConnection_fn;
|
|
2127
|
+
var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
2121
2128
|
constructor(options) {
|
|
2122
|
-
var
|
|
2129
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
2123
2130
|
const withDappMetadata = setupDappMetadata(options);
|
|
2124
|
-
const integrationType = ((
|
|
2131
|
+
const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "direct";
|
|
2125
2132
|
const allOptions = __spreadProps(__spreadValues({}, withDappMetadata), {
|
|
2126
2133
|
ui: __spreadProps(__spreadValues({}, withDappMetadata.ui), {
|
|
2127
|
-
preferExtension: (
|
|
2128
|
-
showInstallModal: (
|
|
2129
|
-
headless: (
|
|
2134
|
+
preferExtension: (_c = withDappMetadata.ui.preferExtension) != null ? _c : true,
|
|
2135
|
+
showInstallModal: (_d = withDappMetadata.ui.showInstallModal) != null ? _d : false,
|
|
2136
|
+
headless: (_e = withDappMetadata.ui.headless) != null ? _e : false
|
|
2130
2137
|
}),
|
|
2131
|
-
analytics: __spreadProps(__spreadValues({}, (
|
|
2132
|
-
enabled: (_g = (_f = options.analytics) == null ? void 0 : _f.enabled) != null ? _g : true,
|
|
2138
|
+
analytics: __spreadProps(__spreadValues({}, (_f = options.analytics) != null ? _f : {}), {
|
|
2133
2139
|
integrationType
|
|
2134
2140
|
})
|
|
2135
2141
|
});
|
|
2136
2142
|
super(allOptions);
|
|
2137
|
-
this
|
|
2138
|
-
this
|
|
2139
|
-
this
|
|
2140
|
-
this
|
|
2143
|
+
__privateAdd(this, _MultichainSDK_instances);
|
|
2144
|
+
__privateAdd(this, _provider);
|
|
2145
|
+
__privateAdd(this, _transport2);
|
|
2146
|
+
__privateAdd(this, _dappClient);
|
|
2147
|
+
__privateAdd(this, _beforeUnloadListener);
|
|
2148
|
+
this._state = "pending";
|
|
2149
|
+
__privateAdd(this, _listener);
|
|
2150
|
+
__privateAdd(this, _sdkInfo, `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(_a = this.options.dapp.url) != null ? _a : this.options.dapp.name} dAppTitle/${this.options.dapp.name}`);
|
|
2141
2151
|
}
|
|
2142
2152
|
get state() {
|
|
2143
|
-
return this.
|
|
2153
|
+
return this._state;
|
|
2144
2154
|
}
|
|
2145
2155
|
set state(value) {
|
|
2146
|
-
var
|
|
2147
|
-
this.
|
|
2148
|
-
(_b = (
|
|
2156
|
+
var _a2, _b;
|
|
2157
|
+
this._state = value;
|
|
2158
|
+
(_b = (_a2 = this.options.transport) == null ? void 0 : _a2.onNotification) == null ? void 0 : _b.call(_a2, {
|
|
2149
2159
|
method: "stateChanged",
|
|
2150
2160
|
params: value
|
|
2151
2161
|
});
|
|
2152
2162
|
}
|
|
2153
2163
|
get provider() {
|
|
2154
|
-
if (!this
|
|
2155
|
-
this
|
|
2156
|
-
return this
|
|
2164
|
+
if (!__privateGet(this, _provider) && __privateGet(this, _transport2)) {
|
|
2165
|
+
__privateSet(this, _provider, getMultichainClient({ transport: __privateGet(this, _transport2) }));
|
|
2166
|
+
return __privateGet(this, _provider);
|
|
2157
2167
|
}
|
|
2158
|
-
if (!this
|
|
2168
|
+
if (!__privateGet(this, _provider)) {
|
|
2159
2169
|
throw new Error("Provider not initialized, establish connection first");
|
|
2160
2170
|
}
|
|
2161
|
-
return this
|
|
2171
|
+
return __privateGet(this, _provider);
|
|
2162
2172
|
}
|
|
2163
2173
|
get transport() {
|
|
2164
|
-
if (!this
|
|
2174
|
+
if (!__privateGet(this, _transport2)) {
|
|
2165
2175
|
throw new Error("Transport not initialized, establish connection first");
|
|
2166
2176
|
}
|
|
2167
|
-
return this
|
|
2177
|
+
return __privateGet(this, _transport2);
|
|
2168
2178
|
}
|
|
2169
2179
|
get dappClient() {
|
|
2170
|
-
if (!this
|
|
2180
|
+
if (!__privateGet(this, _dappClient)) {
|
|
2171
2181
|
throw new Error("DappClient not initialized, establish connection first");
|
|
2172
2182
|
}
|
|
2173
|
-
return this
|
|
2183
|
+
return __privateGet(this, _dappClient);
|
|
2174
2184
|
}
|
|
2175
2185
|
get storage() {
|
|
2176
2186
|
return this.options.storage;
|
|
2177
2187
|
}
|
|
2178
2188
|
get transportType() {
|
|
2179
|
-
return this
|
|
2180
|
-
}
|
|
2181
|
-
get sdkInfo() {
|
|
2182
|
-
var _a;
|
|
2183
|
-
return `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(_a = this.options.dapp.url) != null ? _a : this.options.dapp.name} dAppTitle/${this.options.dapp.name}`;
|
|
2189
|
+
return __privateGet(this, _transport2) instanceof MWPTransport ? "mwp" /* MWP */ : "browser" /* Browser */;
|
|
2184
2190
|
}
|
|
2185
2191
|
static create(options) {
|
|
2186
2192
|
return __async(this, null, function* () {
|
|
2193
|
+
var _a2;
|
|
2187
2194
|
const instance = new _MultichainSDK(options);
|
|
2188
2195
|
const isEnabled2 = yield isEnabled(
|
|
2189
2196
|
"metamask-sdk:core",
|
|
@@ -2192,353 +2199,16 @@ var MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2192
2199
|
if (isEnabled2) {
|
|
2193
2200
|
enableDebug("metamask-sdk:core");
|
|
2194
2201
|
}
|
|
2195
|
-
yield instance.
|
|
2202
|
+
yield __privateMethod(_a2 = instance, _MultichainSDK_instances, init_fn).call(_a2);
|
|
2196
2203
|
return instance;
|
|
2197
2204
|
});
|
|
2198
2205
|
}
|
|
2199
|
-
setupAnalytics() {
|
|
2200
|
-
return __async(this, null, function* () {
|
|
2201
|
-
var _a, _b;
|
|
2202
|
-
if (!((_a = this.options.analytics) == null ? void 0 : _a.enabled)) {
|
|
2203
|
-
return;
|
|
2204
|
-
}
|
|
2205
|
-
const platform = getPlatformType();
|
|
2206
|
-
const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
|
|
2207
|
-
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
2208
|
-
if (!isBrowser && !isReactNative2) {
|
|
2209
|
-
return;
|
|
2210
|
-
}
|
|
2211
|
-
const version = getVersion();
|
|
2212
|
-
const dappId = getDappId(this.options.dapp);
|
|
2213
|
-
const anonId = yield this.storage.getAnonId();
|
|
2214
|
-
const { integrationType } = (_b = this.options.analytics) != null ? _b : {
|
|
2215
|
-
integrationType: ""
|
|
2216
|
-
};
|
|
2217
|
-
analytics2.setGlobalProperty("mmconnect_version", version);
|
|
2218
|
-
analytics2.setGlobalProperty("dapp_id", dappId);
|
|
2219
|
-
analytics2.setGlobalProperty("anon_id", anonId);
|
|
2220
|
-
analytics2.setGlobalProperty("platform", platform);
|
|
2221
|
-
analytics2.setGlobalProperty("integration_type", integrationType);
|
|
2222
|
-
analytics2.enable();
|
|
2223
|
-
});
|
|
2224
|
-
}
|
|
2225
|
-
onTransportNotification(payload) {
|
|
2226
|
-
return __async(this, null, function* () {
|
|
2227
|
-
var _a;
|
|
2228
|
-
if (typeof payload === "object" && payload !== null && "method" in payload) {
|
|
2229
|
-
this.emit(payload.method, (_a = payload.params) != null ? _a : payload.result);
|
|
2230
|
-
}
|
|
2231
|
-
});
|
|
2232
|
-
}
|
|
2233
|
-
getStoredTransport() {
|
|
2234
|
-
return __async(this, null, function* () {
|
|
2235
|
-
const transportType = yield this.storage.getTransport();
|
|
2236
|
-
const hasExtensionInstalled = yield hasExtension();
|
|
2237
|
-
if (transportType) {
|
|
2238
|
-
if (transportType === "browser" /* Browser */) {
|
|
2239
|
-
if (hasExtensionInstalled) {
|
|
2240
|
-
const apiTransport = new DefaultTransport();
|
|
2241
|
-
this.__transport = apiTransport;
|
|
2242
|
-
this.listener = apiTransport.onNotification(
|
|
2243
|
-
this.onTransportNotification.bind(this)
|
|
2244
|
-
);
|
|
2245
|
-
return apiTransport;
|
|
2246
|
-
}
|
|
2247
|
-
} else if (transportType === "mwp" /* MWP */) {
|
|
2248
|
-
const { adapter: kvstore } = this.options.storage;
|
|
2249
|
-
const dappClient = yield this.createDappClient();
|
|
2250
|
-
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2251
|
-
this.__dappClient = dappClient;
|
|
2252
|
-
this.__transport = apiTransport;
|
|
2253
|
-
this.listener = apiTransport.onNotification(
|
|
2254
|
-
this.onTransportNotification.bind(this)
|
|
2255
|
-
);
|
|
2256
|
-
return apiTransport;
|
|
2257
|
-
}
|
|
2258
|
-
yield this.storage.removeTransport();
|
|
2259
|
-
}
|
|
2260
|
-
return void 0;
|
|
2261
|
-
});
|
|
2262
|
-
}
|
|
2263
|
-
setupTransport() {
|
|
2264
|
-
return __async(this, null, function* () {
|
|
2265
|
-
const transport = yield this.getStoredTransport();
|
|
2266
|
-
if (transport) {
|
|
2267
|
-
if (!this.transport.isConnected()) {
|
|
2268
|
-
this.state = "connecting";
|
|
2269
|
-
yield this.transport.connect();
|
|
2270
|
-
}
|
|
2271
|
-
this.state = "connected";
|
|
2272
|
-
if (this.transport instanceof MWPTransport) {
|
|
2273
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2274
|
-
} else {
|
|
2275
|
-
yield this.storage.setTransport("browser" /* Browser */);
|
|
2276
|
-
}
|
|
2277
|
-
} else {
|
|
2278
|
-
this.state = "loaded";
|
|
2279
|
-
}
|
|
2280
|
-
});
|
|
2281
|
-
}
|
|
2282
|
-
init() {
|
|
2283
|
-
return __async(this, null, function* () {
|
|
2284
|
-
var _a, _b;
|
|
2285
|
-
try {
|
|
2286
|
-
if (typeof window !== "undefined" && ((_a = window.mmsdk) == null ? void 0 : _a.isInitialized)) {
|
|
2287
|
-
logger2("MetaMaskSDK: init already initialized");
|
|
2288
|
-
} else {
|
|
2289
|
-
yield this.setupAnalytics();
|
|
2290
|
-
yield this.setupTransport();
|
|
2291
|
-
if ((_b = this.options.analytics) == null ? void 0 : _b.enabled) {
|
|
2292
|
-
try {
|
|
2293
|
-
const baseProps = yield getBaseAnalyticsProperties(
|
|
2294
|
-
this.options,
|
|
2295
|
-
this.storage
|
|
2296
|
-
);
|
|
2297
|
-
analytics2.track("mmconnect_initialized", baseProps);
|
|
2298
|
-
} catch (error) {
|
|
2299
|
-
logger2("Error tracking initialized event", error);
|
|
2300
|
-
}
|
|
2301
|
-
}
|
|
2302
|
-
if (typeof window !== "undefined") {
|
|
2303
|
-
window.mmsdk = this;
|
|
2304
|
-
}
|
|
2305
|
-
}
|
|
2306
|
-
} catch (error) {
|
|
2307
|
-
yield this.storage.removeTransport();
|
|
2308
|
-
this.state = "pending";
|
|
2309
|
-
logger2("MetaMaskSDK error during initialization", error);
|
|
2310
|
-
}
|
|
2311
|
-
});
|
|
2312
|
-
}
|
|
2313
|
-
createDappClient() {
|
|
2314
|
-
return __async(this, null, function* () {
|
|
2315
|
-
const { adapter: kvstore } = this.options.storage;
|
|
2316
|
-
const sessionstore = new SessionStore2(kvstore);
|
|
2317
|
-
const websocket = (
|
|
2318
|
-
// eslint-disable-next-line no-negated-condition
|
|
2319
|
-
typeof window !== "undefined" ? WebSocket : (yield import("ws")).WebSocket
|
|
2320
|
-
);
|
|
2321
|
-
const transport = yield WebSocketTransport.create({
|
|
2322
|
-
url: MWP_RELAY_URL,
|
|
2323
|
-
kvstore,
|
|
2324
|
-
websocket
|
|
2325
|
-
});
|
|
2326
|
-
const dappClient = new DappClient({ transport, sessionstore, keymanager });
|
|
2327
|
-
return dappClient;
|
|
2328
|
-
});
|
|
2329
|
-
}
|
|
2330
|
-
setupMWP() {
|
|
2331
|
-
return __async(this, null, function* () {
|
|
2332
|
-
if (this.__transport instanceof MWPTransport) {
|
|
2333
|
-
return;
|
|
2334
|
-
}
|
|
2335
|
-
const { adapter: kvstore } = this.options.storage;
|
|
2336
|
-
const dappClient = yield this.createDappClient();
|
|
2337
|
-
this.__dappClient = dappClient;
|
|
2338
|
-
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2339
|
-
this.__transport = apiTransport;
|
|
2340
|
-
this.listener = this.transport.onNotification(
|
|
2341
|
-
this.onTransportNotification.bind(this)
|
|
2342
|
-
);
|
|
2343
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2344
|
-
});
|
|
2345
|
-
}
|
|
2346
|
-
onBeforeUnload() {
|
|
2347
|
-
return __async(this, null, function* () {
|
|
2348
|
-
var _a;
|
|
2349
|
-
if ((_a = this.options.ui.factory.modal) == null ? void 0 : _a.isMounted) {
|
|
2350
|
-
yield this.storage.removeTransport();
|
|
2351
|
-
}
|
|
2352
|
-
});
|
|
2353
|
-
}
|
|
2354
|
-
createBeforeUnloadListener() {
|
|
2355
|
-
if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
|
|
2356
|
-
window.addEventListener("beforeunload", this.onBeforeUnload.bind(this));
|
|
2357
|
-
}
|
|
2358
|
-
return () => {
|
|
2359
|
-
if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined") {
|
|
2360
|
-
window.removeEventListener(
|
|
2361
|
-
"beforeunload",
|
|
2362
|
-
this.onBeforeUnload.bind(this)
|
|
2363
|
-
);
|
|
2364
|
-
}
|
|
2365
|
-
};
|
|
2366
|
-
}
|
|
2367
|
-
showInstallModal(desktopPreferred, scopes, caipAccountIds) {
|
|
2368
|
-
return __async(this, null, function* () {
|
|
2369
|
-
var _a;
|
|
2370
|
-
(_a = this.__beforeUnloadListener) != null ? _a : this.__beforeUnloadListener = this.createBeforeUnloadListener();
|
|
2371
|
-
return new Promise((resolve, reject) => {
|
|
2372
|
-
this.options.ui.factory.renderInstallModal(
|
|
2373
|
-
desktopPreferred,
|
|
2374
|
-
() => __async(this, null, function* () {
|
|
2375
|
-
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
2376
|
-
yield this.dappClient.disconnect();
|
|
2377
|
-
}
|
|
2378
|
-
return new Promise((resolveConnectionRequest) => {
|
|
2379
|
-
this.dappClient.on(
|
|
2380
|
-
"session_request",
|
|
2381
|
-
(sessionRequest) => {
|
|
2382
|
-
resolveConnectionRequest({
|
|
2383
|
-
sessionRequest,
|
|
2384
|
-
metadata: {
|
|
2385
|
-
dapp: this.options.dapp,
|
|
2386
|
-
sdk: {
|
|
2387
|
-
version: getVersion(),
|
|
2388
|
-
platform: getPlatformType()
|
|
2389
|
-
}
|
|
2390
|
-
}
|
|
2391
|
-
});
|
|
2392
|
-
}
|
|
2393
|
-
);
|
|
2394
|
-
this.transport.connect({ scopes, caipAccountIds }).then(() => {
|
|
2395
|
-
var _a2;
|
|
2396
|
-
this.options.ui.factory.unload();
|
|
2397
|
-
(_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
|
|
2398
|
-
this.state = "connected";
|
|
2399
|
-
return this.storage.setTransport("mwp" /* MWP */);
|
|
2400
|
-
}).catch((error) => {
|
|
2401
|
-
if (error instanceof ProtocolError) {
|
|
2402
|
-
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
2403
|
-
this.state = "disconnected";
|
|
2404
|
-
reject(error);
|
|
2405
|
-
}
|
|
2406
|
-
} else {
|
|
2407
|
-
this.state = "disconnected";
|
|
2408
|
-
reject(error);
|
|
2409
|
-
}
|
|
2410
|
-
});
|
|
2411
|
-
});
|
|
2412
|
-
}),
|
|
2413
|
-
(error) => __async(this, null, function* () {
|
|
2414
|
-
if (!error) {
|
|
2415
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2416
|
-
resolve();
|
|
2417
|
-
} else {
|
|
2418
|
-
yield this.storage.removeTransport();
|
|
2419
|
-
reject(error);
|
|
2420
|
-
}
|
|
2421
|
-
})
|
|
2422
|
-
);
|
|
2423
|
-
});
|
|
2424
|
-
});
|
|
2425
|
-
}
|
|
2426
|
-
setupDefaultTransport() {
|
|
2427
|
-
return __async(this, null, function* () {
|
|
2428
|
-
this.state = "connecting";
|
|
2429
|
-
yield this.storage.setTransport("browser" /* Browser */);
|
|
2430
|
-
const transport = new DefaultTransport();
|
|
2431
|
-
this.listener = transport.onNotification(
|
|
2432
|
-
this.onTransportNotification.bind(this)
|
|
2433
|
-
);
|
|
2434
|
-
this.__transport = transport;
|
|
2435
|
-
return transport;
|
|
2436
|
-
});
|
|
2437
|
-
}
|
|
2438
|
-
deeplinkConnect(scopes, caipAccountIds) {
|
|
2439
|
-
return __async(this, null, function* () {
|
|
2440
|
-
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
2441
|
-
this.dappClient.on("message", (payload) => {
|
|
2442
|
-
var _a, _b, _c;
|
|
2443
|
-
const data = payload.data;
|
|
2444
|
-
if (typeof data === "object" && data !== null) {
|
|
2445
|
-
if ("method" in data && data.method === "wallet_createSession") {
|
|
2446
|
-
if (data.error) {
|
|
2447
|
-
this.state = "loaded";
|
|
2448
|
-
return reject(data.error);
|
|
2449
|
-
}
|
|
2450
|
-
const session = (_a = data.params) != null ? _a : data.result;
|
|
2451
|
-
if (session) {
|
|
2452
|
-
(_c = (_b = this.options.transport) == null ? void 0 : _b.onNotification) == null ? void 0 : _c.call(_b, payload.data);
|
|
2453
|
-
this.emit("wallet_sessionChanged", session);
|
|
2454
|
-
}
|
|
2455
|
-
}
|
|
2456
|
-
}
|
|
2457
|
-
});
|
|
2458
|
-
let timeout;
|
|
2459
|
-
if (!this.transport.isConnected()) {
|
|
2460
|
-
this.dappClient.once(
|
|
2461
|
-
"session_request",
|
|
2462
|
-
(sessionRequest) => {
|
|
2463
|
-
var _a;
|
|
2464
|
-
const connectionRequest = {
|
|
2465
|
-
sessionRequest,
|
|
2466
|
-
metadata: {
|
|
2467
|
-
dapp: this.options.dapp,
|
|
2468
|
-
sdk: { version: getVersion(), platform: getPlatformType() }
|
|
2469
|
-
}
|
|
2470
|
-
};
|
|
2471
|
-
const deeplink = this.options.ui.factory.createDeeplink(connectionRequest);
|
|
2472
|
-
const universalLink = this.options.ui.factory.createUniversalLink(connectionRequest);
|
|
2473
|
-
if ((_a = this.options.mobile) == null ? void 0 : _a.preferredOpenLink) {
|
|
2474
|
-
this.options.mobile.preferredOpenLink(deeplink, "_self");
|
|
2475
|
-
} else {
|
|
2476
|
-
openDeeplink(this.options, deeplink, universalLink);
|
|
2477
|
-
}
|
|
2478
|
-
}
|
|
2479
|
-
);
|
|
2480
|
-
}
|
|
2481
|
-
this.transport.connect({ scopes, caipAccountIds }).then(resolve).catch((error) => {
|
|
2482
|
-
this.storage.removeTransport();
|
|
2483
|
-
reject(error);
|
|
2484
|
-
}).finally(() => {
|
|
2485
|
-
if (timeout) {
|
|
2486
|
-
clearTimeout(timeout);
|
|
2487
|
-
}
|
|
2488
|
-
});
|
|
2489
|
-
}));
|
|
2490
|
-
});
|
|
2491
|
-
}
|
|
2492
|
-
handleConnection(promise, scopes, transportType) {
|
|
2493
|
-
return __async(this, null, function* () {
|
|
2494
|
-
this.state = "connecting";
|
|
2495
|
-
return promise.then(() => __async(this, null, function* () {
|
|
2496
|
-
var _a;
|
|
2497
|
-
this.state = "connected";
|
|
2498
|
-
if ((_a = this.options.analytics) == null ? void 0 : _a.enabled) {
|
|
2499
|
-
try {
|
|
2500
|
-
const baseProps = yield getBaseAnalyticsProperties(
|
|
2501
|
-
this.options,
|
|
2502
|
-
this.storage
|
|
2503
|
-
);
|
|
2504
|
-
analytics2.track("mmconnect_connection_established", __spreadProps(__spreadValues({}, baseProps), {
|
|
2505
|
-
transport_type: transportType,
|
|
2506
|
-
user_permissioned_chains: scopes
|
|
2507
|
-
}));
|
|
2508
|
-
} catch (error) {
|
|
2509
|
-
logger2("Error tracking connection_established event", error);
|
|
2510
|
-
}
|
|
2511
|
-
}
|
|
2512
|
-
})).catch((error) => __async(this, null, function* () {
|
|
2513
|
-
var _a;
|
|
2514
|
-
this.state = "disconnected";
|
|
2515
|
-
if ((_a = this.options.analytics) == null ? void 0 : _a.enabled) {
|
|
2516
|
-
try {
|
|
2517
|
-
const baseProps = yield getBaseAnalyticsProperties(
|
|
2518
|
-
this.options,
|
|
2519
|
-
this.storage
|
|
2520
|
-
);
|
|
2521
|
-
const isRejection = isRejectionError(error);
|
|
2522
|
-
if (isRejection) {
|
|
2523
|
-
analytics2.track("mmconnect_connection_rejected", __spreadProps(__spreadValues({}, baseProps), {
|
|
2524
|
-
transport_type: transportType
|
|
2525
|
-
}));
|
|
2526
|
-
} else {
|
|
2527
|
-
analytics2.track("mmconnect_connection_failed", __spreadProps(__spreadValues({}, baseProps), {
|
|
2528
|
-
transport_type: transportType
|
|
2529
|
-
}));
|
|
2530
|
-
}
|
|
2531
|
-
} catch (e) {
|
|
2532
|
-
logger2("Error tracking connection failed/rejected event", error);
|
|
2533
|
-
}
|
|
2534
|
-
}
|
|
2535
|
-
return Promise.reject(error);
|
|
2536
|
-
}));
|
|
2537
|
-
});
|
|
2538
|
-
}
|
|
2539
2206
|
connect(scopes, caipAccountIds, forceRequest) {
|
|
2540
2207
|
return __async(this, null, function* () {
|
|
2541
|
-
var
|
|
2208
|
+
var _a2;
|
|
2209
|
+
if (this.state !== "connected") {
|
|
2210
|
+
yield this.disconnect();
|
|
2211
|
+
}
|
|
2542
2212
|
const { ui } = this.options;
|
|
2543
2213
|
const platformType = getPlatformType();
|
|
2544
2214
|
const isWeb = platformType === "in-app-browser" /* MetaMaskMobileWebview */ || platformType === "web-desktop" /* DesktopWeb */;
|
|
@@ -2551,96 +2221,72 @@ var MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2551
2221
|
} else {
|
|
2552
2222
|
transportType = "mwp" /* MWP */;
|
|
2553
2223
|
}
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
this.storage
|
|
2559
|
-
);
|
|
2560
|
-
const dappConfiguredChains = Object.keys(
|
|
2561
|
-
this.options.api.supportedNetworks
|
|
2562
|
-
);
|
|
2563
|
-
analytics2.track("mmconnect_connection_initiated", __spreadProps(__spreadValues({}, baseProps), {
|
|
2564
|
-
transport_type: transportType,
|
|
2565
|
-
dapp_configured_chains: dappConfiguredChains,
|
|
2566
|
-
dapp_requested_chains: scopes
|
|
2567
|
-
}));
|
|
2568
|
-
} catch (error) {
|
|
2569
|
-
logger2("Error tracking connection_initiated event", error);
|
|
2570
|
-
}
|
|
2571
|
-
}
|
|
2572
|
-
if (((_b = this.__transport) == null ? void 0 : _b.isConnected()) && !secure) {
|
|
2573
|
-
return this.handleConnection(
|
|
2574
|
-
this.__transport.connect({ scopes, caipAccountIds, forceRequest }).then(() => {
|
|
2575
|
-
if (this.__transport instanceof MWPTransport) {
|
|
2576
|
-
return this.storage.setTransport("mwp" /* MWP */);
|
|
2577
|
-
} else {
|
|
2578
|
-
return this.storage.setTransport("browser" /* Browser */);
|
|
2579
|
-
}
|
|
2580
|
-
}),
|
|
2581
|
-
scopes,
|
|
2582
|
-
transportType
|
|
2224
|
+
try {
|
|
2225
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2226
|
+
this.options,
|
|
2227
|
+
this.storage
|
|
2583
2228
|
);
|
|
2229
|
+
const dappConfiguredChains = Object.keys(
|
|
2230
|
+
this.options.api.supportedNetworks
|
|
2231
|
+
);
|
|
2232
|
+
analytics2.track("mmconnect_connection_initiated", __spreadProps(__spreadValues({}, baseProps), {
|
|
2233
|
+
transport_type: transportType,
|
|
2234
|
+
dapp_configured_chains: dappConfiguredChains,
|
|
2235
|
+
dapp_requested_chains: scopes
|
|
2236
|
+
}));
|
|
2237
|
+
} catch (error) {
|
|
2238
|
+
logger2("Error tracking connection_initiated event", error);
|
|
2239
|
+
}
|
|
2240
|
+
if (((_a2 = __privateGet(this, _transport2)) == null ? void 0 : _a2.isConnected()) && !secure) {
|
|
2241
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateGet(this, _transport2).connect({ scopes, caipAccountIds, forceRequest }).then(() => __async(this, null, function* () {
|
|
2242
|
+
if (__privateGet(this, _transport2) instanceof MWPTransport) {
|
|
2243
|
+
return this.storage.setTransport("mwp" /* MWP */);
|
|
2244
|
+
}
|
|
2245
|
+
return this.storage.setTransport("browser" /* Browser */);
|
|
2246
|
+
})), scopes, transportType);
|
|
2584
2247
|
}
|
|
2585
2248
|
if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
|
|
2586
|
-
const defaultTransport = yield this.
|
|
2587
|
-
return this.
|
|
2588
|
-
defaultTransport.connect({ scopes, caipAccountIds, forceRequest }),
|
|
2589
|
-
scopes,
|
|
2590
|
-
transportType
|
|
2591
|
-
);
|
|
2249
|
+
const defaultTransport = yield __privateMethod(this, _MultichainSDK_instances, setupDefaultTransport_fn).call(this);
|
|
2250
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, forceRequest }), scopes, transportType);
|
|
2592
2251
|
}
|
|
2593
2252
|
if (isWeb && hasExtensionInstalled && preferExtension) {
|
|
2594
|
-
const defaultTransport = yield this.
|
|
2595
|
-
return this.
|
|
2596
|
-
defaultTransport.connect({ scopes, caipAccountIds, forceRequest }),
|
|
2597
|
-
scopes,
|
|
2598
|
-
transportType
|
|
2599
|
-
);
|
|
2253
|
+
const defaultTransport = yield __privateMethod(this, _MultichainSDK_instances, setupDefaultTransport_fn).call(this);
|
|
2254
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, forceRequest }), scopes, transportType);
|
|
2600
2255
|
}
|
|
2601
|
-
yield this.
|
|
2256
|
+
yield __privateMethod(this, _MultichainSDK_instances, setupMWP_fn).call(this);
|
|
2602
2257
|
const shouldShowInstallModal = hasExtensionInstalled ? showInstallModal : !preferExtension || showInstallModal;
|
|
2603
2258
|
if (secure && !shouldShowInstallModal) {
|
|
2604
|
-
return this.
|
|
2605
|
-
this.deeplinkConnect(scopes, caipAccountIds),
|
|
2606
|
-
scopes,
|
|
2607
|
-
transportType
|
|
2608
|
-
);
|
|
2259
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateMethod(this, _MultichainSDK_instances, deeplinkConnect_fn).call(this, scopes, caipAccountIds), scopes, transportType);
|
|
2609
2260
|
}
|
|
2610
|
-
return this.
|
|
2611
|
-
this.showInstallModal(shouldShowInstallModal, scopes, caipAccountIds),
|
|
2612
|
-
scopes,
|
|
2613
|
-
transportType
|
|
2614
|
-
);
|
|
2261
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateMethod(this, _MultichainSDK_instances, showInstallModal_fn).call(this, shouldShowInstallModal, scopes, caipAccountIds), scopes, transportType);
|
|
2615
2262
|
});
|
|
2616
2263
|
}
|
|
2617
2264
|
emit(event, args) {
|
|
2618
|
-
var
|
|
2619
|
-
(_b = (
|
|
2265
|
+
var _a2, _b;
|
|
2266
|
+
(_b = (_a2 = this.options.transport) == null ? void 0 : _a2.onNotification) == null ? void 0 : _b.call(_a2, { method: event, params: args });
|
|
2620
2267
|
super.emit(event, args);
|
|
2621
2268
|
}
|
|
2622
2269
|
disconnect() {
|
|
2623
2270
|
return __async(this, null, function* () {
|
|
2624
|
-
var
|
|
2625
|
-
(
|
|
2626
|
-
(_b = this
|
|
2627
|
-
yield (_c = this
|
|
2271
|
+
var _a2, _b, _c;
|
|
2272
|
+
yield (_a2 = __privateGet(this, _listener)) == null ? void 0 : _a2.call(this);
|
|
2273
|
+
(_b = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _b.call(this);
|
|
2274
|
+
yield (_c = __privateGet(this, _transport2)) == null ? void 0 : _c.disconnect();
|
|
2628
2275
|
yield this.storage.removeTransport();
|
|
2629
|
-
this.emit("wallet_sessionChanged", void 0);
|
|
2630
2276
|
this.emit("stateChanged", "disconnected");
|
|
2631
|
-
this
|
|
2632
|
-
this
|
|
2633
|
-
this
|
|
2634
|
-
this
|
|
2635
|
-
this
|
|
2277
|
+
__privateSet(this, _listener, void 0);
|
|
2278
|
+
__privateSet(this, _beforeUnloadListener, void 0);
|
|
2279
|
+
__privateSet(this, _transport2, void 0);
|
|
2280
|
+
__privateSet(this, _provider, void 0);
|
|
2281
|
+
__privateSet(this, _dappClient, void 0);
|
|
2636
2282
|
});
|
|
2637
2283
|
}
|
|
2638
2284
|
invokeMethod(request) {
|
|
2639
2285
|
return __async(this, null, function* () {
|
|
2640
|
-
var
|
|
2641
|
-
const {
|
|
2642
|
-
(
|
|
2643
|
-
const rpcClient = new RpcClient(options,
|
|
2286
|
+
var _a2;
|
|
2287
|
+
const { transport, options } = this;
|
|
2288
|
+
(_a2 = __privateGet(this, _provider)) != null ? _a2 : __privateSet(this, _provider, getMultichainClient({ transport }));
|
|
2289
|
+
const rpcClient = new RpcClient(options, __privateGet(this, _sdkInfo));
|
|
2644
2290
|
const requestRouter = new RequestRouter(transport, rpcClient, options);
|
|
2645
2291
|
return requestRouter.invokeMethod(request);
|
|
2646
2292
|
});
|
|
@@ -2652,20 +2298,381 @@ var MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2652
2298
|
const secure = isSecure();
|
|
2653
2299
|
const shouldOpenDeeplink = secure && !showInstallModal;
|
|
2654
2300
|
if (shouldOpenDeeplink) {
|
|
2655
|
-
setTimeout(() => {
|
|
2301
|
+
setTimeout(() => __async(this, null, function* () {
|
|
2302
|
+
const session = yield this.transport.getActiveSession();
|
|
2303
|
+
if (!session) {
|
|
2304
|
+
throw new Error("No active session found");
|
|
2305
|
+
}
|
|
2306
|
+
const url = `${METAMASK_DEEPLINK_BASE}/mwp?id=${encodeURIComponent(session.id)}`;
|
|
2656
2307
|
if (mobile == null ? void 0 : mobile.preferredOpenLink) {
|
|
2657
|
-
mobile.preferredOpenLink(
|
|
2308
|
+
mobile.preferredOpenLink(url, "_self");
|
|
2658
2309
|
} else {
|
|
2659
|
-
openDeeplink(
|
|
2310
|
+
openDeeplink(this.options, url, METAMASK_CONNECT_BASE_URL);
|
|
2311
|
+
}
|
|
2312
|
+
}), 10);
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
};
|
|
2316
|
+
_provider = new WeakMap();
|
|
2317
|
+
_transport2 = new WeakMap();
|
|
2318
|
+
_dappClient = new WeakMap();
|
|
2319
|
+
_beforeUnloadListener = new WeakMap();
|
|
2320
|
+
_listener = new WeakMap();
|
|
2321
|
+
_sdkInfo = new WeakMap();
|
|
2322
|
+
_MultichainSDK_instances = new WeakSet();
|
|
2323
|
+
setupAnalytics_fn = function() {
|
|
2324
|
+
return __async(this, null, function* () {
|
|
2325
|
+
var _a2;
|
|
2326
|
+
const platform = getPlatformType();
|
|
2327
|
+
const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
|
|
2328
|
+
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
2329
|
+
if (!isBrowser && !isReactNative2) {
|
|
2330
|
+
return;
|
|
2331
|
+
}
|
|
2332
|
+
const version = getVersion();
|
|
2333
|
+
const dappId = getDappId(this.options.dapp);
|
|
2334
|
+
const anonId = yield this.storage.getAnonId();
|
|
2335
|
+
const { integrationType } = (_a2 = this.options.analytics) != null ? _a2 : {
|
|
2336
|
+
integrationType: ""
|
|
2337
|
+
};
|
|
2338
|
+
analytics2.setGlobalProperty("mmconnect_version", version);
|
|
2339
|
+
analytics2.setGlobalProperty("dapp_id", dappId);
|
|
2340
|
+
analytics2.setGlobalProperty("anon_id", anonId);
|
|
2341
|
+
analytics2.setGlobalProperty("platform", platform);
|
|
2342
|
+
analytics2.setGlobalProperty("integration_type", integrationType);
|
|
2343
|
+
analytics2.enable();
|
|
2344
|
+
});
|
|
2345
|
+
};
|
|
2346
|
+
onTransportNotification_fn = function(payload) {
|
|
2347
|
+
return __async(this, null, function* () {
|
|
2348
|
+
var _a2;
|
|
2349
|
+
if (typeof payload === "object" && payload !== null && "method" in payload) {
|
|
2350
|
+
this.emit(payload.method, (_a2 = payload.params) != null ? _a2 : payload.result);
|
|
2351
|
+
}
|
|
2352
|
+
});
|
|
2353
|
+
};
|
|
2354
|
+
getStoredTransport_fn = function() {
|
|
2355
|
+
return __async(this, null, function* () {
|
|
2356
|
+
const transportType = yield this.storage.getTransport();
|
|
2357
|
+
const hasExtensionInstalled = yield hasExtension();
|
|
2358
|
+
if (transportType) {
|
|
2359
|
+
if (transportType === "browser" /* Browser */) {
|
|
2360
|
+
if (hasExtensionInstalled) {
|
|
2361
|
+
const apiTransport = new DefaultTransport();
|
|
2362
|
+
__privateSet(this, _transport2, apiTransport);
|
|
2363
|
+
__privateSet(this, _listener, apiTransport.onNotification(
|
|
2364
|
+
__privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
|
|
2365
|
+
));
|
|
2366
|
+
return apiTransport;
|
|
2367
|
+
}
|
|
2368
|
+
} else if (transportType === "mwp" /* MWP */) {
|
|
2369
|
+
const { adapter: kvstore } = this.options.storage;
|
|
2370
|
+
const dappClient = yield __privateMethod(this, _MultichainSDK_instances, createDappClient_fn).call(this);
|
|
2371
|
+
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2372
|
+
__privateSet(this, _dappClient, dappClient);
|
|
2373
|
+
__privateSet(this, _transport2, apiTransport);
|
|
2374
|
+
__privateSet(this, _listener, apiTransport.onNotification(
|
|
2375
|
+
__privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
|
|
2376
|
+
));
|
|
2377
|
+
return apiTransport;
|
|
2378
|
+
}
|
|
2379
|
+
yield this.storage.removeTransport();
|
|
2380
|
+
}
|
|
2381
|
+
return void 0;
|
|
2382
|
+
});
|
|
2383
|
+
};
|
|
2384
|
+
setupTransport_fn = function() {
|
|
2385
|
+
return __async(this, null, function* () {
|
|
2386
|
+
const transport = yield __privateMethod(this, _MultichainSDK_instances, getStoredTransport_fn).call(this);
|
|
2387
|
+
if (transport) {
|
|
2388
|
+
if (!this.transport.isConnected()) {
|
|
2389
|
+
this.state = "connecting";
|
|
2390
|
+
yield this.transport.connect();
|
|
2391
|
+
}
|
|
2392
|
+
this.state = "connected";
|
|
2393
|
+
if (this.transport instanceof MWPTransport) {
|
|
2394
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2395
|
+
} else {
|
|
2396
|
+
yield this.storage.setTransport("browser" /* Browser */);
|
|
2397
|
+
}
|
|
2398
|
+
} else {
|
|
2399
|
+
this.state = "loaded";
|
|
2400
|
+
}
|
|
2401
|
+
});
|
|
2402
|
+
};
|
|
2403
|
+
init_fn = function() {
|
|
2404
|
+
return __async(this, null, function* () {
|
|
2405
|
+
var _a2;
|
|
2406
|
+
try {
|
|
2407
|
+
if (typeof window !== "undefined" && ((_a2 = window.mmsdk) == null ? void 0 : _a2.isInitialized)) {
|
|
2408
|
+
logger2("MetaMaskSDK: init already initialized");
|
|
2409
|
+
} else {
|
|
2410
|
+
yield __privateMethod(this, _MultichainSDK_instances, setupAnalytics_fn).call(this);
|
|
2411
|
+
yield __privateMethod(this, _MultichainSDK_instances, setupTransport_fn).call(this);
|
|
2412
|
+
try {
|
|
2413
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2660
2414
|
this.options,
|
|
2661
|
-
|
|
2662
|
-
METAMASK_CONNECT_BASE_URL
|
|
2415
|
+
this.storage
|
|
2663
2416
|
);
|
|
2417
|
+
analytics2.track("mmconnect_initialized", baseProps);
|
|
2418
|
+
} catch (error) {
|
|
2419
|
+
logger2("Error tracking initialized event", error);
|
|
2420
|
+
}
|
|
2421
|
+
if (typeof window !== "undefined") {
|
|
2422
|
+
window.mmsdk = this;
|
|
2664
2423
|
}
|
|
2665
|
-
}
|
|
2424
|
+
}
|
|
2425
|
+
} catch (error) {
|
|
2426
|
+
yield this.storage.removeTransport();
|
|
2427
|
+
this.state = "pending";
|
|
2428
|
+
logger2("MetaMaskSDK error during initialization", error);
|
|
2666
2429
|
}
|
|
2667
|
-
}
|
|
2430
|
+
});
|
|
2431
|
+
};
|
|
2432
|
+
createDappClient_fn = function() {
|
|
2433
|
+
return __async(this, null, function* () {
|
|
2434
|
+
const { adapter: kvstore } = this.options.storage;
|
|
2435
|
+
const sessionstore = new SessionStore2(kvstore);
|
|
2436
|
+
const websocket = (
|
|
2437
|
+
// eslint-disable-next-line no-negated-condition
|
|
2438
|
+
typeof window !== "undefined" ? WebSocket : (yield import("ws")).WebSocket
|
|
2439
|
+
);
|
|
2440
|
+
const transport = yield WebSocketTransport.create({
|
|
2441
|
+
url: MWP_RELAY_URL,
|
|
2442
|
+
kvstore,
|
|
2443
|
+
websocket
|
|
2444
|
+
});
|
|
2445
|
+
const dappClient = new DappClient({ transport, sessionstore, keymanager });
|
|
2446
|
+
return dappClient;
|
|
2447
|
+
});
|
|
2448
|
+
};
|
|
2449
|
+
setupMWP_fn = function() {
|
|
2450
|
+
return __async(this, null, function* () {
|
|
2451
|
+
if (__privateGet(this, _transport2) instanceof MWPTransport) {
|
|
2452
|
+
return;
|
|
2453
|
+
}
|
|
2454
|
+
const { adapter: kvstore } = this.options.storage;
|
|
2455
|
+
const dappClient = yield __privateMethod(this, _MultichainSDK_instances, createDappClient_fn).call(this);
|
|
2456
|
+
__privateSet(this, _dappClient, dappClient);
|
|
2457
|
+
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2458
|
+
__privateSet(this, _transport2, apiTransport);
|
|
2459
|
+
__privateSet(this, _listener, this.transport.onNotification(
|
|
2460
|
+
__privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
|
|
2461
|
+
));
|
|
2462
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2463
|
+
});
|
|
2464
|
+
};
|
|
2465
|
+
onBeforeUnload_fn = function() {
|
|
2466
|
+
return __async(this, null, function* () {
|
|
2467
|
+
var _a2;
|
|
2468
|
+
if ((_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.isMounted) {
|
|
2469
|
+
yield this.storage.removeTransport();
|
|
2470
|
+
}
|
|
2471
|
+
});
|
|
2472
|
+
};
|
|
2473
|
+
createBeforeUnloadListener_fn = function() {
|
|
2474
|
+
if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
|
|
2475
|
+
window.addEventListener("beforeunload", __privateMethod(this, _MultichainSDK_instances, onBeforeUnload_fn).bind(this));
|
|
2476
|
+
}
|
|
2477
|
+
return () => {
|
|
2478
|
+
if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined") {
|
|
2479
|
+
window.removeEventListener(
|
|
2480
|
+
"beforeunload",
|
|
2481
|
+
__privateMethod(this, _MultichainSDK_instances, onBeforeUnload_fn).bind(this)
|
|
2482
|
+
);
|
|
2483
|
+
}
|
|
2484
|
+
};
|
|
2485
|
+
};
|
|
2486
|
+
renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds) {
|
|
2487
|
+
return __async(this, null, function* () {
|
|
2488
|
+
return new Promise((resolve, reject) => {
|
|
2489
|
+
this.options.ui.factory.renderInstallModal(
|
|
2490
|
+
desktopPreferred,
|
|
2491
|
+
() => __async(this, null, function* () {
|
|
2492
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
2493
|
+
yield this.dappClient.disconnect();
|
|
2494
|
+
}
|
|
2495
|
+
return new Promise((_resolve) => {
|
|
2496
|
+
this.dappClient.on(
|
|
2497
|
+
"session_request",
|
|
2498
|
+
(sessionRequest) => {
|
|
2499
|
+
_resolve({
|
|
2500
|
+
sessionRequest,
|
|
2501
|
+
metadata: {
|
|
2502
|
+
dapp: this.options.dapp,
|
|
2503
|
+
sdk: {
|
|
2504
|
+
version: getVersion(),
|
|
2505
|
+
platform: getPlatformType()
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
});
|
|
2509
|
+
}
|
|
2510
|
+
);
|
|
2511
|
+
(() => __async(this, null, function* () {
|
|
2512
|
+
var _a2;
|
|
2513
|
+
try {
|
|
2514
|
+
yield this.transport.connect({ scopes, caipAccountIds });
|
|
2515
|
+
yield this.options.ui.factory.unload();
|
|
2516
|
+
(_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
|
|
2517
|
+
this.state = "connected";
|
|
2518
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2519
|
+
} catch (error) {
|
|
2520
|
+
if (error instanceof ProtocolError) {
|
|
2521
|
+
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
2522
|
+
this.state = "disconnected";
|
|
2523
|
+
reject(error);
|
|
2524
|
+
}
|
|
2525
|
+
} else {
|
|
2526
|
+
this.state = "disconnected";
|
|
2527
|
+
reject(
|
|
2528
|
+
error instanceof Error ? error : new Error(String(error))
|
|
2529
|
+
);
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
}))().catch(() => {
|
|
2533
|
+
});
|
|
2534
|
+
});
|
|
2535
|
+
}),
|
|
2536
|
+
(error) => __async(this, null, function* () {
|
|
2537
|
+
if (error) {
|
|
2538
|
+
yield this.storage.removeTransport();
|
|
2539
|
+
reject(error);
|
|
2540
|
+
} else {
|
|
2541
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2542
|
+
resolve();
|
|
2543
|
+
}
|
|
2544
|
+
})
|
|
2545
|
+
).catch((error) => {
|
|
2546
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2547
|
+
});
|
|
2548
|
+
});
|
|
2549
|
+
});
|
|
2550
|
+
};
|
|
2551
|
+
showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds) {
|
|
2552
|
+
return __async(this, null, function* () {
|
|
2553
|
+
var _a2;
|
|
2554
|
+
(_a2 = __privateGet(this, _beforeUnloadListener)) != null ? _a2 : __privateSet(this, _beforeUnloadListener, __privateMethod(this, _MultichainSDK_instances, createBeforeUnloadListener_fn).call(this));
|
|
2555
|
+
yield __privateMethod(this, _MultichainSDK_instances, renderInstallModalAsync_fn).call(this, desktopPreferred, scopes, caipAccountIds);
|
|
2556
|
+
});
|
|
2557
|
+
};
|
|
2558
|
+
setupDefaultTransport_fn = function() {
|
|
2559
|
+
return __async(this, null, function* () {
|
|
2560
|
+
this.state = "connecting";
|
|
2561
|
+
yield this.storage.setTransport("browser" /* Browser */);
|
|
2562
|
+
const transport = new DefaultTransport();
|
|
2563
|
+
__privateSet(this, _listener, transport.onNotification(
|
|
2564
|
+
__privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
|
|
2565
|
+
));
|
|
2566
|
+
__privateSet(this, _transport2, transport);
|
|
2567
|
+
return transport;
|
|
2568
|
+
});
|
|
2569
|
+
};
|
|
2570
|
+
deeplinkConnect_fn = function(scopes, caipAccountIds) {
|
|
2571
|
+
return __async(this, null, function* () {
|
|
2572
|
+
return new Promise((resolve, reject) => {
|
|
2573
|
+
const dappClientMessageHandler = (payload) => {
|
|
2574
|
+
var _a2;
|
|
2575
|
+
if (typeof payload !== "object" || payload === null || !("data" in payload)) {
|
|
2576
|
+
return;
|
|
2577
|
+
}
|
|
2578
|
+
const data = payload.data;
|
|
2579
|
+
if (typeof data === "object" && data !== null) {
|
|
2580
|
+
if (data.error) {
|
|
2581
|
+
this.dappClient.off("message", dappClientMessageHandler);
|
|
2582
|
+
reject(data.error);
|
|
2583
|
+
}
|
|
2584
|
+
if ((_a2 = data == null ? void 0 : data.result) == null ? void 0 : _a2.sessionScopes) {
|
|
2585
|
+
this.dappClient.off("message", dappClientMessageHandler);
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
};
|
|
2589
|
+
this.dappClient.on("message", dappClientMessageHandler);
|
|
2590
|
+
let timeout;
|
|
2591
|
+
if (this.transport.isConnected()) {
|
|
2592
|
+
timeout = setTimeout(() => {
|
|
2593
|
+
this.openDeeplinkIfNeeded();
|
|
2594
|
+
}, 250);
|
|
2595
|
+
} else {
|
|
2596
|
+
this.dappClient.once(
|
|
2597
|
+
"session_request",
|
|
2598
|
+
(sessionRequest) => {
|
|
2599
|
+
var _a2;
|
|
2600
|
+
const connectionRequest = {
|
|
2601
|
+
sessionRequest,
|
|
2602
|
+
metadata: {
|
|
2603
|
+
dapp: this.options.dapp,
|
|
2604
|
+
sdk: { version: getVersion(), platform: getPlatformType() }
|
|
2605
|
+
}
|
|
2606
|
+
};
|
|
2607
|
+
const deeplink = this.options.ui.factory.createConnectionDeeplink(
|
|
2608
|
+
connectionRequest
|
|
2609
|
+
);
|
|
2610
|
+
const universalLink = this.options.ui.factory.createConnectionUniversalLink(
|
|
2611
|
+
connectionRequest
|
|
2612
|
+
);
|
|
2613
|
+
if ((_a2 = this.options.mobile) == null ? void 0 : _a2.preferredOpenLink) {
|
|
2614
|
+
this.options.mobile.preferredOpenLink(deeplink, "_self");
|
|
2615
|
+
} else {
|
|
2616
|
+
openDeeplink(this.options, deeplink, universalLink);
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
);
|
|
2620
|
+
}
|
|
2621
|
+
return this.transport.connect({ scopes, caipAccountIds }).then(resolve).catch((error) => __async(this, null, function* () {
|
|
2622
|
+
yield this.storage.removeTransport();
|
|
2623
|
+
this.dappClient.off("message", dappClientMessageHandler);
|
|
2624
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2625
|
+
})).finally(() => {
|
|
2626
|
+
if (timeout) {
|
|
2627
|
+
clearTimeout(timeout);
|
|
2628
|
+
}
|
|
2629
|
+
});
|
|
2630
|
+
});
|
|
2631
|
+
});
|
|
2632
|
+
};
|
|
2633
|
+
handleConnection_fn = function(promise, scopes, transportType) {
|
|
2634
|
+
return __async(this, null, function* () {
|
|
2635
|
+
this.state = "connecting";
|
|
2636
|
+
return promise.then(() => __async(this, null, function* () {
|
|
2637
|
+
this.state = "connected";
|
|
2638
|
+
try {
|
|
2639
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2640
|
+
this.options,
|
|
2641
|
+
this.storage
|
|
2642
|
+
);
|
|
2643
|
+
analytics2.track("mmconnect_connection_established", __spreadProps(__spreadValues({}, baseProps), {
|
|
2644
|
+
transport_type: transportType,
|
|
2645
|
+
user_permissioned_chains: scopes
|
|
2646
|
+
}));
|
|
2647
|
+
} catch (error) {
|
|
2648
|
+
logger2("Error tracking connection_established event", error);
|
|
2649
|
+
}
|
|
2650
|
+
return void 0;
|
|
2651
|
+
})).catch((error) => __async(this, null, function* () {
|
|
2652
|
+
this.state = "disconnected";
|
|
2653
|
+
try {
|
|
2654
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2655
|
+
this.options,
|
|
2656
|
+
this.storage
|
|
2657
|
+
);
|
|
2658
|
+
const isRejection = isRejectionError(error);
|
|
2659
|
+
if (isRejection) {
|
|
2660
|
+
analytics2.track("mmconnect_connection_rejected", __spreadProps(__spreadValues({}, baseProps), {
|
|
2661
|
+
transport_type: transportType
|
|
2662
|
+
}));
|
|
2663
|
+
} else {
|
|
2664
|
+
analytics2.track("mmconnect_connection_failed", __spreadProps(__spreadValues({}, baseProps), {
|
|
2665
|
+
transport_type: transportType
|
|
2666
|
+
}));
|
|
2667
|
+
}
|
|
2668
|
+
} catch (e) {
|
|
2669
|
+
logger2("Error tracking connection failed/rejected event", error);
|
|
2670
|
+
}
|
|
2671
|
+
throw error;
|
|
2672
|
+
}));
|
|
2673
|
+
});
|
|
2668
2674
|
};
|
|
2675
|
+
var MultichainSDK = _MultichainSDK;
|
|
2669
2676
|
|
|
2670
2677
|
// src/store/index.ts
|
|
2671
2678
|
import * as uuid from "uuid";
|
|
@@ -2849,37 +2856,24 @@ var Store = class extends StoreClient {
|
|
|
2849
2856
|
// src/ui/index.ts
|
|
2850
2857
|
import MetaMaskOnboarding from "@metamask/onboarding";
|
|
2851
2858
|
init_domain();
|
|
2852
|
-
init_qr();
|
|
2853
2859
|
init_utils();
|
|
2854
|
-
|
|
2860
|
+
|
|
2861
|
+
// src/ui/preload.web.ts
|
|
2855
2862
|
function preload() {
|
|
2856
2863
|
return __async(this, null, function* () {
|
|
2857
|
-
if (
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
return Promise.resolve(void 0);
|
|
2866
|
-
}));
|
|
2867
|
-
} else {
|
|
2868
|
-
const dynamicImport = (0, eval)("import");
|
|
2869
|
-
__instance != null ? __instance : __instance = yield dynamicImport(
|
|
2870
|
-
"@metamask/multichain-ui/dist/loader/index.js"
|
|
2871
|
-
).then((loader) => __async(null, null, function* () {
|
|
2872
|
-
if (typeof (loader == null ? void 0 : loader.defineCustomElements) === "function") {
|
|
2873
|
-
loader.defineCustomElements();
|
|
2874
|
-
}
|
|
2875
|
-
return Promise.resolve(loader);
|
|
2876
|
-
})).catch((error) => __async(null, null, function* () {
|
|
2877
|
-
console.error(`Gracefully Failed to load modal customElements:`, error);
|
|
2878
|
-
return Promise.resolve(void 0);
|
|
2879
|
-
}));
|
|
2864
|
+
if (typeof document === "undefined") {
|
|
2865
|
+
return;
|
|
2866
|
+
}
|
|
2867
|
+
try {
|
|
2868
|
+
const { defineCustomElements } = yield import("@metamask/multichain-ui/loader");
|
|
2869
|
+
yield defineCustomElements();
|
|
2870
|
+
} catch (error) {
|
|
2871
|
+
console.error("Failed to load customElements:", error);
|
|
2880
2872
|
}
|
|
2881
2873
|
});
|
|
2882
2874
|
}
|
|
2875
|
+
|
|
2876
|
+
// src/ui/index.ts
|
|
2883
2877
|
var ModalFactory = class {
|
|
2884
2878
|
/**
|
|
2885
2879
|
* Creates a new modal factory instance.
|
|
@@ -2902,8 +2896,8 @@ var ModalFactory = class {
|
|
|
2902
2896
|
}
|
|
2903
2897
|
unload(error) {
|
|
2904
2898
|
return __async(this, null, function* () {
|
|
2905
|
-
var
|
|
2906
|
-
(
|
|
2899
|
+
var _a2, _b;
|
|
2900
|
+
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
2907
2901
|
yield (_b = this.successCallback) == null ? void 0 : _b.call(this, error);
|
|
2908
2902
|
});
|
|
2909
2903
|
}
|
|
@@ -2941,16 +2935,16 @@ var ModalFactory = class {
|
|
|
2941
2935
|
}
|
|
2942
2936
|
return container;
|
|
2943
2937
|
}
|
|
2944
|
-
|
|
2938
|
+
createConnectionDeeplink(connectionRequest) {
|
|
2945
2939
|
if (!connectionRequest) {
|
|
2946
|
-
throw new Error("
|
|
2940
|
+
throw new Error("createConnectionDeeplink can only be called with a connection request");
|
|
2947
2941
|
}
|
|
2948
2942
|
const json = JSON.stringify(connectionRequest);
|
|
2949
2943
|
const compressed = compressString(json);
|
|
2950
2944
|
const urlEncoded = encodeURIComponent(compressed);
|
|
2951
2945
|
return `${METAMASK_DEEPLINK_BASE}/mwp?p=${urlEncoded}&c=1`;
|
|
2952
2946
|
}
|
|
2953
|
-
|
|
2947
|
+
createConnectionUniversalLink(connectionRequest) {
|
|
2954
2948
|
if (!connectionRequest) {
|
|
2955
2949
|
return `${METAMASK_CONNECT_BASE_URL}`;
|
|
2956
2950
|
}
|
|
@@ -2971,13 +2965,13 @@ var ModalFactory = class {
|
|
|
2971
2965
|
}
|
|
2972
2966
|
renderInstallModal(showInstallModal, createConnectionRequest, successCallback) {
|
|
2973
2967
|
return __async(this, null, function* () {
|
|
2974
|
-
var
|
|
2975
|
-
(
|
|
2976
|
-
yield
|
|
2968
|
+
var _a2;
|
|
2969
|
+
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
2970
|
+
yield preload();
|
|
2977
2971
|
this.successCallback = successCallback;
|
|
2978
2972
|
const parentElement = this.getMountedContainer();
|
|
2979
2973
|
const connectionRequest = yield createConnectionRequest();
|
|
2980
|
-
const qrCodeLink = this.
|
|
2974
|
+
const qrCodeLink = this.createConnectionDeeplink(connectionRequest);
|
|
2981
2975
|
const modal = new this.options.InstallModal({
|
|
2982
2976
|
expiresIn: (connectionRequest.sessionRequest.expiresAt - Date.now()) / 1e3,
|
|
2983
2977
|
connectionRequest,
|
|
@@ -2986,7 +2980,7 @@ var ModalFactory = class {
|
|
|
2986
2980
|
link: qrCodeLink,
|
|
2987
2981
|
sdkVersion: getVersion(),
|
|
2988
2982
|
generateQRCode: (request) => __async(this, null, function* () {
|
|
2989
|
-
return this.
|
|
2983
|
+
return this.createConnectionDeeplink(request);
|
|
2990
2984
|
}),
|
|
2991
2985
|
onClose: this.onCloseModal.bind(this),
|
|
2992
2986
|
startDesktopOnboarding: this.onStartDesktopOnboarding.bind(this),
|
|
@@ -2998,9 +2992,9 @@ var ModalFactory = class {
|
|
|
2998
2992
|
}
|
|
2999
2993
|
renderOTPCodeModal(createOTPCode, successCallback, updateOTPCode) {
|
|
3000
2994
|
return __async(this, null, function* () {
|
|
3001
|
-
var
|
|
3002
|
-
(
|
|
3003
|
-
yield
|
|
2995
|
+
var _a2;
|
|
2996
|
+
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
2997
|
+
yield preload();
|
|
3004
2998
|
this.successCallback = successCallback;
|
|
3005
2999
|
const container = this.getMountedContainer();
|
|
3006
3000
|
const otpCode = yield createOTPCode();
|