@metamask/connect-multichain 0.3.2 → 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.
Files changed (57) hide show
  1. package/CHANGELOG.md +30 -15
  2. package/README.md +1 -1
  3. package/dist/browser/es/connect-multichain.d.mts +0 -3
  4. package/dist/browser/es/connect-multichain.mjs +552 -567
  5. package/dist/browser/es/connect-multichain.mjs.map +1 -1
  6. package/dist/browser/es/metafile-esm.json +1 -1
  7. package/dist/browser/iife/connect-multichain.d.ts +0 -3
  8. package/dist/browser/iife/connect-multichain.js +3780 -2088
  9. package/dist/browser/iife/connect-multichain.js.map +1 -1
  10. package/dist/browser/iife/metafile-iife.json +1 -1
  11. package/dist/browser/umd/connect-multichain.d.ts +0 -3
  12. package/dist/browser/umd/connect-multichain.js +552 -567
  13. package/dist/browser/umd/connect-multichain.js.map +1 -1
  14. package/dist/browser/umd/metafile-cjs.json +1 -1
  15. package/dist/node/cjs/connect-multichain.d.ts +0 -3
  16. package/dist/node/cjs/connect-multichain.js +553 -579
  17. package/dist/node/cjs/connect-multichain.js.map +1 -1
  18. package/dist/node/cjs/metafile-cjs.json +1 -1
  19. package/dist/node/es/connect-multichain.d.mts +0 -3
  20. package/dist/node/es/connect-multichain.mjs +552 -578
  21. package/dist/node/es/connect-multichain.mjs.map +1 -1
  22. package/dist/node/es/metafile-esm.json +1 -1
  23. package/dist/react-native/es/connect-multichain.d.mts +0 -3
  24. package/dist/react-native/es/connect-multichain.mjs +539 -563
  25. package/dist/react-native/es/connect-multichain.mjs.map +1 -1
  26. package/dist/react-native/es/metafile-esm.json +1 -1
  27. package/dist/src/domain/multichain/types.d.ts +0 -3
  28. package/dist/src/domain/multichain/types.d.ts.map +1 -1
  29. package/dist/src/multichain/index.d.ts +3 -22
  30. package/dist/src/multichain/index.d.ts.map +1 -1
  31. package/dist/src/multichain/index.js +413 -420
  32. package/dist/src/multichain/index.js.map +1 -1
  33. package/dist/src/multichain/rpc/requestRouter.d.ts.map +1 -1
  34. package/dist/src/multichain/rpc/requestRouter.js +8 -15
  35. package/dist/src/multichain/rpc/requestRouter.js.map +1 -1
  36. package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
  37. package/dist/src/multichain/transports/mwp/index.js +22 -4
  38. package/dist/src/multichain/transports/mwp/index.js.map +1 -1
  39. package/dist/src/ui/index.d.ts +0 -4
  40. package/dist/src/ui/index.d.ts.map +1 -1
  41. package/dist/src/ui/index.js +3 -44
  42. package/dist/src/ui/index.js.map +1 -1
  43. package/dist/src/ui/modals/node/install.js +2 -2
  44. package/dist/src/ui/modals/node/install.js.map +1 -1
  45. package/dist/src/ui/preload.native.d.ts +5 -0
  46. package/dist/src/ui/preload.native.d.ts.map +1 -0
  47. package/dist/src/ui/preload.native.js +18 -0
  48. package/dist/src/ui/preload.native.js.map +1 -0
  49. package/dist/src/ui/preload.web.d.ts +5 -0
  50. package/dist/src/ui/preload.web.d.ts.map +1 -0
  51. package/dist/src/ui/{qr.js → preload.web.js} +13 -18
  52. package/dist/src/ui/preload.web.js.map +1 -0
  53. package/dist/types/connect-multichain.d.ts +0 -3
  54. package/package.json +7 -7
  55. package/dist/src/ui/qr.d.ts +0 -3
  56. package/dist/src/ui/qr.d.ts.map +0 -1
  57. 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 _a;
239
- if ("process" in globalThis && ((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.DEBUG)) {
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 _a;
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" && ((_a = global == null ? void 0 : global.navigator) == null ? void 0 : _a.product) === "ReactNative") {
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 _a;
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 && ((_a = window.navigator) == null ? void 0 : _a.product) === "ReactNative";
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 _a, _b;
435
+ var _a2, _b;
436
436
  const browser = Bowser.parse(window.navigator.userAgent);
437
- return ((_a = browser == null ? void 0 : browser.platform) == null ? void 0 : _a.type) === "mobile" || ((_b = browser == null ? void 0 : browser.platform) == null ? void 0 : _b.type) === "tablet";
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 _a;
455
+ var _a2;
456
456
  if (typeof window === "undefined") {
457
457
  return false;
458
458
  }
459
- return Boolean((_a = window.ethereum) == null ? void 0 : _a.isMetaMask);
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 _a, _b;
491
- if ((_b = (_a = event == null ? void 0 : event.detail) == null ? void 0 : _a.info) == null ? void 0 : _b.rdns) {
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 _a, _b;
502
- return (_b = (_a = provider == null ? void 0 : provider.info) == null ? void 0 : _a.rdns) == null ? void 0 : _b.startsWith("io.metamask");
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 _a;
607
- return (_a = dapp.url) != null ? _a : dapp.name;
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 _a, _b;
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 (!((_a = options.dapp) == null ? void 0 : _a.name)) {
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 _a;
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 _a2, _b, _c;
717
+ var _a3, _b, _c;
718
718
  return [
719
719
  scope,
720
720
  {
721
- methods: [...(_a2 = scopeData == null ? void 0 : scopeData.methods) != null ? _a2 : []],
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
- (_a = accountsByChain.get(chainKey)) == null ? void 0 : _a.push(accountId);
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 _a;
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 = (_a = nodeList[i].getAttribute("href")) != null ? _a : void 0;
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 _a, _b;
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 = (_a = errorObj.message) == null ? void 0 : _a.toLowerCase()) != null ? _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 _a, _b;
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 = (_a = options.analytics) == null ? void 0 : _a.integrationType) != null ? _b : "unknown" /* UNKNOWN */;
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 _a, _b;
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 = (_a = options.analytics) == null ? void 0 : _a.integrationType) != null ? _b : "unknown";
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 _a, _b, _c;
1144
- const supportedNetworks = (_c = (_b = (_a = this.config) == null ? void 0 : _a.api) == null ? void 0 : _b.supportedNetworks) != null ? _c : {};
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}`);
@@ -1296,24 +1296,17 @@ var RequestRouter = class {
1296
1296
  _RequestRouter_instances = new WeakSet();
1297
1297
  withAnalyticsTracking_fn = function(options, execute) {
1298
1298
  return __async(this, null, function* () {
1299
- var _a, _b, _c;
1300
- if ((_a = this.config.analytics) == null ? void 0 : _a.enabled) {
1301
- yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRequested_fn).call(this, options);
1302
- }
1299
+ yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRequested_fn).call(this, options);
1303
1300
  try {
1304
1301
  const result = yield execute();
1305
- if ((_b = this.config.analytics) == null ? void 0 : _b.enabled) {
1306
- yield __privateMethod(this, _RequestRouter_instances, trackWalletActionSucceeded_fn).call(this, options);
1307
- }
1302
+ yield __privateMethod(this, _RequestRouter_instances, trackWalletActionSucceeded_fn).call(this, options);
1308
1303
  return result;
1309
1304
  } catch (error) {
1310
- if ((_c = this.config.analytics) == null ? void 0 : _c.enabled) {
1311
- const isRejection = isRejectionError(error);
1312
- if (isRejection) {
1313
- yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRejected_fn).call(this, options);
1314
- } else {
1315
- yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options);
1316
- }
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);
1317
1310
  }
1318
1311
  throw new RPCInvokeMethodErr(error.message);
1319
1312
  }
@@ -1375,11 +1368,11 @@ var DefaultTransport = class {
1375
1368
  id: requestId
1376
1369
  }, payload);
1377
1370
  return new Promise((resolve, reject) => {
1378
- var _a;
1371
+ var _a2;
1379
1372
  const timeout = setTimeout(() => {
1380
1373
  __privateGet(this, _pendingRequests).delete(requestId);
1381
1374
  reject(new Error("Request timeout"));
1382
- }, (_a = options == null ? void 0 : options.timeout) != null ? _a : __privateGet(this, _defaultRequestOptions).timeout);
1375
+ }, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : __privateGet(this, _defaultRequestOptions).timeout);
1383
1376
  __privateGet(this, _pendingRequests).set(requestId, {
1384
1377
  resolve: (response) => {
1385
1378
  resolve(response);
@@ -1403,7 +1396,7 @@ var DefaultTransport = class {
1403
1396
  }
1404
1397
  connect(options) {
1405
1398
  return __async(this, null, function* () {
1406
- var _a, _b, _c, _d, _e, _f, _g;
1399
+ var _a2, _b, _c, _d, _e, _f, _g;
1407
1400
  __privateMethod(this, _DefaultTransport_instances, setupMessageListener_fn).call(this);
1408
1401
  yield __privateGet(this, _transport).connect();
1409
1402
  const sessionRequest = yield this.request(
@@ -1416,7 +1409,7 @@ var DefaultTransport = class {
1416
1409
  let walletSession = sessionRequest.result;
1417
1410
  if (walletSession && options && !options.forceRequest) {
1418
1411
  const currentScopes = Object.keys(
1419
- (_a = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a : {}
1412
+ (_a2 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a2 : {}
1420
1413
  );
1421
1414
  const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
1422
1415
  const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
@@ -1530,16 +1523,16 @@ notifyCallbacks_fn = function(data) {
1530
1523
  }
1531
1524
  };
1532
1525
  isMetamaskProviderEvent_fn = function(event) {
1533
- var _a, _b;
1534
- return ((_b = (_a = event == null ? void 0 : event.data) == null ? void 0 : _a.data) == null ? void 0 : _b.name) === "metamask-provider" && // eslint-disable-next-line no-restricted-globals
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
1535
1528
  event.origin === location.origin;
1536
1529
  };
1537
1530
  handleResponse_fn = function(event) {
1538
- var _a, _b;
1531
+ var _a2, _b;
1539
1532
  if (!__privateMethod(this, _DefaultTransport_instances, isMetamaskProviderEvent_fn).call(this, event)) {
1540
1533
  return;
1541
1534
  }
1542
- const responseData = (_b = (_a = event == null ? void 0 : event.data) == null ? void 0 : _a.data) == null ? void 0 : _b.data;
1535
+ const responseData = (_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.data;
1543
1536
  if (typeof responseData === "object" && responseData !== null && "method" in responseData) {
1544
1537
  return;
1545
1538
  }
@@ -1561,11 +1554,11 @@ handleResponse_fn = function(event) {
1561
1554
  }
1562
1555
  };
1563
1556
  handleNotification_fn = function(event) {
1564
- var _a, _b;
1557
+ var _a2, _b;
1565
1558
  if (!__privateMethod(this, _DefaultTransport_instances, isMetamaskProviderEvent_fn).call(this, event)) {
1566
1559
  return;
1567
1560
  }
1568
- const responseData = (_b = (_a = event == null ? void 0 : event.data) == null ? void 0 : _a.data) == null ? void 0 : _b.data;
1561
+ const responseData = (_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.data;
1569
1562
  if (typeof responseData === "object" && responseData.method === "metamask_chainChanged" || responseData.method === "metamask_accountsChanged") {
1570
1563
  __privateMethod(this, _DefaultTransport_instances, notifyCallbacks_fn).call(this, responseData);
1571
1564
  }
@@ -1693,7 +1686,7 @@ var MWPTransport = class {
1693
1686
  }
1694
1687
  onResumeSuccess(resumeResolve, resumeReject, options) {
1695
1688
  return __async(this, null, function* () {
1696
- var _a, _b, _c, _d, _e, _f, _g;
1689
+ var _a2, _b, _c, _d, _e, _f, _g;
1697
1690
  try {
1698
1691
  const sessionRequest = yield this.request({
1699
1692
  method: "wallet_getSession"
@@ -1704,7 +1697,7 @@ var MWPTransport = class {
1704
1697
  let walletSession = sessionRequest.result;
1705
1698
  if (walletSession && options) {
1706
1699
  const currentScopes = Object.keys(
1707
- (_a = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a : {}
1700
+ (_a2 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a2 : {}
1708
1701
  );
1709
1702
  const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
1710
1703
  const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
@@ -1769,10 +1762,10 @@ var MWPTransport = class {
1769
1762
  return cachedWalletSession;
1770
1763
  }
1771
1764
  return new Promise((resolve, reject) => {
1772
- var _a;
1765
+ var _a2;
1773
1766
  const timeout = setTimeout(() => {
1774
1767
  this.rejectRequest(request.id, new TransportTimeoutError());
1775
- }, (_a = options == null ? void 0 : options.timeout) != null ? _a : this.options.requestTimeout);
1768
+ }, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : this.options.requestTimeout);
1776
1769
  this.pendingRequests.set(request.id, {
1777
1770
  request,
1778
1771
  method: request.method,
@@ -1798,26 +1791,27 @@ var MWPTransport = class {
1798
1791
  logger("active session found", session);
1799
1792
  }
1800
1793
  let timeout;
1794
+ let initialConnectionMessageHandler;
1801
1795
  const connectionPromise = new Promise((resolve, reject) => {
1802
1796
  let connection;
1803
1797
  if (session) {
1804
1798
  connection = new Promise((resumeResolve, resumeReject) => {
1805
- var _a;
1799
+ var _a2;
1806
1800
  if (this.dappClient.state === "CONNECTED") {
1807
1801
  this.onResumeSuccess(resumeResolve, resumeReject, options);
1808
1802
  } else {
1809
1803
  this.dappClient.once("connected", () => __async(this, null, function* () {
1810
1804
  this.onResumeSuccess(resumeResolve, resumeReject, options);
1811
1805
  }));
1812
- dappClient.resume((_a = session == null ? void 0 : session.id) != null ? _a : "");
1806
+ dappClient.resume((_a2 = session == null ? void 0 : session.id) != null ? _a2 : "");
1813
1807
  }
1814
1808
  });
1815
1809
  } else {
1816
1810
  connection = new Promise(
1817
1811
  (resolveConnection, rejectConnection) => {
1818
- var _a, _b;
1812
+ var _a2, _b;
1819
1813
  const optionalScopes = addValidAccounts(
1820
- getOptionalScopes((_a = options == null ? void 0 : options.scopes) != null ? _a : []),
1814
+ getOptionalScopes((_a2 = options == null ? void 0 : options.scopes) != null ? _a2 : []),
1821
1815
  getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
1822
1816
  );
1823
1817
  const sessionRequest = {
@@ -1829,12 +1823,18 @@ var MWPTransport = class {
1829
1823
  method: "wallet_createSession",
1830
1824
  params: sessionRequest
1831
1825
  };
1832
- this.dappClient.on("message", (message) => __async(this, null, function* () {
1826
+ initialConnectionMessageHandler = (message) => __async(this, null, function* () {
1833
1827
  if (typeof message === "object" && message !== null) {
1834
1828
  if ("data" in message) {
1835
1829
  const messagePayload = message.data;
1836
1830
  if (messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged") {
1837
1831
  if (messagePayload.error) {
1832
+ if (initialConnectionMessageHandler) {
1833
+ this.dappClient.off(
1834
+ "message",
1835
+ initialConnectionMessageHandler
1836
+ );
1837
+ }
1838
1838
  return rejectConnection(messagePayload.error);
1839
1839
  }
1840
1840
  yield this.storeWalletSession(
@@ -1846,14 +1846,23 @@ var MWPTransport = class {
1846
1846
  }
1847
1847
  }
1848
1848
  }
1849
- }));
1849
+ });
1850
+ this.dappClient.on("message", initialConnectionMessageHandler);
1850
1851
  dappClient.connect({
1851
1852
  mode: "trusted",
1852
1853
  initialPayload: {
1853
1854
  name: MULTICHAIN_PROVIDER_STREAM_NAME,
1854
1855
  data: request
1855
1856
  }
1856
- }).catch(rejectConnection);
1857
+ }).catch((error) => {
1858
+ if (initialConnectionMessageHandler) {
1859
+ this.dappClient.off(
1860
+ "message",
1861
+ initialConnectionMessageHandler
1862
+ );
1863
+ }
1864
+ rejectConnection(error);
1865
+ });
1857
1866
  }
1858
1867
  );
1859
1868
  }
@@ -1862,10 +1871,16 @@ var MWPTransport = class {
1862
1871
  }, this.options.connectionTimeout);
1863
1872
  connection.then(resolve).catch(reject);
1864
1873
  });
1865
- return connectionPromise.finally(() => {
1874
+ return connectionPromise.catch((error) => {
1875
+ throw error;
1876
+ }).finally(() => {
1866
1877
  if (timeout) {
1867
1878
  clearTimeout(timeout);
1868
1879
  }
1880
+ if (initialConnectionMessageHandler) {
1881
+ this.dappClient.off("message", initialConnectionMessageHandler);
1882
+ initialConnectionMessageHandler = void 0;
1883
+ }
1869
1884
  });
1870
1885
  });
1871
1886
  }
@@ -1928,7 +1943,7 @@ var MWPTransport = class {
1928
1943
  }
1929
1944
  getCachedResponse(request) {
1930
1945
  return __async(this, null, function* () {
1931
- var _a;
1946
+ var _a2;
1932
1947
  if (request.method === "wallet_getSession") {
1933
1948
  const walletGetSession = yield this.kvstore.get(SESSION_STORE_KEY);
1934
1949
  if (walletGetSession) {
@@ -1936,7 +1951,7 @@ var MWPTransport = class {
1936
1951
  return {
1937
1952
  id: request.id,
1938
1953
  jsonrpc: "2.0",
1939
- result: (_a = walletSession.params) != null ? _a : walletSession.result,
1954
+ result: (_a2 = walletSession.params) != null ? _a2 : walletSession.result,
1940
1955
  // "what?... why walletSession.params?.."
1941
1956
  method: request.method
1942
1957
  };
@@ -2000,10 +2015,10 @@ var MWPTransport = class {
2000
2015
  yield this.attemptResumeSession();
2001
2016
  }
2002
2017
  return new Promise((resolve, reject) => {
2003
- var _a;
2018
+ var _a2;
2004
2019
  const timeout = setTimeout(() => {
2005
2020
  this.rejectRequest(request.id, new TransportTimeoutError());
2006
- }, (_a = options == null ? void 0 : options.timeout) != null ? _a : this.options.requestTimeout);
2021
+ }, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : this.options.requestTimeout);
2007
2022
  this.pendingRequests.set(request.id, {
2008
2023
  request,
2009
2024
  method: request.method,
@@ -2072,73 +2087,74 @@ var keymanager = new KeyManager();
2072
2087
  // src/multichain/index.ts
2073
2088
  init_utils();
2074
2089
  var logger2 = createLogger("metamask-sdk:core");
2075
- var MultichainSDK = class _MultichainSDK extends MultichainCore {
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 {
2076
2092
  constructor(options) {
2077
- var _a, _b, _c, _d, _e, _f, _g;
2093
+ var _a2, _b, _c, _d, _e, _f;
2078
2094
  const withDappMetadata = setupDappMetadata(options);
2079
- const integrationType = ((_a = options.analytics) == null ? void 0 : _a.enabled) ? options.analytics.integrationType : "direct";
2095
+ const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "direct";
2080
2096
  const allOptions = __spreadProps(__spreadValues({}, withDappMetadata), {
2081
2097
  ui: __spreadProps(__spreadValues({}, withDappMetadata.ui), {
2082
- preferExtension: (_b = withDappMetadata.ui.preferExtension) != null ? _b : true,
2083
- showInstallModal: (_c = withDappMetadata.ui.showInstallModal) != null ? _c : false,
2084
- headless: (_d = withDappMetadata.ui.headless) != null ? _d : false
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
2085
2101
  }),
2086
- analytics: __spreadProps(__spreadValues({}, (_e = options.analytics) != null ? _e : {}), {
2087
- enabled: (_g = (_f = options.analytics) == null ? void 0 : _f.enabled) != null ? _g : true,
2102
+ analytics: __spreadProps(__spreadValues({}, (_f = options.analytics) != null ? _f : {}), {
2088
2103
  integrationType
2089
2104
  })
2090
2105
  });
2091
2106
  super(allOptions);
2092
- this.__provider = void 0;
2093
- this.__transport = void 0;
2094
- this.__dappClient = void 0;
2095
- this.__state = "pending";
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}`);
2096
2115
  }
2097
2116
  get state() {
2098
- return this.__state;
2117
+ return this._state;
2099
2118
  }
2100
2119
  set state(value) {
2101
- var _a, _b;
2102
- this.__state = value;
2103
- (_b = (_a = this.options.transport) == null ? void 0 : _a.onNotification) == null ? void 0 : _b.call(_a, {
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, {
2104
2123
  method: "stateChanged",
2105
2124
  params: value
2106
2125
  });
2107
2126
  }
2108
2127
  get provider() {
2109
- if (!this.__provider && this.__transport) {
2110
- this.__provider = getMultichainClient({ transport: this.__transport });
2111
- return this.__provider;
2128
+ if (!__privateGet(this, _provider) && __privateGet(this, _transport2)) {
2129
+ __privateSet(this, _provider, getMultichainClient({ transport: __privateGet(this, _transport2) }));
2130
+ return __privateGet(this, _provider);
2112
2131
  }
2113
- if (!this.__provider) {
2132
+ if (!__privateGet(this, _provider)) {
2114
2133
  throw new Error("Provider not initialized, establish connection first");
2115
2134
  }
2116
- return this.__provider;
2135
+ return __privateGet(this, _provider);
2117
2136
  }
2118
2137
  get transport() {
2119
- if (!this.__transport) {
2138
+ if (!__privateGet(this, _transport2)) {
2120
2139
  throw new Error("Transport not initialized, establish connection first");
2121
2140
  }
2122
- return this.__transport;
2141
+ return __privateGet(this, _transport2);
2123
2142
  }
2124
2143
  get dappClient() {
2125
- if (!this.__dappClient) {
2144
+ if (!__privateGet(this, _dappClient)) {
2126
2145
  throw new Error("DappClient not initialized, establish connection first");
2127
2146
  }
2128
- return this.__dappClient;
2147
+ return __privateGet(this, _dappClient);
2129
2148
  }
2130
2149
  get storage() {
2131
2150
  return this.options.storage;
2132
2151
  }
2133
2152
  get transportType() {
2134
- return this.__transport instanceof MWPTransport ? "mwp" /* MWP */ : "browser" /* Browser */;
2135
- }
2136
- get sdkInfo() {
2137
- var _a;
2138
- 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 */;
2139
2154
  }
2140
2155
  static create(options) {
2141
2156
  return __async(this, null, function* () {
2157
+ var _a2;
2142
2158
  const instance = new _MultichainSDK(options);
2143
2159
  const isEnabled2 = yield isEnabled(
2144
2160
  "metamask-sdk:core",
@@ -2147,353 +2163,16 @@ var MultichainSDK = class _MultichainSDK extends MultichainCore {
2147
2163
  if (isEnabled2) {
2148
2164
  enableDebug("metamask-sdk:core");
2149
2165
  }
2150
- yield instance.init();
2166
+ yield __privateMethod(_a2 = instance, _MultichainSDK_instances, init_fn).call(_a2);
2151
2167
  return instance;
2152
2168
  });
2153
2169
  }
2154
- setupAnalytics() {
2155
- return __async(this, null, function* () {
2156
- var _a, _b;
2157
- if (!((_a = this.options.analytics) == null ? void 0 : _a.enabled)) {
2158
- return;
2159
- }
2160
- const platform = getPlatformType();
2161
- const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
2162
- const isReactNative2 = platform === "react-native" /* ReactNative */;
2163
- if (!isBrowser && !isReactNative2) {
2164
- return;
2165
- }
2166
- const version = getVersion();
2167
- const dappId = getDappId(this.options.dapp);
2168
- const anonId = yield this.storage.getAnonId();
2169
- const { integrationType } = (_b = this.options.analytics) != null ? _b : {
2170
- integrationType: ""
2171
- };
2172
- analytics2.setGlobalProperty("mmconnect_version", version);
2173
- analytics2.setGlobalProperty("dapp_id", dappId);
2174
- analytics2.setGlobalProperty("anon_id", anonId);
2175
- analytics2.setGlobalProperty("platform", platform);
2176
- analytics2.setGlobalProperty("integration_type", integrationType);
2177
- analytics2.enable();
2178
- });
2179
- }
2180
- onTransportNotification(payload) {
2181
- return __async(this, null, function* () {
2182
- var _a;
2183
- if (typeof payload === "object" && payload !== null && "method" in payload) {
2184
- this.emit(payload.method, (_a = payload.params) != null ? _a : payload.result);
2185
- }
2186
- });
2187
- }
2188
- getStoredTransport() {
2189
- return __async(this, null, function* () {
2190
- const transportType = yield this.storage.getTransport();
2191
- const hasExtensionInstalled = yield hasExtension();
2192
- if (transportType) {
2193
- if (transportType === "browser" /* Browser */) {
2194
- if (hasExtensionInstalled) {
2195
- const apiTransport = new DefaultTransport();
2196
- this.__transport = apiTransport;
2197
- this.listener = apiTransport.onNotification(
2198
- this.onTransportNotification.bind(this)
2199
- );
2200
- return apiTransport;
2201
- }
2202
- } else if (transportType === "mwp" /* MWP */) {
2203
- const { adapter: kvstore } = this.options.storage;
2204
- const dappClient = yield this.createDappClient();
2205
- const apiTransport = new MWPTransport(dappClient, kvstore);
2206
- this.__dappClient = dappClient;
2207
- this.__transport = apiTransport;
2208
- this.listener = apiTransport.onNotification(
2209
- this.onTransportNotification.bind(this)
2210
- );
2211
- return apiTransport;
2212
- }
2213
- yield this.storage.removeTransport();
2214
- }
2215
- return void 0;
2216
- });
2217
- }
2218
- setupTransport() {
2219
- return __async(this, null, function* () {
2220
- const transport = yield this.getStoredTransport();
2221
- if (transport) {
2222
- if (!this.transport.isConnected()) {
2223
- this.state = "connecting";
2224
- yield this.transport.connect();
2225
- }
2226
- this.state = "connected";
2227
- if (this.transport instanceof MWPTransport) {
2228
- yield this.storage.setTransport("mwp" /* MWP */);
2229
- } else {
2230
- yield this.storage.setTransport("browser" /* Browser */);
2231
- }
2232
- } else {
2233
- this.state = "loaded";
2234
- }
2235
- });
2236
- }
2237
- init() {
2238
- return __async(this, null, function* () {
2239
- var _a, _b;
2240
- try {
2241
- if (typeof window !== "undefined" && ((_a = window.mmsdk) == null ? void 0 : _a.isInitialized)) {
2242
- logger2("MetaMaskSDK: init already initialized");
2243
- } else {
2244
- yield this.setupAnalytics();
2245
- yield this.setupTransport();
2246
- if ((_b = this.options.analytics) == null ? void 0 : _b.enabled) {
2247
- try {
2248
- const baseProps = yield getBaseAnalyticsProperties(
2249
- this.options,
2250
- this.storage
2251
- );
2252
- analytics2.track("mmconnect_initialized", baseProps);
2253
- } catch (error) {
2254
- logger2("Error tracking initialized event", error);
2255
- }
2256
- }
2257
- if (typeof window !== "undefined") {
2258
- window.mmsdk = this;
2259
- }
2260
- }
2261
- } catch (error) {
2262
- yield this.storage.removeTransport();
2263
- this.state = "pending";
2264
- logger2("MetaMaskSDK error during initialization", error);
2265
- }
2266
- });
2267
- }
2268
- createDappClient() {
2269
- return __async(this, null, function* () {
2270
- const { adapter: kvstore } = this.options.storage;
2271
- const sessionstore = new SessionStore2(kvstore);
2272
- const websocket = (
2273
- // eslint-disable-next-line no-negated-condition
2274
- typeof window !== "undefined" ? WebSocket : (yield import("ws")).WebSocket
2275
- );
2276
- const transport = yield WebSocketTransport.create({
2277
- url: MWP_RELAY_URL,
2278
- kvstore,
2279
- websocket
2280
- });
2281
- const dappClient = new DappClient({ transport, sessionstore, keymanager });
2282
- return dappClient;
2283
- });
2284
- }
2285
- setupMWP() {
2286
- return __async(this, null, function* () {
2287
- if (this.__transport instanceof MWPTransport) {
2288
- return;
2289
- }
2290
- const { adapter: kvstore } = this.options.storage;
2291
- const dappClient = yield this.createDappClient();
2292
- this.__dappClient = dappClient;
2293
- const apiTransport = new MWPTransport(dappClient, kvstore);
2294
- this.__transport = apiTransport;
2295
- this.listener = this.transport.onNotification(
2296
- this.onTransportNotification.bind(this)
2297
- );
2298
- yield this.storage.setTransport("mwp" /* MWP */);
2299
- });
2300
- }
2301
- onBeforeUnload() {
2302
- return __async(this, null, function* () {
2303
- var _a;
2304
- if ((_a = this.options.ui.factory.modal) == null ? void 0 : _a.isMounted) {
2305
- yield this.storage.removeTransport();
2306
- }
2307
- });
2308
- }
2309
- createBeforeUnloadListener() {
2310
- if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
2311
- window.addEventListener("beforeunload", this.onBeforeUnload.bind(this));
2312
- }
2313
- return () => {
2314
- if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined") {
2315
- window.removeEventListener(
2316
- "beforeunload",
2317
- this.onBeforeUnload.bind(this)
2318
- );
2319
- }
2320
- };
2321
- }
2322
- showInstallModal(desktopPreferred, scopes, caipAccountIds) {
2323
- return __async(this, null, function* () {
2324
- var _a;
2325
- (_a = this.__beforeUnloadListener) != null ? _a : this.__beforeUnloadListener = this.createBeforeUnloadListener();
2326
- return new Promise((resolve, reject) => {
2327
- this.options.ui.factory.renderInstallModal(
2328
- desktopPreferred,
2329
- () => __async(this, null, function* () {
2330
- if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
2331
- yield this.dappClient.disconnect();
2332
- }
2333
- return new Promise((resolveConnectionRequest) => {
2334
- this.dappClient.on(
2335
- "session_request",
2336
- (sessionRequest) => {
2337
- resolveConnectionRequest({
2338
- sessionRequest,
2339
- metadata: {
2340
- dapp: this.options.dapp,
2341
- sdk: {
2342
- version: getVersion(),
2343
- platform: getPlatformType()
2344
- }
2345
- }
2346
- });
2347
- }
2348
- );
2349
- this.transport.connect({ scopes, caipAccountIds }).then(() => {
2350
- var _a2;
2351
- this.options.ui.factory.unload();
2352
- (_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
2353
- this.state = "connected";
2354
- return this.storage.setTransport("mwp" /* MWP */);
2355
- }).catch((error) => {
2356
- if (error instanceof ProtocolError) {
2357
- if (error.code !== ErrorCode.REQUEST_EXPIRED) {
2358
- this.state = "disconnected";
2359
- reject(error);
2360
- }
2361
- } else {
2362
- this.state = "disconnected";
2363
- reject(error);
2364
- }
2365
- });
2366
- });
2367
- }),
2368
- (error) => __async(this, null, function* () {
2369
- if (!error) {
2370
- yield this.storage.setTransport("mwp" /* MWP */);
2371
- resolve();
2372
- } else {
2373
- yield this.storage.removeTransport();
2374
- reject(error);
2375
- }
2376
- })
2377
- );
2378
- });
2379
- });
2380
- }
2381
- setupDefaultTransport() {
2382
- return __async(this, null, function* () {
2383
- this.state = "connecting";
2384
- yield this.storage.setTransport("browser" /* Browser */);
2385
- const transport = new DefaultTransport();
2386
- this.listener = transport.onNotification(
2387
- this.onTransportNotification.bind(this)
2388
- );
2389
- this.__transport = transport;
2390
- return transport;
2391
- });
2392
- }
2393
- deeplinkConnect(scopes, caipAccountIds) {
2394
- return __async(this, null, function* () {
2395
- return new Promise((resolve, reject) => __async(this, null, function* () {
2396
- this.dappClient.on("message", (payload) => {
2397
- var _a, _b, _c;
2398
- const data = payload.data;
2399
- if (typeof data === "object" && data !== null) {
2400
- if ("method" in data && data.method === "wallet_createSession") {
2401
- if (data.error) {
2402
- this.state = "loaded";
2403
- return reject(data.error);
2404
- }
2405
- const session = (_a = data.params) != null ? _a : data.result;
2406
- if (session) {
2407
- (_c = (_b = this.options.transport) == null ? void 0 : _b.onNotification) == null ? void 0 : _c.call(_b, payload.data);
2408
- this.emit("wallet_sessionChanged", session);
2409
- }
2410
- }
2411
- }
2412
- });
2413
- let timeout;
2414
- if (!this.transport.isConnected()) {
2415
- this.dappClient.once(
2416
- "session_request",
2417
- (sessionRequest) => {
2418
- var _a;
2419
- const connectionRequest = {
2420
- sessionRequest,
2421
- metadata: {
2422
- dapp: this.options.dapp,
2423
- sdk: { version: getVersion(), platform: getPlatformType() }
2424
- }
2425
- };
2426
- const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
2427
- const universalLink = this.options.ui.factory.createConnectionUniversalLink(connectionRequest);
2428
- if ((_a = this.options.mobile) == null ? void 0 : _a.preferredOpenLink) {
2429
- this.options.mobile.preferredOpenLink(deeplink, "_self");
2430
- } else {
2431
- openDeeplink(this.options, deeplink, universalLink);
2432
- }
2433
- }
2434
- );
2435
- }
2436
- this.transport.connect({ scopes, caipAccountIds }).then(resolve).catch((error) => {
2437
- this.storage.removeTransport();
2438
- reject(error);
2439
- }).finally(() => {
2440
- if (timeout) {
2441
- clearTimeout(timeout);
2442
- }
2443
- });
2444
- }));
2445
- });
2446
- }
2447
- handleConnection(promise, scopes, transportType) {
2448
- return __async(this, null, function* () {
2449
- this.state = "connecting";
2450
- return promise.then(() => __async(this, null, function* () {
2451
- var _a;
2452
- this.state = "connected";
2453
- if ((_a = this.options.analytics) == null ? void 0 : _a.enabled) {
2454
- try {
2455
- const baseProps = yield getBaseAnalyticsProperties(
2456
- this.options,
2457
- this.storage
2458
- );
2459
- analytics2.track("mmconnect_connection_established", __spreadProps(__spreadValues({}, baseProps), {
2460
- transport_type: transportType,
2461
- user_permissioned_chains: scopes
2462
- }));
2463
- } catch (error) {
2464
- logger2("Error tracking connection_established event", error);
2465
- }
2466
- }
2467
- })).catch((error) => __async(this, null, function* () {
2468
- var _a;
2469
- this.state = "disconnected";
2470
- if ((_a = this.options.analytics) == null ? void 0 : _a.enabled) {
2471
- try {
2472
- const baseProps = yield getBaseAnalyticsProperties(
2473
- this.options,
2474
- this.storage
2475
- );
2476
- const isRejection = isRejectionError(error);
2477
- if (isRejection) {
2478
- analytics2.track("mmconnect_connection_rejected", __spreadProps(__spreadValues({}, baseProps), {
2479
- transport_type: transportType
2480
- }));
2481
- } else {
2482
- analytics2.track("mmconnect_connection_failed", __spreadProps(__spreadValues({}, baseProps), {
2483
- transport_type: transportType
2484
- }));
2485
- }
2486
- } catch (e) {
2487
- logger2("Error tracking connection failed/rejected event", error);
2488
- }
2489
- }
2490
- return Promise.reject(error);
2491
- }));
2492
- });
2493
- }
2494
2170
  connect(scopes, caipAccountIds, forceRequest) {
2495
2171
  return __async(this, null, function* () {
2496
- var _a, _b;
2172
+ var _a2;
2173
+ if (this.state !== "connected") {
2174
+ yield this.disconnect();
2175
+ }
2497
2176
  const { ui } = this.options;
2498
2177
  const platformType = getPlatformType();
2499
2178
  const isWeb = platformType === "in-app-browser" /* MetaMaskMobileWebview */ || platformType === "web-desktop" /* DesktopWeb */;
@@ -2506,96 +2185,72 @@ var MultichainSDK = class _MultichainSDK extends MultichainCore {
2506
2185
  } else {
2507
2186
  transportType = "mwp" /* MWP */;
2508
2187
  }
2509
- if ((_a = this.options.analytics) == null ? void 0 : _a.enabled) {
2510
- try {
2511
- const baseProps = yield getBaseAnalyticsProperties(
2512
- this.options,
2513
- this.storage
2514
- );
2515
- const dappConfiguredChains = Object.keys(
2516
- this.options.api.supportedNetworks
2517
- );
2518
- analytics2.track("mmconnect_connection_initiated", __spreadProps(__spreadValues({}, baseProps), {
2519
- transport_type: transportType,
2520
- dapp_configured_chains: dappConfiguredChains,
2521
- dapp_requested_chains: scopes
2522
- }));
2523
- } catch (error) {
2524
- logger2("Error tracking connection_initiated event", error);
2525
- }
2526
- }
2527
- if (((_b = this.__transport) == null ? void 0 : _b.isConnected()) && !secure) {
2528
- return this.handleConnection(
2529
- this.__transport.connect({ scopes, caipAccountIds, forceRequest }).then(() => {
2530
- if (this.__transport instanceof MWPTransport) {
2531
- return this.storage.setTransport("mwp" /* MWP */);
2532
- } else {
2533
- return this.storage.setTransport("browser" /* Browser */);
2534
- }
2535
- }),
2536
- scopes,
2537
- 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
2538
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);
2539
2211
  }
2540
2212
  if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
2541
- const defaultTransport = yield this.setupDefaultTransport();
2542
- return this.handleConnection(
2543
- defaultTransport.connect({ scopes, caipAccountIds, forceRequest }),
2544
- scopes,
2545
- transportType
2546
- );
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);
2547
2215
  }
2548
2216
  if (isWeb && hasExtensionInstalled && preferExtension) {
2549
- const defaultTransport = yield this.setupDefaultTransport();
2550
- return this.handleConnection(
2551
- defaultTransport.connect({ scopes, caipAccountIds, forceRequest }),
2552
- scopes,
2553
- transportType
2554
- );
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);
2555
2219
  }
2556
- yield this.setupMWP();
2220
+ yield __privateMethod(this, _MultichainSDK_instances, setupMWP_fn).call(this);
2557
2221
  const shouldShowInstallModal = hasExtensionInstalled ? showInstallModal : !preferExtension || showInstallModal;
2558
2222
  if (secure && !shouldShowInstallModal) {
2559
- return this.handleConnection(
2560
- this.deeplinkConnect(scopes, caipAccountIds),
2561
- scopes,
2562
- transportType
2563
- );
2223
+ return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateMethod(this, _MultichainSDK_instances, deeplinkConnect_fn).call(this, scopes, caipAccountIds), scopes, transportType);
2564
2224
  }
2565
- return this.handleConnection(
2566
- this.showInstallModal(shouldShowInstallModal, scopes, caipAccountIds),
2567
- scopes,
2568
- transportType
2569
- );
2225
+ return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateMethod(this, _MultichainSDK_instances, showInstallModal_fn).call(this, shouldShowInstallModal, scopes, caipAccountIds), scopes, transportType);
2570
2226
  });
2571
2227
  }
2572
2228
  emit(event, args) {
2573
- var _a, _b;
2574
- (_b = (_a = this.options.transport) == null ? void 0 : _a.onNotification) == null ? void 0 : _b.call(_a, { method: event, params: args });
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 });
2575
2231
  super.emit(event, args);
2576
2232
  }
2577
2233
  disconnect() {
2578
2234
  return __async(this, null, function* () {
2579
- var _a, _b, _c;
2580
- (_a = this.listener) == null ? void 0 : _a.call(this);
2581
- (_b = this.__beforeUnloadListener) == null ? void 0 : _b.call(this);
2582
- yield (_c = this.__transport) == null ? void 0 : _c.disconnect();
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();
2583
2239
  yield this.storage.removeTransport();
2584
- this.emit("wallet_sessionChanged", void 0);
2585
2240
  this.emit("stateChanged", "disconnected");
2586
- this.listener = void 0;
2587
- this.__beforeUnloadListener = void 0;
2588
- this.__transport = void 0;
2589
- this.__provider = void 0;
2590
- this.__dappClient = void 0;
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);
2591
2246
  });
2592
2247
  }
2593
2248
  invokeMethod(request) {
2594
2249
  return __async(this, null, function* () {
2595
- var _a;
2596
- const { sdkInfo, transport, options } = this;
2597
- (_a = this.__provider) != null ? _a : this.__provider = getMultichainClient({ transport });
2598
- const rpcClient = new RpcClient(options, sdkInfo);
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));
2599
2254
  const requestRouter = new RequestRouter(transport, rpcClient, options);
2600
2255
  return requestRouter.invokeMethod(request);
2601
2256
  });
@@ -2616,16 +2271,372 @@ var MultichainSDK = class _MultichainSDK extends MultichainCore {
2616
2271
  if (mobile == null ? void 0 : mobile.preferredOpenLink) {
2617
2272
  mobile.preferredOpenLink(url, "_self");
2618
2273
  } else {
2619
- openDeeplink(
2620
- this.options,
2621
- url,
2622
- METAMASK_CONNECT_BASE_URL
2623
- );
2274
+ openDeeplink(this.options, url, METAMASK_CONNECT_BASE_URL);
2624
2275
  }
2625
2276
  }), 10);
2626
2277
  }
2627
2278
  }
2628
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(
2378
+ this.options,
2379
+ this.storage
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;
2387
+ }
2388
+ }
2389
+ } catch (error) {
2390
+ yield this.storage.removeTransport();
2391
+ this.state = "pending";
2392
+ logger2("MetaMaskSDK error during initialization", error);
2393
+ }
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
+ });
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;
2629
2640
 
2630
2641
  // src/store/index.ts
2631
2642
  import * as uuid from "uuid";
@@ -2809,50 +2820,15 @@ var Store = class extends StoreClient {
2809
2820
  // src/ui/index.ts
2810
2821
  import MetaMaskOnboarding from "@metamask/onboarding";
2811
2822
  init_domain();
2823
+ init_utils();
2812
2824
 
2813
- // src/ui/qr.ts
2814
- var encodeQRImpl = null;
2815
- function preloadQR() {
2825
+ // src/ui/preload.native.ts
2826
+ function preload() {
2816
2827
  return __async(this, null, function* () {
2817
- if (encodeQRImpl) {
2818
- return;
2819
- }
2820
- const mod = yield import("@paulmillr/qr");
2821
- encodeQRImpl = mod.default;
2822
2828
  });
2823
2829
  }
2824
2830
 
2825
2831
  // src/ui/index.ts
2826
- init_utils();
2827
- var __instance;
2828
- function preload() {
2829
- return __async(this, null, function* () {
2830
- if (false) {
2831
- __instance != null ? __instance : __instance = yield null.then((loader) => __async(null, null, function* () {
2832
- if (typeof (loader == null ? void 0 : loader.defineCustomElements) === "function") {
2833
- loader.defineCustomElements();
2834
- }
2835
- return Promise.resolve(loader);
2836
- })).catch((error) => __async(null, null, function* () {
2837
- console.error(`Gracefully Failed to load modal customElements:`, error);
2838
- return Promise.resolve(void 0);
2839
- }));
2840
- } else {
2841
- const dynamicImport = (0, eval)("import");
2842
- __instance != null ? __instance : __instance = yield dynamicImport(
2843
- "@metamask/multichain-ui/dist/loader/index.js"
2844
- ).then((loader) => __async(null, null, function* () {
2845
- if (typeof (loader == null ? void 0 : loader.defineCustomElements) === "function") {
2846
- loader.defineCustomElements();
2847
- }
2848
- return Promise.resolve(loader);
2849
- })).catch((error) => __async(null, null, function* () {
2850
- console.error(`Gracefully Failed to load modal customElements:`, error);
2851
- return Promise.resolve(void 0);
2852
- }));
2853
- }
2854
- });
2855
- }
2856
2832
  var ModalFactory = class {
2857
2833
  /**
2858
2834
  * Creates a new modal factory instance.
@@ -2875,8 +2851,8 @@ var ModalFactory = class {
2875
2851
  }
2876
2852
  unload(error) {
2877
2853
  return __async(this, null, function* () {
2878
- var _a, _b;
2879
- (_a = this.modal) == null ? void 0 : _a.unmount();
2854
+ var _a2, _b;
2855
+ (_a2 = this.modal) == null ? void 0 : _a2.unmount();
2880
2856
  yield (_b = this.successCallback) == null ? void 0 : _b.call(this, error);
2881
2857
  });
2882
2858
  }
@@ -2944,9 +2920,9 @@ var ModalFactory = class {
2944
2920
  }
2945
2921
  renderInstallModal(showInstallModal, createConnectionRequest, successCallback) {
2946
2922
  return __async(this, null, function* () {
2947
- var _a;
2948
- (_a = this.modal) == null ? void 0 : _a.unmount();
2949
- yield Promise.all([preload(), preloadQR()]);
2923
+ var _a2;
2924
+ (_a2 = this.modal) == null ? void 0 : _a2.unmount();
2925
+ yield preload();
2950
2926
  this.successCallback = successCallback;
2951
2927
  const parentElement = this.getMountedContainer();
2952
2928
  const connectionRequest = yield createConnectionRequest();
@@ -2971,9 +2947,9 @@ var ModalFactory = class {
2971
2947
  }
2972
2948
  renderOTPCodeModal(createOTPCode, successCallback, updateOTPCode) {
2973
2949
  return __async(this, null, function* () {
2974
- var _a;
2975
- (_a = this.modal) == null ? void 0 : _a.unmount();
2976
- yield Promise.all([preload(), preloadQR()]);
2950
+ var _a2;
2951
+ (_a2 = this.modal) == null ? void 0 : _a2.unmount();
2952
+ yield preload();
2977
2953
  this.successCallback = successCallback;
2978
2954
  const container = this.getMountedContainer();
2979
2955
  const otpCode = yield createOTPCode();