@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,
|
|
@@ -973,11 +973,6 @@ var init_AbstractInstallModal = __esm({
|
|
|
973
973
|
`[UI: InstallModal-nodejs()] \u274C Error generating new QR code: ${error}`
|
|
974
974
|
);
|
|
975
975
|
}
|
|
976
|
-
} else {
|
|
977
|
-
const generateQRCode = yield this.options.generateQRCode(
|
|
978
|
-
currentConnectionRequest
|
|
979
|
-
);
|
|
980
|
-
this.renderQRCode(generateQRCode, currentConnectionRequest);
|
|
981
976
|
}
|
|
982
977
|
}), 1e3);
|
|
983
978
|
}
|
|
@@ -1004,7 +999,7 @@ var init_install = __esm({
|
|
|
1004
999
|
renderQRCode() {
|
|
1005
1000
|
}
|
|
1006
1001
|
mount() {
|
|
1007
|
-
var
|
|
1002
|
+
var _a2;
|
|
1008
1003
|
const { options } = this;
|
|
1009
1004
|
const modal = document.createElement(
|
|
1010
1005
|
"mm-install-modal"
|
|
@@ -1021,14 +1016,14 @@ var init_install = __esm({
|
|
|
1021
1016
|
);
|
|
1022
1017
|
modal.link = options.link;
|
|
1023
1018
|
this.instance = modal;
|
|
1024
|
-
(
|
|
1019
|
+
(_a2 = options.parentElement) == null ? void 0 : _a2.appendChild(modal);
|
|
1025
1020
|
this.startExpirationCheck(options.connectionRequest);
|
|
1026
1021
|
}
|
|
1027
1022
|
unmount() {
|
|
1028
|
-
var
|
|
1023
|
+
var _a2;
|
|
1029
1024
|
const { options, instance: modal } = this;
|
|
1030
1025
|
this.stopExpirationCheck();
|
|
1031
|
-
if (modal && ((
|
|
1026
|
+
if (modal && ((_a2 = options.parentElement) == null ? void 0 : _a2.contains(modal))) {
|
|
1032
1027
|
options.parentElement.removeChild(modal);
|
|
1033
1028
|
this.instance = void 0;
|
|
1034
1029
|
}
|
|
@@ -1140,8 +1135,8 @@ var init_web2 = __esm({
|
|
|
1140
1135
|
const request = store.get(key);
|
|
1141
1136
|
request.onerror = () => reject(new Error("Failed to get value from IndexedDB."));
|
|
1142
1137
|
request.onsuccess = () => {
|
|
1143
|
-
var
|
|
1144
|
-
return resolve((
|
|
1138
|
+
var _a2;
|
|
1139
|
+
return resolve((_a2 = request.result) != null ? _a2 : null);
|
|
1145
1140
|
};
|
|
1146
1141
|
} catch (error) {
|
|
1147
1142
|
reject(error);
|
|
@@ -1207,7 +1202,7 @@ __export(index_browser_exports, {
|
|
|
1207
1202
|
StoreClient: () => StoreClient,
|
|
1208
1203
|
TransportType: () => TransportType,
|
|
1209
1204
|
createLogger: () => createLogger,
|
|
1210
|
-
|
|
1205
|
+
createMultichainClient: () => createMultichainClient,
|
|
1211
1206
|
enableDebug: () => enableDebug,
|
|
1212
1207
|
getInfuraRpcUrls: () => getInfuraRpcUrls,
|
|
1213
1208
|
getPlatformType: () => getPlatformType,
|
|
@@ -1276,8 +1271,8 @@ var RpcClient = class {
|
|
|
1276
1271
|
});
|
|
1277
1272
|
}
|
|
1278
1273
|
getRpcEndpoint(scope) {
|
|
1279
|
-
var
|
|
1280
|
-
const supportedNetworks = (_c = (_b = (
|
|
1274
|
+
var _a2, _b, _c;
|
|
1275
|
+
const supportedNetworks = (_c = (_b = (_a2 = this.config) == null ? void 0 : _a2.api) == null ? void 0 : _b.supportedNetworks) != null ? _c : {};
|
|
1281
1276
|
const rpcEndpoint = supportedNetworks[scope];
|
|
1282
1277
|
if (!rpcEndpoint) {
|
|
1283
1278
|
throw new MissingRpcEndpointErr(`No RPC endpoint found for scope ${scope}`);
|
|
@@ -1432,24 +1427,17 @@ var RequestRouter = class {
|
|
|
1432
1427
|
_RequestRouter_instances = new WeakSet();
|
|
1433
1428
|
withAnalyticsTracking_fn = function(options, execute) {
|
|
1434
1429
|
return __async(this, null, function* () {
|
|
1435
|
-
|
|
1436
|
-
if ((_a = this.config.analytics) == null ? void 0 : _a.enabled) {
|
|
1437
|
-
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRequested_fn).call(this, options);
|
|
1438
|
-
}
|
|
1430
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRequested_fn).call(this, options);
|
|
1439
1431
|
try {
|
|
1440
1432
|
const result = yield execute();
|
|
1441
|
-
|
|
1442
|
-
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionSucceeded_fn).call(this, options);
|
|
1443
|
-
}
|
|
1433
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionSucceeded_fn).call(this, options);
|
|
1444
1434
|
return result;
|
|
1445
1435
|
} catch (error) {
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options);
|
|
1452
|
-
}
|
|
1436
|
+
const isRejection = isRejectionError(error);
|
|
1437
|
+
if (isRejection) {
|
|
1438
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRejected_fn).call(this, options);
|
|
1439
|
+
} else {
|
|
1440
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options);
|
|
1453
1441
|
}
|
|
1454
1442
|
throw new RPCInvokeMethodErr(error.message);
|
|
1455
1443
|
}
|
|
@@ -1509,11 +1497,11 @@ var DefaultTransport = class {
|
|
|
1509
1497
|
id: requestId
|
|
1510
1498
|
}, payload);
|
|
1511
1499
|
return new Promise((resolve, reject) => {
|
|
1512
|
-
var
|
|
1500
|
+
var _a2;
|
|
1513
1501
|
const timeout = setTimeout(() => {
|
|
1514
1502
|
__privateGet(this, _pendingRequests).delete(requestId);
|
|
1515
1503
|
reject(new Error("Request timeout"));
|
|
1516
|
-
}, (
|
|
1504
|
+
}, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : __privateGet(this, _defaultRequestOptions).timeout);
|
|
1517
1505
|
__privateGet(this, _pendingRequests).set(requestId, {
|
|
1518
1506
|
resolve: (response) => {
|
|
1519
1507
|
resolve(response);
|
|
@@ -1537,7 +1525,7 @@ var DefaultTransport = class {
|
|
|
1537
1525
|
}
|
|
1538
1526
|
connect(options) {
|
|
1539
1527
|
return __async(this, null, function* () {
|
|
1540
|
-
var
|
|
1528
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1541
1529
|
__privateMethod(this, _DefaultTransport_instances, setupMessageListener_fn).call(this);
|
|
1542
1530
|
yield __privateGet(this, _transport).connect();
|
|
1543
1531
|
const sessionRequest = yield this.request(
|
|
@@ -1550,7 +1538,7 @@ var DefaultTransport = class {
|
|
|
1550
1538
|
let walletSession = sessionRequest.result;
|
|
1551
1539
|
if (walletSession && options && !options.forceRequest) {
|
|
1552
1540
|
const currentScopes = Object.keys(
|
|
1553
|
-
(
|
|
1541
|
+
(_a2 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a2 : {}
|
|
1554
1542
|
);
|
|
1555
1543
|
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
1556
1544
|
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
@@ -1587,7 +1575,8 @@ var DefaultTransport = class {
|
|
|
1587
1575
|
getValidAccounts((_g = options == null ? void 0 : options.caipAccountIds) != null ? _g : [])
|
|
1588
1576
|
);
|
|
1589
1577
|
const createSessionParams = {
|
|
1590
|
-
optionalScopes
|
|
1578
|
+
optionalScopes,
|
|
1579
|
+
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
1591
1580
|
};
|
|
1592
1581
|
const response = yield this.request(
|
|
1593
1582
|
{ method: "wallet_createSession", params: createSessionParams },
|
|
@@ -1664,16 +1653,16 @@ notifyCallbacks_fn = function(data) {
|
|
|
1664
1653
|
}
|
|
1665
1654
|
};
|
|
1666
1655
|
isMetamaskProviderEvent_fn = function(event) {
|
|
1667
|
-
var
|
|
1668
|
-
return ((_b = (
|
|
1656
|
+
var _a2, _b;
|
|
1657
|
+
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
|
|
1669
1658
|
event.origin === location.origin;
|
|
1670
1659
|
};
|
|
1671
1660
|
handleResponse_fn = function(event) {
|
|
1672
|
-
var
|
|
1661
|
+
var _a2, _b;
|
|
1673
1662
|
if (!__privateMethod(this, _DefaultTransport_instances, isMetamaskProviderEvent_fn).call(this, event)) {
|
|
1674
1663
|
return;
|
|
1675
1664
|
}
|
|
1676
|
-
const responseData = (_b = (
|
|
1665
|
+
const responseData = (_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.data;
|
|
1677
1666
|
if (typeof responseData === "object" && responseData !== null && "method" in responseData) {
|
|
1678
1667
|
return;
|
|
1679
1668
|
}
|
|
@@ -1695,11 +1684,11 @@ handleResponse_fn = function(event) {
|
|
|
1695
1684
|
}
|
|
1696
1685
|
};
|
|
1697
1686
|
handleNotification_fn = function(event) {
|
|
1698
|
-
var
|
|
1687
|
+
var _a2, _b;
|
|
1699
1688
|
if (!__privateMethod(this, _DefaultTransport_instances, isMetamaskProviderEvent_fn).call(this, event)) {
|
|
1700
1689
|
return;
|
|
1701
1690
|
}
|
|
1702
|
-
const responseData = (_b = (
|
|
1691
|
+
const responseData = (_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.data;
|
|
1703
1692
|
if (typeof responseData === "object" && responseData.method === "metamask_chainChanged" || responseData.method === "metamask_accountsChanged") {
|
|
1704
1693
|
__privateMethod(this, _DefaultTransport_instances, notifyCallbacks_fn).call(this, responseData);
|
|
1705
1694
|
}
|
|
@@ -1727,6 +1716,7 @@ var MULTICHAIN_PROVIDER_STREAM_NAME = "metamask-multichain-provider";
|
|
|
1727
1716
|
var DEFAULT_REQUEST_TIMEOUT2 = 60 * 1e3;
|
|
1728
1717
|
var CONNECTION_GRACE_PERIOD = 60 * 1e3;
|
|
1729
1718
|
var DEFAULT_CONNECTION_TIMEOUT = DEFAULT_REQUEST_TIMEOUT2 + CONNECTION_GRACE_PERIOD;
|
|
1719
|
+
var DEFAULT_RESUME_TIMEOUT = 10 * 1e3;
|
|
1730
1720
|
var SESSION_STORE_KEY = "cache_wallet_getSession";
|
|
1731
1721
|
var ACCOUNTS_STORE_KEY = "cache_eth_accounts";
|
|
1732
1722
|
var CHAIN_STORE_KEY = "cache_eth_chainId";
|
|
@@ -1743,7 +1733,8 @@ var logger = createLogger("metamask-sdk:transport");
|
|
|
1743
1733
|
var MWPTransport = class {
|
|
1744
1734
|
constructor(dappClient, kvstore, options = {
|
|
1745
1735
|
requestTimeout: DEFAULT_REQUEST_TIMEOUT2,
|
|
1746
|
-
connectionTimeout: DEFAULT_CONNECTION_TIMEOUT
|
|
1736
|
+
connectionTimeout: DEFAULT_CONNECTION_TIMEOUT,
|
|
1737
|
+
resumeTimeout: DEFAULT_RESUME_TIMEOUT
|
|
1747
1738
|
}) {
|
|
1748
1739
|
this.dappClient = dappClient;
|
|
1749
1740
|
this.kvstore = kvstore;
|
|
@@ -1818,6 +1809,13 @@ var MWPTransport = class {
|
|
|
1818
1809
|
)
|
|
1819
1810
|
);
|
|
1820
1811
|
}
|
|
1812
|
+
if (message.data.method === "wallet_sessionChanged") {
|
|
1813
|
+
const notification = message.data;
|
|
1814
|
+
const response = {
|
|
1815
|
+
result: notification.params
|
|
1816
|
+
};
|
|
1817
|
+
this.kvstore.set(SESSION_STORE_KEY, JSON.stringify(response));
|
|
1818
|
+
}
|
|
1821
1819
|
this.notifyCallbacks(message.data);
|
|
1822
1820
|
}
|
|
1823
1821
|
}
|
|
@@ -1825,8 +1823,9 @@ var MWPTransport = class {
|
|
|
1825
1823
|
}
|
|
1826
1824
|
onResumeSuccess(resumeResolve, resumeReject, options) {
|
|
1827
1825
|
return __async(this, null, function* () {
|
|
1828
|
-
var
|
|
1826
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1829
1827
|
try {
|
|
1828
|
+
yield this.waitForWalletSessionIfNotCached();
|
|
1830
1829
|
const sessionRequest = yield this.request({
|
|
1831
1830
|
method: "wallet_getSession"
|
|
1832
1831
|
});
|
|
@@ -1836,7 +1835,7 @@ var MWPTransport = class {
|
|
|
1836
1835
|
let walletSession = sessionRequest.result;
|
|
1837
1836
|
if (walletSession && options) {
|
|
1838
1837
|
const currentScopes = Object.keys(
|
|
1839
|
-
(
|
|
1838
|
+
(_a2 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a2 : {}
|
|
1840
1839
|
);
|
|
1841
1840
|
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
1842
1841
|
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
@@ -1901,10 +1900,10 @@ var MWPTransport = class {
|
|
|
1901
1900
|
return cachedWalletSession;
|
|
1902
1901
|
}
|
|
1903
1902
|
return new Promise((resolve, reject) => {
|
|
1904
|
-
var
|
|
1903
|
+
var _a2;
|
|
1905
1904
|
const timeout = setTimeout(() => {
|
|
1906
1905
|
this.rejectRequest(request.id, new import_multichain_api_client2.TransportTimeoutError());
|
|
1907
|
-
}, (
|
|
1906
|
+
}, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : this.options.requestTimeout);
|
|
1908
1907
|
this.pendingRequests.set(request.id, {
|
|
1909
1908
|
request,
|
|
1910
1909
|
method: request.method,
|
|
@@ -1930,30 +1929,32 @@ var MWPTransport = class {
|
|
|
1930
1929
|
logger("active session found", session);
|
|
1931
1930
|
}
|
|
1932
1931
|
let timeout;
|
|
1933
|
-
|
|
1932
|
+
let initialConnectionMessageHandler;
|
|
1933
|
+
const connectionPromise = new Promise((resolve, reject) => __async(this, null, function* () {
|
|
1934
1934
|
let connection;
|
|
1935
1935
|
if (session) {
|
|
1936
1936
|
connection = new Promise((resumeResolve, resumeReject) => {
|
|
1937
|
-
var
|
|
1937
|
+
var _a2;
|
|
1938
1938
|
if (this.dappClient.state === "CONNECTED") {
|
|
1939
1939
|
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
1940
1940
|
} else {
|
|
1941
1941
|
this.dappClient.once("connected", () => __async(this, null, function* () {
|
|
1942
1942
|
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
1943
1943
|
}));
|
|
1944
|
-
dappClient.resume((
|
|
1944
|
+
dappClient.resume((_a2 = session == null ? void 0 : session.id) != null ? _a2 : "");
|
|
1945
1945
|
}
|
|
1946
1946
|
});
|
|
1947
1947
|
} else {
|
|
1948
1948
|
connection = new Promise(
|
|
1949
1949
|
(resolveConnection, rejectConnection) => {
|
|
1950
|
-
var
|
|
1950
|
+
var _a2, _b;
|
|
1951
1951
|
const optionalScopes = addValidAccounts(
|
|
1952
|
-
getOptionalScopes((
|
|
1952
|
+
getOptionalScopes((_a2 = options == null ? void 0 : options.scopes) != null ? _a2 : []),
|
|
1953
1953
|
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
1954
1954
|
);
|
|
1955
1955
|
const sessionRequest = {
|
|
1956
|
-
optionalScopes
|
|
1956
|
+
optionalScopes,
|
|
1957
|
+
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
1957
1958
|
};
|
|
1958
1959
|
const request = {
|
|
1959
1960
|
jsonrpc: "2.0",
|
|
@@ -1961,12 +1962,18 @@ var MWPTransport = class {
|
|
|
1961
1962
|
method: "wallet_createSession",
|
|
1962
1963
|
params: sessionRequest
|
|
1963
1964
|
};
|
|
1964
|
-
|
|
1965
|
+
initialConnectionMessageHandler = (message) => __async(this, null, function* () {
|
|
1965
1966
|
if (typeof message === "object" && message !== null) {
|
|
1966
1967
|
if ("data" in message) {
|
|
1967
1968
|
const messagePayload = message.data;
|
|
1968
1969
|
if (messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged") {
|
|
1969
1970
|
if (messagePayload.error) {
|
|
1971
|
+
if (initialConnectionMessageHandler) {
|
|
1972
|
+
this.dappClient.off(
|
|
1973
|
+
"message",
|
|
1974
|
+
initialConnectionMessageHandler
|
|
1975
|
+
);
|
|
1976
|
+
}
|
|
1970
1977
|
return rejectConnection(messagePayload.error);
|
|
1971
1978
|
}
|
|
1972
1979
|
yield this.storeWalletSession(
|
|
@@ -1978,14 +1985,23 @@ var MWPTransport = class {
|
|
|
1978
1985
|
}
|
|
1979
1986
|
}
|
|
1980
1987
|
}
|
|
1981
|
-
})
|
|
1988
|
+
});
|
|
1989
|
+
this.dappClient.on("message", initialConnectionMessageHandler);
|
|
1982
1990
|
dappClient.connect({
|
|
1983
1991
|
mode: "trusted",
|
|
1984
1992
|
initialPayload: {
|
|
1985
1993
|
name: MULTICHAIN_PROVIDER_STREAM_NAME,
|
|
1986
1994
|
data: request
|
|
1987
1995
|
}
|
|
1988
|
-
}).catch(
|
|
1996
|
+
}).catch((error) => {
|
|
1997
|
+
if (initialConnectionMessageHandler) {
|
|
1998
|
+
this.dappClient.off(
|
|
1999
|
+
"message",
|
|
2000
|
+
initialConnectionMessageHandler
|
|
2001
|
+
);
|
|
2002
|
+
}
|
|
2003
|
+
rejectConnection(error);
|
|
2004
|
+
});
|
|
1989
2005
|
}
|
|
1990
2006
|
);
|
|
1991
2007
|
}
|
|
@@ -1993,11 +2009,17 @@ var MWPTransport = class {
|
|
|
1993
2009
|
reject(new import_multichain_api_client2.TransportTimeoutError());
|
|
1994
2010
|
}, this.options.connectionTimeout);
|
|
1995
2011
|
connection.then(resolve).catch(reject);
|
|
1996
|
-
});
|
|
1997
|
-
return connectionPromise.
|
|
2012
|
+
}));
|
|
2013
|
+
return connectionPromise.catch((error) => {
|
|
2014
|
+
throw error;
|
|
2015
|
+
}).finally(() => {
|
|
1998
2016
|
if (timeout) {
|
|
1999
2017
|
clearTimeout(timeout);
|
|
2000
2018
|
}
|
|
2019
|
+
if (initialConnectionMessageHandler) {
|
|
2020
|
+
this.dappClient.off("message", initialConnectionMessageHandler);
|
|
2021
|
+
initialConnectionMessageHandler = void 0;
|
|
2022
|
+
}
|
|
2001
2023
|
});
|
|
2002
2024
|
});
|
|
2003
2025
|
}
|
|
@@ -2060,7 +2082,7 @@ var MWPTransport = class {
|
|
|
2060
2082
|
}
|
|
2061
2083
|
getCachedResponse(request) {
|
|
2062
2084
|
return __async(this, null, function* () {
|
|
2063
|
-
var
|
|
2085
|
+
var _a2;
|
|
2064
2086
|
if (request.method === "wallet_getSession") {
|
|
2065
2087
|
const walletGetSession = yield this.kvstore.get(SESSION_STORE_KEY);
|
|
2066
2088
|
if (walletGetSession) {
|
|
@@ -2068,7 +2090,7 @@ var MWPTransport = class {
|
|
|
2068
2090
|
return {
|
|
2069
2091
|
id: request.id,
|
|
2070
2092
|
jsonrpc: "2.0",
|
|
2071
|
-
result: (
|
|
2093
|
+
result: (_a2 = walletSession.params) != null ? _a2 : walletSession.result,
|
|
2072
2094
|
// "what?... why walletSession.params?.."
|
|
2073
2095
|
method: request.method
|
|
2074
2096
|
};
|
|
@@ -2132,10 +2154,10 @@ var MWPTransport = class {
|
|
|
2132
2154
|
yield this.attemptResumeSession();
|
|
2133
2155
|
}
|
|
2134
2156
|
return new Promise((resolve, reject) => {
|
|
2135
|
-
var
|
|
2157
|
+
var _a2;
|
|
2136
2158
|
const timeout = setTimeout(() => {
|
|
2137
2159
|
this.rejectRequest(request.id, new import_multichain_api_client2.TransportTimeoutError());
|
|
2138
|
-
}, (
|
|
2160
|
+
}, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : this.options.requestTimeout);
|
|
2139
2161
|
this.pendingRequests.set(request.id, {
|
|
2140
2162
|
request,
|
|
2141
2163
|
method: request.method,
|
|
@@ -2172,6 +2194,43 @@ var MWPTransport = class {
|
|
|
2172
2194
|
}
|
|
2173
2195
|
});
|
|
2174
2196
|
}
|
|
2197
|
+
// This method checks if an existing CAIP session response is cached or waits for one
|
|
2198
|
+
// to be received from the wallet if not cached. This is necessary because there is an edge
|
|
2199
|
+
// case during the initial connection flow where after the user has accepted the permission approval
|
|
2200
|
+
// and returned back to the dapp from the wallet, the dapp page may have gotten unloaded and refreshed.
|
|
2201
|
+
// When it is unloaded and refreshed, it will try to resume the session by making a request for wallet_getSession
|
|
2202
|
+
// which should resolve from cache, but because a race condition makes it possible for the response from the wallet
|
|
2203
|
+
// for the initial wallet_createSession connection request to not have been handled and cached yet. This results
|
|
2204
|
+
// in the wallet_getSession request never resolving unless we wait for it explicitly as done in this method.
|
|
2205
|
+
waitForWalletSessionIfNotCached() {
|
|
2206
|
+
return __async(this, null, function* () {
|
|
2207
|
+
const cachedWalletGetSessionResponse = yield this.kvstore.get(SESSION_STORE_KEY);
|
|
2208
|
+
if (cachedWalletGetSessionResponse) {
|
|
2209
|
+
return;
|
|
2210
|
+
}
|
|
2211
|
+
let unsubscribe;
|
|
2212
|
+
const responsePromise = new Promise((resolve) => {
|
|
2213
|
+
unsubscribe = this.onNotification((message) => {
|
|
2214
|
+
if (typeof message === "object" && message !== null) {
|
|
2215
|
+
if ("data" in message) {
|
|
2216
|
+
const messagePayload = message.data;
|
|
2217
|
+
if (messagePayload.method === "wallet_getSession" || messagePayload.method === "wallet_sessionChanged") {
|
|
2218
|
+
unsubscribe();
|
|
2219
|
+
resolve();
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
});
|
|
2224
|
+
});
|
|
2225
|
+
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
2226
|
+
setTimeout(() => {
|
|
2227
|
+
unsubscribe();
|
|
2228
|
+
reject(new import_multichain_api_client2.TransportTimeoutError());
|
|
2229
|
+
}, this.options.resumeTimeout);
|
|
2230
|
+
});
|
|
2231
|
+
return Promise.race([responsePromise, timeoutPromise]);
|
|
2232
|
+
});
|
|
2233
|
+
}
|
|
2175
2234
|
};
|
|
2176
2235
|
|
|
2177
2236
|
// src/multichain/transports/mwp/KeyManager.ts
|
|
@@ -2203,74 +2262,229 @@ var keymanager = new KeyManager();
|
|
|
2203
2262
|
|
|
2204
2263
|
// src/multichain/index.ts
|
|
2205
2264
|
init_utils();
|
|
2265
|
+
|
|
2266
|
+
// src/multichain/transports/multichainApiClientWrapper/index.ts
|
|
2267
|
+
var import_rpc_errors = require("@metamask/rpc-errors");
|
|
2268
|
+
var MAX = 4294967295;
|
|
2269
|
+
var idCounter = Math.floor(Math.random() * MAX);
|
|
2270
|
+
var getUniqueId = () => {
|
|
2271
|
+
idCounter = (idCounter + 1) % MAX;
|
|
2272
|
+
return idCounter;
|
|
2273
|
+
};
|
|
2274
|
+
var _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
2275
|
+
var MultichainApiClientWrapperTransport = class {
|
|
2276
|
+
constructor(multichainSDK) {
|
|
2277
|
+
this.multichainSDK = multichainSDK;
|
|
2278
|
+
__privateAdd(this, _MultichainApiClientWrapperTransport_instances);
|
|
2279
|
+
this.requestId = getUniqueId();
|
|
2280
|
+
this.notificationCallbacks = /* @__PURE__ */ new Set();
|
|
2281
|
+
}
|
|
2282
|
+
isTransportDefined() {
|
|
2283
|
+
try {
|
|
2284
|
+
return Boolean(this.multichainSDK.transport);
|
|
2285
|
+
} catch (error) {
|
|
2286
|
+
return false;
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
clearNotificationCallbacks() {
|
|
2290
|
+
this.notificationCallbacks.clear();
|
|
2291
|
+
}
|
|
2292
|
+
notifyCallbacks(data) {
|
|
2293
|
+
this.notificationCallbacks.forEach((callback) => {
|
|
2294
|
+
callback(data);
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
setupNotifcationListener() {
|
|
2298
|
+
this.multichainSDK.transport.onNotification(
|
|
2299
|
+
this.notifyCallbacks.bind(this)
|
|
2300
|
+
);
|
|
2301
|
+
}
|
|
2302
|
+
connect() {
|
|
2303
|
+
return __async(this, null, function* () {
|
|
2304
|
+
console.log("\u{1F4DA} connect");
|
|
2305
|
+
return Promise.resolve();
|
|
2306
|
+
});
|
|
2307
|
+
}
|
|
2308
|
+
disconnect() {
|
|
2309
|
+
return __async(this, null, function* () {
|
|
2310
|
+
return Promise.resolve();
|
|
2311
|
+
});
|
|
2312
|
+
}
|
|
2313
|
+
isConnected() {
|
|
2314
|
+
return true;
|
|
2315
|
+
}
|
|
2316
|
+
request(_0) {
|
|
2317
|
+
return __async(this, arguments, function* (params, _options = {}) {
|
|
2318
|
+
const id = this.requestId++;
|
|
2319
|
+
const requestPayload = __spreadValues({
|
|
2320
|
+
id,
|
|
2321
|
+
jsonrpc: "2.0"
|
|
2322
|
+
}, params);
|
|
2323
|
+
switch (requestPayload.method) {
|
|
2324
|
+
case "wallet_createSession":
|
|
2325
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn).call(this, requestPayload);
|
|
2326
|
+
case "wallet_getSession":
|
|
2327
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletGetSession_fn).call(this, requestPayload);
|
|
2328
|
+
case "wallet_revokeSession":
|
|
2329
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletRevokeSession_fn).call(this, requestPayload);
|
|
2330
|
+
case "wallet_invokeMethod":
|
|
2331
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletInvokeMethod_fn).call(this, requestPayload);
|
|
2332
|
+
default:
|
|
2333
|
+
throw new Error(`Unsupported method: ${requestPayload.method}`);
|
|
2334
|
+
}
|
|
2335
|
+
throw new Error(`Unknown method: ${requestPayload.method}`);
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
onNotification(callback) {
|
|
2339
|
+
if (!this.isTransportDefined()) {
|
|
2340
|
+
this.notificationCallbacks.add(callback);
|
|
2341
|
+
return () => {
|
|
2342
|
+
this.notificationCallbacks.delete(callback);
|
|
2343
|
+
};
|
|
2344
|
+
}
|
|
2345
|
+
return this.multichainSDK.transport.onNotification(callback);
|
|
2346
|
+
}
|
|
2347
|
+
};
|
|
2348
|
+
_MultichainApiClientWrapperTransport_instances = new WeakSet();
|
|
2349
|
+
walletCreateSession_fn = function(request) {
|
|
2350
|
+
return __async(this, null, function* () {
|
|
2351
|
+
console.log("\u{1F4DA} #walletCreateSession", request);
|
|
2352
|
+
const createSessionParams = request.params;
|
|
2353
|
+
const scopes = Object.keys(__spreadValues(__spreadValues({}, createSessionParams.optionalScopes), createSessionParams.requiredScopes));
|
|
2354
|
+
const scopeAccounts = [];
|
|
2355
|
+
scopes.forEach((scope) => {
|
|
2356
|
+
var _a2, _b, _c, _d;
|
|
2357
|
+
const requiredScope = (_a2 = createSessionParams.requiredScopes) == null ? void 0 : _a2[scope];
|
|
2358
|
+
const optionalScope = (_b = createSessionParams.optionalScopes) == null ? void 0 : _b[scope];
|
|
2359
|
+
if (requiredScope) {
|
|
2360
|
+
scopeAccounts.push(...(_c = requiredScope.accounts) != null ? _c : []);
|
|
2361
|
+
}
|
|
2362
|
+
if (optionalScope) {
|
|
2363
|
+
scopeAccounts.push(...(_d = optionalScope.accounts) != null ? _d : []);
|
|
2364
|
+
}
|
|
2365
|
+
});
|
|
2366
|
+
const accounts = [...new Set(scopeAccounts)];
|
|
2367
|
+
console.log("\u{1F4DA} SDK connect");
|
|
2368
|
+
yield this.multichainSDK.connect(
|
|
2369
|
+
scopes,
|
|
2370
|
+
accounts,
|
|
2371
|
+
createSessionParams.sessionProperties
|
|
2372
|
+
);
|
|
2373
|
+
console.log("\u{1F4DA} SDK connected");
|
|
2374
|
+
return this.multichainSDK.transport.request({
|
|
2375
|
+
method: "wallet_getSession"
|
|
2376
|
+
});
|
|
2377
|
+
});
|
|
2378
|
+
};
|
|
2379
|
+
walletGetSession_fn = function(request) {
|
|
2380
|
+
return __async(this, null, function* () {
|
|
2381
|
+
if (!this.isTransportDefined()) {
|
|
2382
|
+
return {
|
|
2383
|
+
jsonrpc: "2.0",
|
|
2384
|
+
id: request.id,
|
|
2385
|
+
result: {
|
|
2386
|
+
sessionScopes: {}
|
|
2387
|
+
}
|
|
2388
|
+
};
|
|
2389
|
+
}
|
|
2390
|
+
return this.multichainSDK.transport.request({
|
|
2391
|
+
method: "wallet_getSession"
|
|
2392
|
+
});
|
|
2393
|
+
});
|
|
2394
|
+
};
|
|
2395
|
+
walletRevokeSession_fn = function(request) {
|
|
2396
|
+
return __async(this, null, function* () {
|
|
2397
|
+
if (!this.isTransportDefined()) {
|
|
2398
|
+
return { jsonrpc: "2.0", id: request.id, result: true };
|
|
2399
|
+
}
|
|
2400
|
+
try {
|
|
2401
|
+
this.multichainSDK.disconnect();
|
|
2402
|
+
return { jsonrpc: "2.0", id: request.id, result: true };
|
|
2403
|
+
} catch (error) {
|
|
2404
|
+
return { jsonrpc: "2.0", id: request.id, result: false };
|
|
2405
|
+
}
|
|
2406
|
+
});
|
|
2407
|
+
};
|
|
2408
|
+
walletInvokeMethod_fn = function(request) {
|
|
2409
|
+
return __async(this, null, function* () {
|
|
2410
|
+
if (!this.isTransportDefined()) {
|
|
2411
|
+
return { error: import_rpc_errors.providerErrors.unauthorized() };
|
|
2412
|
+
}
|
|
2413
|
+
const result = this.multichainSDK.invokeMethod(
|
|
2414
|
+
request.params
|
|
2415
|
+
);
|
|
2416
|
+
return {
|
|
2417
|
+
result
|
|
2418
|
+
};
|
|
2419
|
+
});
|
|
2420
|
+
};
|
|
2421
|
+
|
|
2422
|
+
// src/multichain/index.ts
|
|
2206
2423
|
var logger2 = createLogger("metamask-sdk:core");
|
|
2207
|
-
var
|
|
2424
|
+
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;
|
|
2425
|
+
var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
2208
2426
|
constructor(options) {
|
|
2209
|
-
var
|
|
2427
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
2210
2428
|
const withDappMetadata = setupDappMetadata(options);
|
|
2211
|
-
const integrationType = ((
|
|
2429
|
+
const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "direct";
|
|
2212
2430
|
const allOptions = __spreadProps(__spreadValues({}, withDappMetadata), {
|
|
2213
2431
|
ui: __spreadProps(__spreadValues({}, withDappMetadata.ui), {
|
|
2214
|
-
preferExtension: (
|
|
2215
|
-
showInstallModal: (
|
|
2216
|
-
headless: (
|
|
2432
|
+
preferExtension: (_c = withDappMetadata.ui.preferExtension) != null ? _c : true,
|
|
2433
|
+
showInstallModal: (_d = withDappMetadata.ui.showInstallModal) != null ? _d : false,
|
|
2434
|
+
headless: (_e = withDappMetadata.ui.headless) != null ? _e : false
|
|
2217
2435
|
}),
|
|
2218
|
-
analytics: __spreadProps(__spreadValues({}, (
|
|
2219
|
-
enabled: (_g = (_f = options.analytics) == null ? void 0 : _f.enabled) != null ? _g : true,
|
|
2436
|
+
analytics: __spreadProps(__spreadValues({}, (_f = options.analytics) != null ? _f : {}), {
|
|
2220
2437
|
integrationType
|
|
2221
2438
|
})
|
|
2222
2439
|
});
|
|
2223
2440
|
super(allOptions);
|
|
2224
|
-
this
|
|
2225
|
-
this
|
|
2226
|
-
this
|
|
2227
|
-
this
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
this.
|
|
2235
|
-
|
|
2441
|
+
__privateAdd(this, _MultichainSDK_instances);
|
|
2442
|
+
__privateAdd(this, _provider);
|
|
2443
|
+
__privateAdd(this, _providerTransportWrapper);
|
|
2444
|
+
__privateAdd(this, _transport2);
|
|
2445
|
+
__privateAdd(this, _dappClient);
|
|
2446
|
+
__privateAdd(this, _beforeUnloadListener);
|
|
2447
|
+
this._status = "pending";
|
|
2448
|
+
__privateAdd(this, _listener);
|
|
2449
|
+
__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}`);
|
|
2450
|
+
__privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(this));
|
|
2451
|
+
__privateSet(this, _provider, (0, import_multichain_api_client3.getMultichainClient)({ transport: __privateGet(this, _providerTransportWrapper) }));
|
|
2452
|
+
}
|
|
2453
|
+
get status() {
|
|
2454
|
+
return this._status;
|
|
2455
|
+
}
|
|
2456
|
+
set status(value) {
|
|
2457
|
+
var _a2, _b;
|
|
2458
|
+
this._status = value;
|
|
2459
|
+
(_b = (_a2 = this.options.transport) == null ? void 0 : _a2.onNotification) == null ? void 0 : _b.call(_a2, {
|
|
2236
2460
|
method: "stateChanged",
|
|
2237
2461
|
params: value
|
|
2238
2462
|
});
|
|
2239
2463
|
}
|
|
2240
2464
|
get provider() {
|
|
2241
|
-
|
|
2242
|
-
this.__provider = (0, import_multichain_api_client3.getMultichainClient)({ transport: this.__transport });
|
|
2243
|
-
return this.__provider;
|
|
2244
|
-
}
|
|
2245
|
-
if (!this.__provider) {
|
|
2246
|
-
throw new Error("Provider not initialized, establish connection first");
|
|
2247
|
-
}
|
|
2248
|
-
return this.__provider;
|
|
2465
|
+
return __privateGet(this, _provider);
|
|
2249
2466
|
}
|
|
2250
2467
|
get transport() {
|
|
2251
|
-
if (!this
|
|
2468
|
+
if (!__privateGet(this, _transport2)) {
|
|
2252
2469
|
throw new Error("Transport not initialized, establish connection first");
|
|
2253
2470
|
}
|
|
2254
|
-
return this
|
|
2471
|
+
return __privateGet(this, _transport2);
|
|
2255
2472
|
}
|
|
2256
2473
|
get dappClient() {
|
|
2257
|
-
if (!this
|
|
2474
|
+
if (!__privateGet(this, _dappClient)) {
|
|
2258
2475
|
throw new Error("DappClient not initialized, establish connection first");
|
|
2259
2476
|
}
|
|
2260
|
-
return this
|
|
2477
|
+
return __privateGet(this, _dappClient);
|
|
2261
2478
|
}
|
|
2262
2479
|
get storage() {
|
|
2263
2480
|
return this.options.storage;
|
|
2264
2481
|
}
|
|
2265
2482
|
get transportType() {
|
|
2266
|
-
return this
|
|
2267
|
-
}
|
|
2268
|
-
get sdkInfo() {
|
|
2269
|
-
var _a;
|
|
2270
|
-
return `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(_a = this.options.dapp.url) != null ? _a : this.options.dapp.name} dAppTitle/${this.options.dapp.name}`;
|
|
2483
|
+
return __privateGet(this, _transport2) instanceof MWPTransport ? "mwp" /* MWP */ : "browser" /* Browser */;
|
|
2271
2484
|
}
|
|
2272
2485
|
static create(options) {
|
|
2273
2486
|
return __async(this, null, function* () {
|
|
2487
|
+
var _a2;
|
|
2274
2488
|
const instance = new _MultichainSDK(options);
|
|
2275
2489
|
const isEnabled2 = yield isEnabled(
|
|
2276
2490
|
"metamask-sdk:core",
|
|
@@ -2279,353 +2493,17 @@ var MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2279
2493
|
if (isEnabled2) {
|
|
2280
2494
|
enableDebug("metamask-sdk:core");
|
|
2281
2495
|
}
|
|
2282
|
-
yield instance.
|
|
2496
|
+
yield __privateMethod(_a2 = instance, _MultichainSDK_instances, init_fn).call(_a2);
|
|
2283
2497
|
return instance;
|
|
2284
2498
|
});
|
|
2285
2499
|
}
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
var _a, _b;
|
|
2289
|
-
if (!((_a = this.options.analytics) == null ? void 0 : _a.enabled)) {
|
|
2290
|
-
return;
|
|
2291
|
-
}
|
|
2292
|
-
const platform = getPlatformType();
|
|
2293
|
-
const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
|
|
2294
|
-
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
2295
|
-
if (!isBrowser && !isReactNative2) {
|
|
2296
|
-
return;
|
|
2297
|
-
}
|
|
2298
|
-
const version = getVersion();
|
|
2299
|
-
const dappId = getDappId(this.options.dapp);
|
|
2300
|
-
const anonId = yield this.storage.getAnonId();
|
|
2301
|
-
const { integrationType } = (_b = this.options.analytics) != null ? _b : {
|
|
2302
|
-
integrationType: ""
|
|
2303
|
-
};
|
|
2304
|
-
import_analytics4.analytics.setGlobalProperty("mmconnect_version", version);
|
|
2305
|
-
import_analytics4.analytics.setGlobalProperty("dapp_id", dappId);
|
|
2306
|
-
import_analytics4.analytics.setGlobalProperty("anon_id", anonId);
|
|
2307
|
-
import_analytics4.analytics.setGlobalProperty("platform", platform);
|
|
2308
|
-
import_analytics4.analytics.setGlobalProperty("integration_type", integrationType);
|
|
2309
|
-
import_analytics4.analytics.enable();
|
|
2310
|
-
});
|
|
2311
|
-
}
|
|
2312
|
-
onTransportNotification(payload) {
|
|
2313
|
-
return __async(this, null, function* () {
|
|
2314
|
-
var _a;
|
|
2315
|
-
if (typeof payload === "object" && payload !== null && "method" in payload) {
|
|
2316
|
-
this.emit(payload.method, (_a = payload.params) != null ? _a : payload.result);
|
|
2317
|
-
}
|
|
2318
|
-
});
|
|
2319
|
-
}
|
|
2320
|
-
getStoredTransport() {
|
|
2500
|
+
// TODO: make this into param object
|
|
2501
|
+
connect(scopes, caipAccountIds, sessionProperties, forceRequest) {
|
|
2321
2502
|
return __async(this, null, function* () {
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
if (transportType === "browser" /* Browser */) {
|
|
2326
|
-
if (hasExtensionInstalled) {
|
|
2327
|
-
const apiTransport = new DefaultTransport();
|
|
2328
|
-
this.__transport = apiTransport;
|
|
2329
|
-
this.listener = apiTransport.onNotification(
|
|
2330
|
-
this.onTransportNotification.bind(this)
|
|
2331
|
-
);
|
|
2332
|
-
return apiTransport;
|
|
2333
|
-
}
|
|
2334
|
-
} else if (transportType === "mwp" /* MWP */) {
|
|
2335
|
-
const { adapter: kvstore } = this.options.storage;
|
|
2336
|
-
const dappClient = yield this.createDappClient();
|
|
2337
|
-
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2338
|
-
this.__dappClient = dappClient;
|
|
2339
|
-
this.__transport = apiTransport;
|
|
2340
|
-
this.listener = apiTransport.onNotification(
|
|
2341
|
-
this.onTransportNotification.bind(this)
|
|
2342
|
-
);
|
|
2343
|
-
return apiTransport;
|
|
2344
|
-
}
|
|
2345
|
-
yield this.storage.removeTransport();
|
|
2503
|
+
var _a2;
|
|
2504
|
+
if (this.status !== "connected") {
|
|
2505
|
+
yield this.disconnect();
|
|
2346
2506
|
}
|
|
2347
|
-
return void 0;
|
|
2348
|
-
});
|
|
2349
|
-
}
|
|
2350
|
-
setupTransport() {
|
|
2351
|
-
return __async(this, null, function* () {
|
|
2352
|
-
const transport = yield this.getStoredTransport();
|
|
2353
|
-
if (transport) {
|
|
2354
|
-
if (!this.transport.isConnected()) {
|
|
2355
|
-
this.state = "connecting";
|
|
2356
|
-
yield this.transport.connect();
|
|
2357
|
-
}
|
|
2358
|
-
this.state = "connected";
|
|
2359
|
-
if (this.transport instanceof MWPTransport) {
|
|
2360
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2361
|
-
} else {
|
|
2362
|
-
yield this.storage.setTransport("browser" /* Browser */);
|
|
2363
|
-
}
|
|
2364
|
-
} else {
|
|
2365
|
-
this.state = "loaded";
|
|
2366
|
-
}
|
|
2367
|
-
});
|
|
2368
|
-
}
|
|
2369
|
-
init() {
|
|
2370
|
-
return __async(this, null, function* () {
|
|
2371
|
-
var _a, _b;
|
|
2372
|
-
try {
|
|
2373
|
-
if (typeof window !== "undefined" && ((_a = window.mmsdk) == null ? void 0 : _a.isInitialized)) {
|
|
2374
|
-
logger2("MetaMaskSDK: init already initialized");
|
|
2375
|
-
} else {
|
|
2376
|
-
yield this.setupAnalytics();
|
|
2377
|
-
yield this.setupTransport();
|
|
2378
|
-
if ((_b = this.options.analytics) == null ? void 0 : _b.enabled) {
|
|
2379
|
-
try {
|
|
2380
|
-
const baseProps = yield getBaseAnalyticsProperties(
|
|
2381
|
-
this.options,
|
|
2382
|
-
this.storage
|
|
2383
|
-
);
|
|
2384
|
-
import_analytics4.analytics.track("mmconnect_initialized", baseProps);
|
|
2385
|
-
} catch (error) {
|
|
2386
|
-
logger2("Error tracking initialized event", error);
|
|
2387
|
-
}
|
|
2388
|
-
}
|
|
2389
|
-
if (typeof window !== "undefined") {
|
|
2390
|
-
window.mmsdk = this;
|
|
2391
|
-
}
|
|
2392
|
-
}
|
|
2393
|
-
} catch (error) {
|
|
2394
|
-
yield this.storage.removeTransport();
|
|
2395
|
-
this.state = "pending";
|
|
2396
|
-
logger2("MetaMaskSDK error during initialization", error);
|
|
2397
|
-
}
|
|
2398
|
-
});
|
|
2399
|
-
}
|
|
2400
|
-
createDappClient() {
|
|
2401
|
-
return __async(this, null, function* () {
|
|
2402
|
-
const { adapter: kvstore } = this.options.storage;
|
|
2403
|
-
const sessionstore = new import_mobile_wallet_protocol_core2.SessionStore(kvstore);
|
|
2404
|
-
const websocket = (
|
|
2405
|
-
// eslint-disable-next-line no-negated-condition
|
|
2406
|
-
typeof window !== "undefined" ? WebSocket : (yield import("ws")).WebSocket
|
|
2407
|
-
);
|
|
2408
|
-
const transport = yield import_mobile_wallet_protocol_core2.WebSocketTransport.create({
|
|
2409
|
-
url: MWP_RELAY_URL,
|
|
2410
|
-
kvstore,
|
|
2411
|
-
websocket
|
|
2412
|
-
});
|
|
2413
|
-
const dappClient = new import_mobile_wallet_protocol_dapp_client.DappClient({ transport, sessionstore, keymanager });
|
|
2414
|
-
return dappClient;
|
|
2415
|
-
});
|
|
2416
|
-
}
|
|
2417
|
-
setupMWP() {
|
|
2418
|
-
return __async(this, null, function* () {
|
|
2419
|
-
if (this.__transport instanceof MWPTransport) {
|
|
2420
|
-
return;
|
|
2421
|
-
}
|
|
2422
|
-
const { adapter: kvstore } = this.options.storage;
|
|
2423
|
-
const dappClient = yield this.createDappClient();
|
|
2424
|
-
this.__dappClient = dappClient;
|
|
2425
|
-
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2426
|
-
this.__transport = apiTransport;
|
|
2427
|
-
this.listener = this.transport.onNotification(
|
|
2428
|
-
this.onTransportNotification.bind(this)
|
|
2429
|
-
);
|
|
2430
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2431
|
-
});
|
|
2432
|
-
}
|
|
2433
|
-
onBeforeUnload() {
|
|
2434
|
-
return __async(this, null, function* () {
|
|
2435
|
-
var _a;
|
|
2436
|
-
if ((_a = this.options.ui.factory.modal) == null ? void 0 : _a.isMounted) {
|
|
2437
|
-
yield this.storage.removeTransport();
|
|
2438
|
-
}
|
|
2439
|
-
});
|
|
2440
|
-
}
|
|
2441
|
-
createBeforeUnloadListener() {
|
|
2442
|
-
if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
|
|
2443
|
-
window.addEventListener("beforeunload", this.onBeforeUnload.bind(this));
|
|
2444
|
-
}
|
|
2445
|
-
return () => {
|
|
2446
|
-
if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined") {
|
|
2447
|
-
window.removeEventListener(
|
|
2448
|
-
"beforeunload",
|
|
2449
|
-
this.onBeforeUnload.bind(this)
|
|
2450
|
-
);
|
|
2451
|
-
}
|
|
2452
|
-
};
|
|
2453
|
-
}
|
|
2454
|
-
showInstallModal(desktopPreferred, scopes, caipAccountIds) {
|
|
2455
|
-
return __async(this, null, function* () {
|
|
2456
|
-
var _a;
|
|
2457
|
-
(_a = this.__beforeUnloadListener) != null ? _a : this.__beforeUnloadListener = this.createBeforeUnloadListener();
|
|
2458
|
-
return new Promise((resolve, reject) => {
|
|
2459
|
-
this.options.ui.factory.renderInstallModal(
|
|
2460
|
-
desktopPreferred,
|
|
2461
|
-
() => __async(this, null, function* () {
|
|
2462
|
-
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
2463
|
-
yield this.dappClient.disconnect();
|
|
2464
|
-
}
|
|
2465
|
-
return new Promise((resolveConnectionRequest) => {
|
|
2466
|
-
this.dappClient.on(
|
|
2467
|
-
"session_request",
|
|
2468
|
-
(sessionRequest) => {
|
|
2469
|
-
resolveConnectionRequest({
|
|
2470
|
-
sessionRequest,
|
|
2471
|
-
metadata: {
|
|
2472
|
-
dapp: this.options.dapp,
|
|
2473
|
-
sdk: {
|
|
2474
|
-
version: getVersion(),
|
|
2475
|
-
platform: getPlatformType()
|
|
2476
|
-
}
|
|
2477
|
-
}
|
|
2478
|
-
});
|
|
2479
|
-
}
|
|
2480
|
-
);
|
|
2481
|
-
this.transport.connect({ scopes, caipAccountIds }).then(() => {
|
|
2482
|
-
var _a2;
|
|
2483
|
-
this.options.ui.factory.unload();
|
|
2484
|
-
(_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
|
|
2485
|
-
this.state = "connected";
|
|
2486
|
-
return this.storage.setTransport("mwp" /* MWP */);
|
|
2487
|
-
}).catch((error) => {
|
|
2488
|
-
if (error instanceof import_mobile_wallet_protocol_core2.ProtocolError) {
|
|
2489
|
-
if (error.code !== import_mobile_wallet_protocol_core2.ErrorCode.REQUEST_EXPIRED) {
|
|
2490
|
-
this.state = "disconnected";
|
|
2491
|
-
reject(error);
|
|
2492
|
-
}
|
|
2493
|
-
} else {
|
|
2494
|
-
this.state = "disconnected";
|
|
2495
|
-
reject(error);
|
|
2496
|
-
}
|
|
2497
|
-
});
|
|
2498
|
-
});
|
|
2499
|
-
}),
|
|
2500
|
-
(error) => __async(this, null, function* () {
|
|
2501
|
-
if (!error) {
|
|
2502
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2503
|
-
resolve();
|
|
2504
|
-
} else {
|
|
2505
|
-
yield this.storage.removeTransport();
|
|
2506
|
-
reject(error);
|
|
2507
|
-
}
|
|
2508
|
-
})
|
|
2509
|
-
);
|
|
2510
|
-
});
|
|
2511
|
-
});
|
|
2512
|
-
}
|
|
2513
|
-
setupDefaultTransport() {
|
|
2514
|
-
return __async(this, null, function* () {
|
|
2515
|
-
this.state = "connecting";
|
|
2516
|
-
yield this.storage.setTransport("browser" /* Browser */);
|
|
2517
|
-
const transport = new DefaultTransport();
|
|
2518
|
-
this.listener = transport.onNotification(
|
|
2519
|
-
this.onTransportNotification.bind(this)
|
|
2520
|
-
);
|
|
2521
|
-
this.__transport = transport;
|
|
2522
|
-
return transport;
|
|
2523
|
-
});
|
|
2524
|
-
}
|
|
2525
|
-
deeplinkConnect(scopes, caipAccountIds) {
|
|
2526
|
-
return __async(this, null, function* () {
|
|
2527
|
-
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
2528
|
-
this.dappClient.on("message", (payload) => {
|
|
2529
|
-
var _a, _b, _c;
|
|
2530
|
-
const data = payload.data;
|
|
2531
|
-
if (typeof data === "object" && data !== null) {
|
|
2532
|
-
if ("method" in data && data.method === "wallet_createSession") {
|
|
2533
|
-
if (data.error) {
|
|
2534
|
-
this.state = "loaded";
|
|
2535
|
-
return reject(data.error);
|
|
2536
|
-
}
|
|
2537
|
-
const session = (_a = data.params) != null ? _a : data.result;
|
|
2538
|
-
if (session) {
|
|
2539
|
-
(_c = (_b = this.options.transport) == null ? void 0 : _b.onNotification) == null ? void 0 : _c.call(_b, payload.data);
|
|
2540
|
-
this.emit("wallet_sessionChanged", session);
|
|
2541
|
-
}
|
|
2542
|
-
}
|
|
2543
|
-
}
|
|
2544
|
-
});
|
|
2545
|
-
let timeout;
|
|
2546
|
-
if (!this.transport.isConnected()) {
|
|
2547
|
-
this.dappClient.once(
|
|
2548
|
-
"session_request",
|
|
2549
|
-
(sessionRequest) => {
|
|
2550
|
-
var _a;
|
|
2551
|
-
const connectionRequest = {
|
|
2552
|
-
sessionRequest,
|
|
2553
|
-
metadata: {
|
|
2554
|
-
dapp: this.options.dapp,
|
|
2555
|
-
sdk: { version: getVersion(), platform: getPlatformType() }
|
|
2556
|
-
}
|
|
2557
|
-
};
|
|
2558
|
-
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
2559
|
-
const universalLink = this.options.ui.factory.createConnectionUniversalLink(connectionRequest);
|
|
2560
|
-
if ((_a = this.options.mobile) == null ? void 0 : _a.preferredOpenLink) {
|
|
2561
|
-
this.options.mobile.preferredOpenLink(deeplink, "_self");
|
|
2562
|
-
} else {
|
|
2563
|
-
openDeeplink(this.options, deeplink, universalLink);
|
|
2564
|
-
}
|
|
2565
|
-
}
|
|
2566
|
-
);
|
|
2567
|
-
}
|
|
2568
|
-
this.transport.connect({ scopes, caipAccountIds }).then(resolve).catch((error) => {
|
|
2569
|
-
this.storage.removeTransport();
|
|
2570
|
-
reject(error);
|
|
2571
|
-
}).finally(() => {
|
|
2572
|
-
if (timeout) {
|
|
2573
|
-
clearTimeout(timeout);
|
|
2574
|
-
}
|
|
2575
|
-
});
|
|
2576
|
-
}));
|
|
2577
|
-
});
|
|
2578
|
-
}
|
|
2579
|
-
handleConnection(promise, scopes, transportType) {
|
|
2580
|
-
return __async(this, null, function* () {
|
|
2581
|
-
this.state = "connecting";
|
|
2582
|
-
return promise.then(() => __async(this, null, function* () {
|
|
2583
|
-
var _a;
|
|
2584
|
-
this.state = "connected";
|
|
2585
|
-
if ((_a = this.options.analytics) == null ? void 0 : _a.enabled) {
|
|
2586
|
-
try {
|
|
2587
|
-
const baseProps = yield getBaseAnalyticsProperties(
|
|
2588
|
-
this.options,
|
|
2589
|
-
this.storage
|
|
2590
|
-
);
|
|
2591
|
-
import_analytics4.analytics.track("mmconnect_connection_established", __spreadProps(__spreadValues({}, baseProps), {
|
|
2592
|
-
transport_type: transportType,
|
|
2593
|
-
user_permissioned_chains: scopes
|
|
2594
|
-
}));
|
|
2595
|
-
} catch (error) {
|
|
2596
|
-
logger2("Error tracking connection_established event", error);
|
|
2597
|
-
}
|
|
2598
|
-
}
|
|
2599
|
-
})).catch((error) => __async(this, null, function* () {
|
|
2600
|
-
var _a;
|
|
2601
|
-
this.state = "disconnected";
|
|
2602
|
-
if ((_a = this.options.analytics) == null ? void 0 : _a.enabled) {
|
|
2603
|
-
try {
|
|
2604
|
-
const baseProps = yield getBaseAnalyticsProperties(
|
|
2605
|
-
this.options,
|
|
2606
|
-
this.storage
|
|
2607
|
-
);
|
|
2608
|
-
const isRejection = isRejectionError(error);
|
|
2609
|
-
if (isRejection) {
|
|
2610
|
-
import_analytics4.analytics.track("mmconnect_connection_rejected", __spreadProps(__spreadValues({}, baseProps), {
|
|
2611
|
-
transport_type: transportType
|
|
2612
|
-
}));
|
|
2613
|
-
} else {
|
|
2614
|
-
import_analytics4.analytics.track("mmconnect_connection_failed", __spreadProps(__spreadValues({}, baseProps), {
|
|
2615
|
-
transport_type: transportType
|
|
2616
|
-
}));
|
|
2617
|
-
}
|
|
2618
|
-
} catch (e) {
|
|
2619
|
-
logger2("Error tracking connection failed/rejected event", error);
|
|
2620
|
-
}
|
|
2621
|
-
}
|
|
2622
|
-
return Promise.reject(error);
|
|
2623
|
-
}));
|
|
2624
|
-
});
|
|
2625
|
-
}
|
|
2626
|
-
connect(scopes, caipAccountIds, forceRequest) {
|
|
2627
|
-
return __async(this, null, function* () {
|
|
2628
|
-
var _a, _b;
|
|
2629
2507
|
const { ui } = this.options;
|
|
2630
2508
|
const platformType = getPlatformType();
|
|
2631
2509
|
const isWeb = platformType === "in-app-browser" /* MetaMaskMobileWebview */ || platformType === "web-desktop" /* DesktopWeb */;
|
|
@@ -2638,96 +2516,70 @@ var MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2638
2516
|
} else {
|
|
2639
2517
|
transportType = "mwp" /* MWP */;
|
|
2640
2518
|
}
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
this.options.api.supportedNetworks
|
|
2649
|
-
);
|
|
2650
|
-
import_analytics4.analytics.track("mmconnect_connection_initiated", __spreadProps(__spreadValues({}, baseProps), {
|
|
2651
|
-
transport_type: transportType,
|
|
2652
|
-
dapp_configured_chains: dappConfiguredChains,
|
|
2653
|
-
dapp_requested_chains: scopes
|
|
2654
|
-
}));
|
|
2655
|
-
} catch (error) {
|
|
2656
|
-
logger2("Error tracking connection_initiated event", error);
|
|
2657
|
-
}
|
|
2658
|
-
}
|
|
2659
|
-
if (((_b = this.__transport) == null ? void 0 : _b.isConnected()) && !secure) {
|
|
2660
|
-
return this.handleConnection(
|
|
2661
|
-
this.__transport.connect({ scopes, caipAccountIds, forceRequest }).then(() => {
|
|
2662
|
-
if (this.__transport instanceof MWPTransport) {
|
|
2663
|
-
return this.storage.setTransport("mwp" /* MWP */);
|
|
2664
|
-
} else {
|
|
2665
|
-
return this.storage.setTransport("browser" /* Browser */);
|
|
2666
|
-
}
|
|
2667
|
-
}),
|
|
2668
|
-
scopes,
|
|
2669
|
-
transportType
|
|
2519
|
+
try {
|
|
2520
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2521
|
+
this.options,
|
|
2522
|
+
this.storage
|
|
2523
|
+
);
|
|
2524
|
+
const dappConfiguredChains = Object.keys(
|
|
2525
|
+
this.options.api.supportedNetworks
|
|
2670
2526
|
);
|
|
2527
|
+
import_analytics4.analytics.track("mmconnect_connection_initiated", __spreadProps(__spreadValues({}, baseProps), {
|
|
2528
|
+
transport_type: transportType,
|
|
2529
|
+
dapp_configured_chains: dappConfiguredChains,
|
|
2530
|
+
dapp_requested_chains: scopes
|
|
2531
|
+
}));
|
|
2532
|
+
} catch (error) {
|
|
2533
|
+
logger2("Error tracking connection_initiated event", error);
|
|
2534
|
+
}
|
|
2535
|
+
if (((_a2 = __privateGet(this, _transport2)) == null ? void 0 : _a2.isConnected()) && !secure) {
|
|
2536
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateGet(this, _transport2).connect({ scopes, caipAccountIds, sessionProperties, forceRequest }).then(() => __async(this, null, function* () {
|
|
2537
|
+
if (__privateGet(this, _transport2) instanceof MWPTransport) {
|
|
2538
|
+
return this.storage.setTransport("mwp" /* MWP */);
|
|
2539
|
+
}
|
|
2540
|
+
return this.storage.setTransport("browser" /* Browser */);
|
|
2541
|
+
})), scopes, transportType);
|
|
2671
2542
|
}
|
|
2672
2543
|
if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
|
|
2673
|
-
const defaultTransport = yield this.
|
|
2674
|
-
return this.
|
|
2675
|
-
defaultTransport.connect({ scopes, caipAccountIds, forceRequest }),
|
|
2676
|
-
scopes,
|
|
2677
|
-
transportType
|
|
2678
|
-
);
|
|
2544
|
+
const defaultTransport = yield __privateMethod(this, _MultichainSDK_instances, setupDefaultTransport_fn).call(this);
|
|
2545
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, sessionProperties, forceRequest }), scopes, transportType);
|
|
2679
2546
|
}
|
|
2680
2547
|
if (isWeb && hasExtensionInstalled && preferExtension) {
|
|
2681
|
-
const defaultTransport = yield this.
|
|
2682
|
-
return this.
|
|
2683
|
-
defaultTransport.connect({ scopes, caipAccountIds, forceRequest }),
|
|
2684
|
-
scopes,
|
|
2685
|
-
transportType
|
|
2686
|
-
);
|
|
2548
|
+
const defaultTransport = yield __privateMethod(this, _MultichainSDK_instances, setupDefaultTransport_fn).call(this);
|
|
2549
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, sessionProperties, forceRequest }), scopes, transportType);
|
|
2687
2550
|
}
|
|
2688
|
-
yield this.
|
|
2551
|
+
yield __privateMethod(this, _MultichainSDK_instances, setupMWP_fn).call(this);
|
|
2689
2552
|
const shouldShowInstallModal = hasExtensionInstalled ? showInstallModal : !preferExtension || showInstallModal;
|
|
2690
2553
|
if (secure && !shouldShowInstallModal) {
|
|
2691
|
-
return this.
|
|
2692
|
-
this.deeplinkConnect(scopes, caipAccountIds),
|
|
2693
|
-
scopes,
|
|
2694
|
-
transportType
|
|
2695
|
-
);
|
|
2554
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateMethod(this, _MultichainSDK_instances, deeplinkConnect_fn).call(this, scopes, caipAccountIds, sessionProperties), scopes, transportType);
|
|
2696
2555
|
}
|
|
2697
|
-
return this.
|
|
2698
|
-
this.showInstallModal(shouldShowInstallModal, scopes, caipAccountIds),
|
|
2699
|
-
scopes,
|
|
2700
|
-
transportType
|
|
2701
|
-
);
|
|
2556
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateMethod(this, _MultichainSDK_instances, showInstallModal_fn).call(this, shouldShowInstallModal, scopes, caipAccountIds, sessionProperties), scopes, transportType);
|
|
2702
2557
|
});
|
|
2703
2558
|
}
|
|
2704
2559
|
emit(event, args) {
|
|
2705
|
-
var
|
|
2706
|
-
(_b = (
|
|
2560
|
+
var _a2, _b;
|
|
2561
|
+
(_b = (_a2 = this.options.transport) == null ? void 0 : _a2.onNotification) == null ? void 0 : _b.call(_a2, { method: event, params: args });
|
|
2707
2562
|
super.emit(event, args);
|
|
2708
2563
|
}
|
|
2709
2564
|
disconnect() {
|
|
2710
2565
|
return __async(this, null, function* () {
|
|
2711
|
-
var
|
|
2712
|
-
(
|
|
2713
|
-
(_b = this
|
|
2714
|
-
yield (_c = this
|
|
2566
|
+
var _a2, _b, _c;
|
|
2567
|
+
yield (_a2 = __privateGet(this, _listener)) == null ? void 0 : _a2.call(this);
|
|
2568
|
+
(_b = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _b.call(this);
|
|
2569
|
+
yield (_c = __privateGet(this, _transport2)) == null ? void 0 : _c.disconnect();
|
|
2715
2570
|
yield this.storage.removeTransport();
|
|
2716
|
-
this.emit("wallet_sessionChanged", void 0);
|
|
2717
2571
|
this.emit("stateChanged", "disconnected");
|
|
2718
|
-
this
|
|
2719
|
-
this
|
|
2720
|
-
this
|
|
2721
|
-
this.
|
|
2722
|
-
this
|
|
2572
|
+
__privateSet(this, _listener, void 0);
|
|
2573
|
+
__privateSet(this, _beforeUnloadListener, void 0);
|
|
2574
|
+
__privateSet(this, _transport2, void 0);
|
|
2575
|
+
__privateGet(this, _providerTransportWrapper).clearNotificationCallbacks();
|
|
2576
|
+
__privateSet(this, _dappClient, void 0);
|
|
2723
2577
|
});
|
|
2724
2578
|
}
|
|
2725
2579
|
invokeMethod(request) {
|
|
2726
2580
|
return __async(this, null, function* () {
|
|
2727
|
-
|
|
2728
|
-
const
|
|
2729
|
-
(_a = this.__provider) != null ? _a : this.__provider = (0, import_multichain_api_client3.getMultichainClient)({ transport });
|
|
2730
|
-
const rpcClient = new RpcClient(options, sdkInfo);
|
|
2581
|
+
const { transport, options } = this;
|
|
2582
|
+
const rpcClient = new RpcClient(options, __privateGet(this, _sdkInfo));
|
|
2731
2583
|
const requestRouter = new RequestRouter(transport, rpcClient, options);
|
|
2732
2584
|
return requestRouter.invokeMethod(request);
|
|
2733
2585
|
});
|
|
@@ -2748,16 +2600,427 @@ var MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2748
2600
|
if (mobile == null ? void 0 : mobile.preferredOpenLink) {
|
|
2749
2601
|
mobile.preferredOpenLink(url, "_self");
|
|
2750
2602
|
} else {
|
|
2751
|
-
openDeeplink(
|
|
2752
|
-
this.options,
|
|
2753
|
-
url,
|
|
2754
|
-
METAMASK_CONNECT_BASE_URL
|
|
2755
|
-
);
|
|
2603
|
+
openDeeplink(this.options, url, METAMASK_CONNECT_BASE_URL);
|
|
2756
2604
|
}
|
|
2757
2605
|
}), 10);
|
|
2758
2606
|
}
|
|
2759
2607
|
}
|
|
2760
2608
|
};
|
|
2609
|
+
_provider = new WeakMap();
|
|
2610
|
+
_providerTransportWrapper = new WeakMap();
|
|
2611
|
+
_transport2 = new WeakMap();
|
|
2612
|
+
_dappClient = new WeakMap();
|
|
2613
|
+
_beforeUnloadListener = new WeakMap();
|
|
2614
|
+
_listener = new WeakMap();
|
|
2615
|
+
_sdkInfo = new WeakMap();
|
|
2616
|
+
_MultichainSDK_instances = new WeakSet();
|
|
2617
|
+
setupAnalytics_fn = function() {
|
|
2618
|
+
return __async(this, null, function* () {
|
|
2619
|
+
var _a2;
|
|
2620
|
+
const platform = getPlatformType();
|
|
2621
|
+
const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
|
|
2622
|
+
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
2623
|
+
if (!isBrowser && !isReactNative2) {
|
|
2624
|
+
return;
|
|
2625
|
+
}
|
|
2626
|
+
const version = getVersion();
|
|
2627
|
+
const dappId = getDappId(this.options.dapp);
|
|
2628
|
+
const anonId = yield this.storage.getAnonId();
|
|
2629
|
+
const { integrationType } = (_a2 = this.options.analytics) != null ? _a2 : {
|
|
2630
|
+
integrationType: ""
|
|
2631
|
+
};
|
|
2632
|
+
import_analytics4.analytics.setGlobalProperty("mmconnect_version", version);
|
|
2633
|
+
import_analytics4.analytics.setGlobalProperty("dapp_id", dappId);
|
|
2634
|
+
import_analytics4.analytics.setGlobalProperty("anon_id", anonId);
|
|
2635
|
+
import_analytics4.analytics.setGlobalProperty("platform", platform);
|
|
2636
|
+
import_analytics4.analytics.setGlobalProperty("integration_type", integrationType);
|
|
2637
|
+
import_analytics4.analytics.enable();
|
|
2638
|
+
});
|
|
2639
|
+
};
|
|
2640
|
+
onTransportNotification_fn = function(payload) {
|
|
2641
|
+
return __async(this, null, function* () {
|
|
2642
|
+
var _a2;
|
|
2643
|
+
if (typeof payload === "object" && payload !== null && "method" in payload) {
|
|
2644
|
+
this.emit(payload.method, (_a2 = payload.params) != null ? _a2 : payload.result);
|
|
2645
|
+
}
|
|
2646
|
+
});
|
|
2647
|
+
};
|
|
2648
|
+
getStoredTransport_fn = function() {
|
|
2649
|
+
return __async(this, null, function* () {
|
|
2650
|
+
const transportType = yield this.storage.getTransport();
|
|
2651
|
+
const hasExtensionInstalled = yield hasExtension();
|
|
2652
|
+
if (transportType) {
|
|
2653
|
+
if (transportType === "browser" /* Browser */) {
|
|
2654
|
+
if (hasExtensionInstalled) {
|
|
2655
|
+
const apiTransport = new DefaultTransport();
|
|
2656
|
+
__privateSet(this, _transport2, apiTransport);
|
|
2657
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2658
|
+
__privateSet(this, _listener, apiTransport.onNotification(
|
|
2659
|
+
__privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
|
|
2660
|
+
));
|
|
2661
|
+
return apiTransport;
|
|
2662
|
+
}
|
|
2663
|
+
} else if (transportType === "mwp" /* MWP */) {
|
|
2664
|
+
const { adapter: kvstore } = this.options.storage;
|
|
2665
|
+
const dappClient = yield __privateMethod(this, _MultichainSDK_instances, createDappClient_fn).call(this);
|
|
2666
|
+
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2667
|
+
__privateSet(this, _dappClient, dappClient);
|
|
2668
|
+
__privateSet(this, _transport2, apiTransport);
|
|
2669
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2670
|
+
__privateSet(this, _listener, apiTransport.onNotification(
|
|
2671
|
+
__privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
|
|
2672
|
+
));
|
|
2673
|
+
return apiTransport;
|
|
2674
|
+
}
|
|
2675
|
+
yield this.storage.removeTransport();
|
|
2676
|
+
}
|
|
2677
|
+
return void 0;
|
|
2678
|
+
});
|
|
2679
|
+
};
|
|
2680
|
+
setupTransport_fn = function() {
|
|
2681
|
+
return __async(this, null, function* () {
|
|
2682
|
+
const transport = yield __privateMethod(this, _MultichainSDK_instances, getStoredTransport_fn).call(this);
|
|
2683
|
+
if (transport) {
|
|
2684
|
+
if (!this.transport.isConnected()) {
|
|
2685
|
+
this.status = "connecting";
|
|
2686
|
+
yield this.transport.connect();
|
|
2687
|
+
}
|
|
2688
|
+
this.status = "connected";
|
|
2689
|
+
if (this.transport instanceof MWPTransport) {
|
|
2690
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2691
|
+
} else {
|
|
2692
|
+
yield this.storage.setTransport("browser" /* Browser */);
|
|
2693
|
+
}
|
|
2694
|
+
} else {
|
|
2695
|
+
this.status = "loaded";
|
|
2696
|
+
}
|
|
2697
|
+
});
|
|
2698
|
+
};
|
|
2699
|
+
init_fn = function() {
|
|
2700
|
+
return __async(this, null, function* () {
|
|
2701
|
+
var _a2;
|
|
2702
|
+
try {
|
|
2703
|
+
if (typeof window !== "undefined" && ((_a2 = window.mmsdk) == null ? void 0 : _a2.isInitialized)) {
|
|
2704
|
+
logger2("MetaMaskSDK: init already initialized");
|
|
2705
|
+
} else {
|
|
2706
|
+
yield __privateMethod(this, _MultichainSDK_instances, setupAnalytics_fn).call(this);
|
|
2707
|
+
yield __privateMethod(this, _MultichainSDK_instances, setupTransport_fn).call(this);
|
|
2708
|
+
try {
|
|
2709
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2710
|
+
this.options,
|
|
2711
|
+
this.storage
|
|
2712
|
+
);
|
|
2713
|
+
import_analytics4.analytics.track("mmconnect_initialized", baseProps);
|
|
2714
|
+
} catch (error) {
|
|
2715
|
+
logger2("Error tracking initialized event", error);
|
|
2716
|
+
}
|
|
2717
|
+
if (typeof window !== "undefined") {
|
|
2718
|
+
window.mmsdk = this;
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
} catch (error) {
|
|
2722
|
+
yield this.storage.removeTransport();
|
|
2723
|
+
this.status = "pending";
|
|
2724
|
+
logger2("MetaMaskSDK error during initialization", error);
|
|
2725
|
+
}
|
|
2726
|
+
});
|
|
2727
|
+
};
|
|
2728
|
+
createDappClient_fn = function() {
|
|
2729
|
+
return __async(this, null, function* () {
|
|
2730
|
+
const { adapter: kvstore } = this.options.storage;
|
|
2731
|
+
const sessionstore = new import_mobile_wallet_protocol_core2.SessionStore(kvstore);
|
|
2732
|
+
const websocket = (
|
|
2733
|
+
// eslint-disable-next-line no-negated-condition
|
|
2734
|
+
typeof window !== "undefined" ? WebSocket : (yield import("ws")).WebSocket
|
|
2735
|
+
);
|
|
2736
|
+
const transport = yield import_mobile_wallet_protocol_core2.WebSocketTransport.create({
|
|
2737
|
+
url: MWP_RELAY_URL,
|
|
2738
|
+
kvstore,
|
|
2739
|
+
websocket
|
|
2740
|
+
});
|
|
2741
|
+
const dappClient = new import_mobile_wallet_protocol_dapp_client.DappClient({ transport, sessionstore, keymanager });
|
|
2742
|
+
return dappClient;
|
|
2743
|
+
});
|
|
2744
|
+
};
|
|
2745
|
+
setupMWP_fn = function() {
|
|
2746
|
+
return __async(this, null, function* () {
|
|
2747
|
+
if (__privateGet(this, _transport2) instanceof MWPTransport) {
|
|
2748
|
+
return;
|
|
2749
|
+
}
|
|
2750
|
+
const { adapter: kvstore } = this.options.storage;
|
|
2751
|
+
const dappClient = yield __privateMethod(this, _MultichainSDK_instances, createDappClient_fn).call(this);
|
|
2752
|
+
__privateSet(this, _dappClient, dappClient);
|
|
2753
|
+
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2754
|
+
__privateSet(this, _transport2, apiTransport);
|
|
2755
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2756
|
+
__privateSet(this, _listener, this.transport.onNotification(
|
|
2757
|
+
__privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
|
|
2758
|
+
));
|
|
2759
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2760
|
+
});
|
|
2761
|
+
};
|
|
2762
|
+
onBeforeUnload_fn = function() {
|
|
2763
|
+
return __async(this, null, function* () {
|
|
2764
|
+
var _a2;
|
|
2765
|
+
if ((_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.isMounted) {
|
|
2766
|
+
yield this.storage.removeTransport();
|
|
2767
|
+
}
|
|
2768
|
+
});
|
|
2769
|
+
};
|
|
2770
|
+
createBeforeUnloadListener_fn = function() {
|
|
2771
|
+
if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
|
|
2772
|
+
window.addEventListener("beforeunload", __privateMethod(this, _MultichainSDK_instances, onBeforeUnload_fn).bind(this));
|
|
2773
|
+
}
|
|
2774
|
+
return () => {
|
|
2775
|
+
if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined") {
|
|
2776
|
+
window.removeEventListener(
|
|
2777
|
+
"beforeunload",
|
|
2778
|
+
__privateMethod(this, _MultichainSDK_instances, onBeforeUnload_fn).bind(this)
|
|
2779
|
+
);
|
|
2780
|
+
}
|
|
2781
|
+
};
|
|
2782
|
+
};
|
|
2783
|
+
renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
2784
|
+
return __async(this, null, function* () {
|
|
2785
|
+
return new Promise((resolve, reject) => {
|
|
2786
|
+
this.options.ui.factory.renderInstallModal(
|
|
2787
|
+
desktopPreferred,
|
|
2788
|
+
() => __async(this, null, function* () {
|
|
2789
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
2790
|
+
yield this.dappClient.disconnect();
|
|
2791
|
+
}
|
|
2792
|
+
return new Promise((_resolve) => {
|
|
2793
|
+
this.dappClient.on(
|
|
2794
|
+
"session_request",
|
|
2795
|
+
(sessionRequest) => {
|
|
2796
|
+
_resolve({
|
|
2797
|
+
sessionRequest,
|
|
2798
|
+
metadata: {
|
|
2799
|
+
dapp: this.options.dapp,
|
|
2800
|
+
sdk: {
|
|
2801
|
+
version: getVersion(),
|
|
2802
|
+
platform: getPlatformType()
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
});
|
|
2806
|
+
}
|
|
2807
|
+
);
|
|
2808
|
+
(() => __async(this, null, function* () {
|
|
2809
|
+
var _a2;
|
|
2810
|
+
try {
|
|
2811
|
+
yield this.transport.connect({ scopes, caipAccountIds, sessionProperties });
|
|
2812
|
+
yield this.options.ui.factory.unload();
|
|
2813
|
+
(_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
|
|
2814
|
+
this.status = "connected";
|
|
2815
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2816
|
+
} catch (error) {
|
|
2817
|
+
if (error instanceof import_mobile_wallet_protocol_core2.ProtocolError) {
|
|
2818
|
+
if (error.code !== import_mobile_wallet_protocol_core2.ErrorCode.REQUEST_EXPIRED) {
|
|
2819
|
+
this.status = "disconnected";
|
|
2820
|
+
reject(error);
|
|
2821
|
+
}
|
|
2822
|
+
} else {
|
|
2823
|
+
this.status = "disconnected";
|
|
2824
|
+
reject(
|
|
2825
|
+
error instanceof Error ? error : new Error(String(error))
|
|
2826
|
+
);
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2829
|
+
}))().catch(() => {
|
|
2830
|
+
});
|
|
2831
|
+
});
|
|
2832
|
+
}),
|
|
2833
|
+
(error) => __async(this, null, function* () {
|
|
2834
|
+
if (error) {
|
|
2835
|
+
yield this.storage.removeTransport();
|
|
2836
|
+
reject(error);
|
|
2837
|
+
} else {
|
|
2838
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2839
|
+
resolve();
|
|
2840
|
+
}
|
|
2841
|
+
}),
|
|
2842
|
+
(uri) => {
|
|
2843
|
+
this.emit("display_uri", uri);
|
|
2844
|
+
}
|
|
2845
|
+
).catch((error) => {
|
|
2846
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2847
|
+
});
|
|
2848
|
+
});
|
|
2849
|
+
});
|
|
2850
|
+
};
|
|
2851
|
+
showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
2852
|
+
return __async(this, null, function* () {
|
|
2853
|
+
var _a2;
|
|
2854
|
+
(_a2 = __privateGet(this, _beforeUnloadListener)) != null ? _a2 : __privateSet(this, _beforeUnloadListener, __privateMethod(this, _MultichainSDK_instances, createBeforeUnloadListener_fn).call(this));
|
|
2855
|
+
if (this.options.ui.headless) {
|
|
2856
|
+
yield __privateMethod(this, _MultichainSDK_instances, headlessConnect_fn).call(this, scopes, caipAccountIds, sessionProperties);
|
|
2857
|
+
} else {
|
|
2858
|
+
yield __privateMethod(this, _MultichainSDK_instances, renderInstallModalAsync_fn).call(this, desktopPreferred, scopes, caipAccountIds, sessionProperties);
|
|
2859
|
+
}
|
|
2860
|
+
});
|
|
2861
|
+
};
|
|
2862
|
+
headlessConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
2863
|
+
return __async(this, null, function* () {
|
|
2864
|
+
return new Promise((resolve, reject) => {
|
|
2865
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
2866
|
+
this.dappClient.disconnect().catch(() => {
|
|
2867
|
+
});
|
|
2868
|
+
}
|
|
2869
|
+
this.dappClient.on(
|
|
2870
|
+
"session_request",
|
|
2871
|
+
(sessionRequest) => {
|
|
2872
|
+
const connectionRequest = {
|
|
2873
|
+
sessionRequest,
|
|
2874
|
+
metadata: {
|
|
2875
|
+
dapp: this.options.dapp,
|
|
2876
|
+
sdk: {
|
|
2877
|
+
version: getVersion(),
|
|
2878
|
+
platform: getPlatformType()
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
};
|
|
2882
|
+
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
2883
|
+
this.emit("display_uri", deeplink);
|
|
2884
|
+
}
|
|
2885
|
+
);
|
|
2886
|
+
this.transport.connect({ scopes, caipAccountIds, sessionProperties }).then(() => __async(this, null, function* () {
|
|
2887
|
+
this.status = "connected";
|
|
2888
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2889
|
+
resolve();
|
|
2890
|
+
})).catch((error) => __async(this, null, function* () {
|
|
2891
|
+
if (error instanceof import_mobile_wallet_protocol_core2.ProtocolError) {
|
|
2892
|
+
this.status = "disconnected";
|
|
2893
|
+
yield this.storage.removeTransport();
|
|
2894
|
+
reject(error);
|
|
2895
|
+
} else {
|
|
2896
|
+
this.status = "disconnected";
|
|
2897
|
+
yield this.storage.removeTransport();
|
|
2898
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2899
|
+
}
|
|
2900
|
+
}));
|
|
2901
|
+
});
|
|
2902
|
+
});
|
|
2903
|
+
};
|
|
2904
|
+
setupDefaultTransport_fn = function() {
|
|
2905
|
+
return __async(this, null, function* () {
|
|
2906
|
+
this.status = "connecting";
|
|
2907
|
+
yield this.storage.setTransport("browser" /* Browser */);
|
|
2908
|
+
const transport = new DefaultTransport();
|
|
2909
|
+
__privateSet(this, _listener, transport.onNotification(
|
|
2910
|
+
__privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
|
|
2911
|
+
));
|
|
2912
|
+
__privateSet(this, _transport2, transport);
|
|
2913
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2914
|
+
return transport;
|
|
2915
|
+
});
|
|
2916
|
+
};
|
|
2917
|
+
deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
2918
|
+
return __async(this, null, function* () {
|
|
2919
|
+
return new Promise((resolve, reject) => {
|
|
2920
|
+
const dappClientMessageHandler = (payload) => {
|
|
2921
|
+
var _a2;
|
|
2922
|
+
if (typeof payload !== "object" || payload === null || !("data" in payload)) {
|
|
2923
|
+
return;
|
|
2924
|
+
}
|
|
2925
|
+
const data = payload.data;
|
|
2926
|
+
if (typeof data === "object" && data !== null) {
|
|
2927
|
+
if (data.error) {
|
|
2928
|
+
this.dappClient.off("message", dappClientMessageHandler);
|
|
2929
|
+
reject(data.error);
|
|
2930
|
+
}
|
|
2931
|
+
if ((_a2 = data == null ? void 0 : data.result) == null ? void 0 : _a2.sessionScopes) {
|
|
2932
|
+
this.dappClient.off("message", dappClientMessageHandler);
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
};
|
|
2936
|
+
this.dappClient.on("message", dappClientMessageHandler);
|
|
2937
|
+
let timeout;
|
|
2938
|
+
if (this.transport.isConnected()) {
|
|
2939
|
+
timeout = setTimeout(() => {
|
|
2940
|
+
this.openDeeplinkIfNeeded();
|
|
2941
|
+
}, 250);
|
|
2942
|
+
} else {
|
|
2943
|
+
this.dappClient.once(
|
|
2944
|
+
"session_request",
|
|
2945
|
+
(sessionRequest) => {
|
|
2946
|
+
var _a2;
|
|
2947
|
+
const connectionRequest = {
|
|
2948
|
+
sessionRequest,
|
|
2949
|
+
metadata: {
|
|
2950
|
+
dapp: this.options.dapp,
|
|
2951
|
+
sdk: { version: getVersion(), platform: getPlatformType() }
|
|
2952
|
+
}
|
|
2953
|
+
};
|
|
2954
|
+
const deeplink = this.options.ui.factory.createConnectionDeeplink(
|
|
2955
|
+
connectionRequest
|
|
2956
|
+
);
|
|
2957
|
+
const universalLink = this.options.ui.factory.createConnectionUniversalLink(
|
|
2958
|
+
connectionRequest
|
|
2959
|
+
);
|
|
2960
|
+
this.emit("display_uri", deeplink);
|
|
2961
|
+
if ((_a2 = this.options.mobile) == null ? void 0 : _a2.preferredOpenLink) {
|
|
2962
|
+
this.options.mobile.preferredOpenLink(deeplink, "_self");
|
|
2963
|
+
} else {
|
|
2964
|
+
openDeeplink(this.options, deeplink, universalLink);
|
|
2965
|
+
}
|
|
2966
|
+
}
|
|
2967
|
+
);
|
|
2968
|
+
}
|
|
2969
|
+
return this.transport.connect({ scopes, caipAccountIds, sessionProperties }).then(resolve).catch((error) => __async(this, null, function* () {
|
|
2970
|
+
yield this.storage.removeTransport();
|
|
2971
|
+
this.dappClient.off("message", dappClientMessageHandler);
|
|
2972
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2973
|
+
})).finally(() => {
|
|
2974
|
+
if (timeout) {
|
|
2975
|
+
clearTimeout(timeout);
|
|
2976
|
+
}
|
|
2977
|
+
});
|
|
2978
|
+
});
|
|
2979
|
+
});
|
|
2980
|
+
};
|
|
2981
|
+
handleConnection_fn = function(promise, scopes, transportType) {
|
|
2982
|
+
return __async(this, null, function* () {
|
|
2983
|
+
this.status = "connecting";
|
|
2984
|
+
return promise.then(() => __async(this, null, function* () {
|
|
2985
|
+
this.status = "connected";
|
|
2986
|
+
try {
|
|
2987
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2988
|
+
this.options,
|
|
2989
|
+
this.storage
|
|
2990
|
+
);
|
|
2991
|
+
import_analytics4.analytics.track("mmconnect_connection_established", __spreadProps(__spreadValues({}, baseProps), {
|
|
2992
|
+
transport_type: transportType,
|
|
2993
|
+
user_permissioned_chains: scopes
|
|
2994
|
+
}));
|
|
2995
|
+
} catch (error) {
|
|
2996
|
+
logger2("Error tracking connection_established event", error);
|
|
2997
|
+
}
|
|
2998
|
+
return void 0;
|
|
2999
|
+
})).catch((error) => __async(this, null, function* () {
|
|
3000
|
+
this.status = "disconnected";
|
|
3001
|
+
try {
|
|
3002
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
3003
|
+
this.options,
|
|
3004
|
+
this.storage
|
|
3005
|
+
);
|
|
3006
|
+
const isRejection = isRejectionError(error);
|
|
3007
|
+
if (isRejection) {
|
|
3008
|
+
import_analytics4.analytics.track("mmconnect_connection_rejected", __spreadProps(__spreadValues({}, baseProps), {
|
|
3009
|
+
transport_type: transportType
|
|
3010
|
+
}));
|
|
3011
|
+
} else {
|
|
3012
|
+
import_analytics4.analytics.track("mmconnect_connection_failed", __spreadProps(__spreadValues({}, baseProps), {
|
|
3013
|
+
transport_type: transportType
|
|
3014
|
+
}));
|
|
3015
|
+
}
|
|
3016
|
+
} catch (e) {
|
|
3017
|
+
logger2("Error tracking connection failed/rejected event", error);
|
|
3018
|
+
}
|
|
3019
|
+
throw error;
|
|
3020
|
+
}));
|
|
3021
|
+
});
|
|
3022
|
+
};
|
|
3023
|
+
var MultichainSDK = _MultichainSDK;
|
|
2761
3024
|
|
|
2762
3025
|
// src/store/index.ts
|
|
2763
3026
|
var uuid = __toESM(require("uuid"));
|
|
@@ -2938,54 +3201,11 @@ var Store = class extends StoreClient {
|
|
|
2938
3201
|
}
|
|
2939
3202
|
};
|
|
2940
3203
|
|
|
2941
|
-
// src/ui/
|
|
3204
|
+
// src/ui/ModalFactory.ts
|
|
2942
3205
|
var import_onboarding = __toESM(require("@metamask/onboarding"));
|
|
2943
3206
|
init_domain();
|
|
2944
|
-
|
|
2945
|
-
// src/ui/qr.ts
|
|
2946
|
-
var encodeQRImpl = null;
|
|
2947
|
-
function preloadQR() {
|
|
2948
|
-
return __async(this, null, function* () {
|
|
2949
|
-
if (encodeQRImpl) {
|
|
2950
|
-
return;
|
|
2951
|
-
}
|
|
2952
|
-
const mod = yield import("@paulmillr/qr");
|
|
2953
|
-
encodeQRImpl = mod.default;
|
|
2954
|
-
});
|
|
2955
|
-
}
|
|
2956
|
-
|
|
2957
|
-
// src/ui/index.ts
|
|
2958
3207
|
init_utils();
|
|
2959
|
-
var
|
|
2960
|
-
function preload() {
|
|
2961
|
-
return __async(this, null, function* () {
|
|
2962
|
-
if (false) {
|
|
2963
|
-
__instance != null ? __instance : __instance = yield null.then((loader) => __async(null, null, function* () {
|
|
2964
|
-
if (typeof (loader == null ? void 0 : loader.defineCustomElements) === "function") {
|
|
2965
|
-
loader.defineCustomElements();
|
|
2966
|
-
}
|
|
2967
|
-
return Promise.resolve(loader);
|
|
2968
|
-
})).catch((error) => __async(null, null, function* () {
|
|
2969
|
-
console.error(`Gracefully Failed to load modal customElements:`, error);
|
|
2970
|
-
return Promise.resolve(void 0);
|
|
2971
|
-
}));
|
|
2972
|
-
} else {
|
|
2973
|
-
const dynamicImport = (0, eval)("import");
|
|
2974
|
-
__instance != null ? __instance : __instance = yield dynamicImport(
|
|
2975
|
-
"@metamask/multichain-ui/dist/loader/index.js"
|
|
2976
|
-
).then((loader) => __async(null, null, function* () {
|
|
2977
|
-
if (typeof (loader == null ? void 0 : loader.defineCustomElements) === "function") {
|
|
2978
|
-
loader.defineCustomElements();
|
|
2979
|
-
}
|
|
2980
|
-
return Promise.resolve(loader);
|
|
2981
|
-
})).catch((error) => __async(null, null, function* () {
|
|
2982
|
-
console.error(`Gracefully Failed to load modal customElements:`, error);
|
|
2983
|
-
return Promise.resolve(void 0);
|
|
2984
|
-
}));
|
|
2985
|
-
}
|
|
2986
|
-
});
|
|
2987
|
-
}
|
|
2988
|
-
var ModalFactory = class {
|
|
3208
|
+
var BaseModalFactory = class {
|
|
2989
3209
|
/**
|
|
2990
3210
|
* Creates a new modal factory instance.
|
|
2991
3211
|
*
|
|
@@ -3007,8 +3227,8 @@ var ModalFactory = class {
|
|
|
3007
3227
|
}
|
|
3008
3228
|
unload(error) {
|
|
3009
3229
|
return __async(this, null, function* () {
|
|
3010
|
-
var
|
|
3011
|
-
(
|
|
3230
|
+
var _a2, _b;
|
|
3231
|
+
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
3012
3232
|
yield (_b = this.successCallback) == null ? void 0 : _b.call(this, error);
|
|
3013
3233
|
});
|
|
3014
3234
|
}
|
|
@@ -3074,15 +3294,17 @@ var ModalFactory = class {
|
|
|
3074
3294
|
onStartDesktopOnboarding() {
|
|
3075
3295
|
new import_onboarding.default().startOnboarding();
|
|
3076
3296
|
}
|
|
3077
|
-
renderInstallModal(showInstallModal, createConnectionRequest, successCallback) {
|
|
3297
|
+
renderInstallModal(showInstallModal, createConnectionRequest, successCallback, onDisplayUri) {
|
|
3078
3298
|
return __async(this, null, function* () {
|
|
3079
|
-
var
|
|
3080
|
-
(
|
|
3081
|
-
yield
|
|
3299
|
+
var _a2, _b;
|
|
3300
|
+
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
3301
|
+
yield this.preload();
|
|
3082
3302
|
this.successCallback = successCallback;
|
|
3303
|
+
this.displayUriCallback = onDisplayUri;
|
|
3083
3304
|
const parentElement = this.getMountedContainer();
|
|
3084
3305
|
const connectionRequest = yield createConnectionRequest();
|
|
3085
3306
|
const qrCodeLink = this.createConnectionDeeplink(connectionRequest);
|
|
3307
|
+
(_b = this.displayUriCallback) == null ? void 0 : _b.call(this, qrCodeLink);
|
|
3086
3308
|
const modal = new this.options.InstallModal({
|
|
3087
3309
|
expiresIn: (connectionRequest.sessionRequest.expiresAt - Date.now()) / 1e3,
|
|
3088
3310
|
connectionRequest,
|
|
@@ -3091,11 +3313,15 @@ var ModalFactory = class {
|
|
|
3091
3313
|
link: qrCodeLink,
|
|
3092
3314
|
sdkVersion: getVersion(),
|
|
3093
3315
|
generateQRCode: (request) => __async(this, null, function* () {
|
|
3094
|
-
|
|
3316
|
+
var _a3;
|
|
3317
|
+
const newLink = this.createConnectionDeeplink(request);
|
|
3318
|
+
(_a3 = this.displayUriCallback) == null ? void 0 : _a3.call(this, newLink);
|
|
3319
|
+
return newLink;
|
|
3095
3320
|
}),
|
|
3096
3321
|
onClose: this.onCloseModal.bind(this),
|
|
3097
3322
|
startDesktopOnboarding: this.onStartDesktopOnboarding.bind(this),
|
|
3098
|
-
createConnectionRequest
|
|
3323
|
+
createConnectionRequest,
|
|
3324
|
+
onDisplayUri: this.displayUriCallback
|
|
3099
3325
|
});
|
|
3100
3326
|
this.modal = modal;
|
|
3101
3327
|
modal.mount();
|
|
@@ -3103,9 +3329,9 @@ var ModalFactory = class {
|
|
|
3103
3329
|
}
|
|
3104
3330
|
renderOTPCodeModal(createOTPCode, successCallback, updateOTPCode) {
|
|
3105
3331
|
return __async(this, null, function* () {
|
|
3106
|
-
var
|
|
3107
|
-
(
|
|
3108
|
-
yield
|
|
3332
|
+
var _a2;
|
|
3333
|
+
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
3334
|
+
yield this.preload();
|
|
3109
3335
|
this.successCallback = successCallback;
|
|
3110
3336
|
const container = this.getMountedContainer();
|
|
3111
3337
|
const otpCode = yield createOTPCode();
|
|
@@ -3123,9 +3349,31 @@ var ModalFactory = class {
|
|
|
3123
3349
|
}
|
|
3124
3350
|
};
|
|
3125
3351
|
|
|
3352
|
+
// src/ui/index.ts
|
|
3353
|
+
function preload() {
|
|
3354
|
+
return __async(this, null, function* () {
|
|
3355
|
+
if (typeof document === "undefined") {
|
|
3356
|
+
return;
|
|
3357
|
+
}
|
|
3358
|
+
try {
|
|
3359
|
+
const { defineCustomElements } = yield import("@metamask/multichain-ui/loader");
|
|
3360
|
+
yield defineCustomElements();
|
|
3361
|
+
} catch (error) {
|
|
3362
|
+
console.error("Failed to load customElements:", error);
|
|
3363
|
+
}
|
|
3364
|
+
});
|
|
3365
|
+
}
|
|
3366
|
+
var ModalFactory = class extends BaseModalFactory {
|
|
3367
|
+
preload() {
|
|
3368
|
+
return __async(this, null, function* () {
|
|
3369
|
+
return preload();
|
|
3370
|
+
});
|
|
3371
|
+
}
|
|
3372
|
+
};
|
|
3373
|
+
|
|
3126
3374
|
// src/index.browser.ts
|
|
3127
3375
|
init_domain();
|
|
3128
|
-
var
|
|
3376
|
+
var createMultichainClient = (options) => __async(null, null, function* () {
|
|
3129
3377
|
const uiModules = yield Promise.resolve().then(() => (init_web(), web_exports));
|
|
3130
3378
|
let storage;
|
|
3131
3379
|
if (!options.storage) {
|