@metamask/connect-multichain 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -13
- package/README.md +1 -1
- package/dist/browser/es/connect-multichain.d.mts +4 -6
- package/dist/browser/es/connect-multichain.mjs +593 -588
- package/dist/browser/es/connect-multichain.mjs.map +1 -1
- package/dist/browser/es/metafile-esm.json +1 -1
- package/dist/browser/iife/connect-multichain.d.ts +4 -6
- package/dist/browser/iife/connect-multichain.js +3821 -2109
- package/dist/browser/iife/connect-multichain.js.map +1 -1
- package/dist/browser/iife/metafile-iife.json +1 -1
- package/dist/browser/umd/connect-multichain.d.ts +4 -6
- package/dist/browser/umd/connect-multichain.js +593 -588
- package/dist/browser/umd/connect-multichain.js.map +1 -1
- package/dist/browser/umd/metafile-cjs.json +1 -1
- package/dist/node/cjs/connect-multichain.d.ts +4 -6
- package/dist/node/cjs/connect-multichain.js +594 -600
- package/dist/node/cjs/connect-multichain.js.map +1 -1
- package/dist/node/cjs/metafile-cjs.json +1 -1
- package/dist/node/es/connect-multichain.d.mts +4 -6
- package/dist/node/es/connect-multichain.mjs +593 -599
- package/dist/node/es/connect-multichain.mjs.map +1 -1
- package/dist/node/es/metafile-esm.json +1 -1
- package/dist/react-native/es/connect-multichain.d.mts +4 -6
- package/dist/react-native/es/connect-multichain.mjs +580 -584
- package/dist/react-native/es/connect-multichain.mjs.map +1 -1
- package/dist/react-native/es/metafile-esm.json +1 -1
- package/dist/src/domain/multichain/types.d.ts +2 -4
- package/dist/src/domain/multichain/types.d.ts.map +1 -1
- package/dist/src/multichain/index.d.ts +3 -22
- package/dist/src/multichain/index.d.ts.map +1 -1
- package/dist/src/multichain/index.js +422 -424
- package/dist/src/multichain/index.js.map +1 -1
- package/dist/src/multichain/rpc/requestRouter.js +17 -19
- package/dist/src/multichain/rpc/requestRouter.js.map +1 -1
- package/dist/src/multichain/transports/default/index.d.ts +2 -0
- package/dist/src/multichain/transports/default/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/default/index.js +6 -0
- package/dist/src/multichain/transports/default/index.js.map +1 -1
- package/dist/src/multichain/transports/mwp/index.d.ts +2 -1
- package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/mwp/index.js +41 -16
- package/dist/src/multichain/transports/mwp/index.js.map +1 -1
- package/dist/src/ui/index.d.ts +2 -6
- package/dist/src/ui/index.d.ts.map +1 -1
- package/dist/src/ui/index.js +8 -49
- package/dist/src/ui/index.js.map +1 -1
- package/dist/src/ui/modals/node/install.js +2 -2
- package/dist/src/ui/modals/node/install.js.map +1 -1
- package/dist/src/ui/preload.native.d.ts +5 -0
- package/dist/src/ui/preload.native.d.ts.map +1 -0
- package/dist/src/ui/preload.native.js +18 -0
- package/dist/src/ui/preload.native.js.map +1 -0
- package/dist/src/ui/preload.web.d.ts +5 -0
- package/dist/src/ui/preload.web.d.ts.map +1 -0
- package/dist/src/ui/{qr.js → preload.web.js} +13 -18
- package/dist/src/ui/preload.web.js.map +1 -0
- package/dist/types/connect-multichain.d.ts +4 -6
- package/package.json +7 -7
- package/dist/src/ui/qr.d.ts +0 -3
- package/dist/src/ui/qr.d.ts.map +0 -1
- package/dist/src/ui/qr.js.map +0 -1
|
@@ -235,8 +235,8 @@ var init_logger = __esm({
|
|
|
235
235
|
debug.enable(namespace);
|
|
236
236
|
};
|
|
237
237
|
isEnabled = (namespace, storage) => __async(null, null, function* () {
|
|
238
|
-
var
|
|
239
|
-
if ("process" in globalThis && ((
|
|
238
|
+
var _a2;
|
|
239
|
+
if ("process" in globalThis && ((_a2 = process == null ? void 0 : process.env) == null ? void 0 : _a2.DEBUG)) {
|
|
240
240
|
const { DEBUG } = process.env;
|
|
241
241
|
return isNamespaceEnabled(DEBUG, namespace);
|
|
242
242
|
}
|
|
@@ -406,35 +406,35 @@ var init_multichain = __esm({
|
|
|
406
406
|
// src/domain/platform/index.ts
|
|
407
407
|
import Bowser from "bowser";
|
|
408
408
|
function isNotBrowser() {
|
|
409
|
-
var
|
|
409
|
+
var _a2;
|
|
410
410
|
if (typeof window === "undefined") {
|
|
411
411
|
return true;
|
|
412
412
|
}
|
|
413
413
|
if (!(window == null ? void 0 : window.navigator)) {
|
|
414
414
|
return true;
|
|
415
415
|
}
|
|
416
|
-
if (typeof global !== "undefined" && ((
|
|
416
|
+
if (typeof global !== "undefined" && ((_a2 = global == null ? void 0 : global.navigator) == null ? void 0 : _a2.product) === "ReactNative") {
|
|
417
417
|
return true;
|
|
418
418
|
}
|
|
419
419
|
return (navigator == null ? void 0 : navigator.product) === "ReactNative";
|
|
420
420
|
}
|
|
421
421
|
function isReactNative() {
|
|
422
|
-
var
|
|
422
|
+
var _a2;
|
|
423
423
|
const hasWindowNavigator = typeof window !== "undefined" && window.navigator !== void 0;
|
|
424
424
|
const nav = hasWindowNavigator ? window.navigator : void 0;
|
|
425
425
|
if (!nav) {
|
|
426
426
|
return false;
|
|
427
427
|
}
|
|
428
|
-
return hasWindowNavigator && ((
|
|
428
|
+
return hasWindowNavigator && ((_a2 = window.navigator) == null ? void 0 : _a2.product) === "ReactNative";
|
|
429
429
|
}
|
|
430
430
|
function isMetaMaskMobileWebView() {
|
|
431
431
|
return typeof window !== "undefined" && // @ts-expect-error ReactNativeWebView should be defined
|
|
432
432
|
Boolean(window.ReactNativeWebView) && Boolean(window.navigator.userAgent.endsWith("MetaMaskMobile"));
|
|
433
433
|
}
|
|
434
434
|
function isMobile() {
|
|
435
|
-
var
|
|
435
|
+
var _a2, _b;
|
|
436
436
|
const browser = Bowser.parse(window.navigator.userAgent);
|
|
437
|
-
return ((
|
|
437
|
+
return ((_a2 = browser == null ? void 0 : browser.platform) == null ? void 0 : _a2.type) === "mobile" || ((_b = browser == null ? void 0 : browser.platform) == null ? void 0 : _b.type) === "tablet";
|
|
438
438
|
}
|
|
439
439
|
function getPlatformType() {
|
|
440
440
|
if (isReactNative()) {
|
|
@@ -452,11 +452,11 @@ function getPlatformType() {
|
|
|
452
452
|
return "web-desktop" /* DesktopWeb */;
|
|
453
453
|
}
|
|
454
454
|
function isMetamaskExtensionInstalled() {
|
|
455
|
-
var
|
|
455
|
+
var _a2;
|
|
456
456
|
if (typeof window === "undefined") {
|
|
457
457
|
return false;
|
|
458
458
|
}
|
|
459
|
-
return Boolean((
|
|
459
|
+
return Boolean((_a2 = window.ethereum) == null ? void 0 : _a2.isMetaMask);
|
|
460
460
|
}
|
|
461
461
|
function isSecure() {
|
|
462
462
|
const platformType = getPlatformType();
|
|
@@ -487,8 +487,8 @@ var init_platform = __esm({
|
|
|
487
487
|
return new Promise((resolve) => {
|
|
488
488
|
const providers = [];
|
|
489
489
|
const handler = (event) => {
|
|
490
|
-
var
|
|
491
|
-
if ((_b = (
|
|
490
|
+
var _a2, _b;
|
|
491
|
+
if ((_b = (_a2 = event == null ? void 0 : event.detail) == null ? void 0 : _a2.info) == null ? void 0 : _b.rdns) {
|
|
492
492
|
providers.push(event.detail);
|
|
493
493
|
}
|
|
494
494
|
};
|
|
@@ -498,8 +498,8 @@ var init_platform = __esm({
|
|
|
498
498
|
window.removeEventListener("eip6963:announceProvider", handler);
|
|
499
499
|
const hasMetaMask = providers.some(
|
|
500
500
|
(provider) => {
|
|
501
|
-
var
|
|
502
|
-
return (_b = (
|
|
501
|
+
var _a2, _b;
|
|
502
|
+
return (_b = (_a2 = provider == null ? void 0 : provider.info) == null ? void 0 : _a2.rdns) == null ? void 0 : _b.startsWith("io.metamask");
|
|
503
503
|
}
|
|
504
504
|
);
|
|
505
505
|
resolve(hasMetaMask);
|
|
@@ -603,8 +603,8 @@ function compressString(str) {
|
|
|
603
603
|
return base64Encode(binaryString);
|
|
604
604
|
}
|
|
605
605
|
function getDappId(dapp) {
|
|
606
|
-
var
|
|
607
|
-
return (
|
|
606
|
+
var _a2;
|
|
607
|
+
return (_a2 = dapp.url) != null ? _a2 : dapp.name;
|
|
608
608
|
}
|
|
609
609
|
function openDeeplink(options, deeplink, universalLink) {
|
|
610
610
|
const { mobile } = options;
|
|
@@ -634,10 +634,10 @@ function getOptionalScopes(scopes) {
|
|
|
634
634
|
);
|
|
635
635
|
}
|
|
636
636
|
function setupDappMetadata(options) {
|
|
637
|
-
var
|
|
637
|
+
var _a2, _b;
|
|
638
638
|
const platform = getPlatformType();
|
|
639
639
|
const isBrowser = platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */ || platform === "in-app-browser" /* MetaMaskMobileWebview */;
|
|
640
|
-
if (!((
|
|
640
|
+
if (!((_a2 = options.dapp) == null ? void 0 : _a2.name)) {
|
|
641
641
|
throw new Error("You must provide dapp name");
|
|
642
642
|
}
|
|
643
643
|
if (isBrowser) {
|
|
@@ -708,17 +708,17 @@ function getValidAccounts(caipAccountIds) {
|
|
|
708
708
|
);
|
|
709
709
|
}
|
|
710
710
|
function addValidAccounts(optionalScopes, validAccounts) {
|
|
711
|
-
var
|
|
711
|
+
var _a2;
|
|
712
712
|
if (!optionalScopes || !(validAccounts == null ? void 0 : validAccounts.length)) {
|
|
713
713
|
return optionalScopes;
|
|
714
714
|
}
|
|
715
715
|
const result = Object.fromEntries(
|
|
716
716
|
Object.entries(optionalScopes).map(([scope, scopeData]) => {
|
|
717
|
-
var
|
|
717
|
+
var _a3, _b, _c;
|
|
718
718
|
return [
|
|
719
719
|
scope,
|
|
720
720
|
{
|
|
721
|
-
methods: [...(
|
|
721
|
+
methods: [...(_a3 = scopeData == null ? void 0 : scopeData.methods) != null ? _a3 : []],
|
|
722
722
|
notifications: [...(_b = scopeData == null ? void 0 : scopeData.notifications) != null ? _b : []],
|
|
723
723
|
accounts: [...(_c = scopeData == null ? void 0 : scopeData.accounts) != null ? _c : []]
|
|
724
724
|
}
|
|
@@ -732,7 +732,7 @@ function addValidAccounts(optionalScopes, validAccounts) {
|
|
|
732
732
|
if (!accountsByChain.has(chainKey)) {
|
|
733
733
|
accountsByChain.set(chainKey, []);
|
|
734
734
|
}
|
|
735
|
-
(
|
|
735
|
+
(_a2 = accountsByChain.get(chainKey)) == null ? void 0 : _a2.push(accountId);
|
|
736
736
|
}
|
|
737
737
|
for (const [scopeKey, scopeData] of Object.entries(result)) {
|
|
738
738
|
if (!(scopeData == null ? void 0 : scopeData.accounts)) {
|
|
@@ -762,7 +762,7 @@ var init_utils = __esm({
|
|
|
762
762
|
"use strict";
|
|
763
763
|
init_domain();
|
|
764
764
|
extractFavicon = () => {
|
|
765
|
-
var
|
|
765
|
+
var _a2;
|
|
766
766
|
if (typeof document === "undefined") {
|
|
767
767
|
return void 0;
|
|
768
768
|
}
|
|
@@ -770,7 +770,7 @@ var init_utils = __esm({
|
|
|
770
770
|
const nodeList = document.getElementsByTagName("link");
|
|
771
771
|
for (let i = 0; i < nodeList.length; i++) {
|
|
772
772
|
if (nodeList[i].getAttribute("rel") === "icon" || nodeList[i].getAttribute("rel") === "shortcut icon") {
|
|
773
|
-
favicon = (
|
|
773
|
+
favicon = (_a2 = nodeList[i].getAttribute("href")) != null ? _a2 : void 0;
|
|
774
774
|
}
|
|
775
775
|
}
|
|
776
776
|
return favicon;
|
|
@@ -780,25 +780,25 @@ var init_utils = __esm({
|
|
|
780
780
|
|
|
781
781
|
// src/multichain/utils/analytics.ts
|
|
782
782
|
function isRejectionError(error) {
|
|
783
|
-
var
|
|
783
|
+
var _a2, _b;
|
|
784
784
|
if (typeof error !== "object" || error === null) {
|
|
785
785
|
return false;
|
|
786
786
|
}
|
|
787
787
|
const errorObj = error;
|
|
788
788
|
const errorCode = errorObj.code;
|
|
789
|
-
const errorMessage = (_b = (
|
|
789
|
+
const errorMessage = (_b = (_a2 = errorObj.message) == null ? void 0 : _a2.toLowerCase()) != null ? _b : "";
|
|
790
790
|
return errorCode === 4001 || // User rejected request (common EIP-1193 code)
|
|
791
791
|
errorCode === 4100 || // Unauthorized (common rejection code)
|
|
792
792
|
errorMessage.includes("reject") || errorMessage.includes("denied") || errorMessage.includes("cancel") || errorMessage.includes("user");
|
|
793
793
|
}
|
|
794
794
|
function getBaseAnalyticsProperties(options, storage) {
|
|
795
795
|
return __async(this, null, function* () {
|
|
796
|
-
var
|
|
796
|
+
var _a2, _b;
|
|
797
797
|
const version = getVersion();
|
|
798
798
|
const dappId = getDappId(options.dapp);
|
|
799
799
|
const platform = getPlatformType();
|
|
800
800
|
const anonId = yield storage.getAnonId();
|
|
801
|
-
const integrationType = (_b = (
|
|
801
|
+
const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "unknown" /* UNKNOWN */;
|
|
802
802
|
return {
|
|
803
803
|
mmconnect_version: version,
|
|
804
804
|
dapp_id: dappId,
|
|
@@ -810,11 +810,11 @@ function getBaseAnalyticsProperties(options, storage) {
|
|
|
810
810
|
}
|
|
811
811
|
function getWalletActionAnalyticsProperties(options, storage, invokeOptions) {
|
|
812
812
|
return __async(this, null, function* () {
|
|
813
|
-
var
|
|
813
|
+
var _a2, _b;
|
|
814
814
|
const version = getVersion();
|
|
815
815
|
const dappId = getDappId(options.dapp);
|
|
816
816
|
const anonId = yield storage.getAnonId();
|
|
817
|
-
const integrationType = (_b = (
|
|
817
|
+
const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "unknown";
|
|
818
818
|
return {
|
|
819
819
|
mmconnect_version: version,
|
|
820
820
|
dapp_id: dappId,
|
|
@@ -1140,8 +1140,8 @@ var RpcClient = class {
|
|
|
1140
1140
|
});
|
|
1141
1141
|
}
|
|
1142
1142
|
getRpcEndpoint(scope) {
|
|
1143
|
-
var
|
|
1144
|
-
const supportedNetworks = (_c = (_b = (
|
|
1143
|
+
var _a2, _b, _c;
|
|
1144
|
+
const supportedNetworks = (_c = (_b = (_a2 = this.config) == null ? void 0 : _a2.api) == null ? void 0 : _b.supportedNetworks) != null ? _c : {};
|
|
1145
1145
|
const rpcEndpoint = supportedNetworks[scope];
|
|
1146
1146
|
if (!rpcEndpoint) {
|
|
1147
1147
|
throw new MissingRpcEndpointErr(`No RPC endpoint found for scope ${scope}`);
|
|
@@ -1245,13 +1245,18 @@ var RequestRouter = class {
|
|
|
1245
1245
|
const secure = isSecure();
|
|
1246
1246
|
const shouldOpenDeeplink = secure && !showInstallModal;
|
|
1247
1247
|
if (shouldOpenDeeplink) {
|
|
1248
|
-
setTimeout(() => {
|
|
1248
|
+
setTimeout(() => __async(this, null, function* () {
|
|
1249
|
+
const session = yield this.transport.getActiveSession();
|
|
1250
|
+
if (!session) {
|
|
1251
|
+
throw new Error("No active session found");
|
|
1252
|
+
}
|
|
1253
|
+
const url = `${METAMASK_DEEPLINK_BASE}/mwp?id=${encodeURIComponent(session.id)}`;
|
|
1249
1254
|
if (mobile == null ? void 0 : mobile.preferredOpenLink) {
|
|
1250
|
-
mobile.preferredOpenLink(
|
|
1255
|
+
mobile.preferredOpenLink(url, "_self");
|
|
1251
1256
|
} else {
|
|
1252
|
-
openDeeplink(this.config,
|
|
1257
|
+
openDeeplink(this.config, url, METAMASK_CONNECT_BASE_URL);
|
|
1253
1258
|
}
|
|
1254
|
-
}, 10);
|
|
1259
|
+
}), 10);
|
|
1255
1260
|
}
|
|
1256
1261
|
const response = yield request;
|
|
1257
1262
|
if (response.error) {
|
|
@@ -1291,24 +1296,17 @@ var RequestRouter = class {
|
|
|
1291
1296
|
_RequestRouter_instances = new WeakSet();
|
|
1292
1297
|
withAnalyticsTracking_fn = function(options, execute) {
|
|
1293
1298
|
return __async(this, null, function* () {
|
|
1294
|
-
|
|
1295
|
-
if ((_a = this.config.analytics) == null ? void 0 : _a.enabled) {
|
|
1296
|
-
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRequested_fn).call(this, options);
|
|
1297
|
-
}
|
|
1299
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRequested_fn).call(this, options);
|
|
1298
1300
|
try {
|
|
1299
1301
|
const result = yield execute();
|
|
1300
|
-
|
|
1301
|
-
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionSucceeded_fn).call(this, options);
|
|
1302
|
-
}
|
|
1302
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionSucceeded_fn).call(this, options);
|
|
1303
1303
|
return result;
|
|
1304
1304
|
} catch (error) {
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options);
|
|
1311
|
-
}
|
|
1305
|
+
const isRejection = isRejectionError(error);
|
|
1306
|
+
if (isRejection) {
|
|
1307
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRejected_fn).call(this, options);
|
|
1308
|
+
} else {
|
|
1309
|
+
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options);
|
|
1312
1310
|
}
|
|
1313
1311
|
throw new RPCInvokeMethodErr(error.message);
|
|
1314
1312
|
}
|
|
@@ -1370,11 +1368,11 @@ var DefaultTransport = class {
|
|
|
1370
1368
|
id: requestId
|
|
1371
1369
|
}, payload);
|
|
1372
1370
|
return new Promise((resolve, reject) => {
|
|
1373
|
-
var
|
|
1371
|
+
var _a2;
|
|
1374
1372
|
const timeout = setTimeout(() => {
|
|
1375
1373
|
__privateGet(this, _pendingRequests).delete(requestId);
|
|
1376
1374
|
reject(new Error("Request timeout"));
|
|
1377
|
-
}, (
|
|
1375
|
+
}, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : __privateGet(this, _defaultRequestOptions).timeout);
|
|
1378
1376
|
__privateGet(this, _pendingRequests).set(requestId, {
|
|
1379
1377
|
resolve: (response) => {
|
|
1380
1378
|
resolve(response);
|
|
@@ -1398,7 +1396,7 @@ var DefaultTransport = class {
|
|
|
1398
1396
|
}
|
|
1399
1397
|
connect(options) {
|
|
1400
1398
|
return __async(this, null, function* () {
|
|
1401
|
-
var
|
|
1399
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1402
1400
|
__privateMethod(this, _DefaultTransport_instances, setupMessageListener_fn).call(this);
|
|
1403
1401
|
yield __privateGet(this, _transport).connect();
|
|
1404
1402
|
const sessionRequest = yield this.request(
|
|
@@ -1411,7 +1409,7 @@ var DefaultTransport = class {
|
|
|
1411
1409
|
let walletSession = sessionRequest.result;
|
|
1412
1410
|
if (walletSession && options && !options.forceRequest) {
|
|
1413
1411
|
const currentScopes = Object.keys(
|
|
1414
|
-
(
|
|
1412
|
+
(_a2 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a2 : {}
|
|
1415
1413
|
);
|
|
1416
1414
|
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
1417
1415
|
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
@@ -1500,6 +1498,9 @@ var DefaultTransport = class {
|
|
|
1500
1498
|
__privateGet(this, _notificationCallbacks).delete(callback);
|
|
1501
1499
|
};
|
|
1502
1500
|
}
|
|
1501
|
+
getActiveSession() {
|
|
1502
|
+
throw new Error("getActiveSession is purposely not implemented for the DefaultTransport");
|
|
1503
|
+
}
|
|
1503
1504
|
};
|
|
1504
1505
|
_notificationCallbacks = new WeakMap();
|
|
1505
1506
|
_transport = new WeakMap();
|
|
@@ -1522,16 +1523,16 @@ notifyCallbacks_fn = function(data) {
|
|
|
1522
1523
|
}
|
|
1523
1524
|
};
|
|
1524
1525
|
isMetamaskProviderEvent_fn = function(event) {
|
|
1525
|
-
var
|
|
1526
|
-
return ((_b = (
|
|
1526
|
+
var _a2, _b;
|
|
1527
|
+
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
|
|
1527
1528
|
event.origin === location.origin;
|
|
1528
1529
|
};
|
|
1529
1530
|
handleResponse_fn = function(event) {
|
|
1530
|
-
var
|
|
1531
|
+
var _a2, _b;
|
|
1531
1532
|
if (!__privateMethod(this, _DefaultTransport_instances, isMetamaskProviderEvent_fn).call(this, event)) {
|
|
1532
1533
|
return;
|
|
1533
1534
|
}
|
|
1534
|
-
const responseData = (_b = (
|
|
1535
|
+
const responseData = (_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.data;
|
|
1535
1536
|
if (typeof responseData === "object" && responseData !== null && "method" in responseData) {
|
|
1536
1537
|
return;
|
|
1537
1538
|
}
|
|
@@ -1553,11 +1554,11 @@ handleResponse_fn = function(event) {
|
|
|
1553
1554
|
}
|
|
1554
1555
|
};
|
|
1555
1556
|
handleNotification_fn = function(event) {
|
|
1556
|
-
var
|
|
1557
|
+
var _a2, _b;
|
|
1557
1558
|
if (!__privateMethod(this, _DefaultTransport_instances, isMetamaskProviderEvent_fn).call(this, event)) {
|
|
1558
1559
|
return;
|
|
1559
1560
|
}
|
|
1560
|
-
const responseData = (_b = (
|
|
1561
|
+
const responseData = (_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.data;
|
|
1561
1562
|
if (typeof responseData === "object" && responseData.method === "metamask_chainChanged" || responseData.method === "metamask_accountsChanged") {
|
|
1562
1563
|
__privateMethod(this, _DefaultTransport_instances, notifyCallbacks_fn).call(this, responseData);
|
|
1563
1564
|
}
|
|
@@ -1685,7 +1686,7 @@ var MWPTransport = class {
|
|
|
1685
1686
|
}
|
|
1686
1687
|
onResumeSuccess(resumeResolve, resumeReject, options) {
|
|
1687
1688
|
return __async(this, null, function* () {
|
|
1688
|
-
var
|
|
1689
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1689
1690
|
try {
|
|
1690
1691
|
const sessionRequest = yield this.request({
|
|
1691
1692
|
method: "wallet_getSession"
|
|
@@ -1696,7 +1697,7 @@ var MWPTransport = class {
|
|
|
1696
1697
|
let walletSession = sessionRequest.result;
|
|
1697
1698
|
if (walletSession && options) {
|
|
1698
1699
|
const currentScopes = Object.keys(
|
|
1699
|
-
(
|
|
1700
|
+
(_a2 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a2 : {}
|
|
1700
1701
|
);
|
|
1701
1702
|
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
1702
1703
|
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
@@ -1761,10 +1762,10 @@ var MWPTransport = class {
|
|
|
1761
1762
|
return cachedWalletSession;
|
|
1762
1763
|
}
|
|
1763
1764
|
return new Promise((resolve, reject) => {
|
|
1764
|
-
var
|
|
1765
|
+
var _a2;
|
|
1765
1766
|
const timeout = setTimeout(() => {
|
|
1766
1767
|
this.rejectRequest(request.id, new TransportTimeoutError());
|
|
1767
|
-
}, (
|
|
1768
|
+
}, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : this.options.requestTimeout);
|
|
1768
1769
|
this.pendingRequests.set(request.id, {
|
|
1769
1770
|
request,
|
|
1770
1771
|
method: request.method,
|
|
@@ -1784,38 +1785,33 @@ var MWPTransport = class {
|
|
|
1784
1785
|
}
|
|
1785
1786
|
connect(options) {
|
|
1786
1787
|
return __async(this, null, function* () {
|
|
1787
|
-
const { dappClient
|
|
1788
|
-
const
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
const [activeSession] = yield sessionStore.list();
|
|
1792
|
-
if (activeSession) {
|
|
1793
|
-
logger("active session found", activeSession);
|
|
1794
|
-
session = activeSession;
|
|
1795
|
-
}
|
|
1796
|
-
} catch (e) {
|
|
1788
|
+
const { dappClient } = this;
|
|
1789
|
+
const session = yield this.getActiveSession();
|
|
1790
|
+
if (session) {
|
|
1791
|
+
logger("active session found", session);
|
|
1797
1792
|
}
|
|
1798
1793
|
let timeout;
|
|
1794
|
+
let initialConnectionMessageHandler;
|
|
1799
1795
|
const connectionPromise = new Promise((resolve, reject) => {
|
|
1800
1796
|
let connection;
|
|
1801
1797
|
if (session) {
|
|
1802
1798
|
connection = new Promise((resumeResolve, resumeReject) => {
|
|
1803
|
-
var
|
|
1799
|
+
var _a2;
|
|
1804
1800
|
if (this.dappClient.state === "CONNECTED") {
|
|
1805
1801
|
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
1806
1802
|
} else {
|
|
1807
1803
|
this.dappClient.once("connected", () => __async(this, null, function* () {
|
|
1808
1804
|
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
1809
1805
|
}));
|
|
1810
|
-
dappClient.resume((
|
|
1806
|
+
dappClient.resume((_a2 = session == null ? void 0 : session.id) != null ? _a2 : "");
|
|
1811
1807
|
}
|
|
1812
1808
|
});
|
|
1813
1809
|
} else {
|
|
1814
1810
|
connection = new Promise(
|
|
1815
1811
|
(resolveConnection, rejectConnection) => {
|
|
1816
|
-
var
|
|
1812
|
+
var _a2, _b;
|
|
1817
1813
|
const optionalScopes = addValidAccounts(
|
|
1818
|
-
getOptionalScopes((
|
|
1814
|
+
getOptionalScopes((_a2 = options == null ? void 0 : options.scopes) != null ? _a2 : []),
|
|
1819
1815
|
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
1820
1816
|
);
|
|
1821
1817
|
const sessionRequest = {
|
|
@@ -1827,12 +1823,18 @@ var MWPTransport = class {
|
|
|
1827
1823
|
method: "wallet_createSession",
|
|
1828
1824
|
params: sessionRequest
|
|
1829
1825
|
};
|
|
1830
|
-
|
|
1826
|
+
initialConnectionMessageHandler = (message) => __async(this, null, function* () {
|
|
1831
1827
|
if (typeof message === "object" && message !== null) {
|
|
1832
1828
|
if ("data" in message) {
|
|
1833
1829
|
const messagePayload = message.data;
|
|
1834
1830
|
if (messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged") {
|
|
1835
1831
|
if (messagePayload.error) {
|
|
1832
|
+
if (initialConnectionMessageHandler) {
|
|
1833
|
+
this.dappClient.off(
|
|
1834
|
+
"message",
|
|
1835
|
+
initialConnectionMessageHandler
|
|
1836
|
+
);
|
|
1837
|
+
}
|
|
1836
1838
|
return rejectConnection(messagePayload.error);
|
|
1837
1839
|
}
|
|
1838
1840
|
yield this.storeWalletSession(
|
|
@@ -1844,14 +1846,23 @@ var MWPTransport = class {
|
|
|
1844
1846
|
}
|
|
1845
1847
|
}
|
|
1846
1848
|
}
|
|
1847
|
-
})
|
|
1849
|
+
});
|
|
1850
|
+
this.dappClient.on("message", initialConnectionMessageHandler);
|
|
1848
1851
|
dappClient.connect({
|
|
1849
1852
|
mode: "trusted",
|
|
1850
1853
|
initialPayload: {
|
|
1851
1854
|
name: MULTICHAIN_PROVIDER_STREAM_NAME,
|
|
1852
1855
|
data: request
|
|
1853
1856
|
}
|
|
1854
|
-
}).catch(
|
|
1857
|
+
}).catch((error) => {
|
|
1858
|
+
if (initialConnectionMessageHandler) {
|
|
1859
|
+
this.dappClient.off(
|
|
1860
|
+
"message",
|
|
1861
|
+
initialConnectionMessageHandler
|
|
1862
|
+
);
|
|
1863
|
+
}
|
|
1864
|
+
rejectConnection(error);
|
|
1865
|
+
});
|
|
1855
1866
|
}
|
|
1856
1867
|
);
|
|
1857
1868
|
}
|
|
@@ -1860,10 +1871,16 @@ var MWPTransport = class {
|
|
|
1860
1871
|
}, this.options.connectionTimeout);
|
|
1861
1872
|
connection.then(resolve).catch(reject);
|
|
1862
1873
|
});
|
|
1863
|
-
return connectionPromise.
|
|
1874
|
+
return connectionPromise.catch((error) => {
|
|
1875
|
+
throw error;
|
|
1876
|
+
}).finally(() => {
|
|
1864
1877
|
if (timeout) {
|
|
1865
1878
|
clearTimeout(timeout);
|
|
1866
1879
|
}
|
|
1880
|
+
if (initialConnectionMessageHandler) {
|
|
1881
|
+
this.dappClient.off("message", initialConnectionMessageHandler);
|
|
1882
|
+
initialConnectionMessageHandler = void 0;
|
|
1883
|
+
}
|
|
1867
1884
|
});
|
|
1868
1885
|
});
|
|
1869
1886
|
}
|
|
@@ -1926,7 +1943,7 @@ var MWPTransport = class {
|
|
|
1926
1943
|
}
|
|
1927
1944
|
getCachedResponse(request) {
|
|
1928
1945
|
return __async(this, null, function* () {
|
|
1929
|
-
var
|
|
1946
|
+
var _a2;
|
|
1930
1947
|
if (request.method === "wallet_getSession") {
|
|
1931
1948
|
const walletGetSession = yield this.kvstore.get(SESSION_STORE_KEY);
|
|
1932
1949
|
if (walletGetSession) {
|
|
@@ -1934,7 +1951,7 @@ var MWPTransport = class {
|
|
|
1934
1951
|
return {
|
|
1935
1952
|
id: request.id,
|
|
1936
1953
|
jsonrpc: "2.0",
|
|
1937
|
-
result: (
|
|
1954
|
+
result: (_a2 = walletSession.params) != null ? _a2 : walletSession.result,
|
|
1938
1955
|
// "what?... why walletSession.params?.."
|
|
1939
1956
|
method: request.method
|
|
1940
1957
|
};
|
|
@@ -1998,10 +2015,10 @@ var MWPTransport = class {
|
|
|
1998
2015
|
yield this.attemptResumeSession();
|
|
1999
2016
|
}
|
|
2000
2017
|
return new Promise((resolve, reject) => {
|
|
2001
|
-
var
|
|
2018
|
+
var _a2;
|
|
2002
2019
|
const timeout = setTimeout(() => {
|
|
2003
2020
|
this.rejectRequest(request.id, new TransportTimeoutError());
|
|
2004
|
-
}, (
|
|
2021
|
+
}, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : this.options.requestTimeout);
|
|
2005
2022
|
this.pendingRequests.set(request.id, {
|
|
2006
2023
|
request,
|
|
2007
2024
|
method: request.method,
|
|
@@ -2025,6 +2042,19 @@ var MWPTransport = class {
|
|
|
2025
2042
|
this.notificationCallbacks.delete(callback);
|
|
2026
2043
|
};
|
|
2027
2044
|
}
|
|
2045
|
+
getActiveSession() {
|
|
2046
|
+
return __async(this, null, function* () {
|
|
2047
|
+
const { kvstore } = this;
|
|
2048
|
+
const sessionStore = new SessionStore(kvstore);
|
|
2049
|
+
try {
|
|
2050
|
+
const [activeSession] = yield sessionStore.list();
|
|
2051
|
+
return activeSession;
|
|
2052
|
+
} catch (error) {
|
|
2053
|
+
logger("error getting active session", error);
|
|
2054
|
+
return void 0;
|
|
2055
|
+
}
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2028
2058
|
};
|
|
2029
2059
|
|
|
2030
2060
|
// src/multichain/transports/mwp/KeyManager.ts
|
|
@@ -2057,73 +2087,74 @@ var keymanager = new KeyManager();
|
|
|
2057
2087
|
// src/multichain/index.ts
|
|
2058
2088
|
init_utils();
|
|
2059
2089
|
var logger2 = createLogger("metamask-sdk:core");
|
|
2060
|
-
var
|
|
2090
|
+
var _a, _provider, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo, _MultichainSDK_instances, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn, init_fn, createDappClient_fn, setupMWP_fn, onBeforeUnload_fn, createBeforeUnloadListener_fn, renderInstallModalAsync_fn, showInstallModal_fn, setupDefaultTransport_fn, deeplinkConnect_fn, handleConnection_fn;
|
|
2091
|
+
var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
2061
2092
|
constructor(options) {
|
|
2062
|
-
var
|
|
2093
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
2063
2094
|
const withDappMetadata = setupDappMetadata(options);
|
|
2064
|
-
const integrationType = ((
|
|
2095
|
+
const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "direct";
|
|
2065
2096
|
const allOptions = __spreadProps(__spreadValues({}, withDappMetadata), {
|
|
2066
2097
|
ui: __spreadProps(__spreadValues({}, withDappMetadata.ui), {
|
|
2067
|
-
preferExtension: (
|
|
2068
|
-
showInstallModal: (
|
|
2069
|
-
headless: (
|
|
2098
|
+
preferExtension: (_c = withDappMetadata.ui.preferExtension) != null ? _c : true,
|
|
2099
|
+
showInstallModal: (_d = withDappMetadata.ui.showInstallModal) != null ? _d : false,
|
|
2100
|
+
headless: (_e = withDappMetadata.ui.headless) != null ? _e : false
|
|
2070
2101
|
}),
|
|
2071
|
-
analytics: __spreadProps(__spreadValues({}, (
|
|
2072
|
-
enabled: (_g = (_f = options.analytics) == null ? void 0 : _f.enabled) != null ? _g : true,
|
|
2102
|
+
analytics: __spreadProps(__spreadValues({}, (_f = options.analytics) != null ? _f : {}), {
|
|
2073
2103
|
integrationType
|
|
2074
2104
|
})
|
|
2075
2105
|
});
|
|
2076
2106
|
super(allOptions);
|
|
2077
|
-
this
|
|
2078
|
-
this
|
|
2079
|
-
this
|
|
2080
|
-
this
|
|
2107
|
+
__privateAdd(this, _MultichainSDK_instances);
|
|
2108
|
+
__privateAdd(this, _provider);
|
|
2109
|
+
__privateAdd(this, _transport2);
|
|
2110
|
+
__privateAdd(this, _dappClient);
|
|
2111
|
+
__privateAdd(this, _beforeUnloadListener);
|
|
2112
|
+
this._state = "pending";
|
|
2113
|
+
__privateAdd(this, _listener);
|
|
2114
|
+
__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}`);
|
|
2081
2115
|
}
|
|
2082
2116
|
get state() {
|
|
2083
|
-
return this.
|
|
2117
|
+
return this._state;
|
|
2084
2118
|
}
|
|
2085
2119
|
set state(value) {
|
|
2086
|
-
var
|
|
2087
|
-
this.
|
|
2088
|
-
(_b = (
|
|
2120
|
+
var _a2, _b;
|
|
2121
|
+
this._state = value;
|
|
2122
|
+
(_b = (_a2 = this.options.transport) == null ? void 0 : _a2.onNotification) == null ? void 0 : _b.call(_a2, {
|
|
2089
2123
|
method: "stateChanged",
|
|
2090
2124
|
params: value
|
|
2091
2125
|
});
|
|
2092
2126
|
}
|
|
2093
2127
|
get provider() {
|
|
2094
|
-
if (!this
|
|
2095
|
-
this
|
|
2096
|
-
return this
|
|
2128
|
+
if (!__privateGet(this, _provider) && __privateGet(this, _transport2)) {
|
|
2129
|
+
__privateSet(this, _provider, getMultichainClient({ transport: __privateGet(this, _transport2) }));
|
|
2130
|
+
return __privateGet(this, _provider);
|
|
2097
2131
|
}
|
|
2098
|
-
if (!this
|
|
2132
|
+
if (!__privateGet(this, _provider)) {
|
|
2099
2133
|
throw new Error("Provider not initialized, establish connection first");
|
|
2100
2134
|
}
|
|
2101
|
-
return this
|
|
2135
|
+
return __privateGet(this, _provider);
|
|
2102
2136
|
}
|
|
2103
2137
|
get transport() {
|
|
2104
|
-
if (!this
|
|
2138
|
+
if (!__privateGet(this, _transport2)) {
|
|
2105
2139
|
throw new Error("Transport not initialized, establish connection first");
|
|
2106
2140
|
}
|
|
2107
|
-
return this
|
|
2141
|
+
return __privateGet(this, _transport2);
|
|
2108
2142
|
}
|
|
2109
2143
|
get dappClient() {
|
|
2110
|
-
if (!this
|
|
2144
|
+
if (!__privateGet(this, _dappClient)) {
|
|
2111
2145
|
throw new Error("DappClient not initialized, establish connection first");
|
|
2112
2146
|
}
|
|
2113
|
-
return this
|
|
2147
|
+
return __privateGet(this, _dappClient);
|
|
2114
2148
|
}
|
|
2115
2149
|
get storage() {
|
|
2116
2150
|
return this.options.storage;
|
|
2117
2151
|
}
|
|
2118
2152
|
get transportType() {
|
|
2119
|
-
return this
|
|
2120
|
-
}
|
|
2121
|
-
get sdkInfo() {
|
|
2122
|
-
var _a;
|
|
2123
|
-
return `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(_a = this.options.dapp.url) != null ? _a : this.options.dapp.name} dAppTitle/${this.options.dapp.name}`;
|
|
2153
|
+
return __privateGet(this, _transport2) instanceof MWPTransport ? "mwp" /* MWP */ : "browser" /* Browser */;
|
|
2124
2154
|
}
|
|
2125
2155
|
static create(options) {
|
|
2126
2156
|
return __async(this, null, function* () {
|
|
2157
|
+
var _a2;
|
|
2127
2158
|
const instance = new _MultichainSDK(options);
|
|
2128
2159
|
const isEnabled2 = yield isEnabled(
|
|
2129
2160
|
"metamask-sdk:core",
|
|
@@ -2132,353 +2163,16 @@ var MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2132
2163
|
if (isEnabled2) {
|
|
2133
2164
|
enableDebug("metamask-sdk:core");
|
|
2134
2165
|
}
|
|
2135
|
-
yield instance.
|
|
2166
|
+
yield __privateMethod(_a2 = instance, _MultichainSDK_instances, init_fn).call(_a2);
|
|
2136
2167
|
return instance;
|
|
2137
2168
|
});
|
|
2138
2169
|
}
|
|
2139
|
-
setupAnalytics() {
|
|
2140
|
-
return __async(this, null, function* () {
|
|
2141
|
-
var _a, _b;
|
|
2142
|
-
if (!((_a = this.options.analytics) == null ? void 0 : _a.enabled)) {
|
|
2143
|
-
return;
|
|
2144
|
-
}
|
|
2145
|
-
const platform = getPlatformType();
|
|
2146
|
-
const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
|
|
2147
|
-
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
2148
|
-
if (!isBrowser && !isReactNative2) {
|
|
2149
|
-
return;
|
|
2150
|
-
}
|
|
2151
|
-
const version = getVersion();
|
|
2152
|
-
const dappId = getDappId(this.options.dapp);
|
|
2153
|
-
const anonId = yield this.storage.getAnonId();
|
|
2154
|
-
const { integrationType } = (_b = this.options.analytics) != null ? _b : {
|
|
2155
|
-
integrationType: ""
|
|
2156
|
-
};
|
|
2157
|
-
analytics2.setGlobalProperty("mmconnect_version", version);
|
|
2158
|
-
analytics2.setGlobalProperty("dapp_id", dappId);
|
|
2159
|
-
analytics2.setGlobalProperty("anon_id", anonId);
|
|
2160
|
-
analytics2.setGlobalProperty("platform", platform);
|
|
2161
|
-
analytics2.setGlobalProperty("integration_type", integrationType);
|
|
2162
|
-
analytics2.enable();
|
|
2163
|
-
});
|
|
2164
|
-
}
|
|
2165
|
-
onTransportNotification(payload) {
|
|
2166
|
-
return __async(this, null, function* () {
|
|
2167
|
-
var _a;
|
|
2168
|
-
if (typeof payload === "object" && payload !== null && "method" in payload) {
|
|
2169
|
-
this.emit(payload.method, (_a = payload.params) != null ? _a : payload.result);
|
|
2170
|
-
}
|
|
2171
|
-
});
|
|
2172
|
-
}
|
|
2173
|
-
getStoredTransport() {
|
|
2174
|
-
return __async(this, null, function* () {
|
|
2175
|
-
const transportType = yield this.storage.getTransport();
|
|
2176
|
-
const hasExtensionInstalled = yield hasExtension();
|
|
2177
|
-
if (transportType) {
|
|
2178
|
-
if (transportType === "browser" /* Browser */) {
|
|
2179
|
-
if (hasExtensionInstalled) {
|
|
2180
|
-
const apiTransport = new DefaultTransport();
|
|
2181
|
-
this.__transport = apiTransport;
|
|
2182
|
-
this.listener = apiTransport.onNotification(
|
|
2183
|
-
this.onTransportNotification.bind(this)
|
|
2184
|
-
);
|
|
2185
|
-
return apiTransport;
|
|
2186
|
-
}
|
|
2187
|
-
} else if (transportType === "mwp" /* MWP */) {
|
|
2188
|
-
const { adapter: kvstore } = this.options.storage;
|
|
2189
|
-
const dappClient = yield this.createDappClient();
|
|
2190
|
-
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2191
|
-
this.__dappClient = dappClient;
|
|
2192
|
-
this.__transport = apiTransport;
|
|
2193
|
-
this.listener = apiTransport.onNotification(
|
|
2194
|
-
this.onTransportNotification.bind(this)
|
|
2195
|
-
);
|
|
2196
|
-
return apiTransport;
|
|
2197
|
-
}
|
|
2198
|
-
yield this.storage.removeTransport();
|
|
2199
|
-
}
|
|
2200
|
-
return void 0;
|
|
2201
|
-
});
|
|
2202
|
-
}
|
|
2203
|
-
setupTransport() {
|
|
2204
|
-
return __async(this, null, function* () {
|
|
2205
|
-
const transport = yield this.getStoredTransport();
|
|
2206
|
-
if (transport) {
|
|
2207
|
-
if (!this.transport.isConnected()) {
|
|
2208
|
-
this.state = "connecting";
|
|
2209
|
-
yield this.transport.connect();
|
|
2210
|
-
}
|
|
2211
|
-
this.state = "connected";
|
|
2212
|
-
if (this.transport instanceof MWPTransport) {
|
|
2213
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2214
|
-
} else {
|
|
2215
|
-
yield this.storage.setTransport("browser" /* Browser */);
|
|
2216
|
-
}
|
|
2217
|
-
} else {
|
|
2218
|
-
this.state = "loaded";
|
|
2219
|
-
}
|
|
2220
|
-
});
|
|
2221
|
-
}
|
|
2222
|
-
init() {
|
|
2223
|
-
return __async(this, null, function* () {
|
|
2224
|
-
var _a, _b;
|
|
2225
|
-
try {
|
|
2226
|
-
if (typeof window !== "undefined" && ((_a = window.mmsdk) == null ? void 0 : _a.isInitialized)) {
|
|
2227
|
-
logger2("MetaMaskSDK: init already initialized");
|
|
2228
|
-
} else {
|
|
2229
|
-
yield this.setupAnalytics();
|
|
2230
|
-
yield this.setupTransport();
|
|
2231
|
-
if ((_b = this.options.analytics) == null ? void 0 : _b.enabled) {
|
|
2232
|
-
try {
|
|
2233
|
-
const baseProps = yield getBaseAnalyticsProperties(
|
|
2234
|
-
this.options,
|
|
2235
|
-
this.storage
|
|
2236
|
-
);
|
|
2237
|
-
analytics2.track("mmconnect_initialized", baseProps);
|
|
2238
|
-
} catch (error) {
|
|
2239
|
-
logger2("Error tracking initialized event", error);
|
|
2240
|
-
}
|
|
2241
|
-
}
|
|
2242
|
-
if (typeof window !== "undefined") {
|
|
2243
|
-
window.mmsdk = this;
|
|
2244
|
-
}
|
|
2245
|
-
}
|
|
2246
|
-
} catch (error) {
|
|
2247
|
-
yield this.storage.removeTransport();
|
|
2248
|
-
this.state = "pending";
|
|
2249
|
-
logger2("MetaMaskSDK error during initialization", error);
|
|
2250
|
-
}
|
|
2251
|
-
});
|
|
2252
|
-
}
|
|
2253
|
-
createDappClient() {
|
|
2254
|
-
return __async(this, null, function* () {
|
|
2255
|
-
const { adapter: kvstore } = this.options.storage;
|
|
2256
|
-
const sessionstore = new SessionStore2(kvstore);
|
|
2257
|
-
const websocket = (
|
|
2258
|
-
// eslint-disable-next-line no-negated-condition
|
|
2259
|
-
typeof window !== "undefined" ? WebSocket : (yield import("ws")).WebSocket
|
|
2260
|
-
);
|
|
2261
|
-
const transport = yield WebSocketTransport.create({
|
|
2262
|
-
url: MWP_RELAY_URL,
|
|
2263
|
-
kvstore,
|
|
2264
|
-
websocket
|
|
2265
|
-
});
|
|
2266
|
-
const dappClient = new DappClient({ transport, sessionstore, keymanager });
|
|
2267
|
-
return dappClient;
|
|
2268
|
-
});
|
|
2269
|
-
}
|
|
2270
|
-
setupMWP() {
|
|
2271
|
-
return __async(this, null, function* () {
|
|
2272
|
-
if (this.__transport instanceof MWPTransport) {
|
|
2273
|
-
return;
|
|
2274
|
-
}
|
|
2275
|
-
const { adapter: kvstore } = this.options.storage;
|
|
2276
|
-
const dappClient = yield this.createDappClient();
|
|
2277
|
-
this.__dappClient = dappClient;
|
|
2278
|
-
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2279
|
-
this.__transport = apiTransport;
|
|
2280
|
-
this.listener = this.transport.onNotification(
|
|
2281
|
-
this.onTransportNotification.bind(this)
|
|
2282
|
-
);
|
|
2283
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2284
|
-
});
|
|
2285
|
-
}
|
|
2286
|
-
onBeforeUnload() {
|
|
2287
|
-
return __async(this, null, function* () {
|
|
2288
|
-
var _a;
|
|
2289
|
-
if ((_a = this.options.ui.factory.modal) == null ? void 0 : _a.isMounted) {
|
|
2290
|
-
yield this.storage.removeTransport();
|
|
2291
|
-
}
|
|
2292
|
-
});
|
|
2293
|
-
}
|
|
2294
|
-
createBeforeUnloadListener() {
|
|
2295
|
-
if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
|
|
2296
|
-
window.addEventListener("beforeunload", this.onBeforeUnload.bind(this));
|
|
2297
|
-
}
|
|
2298
|
-
return () => {
|
|
2299
|
-
if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined") {
|
|
2300
|
-
window.removeEventListener(
|
|
2301
|
-
"beforeunload",
|
|
2302
|
-
this.onBeforeUnload.bind(this)
|
|
2303
|
-
);
|
|
2304
|
-
}
|
|
2305
|
-
};
|
|
2306
|
-
}
|
|
2307
|
-
showInstallModal(desktopPreferred, scopes, caipAccountIds) {
|
|
2308
|
-
return __async(this, null, function* () {
|
|
2309
|
-
var _a;
|
|
2310
|
-
(_a = this.__beforeUnloadListener) != null ? _a : this.__beforeUnloadListener = this.createBeforeUnloadListener();
|
|
2311
|
-
return new Promise((resolve, reject) => {
|
|
2312
|
-
this.options.ui.factory.renderInstallModal(
|
|
2313
|
-
desktopPreferred,
|
|
2314
|
-
() => __async(this, null, function* () {
|
|
2315
|
-
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
2316
|
-
yield this.dappClient.disconnect();
|
|
2317
|
-
}
|
|
2318
|
-
return new Promise((resolveConnectionRequest) => {
|
|
2319
|
-
this.dappClient.on(
|
|
2320
|
-
"session_request",
|
|
2321
|
-
(sessionRequest) => {
|
|
2322
|
-
resolveConnectionRequest({
|
|
2323
|
-
sessionRequest,
|
|
2324
|
-
metadata: {
|
|
2325
|
-
dapp: this.options.dapp,
|
|
2326
|
-
sdk: {
|
|
2327
|
-
version: getVersion(),
|
|
2328
|
-
platform: getPlatformType()
|
|
2329
|
-
}
|
|
2330
|
-
}
|
|
2331
|
-
});
|
|
2332
|
-
}
|
|
2333
|
-
);
|
|
2334
|
-
this.transport.connect({ scopes, caipAccountIds }).then(() => {
|
|
2335
|
-
var _a2;
|
|
2336
|
-
this.options.ui.factory.unload();
|
|
2337
|
-
(_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
|
|
2338
|
-
this.state = "connected";
|
|
2339
|
-
return this.storage.setTransport("mwp" /* MWP */);
|
|
2340
|
-
}).catch((error) => {
|
|
2341
|
-
if (error instanceof ProtocolError) {
|
|
2342
|
-
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
2343
|
-
this.state = "disconnected";
|
|
2344
|
-
reject(error);
|
|
2345
|
-
}
|
|
2346
|
-
} else {
|
|
2347
|
-
this.state = "disconnected";
|
|
2348
|
-
reject(error);
|
|
2349
|
-
}
|
|
2350
|
-
});
|
|
2351
|
-
});
|
|
2352
|
-
}),
|
|
2353
|
-
(error) => __async(this, null, function* () {
|
|
2354
|
-
if (!error) {
|
|
2355
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2356
|
-
resolve();
|
|
2357
|
-
} else {
|
|
2358
|
-
yield this.storage.removeTransport();
|
|
2359
|
-
reject(error);
|
|
2360
|
-
}
|
|
2361
|
-
})
|
|
2362
|
-
);
|
|
2363
|
-
});
|
|
2364
|
-
});
|
|
2365
|
-
}
|
|
2366
|
-
setupDefaultTransport() {
|
|
2367
|
-
return __async(this, null, function* () {
|
|
2368
|
-
this.state = "connecting";
|
|
2369
|
-
yield this.storage.setTransport("browser" /* Browser */);
|
|
2370
|
-
const transport = new DefaultTransport();
|
|
2371
|
-
this.listener = transport.onNotification(
|
|
2372
|
-
this.onTransportNotification.bind(this)
|
|
2373
|
-
);
|
|
2374
|
-
this.__transport = transport;
|
|
2375
|
-
return transport;
|
|
2376
|
-
});
|
|
2377
|
-
}
|
|
2378
|
-
deeplinkConnect(scopes, caipAccountIds) {
|
|
2379
|
-
return __async(this, null, function* () {
|
|
2380
|
-
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
2381
|
-
this.dappClient.on("message", (payload) => {
|
|
2382
|
-
var _a, _b, _c;
|
|
2383
|
-
const data = payload.data;
|
|
2384
|
-
if (typeof data === "object" && data !== null) {
|
|
2385
|
-
if ("method" in data && data.method === "wallet_createSession") {
|
|
2386
|
-
if (data.error) {
|
|
2387
|
-
this.state = "loaded";
|
|
2388
|
-
return reject(data.error);
|
|
2389
|
-
}
|
|
2390
|
-
const session = (_a = data.params) != null ? _a : data.result;
|
|
2391
|
-
if (session) {
|
|
2392
|
-
(_c = (_b = this.options.transport) == null ? void 0 : _b.onNotification) == null ? void 0 : _c.call(_b, payload.data);
|
|
2393
|
-
this.emit("wallet_sessionChanged", session);
|
|
2394
|
-
}
|
|
2395
|
-
}
|
|
2396
|
-
}
|
|
2397
|
-
});
|
|
2398
|
-
let timeout;
|
|
2399
|
-
if (!this.transport.isConnected()) {
|
|
2400
|
-
this.dappClient.once(
|
|
2401
|
-
"session_request",
|
|
2402
|
-
(sessionRequest) => {
|
|
2403
|
-
var _a;
|
|
2404
|
-
const connectionRequest = {
|
|
2405
|
-
sessionRequest,
|
|
2406
|
-
metadata: {
|
|
2407
|
-
dapp: this.options.dapp,
|
|
2408
|
-
sdk: { version: getVersion(), platform: getPlatformType() }
|
|
2409
|
-
}
|
|
2410
|
-
};
|
|
2411
|
-
const deeplink = this.options.ui.factory.createDeeplink(connectionRequest);
|
|
2412
|
-
const universalLink = this.options.ui.factory.createUniversalLink(connectionRequest);
|
|
2413
|
-
if ((_a = this.options.mobile) == null ? void 0 : _a.preferredOpenLink) {
|
|
2414
|
-
this.options.mobile.preferredOpenLink(deeplink, "_self");
|
|
2415
|
-
} else {
|
|
2416
|
-
openDeeplink(this.options, deeplink, universalLink);
|
|
2417
|
-
}
|
|
2418
|
-
}
|
|
2419
|
-
);
|
|
2420
|
-
}
|
|
2421
|
-
this.transport.connect({ scopes, caipAccountIds }).then(resolve).catch((error) => {
|
|
2422
|
-
this.storage.removeTransport();
|
|
2423
|
-
reject(error);
|
|
2424
|
-
}).finally(() => {
|
|
2425
|
-
if (timeout) {
|
|
2426
|
-
clearTimeout(timeout);
|
|
2427
|
-
}
|
|
2428
|
-
});
|
|
2429
|
-
}));
|
|
2430
|
-
});
|
|
2431
|
-
}
|
|
2432
|
-
handleConnection(promise, scopes, transportType) {
|
|
2433
|
-
return __async(this, null, function* () {
|
|
2434
|
-
this.state = "connecting";
|
|
2435
|
-
return promise.then(() => __async(this, null, function* () {
|
|
2436
|
-
var _a;
|
|
2437
|
-
this.state = "connected";
|
|
2438
|
-
if ((_a = this.options.analytics) == null ? void 0 : _a.enabled) {
|
|
2439
|
-
try {
|
|
2440
|
-
const baseProps = yield getBaseAnalyticsProperties(
|
|
2441
|
-
this.options,
|
|
2442
|
-
this.storage
|
|
2443
|
-
);
|
|
2444
|
-
analytics2.track("mmconnect_connection_established", __spreadProps(__spreadValues({}, baseProps), {
|
|
2445
|
-
transport_type: transportType,
|
|
2446
|
-
user_permissioned_chains: scopes
|
|
2447
|
-
}));
|
|
2448
|
-
} catch (error) {
|
|
2449
|
-
logger2("Error tracking connection_established event", error);
|
|
2450
|
-
}
|
|
2451
|
-
}
|
|
2452
|
-
})).catch((error) => __async(this, null, function* () {
|
|
2453
|
-
var _a;
|
|
2454
|
-
this.state = "disconnected";
|
|
2455
|
-
if ((_a = this.options.analytics) == null ? void 0 : _a.enabled) {
|
|
2456
|
-
try {
|
|
2457
|
-
const baseProps = yield getBaseAnalyticsProperties(
|
|
2458
|
-
this.options,
|
|
2459
|
-
this.storage
|
|
2460
|
-
);
|
|
2461
|
-
const isRejection = isRejectionError(error);
|
|
2462
|
-
if (isRejection) {
|
|
2463
|
-
analytics2.track("mmconnect_connection_rejected", __spreadProps(__spreadValues({}, baseProps), {
|
|
2464
|
-
transport_type: transportType
|
|
2465
|
-
}));
|
|
2466
|
-
} else {
|
|
2467
|
-
analytics2.track("mmconnect_connection_failed", __spreadProps(__spreadValues({}, baseProps), {
|
|
2468
|
-
transport_type: transportType
|
|
2469
|
-
}));
|
|
2470
|
-
}
|
|
2471
|
-
} catch (e) {
|
|
2472
|
-
logger2("Error tracking connection failed/rejected event", error);
|
|
2473
|
-
}
|
|
2474
|
-
}
|
|
2475
|
-
return Promise.reject(error);
|
|
2476
|
-
}));
|
|
2477
|
-
});
|
|
2478
|
-
}
|
|
2479
2170
|
connect(scopes, caipAccountIds, forceRequest) {
|
|
2480
2171
|
return __async(this, null, function* () {
|
|
2481
|
-
var
|
|
2172
|
+
var _a2;
|
|
2173
|
+
if (this.state !== "connected") {
|
|
2174
|
+
yield this.disconnect();
|
|
2175
|
+
}
|
|
2482
2176
|
const { ui } = this.options;
|
|
2483
2177
|
const platformType = getPlatformType();
|
|
2484
2178
|
const isWeb = platformType === "in-app-browser" /* MetaMaskMobileWebview */ || platformType === "web-desktop" /* DesktopWeb */;
|
|
@@ -2491,96 +2185,72 @@ var MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2491
2185
|
} else {
|
|
2492
2186
|
transportType = "mwp" /* MWP */;
|
|
2493
2187
|
}
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
this.options.api.supportedNetworks
|
|
2502
|
-
);
|
|
2503
|
-
analytics2.track("mmconnect_connection_initiated", __spreadProps(__spreadValues({}, baseProps), {
|
|
2504
|
-
transport_type: transportType,
|
|
2505
|
-
dapp_configured_chains: dappConfiguredChains,
|
|
2506
|
-
dapp_requested_chains: scopes
|
|
2507
|
-
}));
|
|
2508
|
-
} catch (error) {
|
|
2509
|
-
logger2("Error tracking connection_initiated event", error);
|
|
2510
|
-
}
|
|
2511
|
-
}
|
|
2512
|
-
if (((_b = this.__transport) == null ? void 0 : _b.isConnected()) && !secure) {
|
|
2513
|
-
return this.handleConnection(
|
|
2514
|
-
this.__transport.connect({ scopes, caipAccountIds, forceRequest }).then(() => {
|
|
2515
|
-
if (this.__transport instanceof MWPTransport) {
|
|
2516
|
-
return this.storage.setTransport("mwp" /* MWP */);
|
|
2517
|
-
} else {
|
|
2518
|
-
return this.storage.setTransport("browser" /* Browser */);
|
|
2519
|
-
}
|
|
2520
|
-
}),
|
|
2521
|
-
scopes,
|
|
2522
|
-
transportType
|
|
2188
|
+
try {
|
|
2189
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2190
|
+
this.options,
|
|
2191
|
+
this.storage
|
|
2192
|
+
);
|
|
2193
|
+
const dappConfiguredChains = Object.keys(
|
|
2194
|
+
this.options.api.supportedNetworks
|
|
2523
2195
|
);
|
|
2196
|
+
analytics2.track("mmconnect_connection_initiated", __spreadProps(__spreadValues({}, baseProps), {
|
|
2197
|
+
transport_type: transportType,
|
|
2198
|
+
dapp_configured_chains: dappConfiguredChains,
|
|
2199
|
+
dapp_requested_chains: scopes
|
|
2200
|
+
}));
|
|
2201
|
+
} catch (error) {
|
|
2202
|
+
logger2("Error tracking connection_initiated event", error);
|
|
2203
|
+
}
|
|
2204
|
+
if (((_a2 = __privateGet(this, _transport2)) == null ? void 0 : _a2.isConnected()) && !secure) {
|
|
2205
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateGet(this, _transport2).connect({ scopes, caipAccountIds, forceRequest }).then(() => __async(this, null, function* () {
|
|
2206
|
+
if (__privateGet(this, _transport2) instanceof MWPTransport) {
|
|
2207
|
+
return this.storage.setTransport("mwp" /* MWP */);
|
|
2208
|
+
}
|
|
2209
|
+
return this.storage.setTransport("browser" /* Browser */);
|
|
2210
|
+
})), scopes, transportType);
|
|
2524
2211
|
}
|
|
2525
2212
|
if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
|
|
2526
|
-
const defaultTransport = yield this.
|
|
2527
|
-
return this.
|
|
2528
|
-
defaultTransport.connect({ scopes, caipAccountIds, forceRequest }),
|
|
2529
|
-
scopes,
|
|
2530
|
-
transportType
|
|
2531
|
-
);
|
|
2213
|
+
const defaultTransport = yield __privateMethod(this, _MultichainSDK_instances, setupDefaultTransport_fn).call(this);
|
|
2214
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, forceRequest }), scopes, transportType);
|
|
2532
2215
|
}
|
|
2533
2216
|
if (isWeb && hasExtensionInstalled && preferExtension) {
|
|
2534
|
-
const defaultTransport = yield this.
|
|
2535
|
-
return this.
|
|
2536
|
-
defaultTransport.connect({ scopes, caipAccountIds, forceRequest }),
|
|
2537
|
-
scopes,
|
|
2538
|
-
transportType
|
|
2539
|
-
);
|
|
2217
|
+
const defaultTransport = yield __privateMethod(this, _MultichainSDK_instances, setupDefaultTransport_fn).call(this);
|
|
2218
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, forceRequest }), scopes, transportType);
|
|
2540
2219
|
}
|
|
2541
|
-
yield this.
|
|
2220
|
+
yield __privateMethod(this, _MultichainSDK_instances, setupMWP_fn).call(this);
|
|
2542
2221
|
const shouldShowInstallModal = hasExtensionInstalled ? showInstallModal : !preferExtension || showInstallModal;
|
|
2543
2222
|
if (secure && !shouldShowInstallModal) {
|
|
2544
|
-
return this.
|
|
2545
|
-
this.deeplinkConnect(scopes, caipAccountIds),
|
|
2546
|
-
scopes,
|
|
2547
|
-
transportType
|
|
2548
|
-
);
|
|
2223
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateMethod(this, _MultichainSDK_instances, deeplinkConnect_fn).call(this, scopes, caipAccountIds), scopes, transportType);
|
|
2549
2224
|
}
|
|
2550
|
-
return this.
|
|
2551
|
-
this.showInstallModal(shouldShowInstallModal, scopes, caipAccountIds),
|
|
2552
|
-
scopes,
|
|
2553
|
-
transportType
|
|
2554
|
-
);
|
|
2225
|
+
return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateMethod(this, _MultichainSDK_instances, showInstallModal_fn).call(this, shouldShowInstallModal, scopes, caipAccountIds), scopes, transportType);
|
|
2555
2226
|
});
|
|
2556
2227
|
}
|
|
2557
2228
|
emit(event, args) {
|
|
2558
|
-
var
|
|
2559
|
-
(_b = (
|
|
2229
|
+
var _a2, _b;
|
|
2230
|
+
(_b = (_a2 = this.options.transport) == null ? void 0 : _a2.onNotification) == null ? void 0 : _b.call(_a2, { method: event, params: args });
|
|
2560
2231
|
super.emit(event, args);
|
|
2561
2232
|
}
|
|
2562
2233
|
disconnect() {
|
|
2563
2234
|
return __async(this, null, function* () {
|
|
2564
|
-
var
|
|
2565
|
-
(
|
|
2566
|
-
(_b = this
|
|
2567
|
-
yield (_c = this
|
|
2235
|
+
var _a2, _b, _c;
|
|
2236
|
+
yield (_a2 = __privateGet(this, _listener)) == null ? void 0 : _a2.call(this);
|
|
2237
|
+
(_b = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _b.call(this);
|
|
2238
|
+
yield (_c = __privateGet(this, _transport2)) == null ? void 0 : _c.disconnect();
|
|
2568
2239
|
yield this.storage.removeTransport();
|
|
2569
|
-
this.emit("wallet_sessionChanged", void 0);
|
|
2570
2240
|
this.emit("stateChanged", "disconnected");
|
|
2571
|
-
this
|
|
2572
|
-
this
|
|
2573
|
-
this
|
|
2574
|
-
this
|
|
2575
|
-
this
|
|
2241
|
+
__privateSet(this, _listener, void 0);
|
|
2242
|
+
__privateSet(this, _beforeUnloadListener, void 0);
|
|
2243
|
+
__privateSet(this, _transport2, void 0);
|
|
2244
|
+
__privateSet(this, _provider, void 0);
|
|
2245
|
+
__privateSet(this, _dappClient, void 0);
|
|
2576
2246
|
});
|
|
2577
2247
|
}
|
|
2578
2248
|
invokeMethod(request) {
|
|
2579
2249
|
return __async(this, null, function* () {
|
|
2580
|
-
var
|
|
2581
|
-
const {
|
|
2582
|
-
(
|
|
2583
|
-
const rpcClient = new RpcClient(options,
|
|
2250
|
+
var _a2;
|
|
2251
|
+
const { transport, options } = this;
|
|
2252
|
+
(_a2 = __privateGet(this, _provider)) != null ? _a2 : __privateSet(this, _provider, getMultichainClient({ transport }));
|
|
2253
|
+
const rpcClient = new RpcClient(options, __privateGet(this, _sdkInfo));
|
|
2584
2254
|
const requestRouter = new RequestRouter(transport, rpcClient, options);
|
|
2585
2255
|
return requestRouter.invokeMethod(request);
|
|
2586
2256
|
});
|
|
@@ -2592,20 +2262,381 @@ var MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2592
2262
|
const secure = isSecure();
|
|
2593
2263
|
const shouldOpenDeeplink = secure && !showInstallModal;
|
|
2594
2264
|
if (shouldOpenDeeplink) {
|
|
2595
|
-
setTimeout(() => {
|
|
2265
|
+
setTimeout(() => __async(this, null, function* () {
|
|
2266
|
+
const session = yield this.transport.getActiveSession();
|
|
2267
|
+
if (!session) {
|
|
2268
|
+
throw new Error("No active session found");
|
|
2269
|
+
}
|
|
2270
|
+
const url = `${METAMASK_DEEPLINK_BASE}/mwp?id=${encodeURIComponent(session.id)}`;
|
|
2596
2271
|
if (mobile == null ? void 0 : mobile.preferredOpenLink) {
|
|
2597
|
-
mobile.preferredOpenLink(
|
|
2272
|
+
mobile.preferredOpenLink(url, "_self");
|
|
2598
2273
|
} else {
|
|
2599
|
-
openDeeplink(
|
|
2274
|
+
openDeeplink(this.options, url, METAMASK_CONNECT_BASE_URL);
|
|
2275
|
+
}
|
|
2276
|
+
}), 10);
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
};
|
|
2280
|
+
_provider = new WeakMap();
|
|
2281
|
+
_transport2 = new WeakMap();
|
|
2282
|
+
_dappClient = new WeakMap();
|
|
2283
|
+
_beforeUnloadListener = new WeakMap();
|
|
2284
|
+
_listener = new WeakMap();
|
|
2285
|
+
_sdkInfo = new WeakMap();
|
|
2286
|
+
_MultichainSDK_instances = new WeakSet();
|
|
2287
|
+
setupAnalytics_fn = function() {
|
|
2288
|
+
return __async(this, null, function* () {
|
|
2289
|
+
var _a2;
|
|
2290
|
+
const platform = getPlatformType();
|
|
2291
|
+
const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
|
|
2292
|
+
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
2293
|
+
if (!isBrowser && !isReactNative2) {
|
|
2294
|
+
return;
|
|
2295
|
+
}
|
|
2296
|
+
const version = getVersion();
|
|
2297
|
+
const dappId = getDappId(this.options.dapp);
|
|
2298
|
+
const anonId = yield this.storage.getAnonId();
|
|
2299
|
+
const { integrationType } = (_a2 = this.options.analytics) != null ? _a2 : {
|
|
2300
|
+
integrationType: ""
|
|
2301
|
+
};
|
|
2302
|
+
analytics2.setGlobalProperty("mmconnect_version", version);
|
|
2303
|
+
analytics2.setGlobalProperty("dapp_id", dappId);
|
|
2304
|
+
analytics2.setGlobalProperty("anon_id", anonId);
|
|
2305
|
+
analytics2.setGlobalProperty("platform", platform);
|
|
2306
|
+
analytics2.setGlobalProperty("integration_type", integrationType);
|
|
2307
|
+
analytics2.enable();
|
|
2308
|
+
});
|
|
2309
|
+
};
|
|
2310
|
+
onTransportNotification_fn = function(payload) {
|
|
2311
|
+
return __async(this, null, function* () {
|
|
2312
|
+
var _a2;
|
|
2313
|
+
if (typeof payload === "object" && payload !== null && "method" in payload) {
|
|
2314
|
+
this.emit(payload.method, (_a2 = payload.params) != null ? _a2 : payload.result);
|
|
2315
|
+
}
|
|
2316
|
+
});
|
|
2317
|
+
};
|
|
2318
|
+
getStoredTransport_fn = function() {
|
|
2319
|
+
return __async(this, null, function* () {
|
|
2320
|
+
const transportType = yield this.storage.getTransport();
|
|
2321
|
+
const hasExtensionInstalled = yield hasExtension();
|
|
2322
|
+
if (transportType) {
|
|
2323
|
+
if (transportType === "browser" /* Browser */) {
|
|
2324
|
+
if (hasExtensionInstalled) {
|
|
2325
|
+
const apiTransport = new DefaultTransport();
|
|
2326
|
+
__privateSet(this, _transport2, apiTransport);
|
|
2327
|
+
__privateSet(this, _listener, apiTransport.onNotification(
|
|
2328
|
+
__privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
|
|
2329
|
+
));
|
|
2330
|
+
return apiTransport;
|
|
2331
|
+
}
|
|
2332
|
+
} else if (transportType === "mwp" /* MWP */) {
|
|
2333
|
+
const { adapter: kvstore } = this.options.storage;
|
|
2334
|
+
const dappClient = yield __privateMethod(this, _MultichainSDK_instances, createDappClient_fn).call(this);
|
|
2335
|
+
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2336
|
+
__privateSet(this, _dappClient, dappClient);
|
|
2337
|
+
__privateSet(this, _transport2, apiTransport);
|
|
2338
|
+
__privateSet(this, _listener, apiTransport.onNotification(
|
|
2339
|
+
__privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
|
|
2340
|
+
));
|
|
2341
|
+
return apiTransport;
|
|
2342
|
+
}
|
|
2343
|
+
yield this.storage.removeTransport();
|
|
2344
|
+
}
|
|
2345
|
+
return void 0;
|
|
2346
|
+
});
|
|
2347
|
+
};
|
|
2348
|
+
setupTransport_fn = function() {
|
|
2349
|
+
return __async(this, null, function* () {
|
|
2350
|
+
const transport = yield __privateMethod(this, _MultichainSDK_instances, getStoredTransport_fn).call(this);
|
|
2351
|
+
if (transport) {
|
|
2352
|
+
if (!this.transport.isConnected()) {
|
|
2353
|
+
this.state = "connecting";
|
|
2354
|
+
yield this.transport.connect();
|
|
2355
|
+
}
|
|
2356
|
+
this.state = "connected";
|
|
2357
|
+
if (this.transport instanceof MWPTransport) {
|
|
2358
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2359
|
+
} else {
|
|
2360
|
+
yield this.storage.setTransport("browser" /* Browser */);
|
|
2361
|
+
}
|
|
2362
|
+
} else {
|
|
2363
|
+
this.state = "loaded";
|
|
2364
|
+
}
|
|
2365
|
+
});
|
|
2366
|
+
};
|
|
2367
|
+
init_fn = function() {
|
|
2368
|
+
return __async(this, null, function* () {
|
|
2369
|
+
var _a2;
|
|
2370
|
+
try {
|
|
2371
|
+
if (typeof window !== "undefined" && ((_a2 = window.mmsdk) == null ? void 0 : _a2.isInitialized)) {
|
|
2372
|
+
logger2("MetaMaskSDK: init already initialized");
|
|
2373
|
+
} else {
|
|
2374
|
+
yield __privateMethod(this, _MultichainSDK_instances, setupAnalytics_fn).call(this);
|
|
2375
|
+
yield __privateMethod(this, _MultichainSDK_instances, setupTransport_fn).call(this);
|
|
2376
|
+
try {
|
|
2377
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2600
2378
|
this.options,
|
|
2601
|
-
|
|
2602
|
-
METAMASK_CONNECT_BASE_URL
|
|
2379
|
+
this.storage
|
|
2603
2380
|
);
|
|
2381
|
+
analytics2.track("mmconnect_initialized", baseProps);
|
|
2382
|
+
} catch (error) {
|
|
2383
|
+
logger2("Error tracking initialized event", error);
|
|
2384
|
+
}
|
|
2385
|
+
if (typeof window !== "undefined") {
|
|
2386
|
+
window.mmsdk = this;
|
|
2604
2387
|
}
|
|
2605
|
-
}
|
|
2388
|
+
}
|
|
2389
|
+
} catch (error) {
|
|
2390
|
+
yield this.storage.removeTransport();
|
|
2391
|
+
this.state = "pending";
|
|
2392
|
+
logger2("MetaMaskSDK error during initialization", error);
|
|
2606
2393
|
}
|
|
2607
|
-
}
|
|
2394
|
+
});
|
|
2395
|
+
};
|
|
2396
|
+
createDappClient_fn = function() {
|
|
2397
|
+
return __async(this, null, function* () {
|
|
2398
|
+
const { adapter: kvstore } = this.options.storage;
|
|
2399
|
+
const sessionstore = new SessionStore2(kvstore);
|
|
2400
|
+
const websocket = (
|
|
2401
|
+
// eslint-disable-next-line no-negated-condition
|
|
2402
|
+
typeof window !== "undefined" ? WebSocket : (yield import("ws")).WebSocket
|
|
2403
|
+
);
|
|
2404
|
+
const transport = yield WebSocketTransport.create({
|
|
2405
|
+
url: MWP_RELAY_URL,
|
|
2406
|
+
kvstore,
|
|
2407
|
+
websocket
|
|
2408
|
+
});
|
|
2409
|
+
const dappClient = new DappClient({ transport, sessionstore, keymanager });
|
|
2410
|
+
return dappClient;
|
|
2411
|
+
});
|
|
2412
|
+
};
|
|
2413
|
+
setupMWP_fn = function() {
|
|
2414
|
+
return __async(this, null, function* () {
|
|
2415
|
+
if (__privateGet(this, _transport2) instanceof MWPTransport) {
|
|
2416
|
+
return;
|
|
2417
|
+
}
|
|
2418
|
+
const { adapter: kvstore } = this.options.storage;
|
|
2419
|
+
const dappClient = yield __privateMethod(this, _MultichainSDK_instances, createDappClient_fn).call(this);
|
|
2420
|
+
__privateSet(this, _dappClient, dappClient);
|
|
2421
|
+
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2422
|
+
__privateSet(this, _transport2, apiTransport);
|
|
2423
|
+
__privateSet(this, _listener, this.transport.onNotification(
|
|
2424
|
+
__privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
|
|
2425
|
+
));
|
|
2426
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2427
|
+
});
|
|
2428
|
+
};
|
|
2429
|
+
onBeforeUnload_fn = function() {
|
|
2430
|
+
return __async(this, null, function* () {
|
|
2431
|
+
var _a2;
|
|
2432
|
+
if ((_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.isMounted) {
|
|
2433
|
+
yield this.storage.removeTransport();
|
|
2434
|
+
}
|
|
2435
|
+
});
|
|
2436
|
+
};
|
|
2437
|
+
createBeforeUnloadListener_fn = function() {
|
|
2438
|
+
if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
|
|
2439
|
+
window.addEventListener("beforeunload", __privateMethod(this, _MultichainSDK_instances, onBeforeUnload_fn).bind(this));
|
|
2440
|
+
}
|
|
2441
|
+
return () => {
|
|
2442
|
+
if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined") {
|
|
2443
|
+
window.removeEventListener(
|
|
2444
|
+
"beforeunload",
|
|
2445
|
+
__privateMethod(this, _MultichainSDK_instances, onBeforeUnload_fn).bind(this)
|
|
2446
|
+
);
|
|
2447
|
+
}
|
|
2448
|
+
};
|
|
2449
|
+
};
|
|
2450
|
+
renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds) {
|
|
2451
|
+
return __async(this, null, function* () {
|
|
2452
|
+
return new Promise((resolve, reject) => {
|
|
2453
|
+
this.options.ui.factory.renderInstallModal(
|
|
2454
|
+
desktopPreferred,
|
|
2455
|
+
() => __async(this, null, function* () {
|
|
2456
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
2457
|
+
yield this.dappClient.disconnect();
|
|
2458
|
+
}
|
|
2459
|
+
return new Promise((_resolve) => {
|
|
2460
|
+
this.dappClient.on(
|
|
2461
|
+
"session_request",
|
|
2462
|
+
(sessionRequest) => {
|
|
2463
|
+
_resolve({
|
|
2464
|
+
sessionRequest,
|
|
2465
|
+
metadata: {
|
|
2466
|
+
dapp: this.options.dapp,
|
|
2467
|
+
sdk: {
|
|
2468
|
+
version: getVersion(),
|
|
2469
|
+
platform: getPlatformType()
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
});
|
|
2473
|
+
}
|
|
2474
|
+
);
|
|
2475
|
+
(() => __async(this, null, function* () {
|
|
2476
|
+
var _a2;
|
|
2477
|
+
try {
|
|
2478
|
+
yield this.transport.connect({ scopes, caipAccountIds });
|
|
2479
|
+
yield this.options.ui.factory.unload();
|
|
2480
|
+
(_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
|
|
2481
|
+
this.state = "connected";
|
|
2482
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2483
|
+
} catch (error) {
|
|
2484
|
+
if (error instanceof ProtocolError) {
|
|
2485
|
+
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
2486
|
+
this.state = "disconnected";
|
|
2487
|
+
reject(error);
|
|
2488
|
+
}
|
|
2489
|
+
} else {
|
|
2490
|
+
this.state = "disconnected";
|
|
2491
|
+
reject(
|
|
2492
|
+
error instanceof Error ? error : new Error(String(error))
|
|
2493
|
+
);
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
}))().catch(() => {
|
|
2497
|
+
});
|
|
2498
|
+
});
|
|
2499
|
+
}),
|
|
2500
|
+
(error) => __async(this, null, function* () {
|
|
2501
|
+
if (error) {
|
|
2502
|
+
yield this.storage.removeTransport();
|
|
2503
|
+
reject(error);
|
|
2504
|
+
} else {
|
|
2505
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2506
|
+
resolve();
|
|
2507
|
+
}
|
|
2508
|
+
})
|
|
2509
|
+
).catch((error) => {
|
|
2510
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2511
|
+
});
|
|
2512
|
+
});
|
|
2513
|
+
});
|
|
2514
|
+
};
|
|
2515
|
+
showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds) {
|
|
2516
|
+
return __async(this, null, function* () {
|
|
2517
|
+
var _a2;
|
|
2518
|
+
(_a2 = __privateGet(this, _beforeUnloadListener)) != null ? _a2 : __privateSet(this, _beforeUnloadListener, __privateMethod(this, _MultichainSDK_instances, createBeforeUnloadListener_fn).call(this));
|
|
2519
|
+
yield __privateMethod(this, _MultichainSDK_instances, renderInstallModalAsync_fn).call(this, desktopPreferred, scopes, caipAccountIds);
|
|
2520
|
+
});
|
|
2521
|
+
};
|
|
2522
|
+
setupDefaultTransport_fn = function() {
|
|
2523
|
+
return __async(this, null, function* () {
|
|
2524
|
+
this.state = "connecting";
|
|
2525
|
+
yield this.storage.setTransport("browser" /* Browser */);
|
|
2526
|
+
const transport = new DefaultTransport();
|
|
2527
|
+
__privateSet(this, _listener, transport.onNotification(
|
|
2528
|
+
__privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
|
|
2529
|
+
));
|
|
2530
|
+
__privateSet(this, _transport2, transport);
|
|
2531
|
+
return transport;
|
|
2532
|
+
});
|
|
2533
|
+
};
|
|
2534
|
+
deeplinkConnect_fn = function(scopes, caipAccountIds) {
|
|
2535
|
+
return __async(this, null, function* () {
|
|
2536
|
+
return new Promise((resolve, reject) => {
|
|
2537
|
+
const dappClientMessageHandler = (payload) => {
|
|
2538
|
+
var _a2;
|
|
2539
|
+
if (typeof payload !== "object" || payload === null || !("data" in payload)) {
|
|
2540
|
+
return;
|
|
2541
|
+
}
|
|
2542
|
+
const data = payload.data;
|
|
2543
|
+
if (typeof data === "object" && data !== null) {
|
|
2544
|
+
if (data.error) {
|
|
2545
|
+
this.dappClient.off("message", dappClientMessageHandler);
|
|
2546
|
+
reject(data.error);
|
|
2547
|
+
}
|
|
2548
|
+
if ((_a2 = data == null ? void 0 : data.result) == null ? void 0 : _a2.sessionScopes) {
|
|
2549
|
+
this.dappClient.off("message", dappClientMessageHandler);
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
};
|
|
2553
|
+
this.dappClient.on("message", dappClientMessageHandler);
|
|
2554
|
+
let timeout;
|
|
2555
|
+
if (this.transport.isConnected()) {
|
|
2556
|
+
timeout = setTimeout(() => {
|
|
2557
|
+
this.openDeeplinkIfNeeded();
|
|
2558
|
+
}, 250);
|
|
2559
|
+
} else {
|
|
2560
|
+
this.dappClient.once(
|
|
2561
|
+
"session_request",
|
|
2562
|
+
(sessionRequest) => {
|
|
2563
|
+
var _a2;
|
|
2564
|
+
const connectionRequest = {
|
|
2565
|
+
sessionRequest,
|
|
2566
|
+
metadata: {
|
|
2567
|
+
dapp: this.options.dapp,
|
|
2568
|
+
sdk: { version: getVersion(), platform: getPlatformType() }
|
|
2569
|
+
}
|
|
2570
|
+
};
|
|
2571
|
+
const deeplink = this.options.ui.factory.createConnectionDeeplink(
|
|
2572
|
+
connectionRequest
|
|
2573
|
+
);
|
|
2574
|
+
const universalLink = this.options.ui.factory.createConnectionUniversalLink(
|
|
2575
|
+
connectionRequest
|
|
2576
|
+
);
|
|
2577
|
+
if ((_a2 = this.options.mobile) == null ? void 0 : _a2.preferredOpenLink) {
|
|
2578
|
+
this.options.mobile.preferredOpenLink(deeplink, "_self");
|
|
2579
|
+
} else {
|
|
2580
|
+
openDeeplink(this.options, deeplink, universalLink);
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
);
|
|
2584
|
+
}
|
|
2585
|
+
return this.transport.connect({ scopes, caipAccountIds }).then(resolve).catch((error) => __async(this, null, function* () {
|
|
2586
|
+
yield this.storage.removeTransport();
|
|
2587
|
+
this.dappClient.off("message", dappClientMessageHandler);
|
|
2588
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2589
|
+
})).finally(() => {
|
|
2590
|
+
if (timeout) {
|
|
2591
|
+
clearTimeout(timeout);
|
|
2592
|
+
}
|
|
2593
|
+
});
|
|
2594
|
+
});
|
|
2595
|
+
});
|
|
2608
2596
|
};
|
|
2597
|
+
handleConnection_fn = function(promise, scopes, transportType) {
|
|
2598
|
+
return __async(this, null, function* () {
|
|
2599
|
+
this.state = "connecting";
|
|
2600
|
+
return promise.then(() => __async(this, null, function* () {
|
|
2601
|
+
this.state = "connected";
|
|
2602
|
+
try {
|
|
2603
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2604
|
+
this.options,
|
|
2605
|
+
this.storage
|
|
2606
|
+
);
|
|
2607
|
+
analytics2.track("mmconnect_connection_established", __spreadProps(__spreadValues({}, baseProps), {
|
|
2608
|
+
transport_type: transportType,
|
|
2609
|
+
user_permissioned_chains: scopes
|
|
2610
|
+
}));
|
|
2611
|
+
} catch (error) {
|
|
2612
|
+
logger2("Error tracking connection_established event", error);
|
|
2613
|
+
}
|
|
2614
|
+
return void 0;
|
|
2615
|
+
})).catch((error) => __async(this, null, function* () {
|
|
2616
|
+
this.state = "disconnected";
|
|
2617
|
+
try {
|
|
2618
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2619
|
+
this.options,
|
|
2620
|
+
this.storage
|
|
2621
|
+
);
|
|
2622
|
+
const isRejection = isRejectionError(error);
|
|
2623
|
+
if (isRejection) {
|
|
2624
|
+
analytics2.track("mmconnect_connection_rejected", __spreadProps(__spreadValues({}, baseProps), {
|
|
2625
|
+
transport_type: transportType
|
|
2626
|
+
}));
|
|
2627
|
+
} else {
|
|
2628
|
+
analytics2.track("mmconnect_connection_failed", __spreadProps(__spreadValues({}, baseProps), {
|
|
2629
|
+
transport_type: transportType
|
|
2630
|
+
}));
|
|
2631
|
+
}
|
|
2632
|
+
} catch (e) {
|
|
2633
|
+
logger2("Error tracking connection failed/rejected event", error);
|
|
2634
|
+
}
|
|
2635
|
+
throw error;
|
|
2636
|
+
}));
|
|
2637
|
+
});
|
|
2638
|
+
};
|
|
2639
|
+
var MultichainSDK = _MultichainSDK;
|
|
2609
2640
|
|
|
2610
2641
|
// src/store/index.ts
|
|
2611
2642
|
import * as uuid from "uuid";
|
|
@@ -2789,50 +2820,15 @@ var Store = class extends StoreClient {
|
|
|
2789
2820
|
// src/ui/index.ts
|
|
2790
2821
|
import MetaMaskOnboarding from "@metamask/onboarding";
|
|
2791
2822
|
init_domain();
|
|
2823
|
+
init_utils();
|
|
2792
2824
|
|
|
2793
|
-
// src/ui/
|
|
2794
|
-
|
|
2795
|
-
function preloadQR() {
|
|
2825
|
+
// src/ui/preload.native.ts
|
|
2826
|
+
function preload() {
|
|
2796
2827
|
return __async(this, null, function* () {
|
|
2797
|
-
if (encodeQRImpl) {
|
|
2798
|
-
return;
|
|
2799
|
-
}
|
|
2800
|
-
const mod = yield import("@paulmillr/qr");
|
|
2801
|
-
encodeQRImpl = mod.default;
|
|
2802
2828
|
});
|
|
2803
2829
|
}
|
|
2804
2830
|
|
|
2805
2831
|
// src/ui/index.ts
|
|
2806
|
-
init_utils();
|
|
2807
|
-
var __instance;
|
|
2808
|
-
function preload() {
|
|
2809
|
-
return __async(this, null, function* () {
|
|
2810
|
-
if (false) {
|
|
2811
|
-
__instance != null ? __instance : __instance = yield null.then((loader) => __async(null, null, function* () {
|
|
2812
|
-
if (typeof (loader == null ? void 0 : loader.defineCustomElements) === "function") {
|
|
2813
|
-
loader.defineCustomElements();
|
|
2814
|
-
}
|
|
2815
|
-
return Promise.resolve(loader);
|
|
2816
|
-
})).catch((error) => __async(null, null, function* () {
|
|
2817
|
-
console.error(`Gracefully Failed to load modal customElements:`, error);
|
|
2818
|
-
return Promise.resolve(void 0);
|
|
2819
|
-
}));
|
|
2820
|
-
} else {
|
|
2821
|
-
const dynamicImport = (0, eval)("import");
|
|
2822
|
-
__instance != null ? __instance : __instance = yield dynamicImport(
|
|
2823
|
-
"@metamask/multichain-ui/dist/loader/index.js"
|
|
2824
|
-
).then((loader) => __async(null, null, function* () {
|
|
2825
|
-
if (typeof (loader == null ? void 0 : loader.defineCustomElements) === "function") {
|
|
2826
|
-
loader.defineCustomElements();
|
|
2827
|
-
}
|
|
2828
|
-
return Promise.resolve(loader);
|
|
2829
|
-
})).catch((error) => __async(null, null, function* () {
|
|
2830
|
-
console.error(`Gracefully Failed to load modal customElements:`, error);
|
|
2831
|
-
return Promise.resolve(void 0);
|
|
2832
|
-
}));
|
|
2833
|
-
}
|
|
2834
|
-
});
|
|
2835
|
-
}
|
|
2836
2832
|
var ModalFactory = class {
|
|
2837
2833
|
/**
|
|
2838
2834
|
* Creates a new modal factory instance.
|
|
@@ -2855,8 +2851,8 @@ var ModalFactory = class {
|
|
|
2855
2851
|
}
|
|
2856
2852
|
unload(error) {
|
|
2857
2853
|
return __async(this, null, function* () {
|
|
2858
|
-
var
|
|
2859
|
-
(
|
|
2854
|
+
var _a2, _b;
|
|
2855
|
+
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
2860
2856
|
yield (_b = this.successCallback) == null ? void 0 : _b.call(this, error);
|
|
2861
2857
|
});
|
|
2862
2858
|
}
|
|
@@ -2894,16 +2890,16 @@ var ModalFactory = class {
|
|
|
2894
2890
|
}
|
|
2895
2891
|
return container;
|
|
2896
2892
|
}
|
|
2897
|
-
|
|
2893
|
+
createConnectionDeeplink(connectionRequest) {
|
|
2898
2894
|
if (!connectionRequest) {
|
|
2899
|
-
throw new Error("
|
|
2895
|
+
throw new Error("createConnectionDeeplink can only be called with a connection request");
|
|
2900
2896
|
}
|
|
2901
2897
|
const json = JSON.stringify(connectionRequest);
|
|
2902
2898
|
const compressed = compressString(json);
|
|
2903
2899
|
const urlEncoded = encodeURIComponent(compressed);
|
|
2904
2900
|
return `${METAMASK_DEEPLINK_BASE}/mwp?p=${urlEncoded}&c=1`;
|
|
2905
2901
|
}
|
|
2906
|
-
|
|
2902
|
+
createConnectionUniversalLink(connectionRequest) {
|
|
2907
2903
|
if (!connectionRequest) {
|
|
2908
2904
|
return `${METAMASK_CONNECT_BASE_URL}`;
|
|
2909
2905
|
}
|
|
@@ -2924,13 +2920,13 @@ var ModalFactory = class {
|
|
|
2924
2920
|
}
|
|
2925
2921
|
renderInstallModal(showInstallModal, createConnectionRequest, successCallback) {
|
|
2926
2922
|
return __async(this, null, function* () {
|
|
2927
|
-
var
|
|
2928
|
-
(
|
|
2929
|
-
yield
|
|
2923
|
+
var _a2;
|
|
2924
|
+
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
2925
|
+
yield preload();
|
|
2930
2926
|
this.successCallback = successCallback;
|
|
2931
2927
|
const parentElement = this.getMountedContainer();
|
|
2932
2928
|
const connectionRequest = yield createConnectionRequest();
|
|
2933
|
-
const qrCodeLink = this.
|
|
2929
|
+
const qrCodeLink = this.createConnectionDeeplink(connectionRequest);
|
|
2934
2930
|
const modal = new this.options.InstallModal({
|
|
2935
2931
|
expiresIn: (connectionRequest.sessionRequest.expiresAt - Date.now()) / 1e3,
|
|
2936
2932
|
connectionRequest,
|
|
@@ -2939,7 +2935,7 @@ var ModalFactory = class {
|
|
|
2939
2935
|
link: qrCodeLink,
|
|
2940
2936
|
sdkVersion: getVersion(),
|
|
2941
2937
|
generateQRCode: (request) => __async(this, null, function* () {
|
|
2942
|
-
return this.
|
|
2938
|
+
return this.createConnectionDeeplink(request);
|
|
2943
2939
|
}),
|
|
2944
2940
|
onClose: this.onCloseModal.bind(this),
|
|
2945
2941
|
startDesktopOnboarding: this.onStartDesktopOnboarding.bind(this),
|
|
@@ -2951,9 +2947,9 @@ var ModalFactory = class {
|
|
|
2951
2947
|
}
|
|
2952
2948
|
renderOTPCodeModal(createOTPCode, successCallback, updateOTPCode) {
|
|
2953
2949
|
return __async(this, null, function* () {
|
|
2954
|
-
var
|
|
2955
|
-
(
|
|
2956
|
-
yield
|
|
2950
|
+
var _a2;
|
|
2951
|
+
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
2952
|
+
yield preload();
|
|
2957
2953
|
this.successCallback = successCallback;
|
|
2958
2954
|
const container = this.getMountedContainer();
|
|
2959
2955
|
const otpCode = yield createOTPCode();
|