@metamask/connect-multichain 0.3.2 → 0.5.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 +55 -15
- package/README.md +1 -1
- package/dist/browser/es/connect-multichain.d.mts +26 -12
- package/dist/browser/es/connect-multichain.mjs +846 -598
- 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 +26 -12
- package/dist/browser/iife/connect-multichain.js +4793 -2291
- 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 +26 -12
- package/dist/browser/umd/connect-multichain.js +846 -598
- 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 +26 -12
- package/dist/node/cjs/connect-multichain.js +846 -609
- 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 +26 -12
- package/dist/node/es/connect-multichain.mjs +844 -607
- 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 +26 -12
- package/dist/react-native/es/connect-multichain.mjs +827 -592
- 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 +4 -4
- package/dist/src/domain/multichain/index.d.ts.map +1 -1
- package/dist/src/domain/multichain/index.js.map +1 -1
- package/dist/src/domain/multichain/types.d.ts +4 -6
- package/dist/src/domain/multichain/types.d.ts.map +1 -1
- package/dist/src/domain/ui/types.d.ts +7 -0
- package/dist/src/domain/ui/types.d.ts.map +1 -1
- package/dist/src/domain/ui/types.js.map +1 -1
- package/dist/src/index.browser.d.ts +1 -1
- package/dist/src/index.browser.d.ts.map +1 -1
- package/dist/src/index.browser.js +1 -1
- package/dist/src/index.browser.js.map +1 -1
- package/dist/src/index.native.d.ts +1 -1
- package/dist/src/index.native.d.ts.map +1 -1
- package/dist/src/index.native.js +2 -2
- package/dist/src/index.native.js.map +1 -1
- package/dist/src/index.node.d.ts +1 -1
- package/dist/src/index.node.d.ts.map +1 -1
- package/dist/src/index.node.js +1 -1
- package/dist/src/index.node.js.map +1 -1
- package/dist/src/multichain/index.d.ts +8 -27
- package/dist/src/multichain/index.d.ts.map +1 -1
- package/dist/src/multichain/index.js +480 -427
- 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 +8 -15
- package/dist/src/multichain/rpc/requestRouter.js.map +1 -1
- package/dist/src/multichain/transports/default/index.d.ts +2 -1
- package/dist/src/multichain/transports/default/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/default/index.js +1 -0
- package/dist/src/multichain/transports/default/index.js.map +1 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts +21 -0
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts.map +1 -0
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js +159 -0
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js.map +1 -0
- package/dist/src/multichain/transports/mwp/index.d.ts +4 -1
- package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/mwp/index.js +76 -6
- package/dist/src/multichain/transports/mwp/index.js.map +1 -1
- package/dist/src/ui/ModalFactory.d.ts +54 -0
- package/dist/src/ui/ModalFactory.d.ts.map +1 -0
- package/dist/src/ui/ModalFactory.js +171 -0
- package/dist/src/ui/ModalFactory.js.map +1 -0
- package/dist/src/ui/index.d.ts +11 -39
- package/dist/src/ui/index.d.ts.map +1 -1
- package/dist/src/ui/index.js +20 -179
- package/dist/src/ui/index.js.map +1 -1
- package/dist/src/ui/index.native.d.ts +13 -0
- package/dist/src/ui/index.native.d.ts.map +1 -0
- package/dist/src/ui/index.native.js +24 -0
- package/dist/src/ui/index.native.js.map +1 -0
- package/dist/src/ui/modals/base/AbstractInstallModal.d.ts.map +1 -1
- package/dist/src/ui/modals/base/AbstractInstallModal.js +0 -4
- package/dist/src/ui/modals/base/AbstractInstallModal.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/types/connect-multichain.d.ts +26 -12
- package/package.json +10 -8
- 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 +0 -32
- package/dist/src/ui/qr.js.map +0 -1
|
@@ -256,8 +256,8 @@ var init_logger = __esm({
|
|
|
256
256
|
import_debug.default.enable(namespace);
|
|
257
257
|
};
|
|
258
258
|
isEnabled = (namespace, storage) => __async(null, null, function* () {
|
|
259
|
-
var
|
|
260
|
-
if ("process" in globalThis && ((
|
|
259
|
+
var _a2;
|
|
260
|
+
if ("process" in globalThis && ((_a2 = process == null ? void 0 : process.env) == null ? void 0 : _a2.DEBUG)) {
|
|
261
261
|
const { DEBUG } = process.env;
|
|
262
262
|
return isNamespaceEnabled(DEBUG, namespace);
|
|
263
263
|
}
|
|
@@ -426,35 +426,35 @@ var init_multichain = __esm({
|
|
|
426
426
|
|
|
427
427
|
// src/domain/platform/index.ts
|
|
428
428
|
function isNotBrowser() {
|
|
429
|
-
var
|
|
429
|
+
var _a2;
|
|
430
430
|
if (typeof window === "undefined") {
|
|
431
431
|
return true;
|
|
432
432
|
}
|
|
433
433
|
if (!(window == null ? void 0 : window.navigator)) {
|
|
434
434
|
return true;
|
|
435
435
|
}
|
|
436
|
-
if (typeof global !== "undefined" && ((
|
|
436
|
+
if (typeof global !== "undefined" && ((_a2 = global == null ? void 0 : global.navigator) == null ? void 0 : _a2.product) === "ReactNative") {
|
|
437
437
|
return true;
|
|
438
438
|
}
|
|
439
439
|
return (navigator == null ? void 0 : navigator.product) === "ReactNative";
|
|
440
440
|
}
|
|
441
441
|
function isReactNative() {
|
|
442
|
-
var
|
|
442
|
+
var _a2;
|
|
443
443
|
const hasWindowNavigator = typeof window !== "undefined" && window.navigator !== void 0;
|
|
444
444
|
const nav = hasWindowNavigator ? window.navigator : void 0;
|
|
445
445
|
if (!nav) {
|
|
446
446
|
return false;
|
|
447
447
|
}
|
|
448
|
-
return hasWindowNavigator && ((
|
|
448
|
+
return hasWindowNavigator && ((_a2 = window.navigator) == null ? void 0 : _a2.product) === "ReactNative";
|
|
449
449
|
}
|
|
450
450
|
function isMetaMaskMobileWebView() {
|
|
451
451
|
return typeof window !== "undefined" && // @ts-expect-error ReactNativeWebView should be defined
|
|
452
452
|
Boolean(window.ReactNativeWebView) && Boolean(window.navigator.userAgent.endsWith("MetaMaskMobile"));
|
|
453
453
|
}
|
|
454
454
|
function isMobile() {
|
|
455
|
-
var
|
|
455
|
+
var _a2, _b;
|
|
456
456
|
const browser = import_bowser.default.parse(window.navigator.userAgent);
|
|
457
|
-
return ((
|
|
457
|
+
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";
|
|
458
458
|
}
|
|
459
459
|
function getPlatformType() {
|
|
460
460
|
if (isReactNative()) {
|
|
@@ -472,11 +472,11 @@ function getPlatformType() {
|
|
|
472
472
|
return "web-desktop" /* DesktopWeb */;
|
|
473
473
|
}
|
|
474
474
|
function isMetamaskExtensionInstalled() {
|
|
475
|
-
var
|
|
475
|
+
var _a2;
|
|
476
476
|
if (typeof window === "undefined") {
|
|
477
477
|
return false;
|
|
478
478
|
}
|
|
479
|
-
return Boolean((
|
|
479
|
+
return Boolean((_a2 = window.ethereum) == null ? void 0 : _a2.isMetaMask);
|
|
480
480
|
}
|
|
481
481
|
function isSecure() {
|
|
482
482
|
const platformType = getPlatformType();
|
|
@@ -508,8 +508,8 @@ var init_platform = __esm({
|
|
|
508
508
|
return new Promise((resolve) => {
|
|
509
509
|
const providers = [];
|
|
510
510
|
const handler = (event) => {
|
|
511
|
-
var
|
|
512
|
-
if ((_b = (
|
|
511
|
+
var _a2, _b;
|
|
512
|
+
if ((_b = (_a2 = event == null ? void 0 : event.detail) == null ? void 0 : _a2.info) == null ? void 0 : _b.rdns) {
|
|
513
513
|
providers.push(event.detail);
|
|
514
514
|
}
|
|
515
515
|
};
|
|
@@ -519,8 +519,8 @@ var init_platform = __esm({
|
|
|
519
519
|
window.removeEventListener("eip6963:announceProvider", handler);
|
|
520
520
|
const hasMetaMask = providers.some(
|
|
521
521
|
(provider) => {
|
|
522
|
-
var
|
|
523
|
-
return (_b = (
|
|
522
|
+
var _a2, _b;
|
|
523
|
+
return (_b = (_a2 = provider == null ? void 0 : provider.info) == null ? void 0 : _a2.rdns) == null ? void 0 : _b.startsWith("io.metamask");
|
|
524
524
|
}
|
|
525
525
|
);
|
|
526
526
|
resolve(hasMetaMask);
|
|
@@ -619,8 +619,8 @@ function compressString(str) {
|
|
|
619
619
|
return base64Encode(binaryString);
|
|
620
620
|
}
|
|
621
621
|
function getDappId(dapp) {
|
|
622
|
-
var
|
|
623
|
-
return (
|
|
622
|
+
var _a2;
|
|
623
|
+
return (_a2 = dapp.url) != null ? _a2 : dapp.name;
|
|
624
624
|
}
|
|
625
625
|
function openDeeplink(options, deeplink, universalLink) {
|
|
626
626
|
const { mobile } = options;
|
|
@@ -650,10 +650,10 @@ function getOptionalScopes(scopes) {
|
|
|
650
650
|
);
|
|
651
651
|
}
|
|
652
652
|
function setupDappMetadata(options) {
|
|
653
|
-
var
|
|
653
|
+
var _a2, _b;
|
|
654
654
|
const platform = getPlatformType();
|
|
655
655
|
const isBrowser = platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */ || platform === "in-app-browser" /* MetaMaskMobileWebview */;
|
|
656
|
-
if (!((
|
|
656
|
+
if (!((_a2 = options.dapp) == null ? void 0 : _a2.name)) {
|
|
657
657
|
throw new Error("You must provide dapp name");
|
|
658
658
|
}
|
|
659
659
|
if (isBrowser) {
|
|
@@ -724,17 +724,17 @@ function getValidAccounts(caipAccountIds) {
|
|
|
724
724
|
);
|
|
725
725
|
}
|
|
726
726
|
function addValidAccounts(optionalScopes, validAccounts) {
|
|
727
|
-
var
|
|
727
|
+
var _a2;
|
|
728
728
|
if (!optionalScopes || !(validAccounts == null ? void 0 : validAccounts.length)) {
|
|
729
729
|
return optionalScopes;
|
|
730
730
|
}
|
|
731
731
|
const result = Object.fromEntries(
|
|
732
732
|
Object.entries(optionalScopes).map(([scope, scopeData]) => {
|
|
733
|
-
var
|
|
733
|
+
var _a3, _b, _c;
|
|
734
734
|
return [
|
|
735
735
|
scope,
|
|
736
736
|
{
|
|
737
|
-
methods: [...(
|
|
737
|
+
methods: [...(_a3 = scopeData == null ? void 0 : scopeData.methods) != null ? _a3 : []],
|
|
738
738
|
notifications: [...(_b = scopeData == null ? void 0 : scopeData.notifications) != null ? _b : []],
|
|
739
739
|
accounts: [...(_c = scopeData == null ? void 0 : scopeData.accounts) != null ? _c : []]
|
|
740
740
|
}
|
|
@@ -748,7 +748,7 @@ function addValidAccounts(optionalScopes, validAccounts) {
|
|
|
748
748
|
if (!accountsByChain.has(chainKey)) {
|
|
749
749
|
accountsByChain.set(chainKey, []);
|
|
750
750
|
}
|
|
751
|
-
(
|
|
751
|
+
(_a2 = accountsByChain.get(chainKey)) == null ? void 0 : _a2.push(accountId);
|
|
752
752
|
}
|
|
753
753
|
for (const [scopeKey, scopeData] of Object.entries(result)) {
|
|
754
754
|
if (!(scopeData == null ? void 0 : scopeData.accounts)) {
|
|
@@ -780,7 +780,7 @@ var init_utils = __esm({
|
|
|
780
780
|
import_utils = require("@metamask/utils");
|
|
781
781
|
init_domain();
|
|
782
782
|
extractFavicon = () => {
|
|
783
|
-
var
|
|
783
|
+
var _a2;
|
|
784
784
|
if (typeof document === "undefined") {
|
|
785
785
|
return void 0;
|
|
786
786
|
}
|
|
@@ -788,7 +788,7 @@ var init_utils = __esm({
|
|
|
788
788
|
const nodeList = document.getElementsByTagName("link");
|
|
789
789
|
for (let i = 0; i < nodeList.length; i++) {
|
|
790
790
|
if (nodeList[i].getAttribute("rel") === "icon" || nodeList[i].getAttribute("rel") === "shortcut icon") {
|
|
791
|
-
favicon = (
|
|
791
|
+
favicon = (_a2 = nodeList[i].getAttribute("href")) != null ? _a2 : void 0;
|
|
792
792
|
}
|
|
793
793
|
}
|
|
794
794
|
return favicon;
|
|
@@ -798,25 +798,25 @@ var init_utils = __esm({
|
|
|
798
798
|
|
|
799
799
|
// src/multichain/utils/analytics.ts
|
|
800
800
|
function isRejectionError(error) {
|
|
801
|
-
var
|
|
801
|
+
var _a2, _b;
|
|
802
802
|
if (typeof error !== "object" || error === null) {
|
|
803
803
|
return false;
|
|
804
804
|
}
|
|
805
805
|
const errorObj = error;
|
|
806
806
|
const errorCode = errorObj.code;
|
|
807
|
-
const errorMessage = (_b = (
|
|
807
|
+
const errorMessage = (_b = (_a2 = errorObj.message) == null ? void 0 : _a2.toLowerCase()) != null ? _b : "";
|
|
808
808
|
return errorCode === 4001 || // User rejected request (common EIP-1193 code)
|
|
809
809
|
errorCode === 4100 || // Unauthorized (common rejection code)
|
|
810
810
|
errorMessage.includes("reject") || errorMessage.includes("denied") || errorMessage.includes("cancel") || errorMessage.includes("user");
|
|
811
811
|
}
|
|
812
812
|
function getBaseAnalyticsProperties(options, storage) {
|
|
813
813
|
return __async(this, null, function* () {
|
|
814
|
-
var
|
|
814
|
+
var _a2, _b;
|
|
815
815
|
const version = getVersion();
|
|
816
816
|
const dappId = getDappId(options.dapp);
|
|
817
817
|
const platform = getPlatformType();
|
|
818
818
|
const anonId = yield storage.getAnonId();
|
|
819
|
-
const integrationType = (_b = (
|
|
819
|
+
const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "unknown" /* UNKNOWN */;
|
|
820
820
|
return {
|
|
821
821
|
mmconnect_version: version,
|
|
822
822
|
dapp_id: dappId,
|
|
@@ -828,11 +828,11 @@ function getBaseAnalyticsProperties(options, storage) {
|
|
|
828
828
|
}
|
|
829
829
|
function getWalletActionAnalyticsProperties(options, storage, invokeOptions) {
|
|
830
830
|
return __async(this, null, function* () {
|
|
831
|
-
var
|
|
831
|
+
var _a2, _b;
|
|
832
832
|
const version = getVersion();
|
|
833
833
|
const dappId = getDappId(options.dapp);
|
|
834
834
|
const anonId = yield storage.getAnonId();
|
|
835
|
-
const integrationType = (_b = (
|
|
835
|
+
const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "unknown";
|
|
836
836
|
return {
|
|
837
837
|
mmconnect_version: version,
|
|
838
838
|
dapp_id: dappId,
|
|
@@ -877,30 +877,6 @@ var init_domain = __esm({
|
|
|
877
877
|
}
|
|
878
878
|
});
|
|
879
879
|
|
|
880
|
-
// src/ui/qr.ts
|
|
881
|
-
function preloadQR() {
|
|
882
|
-
return __async(this, null, function* () {
|
|
883
|
-
if (encodeQRImpl) {
|
|
884
|
-
return;
|
|
885
|
-
}
|
|
886
|
-
const mod = yield import("@paulmillr/qr");
|
|
887
|
-
encodeQRImpl = mod.default;
|
|
888
|
-
});
|
|
889
|
-
}
|
|
890
|
-
function encodeQRSync(input) {
|
|
891
|
-
if (!encodeQRImpl) {
|
|
892
|
-
throw new Error("QR module not preloaded. Call preloadQR() first.");
|
|
893
|
-
}
|
|
894
|
-
return encodeQRImpl(input, "ascii");
|
|
895
|
-
}
|
|
896
|
-
var encodeQRImpl;
|
|
897
|
-
var init_qr = __esm({
|
|
898
|
-
"src/ui/qr.ts"() {
|
|
899
|
-
"use strict";
|
|
900
|
-
encodeQRImpl = null;
|
|
901
|
-
}
|
|
902
|
-
});
|
|
903
|
-
|
|
904
880
|
// src/ui/modals/base/utils.ts
|
|
905
881
|
function formatRemainingTime(milliseconds) {
|
|
906
882
|
if (milliseconds <= 0) return "EXPIRED";
|
|
@@ -997,11 +973,6 @@ var init_AbstractInstallModal = __esm({
|
|
|
997
973
|
`[UI: InstallModal-nodejs()] \u274C Error generating new QR code: ${error}`
|
|
998
974
|
);
|
|
999
975
|
}
|
|
1000
|
-
} else {
|
|
1001
|
-
const generateQRCode = yield this.options.generateQRCode(
|
|
1002
|
-
currentConnectionRequest
|
|
1003
|
-
);
|
|
1004
|
-
this.renderQRCode(generateQRCode, currentConnectionRequest);
|
|
1005
976
|
}
|
|
1006
977
|
}), 1e3);
|
|
1007
978
|
}
|
|
@@ -1019,12 +990,12 @@ var init_AbstractInstallModal = __esm({
|
|
|
1019
990
|
});
|
|
1020
991
|
|
|
1021
992
|
// src/ui/modals/node/install.ts
|
|
1022
|
-
var logger4, InstallModal;
|
|
993
|
+
var import_qr, logger4, InstallModal;
|
|
1023
994
|
var init_install = __esm({
|
|
1024
995
|
"src/ui/modals/node/install.ts"() {
|
|
1025
996
|
"use strict";
|
|
1026
997
|
init_domain();
|
|
1027
|
-
|
|
998
|
+
import_qr = __toESM(require("@paulmillr/qr"));
|
|
1028
999
|
init_AbstractInstallModal();
|
|
1029
1000
|
init_utils3();
|
|
1030
1001
|
logger4 = createLogger("metamask-sdk:ui");
|
|
@@ -1032,7 +1003,7 @@ var init_install = __esm({
|
|
|
1032
1003
|
displayQRWithCountdown(qrCodeLink, expiresInMs) {
|
|
1033
1004
|
const isExpired = expiresInMs <= 0;
|
|
1034
1005
|
const formattedTime = formatRemainingTime(expiresInMs);
|
|
1035
|
-
const qrCode =
|
|
1006
|
+
const qrCode = (0, import_qr.default)(qrCodeLink, "ascii");
|
|
1036
1007
|
console.clear();
|
|
1037
1008
|
console.log(qrCode);
|
|
1038
1009
|
if (isExpired) {
|
|
@@ -1140,8 +1111,8 @@ var init_node2 = __esm({
|
|
|
1140
1111
|
}
|
|
1141
1112
|
get(key) {
|
|
1142
1113
|
return __async(this, null, function* () {
|
|
1143
|
-
var
|
|
1144
|
-
return (
|
|
1114
|
+
var _a2;
|
|
1115
|
+
return (_a2 = this.storage.get(key)) != null ? _a2 : null;
|
|
1145
1116
|
});
|
|
1146
1117
|
}
|
|
1147
1118
|
set(key, value) {
|
|
@@ -1175,7 +1146,7 @@ __export(index_node_exports, {
|
|
|
1175
1146
|
StoreClient: () => StoreClient,
|
|
1176
1147
|
TransportType: () => TransportType,
|
|
1177
1148
|
createLogger: () => createLogger,
|
|
1178
|
-
|
|
1149
|
+
createMultichainClient: () => createMultichainClient,
|
|
1179
1150
|
enableDebug: () => enableDebug,
|
|
1180
1151
|
getInfuraRpcUrls: () => getInfuraRpcUrls,
|
|
1181
1152
|
getPlatformType: () => getPlatformType,
|
|
@@ -1244,8 +1215,8 @@ var RpcClient = class {
|
|
|
1244
1215
|
});
|
|
1245
1216
|
}
|
|
1246
1217
|
getRpcEndpoint(scope) {
|
|
1247
|
-
var
|
|
1248
|
-
const supportedNetworks = (_c = (_b = (
|
|
1218
|
+
var _a2, _b, _c;
|
|
1219
|
+
const supportedNetworks = (_c = (_b = (_a2 = this.config) == null ? void 0 : _a2.api) == null ? void 0 : _b.supportedNetworks) != null ? _c : {};
|
|
1249
1220
|
const rpcEndpoint = supportedNetworks[scope];
|
|
1250
1221
|
if (!rpcEndpoint) {
|
|
1251
1222
|
throw new MissingRpcEndpointErr(`No RPC endpoint found for scope ${scope}`);
|
|
@@ -1400,24 +1371,17 @@ var RequestRouter = class {
|
|
|
1400
1371
|
_RequestRouter_instances = new WeakSet();
|
|
1401
1372
|
withAnalyticsTracking_fn = function(options, execute) {
|
|
1402
1373
|
return __async(this, null, function* () {
|
|
1403
|
-
|
|
1404
|
-
if ((_a = this.config.analytics) == null ? void 0 : _a.enabled) {
|
|
1405
|
-
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRequested_fn).call(this, options);
|
|
1406
|
-
}
|
|
1374
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRequested_fn).call(this, options);
|
|
1407
1375
|
try {
|
|
1408
1376
|
const result = yield execute();
|
|
1409
|
-
|
|
1410
|
-
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionSucceeded_fn).call(this, options);
|
|
1411
|
-
}
|
|
1377
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionSucceeded_fn).call(this, options);
|
|
1412
1378
|
return result;
|
|
1413
1379
|
} catch (error) {
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options);
|
|
1420
|
-
}
|
|
1380
|
+
const isRejection = isRejectionError(error);
|
|
1381
|
+
if (isRejection) {
|
|
1382
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRejected_fn).call(this, options);
|
|
1383
|
+
} else {
|
|
1384
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options);
|
|
1421
1385
|
}
|
|
1422
1386
|
throw new RPCInvokeMethodErr(error.message);
|
|
1423
1387
|
}
|
|
@@ -1477,11 +1441,11 @@ var DefaultTransport = class {
|
|
|
1477
1441
|
id: requestId
|
|
1478
1442
|
}, payload);
|
|
1479
1443
|
return new Promise((resolve, reject) => {
|
|
1480
|
-
var
|
|
1444
|
+
var _a2;
|
|
1481
1445
|
const timeout = setTimeout(() => {
|
|
1482
1446
|
__privateGet(this, _pendingRequests).delete(requestId);
|
|
1483
1447
|
reject(new Error("Request timeout"));
|
|
1484
|
-
}, (
|
|
1448
|
+
}, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : __privateGet(this, _defaultRequestOptions).timeout);
|
|
1485
1449
|
__privateGet(this, _pendingRequests).set(requestId, {
|
|
1486
1450
|
resolve: (response) => {
|
|
1487
1451
|
resolve(response);
|
|
@@ -1505,7 +1469,7 @@ var DefaultTransport = class {
|
|
|
1505
1469
|
}
|
|
1506
1470
|
connect(options) {
|
|
1507
1471
|
return __async(this, null, function* () {
|
|
1508
|
-
var
|
|
1472
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1509
1473
|
__privateMethod(this, _DefaultTransport_instances, setupMessageListener_fn).call(this);
|
|
1510
1474
|
yield __privateGet(this, _transport).connect();
|
|
1511
1475
|
const sessionRequest = yield this.request(
|
|
@@ -1518,7 +1482,7 @@ var DefaultTransport = class {
|
|
|
1518
1482
|
let walletSession = sessionRequest.result;
|
|
1519
1483
|
if (walletSession && options && !options.forceRequest) {
|
|
1520
1484
|
const currentScopes = Object.keys(
|
|
1521
|
-
(
|
|
1485
|
+
(_a2 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a2 : {}
|
|
1522
1486
|
);
|
|
1523
1487
|
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
1524
1488
|
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
@@ -1555,7 +1519,8 @@ var DefaultTransport = class {
|
|
|
1555
1519
|
getValidAccounts((_g = options == null ? void 0 : options.caipAccountIds) != null ? _g : [])
|
|
1556
1520
|
);
|
|
1557
1521
|
const createSessionParams = {
|
|
1558
|
-
optionalScopes
|
|
1522
|
+
optionalScopes,
|
|
1523
|
+
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
1559
1524
|
};
|
|
1560
1525
|
const response = yield this.request(
|
|
1561
1526
|
{ method: "wallet_createSession", params: createSessionParams },
|
|
@@ -1632,16 +1597,16 @@ notifyCallbacks_fn = function(data) {
|
|
|
1632
1597
|
}
|
|
1633
1598
|
};
|
|
1634
1599
|
isMetamaskProviderEvent_fn = function(event) {
|
|
1635
|
-
var
|
|
1636
|
-
return ((_b = (
|
|
1600
|
+
var _a2, _b;
|
|
1601
|
+
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
|
|
1637
1602
|
event.origin === location.origin;
|
|
1638
1603
|
};
|
|
1639
1604
|
handleResponse_fn = function(event) {
|
|
1640
|
-
var
|
|
1605
|
+
var _a2, _b;
|
|
1641
1606
|
if (!__privateMethod(this, _DefaultTransport_instances, isMetamaskProviderEvent_fn).call(this, event)) {
|
|
1642
1607
|
return;
|
|
1643
1608
|
}
|
|
1644
|
-
const responseData = (_b = (
|
|
1609
|
+
const responseData = (_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.data;
|
|
1645
1610
|
if (typeof responseData === "object" && responseData !== null && "method" in responseData) {
|
|
1646
1611
|
return;
|
|
1647
1612
|
}
|
|
@@ -1663,11 +1628,11 @@ handleResponse_fn = function(event) {
|
|
|
1663
1628
|
}
|
|
1664
1629
|
};
|
|
1665
1630
|
handleNotification_fn = function(event) {
|
|
1666
|
-
var
|
|
1631
|
+
var _a2, _b;
|
|
1667
1632
|
if (!__privateMethod(this, _DefaultTransport_instances, isMetamaskProviderEvent_fn).call(this, event)) {
|
|
1668
1633
|
return;
|
|
1669
1634
|
}
|
|
1670
|
-
const responseData = (_b = (
|
|
1635
|
+
const responseData = (_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.data;
|
|
1671
1636
|
if (typeof responseData === "object" && responseData.method === "metamask_chainChanged" || responseData.method === "metamask_accountsChanged") {
|
|
1672
1637
|
__privateMethod(this, _DefaultTransport_instances, notifyCallbacks_fn).call(this, responseData);
|
|
1673
1638
|
}
|
|
@@ -1695,6 +1660,7 @@ var MULTICHAIN_PROVIDER_STREAM_NAME = "metamask-multichain-provider";
|
|
|
1695
1660
|
var DEFAULT_REQUEST_TIMEOUT2 = 60 * 1e3;
|
|
1696
1661
|
var CONNECTION_GRACE_PERIOD = 60 * 1e3;
|
|
1697
1662
|
var DEFAULT_CONNECTION_TIMEOUT = DEFAULT_REQUEST_TIMEOUT2 + CONNECTION_GRACE_PERIOD;
|
|
1663
|
+
var DEFAULT_RESUME_TIMEOUT = 10 * 1e3;
|
|
1698
1664
|
var SESSION_STORE_KEY = "cache_wallet_getSession";
|
|
1699
1665
|
var ACCOUNTS_STORE_KEY = "cache_eth_accounts";
|
|
1700
1666
|
var CHAIN_STORE_KEY = "cache_eth_chainId";
|
|
@@ -1711,7 +1677,8 @@ var logger = createLogger("metamask-sdk:transport");
|
|
|
1711
1677
|
var MWPTransport = class {
|
|
1712
1678
|
constructor(dappClient, kvstore, options = {
|
|
1713
1679
|
requestTimeout: DEFAULT_REQUEST_TIMEOUT2,
|
|
1714
|
-
connectionTimeout: DEFAULT_CONNECTION_TIMEOUT
|
|
1680
|
+
connectionTimeout: DEFAULT_CONNECTION_TIMEOUT,
|
|
1681
|
+
resumeTimeout: DEFAULT_RESUME_TIMEOUT
|
|
1715
1682
|
}) {
|
|
1716
1683
|
this.dappClient = dappClient;
|
|
1717
1684
|
this.kvstore = kvstore;
|
|
@@ -1786,6 +1753,13 @@ var MWPTransport = class {
|
|
|
1786
1753
|
)
|
|
1787
1754
|
);
|
|
1788
1755
|
}
|
|
1756
|
+
if (message.data.method === "wallet_sessionChanged") {
|
|
1757
|
+
const notification = message.data;
|
|
1758
|
+
const response = {
|
|
1759
|
+
result: notification.params
|
|
1760
|
+
};
|
|
1761
|
+
this.kvstore.set(SESSION_STORE_KEY, JSON.stringify(response));
|
|
1762
|
+
}
|
|
1789
1763
|
this.notifyCallbacks(message.data);
|
|
1790
1764
|
}
|
|
1791
1765
|
}
|
|
@@ -1793,8 +1767,9 @@ var MWPTransport = class {
|
|
|
1793
1767
|
}
|
|
1794
1768
|
onResumeSuccess(resumeResolve, resumeReject, options) {
|
|
1795
1769
|
return __async(this, null, function* () {
|
|
1796
|
-
var
|
|
1770
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1797
1771
|
try {
|
|
1772
|
+
yield this.waitForWalletSessionIfNotCached();
|
|
1798
1773
|
const sessionRequest = yield this.request({
|
|
1799
1774
|
method: "wallet_getSession"
|
|
1800
1775
|
});
|
|
@@ -1804,7 +1779,7 @@ var MWPTransport = class {
|
|
|
1804
1779
|
let walletSession = sessionRequest.result;
|
|
1805
1780
|
if (walletSession && options) {
|
|
1806
1781
|
const currentScopes = Object.keys(
|
|
1807
|
-
(
|
|
1782
|
+
(_a2 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a2 : {}
|
|
1808
1783
|
);
|
|
1809
1784
|
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
1810
1785
|
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
@@ -1869,10 +1844,10 @@ var MWPTransport = class {
|
|
|
1869
1844
|
return cachedWalletSession;
|
|
1870
1845
|
}
|
|
1871
1846
|
return new Promise((resolve, reject) => {
|
|
1872
|
-
var
|
|
1847
|
+
var _a2;
|
|
1873
1848
|
const timeout = setTimeout(() => {
|
|
1874
1849
|
this.rejectRequest(request.id, new import_multichain_api_client2.TransportTimeoutError());
|
|
1875
|
-
}, (
|
|
1850
|
+
}, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : this.options.requestTimeout);
|
|
1876
1851
|
this.pendingRequests.set(request.id, {
|
|
1877
1852
|
request,
|
|
1878
1853
|
method: request.method,
|
|
@@ -1898,30 +1873,32 @@ var MWPTransport = class {
|
|
|
1898
1873
|
logger("active session found", session);
|
|
1899
1874
|
}
|
|
1900
1875
|
let timeout;
|
|
1901
|
-
|
|
1876
|
+
let initialConnectionMessageHandler;
|
|
1877
|
+
const connectionPromise = new Promise((resolve, reject) => __async(this, null, function* () {
|
|
1902
1878
|
let connection;
|
|
1903
1879
|
if (session) {
|
|
1904
1880
|
connection = new Promise((resumeResolve, resumeReject) => {
|
|
1905
|
-
var
|
|
1881
|
+
var _a2;
|
|
1906
1882
|
if (this.dappClient.state === "CONNECTED") {
|
|
1907
1883
|
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
1908
1884
|
} else {
|
|
1909
1885
|
this.dappClient.once("connected", () => __async(this, null, function* () {
|
|
1910
1886
|
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
1911
1887
|
}));
|
|
1912
|
-
dappClient.resume((
|
|
1888
|
+
dappClient.resume((_a2 = session == null ? void 0 : session.id) != null ? _a2 : "");
|
|
1913
1889
|
}
|
|
1914
1890
|
});
|
|
1915
1891
|
} else {
|
|
1916
1892
|
connection = new Promise(
|
|
1917
1893
|
(resolveConnection, rejectConnection) => {
|
|
1918
|
-
var
|
|
1894
|
+
var _a2, _b;
|
|
1919
1895
|
const optionalScopes = addValidAccounts(
|
|
1920
|
-
getOptionalScopes((
|
|
1896
|
+
getOptionalScopes((_a2 = options == null ? void 0 : options.scopes) != null ? _a2 : []),
|
|
1921
1897
|
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
1922
1898
|
);
|
|
1923
1899
|
const sessionRequest = {
|
|
1924
|
-
optionalScopes
|
|
1900
|
+
optionalScopes,
|
|
1901
|
+
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
1925
1902
|
};
|
|
1926
1903
|
const request = {
|
|
1927
1904
|
jsonrpc: "2.0",
|
|
@@ -1929,12 +1906,18 @@ var MWPTransport = class {
|
|
|
1929
1906
|
method: "wallet_createSession",
|
|
1930
1907
|
params: sessionRequest
|
|
1931
1908
|
};
|
|
1932
|
-
|
|
1909
|
+
initialConnectionMessageHandler = (message) => __async(this, null, function* () {
|
|
1933
1910
|
if (typeof message === "object" && message !== null) {
|
|
1934
1911
|
if ("data" in message) {
|
|
1935
1912
|
const messagePayload = message.data;
|
|
1936
1913
|
if (messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged") {
|
|
1937
1914
|
if (messagePayload.error) {
|
|
1915
|
+
if (initialConnectionMessageHandler) {
|
|
1916
|
+
this.dappClient.off(
|
|
1917
|
+
"message",
|
|
1918
|
+
initialConnectionMessageHandler
|
|
1919
|
+
);
|
|
1920
|
+
}
|
|
1938
1921
|
return rejectConnection(messagePayload.error);
|
|
1939
1922
|
}
|
|
1940
1923
|
yield this.storeWalletSession(
|
|
@@ -1946,14 +1929,23 @@ var MWPTransport = class {
|
|
|
1946
1929
|
}
|
|
1947
1930
|
}
|
|
1948
1931
|
}
|
|
1949
|
-
})
|
|
1932
|
+
});
|
|
1933
|
+
this.dappClient.on("message", initialConnectionMessageHandler);
|
|
1950
1934
|
dappClient.connect({
|
|
1951
1935
|
mode: "trusted",
|
|
1952
1936
|
initialPayload: {
|
|
1953
1937
|
name: MULTICHAIN_PROVIDER_STREAM_NAME,
|
|
1954
1938
|
data: request
|
|
1955
1939
|
}
|
|
1956
|
-
}).catch(
|
|
1940
|
+
}).catch((error) => {
|
|
1941
|
+
if (initialConnectionMessageHandler) {
|
|
1942
|
+
this.dappClient.off(
|
|
1943
|
+
"message",
|
|
1944
|
+
initialConnectionMessageHandler
|
|
1945
|
+
);
|
|
1946
|
+
}
|
|
1947
|
+
rejectConnection(error);
|
|
1948
|
+
});
|
|
1957
1949
|
}
|
|
1958
1950
|
);
|
|
1959
1951
|
}
|
|
@@ -1961,11 +1953,17 @@ var MWPTransport = class {
|
|
|
1961
1953
|
reject(new import_multichain_api_client2.TransportTimeoutError());
|
|
1962
1954
|
}, this.options.connectionTimeout);
|
|
1963
1955
|
connection.then(resolve).catch(reject);
|
|
1964
|
-
});
|
|
1965
|
-
return connectionPromise.
|
|
1956
|
+
}));
|
|
1957
|
+
return connectionPromise.catch((error) => {
|
|
1958
|
+
throw error;
|
|
1959
|
+
}).finally(() => {
|
|
1966
1960
|
if (timeout) {
|
|
1967
1961
|
clearTimeout(timeout);
|
|
1968
1962
|
}
|
|
1963
|
+
if (initialConnectionMessageHandler) {
|
|
1964
|
+
this.dappClient.off("message", initialConnectionMessageHandler);
|
|
1965
|
+
initialConnectionMessageHandler = void 0;
|
|
1966
|
+
}
|
|
1969
1967
|
});
|
|
1970
1968
|
});
|
|
1971
1969
|
}
|
|
@@ -2028,7 +2026,7 @@ var MWPTransport = class {
|
|
|
2028
2026
|
}
|
|
2029
2027
|
getCachedResponse(request) {
|
|
2030
2028
|
return __async(this, null, function* () {
|
|
2031
|
-
var
|
|
2029
|
+
var _a2;
|
|
2032
2030
|
if (request.method === "wallet_getSession") {
|
|
2033
2031
|
const walletGetSession = yield this.kvstore.get(SESSION_STORE_KEY);
|
|
2034
2032
|
if (walletGetSession) {
|
|
@@ -2036,7 +2034,7 @@ var MWPTransport = class {
|
|
|
2036
2034
|
return {
|
|
2037
2035
|
id: request.id,
|
|
2038
2036
|
jsonrpc: "2.0",
|
|
2039
|
-
result: (
|
|
2037
|
+
result: (_a2 = walletSession.params) != null ? _a2 : walletSession.result,
|
|
2040
2038
|
// "what?... why walletSession.params?.."
|
|
2041
2039
|
method: request.method
|
|
2042
2040
|
};
|
|
@@ -2100,10 +2098,10 @@ var MWPTransport = class {
|
|
|
2100
2098
|
yield this.attemptResumeSession();
|
|
2101
2099
|
}
|
|
2102
2100
|
return new Promise((resolve, reject) => {
|
|
2103
|
-
var
|
|
2101
|
+
var _a2;
|
|
2104
2102
|
const timeout = setTimeout(() => {
|
|
2105
2103
|
this.rejectRequest(request.id, new import_multichain_api_client2.TransportTimeoutError());
|
|
2106
|
-
}, (
|
|
2104
|
+
}, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : this.options.requestTimeout);
|
|
2107
2105
|
this.pendingRequests.set(request.id, {
|
|
2108
2106
|
request,
|
|
2109
2107
|
method: request.method,
|
|
@@ -2140,6 +2138,43 @@ var MWPTransport = class {
|
|
|
2140
2138
|
}
|
|
2141
2139
|
});
|
|
2142
2140
|
}
|
|
2141
|
+
// This method checks if an existing CAIP session response is cached or waits for one
|
|
2142
|
+
// to be received from the wallet if not cached. This is necessary because there is an edge
|
|
2143
|
+
// case during the initial connection flow where after the user has accepted the permission approval
|
|
2144
|
+
// and returned back to the dapp from the wallet, the dapp page may have gotten unloaded and refreshed.
|
|
2145
|
+
// When it is unloaded and refreshed, it will try to resume the session by making a request for wallet_getSession
|
|
2146
|
+
// which should resolve from cache, but because a race condition makes it possible for the response from the wallet
|
|
2147
|
+
// for the initial wallet_createSession connection request to not have been handled and cached yet. This results
|
|
2148
|
+
// in the wallet_getSession request never resolving unless we wait for it explicitly as done in this method.
|
|
2149
|
+
waitForWalletSessionIfNotCached() {
|
|
2150
|
+
return __async(this, null, function* () {
|
|
2151
|
+
const cachedWalletGetSessionResponse = yield this.kvstore.get(SESSION_STORE_KEY);
|
|
2152
|
+
if (cachedWalletGetSessionResponse) {
|
|
2153
|
+
return;
|
|
2154
|
+
}
|
|
2155
|
+
let unsubscribe;
|
|
2156
|
+
const responsePromise = new Promise((resolve) => {
|
|
2157
|
+
unsubscribe = this.onNotification((message) => {
|
|
2158
|
+
if (typeof message === "object" && message !== null) {
|
|
2159
|
+
if ("data" in message) {
|
|
2160
|
+
const messagePayload = message.data;
|
|
2161
|
+
if (messagePayload.method === "wallet_getSession" || messagePayload.method === "wallet_sessionChanged") {
|
|
2162
|
+
unsubscribe();
|
|
2163
|
+
resolve();
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
});
|
|
2168
|
+
});
|
|
2169
|
+
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
2170
|
+
setTimeout(() => {
|
|
2171
|
+
unsubscribe();
|
|
2172
|
+
reject(new import_multichain_api_client2.TransportTimeoutError());
|
|
2173
|
+
}, this.options.resumeTimeout);
|
|
2174
|
+
});
|
|
2175
|
+
return Promise.race([responsePromise, timeoutPromise]);
|
|
2176
|
+
});
|
|
2177
|
+
}
|
|
2143
2178
|
};
|
|
2144
2179
|
|
|
2145
2180
|
// src/multichain/transports/mwp/KeyManager.ts
|
|
@@ -2171,74 +2206,229 @@ var keymanager = new KeyManager();
|
|
|
2171
2206
|
|
|
2172
2207
|
// src/multichain/index.ts
|
|
2173
2208
|
init_utils();
|
|
2209
|
+
|
|
2210
|
+
// src/multichain/transports/multichainApiClientWrapper/index.ts
|
|
2211
|
+
var import_rpc_errors = require("@metamask/rpc-errors");
|
|
2212
|
+
var MAX = 4294967295;
|
|
2213
|
+
var idCounter = Math.floor(Math.random() * MAX);
|
|
2214
|
+
var getUniqueId = () => {
|
|
2215
|
+
idCounter = (idCounter + 1) % MAX;
|
|
2216
|
+
return idCounter;
|
|
2217
|
+
};
|
|
2218
|
+
var _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
2219
|
+
var MultichainApiClientWrapperTransport = class {
|
|
2220
|
+
constructor(multichainSDK) {
|
|
2221
|
+
this.multichainSDK = multichainSDK;
|
|
2222
|
+
__privateAdd(this, _MultichainApiClientWrapperTransport_instances);
|
|
2223
|
+
this.requestId = getUniqueId();
|
|
2224
|
+
this.notificationCallbacks = /* @__PURE__ */ new Set();
|
|
2225
|
+
}
|
|
2226
|
+
isTransportDefined() {
|
|
2227
|
+
try {
|
|
2228
|
+
return Boolean(this.multichainSDK.transport);
|
|
2229
|
+
} catch (error) {
|
|
2230
|
+
return false;
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
clearNotificationCallbacks() {
|
|
2234
|
+
this.notificationCallbacks.clear();
|
|
2235
|
+
}
|
|
2236
|
+
notifyCallbacks(data) {
|
|
2237
|
+
this.notificationCallbacks.forEach((callback) => {
|
|
2238
|
+
callback(data);
|
|
2239
|
+
});
|
|
2240
|
+
}
|
|
2241
|
+
setupNotifcationListener() {
|
|
2242
|
+
this.multichainSDK.transport.onNotification(
|
|
2243
|
+
this.notifyCallbacks.bind(this)
|
|
2244
|
+
);
|
|
2245
|
+
}
|
|
2246
|
+
connect() {
|
|
2247
|
+
return __async(this, null, function* () {
|
|
2248
|
+
console.log("\u{1F4DA} connect");
|
|
2249
|
+
return Promise.resolve();
|
|
2250
|
+
});
|
|
2251
|
+
}
|
|
2252
|
+
disconnect() {
|
|
2253
|
+
return __async(this, null, function* () {
|
|
2254
|
+
return Promise.resolve();
|
|
2255
|
+
});
|
|
2256
|
+
}
|
|
2257
|
+
isConnected() {
|
|
2258
|
+
return true;
|
|
2259
|
+
}
|
|
2260
|
+
request(_0) {
|
|
2261
|
+
return __async(this, arguments, function* (params, _options = {}) {
|
|
2262
|
+
const id = this.requestId++;
|
|
2263
|
+
const requestPayload = __spreadValues({
|
|
2264
|
+
id,
|
|
2265
|
+
jsonrpc: "2.0"
|
|
2266
|
+
}, params);
|
|
2267
|
+
switch (requestPayload.method) {
|
|
2268
|
+
case "wallet_createSession":
|
|
2269
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn).call(this, requestPayload);
|
|
2270
|
+
case "wallet_getSession":
|
|
2271
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletGetSession_fn).call(this, requestPayload);
|
|
2272
|
+
case "wallet_revokeSession":
|
|
2273
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletRevokeSession_fn).call(this, requestPayload);
|
|
2274
|
+
case "wallet_invokeMethod":
|
|
2275
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletInvokeMethod_fn).call(this, requestPayload);
|
|
2276
|
+
default:
|
|
2277
|
+
throw new Error(`Unsupported method: ${requestPayload.method}`);
|
|
2278
|
+
}
|
|
2279
|
+
throw new Error(`Unknown method: ${requestPayload.method}`);
|
|
2280
|
+
});
|
|
2281
|
+
}
|
|
2282
|
+
onNotification(callback) {
|
|
2283
|
+
if (!this.isTransportDefined()) {
|
|
2284
|
+
this.notificationCallbacks.add(callback);
|
|
2285
|
+
return () => {
|
|
2286
|
+
this.notificationCallbacks.delete(callback);
|
|
2287
|
+
};
|
|
2288
|
+
}
|
|
2289
|
+
return this.multichainSDK.transport.onNotification(callback);
|
|
2290
|
+
}
|
|
2291
|
+
};
|
|
2292
|
+
_MultichainApiClientWrapperTransport_instances = new WeakSet();
|
|
2293
|
+
walletCreateSession_fn = function(request) {
|
|
2294
|
+
return __async(this, null, function* () {
|
|
2295
|
+
console.log("\u{1F4DA} #walletCreateSession", request);
|
|
2296
|
+
const createSessionParams = request.params;
|
|
2297
|
+
const scopes = Object.keys(__spreadValues(__spreadValues({}, createSessionParams.optionalScopes), createSessionParams.requiredScopes));
|
|
2298
|
+
const scopeAccounts = [];
|
|
2299
|
+
scopes.forEach((scope) => {
|
|
2300
|
+
var _a2, _b, _c, _d;
|
|
2301
|
+
const requiredScope = (_a2 = createSessionParams.requiredScopes) == null ? void 0 : _a2[scope];
|
|
2302
|
+
const optionalScope = (_b = createSessionParams.optionalScopes) == null ? void 0 : _b[scope];
|
|
2303
|
+
if (requiredScope) {
|
|
2304
|
+
scopeAccounts.push(...(_c = requiredScope.accounts) != null ? _c : []);
|
|
2305
|
+
}
|
|
2306
|
+
if (optionalScope) {
|
|
2307
|
+
scopeAccounts.push(...(_d = optionalScope.accounts) != null ? _d : []);
|
|
2308
|
+
}
|
|
2309
|
+
});
|
|
2310
|
+
const accounts = [...new Set(scopeAccounts)];
|
|
2311
|
+
console.log("\u{1F4DA} SDK connect");
|
|
2312
|
+
yield this.multichainSDK.connect(
|
|
2313
|
+
scopes,
|
|
2314
|
+
accounts,
|
|
2315
|
+
createSessionParams.sessionProperties
|
|
2316
|
+
);
|
|
2317
|
+
console.log("\u{1F4DA} SDK connected");
|
|
2318
|
+
return this.multichainSDK.transport.request({
|
|
2319
|
+
method: "wallet_getSession"
|
|
2320
|
+
});
|
|
2321
|
+
});
|
|
2322
|
+
};
|
|
2323
|
+
walletGetSession_fn = function(request) {
|
|
2324
|
+
return __async(this, null, function* () {
|
|
2325
|
+
if (!this.isTransportDefined()) {
|
|
2326
|
+
return {
|
|
2327
|
+
jsonrpc: "2.0",
|
|
2328
|
+
id: request.id,
|
|
2329
|
+
result: {
|
|
2330
|
+
sessionScopes: {}
|
|
2331
|
+
}
|
|
2332
|
+
};
|
|
2333
|
+
}
|
|
2334
|
+
return this.multichainSDK.transport.request({
|
|
2335
|
+
method: "wallet_getSession"
|
|
2336
|
+
});
|
|
2337
|
+
});
|
|
2338
|
+
};
|
|
2339
|
+
walletRevokeSession_fn = function(request) {
|
|
2340
|
+
return __async(this, null, function* () {
|
|
2341
|
+
if (!this.isTransportDefined()) {
|
|
2342
|
+
return { jsonrpc: "2.0", id: request.id, result: true };
|
|
2343
|
+
}
|
|
2344
|
+
try {
|
|
2345
|
+
this.multichainSDK.disconnect();
|
|
2346
|
+
return { jsonrpc: "2.0", id: request.id, result: true };
|
|
2347
|
+
} catch (error) {
|
|
2348
|
+
return { jsonrpc: "2.0", id: request.id, result: false };
|
|
2349
|
+
}
|
|
2350
|
+
});
|
|
2351
|
+
};
|
|
2352
|
+
walletInvokeMethod_fn = function(request) {
|
|
2353
|
+
return __async(this, null, function* () {
|
|
2354
|
+
if (!this.isTransportDefined()) {
|
|
2355
|
+
return { error: import_rpc_errors.providerErrors.unauthorized() };
|
|
2356
|
+
}
|
|
2357
|
+
const result = this.multichainSDK.invokeMethod(
|
|
2358
|
+
request.params
|
|
2359
|
+
);
|
|
2360
|
+
return {
|
|
2361
|
+
result
|
|
2362
|
+
};
|
|
2363
|
+
});
|
|
2364
|
+
};
|
|
2365
|
+
|
|
2366
|
+
// src/multichain/index.ts
|
|
2174
2367
|
var logger2 = createLogger("metamask-sdk:core");
|
|
2175
|
-
var
|
|
2368
|
+
var _a, _provider, _providerTransportWrapper, _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, headlessConnect_fn, setupDefaultTransport_fn, deeplinkConnect_fn, handleConnection_fn;
|
|
2369
|
+
var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
2176
2370
|
constructor(options) {
|
|
2177
|
-
var
|
|
2371
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
2178
2372
|
const withDappMetadata = setupDappMetadata(options);
|
|
2179
|
-
const integrationType = ((
|
|
2373
|
+
const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "direct";
|
|
2180
2374
|
const allOptions = __spreadProps(__spreadValues({}, withDappMetadata), {
|
|
2181
2375
|
ui: __spreadProps(__spreadValues({}, withDappMetadata.ui), {
|
|
2182
|
-
preferExtension: (
|
|
2183
|
-
showInstallModal: (
|
|
2184
|
-
headless: (
|
|
2376
|
+
preferExtension: (_c = withDappMetadata.ui.preferExtension) != null ? _c : true,
|
|
2377
|
+
showInstallModal: (_d = withDappMetadata.ui.showInstallModal) != null ? _d : false,
|
|
2378
|
+
headless: (_e = withDappMetadata.ui.headless) != null ? _e : false
|
|
2185
2379
|
}),
|
|
2186
|
-
analytics: __spreadProps(__spreadValues({}, (
|
|
2187
|
-
enabled: (_g = (_f = options.analytics) == null ? void 0 : _f.enabled) != null ? _g : true,
|
|
2380
|
+
analytics: __spreadProps(__spreadValues({}, (_f = options.analytics) != null ? _f : {}), {
|
|
2188
2381
|
integrationType
|
|
2189
2382
|
})
|
|
2190
2383
|
});
|
|
2191
2384
|
super(allOptions);
|
|
2192
|
-
this
|
|
2193
|
-
this
|
|
2194
|
-
this
|
|
2195
|
-
this
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
this.
|
|
2203
|
-
|
|
2385
|
+
__privateAdd(this, _MultichainSDK_instances);
|
|
2386
|
+
__privateAdd(this, _provider);
|
|
2387
|
+
__privateAdd(this, _providerTransportWrapper);
|
|
2388
|
+
__privateAdd(this, _transport2);
|
|
2389
|
+
__privateAdd(this, _dappClient);
|
|
2390
|
+
__privateAdd(this, _beforeUnloadListener);
|
|
2391
|
+
this._status = "pending";
|
|
2392
|
+
__privateAdd(this, _listener);
|
|
2393
|
+
__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}`);
|
|
2394
|
+
__privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(this));
|
|
2395
|
+
__privateSet(this, _provider, (0, import_multichain_api_client3.getMultichainClient)({ transport: __privateGet(this, _providerTransportWrapper) }));
|
|
2396
|
+
}
|
|
2397
|
+
get status() {
|
|
2398
|
+
return this._status;
|
|
2399
|
+
}
|
|
2400
|
+
set status(value) {
|
|
2401
|
+
var _a2, _b;
|
|
2402
|
+
this._status = value;
|
|
2403
|
+
(_b = (_a2 = this.options.transport) == null ? void 0 : _a2.onNotification) == null ? void 0 : _b.call(_a2, {
|
|
2204
2404
|
method: "stateChanged",
|
|
2205
2405
|
params: value
|
|
2206
2406
|
});
|
|
2207
2407
|
}
|
|
2208
2408
|
get provider() {
|
|
2209
|
-
|
|
2210
|
-
this.__provider = (0, import_multichain_api_client3.getMultichainClient)({ transport: this.__transport });
|
|
2211
|
-
return this.__provider;
|
|
2212
|
-
}
|
|
2213
|
-
if (!this.__provider) {
|
|
2214
|
-
throw new Error("Provider not initialized, establish connection first");
|
|
2215
|
-
}
|
|
2216
|
-
return this.__provider;
|
|
2409
|
+
return __privateGet(this, _provider);
|
|
2217
2410
|
}
|
|
2218
2411
|
get transport() {
|
|
2219
|
-
if (!this
|
|
2412
|
+
if (!__privateGet(this, _transport2)) {
|
|
2220
2413
|
throw new Error("Transport not initialized, establish connection first");
|
|
2221
2414
|
}
|
|
2222
|
-
return this
|
|
2415
|
+
return __privateGet(this, _transport2);
|
|
2223
2416
|
}
|
|
2224
2417
|
get dappClient() {
|
|
2225
|
-
if (!this
|
|
2418
|
+
if (!__privateGet(this, _dappClient)) {
|
|
2226
2419
|
throw new Error("DappClient not initialized, establish connection first");
|
|
2227
2420
|
}
|
|
2228
|
-
return this
|
|
2421
|
+
return __privateGet(this, _dappClient);
|
|
2229
2422
|
}
|
|
2230
2423
|
get storage() {
|
|
2231
2424
|
return this.options.storage;
|
|
2232
2425
|
}
|
|
2233
2426
|
get transportType() {
|
|
2234
|
-
return this
|
|
2235
|
-
}
|
|
2236
|
-
get sdkInfo() {
|
|
2237
|
-
var _a;
|
|
2238
|
-
return `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(_a = this.options.dapp.url) != null ? _a : this.options.dapp.name} dAppTitle/${this.options.dapp.name}`;
|
|
2427
|
+
return __privateGet(this, _transport2) instanceof MWPTransport ? "mwp" /* MWP */ : "browser" /* Browser */;
|
|
2239
2428
|
}
|
|
2240
2429
|
static create(options) {
|
|
2241
2430
|
return __async(this, null, function* () {
|
|
2431
|
+
var _a2;
|
|
2242
2432
|
const instance = new _MultichainSDK(options);
|
|
2243
2433
|
const isEnabled2 = yield isEnabled(
|
|
2244
2434
|
"metamask-sdk:core",
|
|
@@ -2247,353 +2437,17 @@ var MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2247
2437
|
if (isEnabled2) {
|
|
2248
2438
|
enableDebug("metamask-sdk:core");
|
|
2249
2439
|
}
|
|
2250
|
-
yield instance.
|
|
2440
|
+
yield __privateMethod(_a2 = instance, _MultichainSDK_instances, init_fn).call(_a2);
|
|
2251
2441
|
return instance;
|
|
2252
2442
|
});
|
|
2253
2443
|
}
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
var _a, _b;
|
|
2257
|
-
if (!((_a = this.options.analytics) == null ? void 0 : _a.enabled)) {
|
|
2258
|
-
return;
|
|
2259
|
-
}
|
|
2260
|
-
const platform = getPlatformType();
|
|
2261
|
-
const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
|
|
2262
|
-
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
2263
|
-
if (!isBrowser && !isReactNative2) {
|
|
2264
|
-
return;
|
|
2265
|
-
}
|
|
2266
|
-
const version = getVersion();
|
|
2267
|
-
const dappId = getDappId(this.options.dapp);
|
|
2268
|
-
const anonId = yield this.storage.getAnonId();
|
|
2269
|
-
const { integrationType } = (_b = this.options.analytics) != null ? _b : {
|
|
2270
|
-
integrationType: ""
|
|
2271
|
-
};
|
|
2272
|
-
import_analytics4.analytics.setGlobalProperty("mmconnect_version", version);
|
|
2273
|
-
import_analytics4.analytics.setGlobalProperty("dapp_id", dappId);
|
|
2274
|
-
import_analytics4.analytics.setGlobalProperty("anon_id", anonId);
|
|
2275
|
-
import_analytics4.analytics.setGlobalProperty("platform", platform);
|
|
2276
|
-
import_analytics4.analytics.setGlobalProperty("integration_type", integrationType);
|
|
2277
|
-
import_analytics4.analytics.enable();
|
|
2278
|
-
});
|
|
2279
|
-
}
|
|
2280
|
-
onTransportNotification(payload) {
|
|
2444
|
+
// TODO: make this into param object
|
|
2445
|
+
connect(scopes, caipAccountIds, sessionProperties, forceRequest) {
|
|
2281
2446
|
return __async(this, null, function* () {
|
|
2282
|
-
var
|
|
2283
|
-
if (
|
|
2284
|
-
this.
|
|
2447
|
+
var _a2;
|
|
2448
|
+
if (this.status !== "connected") {
|
|
2449
|
+
yield this.disconnect();
|
|
2285
2450
|
}
|
|
2286
|
-
});
|
|
2287
|
-
}
|
|
2288
|
-
getStoredTransport() {
|
|
2289
|
-
return __async(this, null, function* () {
|
|
2290
|
-
const transportType = yield this.storage.getTransport();
|
|
2291
|
-
const hasExtensionInstalled = yield hasExtension();
|
|
2292
|
-
if (transportType) {
|
|
2293
|
-
if (transportType === "browser" /* Browser */) {
|
|
2294
|
-
if (hasExtensionInstalled) {
|
|
2295
|
-
const apiTransport = new DefaultTransport();
|
|
2296
|
-
this.__transport = apiTransport;
|
|
2297
|
-
this.listener = apiTransport.onNotification(
|
|
2298
|
-
this.onTransportNotification.bind(this)
|
|
2299
|
-
);
|
|
2300
|
-
return apiTransport;
|
|
2301
|
-
}
|
|
2302
|
-
} else if (transportType === "mwp" /* MWP */) {
|
|
2303
|
-
const { adapter: kvstore } = this.options.storage;
|
|
2304
|
-
const dappClient = yield this.createDappClient();
|
|
2305
|
-
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2306
|
-
this.__dappClient = dappClient;
|
|
2307
|
-
this.__transport = apiTransport;
|
|
2308
|
-
this.listener = apiTransport.onNotification(
|
|
2309
|
-
this.onTransportNotification.bind(this)
|
|
2310
|
-
);
|
|
2311
|
-
return apiTransport;
|
|
2312
|
-
}
|
|
2313
|
-
yield this.storage.removeTransport();
|
|
2314
|
-
}
|
|
2315
|
-
return void 0;
|
|
2316
|
-
});
|
|
2317
|
-
}
|
|
2318
|
-
setupTransport() {
|
|
2319
|
-
return __async(this, null, function* () {
|
|
2320
|
-
const transport = yield this.getStoredTransport();
|
|
2321
|
-
if (transport) {
|
|
2322
|
-
if (!this.transport.isConnected()) {
|
|
2323
|
-
this.state = "connecting";
|
|
2324
|
-
yield this.transport.connect();
|
|
2325
|
-
}
|
|
2326
|
-
this.state = "connected";
|
|
2327
|
-
if (this.transport instanceof MWPTransport) {
|
|
2328
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2329
|
-
} else {
|
|
2330
|
-
yield this.storage.setTransport("browser" /* Browser */);
|
|
2331
|
-
}
|
|
2332
|
-
} else {
|
|
2333
|
-
this.state = "loaded";
|
|
2334
|
-
}
|
|
2335
|
-
});
|
|
2336
|
-
}
|
|
2337
|
-
init() {
|
|
2338
|
-
return __async(this, null, function* () {
|
|
2339
|
-
var _a, _b;
|
|
2340
|
-
try {
|
|
2341
|
-
if (typeof window !== "undefined" && ((_a = window.mmsdk) == null ? void 0 : _a.isInitialized)) {
|
|
2342
|
-
logger2("MetaMaskSDK: init already initialized");
|
|
2343
|
-
} else {
|
|
2344
|
-
yield this.setupAnalytics();
|
|
2345
|
-
yield this.setupTransport();
|
|
2346
|
-
if ((_b = this.options.analytics) == null ? void 0 : _b.enabled) {
|
|
2347
|
-
try {
|
|
2348
|
-
const baseProps = yield getBaseAnalyticsProperties(
|
|
2349
|
-
this.options,
|
|
2350
|
-
this.storage
|
|
2351
|
-
);
|
|
2352
|
-
import_analytics4.analytics.track("mmconnect_initialized", baseProps);
|
|
2353
|
-
} catch (error) {
|
|
2354
|
-
logger2("Error tracking initialized event", error);
|
|
2355
|
-
}
|
|
2356
|
-
}
|
|
2357
|
-
if (typeof window !== "undefined") {
|
|
2358
|
-
window.mmsdk = this;
|
|
2359
|
-
}
|
|
2360
|
-
}
|
|
2361
|
-
} catch (error) {
|
|
2362
|
-
yield this.storage.removeTransport();
|
|
2363
|
-
this.state = "pending";
|
|
2364
|
-
logger2("MetaMaskSDK error during initialization", error);
|
|
2365
|
-
}
|
|
2366
|
-
});
|
|
2367
|
-
}
|
|
2368
|
-
createDappClient() {
|
|
2369
|
-
return __async(this, null, function* () {
|
|
2370
|
-
const { adapter: kvstore } = this.options.storage;
|
|
2371
|
-
const sessionstore = new import_mobile_wallet_protocol_core2.SessionStore(kvstore);
|
|
2372
|
-
const websocket = (
|
|
2373
|
-
// eslint-disable-next-line no-negated-condition
|
|
2374
|
-
typeof window !== "undefined" ? WebSocket : (yield import("ws")).WebSocket
|
|
2375
|
-
);
|
|
2376
|
-
const transport = yield import_mobile_wallet_protocol_core2.WebSocketTransport.create({
|
|
2377
|
-
url: MWP_RELAY_URL,
|
|
2378
|
-
kvstore,
|
|
2379
|
-
websocket
|
|
2380
|
-
});
|
|
2381
|
-
const dappClient = new import_mobile_wallet_protocol_dapp_client.DappClient({ transport, sessionstore, keymanager });
|
|
2382
|
-
return dappClient;
|
|
2383
|
-
});
|
|
2384
|
-
}
|
|
2385
|
-
setupMWP() {
|
|
2386
|
-
return __async(this, null, function* () {
|
|
2387
|
-
if (this.__transport instanceof MWPTransport) {
|
|
2388
|
-
return;
|
|
2389
|
-
}
|
|
2390
|
-
const { adapter: kvstore } = this.options.storage;
|
|
2391
|
-
const dappClient = yield this.createDappClient();
|
|
2392
|
-
this.__dappClient = dappClient;
|
|
2393
|
-
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2394
|
-
this.__transport = apiTransport;
|
|
2395
|
-
this.listener = this.transport.onNotification(
|
|
2396
|
-
this.onTransportNotification.bind(this)
|
|
2397
|
-
);
|
|
2398
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2399
|
-
});
|
|
2400
|
-
}
|
|
2401
|
-
onBeforeUnload() {
|
|
2402
|
-
return __async(this, null, function* () {
|
|
2403
|
-
var _a;
|
|
2404
|
-
if ((_a = this.options.ui.factory.modal) == null ? void 0 : _a.isMounted) {
|
|
2405
|
-
yield this.storage.removeTransport();
|
|
2406
|
-
}
|
|
2407
|
-
});
|
|
2408
|
-
}
|
|
2409
|
-
createBeforeUnloadListener() {
|
|
2410
|
-
if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
|
|
2411
|
-
window.addEventListener("beforeunload", this.onBeforeUnload.bind(this));
|
|
2412
|
-
}
|
|
2413
|
-
return () => {
|
|
2414
|
-
if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined") {
|
|
2415
|
-
window.removeEventListener(
|
|
2416
|
-
"beforeunload",
|
|
2417
|
-
this.onBeforeUnload.bind(this)
|
|
2418
|
-
);
|
|
2419
|
-
}
|
|
2420
|
-
};
|
|
2421
|
-
}
|
|
2422
|
-
showInstallModal(desktopPreferred, scopes, caipAccountIds) {
|
|
2423
|
-
return __async(this, null, function* () {
|
|
2424
|
-
var _a;
|
|
2425
|
-
(_a = this.__beforeUnloadListener) != null ? _a : this.__beforeUnloadListener = this.createBeforeUnloadListener();
|
|
2426
|
-
return new Promise((resolve, reject) => {
|
|
2427
|
-
this.options.ui.factory.renderInstallModal(
|
|
2428
|
-
desktopPreferred,
|
|
2429
|
-
() => __async(this, null, function* () {
|
|
2430
|
-
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
2431
|
-
yield this.dappClient.disconnect();
|
|
2432
|
-
}
|
|
2433
|
-
return new Promise((resolveConnectionRequest) => {
|
|
2434
|
-
this.dappClient.on(
|
|
2435
|
-
"session_request",
|
|
2436
|
-
(sessionRequest) => {
|
|
2437
|
-
resolveConnectionRequest({
|
|
2438
|
-
sessionRequest,
|
|
2439
|
-
metadata: {
|
|
2440
|
-
dapp: this.options.dapp,
|
|
2441
|
-
sdk: {
|
|
2442
|
-
version: getVersion(),
|
|
2443
|
-
platform: getPlatformType()
|
|
2444
|
-
}
|
|
2445
|
-
}
|
|
2446
|
-
});
|
|
2447
|
-
}
|
|
2448
|
-
);
|
|
2449
|
-
this.transport.connect({ scopes, caipAccountIds }).then(() => {
|
|
2450
|
-
var _a2;
|
|
2451
|
-
this.options.ui.factory.unload();
|
|
2452
|
-
(_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
|
|
2453
|
-
this.state = "connected";
|
|
2454
|
-
return this.storage.setTransport("mwp" /* MWP */);
|
|
2455
|
-
}).catch((error) => {
|
|
2456
|
-
if (error instanceof import_mobile_wallet_protocol_core2.ProtocolError) {
|
|
2457
|
-
if (error.code !== import_mobile_wallet_protocol_core2.ErrorCode.REQUEST_EXPIRED) {
|
|
2458
|
-
this.state = "disconnected";
|
|
2459
|
-
reject(error);
|
|
2460
|
-
}
|
|
2461
|
-
} else {
|
|
2462
|
-
this.state = "disconnected";
|
|
2463
|
-
reject(error);
|
|
2464
|
-
}
|
|
2465
|
-
});
|
|
2466
|
-
});
|
|
2467
|
-
}),
|
|
2468
|
-
(error) => __async(this, null, function* () {
|
|
2469
|
-
if (!error) {
|
|
2470
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2471
|
-
resolve();
|
|
2472
|
-
} else {
|
|
2473
|
-
yield this.storage.removeTransport();
|
|
2474
|
-
reject(error);
|
|
2475
|
-
}
|
|
2476
|
-
})
|
|
2477
|
-
);
|
|
2478
|
-
});
|
|
2479
|
-
});
|
|
2480
|
-
}
|
|
2481
|
-
setupDefaultTransport() {
|
|
2482
|
-
return __async(this, null, function* () {
|
|
2483
|
-
this.state = "connecting";
|
|
2484
|
-
yield this.storage.setTransport("browser" /* Browser */);
|
|
2485
|
-
const transport = new DefaultTransport();
|
|
2486
|
-
this.listener = transport.onNotification(
|
|
2487
|
-
this.onTransportNotification.bind(this)
|
|
2488
|
-
);
|
|
2489
|
-
this.__transport = transport;
|
|
2490
|
-
return transport;
|
|
2491
|
-
});
|
|
2492
|
-
}
|
|
2493
|
-
deeplinkConnect(scopes, caipAccountIds) {
|
|
2494
|
-
return __async(this, null, function* () {
|
|
2495
|
-
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
2496
|
-
this.dappClient.on("message", (payload) => {
|
|
2497
|
-
var _a, _b, _c;
|
|
2498
|
-
const data = payload.data;
|
|
2499
|
-
if (typeof data === "object" && data !== null) {
|
|
2500
|
-
if ("method" in data && data.method === "wallet_createSession") {
|
|
2501
|
-
if (data.error) {
|
|
2502
|
-
this.state = "loaded";
|
|
2503
|
-
return reject(data.error);
|
|
2504
|
-
}
|
|
2505
|
-
const session = (_a = data.params) != null ? _a : data.result;
|
|
2506
|
-
if (session) {
|
|
2507
|
-
(_c = (_b = this.options.transport) == null ? void 0 : _b.onNotification) == null ? void 0 : _c.call(_b, payload.data);
|
|
2508
|
-
this.emit("wallet_sessionChanged", session);
|
|
2509
|
-
}
|
|
2510
|
-
}
|
|
2511
|
-
}
|
|
2512
|
-
});
|
|
2513
|
-
let timeout;
|
|
2514
|
-
if (!this.transport.isConnected()) {
|
|
2515
|
-
this.dappClient.once(
|
|
2516
|
-
"session_request",
|
|
2517
|
-
(sessionRequest) => {
|
|
2518
|
-
var _a;
|
|
2519
|
-
const connectionRequest = {
|
|
2520
|
-
sessionRequest,
|
|
2521
|
-
metadata: {
|
|
2522
|
-
dapp: this.options.dapp,
|
|
2523
|
-
sdk: { version: getVersion(), platform: getPlatformType() }
|
|
2524
|
-
}
|
|
2525
|
-
};
|
|
2526
|
-
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
2527
|
-
const universalLink = this.options.ui.factory.createConnectionUniversalLink(connectionRequest);
|
|
2528
|
-
if ((_a = this.options.mobile) == null ? void 0 : _a.preferredOpenLink) {
|
|
2529
|
-
this.options.mobile.preferredOpenLink(deeplink, "_self");
|
|
2530
|
-
} else {
|
|
2531
|
-
openDeeplink(this.options, deeplink, universalLink);
|
|
2532
|
-
}
|
|
2533
|
-
}
|
|
2534
|
-
);
|
|
2535
|
-
}
|
|
2536
|
-
this.transport.connect({ scopes, caipAccountIds }).then(resolve).catch((error) => {
|
|
2537
|
-
this.storage.removeTransport();
|
|
2538
|
-
reject(error);
|
|
2539
|
-
}).finally(() => {
|
|
2540
|
-
if (timeout) {
|
|
2541
|
-
clearTimeout(timeout);
|
|
2542
|
-
}
|
|
2543
|
-
});
|
|
2544
|
-
}));
|
|
2545
|
-
});
|
|
2546
|
-
}
|
|
2547
|
-
handleConnection(promise, scopes, transportType) {
|
|
2548
|
-
return __async(this, null, function* () {
|
|
2549
|
-
this.state = "connecting";
|
|
2550
|
-
return promise.then(() => __async(this, null, function* () {
|
|
2551
|
-
var _a;
|
|
2552
|
-
this.state = "connected";
|
|
2553
|
-
if ((_a = this.options.analytics) == null ? void 0 : _a.enabled) {
|
|
2554
|
-
try {
|
|
2555
|
-
const baseProps = yield getBaseAnalyticsProperties(
|
|
2556
|
-
this.options,
|
|
2557
|
-
this.storage
|
|
2558
|
-
);
|
|
2559
|
-
import_analytics4.analytics.track("mmconnect_connection_established", __spreadProps(__spreadValues({}, baseProps), {
|
|
2560
|
-
transport_type: transportType,
|
|
2561
|
-
user_permissioned_chains: scopes
|
|
2562
|
-
}));
|
|
2563
|
-
} catch (error) {
|
|
2564
|
-
logger2("Error tracking connection_established event", error);
|
|
2565
|
-
}
|
|
2566
|
-
}
|
|
2567
|
-
})).catch((error) => __async(this, null, function* () {
|
|
2568
|
-
var _a;
|
|
2569
|
-
this.state = "disconnected";
|
|
2570
|
-
if ((_a = this.options.analytics) == null ? void 0 : _a.enabled) {
|
|
2571
|
-
try {
|
|
2572
|
-
const baseProps = yield getBaseAnalyticsProperties(
|
|
2573
|
-
this.options,
|
|
2574
|
-
this.storage
|
|
2575
|
-
);
|
|
2576
|
-
const isRejection = isRejectionError(error);
|
|
2577
|
-
if (isRejection) {
|
|
2578
|
-
import_analytics4.analytics.track("mmconnect_connection_rejected", __spreadProps(__spreadValues({}, baseProps), {
|
|
2579
|
-
transport_type: transportType
|
|
2580
|
-
}));
|
|
2581
|
-
} else {
|
|
2582
|
-
import_analytics4.analytics.track("mmconnect_connection_failed", __spreadProps(__spreadValues({}, baseProps), {
|
|
2583
|
-
transport_type: transportType
|
|
2584
|
-
}));
|
|
2585
|
-
}
|
|
2586
|
-
} catch (e) {
|
|
2587
|
-
logger2("Error tracking connection failed/rejected event", error);
|
|
2588
|
-
}
|
|
2589
|
-
}
|
|
2590
|
-
return Promise.reject(error);
|
|
2591
|
-
}));
|
|
2592
|
-
});
|
|
2593
|
-
}
|
|
2594
|
-
connect(scopes, caipAccountIds, forceRequest) {
|
|
2595
|
-
return __async(this, null, function* () {
|
|
2596
|
-
var _a, _b;
|
|
2597
2451
|
const { ui } = this.options;
|
|
2598
2452
|
const platformType = getPlatformType();
|
|
2599
2453
|
const isWeb = platformType === "in-app-browser" /* MetaMaskMobileWebview */ || platformType === "web-desktop" /* DesktopWeb */;
|
|
@@ -2606,96 +2460,70 @@ var MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2606
2460
|
} else {
|
|
2607
2461
|
transportType = "mwp" /* MWP */;
|
|
2608
2462
|
}
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
this.options.api.supportedNetworks
|
|
2617
|
-
);
|
|
2618
|
-
import_analytics4.analytics.track("mmconnect_connection_initiated", __spreadProps(__spreadValues({}, baseProps), {
|
|
2619
|
-
transport_type: transportType,
|
|
2620
|
-
dapp_configured_chains: dappConfiguredChains,
|
|
2621
|
-
dapp_requested_chains: scopes
|
|
2622
|
-
}));
|
|
2623
|
-
} catch (error) {
|
|
2624
|
-
logger2("Error tracking connection_initiated event", error);
|
|
2625
|
-
}
|
|
2626
|
-
}
|
|
2627
|
-
if (((_b = this.__transport) == null ? void 0 : _b.isConnected()) && !secure) {
|
|
2628
|
-
return this.handleConnection(
|
|
2629
|
-
this.__transport.connect({ scopes, caipAccountIds, forceRequest }).then(() => {
|
|
2630
|
-
if (this.__transport instanceof MWPTransport) {
|
|
2631
|
-
return this.storage.setTransport("mwp" /* MWP */);
|
|
2632
|
-
} else {
|
|
2633
|
-
return this.storage.setTransport("browser" /* Browser */);
|
|
2634
|
-
}
|
|
2635
|
-
}),
|
|
2636
|
-
scopes,
|
|
2637
|
-
transportType
|
|
2463
|
+
try {
|
|
2464
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2465
|
+
this.options,
|
|
2466
|
+
this.storage
|
|
2467
|
+
);
|
|
2468
|
+
const dappConfiguredChains = Object.keys(
|
|
2469
|
+
this.options.api.supportedNetworks
|
|
2638
2470
|
);
|
|
2471
|
+
import_analytics4.analytics.track("mmconnect_connection_initiated", __spreadProps(__spreadValues({}, baseProps), {
|
|
2472
|
+
transport_type: transportType,
|
|
2473
|
+
dapp_configured_chains: dappConfiguredChains,
|
|
2474
|
+
dapp_requested_chains: scopes
|
|
2475
|
+
}));
|
|
2476
|
+
} catch (error) {
|
|
2477
|
+
logger2("Error tracking connection_initiated event", error);
|
|
2478
|
+
}
|
|
2479
|
+
if (((_a2 = __privateGet(this, _transport2)) == null ? void 0 : _a2.isConnected()) && !secure) {
|
|
2480
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateGet(this, _transport2).connect({ scopes, caipAccountIds, sessionProperties, forceRequest }).then(() => __async(this, null, function* () {
|
|
2481
|
+
if (__privateGet(this, _transport2) instanceof MWPTransport) {
|
|
2482
|
+
return this.storage.setTransport("mwp" /* MWP */);
|
|
2483
|
+
}
|
|
2484
|
+
return this.storage.setTransport("browser" /* Browser */);
|
|
2485
|
+
})), scopes, transportType);
|
|
2639
2486
|
}
|
|
2640
2487
|
if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
|
|
2641
|
-
const defaultTransport = yield this.
|
|
2642
|
-
return this.
|
|
2643
|
-
defaultTransport.connect({ scopes, caipAccountIds, forceRequest }),
|
|
2644
|
-
scopes,
|
|
2645
|
-
transportType
|
|
2646
|
-
);
|
|
2488
|
+
const defaultTransport = yield __privateMethod(this, _MultichainSDK_instances, setupDefaultTransport_fn).call(this);
|
|
2489
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, sessionProperties, forceRequest }), scopes, transportType);
|
|
2647
2490
|
}
|
|
2648
2491
|
if (isWeb && hasExtensionInstalled && preferExtension) {
|
|
2649
|
-
const defaultTransport = yield this.
|
|
2650
|
-
return this.
|
|
2651
|
-
defaultTransport.connect({ scopes, caipAccountIds, forceRequest }),
|
|
2652
|
-
scopes,
|
|
2653
|
-
transportType
|
|
2654
|
-
);
|
|
2492
|
+
const defaultTransport = yield __privateMethod(this, _MultichainSDK_instances, setupDefaultTransport_fn).call(this);
|
|
2493
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, sessionProperties, forceRequest }), scopes, transportType);
|
|
2655
2494
|
}
|
|
2656
|
-
yield this.
|
|
2495
|
+
yield __privateMethod(this, _MultichainSDK_instances, setupMWP_fn).call(this);
|
|
2657
2496
|
const shouldShowInstallModal = hasExtensionInstalled ? showInstallModal : !preferExtension || showInstallModal;
|
|
2658
2497
|
if (secure && !shouldShowInstallModal) {
|
|
2659
|
-
return this.
|
|
2660
|
-
this.deeplinkConnect(scopes, caipAccountIds),
|
|
2661
|
-
scopes,
|
|
2662
|
-
transportType
|
|
2663
|
-
);
|
|
2498
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateMethod(this, _MultichainSDK_instances, deeplinkConnect_fn).call(this, scopes, caipAccountIds, sessionProperties), scopes, transportType);
|
|
2664
2499
|
}
|
|
2665
|
-
return this.
|
|
2666
|
-
this.showInstallModal(shouldShowInstallModal, scopes, caipAccountIds),
|
|
2667
|
-
scopes,
|
|
2668
|
-
transportType
|
|
2669
|
-
);
|
|
2500
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateMethod(this, _MultichainSDK_instances, showInstallModal_fn).call(this, shouldShowInstallModal, scopes, caipAccountIds, sessionProperties), scopes, transportType);
|
|
2670
2501
|
});
|
|
2671
2502
|
}
|
|
2672
2503
|
emit(event, args) {
|
|
2673
|
-
var
|
|
2674
|
-
(_b = (
|
|
2504
|
+
var _a2, _b;
|
|
2505
|
+
(_b = (_a2 = this.options.transport) == null ? void 0 : _a2.onNotification) == null ? void 0 : _b.call(_a2, { method: event, params: args });
|
|
2675
2506
|
super.emit(event, args);
|
|
2676
2507
|
}
|
|
2677
2508
|
disconnect() {
|
|
2678
2509
|
return __async(this, null, function* () {
|
|
2679
|
-
var
|
|
2680
|
-
(
|
|
2681
|
-
(_b = this
|
|
2682
|
-
yield (_c = this
|
|
2510
|
+
var _a2, _b, _c;
|
|
2511
|
+
yield (_a2 = __privateGet(this, _listener)) == null ? void 0 : _a2.call(this);
|
|
2512
|
+
(_b = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _b.call(this);
|
|
2513
|
+
yield (_c = __privateGet(this, _transport2)) == null ? void 0 : _c.disconnect();
|
|
2683
2514
|
yield this.storage.removeTransport();
|
|
2684
|
-
this.emit("wallet_sessionChanged", void 0);
|
|
2685
2515
|
this.emit("stateChanged", "disconnected");
|
|
2686
|
-
this
|
|
2687
|
-
this
|
|
2688
|
-
this
|
|
2689
|
-
this.
|
|
2690
|
-
this
|
|
2516
|
+
__privateSet(this, _listener, void 0);
|
|
2517
|
+
__privateSet(this, _beforeUnloadListener, void 0);
|
|
2518
|
+
__privateSet(this, _transport2, void 0);
|
|
2519
|
+
__privateGet(this, _providerTransportWrapper).clearNotificationCallbacks();
|
|
2520
|
+
__privateSet(this, _dappClient, void 0);
|
|
2691
2521
|
});
|
|
2692
2522
|
}
|
|
2693
2523
|
invokeMethod(request) {
|
|
2694
2524
|
return __async(this, null, function* () {
|
|
2695
|
-
|
|
2696
|
-
const
|
|
2697
|
-
(_a = this.__provider) != null ? _a : this.__provider = (0, import_multichain_api_client3.getMultichainClient)({ transport });
|
|
2698
|
-
const rpcClient = new RpcClient(options, sdkInfo);
|
|
2525
|
+
const { transport, options } = this;
|
|
2526
|
+
const rpcClient = new RpcClient(options, __privateGet(this, _sdkInfo));
|
|
2699
2527
|
const requestRouter = new RequestRouter(transport, rpcClient, options);
|
|
2700
2528
|
return requestRouter.invokeMethod(request);
|
|
2701
2529
|
});
|
|
@@ -2716,16 +2544,427 @@ var MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2716
2544
|
if (mobile == null ? void 0 : mobile.preferredOpenLink) {
|
|
2717
2545
|
mobile.preferredOpenLink(url, "_self");
|
|
2718
2546
|
} else {
|
|
2719
|
-
openDeeplink(
|
|
2720
|
-
this.options,
|
|
2721
|
-
url,
|
|
2722
|
-
METAMASK_CONNECT_BASE_URL
|
|
2723
|
-
);
|
|
2547
|
+
openDeeplink(this.options, url, METAMASK_CONNECT_BASE_URL);
|
|
2724
2548
|
}
|
|
2725
2549
|
}), 10);
|
|
2726
2550
|
}
|
|
2727
2551
|
}
|
|
2728
2552
|
};
|
|
2553
|
+
_provider = new WeakMap();
|
|
2554
|
+
_providerTransportWrapper = new WeakMap();
|
|
2555
|
+
_transport2 = new WeakMap();
|
|
2556
|
+
_dappClient = new WeakMap();
|
|
2557
|
+
_beforeUnloadListener = new WeakMap();
|
|
2558
|
+
_listener = new WeakMap();
|
|
2559
|
+
_sdkInfo = new WeakMap();
|
|
2560
|
+
_MultichainSDK_instances = new WeakSet();
|
|
2561
|
+
setupAnalytics_fn = function() {
|
|
2562
|
+
return __async(this, null, function* () {
|
|
2563
|
+
var _a2;
|
|
2564
|
+
const platform = getPlatformType();
|
|
2565
|
+
const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
|
|
2566
|
+
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
2567
|
+
if (!isBrowser && !isReactNative2) {
|
|
2568
|
+
return;
|
|
2569
|
+
}
|
|
2570
|
+
const version = getVersion();
|
|
2571
|
+
const dappId = getDappId(this.options.dapp);
|
|
2572
|
+
const anonId = yield this.storage.getAnonId();
|
|
2573
|
+
const { integrationType } = (_a2 = this.options.analytics) != null ? _a2 : {
|
|
2574
|
+
integrationType: ""
|
|
2575
|
+
};
|
|
2576
|
+
import_analytics4.analytics.setGlobalProperty("mmconnect_version", version);
|
|
2577
|
+
import_analytics4.analytics.setGlobalProperty("dapp_id", dappId);
|
|
2578
|
+
import_analytics4.analytics.setGlobalProperty("anon_id", anonId);
|
|
2579
|
+
import_analytics4.analytics.setGlobalProperty("platform", platform);
|
|
2580
|
+
import_analytics4.analytics.setGlobalProperty("integration_type", integrationType);
|
|
2581
|
+
import_analytics4.analytics.enable();
|
|
2582
|
+
});
|
|
2583
|
+
};
|
|
2584
|
+
onTransportNotification_fn = function(payload) {
|
|
2585
|
+
return __async(this, null, function* () {
|
|
2586
|
+
var _a2;
|
|
2587
|
+
if (typeof payload === "object" && payload !== null && "method" in payload) {
|
|
2588
|
+
this.emit(payload.method, (_a2 = payload.params) != null ? _a2 : payload.result);
|
|
2589
|
+
}
|
|
2590
|
+
});
|
|
2591
|
+
};
|
|
2592
|
+
getStoredTransport_fn = function() {
|
|
2593
|
+
return __async(this, null, function* () {
|
|
2594
|
+
const transportType = yield this.storage.getTransport();
|
|
2595
|
+
const hasExtensionInstalled = yield hasExtension();
|
|
2596
|
+
if (transportType) {
|
|
2597
|
+
if (transportType === "browser" /* Browser */) {
|
|
2598
|
+
if (hasExtensionInstalled) {
|
|
2599
|
+
const apiTransport = new DefaultTransport();
|
|
2600
|
+
__privateSet(this, _transport2, apiTransport);
|
|
2601
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2602
|
+
__privateSet(this, _listener, apiTransport.onNotification(
|
|
2603
|
+
__privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
|
|
2604
|
+
));
|
|
2605
|
+
return apiTransport;
|
|
2606
|
+
}
|
|
2607
|
+
} else if (transportType === "mwp" /* MWP */) {
|
|
2608
|
+
const { adapter: kvstore } = this.options.storage;
|
|
2609
|
+
const dappClient = yield __privateMethod(this, _MultichainSDK_instances, createDappClient_fn).call(this);
|
|
2610
|
+
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2611
|
+
__privateSet(this, _dappClient, dappClient);
|
|
2612
|
+
__privateSet(this, _transport2, apiTransport);
|
|
2613
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2614
|
+
__privateSet(this, _listener, apiTransport.onNotification(
|
|
2615
|
+
__privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
|
|
2616
|
+
));
|
|
2617
|
+
return apiTransport;
|
|
2618
|
+
}
|
|
2619
|
+
yield this.storage.removeTransport();
|
|
2620
|
+
}
|
|
2621
|
+
return void 0;
|
|
2622
|
+
});
|
|
2623
|
+
};
|
|
2624
|
+
setupTransport_fn = function() {
|
|
2625
|
+
return __async(this, null, function* () {
|
|
2626
|
+
const transport = yield __privateMethod(this, _MultichainSDK_instances, getStoredTransport_fn).call(this);
|
|
2627
|
+
if (transport) {
|
|
2628
|
+
if (!this.transport.isConnected()) {
|
|
2629
|
+
this.status = "connecting";
|
|
2630
|
+
yield this.transport.connect();
|
|
2631
|
+
}
|
|
2632
|
+
this.status = "connected";
|
|
2633
|
+
if (this.transport instanceof MWPTransport) {
|
|
2634
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2635
|
+
} else {
|
|
2636
|
+
yield this.storage.setTransport("browser" /* Browser */);
|
|
2637
|
+
}
|
|
2638
|
+
} else {
|
|
2639
|
+
this.status = "loaded";
|
|
2640
|
+
}
|
|
2641
|
+
});
|
|
2642
|
+
};
|
|
2643
|
+
init_fn = function() {
|
|
2644
|
+
return __async(this, null, function* () {
|
|
2645
|
+
var _a2;
|
|
2646
|
+
try {
|
|
2647
|
+
if (typeof window !== "undefined" && ((_a2 = window.mmsdk) == null ? void 0 : _a2.isInitialized)) {
|
|
2648
|
+
logger2("MetaMaskSDK: init already initialized");
|
|
2649
|
+
} else {
|
|
2650
|
+
yield __privateMethod(this, _MultichainSDK_instances, setupAnalytics_fn).call(this);
|
|
2651
|
+
yield __privateMethod(this, _MultichainSDK_instances, setupTransport_fn).call(this);
|
|
2652
|
+
try {
|
|
2653
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2654
|
+
this.options,
|
|
2655
|
+
this.storage
|
|
2656
|
+
);
|
|
2657
|
+
import_analytics4.analytics.track("mmconnect_initialized", baseProps);
|
|
2658
|
+
} catch (error) {
|
|
2659
|
+
logger2("Error tracking initialized event", error);
|
|
2660
|
+
}
|
|
2661
|
+
if (typeof window !== "undefined") {
|
|
2662
|
+
window.mmsdk = this;
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
} catch (error) {
|
|
2666
|
+
yield this.storage.removeTransport();
|
|
2667
|
+
this.status = "pending";
|
|
2668
|
+
logger2("MetaMaskSDK error during initialization", error);
|
|
2669
|
+
}
|
|
2670
|
+
});
|
|
2671
|
+
};
|
|
2672
|
+
createDappClient_fn = function() {
|
|
2673
|
+
return __async(this, null, function* () {
|
|
2674
|
+
const { adapter: kvstore } = this.options.storage;
|
|
2675
|
+
const sessionstore = new import_mobile_wallet_protocol_core2.SessionStore(kvstore);
|
|
2676
|
+
const websocket = (
|
|
2677
|
+
// eslint-disable-next-line no-negated-condition
|
|
2678
|
+
typeof window !== "undefined" ? WebSocket : (yield import("ws")).WebSocket
|
|
2679
|
+
);
|
|
2680
|
+
const transport = yield import_mobile_wallet_protocol_core2.WebSocketTransport.create({
|
|
2681
|
+
url: MWP_RELAY_URL,
|
|
2682
|
+
kvstore,
|
|
2683
|
+
websocket
|
|
2684
|
+
});
|
|
2685
|
+
const dappClient = new import_mobile_wallet_protocol_dapp_client.DappClient({ transport, sessionstore, keymanager });
|
|
2686
|
+
return dappClient;
|
|
2687
|
+
});
|
|
2688
|
+
};
|
|
2689
|
+
setupMWP_fn = function() {
|
|
2690
|
+
return __async(this, null, function* () {
|
|
2691
|
+
if (__privateGet(this, _transport2) instanceof MWPTransport) {
|
|
2692
|
+
return;
|
|
2693
|
+
}
|
|
2694
|
+
const { adapter: kvstore } = this.options.storage;
|
|
2695
|
+
const dappClient = yield __privateMethod(this, _MultichainSDK_instances, createDappClient_fn).call(this);
|
|
2696
|
+
__privateSet(this, _dappClient, dappClient);
|
|
2697
|
+
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2698
|
+
__privateSet(this, _transport2, apiTransport);
|
|
2699
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2700
|
+
__privateSet(this, _listener, this.transport.onNotification(
|
|
2701
|
+
__privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
|
|
2702
|
+
));
|
|
2703
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2704
|
+
});
|
|
2705
|
+
};
|
|
2706
|
+
onBeforeUnload_fn = function() {
|
|
2707
|
+
return __async(this, null, function* () {
|
|
2708
|
+
var _a2;
|
|
2709
|
+
if ((_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.isMounted) {
|
|
2710
|
+
yield this.storage.removeTransport();
|
|
2711
|
+
}
|
|
2712
|
+
});
|
|
2713
|
+
};
|
|
2714
|
+
createBeforeUnloadListener_fn = function() {
|
|
2715
|
+
if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
|
|
2716
|
+
window.addEventListener("beforeunload", __privateMethod(this, _MultichainSDK_instances, onBeforeUnload_fn).bind(this));
|
|
2717
|
+
}
|
|
2718
|
+
return () => {
|
|
2719
|
+
if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined") {
|
|
2720
|
+
window.removeEventListener(
|
|
2721
|
+
"beforeunload",
|
|
2722
|
+
__privateMethod(this, _MultichainSDK_instances, onBeforeUnload_fn).bind(this)
|
|
2723
|
+
);
|
|
2724
|
+
}
|
|
2725
|
+
};
|
|
2726
|
+
};
|
|
2727
|
+
renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
2728
|
+
return __async(this, null, function* () {
|
|
2729
|
+
return new Promise((resolve, reject) => {
|
|
2730
|
+
this.options.ui.factory.renderInstallModal(
|
|
2731
|
+
desktopPreferred,
|
|
2732
|
+
() => __async(this, null, function* () {
|
|
2733
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
2734
|
+
yield this.dappClient.disconnect();
|
|
2735
|
+
}
|
|
2736
|
+
return new Promise((_resolve) => {
|
|
2737
|
+
this.dappClient.on(
|
|
2738
|
+
"session_request",
|
|
2739
|
+
(sessionRequest) => {
|
|
2740
|
+
_resolve({
|
|
2741
|
+
sessionRequest,
|
|
2742
|
+
metadata: {
|
|
2743
|
+
dapp: this.options.dapp,
|
|
2744
|
+
sdk: {
|
|
2745
|
+
version: getVersion(),
|
|
2746
|
+
platform: getPlatformType()
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
});
|
|
2750
|
+
}
|
|
2751
|
+
);
|
|
2752
|
+
(() => __async(this, null, function* () {
|
|
2753
|
+
var _a2;
|
|
2754
|
+
try {
|
|
2755
|
+
yield this.transport.connect({ scopes, caipAccountIds, sessionProperties });
|
|
2756
|
+
yield this.options.ui.factory.unload();
|
|
2757
|
+
(_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
|
|
2758
|
+
this.status = "connected";
|
|
2759
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2760
|
+
} catch (error) {
|
|
2761
|
+
if (error instanceof import_mobile_wallet_protocol_core2.ProtocolError) {
|
|
2762
|
+
if (error.code !== import_mobile_wallet_protocol_core2.ErrorCode.REQUEST_EXPIRED) {
|
|
2763
|
+
this.status = "disconnected";
|
|
2764
|
+
reject(error);
|
|
2765
|
+
}
|
|
2766
|
+
} else {
|
|
2767
|
+
this.status = "disconnected";
|
|
2768
|
+
reject(
|
|
2769
|
+
error instanceof Error ? error : new Error(String(error))
|
|
2770
|
+
);
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
}))().catch(() => {
|
|
2774
|
+
});
|
|
2775
|
+
});
|
|
2776
|
+
}),
|
|
2777
|
+
(error) => __async(this, null, function* () {
|
|
2778
|
+
if (error) {
|
|
2779
|
+
yield this.storage.removeTransport();
|
|
2780
|
+
reject(error);
|
|
2781
|
+
} else {
|
|
2782
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2783
|
+
resolve();
|
|
2784
|
+
}
|
|
2785
|
+
}),
|
|
2786
|
+
(uri) => {
|
|
2787
|
+
this.emit("display_uri", uri);
|
|
2788
|
+
}
|
|
2789
|
+
).catch((error) => {
|
|
2790
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2791
|
+
});
|
|
2792
|
+
});
|
|
2793
|
+
});
|
|
2794
|
+
};
|
|
2795
|
+
showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
2796
|
+
return __async(this, null, function* () {
|
|
2797
|
+
var _a2;
|
|
2798
|
+
(_a2 = __privateGet(this, _beforeUnloadListener)) != null ? _a2 : __privateSet(this, _beforeUnloadListener, __privateMethod(this, _MultichainSDK_instances, createBeforeUnloadListener_fn).call(this));
|
|
2799
|
+
if (this.options.ui.headless) {
|
|
2800
|
+
yield __privateMethod(this, _MultichainSDK_instances, headlessConnect_fn).call(this, scopes, caipAccountIds, sessionProperties);
|
|
2801
|
+
} else {
|
|
2802
|
+
yield __privateMethod(this, _MultichainSDK_instances, renderInstallModalAsync_fn).call(this, desktopPreferred, scopes, caipAccountIds, sessionProperties);
|
|
2803
|
+
}
|
|
2804
|
+
});
|
|
2805
|
+
};
|
|
2806
|
+
headlessConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
2807
|
+
return __async(this, null, function* () {
|
|
2808
|
+
return new Promise((resolve, reject) => {
|
|
2809
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
2810
|
+
this.dappClient.disconnect().catch(() => {
|
|
2811
|
+
});
|
|
2812
|
+
}
|
|
2813
|
+
this.dappClient.on(
|
|
2814
|
+
"session_request",
|
|
2815
|
+
(sessionRequest) => {
|
|
2816
|
+
const connectionRequest = {
|
|
2817
|
+
sessionRequest,
|
|
2818
|
+
metadata: {
|
|
2819
|
+
dapp: this.options.dapp,
|
|
2820
|
+
sdk: {
|
|
2821
|
+
version: getVersion(),
|
|
2822
|
+
platform: getPlatformType()
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
};
|
|
2826
|
+
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
2827
|
+
this.emit("display_uri", deeplink);
|
|
2828
|
+
}
|
|
2829
|
+
);
|
|
2830
|
+
this.transport.connect({ scopes, caipAccountIds, sessionProperties }).then(() => __async(this, null, function* () {
|
|
2831
|
+
this.status = "connected";
|
|
2832
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2833
|
+
resolve();
|
|
2834
|
+
})).catch((error) => __async(this, null, function* () {
|
|
2835
|
+
if (error instanceof import_mobile_wallet_protocol_core2.ProtocolError) {
|
|
2836
|
+
this.status = "disconnected";
|
|
2837
|
+
yield this.storage.removeTransport();
|
|
2838
|
+
reject(error);
|
|
2839
|
+
} else {
|
|
2840
|
+
this.status = "disconnected";
|
|
2841
|
+
yield this.storage.removeTransport();
|
|
2842
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2843
|
+
}
|
|
2844
|
+
}));
|
|
2845
|
+
});
|
|
2846
|
+
});
|
|
2847
|
+
};
|
|
2848
|
+
setupDefaultTransport_fn = function() {
|
|
2849
|
+
return __async(this, null, function* () {
|
|
2850
|
+
this.status = "connecting";
|
|
2851
|
+
yield this.storage.setTransport("browser" /* Browser */);
|
|
2852
|
+
const transport = new DefaultTransport();
|
|
2853
|
+
__privateSet(this, _listener, transport.onNotification(
|
|
2854
|
+
__privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
|
|
2855
|
+
));
|
|
2856
|
+
__privateSet(this, _transport2, transport);
|
|
2857
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2858
|
+
return transport;
|
|
2859
|
+
});
|
|
2860
|
+
};
|
|
2861
|
+
deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
2862
|
+
return __async(this, null, function* () {
|
|
2863
|
+
return new Promise((resolve, reject) => {
|
|
2864
|
+
const dappClientMessageHandler = (payload) => {
|
|
2865
|
+
var _a2;
|
|
2866
|
+
if (typeof payload !== "object" || payload === null || !("data" in payload)) {
|
|
2867
|
+
return;
|
|
2868
|
+
}
|
|
2869
|
+
const data = payload.data;
|
|
2870
|
+
if (typeof data === "object" && data !== null) {
|
|
2871
|
+
if (data.error) {
|
|
2872
|
+
this.dappClient.off("message", dappClientMessageHandler);
|
|
2873
|
+
reject(data.error);
|
|
2874
|
+
}
|
|
2875
|
+
if ((_a2 = data == null ? void 0 : data.result) == null ? void 0 : _a2.sessionScopes) {
|
|
2876
|
+
this.dappClient.off("message", dappClientMessageHandler);
|
|
2877
|
+
}
|
|
2878
|
+
}
|
|
2879
|
+
};
|
|
2880
|
+
this.dappClient.on("message", dappClientMessageHandler);
|
|
2881
|
+
let timeout;
|
|
2882
|
+
if (this.transport.isConnected()) {
|
|
2883
|
+
timeout = setTimeout(() => {
|
|
2884
|
+
this.openDeeplinkIfNeeded();
|
|
2885
|
+
}, 250);
|
|
2886
|
+
} else {
|
|
2887
|
+
this.dappClient.once(
|
|
2888
|
+
"session_request",
|
|
2889
|
+
(sessionRequest) => {
|
|
2890
|
+
var _a2;
|
|
2891
|
+
const connectionRequest = {
|
|
2892
|
+
sessionRequest,
|
|
2893
|
+
metadata: {
|
|
2894
|
+
dapp: this.options.dapp,
|
|
2895
|
+
sdk: { version: getVersion(), platform: getPlatformType() }
|
|
2896
|
+
}
|
|
2897
|
+
};
|
|
2898
|
+
const deeplink = this.options.ui.factory.createConnectionDeeplink(
|
|
2899
|
+
connectionRequest
|
|
2900
|
+
);
|
|
2901
|
+
const universalLink = this.options.ui.factory.createConnectionUniversalLink(
|
|
2902
|
+
connectionRequest
|
|
2903
|
+
);
|
|
2904
|
+
this.emit("display_uri", deeplink);
|
|
2905
|
+
if ((_a2 = this.options.mobile) == null ? void 0 : _a2.preferredOpenLink) {
|
|
2906
|
+
this.options.mobile.preferredOpenLink(deeplink, "_self");
|
|
2907
|
+
} else {
|
|
2908
|
+
openDeeplink(this.options, deeplink, universalLink);
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
);
|
|
2912
|
+
}
|
|
2913
|
+
return this.transport.connect({ scopes, caipAccountIds, sessionProperties }).then(resolve).catch((error) => __async(this, null, function* () {
|
|
2914
|
+
yield this.storage.removeTransport();
|
|
2915
|
+
this.dappClient.off("message", dappClientMessageHandler);
|
|
2916
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2917
|
+
})).finally(() => {
|
|
2918
|
+
if (timeout) {
|
|
2919
|
+
clearTimeout(timeout);
|
|
2920
|
+
}
|
|
2921
|
+
});
|
|
2922
|
+
});
|
|
2923
|
+
});
|
|
2924
|
+
};
|
|
2925
|
+
handleConnection_fn = function(promise, scopes, transportType) {
|
|
2926
|
+
return __async(this, null, function* () {
|
|
2927
|
+
this.status = "connecting";
|
|
2928
|
+
return promise.then(() => __async(this, null, function* () {
|
|
2929
|
+
this.status = "connected";
|
|
2930
|
+
try {
|
|
2931
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2932
|
+
this.options,
|
|
2933
|
+
this.storage
|
|
2934
|
+
);
|
|
2935
|
+
import_analytics4.analytics.track("mmconnect_connection_established", __spreadProps(__spreadValues({}, baseProps), {
|
|
2936
|
+
transport_type: transportType,
|
|
2937
|
+
user_permissioned_chains: scopes
|
|
2938
|
+
}));
|
|
2939
|
+
} catch (error) {
|
|
2940
|
+
logger2("Error tracking connection_established event", error);
|
|
2941
|
+
}
|
|
2942
|
+
return void 0;
|
|
2943
|
+
})).catch((error) => __async(this, null, function* () {
|
|
2944
|
+
this.status = "disconnected";
|
|
2945
|
+
try {
|
|
2946
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2947
|
+
this.options,
|
|
2948
|
+
this.storage
|
|
2949
|
+
);
|
|
2950
|
+
const isRejection = isRejectionError(error);
|
|
2951
|
+
if (isRejection) {
|
|
2952
|
+
import_analytics4.analytics.track("mmconnect_connection_rejected", __spreadProps(__spreadValues({}, baseProps), {
|
|
2953
|
+
transport_type: transportType
|
|
2954
|
+
}));
|
|
2955
|
+
} else {
|
|
2956
|
+
import_analytics4.analytics.track("mmconnect_connection_failed", __spreadProps(__spreadValues({}, baseProps), {
|
|
2957
|
+
transport_type: transportType
|
|
2958
|
+
}));
|
|
2959
|
+
}
|
|
2960
|
+
} catch (e) {
|
|
2961
|
+
logger2("Error tracking connection failed/rejected event", error);
|
|
2962
|
+
}
|
|
2963
|
+
throw error;
|
|
2964
|
+
}));
|
|
2965
|
+
});
|
|
2966
|
+
};
|
|
2967
|
+
var MultichainSDK = _MultichainSDK;
|
|
2729
2968
|
|
|
2730
2969
|
// src/store/index.ts
|
|
2731
2970
|
var uuid = __toESM(require("uuid"));
|
|
@@ -2906,41 +3145,11 @@ var Store = class extends StoreClient {
|
|
|
2906
3145
|
}
|
|
2907
3146
|
};
|
|
2908
3147
|
|
|
2909
|
-
// src/ui/
|
|
3148
|
+
// src/ui/ModalFactory.ts
|
|
2910
3149
|
var import_onboarding = __toESM(require("@metamask/onboarding"));
|
|
2911
3150
|
init_domain();
|
|
2912
|
-
init_qr();
|
|
2913
3151
|
init_utils();
|
|
2914
|
-
var
|
|
2915
|
-
function preload() {
|
|
2916
|
-
return __async(this, null, function* () {
|
|
2917
|
-
if (false) {
|
|
2918
|
-
__instance != null ? __instance : __instance = yield null.then((loader) => __async(null, null, function* () {
|
|
2919
|
-
if (typeof (loader == null ? void 0 : loader.defineCustomElements) === "function") {
|
|
2920
|
-
loader.defineCustomElements();
|
|
2921
|
-
}
|
|
2922
|
-
return Promise.resolve(loader);
|
|
2923
|
-
})).catch((error) => __async(null, null, function* () {
|
|
2924
|
-
console.error(`Gracefully Failed to load modal customElements:`, error);
|
|
2925
|
-
return Promise.resolve(void 0);
|
|
2926
|
-
}));
|
|
2927
|
-
} else {
|
|
2928
|
-
const dynamicImport = (0, eval)("import");
|
|
2929
|
-
__instance != null ? __instance : __instance = yield dynamicImport(
|
|
2930
|
-
"@metamask/multichain-ui/dist/loader/index.js"
|
|
2931
|
-
).then((loader) => __async(null, null, function* () {
|
|
2932
|
-
if (typeof (loader == null ? void 0 : loader.defineCustomElements) === "function") {
|
|
2933
|
-
loader.defineCustomElements();
|
|
2934
|
-
}
|
|
2935
|
-
return Promise.resolve(loader);
|
|
2936
|
-
})).catch((error) => __async(null, null, function* () {
|
|
2937
|
-
console.error(`Gracefully Failed to load modal customElements:`, error);
|
|
2938
|
-
return Promise.resolve(void 0);
|
|
2939
|
-
}));
|
|
2940
|
-
}
|
|
2941
|
-
});
|
|
2942
|
-
}
|
|
2943
|
-
var ModalFactory = class {
|
|
3152
|
+
var BaseModalFactory = class {
|
|
2944
3153
|
/**
|
|
2945
3154
|
* Creates a new modal factory instance.
|
|
2946
3155
|
*
|
|
@@ -2962,8 +3171,8 @@ var ModalFactory = class {
|
|
|
2962
3171
|
}
|
|
2963
3172
|
unload(error) {
|
|
2964
3173
|
return __async(this, null, function* () {
|
|
2965
|
-
var
|
|
2966
|
-
(
|
|
3174
|
+
var _a2, _b;
|
|
3175
|
+
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
2967
3176
|
yield (_b = this.successCallback) == null ? void 0 : _b.call(this, error);
|
|
2968
3177
|
});
|
|
2969
3178
|
}
|
|
@@ -3029,15 +3238,17 @@ var ModalFactory = class {
|
|
|
3029
3238
|
onStartDesktopOnboarding() {
|
|
3030
3239
|
new import_onboarding.default().startOnboarding();
|
|
3031
3240
|
}
|
|
3032
|
-
renderInstallModal(showInstallModal, createConnectionRequest, successCallback) {
|
|
3241
|
+
renderInstallModal(showInstallModal, createConnectionRequest, successCallback, onDisplayUri) {
|
|
3033
3242
|
return __async(this, null, function* () {
|
|
3034
|
-
var
|
|
3035
|
-
(
|
|
3036
|
-
yield
|
|
3243
|
+
var _a2, _b;
|
|
3244
|
+
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
3245
|
+
yield this.preload();
|
|
3037
3246
|
this.successCallback = successCallback;
|
|
3247
|
+
this.displayUriCallback = onDisplayUri;
|
|
3038
3248
|
const parentElement = this.getMountedContainer();
|
|
3039
3249
|
const connectionRequest = yield createConnectionRequest();
|
|
3040
3250
|
const qrCodeLink = this.createConnectionDeeplink(connectionRequest);
|
|
3251
|
+
(_b = this.displayUriCallback) == null ? void 0 : _b.call(this, qrCodeLink);
|
|
3041
3252
|
const modal = new this.options.InstallModal({
|
|
3042
3253
|
expiresIn: (connectionRequest.sessionRequest.expiresAt - Date.now()) / 1e3,
|
|
3043
3254
|
connectionRequest,
|
|
@@ -3046,11 +3257,15 @@ var ModalFactory = class {
|
|
|
3046
3257
|
link: qrCodeLink,
|
|
3047
3258
|
sdkVersion: getVersion(),
|
|
3048
3259
|
generateQRCode: (request) => __async(this, null, function* () {
|
|
3049
|
-
|
|
3260
|
+
var _a3;
|
|
3261
|
+
const newLink = this.createConnectionDeeplink(request);
|
|
3262
|
+
(_a3 = this.displayUriCallback) == null ? void 0 : _a3.call(this, newLink);
|
|
3263
|
+
return newLink;
|
|
3050
3264
|
}),
|
|
3051
3265
|
onClose: this.onCloseModal.bind(this),
|
|
3052
3266
|
startDesktopOnboarding: this.onStartDesktopOnboarding.bind(this),
|
|
3053
|
-
createConnectionRequest
|
|
3267
|
+
createConnectionRequest,
|
|
3268
|
+
onDisplayUri: this.displayUriCallback
|
|
3054
3269
|
});
|
|
3055
3270
|
this.modal = modal;
|
|
3056
3271
|
modal.mount();
|
|
@@ -3058,9 +3273,9 @@ var ModalFactory = class {
|
|
|
3058
3273
|
}
|
|
3059
3274
|
renderOTPCodeModal(createOTPCode, successCallback, updateOTPCode) {
|
|
3060
3275
|
return __async(this, null, function* () {
|
|
3061
|
-
var
|
|
3062
|
-
(
|
|
3063
|
-
yield
|
|
3276
|
+
var _a2;
|
|
3277
|
+
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
3278
|
+
yield this.preload();
|
|
3064
3279
|
this.successCallback = successCallback;
|
|
3065
3280
|
const container = this.getMountedContainer();
|
|
3066
3281
|
const otpCode = yield createOTPCode();
|
|
@@ -3078,9 +3293,31 @@ var ModalFactory = class {
|
|
|
3078
3293
|
}
|
|
3079
3294
|
};
|
|
3080
3295
|
|
|
3296
|
+
// src/ui/index.ts
|
|
3297
|
+
function preload() {
|
|
3298
|
+
return __async(this, null, function* () {
|
|
3299
|
+
if (typeof document === "undefined") {
|
|
3300
|
+
return;
|
|
3301
|
+
}
|
|
3302
|
+
try {
|
|
3303
|
+
const { defineCustomElements } = yield import("@metamask/multichain-ui/loader");
|
|
3304
|
+
yield defineCustomElements();
|
|
3305
|
+
} catch (error) {
|
|
3306
|
+
console.error("Failed to load customElements:", error);
|
|
3307
|
+
}
|
|
3308
|
+
});
|
|
3309
|
+
}
|
|
3310
|
+
var ModalFactory = class extends BaseModalFactory {
|
|
3311
|
+
preload() {
|
|
3312
|
+
return __async(this, null, function* () {
|
|
3313
|
+
return preload();
|
|
3314
|
+
});
|
|
3315
|
+
}
|
|
3316
|
+
};
|
|
3317
|
+
|
|
3081
3318
|
// src/index.node.ts
|
|
3082
3319
|
init_domain();
|
|
3083
|
-
var
|
|
3320
|
+
var createMultichainClient = (options) => __async(null, null, function* () {
|
|
3084
3321
|
const uiModules = yield Promise.resolve().then(() => (init_node(), node_exports));
|
|
3085
3322
|
let storage;
|
|
3086
3323
|
if (!options.storage) {
|
|
@@ -3114,7 +3351,7 @@ var createMetamaskConnect = (options) => __async(null, null, function* () {
|
|
|
3114
3351
|
StoreClient,
|
|
3115
3352
|
TransportType,
|
|
3116
3353
|
createLogger,
|
|
3117
|
-
|
|
3354
|
+
createMultichainClient,
|
|
3118
3355
|
enableDebug,
|
|
3119
3356
|
getInfuraRpcUrls,
|
|
3120
3357
|
getPlatformType,
|