@metamask/connect-multichain 0.5.3 → 0.7.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 (60) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/README.md +30 -22
  3. package/dist/browser/es/connect-multichain.d.mts +29 -4
  4. package/dist/browser/es/connect-multichain.mjs +636 -335
  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 +29 -4
  8. package/dist/browser/iife/connect-multichain.js +3487 -3072
  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 +29 -4
  12. package/dist/browser/umd/connect-multichain.js +636 -335
  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 +29 -4
  16. package/dist/node/cjs/connect-multichain.js +454 -153
  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 +29 -4
  20. package/dist/node/es/connect-multichain.mjs +454 -153
  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 +29 -4
  24. package/dist/react-native/es/connect-multichain.mjs +629 -328
  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/index.d.ts +15 -4
  28. package/dist/src/domain/multichain/index.d.ts.map +1 -1
  29. package/dist/src/domain/multichain/index.js +14 -0
  30. package/dist/src/domain/multichain/index.js.map +1 -1
  31. package/dist/src/domain/multichain/types.d.ts +14 -0
  32. package/dist/src/domain/multichain/types.d.ts.map +1 -1
  33. package/dist/src/multichain/index.d.ts +3 -2
  34. package/dist/src/multichain/index.d.ts.map +1 -1
  35. package/dist/src/multichain/index.js +158 -61
  36. package/dist/src/multichain/index.js.map +1 -1
  37. package/dist/src/multichain/transports/default/index.d.ts +3 -1
  38. package/dist/src/multichain/transports/default/index.d.ts.map +1 -1
  39. package/dist/src/multichain/transports/default/index.js +17 -11
  40. package/dist/src/multichain/transports/default/index.js.map +1 -1
  41. package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts +3 -1
  42. package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts.map +1 -1
  43. package/dist/src/multichain/transports/multichainApiClientWrapper/index.js +28 -32
  44. package/dist/src/multichain/transports/multichainApiClientWrapper/index.js.map +1 -1
  45. package/dist/src/multichain/transports/mwp/index.d.ts +15 -2
  46. package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
  47. package/dist/src/multichain/transports/mwp/index.js +161 -39
  48. package/dist/src/multichain/transports/mwp/index.js.map +1 -1
  49. package/dist/src/multichain/utils/index.d.ts +23 -0
  50. package/dist/src/multichain/utils/index.d.ts.map +1 -1
  51. package/dist/src/multichain/utils/index.js +94 -4
  52. package/dist/src/multichain/utils/index.js.map +1 -1
  53. package/dist/src/polyfills/buffer-shim.js +4 -14
  54. package/dist/src/polyfills/buffer-shim.js.map +1 -1
  55. package/dist/src/store/adapters/web.d.ts +1 -1
  56. package/dist/src/store/adapters/web.d.ts.map +1 -1
  57. package/dist/src/store/adapters/web.js +1 -1
  58. package/dist/src/store/adapters/web.js.map +1 -1
  59. package/dist/types/connect-multichain.d.ts +29 -4
  60. package/package.json +2 -2
@@ -34,14 +34,6 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
34
34
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
35
35
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
36
36
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
37
- var __privateWrapper = (obj, member, setter, getter) => ({
38
- set _(value) {
39
- __privateSet(obj, member, value, setter);
40
- },
41
- get _() {
42
- return __privateGet(obj, member, getter);
43
- }
44
- });
45
37
  var __async = (__this, __arguments, generator) => {
46
38
  return new Promise((resolve, reject) => {
47
39
  var fulfilled = (value) => {
@@ -243,8 +235,8 @@ var init_logger = __esm({
243
235
  debug.enable(namespace);
244
236
  };
245
237
  isEnabled = (namespace, storage) => __async(null, null, function* () {
246
- var _a2;
247
- if ("process" in globalThis && ((_a2 = process == null ? void 0 : process.env) == null ? void 0 : _a2.DEBUG)) {
238
+ var _a3;
239
+ if ("process" in globalThis && ((_a3 = process == null ? void 0 : process.env) == null ? void 0 : _a3.DEBUG)) {
248
240
  const { DEBUG } = process.env;
249
241
  return isNamespaceEnabled(DEBUG, namespace);
250
242
  }
@@ -407,6 +399,34 @@ var init_multichain = __esm({
407
399
  super();
408
400
  this.options = options;
409
401
  }
402
+ /**
403
+ * Merges the given options into the current instance options.
404
+ * Only the mergeable keys are updated (api.supportedNetworks, ui.*, mobile.*, transport.extensionId, debug).
405
+ * The main thing to note is that the value for `dapp` is not merged as it does not make sense for
406
+ * subsequent calls to `createMultichainClient` to have a different `dapp` value.
407
+ * Used when createMultichainClient is called with an existing singleton.
408
+ *
409
+ * @param partial - Options to merge/overwrite onto the current instance
410
+ */
411
+ mergeOptions(partial) {
412
+ var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
413
+ const opts = this.options;
414
+ this.options = __spreadProps(__spreadValues({}, opts), {
415
+ api: __spreadProps(__spreadValues({}, opts.api), {
416
+ supportedNetworks: __spreadValues(__spreadValues({}, opts.api.supportedNetworks), (_b = (_a3 = partial.api) == null ? void 0 : _a3.supportedNetworks) != null ? _b : {})
417
+ }),
418
+ ui: __spreadProps(__spreadValues({}, opts.ui), {
419
+ headless: (_d = (_c = partial.ui) == null ? void 0 : _c.headless) != null ? _d : opts.ui.headless,
420
+ preferExtension: (_f = (_e = partial.ui) == null ? void 0 : _e.preferExtension) != null ? _f : opts.ui.preferExtension,
421
+ showInstallModal: (_h = (_g = partial.ui) == null ? void 0 : _g.showInstallModal) != null ? _h : opts.ui.showInstallModal
422
+ }),
423
+ mobile: __spreadValues(__spreadValues({}, opts.mobile), (_i = partial.mobile) != null ? _i : {}),
424
+ transport: __spreadProps(__spreadValues({}, (_j = opts.transport) != null ? _j : {}), {
425
+ extensionId: (_m = (_k = partial.transport) == null ? void 0 : _k.extensionId) != null ? _m : (_l = opts.transport) == null ? void 0 : _l.extensionId
426
+ }),
427
+ debug: (_n = partial.debug) != null ? _n : opts.debug
428
+ });
429
+ }
410
430
  };
411
431
  }
412
432
  });
@@ -414,35 +434,35 @@ var init_multichain = __esm({
414
434
  // src/domain/platform/index.ts
415
435
  import Bowser from "bowser";
416
436
  function isNotBrowser() {
417
- var _a2;
437
+ var _a3;
418
438
  if (typeof window === "undefined") {
419
439
  return true;
420
440
  }
421
441
  if (!(window == null ? void 0 : window.navigator)) {
422
442
  return true;
423
443
  }
424
- if (typeof global !== "undefined" && ((_a2 = global == null ? void 0 : global.navigator) == null ? void 0 : _a2.product) === "ReactNative") {
444
+ if (typeof global !== "undefined" && ((_a3 = global == null ? void 0 : global.navigator) == null ? void 0 : _a3.product) === "ReactNative") {
425
445
  return true;
426
446
  }
427
447
  return (navigator == null ? void 0 : navigator.product) === "ReactNative";
428
448
  }
429
449
  function isReactNative() {
430
- var _a2;
450
+ var _a3;
431
451
  const hasWindowNavigator = typeof window !== "undefined" && window.navigator !== void 0;
432
452
  const nav = hasWindowNavigator ? window.navigator : void 0;
433
453
  if (!nav) {
434
454
  return false;
435
455
  }
436
- return hasWindowNavigator && ((_a2 = window.navigator) == null ? void 0 : _a2.product) === "ReactNative";
456
+ return hasWindowNavigator && ((_a3 = window.navigator) == null ? void 0 : _a3.product) === "ReactNative";
437
457
  }
438
458
  function isMetaMaskMobileWebView() {
439
459
  return typeof window !== "undefined" && // @ts-expect-error ReactNativeWebView should be defined
440
460
  Boolean(window.ReactNativeWebView) && Boolean(window.navigator.userAgent.endsWith("MetaMaskMobile"));
441
461
  }
442
462
  function isMobile() {
443
- var _a2, _b;
463
+ var _a3, _b;
444
464
  const browser = Bowser.parse(window.navigator.userAgent);
445
- 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";
465
+ return ((_a3 = browser == null ? void 0 : browser.platform) == null ? void 0 : _a3.type) === "mobile" || ((_b = browser == null ? void 0 : browser.platform) == null ? void 0 : _b.type) === "tablet";
446
466
  }
447
467
  function getPlatformType() {
448
468
  if (isReactNative()) {
@@ -460,11 +480,11 @@ function getPlatformType() {
460
480
  return "web-desktop" /* DesktopWeb */;
461
481
  }
462
482
  function isMetamaskExtensionInstalled() {
463
- var _a2;
483
+ var _a3;
464
484
  if (typeof window === "undefined") {
465
485
  return false;
466
486
  }
467
- return Boolean((_a2 = window.ethereum) == null ? void 0 : _a2.isMetaMask);
487
+ return Boolean((_a3 = window.ethereum) == null ? void 0 : _a3.isMetaMask);
468
488
  }
469
489
  function isSecure() {
470
490
  const platformType = getPlatformType();
@@ -495,8 +515,8 @@ var init_platform = __esm({
495
515
  return new Promise((resolve) => {
496
516
  const providers = [];
497
517
  const handler = (event) => {
498
- var _a2, _b;
499
- if ((_b = (_a2 = event == null ? void 0 : event.detail) == null ? void 0 : _a2.info) == null ? void 0 : _b.rdns) {
518
+ var _a3, _b;
519
+ if ((_b = (_a3 = event == null ? void 0 : event.detail) == null ? void 0 : _a3.info) == null ? void 0 : _b.rdns) {
500
520
  providers.push(event.detail);
501
521
  }
502
522
  };
@@ -506,8 +526,8 @@ var init_platform = __esm({
506
526
  window.removeEventListener("eip6963:announceProvider", handler);
507
527
  const hasMetaMask = providers.some(
508
528
  (provider) => {
509
- var _a2, _b;
510
- return (_b = (_a2 = provider == null ? void 0 : provider.info) == null ? void 0 : _a2.rdns) == null ? void 0 : _b.startsWith("io.metamask");
529
+ var _a3, _b;
530
+ return (_b = (_a3 = provider == null ? void 0 : provider.info) == null ? void 0 : _a3.rdns) == null ? void 0 : _b.startsWith("io.metamask");
511
531
  }
512
532
  );
513
533
  resolve(hasMetaMask);
@@ -591,12 +611,108 @@ var init_ui = __esm({
591
611
  }
592
612
  });
593
613
 
614
+ // src/multichain/utils/analytics.ts
615
+ function isRejectionError(error) {
616
+ var _a3, _b;
617
+ if (typeof error !== "object" || error === null) {
618
+ return false;
619
+ }
620
+ const errorObj = error;
621
+ const errorCode = errorObj.code;
622
+ const errorMessage = (_b = (_a3 = errorObj.message) == null ? void 0 : _a3.toLowerCase()) != null ? _b : "";
623
+ return errorCode === 4001 || // User rejected request (common EIP-1193 code)
624
+ errorCode === 4100 || // Unauthorized (common rejection code)
625
+ errorMessage.includes("reject") || errorMessage.includes("denied") || errorMessage.includes("cancel") || errorMessage.includes("user");
626
+ }
627
+ function getBaseAnalyticsProperties(options, storage) {
628
+ return __async(this, null, function* () {
629
+ var _a3, _b;
630
+ const version = getVersion();
631
+ const dappId = getDappId(options.dapp);
632
+ const platform = getPlatformType();
633
+ const anonId = yield storage.getAnonId();
634
+ const integrationType = (_b = (_a3 = options.analytics) == null ? void 0 : _a3.integrationType) != null ? _b : "unknown" /* UNKNOWN */;
635
+ return {
636
+ mmconnect_version: version,
637
+ dapp_id: dappId,
638
+ platform,
639
+ integration_type: integrationType,
640
+ anon_id: anonId
641
+ };
642
+ });
643
+ }
644
+ function getWalletActionAnalyticsProperties(options, storage, invokeOptions) {
645
+ return __async(this, null, function* () {
646
+ var _a3, _b;
647
+ const version = getVersion();
648
+ const dappId = getDappId(options.dapp);
649
+ const anonId = yield storage.getAnonId();
650
+ const integrationType = (_b = (_a3 = options.analytics) == null ? void 0 : _a3.integrationType) != null ? _b : "unknown";
651
+ return {
652
+ mmconnect_version: version,
653
+ dapp_id: dappId,
654
+ method: invokeOptions.request.method,
655
+ integration_type: integrationType,
656
+ caip_chain_id: invokeOptions.scope,
657
+ anon_id: anonId
658
+ };
659
+ });
660
+ }
661
+ var init_analytics = __esm({
662
+ "src/multichain/utils/analytics.ts"() {
663
+ "use strict";
664
+ init_utils2();
665
+ init_domain();
666
+ }
667
+ });
668
+
669
+ // src/domain/utils/index.ts
670
+ function getVersion() {
671
+ return "0.0.0";
672
+ }
673
+ var init_utils = __esm({
674
+ "src/domain/utils/index.ts"() {
675
+ "use strict";
676
+ init_analytics();
677
+ }
678
+ });
679
+
680
+ // src/domain/index.ts
681
+ var init_domain = __esm({
682
+ "src/domain/index.ts"() {
683
+ "use strict";
684
+ init_errors();
685
+ init_events();
686
+ init_logger();
687
+ init_multichain();
688
+ init_platform();
689
+ init_store();
690
+ init_ui();
691
+ init_utils();
692
+ }
693
+ });
694
+
594
695
  // src/multichain/utils/index.ts
595
696
  import {
596
697
  parseCaipAccountId,
597
698
  parseCaipChainId
598
699
  } from "@metamask/utils";
599
700
  import { deflate } from "pako";
701
+ function getGlobalObject() {
702
+ if (typeof globalThis !== "undefined") {
703
+ return globalThis;
704
+ }
705
+ if (typeof global !== "undefined") {
706
+ return global;
707
+ }
708
+ if (typeof self !== "undefined") {
709
+ return self;
710
+ }
711
+ if (typeof window !== "undefined") {
712
+ return window;
713
+ }
714
+ throw new Error("Unable to locate global object");
715
+ }
600
716
  function base64Encode(str) {
601
717
  if (typeof btoa !== "undefined") {
602
718
  return btoa(str);
@@ -611,13 +727,13 @@ function compressString(str) {
611
727
  return base64Encode(binaryString);
612
728
  }
613
729
  function getDappId(dapp) {
614
- var _a2;
615
- return (_a2 = dapp.url) != null ? _a2 : dapp.name;
730
+ var _a3;
731
+ return (_a3 = dapp.url) != null ? _a3 : dapp.name;
616
732
  }
617
733
  function openDeeplink(options, deeplink, universalLink) {
618
- var _a2;
734
+ var _a3;
619
735
  const { mobile } = options;
620
- const useDeeplink = (_a2 = mobile == null ? void 0 : mobile.useDeeplink) != null ? _a2 : true;
736
+ const useDeeplink = (_a3 = mobile == null ? void 0 : mobile.useDeeplink) != null ? _a3 : true;
621
737
  if (useDeeplink) {
622
738
  if (typeof window !== "undefined") {
623
739
  window.location.href = deeplink;
@@ -630,6 +746,29 @@ function openDeeplink(options, deeplink, universalLink) {
630
746
  link.click();
631
747
  }
632
748
  }
749
+ function mergeRequestedSessionWithExisting(sessionData, scopes, caipAccountIds, sessionProperties) {
750
+ const existingCaipChainIds = Object.keys(sessionData.sessionScopes);
751
+ const existingCaipAccountIds = [];
752
+ Object.values(sessionData.sessionScopes).forEach((scopeObject) => {
753
+ if ((scopeObject == null ? void 0 : scopeObject.accounts) && Array.isArray(scopeObject.accounts)) {
754
+ scopeObject.accounts.forEach((account) => {
755
+ existingCaipAccountIds.push(account);
756
+ });
757
+ }
758
+ });
759
+ const mergedScopes = Array.from(
760
+ /* @__PURE__ */ new Set([...existingCaipChainIds, ...scopes])
761
+ );
762
+ const mergedCaipAccountIds = Array.from(
763
+ /* @__PURE__ */ new Set([...existingCaipAccountIds, ...caipAccountIds])
764
+ );
765
+ const mergedSessionProperties = __spreadValues(__spreadValues({}, sessionData.sessionProperties), sessionProperties);
766
+ return {
767
+ mergedScopes,
768
+ mergedCaipAccountIds,
769
+ mergedSessionProperties
770
+ };
771
+ }
633
772
  function getOptionalScopes(scopes) {
634
773
  return scopes.reduce(
635
774
  (prev, scope) => __spreadProps(__spreadValues({}, prev), {
@@ -642,11 +781,26 @@ function getOptionalScopes(scopes) {
642
781
  {}
643
782
  );
644
783
  }
784
+ function normalizeNativeUrl(url) {
785
+ var _a3;
786
+ const httpPattern = /^https?:\/\//u;
787
+ if (httpPattern.test(url)) {
788
+ return void 0;
789
+ }
790
+ const schemeMatch = url.match(/^([^:]*):\/\//u);
791
+ const rawScheme = (_a3 = schemeMatch == null ? void 0 : schemeMatch[1]) != null ? _a3 : url;
792
+ const sanitized = rawScheme.toLowerCase().replace(/[^a-z0-9-]/gu, "-").replace(/^-+|-+$/gu, "");
793
+ const subdomain = (sanitized || "unknown").slice(0, 63).replace(/-+$/u, "");
794
+ return {
795
+ url: `https://${subdomain}.rn.dapp.local`,
796
+ nativeScheme: url
797
+ };
798
+ }
645
799
  function setupDappMetadata(options) {
646
- var _a2, _b;
800
+ var _a3, _b;
647
801
  const platform = getPlatformType();
648
802
  const isBrowser = platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */ || platform === "in-app-browser" /* MetaMaskMobileWebview */;
649
- if (!((_a2 = options.dapp) == null ? void 0 : _a2.name)) {
803
+ if (!((_a3 = options.dapp) == null ? void 0 : _a3.name)) {
650
804
  throw new Error("You must provide dapp name");
651
805
  }
652
806
  if (isBrowser) {
@@ -657,6 +811,18 @@ function setupDappMetadata(options) {
657
811
  if (!((_b = options.dapp) == null ? void 0 : _b.url)) {
658
812
  throw new Error("You must provide dapp url");
659
813
  }
814
+ if (platform === "react-native" /* ReactNative */ && options.dapp.url) {
815
+ const normalized = normalizeNativeUrl(options.dapp.url);
816
+ if (normalized) {
817
+ console.info(
818
+ `Normalizing dapp URL for React Native: "${options.dapp.url}" -> "${normalized.url}"`
819
+ );
820
+ options.dapp = __spreadProps(__spreadValues({}, options.dapp), {
821
+ url: normalized.url,
822
+ nativeScheme: normalized.nativeScheme
823
+ });
824
+ }
825
+ }
660
826
  const BASE_64_ICON_MAX_LENGTH = 163400;
661
827
  const urlPattern = /^(http|https):\/\/[^\s]*$/u;
662
828
  if (options.dapp) {
@@ -720,17 +886,17 @@ function getValidAccounts(caipAccountIds) {
720
886
  );
721
887
  }
722
888
  function addValidAccounts(optionalScopes, validAccounts) {
723
- var _a2;
889
+ var _a3;
724
890
  if (!optionalScopes || !(validAccounts == null ? void 0 : validAccounts.length)) {
725
891
  return optionalScopes;
726
892
  }
727
893
  const result = Object.fromEntries(
728
894
  Object.entries(optionalScopes).map(([scope, scopeData]) => {
729
- var _a3, _b, _c;
895
+ var _a4, _b, _c;
730
896
  return [
731
897
  scope,
732
898
  {
733
- methods: [...(_a3 = scopeData == null ? void 0 : scopeData.methods) != null ? _a3 : []],
899
+ methods: [...(_a4 = scopeData == null ? void 0 : scopeData.methods) != null ? _a4 : []],
734
900
  notifications: [...(_b = scopeData == null ? void 0 : scopeData.notifications) != null ? _b : []],
735
901
  accounts: [...(_c = scopeData == null ? void 0 : scopeData.accounts) != null ? _c : []]
736
902
  }
@@ -744,7 +910,7 @@ function addValidAccounts(optionalScopes, validAccounts) {
744
910
  if (!accountsByChain.has(chainKey)) {
745
911
  accountsByChain.set(chainKey, []);
746
912
  }
747
- (_a2 = accountsByChain.get(chainKey)) == null ? void 0 : _a2.push(accountId);
913
+ (_a3 = accountsByChain.get(chainKey)) == null ? void 0 : _a3.push(accountId);
748
914
  }
749
915
  for (const [scopeKey, scopeData] of Object.entries(result)) {
750
916
  if (!(scopeData == null ? void 0 : scopeData.accounts)) {
@@ -768,13 +934,13 @@ function addValidAccounts(optionalScopes, validAccounts) {
768
934
  }
769
935
  return result;
770
936
  }
771
- var extractFavicon;
772
- var init_utils = __esm({
937
+ var extractFavicon, MAX, idCounter, getUniqueRequestId;
938
+ var init_utils2 = __esm({
773
939
  "src/multichain/utils/index.ts"() {
774
940
  "use strict";
775
941
  init_domain();
776
942
  extractFavicon = () => {
777
- var _a2;
943
+ var _a3;
778
944
  if (typeof document === "undefined") {
779
945
  return void 0;
780
946
  }
@@ -782,92 +948,17 @@ var init_utils = __esm({
782
948
  const nodeList = document.getElementsByTagName("link");
783
949
  for (let i = 0; i < nodeList.length; i++) {
784
950
  if (nodeList[i].getAttribute("rel") === "icon" || nodeList[i].getAttribute("rel") === "shortcut icon") {
785
- favicon = (_a2 = nodeList[i].getAttribute("href")) != null ? _a2 : void 0;
951
+ favicon = (_a3 = nodeList[i].getAttribute("href")) != null ? _a3 : void 0;
786
952
  }
787
953
  }
788
954
  return favicon;
789
955
  };
790
- }
791
- });
792
-
793
- // src/multichain/utils/analytics.ts
794
- function isRejectionError(error) {
795
- var _a2, _b;
796
- if (typeof error !== "object" || error === null) {
797
- return false;
798
- }
799
- const errorObj = error;
800
- const errorCode = errorObj.code;
801
- const errorMessage = (_b = (_a2 = errorObj.message) == null ? void 0 : _a2.toLowerCase()) != null ? _b : "";
802
- return errorCode === 4001 || // User rejected request (common EIP-1193 code)
803
- errorCode === 4100 || // Unauthorized (common rejection code)
804
- errorMessage.includes("reject") || errorMessage.includes("denied") || errorMessage.includes("cancel") || errorMessage.includes("user");
805
- }
806
- function getBaseAnalyticsProperties(options, storage) {
807
- return __async(this, null, function* () {
808
- var _a2, _b;
809
- const version = getVersion();
810
- const dappId = getDappId(options.dapp);
811
- const platform = getPlatformType();
812
- const anonId = yield storage.getAnonId();
813
- const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "unknown" /* UNKNOWN */;
814
- return {
815
- mmconnect_version: version,
816
- dapp_id: dappId,
817
- platform,
818
- integration_type: integrationType,
819
- anon_id: anonId
820
- };
821
- });
822
- }
823
- function getWalletActionAnalyticsProperties(options, storage, invokeOptions) {
824
- return __async(this, null, function* () {
825
- var _a2, _b;
826
- const version = getVersion();
827
- const dappId = getDappId(options.dapp);
828
- const anonId = yield storage.getAnonId();
829
- const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "unknown";
830
- return {
831
- mmconnect_version: version,
832
- dapp_id: dappId,
833
- method: invokeOptions.request.method,
834
- integration_type: integrationType,
835
- caip_chain_id: invokeOptions.scope,
836
- anon_id: anonId
956
+ MAX = 4294967295;
957
+ idCounter = Math.floor(Math.random() * MAX);
958
+ getUniqueRequestId = () => {
959
+ idCounter = (idCounter + 1) % MAX;
960
+ return idCounter;
837
961
  };
838
- });
839
- }
840
- var init_analytics = __esm({
841
- "src/multichain/utils/analytics.ts"() {
842
- "use strict";
843
- init_utils();
844
- init_domain();
845
- }
846
- });
847
-
848
- // src/domain/utils/index.ts
849
- function getVersion() {
850
- return "0.0.0";
851
- }
852
- var init_utils2 = __esm({
853
- "src/domain/utils/index.ts"() {
854
- "use strict";
855
- init_analytics();
856
- }
857
- });
858
-
859
- // src/domain/index.ts
860
- var init_domain = __esm({
861
- "src/domain/index.ts"() {
862
- "use strict";
863
- init_errors();
864
- init_events();
865
- init_logger();
866
- init_multichain();
867
- init_platform();
868
- init_store();
869
- init_ui();
870
- init_utils2();
871
962
  }
872
963
  });
873
964
 
@@ -1091,11 +1182,11 @@ var init_rn2 = __esm({
1091
1182
  });
1092
1183
 
1093
1184
  // src/polyfills/buffer-shim.ts
1185
+ init_utils2();
1094
1186
  import { Buffer as Buffer2 } from "buffer";
1095
- var globalObj = typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : {};
1096
- if (!globalObj.Buffer) {
1097
- globalObj.Buffer = Buffer2;
1098
- }
1187
+ var globalObj = getGlobalObject();
1188
+ var _a;
1189
+ (_a = globalObj.Buffer) != null ? _a : globalObj.Buffer = Buffer2;
1099
1190
 
1100
1191
  // src/index.native.ts
1101
1192
  init_domain();
@@ -1168,8 +1259,8 @@ var RpcClient = class {
1168
1259
  });
1169
1260
  }
1170
1261
  getRpcEndpoint(scope) {
1171
- var _a2, _b, _c;
1172
- const supportedNetworks = (_c = (_b = (_a2 = this.config) == null ? void 0 : _a2.api) == null ? void 0 : _b.supportedNetworks) != null ? _c : {};
1262
+ var _a3, _b, _c;
1263
+ const supportedNetworks = (_c = (_b = (_a3 = this.config) == null ? void 0 : _a3.api) == null ? void 0 : _b.supportedNetworks) != null ? _c : {};
1173
1264
  const rpcEndpoint = supportedNetworks[scope];
1174
1265
  if (!rpcEndpoint) {
1175
1266
  throw new MissingRpcEndpointErr(
@@ -1233,7 +1324,7 @@ var RpcClient = class {
1233
1324
  // src/multichain/rpc/requestRouter.ts
1234
1325
  import { analytics } from "@metamask/analytics";
1235
1326
  init_domain();
1236
- init_utils();
1327
+ init_utils2();
1237
1328
  init_analytics();
1238
1329
  var _RequestRouter_instances, withAnalyticsTracking_fn, trackWalletActionRequested_fn, trackWalletActionSucceeded_fn, trackWalletActionFailed_fn, trackWalletActionRejected_fn;
1239
1330
  var RequestRouter = class {
@@ -1400,12 +1491,12 @@ trackWalletActionRejected_fn = function(options) {
1400
1491
  };
1401
1492
 
1402
1493
  // src/multichain/transports/default/index.ts
1403
- init_utils();
1494
+ init_utils2();
1404
1495
  import {
1405
1496
  getDefaultTransport
1406
1497
  } from "@metamask/multichain-api-client";
1407
1498
  var DEFAULT_REQUEST_TIMEOUT = 60 * 1e3;
1408
- var _notificationCallbacks, _transport, _defaultRequestOptions, _reqId, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn;
1499
+ var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn;
1409
1500
  var DefaultTransport = class {
1410
1501
  constructor() {
1411
1502
  __privateAdd(this, _DefaultTransport_instances);
@@ -1414,8 +1505,6 @@ var DefaultTransport = class {
1414
1505
  __privateAdd(this, _defaultRequestOptions, {
1415
1506
  timeout: DEFAULT_REQUEST_TIMEOUT
1416
1507
  });
1417
- // Use timestamp-based ID to avoid conflicts across disconnect/reconnect cycles
1418
- __privateAdd(this, _reqId, Date.now());
1419
1508
  __privateAdd(this, _pendingRequests, /* @__PURE__ */ new Map());
1420
1509
  __privateAdd(this, _handleResponseListener);
1421
1510
  __privateAdd(this, _handleNotificationListener);
@@ -1423,18 +1512,17 @@ var DefaultTransport = class {
1423
1512
  sendEip1193Message(payload, options) {
1424
1513
  return __async(this, null, function* () {
1425
1514
  __privateMethod(this, _DefaultTransport_instances, setupMessageListener_fn).call(this);
1426
- __privateSet(this, _reqId, __privateGet(this, _reqId) + 1);
1427
- const requestId = `${__privateGet(this, _reqId)}`;
1515
+ const requestId = String(getUniqueRequestId());
1428
1516
  const request = __spreadValues({
1429
1517
  jsonrpc: "2.0",
1430
1518
  id: requestId
1431
1519
  }, payload);
1432
1520
  return new Promise((resolve, reject) => {
1433
- var _a2;
1521
+ var _a3;
1434
1522
  const timeout = setTimeout(() => {
1435
1523
  __privateGet(this, _pendingRequests).delete(requestId);
1436
1524
  reject(new Error("Request timeout"));
1437
- }, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : __privateGet(this, _defaultRequestOptions).timeout);
1525
+ }, (_a3 = options == null ? void 0 : options.timeout) != null ? _a3 : __privateGet(this, _defaultRequestOptions).timeout);
1438
1526
  __privateGet(this, _pendingRequests).set(requestId, {
1439
1527
  resolve: (response) => {
1440
1528
  resolve(response);
@@ -1458,7 +1546,7 @@ var DefaultTransport = class {
1458
1546
  }
1459
1547
  connect(options) {
1460
1548
  return __async(this, null, function* () {
1461
- var _a2, _b, _c, _d, _e;
1549
+ var _a3, _b, _c, _d, _e;
1462
1550
  __privateMethod(this, _DefaultTransport_instances, setupMessageListener_fn).call(this);
1463
1551
  yield __privateGet(this, _transport).connect();
1464
1552
  const sessionRequest = yield this.request(
@@ -1471,7 +1559,7 @@ var DefaultTransport = class {
1471
1559
  let walletSession = sessionRequest.result;
1472
1560
  const createSessionParams = {
1473
1561
  optionalScopes: addValidAccounts(
1474
- getOptionalScopes((_a2 = options == null ? void 0 : options.scopes) != null ? _a2 : []),
1562
+ getOptionalScopes((_a3 = options == null ? void 0 : options.scopes) != null ? _a3 : []),
1475
1563
  getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
1476
1564
  ),
1477
1565
  sessionProperties: options == null ? void 0 : options.sessionProperties
@@ -1489,10 +1577,6 @@ var DefaultTransport = class {
1489
1577
  proposedCaipAccountIds
1490
1578
  );
1491
1579
  if (!hasSameScopesAndAccounts) {
1492
- yield this.request(
1493
- { method: "wallet_revokeSession", params: walletSession },
1494
- __privateGet(this, _defaultRequestOptions)
1495
- );
1496
1580
  const response = yield this.request(
1497
1581
  { method: "wallet_createSession", params: createSessionParams },
1498
1582
  __privateGet(this, _defaultRequestOptions)
@@ -1519,9 +1603,14 @@ var DefaultTransport = class {
1519
1603
  });
1520
1604
  }
1521
1605
  disconnect() {
1522
- return __async(this, null, function* () {
1606
+ return __async(this, arguments, function* (scopes = []) {
1607
+ yield this.request({ method: "wallet_revokeSession", params: { scopes } });
1608
+ const response = yield this.request({ method: "wallet_getSession" });
1609
+ const { sessionScopes } = response.result;
1610
+ if (Object.keys(sessionScopes).length > 0) {
1611
+ return;
1612
+ }
1523
1613
  __privateGet(this, _notificationCallbacks).clear();
1524
- yield this.request({ method: "wallet_revokeSession", params: {} });
1525
1614
  if (__privateGet(this, _handleResponseListener)) {
1526
1615
  window.removeEventListener("message", __privateGet(this, _handleResponseListener));
1527
1616
  __privateSet(this, _handleResponseListener, void 0);
@@ -1535,7 +1624,7 @@ var DefaultTransport = class {
1535
1624
  request.reject(new Error("Transport disconnected"));
1536
1625
  }
1537
1626
  __privateGet(this, _pendingRequests).clear();
1538
- return __privateGet(this, _transport).disconnect();
1627
+ yield __privateGet(this, _transport).disconnect();
1539
1628
  });
1540
1629
  }
1541
1630
  isConnected() {
@@ -1560,11 +1649,17 @@ var DefaultTransport = class {
1560
1649
  );
1561
1650
  });
1562
1651
  }
1652
+ getStoredPendingSessionRequest() {
1653
+ return __async(this, null, function* () {
1654
+ throw new Error(
1655
+ "getStoredPendingSessionRequest is purposely not implemented for the DefaultTransport"
1656
+ );
1657
+ });
1658
+ }
1563
1659
  };
1564
1660
  _notificationCallbacks = new WeakMap();
1565
1661
  _transport = new WeakMap();
1566
1662
  _defaultRequestOptions = new WeakMap();
1567
- _reqId = new WeakMap();
1568
1663
  _pendingRequests = new WeakMap();
1569
1664
  _handleResponseListener = new WeakMap();
1570
1665
  _handleNotificationListener = new WeakMap();
@@ -1582,16 +1677,16 @@ notifyCallbacks_fn = function(data) {
1582
1677
  }
1583
1678
  };
1584
1679
  isMetamaskProviderEvent_fn = function(event) {
1585
- var _a2, _b;
1586
- 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
1680
+ var _a3, _b;
1681
+ return ((_b = (_a3 = event == null ? void 0 : event.data) == null ? void 0 : _a3.data) == null ? void 0 : _b.name) === "metamask-provider" && // eslint-disable-next-line no-restricted-globals
1587
1682
  event.origin === location.origin;
1588
1683
  };
1589
1684
  handleResponse_fn = function(event) {
1590
- var _a2, _b;
1685
+ var _a3, _b;
1591
1686
  if (!__privateMethod(this, _DefaultTransport_instances, isMetamaskProviderEvent_fn).call(this, event)) {
1592
1687
  return;
1593
1688
  }
1594
- const responseData = (_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.data;
1689
+ const responseData = (_b = (_a3 = event == null ? void 0 : event.data) == null ? void 0 : _a3.data) == null ? void 0 : _b.data;
1595
1690
  if (typeof responseData === "object" && responseData !== null && "method" in responseData) {
1596
1691
  return;
1597
1692
  }
@@ -1613,11 +1708,11 @@ handleResponse_fn = function(event) {
1613
1708
  }
1614
1709
  };
1615
1710
  handleNotification_fn = function(event) {
1616
- var _a2, _b;
1711
+ var _a3, _b;
1617
1712
  if (!__privateMethod(this, _DefaultTransport_instances, isMetamaskProviderEvent_fn).call(this, event)) {
1618
1713
  return;
1619
1714
  }
1620
- const responseData = (_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.data;
1715
+ const responseData = (_b = (_a3 = event == null ? void 0 : event.data) == null ? void 0 : _a3.data) == null ? void 0 : _b.data;
1621
1716
  if (typeof responseData === "object" && responseData.method === "metamask_chainChanged" || responseData.method === "metamask_accountsChanged") {
1622
1717
  __privateMethod(this, _DefaultTransport_instances, notifyCallbacks_fn).call(this, responseData);
1623
1718
  }
@@ -1633,19 +1728,13 @@ setupMessageListener_fn = function() {
1633
1728
  };
1634
1729
 
1635
1730
  // src/multichain/transports/multichainApiClientWrapper/index.ts
1731
+ init_utils2();
1636
1732
  import { providerErrors } from "@metamask/rpc-errors";
1637
- var MAX = 4294967295;
1638
- var idCounter = Math.floor(Math.random() * MAX);
1639
- var getUniqueId = () => {
1640
- idCounter = (idCounter + 1) % MAX;
1641
- return idCounter;
1642
- };
1643
- var _requestId, _notificationCallbacks2, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
1733
+ var _notificationCallbacks2, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
1644
1734
  var MultichainApiClientWrapperTransport = class {
1645
1735
  constructor(metamaskConnectMultichain) {
1646
1736
  this.metamaskConnectMultichain = metamaskConnectMultichain;
1647
1737
  __privateAdd(this, _MultichainApiClientWrapperTransport_instances);
1648
- __privateAdd(this, _requestId, getUniqueId());
1649
1738
  __privateAdd(this, _notificationCallbacks2, /* @__PURE__ */ new Set());
1650
1739
  }
1651
1740
  isTransportDefined() {
@@ -1663,15 +1752,23 @@ var MultichainApiClientWrapperTransport = class {
1663
1752
  callback(data);
1664
1753
  });
1665
1754
  }
1666
- setupNotifcationListener() {
1667
- this.metamaskConnectMultichain.transport.onNotification(
1755
+ clearTransportNotificationListener() {
1756
+ var _a3;
1757
+ (_a3 = this.notificationListener) == null ? void 0 : _a3.call(this);
1758
+ this.notificationListener = void 0;
1759
+ }
1760
+ setupTransportNotificationListener() {
1761
+ if (!this.isTransportDefined() || this.notificationListener) {
1762
+ return;
1763
+ }
1764
+ this.notificationListener = this.metamaskConnectMultichain.transport.onNotification(
1668
1765
  this.notifyCallbacks.bind(this)
1669
1766
  );
1670
1767
  }
1671
1768
  connect() {
1672
1769
  return __async(this, null, function* () {
1673
1770
  console.log("\u{1F4DA} connect");
1674
- return Promise.resolve();
1771
+ yield this.metamaskConnectMultichain.emitSessionChanged();
1675
1772
  });
1676
1773
  }
1677
1774
  disconnect() {
@@ -1684,7 +1781,7 @@ var MultichainApiClientWrapperTransport = class {
1684
1781
  }
1685
1782
  request(_0) {
1686
1783
  return __async(this, arguments, function* (params, _options = {}) {
1687
- const id = __privateWrapper(this, _requestId)._++;
1784
+ const id = getUniqueRequestId();
1688
1785
  const requestPayload = __spreadValues({
1689
1786
  id,
1690
1787
  jsonrpc: "2.0"
@@ -1705,27 +1802,23 @@ var MultichainApiClientWrapperTransport = class {
1705
1802
  });
1706
1803
  }
1707
1804
  onNotification(callback) {
1708
- if (!this.isTransportDefined()) {
1709
- __privateGet(this, _notificationCallbacks2).add(callback);
1710
- return () => {
1711
- __privateGet(this, _notificationCallbacks2).delete(callback);
1712
- };
1713
- }
1714
- return this.metamaskConnectMultichain.transport.onNotification(callback);
1805
+ this.setupTransportNotificationListener();
1806
+ __privateGet(this, _notificationCallbacks2).add(callback);
1807
+ return () => {
1808
+ __privateGet(this, _notificationCallbacks2).delete(callback);
1809
+ };
1715
1810
  }
1716
1811
  };
1717
- _requestId = new WeakMap();
1718
1812
  _notificationCallbacks2 = new WeakMap();
1719
1813
  _MultichainApiClientWrapperTransport_instances = new WeakSet();
1720
1814
  walletCreateSession_fn = function(request) {
1721
1815
  return __async(this, null, function* () {
1722
- console.log("\u{1F4DA} #walletCreateSession", request);
1723
1816
  const createSessionParams = request.params;
1724
1817
  const scopes = Object.keys(__spreadValues(__spreadValues({}, createSessionParams.optionalScopes), createSessionParams.requiredScopes));
1725
1818
  const scopeAccounts = [];
1726
1819
  scopes.forEach((scope) => {
1727
- var _a2, _b, _c, _d;
1728
- const requiredScope = (_a2 = createSessionParams.requiredScopes) == null ? void 0 : _a2[scope];
1820
+ var _a3, _b, _c, _d;
1821
+ const requiredScope = (_a3 = createSessionParams.requiredScopes) == null ? void 0 : _a3[scope];
1729
1822
  const optionalScope = (_b = createSessionParams.optionalScopes) == null ? void 0 : _b[scope];
1730
1823
  if (requiredScope) {
1731
1824
  scopeAccounts.push(...(_c = requiredScope.accounts) != null ? _c : []);
@@ -1765,11 +1858,14 @@ walletGetSession_fn = function(request) {
1765
1858
  };
1766
1859
  walletRevokeSession_fn = function(request) {
1767
1860
  return __async(this, null, function* () {
1861
+ var _a3;
1768
1862
  if (!this.isTransportDefined()) {
1769
1863
  return { jsonrpc: "2.0", id: request.id, result: true };
1770
1864
  }
1865
+ const revokeSessionParams = request.params;
1866
+ const scopes = (_a3 = revokeSessionParams == null ? void 0 : revokeSessionParams.scopes) != null ? _a3 : [];
1771
1867
  try {
1772
- this.metamaskConnectMultichain.disconnect();
1868
+ yield this.metamaskConnectMultichain.disconnect(scopes);
1773
1869
  return { jsonrpc: "2.0", id: request.id, result: true };
1774
1870
  } catch (_error) {
1775
1871
  return { jsonrpc: "2.0", id: request.id, result: false };
@@ -1792,11 +1888,12 @@ walletInvokeMethod_fn = function(request) {
1792
1888
 
1793
1889
  // src/multichain/transports/mwp/index.ts
1794
1890
  init_domain();
1795
- init_utils();
1891
+ init_utils2();
1796
1892
  import { SessionStore } from "@metamask/mobile-wallet-protocol-core";
1797
1893
  import {
1798
1894
  TransportTimeoutError
1799
1895
  } from "@metamask/multichain-api-client";
1896
+ import { JsonRpcError, providerErrors as providerErrors2, rpcErrors } from "@metamask/rpc-errors";
1800
1897
 
1801
1898
  // src/multichain/transports/constants.ts
1802
1899
  var MULTICHAIN_PROVIDER_STREAM_NAME = "metamask-multichain-provider";
@@ -1809,6 +1906,7 @@ var DEFAULT_RESUME_TIMEOUT = 10 * 1e3;
1809
1906
  var SESSION_STORE_KEY = "cache_wallet_getSession";
1810
1907
  var ACCOUNTS_STORE_KEY = "cache_eth_accounts";
1811
1908
  var CHAIN_STORE_KEY = "cache_eth_chainId";
1909
+ var PENDING_SESSION_REQUEST_KEY = "pending_session_request";
1812
1910
  var CACHED_METHOD_LIST = [
1813
1911
  "wallet_getSession",
1814
1912
  "wallet_createSession",
@@ -1828,10 +1926,15 @@ var MWPTransport = class {
1828
1926
  this.dappClient = dappClient;
1829
1927
  this.kvstore = kvstore;
1830
1928
  this.options = options;
1831
- this.__reqId = 0;
1832
1929
  this.__pendingRequests = /* @__PURE__ */ new Map();
1833
1930
  this.notificationCallbacks = /* @__PURE__ */ new Set();
1834
1931
  this.dappClient.on("message", this.handleMessage.bind(this));
1932
+ this.dappClient.on("session_request", (sessionRequest) => {
1933
+ this.currentSessionRequest = sessionRequest;
1934
+ this.kvstore.set(PENDING_SESSION_REQUEST_KEY, JSON.stringify(sessionRequest)).catch((err) => {
1935
+ logger("Failed to store pending session request", err);
1936
+ });
1937
+ });
1835
1938
  if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
1836
1939
  this.windowFocusHandler = this.onWindowFocus.bind(this);
1837
1940
  window.addEventListener("focus", this.windowFocusHandler);
@@ -1846,6 +1949,34 @@ var MWPTransport = class {
1846
1949
  get sessionRequest() {
1847
1950
  return this.currentSessionRequest;
1848
1951
  }
1952
+ /**
1953
+ * Returns the stored pending session request from the dappClient session_request event, if any.
1954
+ *
1955
+ * @returns The stored SessionRequest, or null if none or invalid.
1956
+ */
1957
+ getStoredPendingSessionRequest() {
1958
+ return __async(this, null, function* () {
1959
+ try {
1960
+ const raw = yield this.kvstore.get(PENDING_SESSION_REQUEST_KEY);
1961
+ if (!raw) {
1962
+ return null;
1963
+ }
1964
+ return JSON.parse(raw);
1965
+ } catch (e) {
1966
+ return null;
1967
+ }
1968
+ });
1969
+ }
1970
+ /**
1971
+ * Removes the stored pending session request from the KVStore.
1972
+ * This is necessary to ensure that ConnectMultichain is able to correctly
1973
+ * infer the MWP Transport connection attempt status.
1974
+ */
1975
+ removeStoredPendingSessionRequest() {
1976
+ return __async(this, null, function* () {
1977
+ yield this.kvstore.delete(PENDING_SESSION_REQUEST_KEY);
1978
+ });
1979
+ }
1849
1980
  onWindowFocus() {
1850
1981
  if (!this.isConnected()) {
1851
1982
  this.dappClient.reconnect();
@@ -1862,6 +1993,18 @@ var MWPTransport = class {
1862
1993
  request.reject(error);
1863
1994
  }
1864
1995
  }
1996
+ parseWalletError(errorPayload) {
1997
+ const errorData = errorPayload;
1998
+ if (typeof errorData.code === "number" && typeof errorData.message === "string") {
1999
+ const { code, message: message2 } = errorData;
2000
+ if (code >= 1e3 && code <= 4999) {
2001
+ return providerErrors2.custom({ code, message: message2 });
2002
+ }
2003
+ return new JsonRpcError(code, message2);
2004
+ }
2005
+ const message = errorPayload instanceof Error ? errorPayload.message : JSON.stringify(errorPayload);
2006
+ return rpcErrors.internal({ message });
2007
+ }
1865
2008
  handleMessage(message) {
1866
2009
  if (typeof message === "object" && message !== null) {
1867
2010
  if ("data" in message) {
@@ -1869,6 +2012,12 @@ var MWPTransport = class {
1869
2012
  if ("id" in messagePayload && typeof messagePayload.id === "string") {
1870
2013
  const request = this.pendingRequests.get(messagePayload.id);
1871
2014
  if (request) {
2015
+ clearTimeout(request.timeout);
2016
+ if ("error" in messagePayload && messagePayload.error) {
2017
+ this.pendingRequests.delete(messagePayload.id);
2018
+ request.reject(this.parseWalletError(messagePayload.error));
2019
+ return;
2020
+ }
1872
2021
  const requestWithName = __spreadProps(__spreadValues({}, messagePayload), {
1873
2022
  method: request.method === "wallet_getSession" || request.method === "wallet_createSession" ? "wallet_sessionChanged" : request.method
1874
2023
  });
@@ -1876,7 +2025,6 @@ var MWPTransport = class {
1876
2025
  method: request.method === "wallet_getSession" || request.method === "wallet_createSession" ? "wallet_sessionChanged" : request.method,
1877
2026
  params: requestWithName.result
1878
2027
  });
1879
- clearTimeout(request.timeout);
1880
2028
  this.notifyCallbacks(notification);
1881
2029
  request.resolve(requestWithName);
1882
2030
  this.pendingRequests.delete(messagePayload.id);
@@ -1912,7 +2060,7 @@ var MWPTransport = class {
1912
2060
  }
1913
2061
  onResumeSuccess(resumeResolve, resumeReject, options) {
1914
2062
  return __async(this, null, function* () {
1915
- var _a2, _b, _c, _d, _e, _f, _g;
2063
+ var _a3, _b, _c, _d, _e, _f, _g;
1916
2064
  try {
1917
2065
  yield this.waitForWalletSessionIfNotCached();
1918
2066
  const sessionRequest = yield this.request({
@@ -1924,7 +2072,7 @@ var MWPTransport = class {
1924
2072
  let walletSession = sessionRequest.result;
1925
2073
  if (walletSession && options) {
1926
2074
  const currentScopes = Object.keys(
1927
- (_a2 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a2 : {}
2075
+ (_a3 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a3 : {}
1928
2076
  );
1929
2077
  const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
1930
2078
  const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
@@ -1966,6 +2114,7 @@ var MWPTransport = class {
1966
2114
  }
1967
2115
  walletSession = response.result;
1968
2116
  }
2117
+ yield this.removeStoredPendingSessionRequest();
1969
2118
  this.notifyCallbacks({
1970
2119
  method: "wallet_sessionChanged",
1971
2120
  params: walletSession
@@ -1981,7 +2130,7 @@ var MWPTransport = class {
1981
2130
  return __async(this, null, function* () {
1982
2131
  const request = __spreadValues({
1983
2132
  jsonrpc: "2.0",
1984
- id: `${this.__reqId++}`
2133
+ id: String(getUniqueRequestId())
1985
2134
  }, payload);
1986
2135
  const cachedWalletSession = yield this.getCachedResponse(request);
1987
2136
  if (cachedWalletSession) {
@@ -1989,10 +2138,10 @@ var MWPTransport = class {
1989
2138
  return cachedWalletSession;
1990
2139
  }
1991
2140
  return new Promise((resolve, reject) => {
1992
- var _a2;
2141
+ var _a3;
1993
2142
  const timeout = setTimeout(() => {
1994
2143
  this.rejectRequest(request.id, new TransportTimeoutError());
1995
- }, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : this.options.requestTimeout);
2144
+ }, (_a3 = options == null ? void 0 : options.timeout) != null ? _a3 : this.options.requestTimeout);
1996
2145
  this.pendingRequests.set(request.id, {
1997
2146
  request,
1998
2147
  method: request.method,
@@ -2015,30 +2164,35 @@ var MWPTransport = class {
2015
2164
  const { dappClient } = this;
2016
2165
  const session = yield this.getActiveSession();
2017
2166
  if (session) {
2018
- logger("active session found", session);
2167
+ logger("active session found", {
2168
+ id: session.id,
2169
+ channel: session.channel,
2170
+ expiresAt: session.expiresAt
2171
+ });
2019
2172
  }
2173
+ const storedSessionRequestBeforeConnectionAttempt = yield this.getStoredPendingSessionRequest();
2020
2174
  let timeout;
2021
2175
  let initialConnectionMessageHandler;
2022
2176
  const connectionPromise = new Promise((resolve, reject) => __async(this, null, function* () {
2023
2177
  let connection;
2024
2178
  if (session) {
2025
2179
  connection = new Promise((resumeResolve, resumeReject) => {
2026
- var _a2;
2180
+ var _a3;
2027
2181
  if (this.dappClient.state === "CONNECTED") {
2028
2182
  this.onResumeSuccess(resumeResolve, resumeReject, options);
2029
2183
  } else {
2030
2184
  this.dappClient.once("connected", () => __async(this, null, function* () {
2031
2185
  this.onResumeSuccess(resumeResolve, resumeReject, options);
2032
2186
  }));
2033
- dappClient.resume((_a2 = session == null ? void 0 : session.id) != null ? _a2 : "");
2187
+ dappClient.resume((_a3 = session == null ? void 0 : session.id) != null ? _a3 : "");
2034
2188
  }
2035
2189
  });
2036
2190
  } else {
2037
2191
  connection = new Promise(
2038
2192
  (resolveConnection, rejectConnection) => {
2039
- var _a2, _b;
2193
+ var _a3, _b;
2040
2194
  const optionalScopes = addValidAccounts(
2041
- getOptionalScopes((_a2 = options == null ? void 0 : options.scopes) != null ? _a2 : []),
2195
+ getOptionalScopes((_a3 = options == null ? void 0 : options.scopes) != null ? _a3 : []),
2042
2196
  getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
2043
2197
  );
2044
2198
  const sessionRequest = {
@@ -2047,33 +2201,35 @@ var MWPTransport = class {
2047
2201
  };
2048
2202
  const request = {
2049
2203
  jsonrpc: "2.0",
2050
- id: `${this.__reqId++}`,
2204
+ id: String(getUniqueRequestId()),
2051
2205
  method: "wallet_createSession",
2052
2206
  params: sessionRequest
2053
2207
  };
2054
2208
  initialConnectionMessageHandler = (message) => __async(this, null, function* () {
2055
- if (typeof message === "object" && message !== null) {
2056
- if ("data" in message) {
2057
- const messagePayload = message.data;
2058
- if (messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged") {
2059
- if (messagePayload.error) {
2060
- if (initialConnectionMessageHandler) {
2061
- this.dappClient.off(
2062
- "message",
2063
- initialConnectionMessageHandler
2064
- );
2065
- }
2066
- return rejectConnection(messagePayload.error);
2067
- }
2068
- yield this.storeWalletSession(
2069
- request,
2070
- messagePayload
2071
- );
2072
- this.notifyCallbacks(messagePayload);
2073
- return resolveConnection();
2074
- }
2075
- }
2209
+ if (typeof message !== "object" || message === null) {
2210
+ return;
2211
+ }
2212
+ if (!("data" in message)) {
2213
+ return;
2076
2214
  }
2215
+ const messagePayload = message.data;
2216
+ const isMatchingId = messagePayload.id === request.id;
2217
+ const isMatchingMethod = messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged";
2218
+ if (!isMatchingId && !isMatchingMethod) {
2219
+ return;
2220
+ }
2221
+ if (messagePayload.error) {
2222
+ return rejectConnection(
2223
+ this.parseWalletError(messagePayload.error)
2224
+ );
2225
+ }
2226
+ yield this.storeWalletSession(
2227
+ request,
2228
+ messagePayload
2229
+ );
2230
+ yield this.removeStoredPendingSessionRequest();
2231
+ this.notifyCallbacks(messagePayload);
2232
+ return resolveConnection();
2077
2233
  });
2078
2234
  this.dappClient.on("message", initialConnectionMessageHandler);
2079
2235
  dappClient.connect({
@@ -2094,14 +2250,18 @@ var MWPTransport = class {
2094
2250
  }
2095
2251
  );
2096
2252
  }
2097
- timeout = setTimeout(() => {
2098
- reject(new TransportTimeoutError());
2099
- }, this.options.connectionTimeout);
2253
+ timeout = setTimeout(
2254
+ () => {
2255
+ reject(new TransportTimeoutError());
2256
+ },
2257
+ storedSessionRequestBeforeConnectionAttempt ? this.options.resumeTimeout : this.options.connectionTimeout
2258
+ );
2100
2259
  connection.then(resolve).catch(reject);
2101
2260
  }));
2102
- return connectionPromise.catch((error) => {
2261
+ return connectionPromise.catch((error) => __async(this, null, function* () {
2262
+ yield this.dappClient.disconnect();
2103
2263
  throw error;
2104
- }).finally(() => {
2264
+ })).finally(() => {
2105
2265
  if (timeout) {
2106
2266
  clearTimeout(timeout);
2107
2267
  }
@@ -2109,24 +2269,68 @@ var MWPTransport = class {
2109
2269
  this.dappClient.off("message", initialConnectionMessageHandler);
2110
2270
  initialConnectionMessageHandler = void 0;
2111
2271
  }
2272
+ this.removeStoredPendingSessionRequest();
2112
2273
  });
2113
2274
  });
2114
2275
  }
2115
2276
  /**
2116
2277
  * Disconnects from the Mobile Wallet Protocol
2117
2278
  *
2279
+ * @param [scopes] - The scopes to revoke. If not provided or empty, all scopes will be revoked.
2118
2280
  * @returns Nothing
2119
2281
  */
2120
2282
  disconnect() {
2121
- return __async(this, null, function* () {
2122
- if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined" && this.windowFocusHandler) {
2123
- window.removeEventListener("focus", this.windowFocusHandler);
2124
- this.windowFocusHandler = void 0;
2125
- }
2126
- this.kvstore.delete(SESSION_STORE_KEY);
2127
- this.kvstore.delete(ACCOUNTS_STORE_KEY);
2128
- this.kvstore.delete(CHAIN_STORE_KEY);
2129
- return this.dappClient.disconnect();
2283
+ return __async(this, arguments, function* (scopes = []) {
2284
+ var _a3, _b;
2285
+ const cachedSession = yield this.getCachedResponse({
2286
+ jsonrpc: "2.0",
2287
+ id: "0",
2288
+ method: "wallet_getSession"
2289
+ });
2290
+ const cachedSessionScopes = (_b = (_a3 = cachedSession == null ? void 0 : cachedSession.result) == null ? void 0 : _a3.sessionScopes) != null ? _b : {};
2291
+ const remainingScopes = scopes.length === 0 ? [] : Object.keys(cachedSessionScopes).filter(
2292
+ (scope) => !scopes.includes(scope)
2293
+ );
2294
+ const newSessionScopes = Object.fromEntries(
2295
+ Object.entries(cachedSessionScopes).filter(
2296
+ ([key]) => remainingScopes.includes(key)
2297
+ )
2298
+ );
2299
+ this.request({ method: "wallet_revokeSession", params: { scopes } }).catch(
2300
+ (err) => {
2301
+ console.error("error revoking session", err);
2302
+ }
2303
+ );
2304
+ const remainingScopesIncludeEip155 = remainingScopes.some(
2305
+ (scope) => scope.includes("eip155")
2306
+ );
2307
+ if (!remainingScopesIncludeEip155) {
2308
+ this.kvstore.delete(ACCOUNTS_STORE_KEY);
2309
+ this.kvstore.delete(CHAIN_STORE_KEY);
2310
+ }
2311
+ if (remainingScopes.length > 0) {
2312
+ this.kvstore.set(
2313
+ SESSION_STORE_KEY,
2314
+ JSON.stringify({
2315
+ result: {
2316
+ sessionScopes: newSessionScopes
2317
+ }
2318
+ })
2319
+ );
2320
+ } else {
2321
+ this.kvstore.delete(SESSION_STORE_KEY);
2322
+ if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined" && this.windowFocusHandler) {
2323
+ window.removeEventListener("focus", this.windowFocusHandler);
2324
+ this.windowFocusHandler = void 0;
2325
+ }
2326
+ yield this.dappClient.disconnect();
2327
+ }
2328
+ this.notifyCallbacks({
2329
+ method: "wallet_sessionChanged",
2330
+ params: {
2331
+ sessionScopes: newSessionScopes
2332
+ }
2333
+ });
2130
2334
  });
2131
2335
  }
2132
2336
  /**
@@ -2171,7 +2375,7 @@ var MWPTransport = class {
2171
2375
  }
2172
2376
  getCachedResponse(request) {
2173
2377
  return __async(this, null, function* () {
2174
- var _a2;
2378
+ var _a3;
2175
2379
  if (request.method === "wallet_getSession") {
2176
2380
  const walletGetSession = yield this.kvstore.get(SESSION_STORE_KEY);
2177
2381
  if (walletGetSession) {
@@ -2179,7 +2383,7 @@ var MWPTransport = class {
2179
2383
  return {
2180
2384
  id: request.id,
2181
2385
  jsonrpc: "2.0",
2182
- result: (_a2 = walletSession.params) != null ? _a2 : walletSession.result,
2386
+ result: (_a3 = walletSession.params) != null ? _a3 : walletSession.result,
2183
2387
  // "what?... why walletSession.params?.."
2184
2388
  method: request.method
2185
2389
  };
@@ -2232,7 +2436,7 @@ var MWPTransport = class {
2232
2436
  return __async(this, null, function* () {
2233
2437
  const request = __spreadValues({
2234
2438
  jsonrpc: "2.0",
2235
- id: `${this.__reqId++}`
2439
+ id: String(getUniqueRequestId())
2236
2440
  }, payload);
2237
2441
  const cachedWalletSession = yield this.getCachedResponse(request);
2238
2442
  if (cachedWalletSession) {
@@ -2243,10 +2447,10 @@ var MWPTransport = class {
2243
2447
  yield this.attemptResumeSession();
2244
2448
  }
2245
2449
  return new Promise((resolve, reject) => {
2246
- var _a2;
2450
+ var _a3;
2247
2451
  const timeout = setTimeout(() => {
2248
2452
  this.rejectRequest(request.id, new TransportTimeoutError());
2249
- }, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : this.options.requestTimeout);
2453
+ }, (_a3 = options == null ? void 0 : options.timeout) != null ? _a3 : this.options.requestTimeout);
2250
2454
  this.pendingRequests.set(request.id, {
2251
2455
  request,
2252
2456
  method: request.method,
@@ -2314,6 +2518,7 @@ var MWPTransport = class {
2314
2518
  const timeoutPromise = new Promise((_resolve, reject) => {
2315
2519
  setTimeout(() => {
2316
2520
  unsubscribe();
2521
+ this.removeStoredPendingSessionRequest();
2317
2522
  reject(new TransportTimeoutError());
2318
2523
  }, this.options.resumeTimeout);
2319
2524
  });
@@ -2350,14 +2555,15 @@ var KeyManager = class {
2350
2555
  var keymanager = new KeyManager();
2351
2556
 
2352
2557
  // src/multichain/index.ts
2353
- init_utils();
2558
+ init_utils2();
2354
2559
  var logger2 = createLogger("metamask-sdk:core");
2355
- var _a, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo, _MetaMaskConnectMultichain_instances, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn, init_fn, createDappClient_fn, setupMWP_fn, onBeforeUnload_fn, createBeforeUnloadListener_fn, renderInstallModalAsync_fn, showInstallModal_fn, headlessConnect_fn, setupDefaultTransport_fn, deeplinkConnect_fn, handleConnection_fn;
2560
+ var SINGLETON_KEY = "__METAMASK_CONNECT_MULTICHAIN_SINGLETON__";
2561
+ var _a2, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo, _MetaMaskConnectMultichain_instances, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn, init_fn, createDappClient_fn, setupMWP_fn, onBeforeUnload_fn, createBeforeUnloadListener_fn, renderInstallModalAsync_fn, showInstallModal_fn, headlessConnect_fn, setupDefaultTransport_fn, deeplinkConnect_fn, handleConnection_fn, getCaipSession_fn, openConnectDeeplinkIfNeeded_fn;
2356
2562
  var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
2357
2563
  constructor(options) {
2358
- var _a2, _b, _c, _d, _e, _f;
2564
+ var _a3, _b, _c, _d, _e, _f;
2359
2565
  const withDappMetadata = setupDappMetadata(options);
2360
- const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "direct";
2566
+ const integrationType = (_b = (_a3 = options.analytics) == null ? void 0 : _a3.integrationType) != null ? _b : "direct";
2361
2567
  const allOptions = __spreadProps(__spreadValues({}, withDappMetadata), {
2362
2568
  ui: __spreadProps(__spreadValues({}, withDappMetadata.ui), {
2363
2569
  preferExtension: (_c = withDappMetadata.ui.preferExtension) != null ? _c : true,
@@ -2377,7 +2583,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2377
2583
  __privateAdd(this, _beforeUnloadListener);
2378
2584
  this._status = "pending";
2379
2585
  __privateAdd(this, _listener);
2380
- __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}`);
2586
+ __privateAdd(this, _sdkInfo, `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(_a2 = this.options.dapp.url) != null ? _a2 : this.options.dapp.name} dAppTitle/${this.options.dapp.name}`);
2381
2587
  __privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(
2382
2588
  this
2383
2589
  ));
@@ -2389,9 +2595,9 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2389
2595
  return this._status;
2390
2596
  }
2391
2597
  set status(value) {
2392
- var _a2, _b;
2598
+ var _a3, _b;
2393
2599
  this._status = value;
2394
- (_b = (_a2 = this.options.transport) == null ? void 0 : _a2.onNotification) == null ? void 0 : _b.call(_a2, {
2600
+ (_b = (_a3 = this.options.transport) == null ? void 0 : _a3.onNotification) == null ? void 0 : _b.call(_a3, {
2395
2601
  method: "stateChanged",
2396
2602
  params: value
2397
2603
  });
@@ -2417,27 +2623,54 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2417
2623
  get transportType() {
2418
2624
  return __privateGet(this, _transport2) instanceof MWPTransport ? "mwp" /* MWP */ : "browser" /* Browser */;
2419
2625
  }
2626
+ // Creates a singleton instance of MetaMaskConnectMultichain.
2627
+ // If the singleton already exists, it merges the incoming options with the
2628
+ // existing singleton options for the following keys: `api.supportedNetworks`,
2629
+ // `ui.*`, `mobile.*`, `transport.extensionId`, `debug`. Take note that the
2630
+ // value for `dapp` is not merged as it does not make sense for subsequent calls to
2631
+ // `createMultichainClient` to have a different `dapp` value.
2420
2632
  static create(options) {
2421
2633
  return __async(this, null, function* () {
2422
- var _a2;
2423
- const instance = new _MetaMaskConnectMultichain(options);
2424
- const isEnabled2 = yield isEnabled(
2425
- "metamask-sdk:core",
2426
- instance.options.storage
2427
- );
2428
- if (isEnabled2) {
2429
- enableDebug("metamask-sdk:core");
2430
- }
2431
- yield __privateMethod(_a2 = instance, _MetaMaskConnectMultichain_instances, init_fn).call(_a2);
2432
- return instance;
2634
+ const globalObject = getGlobalObject();
2635
+ const existing = globalObject[SINGLETON_KEY];
2636
+ if (existing) {
2637
+ const instance = yield existing;
2638
+ instance.mergeOptions(options);
2639
+ if (options.debug) {
2640
+ enableDebug("metamask-sdk:*");
2641
+ }
2642
+ return instance;
2643
+ }
2644
+ const instancePromise = (() => __async(null, null, function* () {
2645
+ var _a3;
2646
+ const instance = new _MetaMaskConnectMultichain(options);
2647
+ const isEnabled2 = yield isEnabled(
2648
+ "metamask-sdk:core",
2649
+ instance.options.storage
2650
+ );
2651
+ if (isEnabled2) {
2652
+ enableDebug("metamask-sdk:core");
2653
+ }
2654
+ yield __privateMethod(_a3 = instance, _MetaMaskConnectMultichain_instances, init_fn).call(_a3);
2655
+ return instance;
2656
+ }))();
2657
+ globalObject[SINGLETON_KEY] = instancePromise;
2658
+ instancePromise.catch((error) => {
2659
+ globalObject[SINGLETON_KEY] = void 0;
2660
+ console.error("Error initializing MetaMaskConnectMultichain", error);
2661
+ });
2662
+ return instancePromise;
2433
2663
  });
2434
2664
  }
2435
2665
  // TODO: make this into param object
2436
2666
  connect(scopes, caipAccountIds, sessionProperties, forceRequest) {
2437
2667
  return __async(this, null, function* () {
2438
- var _a2;
2439
- if (this.status !== "connected") {
2440
- yield this.disconnect();
2668
+ var _a3;
2669
+ if (this.status === "connecting" && this.transportType === "mwp" /* MWP */) {
2670
+ yield __privateMethod(this, _MetaMaskConnectMultichain_instances, openConnectDeeplinkIfNeeded_fn).call(this);
2671
+ throw new Error(
2672
+ "Existing connection is pending. Please check your MetaMask Mobile app to continue."
2673
+ );
2441
2674
  }
2442
2675
  const { ui } = this.options;
2443
2676
  const platformType = getPlatformType();
@@ -2467,12 +2700,19 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2467
2700
  } catch (error) {
2468
2701
  logger2("Error tracking connection_initiated event", error);
2469
2702
  }
2470
- const nonEmptySessionProperites = Object.keys(sessionProperties != null ? sessionProperties : {}).length > 0 ? sessionProperties : void 0;
2471
- if (((_a2 = __privateGet(this, _transport2)) == null ? void 0 : _a2.isConnected()) && !secure) {
2703
+ const sessionData = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getCaipSession_fn).call(this);
2704
+ const { mergedScopes, mergedCaipAccountIds, mergedSessionProperties } = mergeRequestedSessionWithExisting(
2705
+ sessionData,
2706
+ scopes,
2707
+ caipAccountIds,
2708
+ sessionProperties
2709
+ );
2710
+ const nonEmptySessionProperties = Object.keys(mergedSessionProperties != null ? mergedSessionProperties : {}).length > 0 ? mergedSessionProperties : void 0;
2711
+ if (((_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.isConnected()) && !secure) {
2472
2712
  return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateGet(this, _transport2).connect({
2473
- scopes,
2474
- caipAccountIds,
2475
- sessionProperties: nonEmptySessionProperites,
2713
+ scopes: mergedScopes,
2714
+ caipAccountIds: mergedCaipAccountIds,
2715
+ sessionProperties: nonEmptySessionProperties,
2476
2716
  forceRequest
2477
2717
  }).then(() => __async(this, null, function* () {
2478
2718
  if (__privateGet(this, _transport2) instanceof MWPTransport) {
@@ -2484,47 +2724,53 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2484
2724
  if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
2485
2725
  const defaultTransport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this);
2486
2726
  return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({
2487
- scopes,
2488
- caipAccountIds,
2489
- sessionProperties: nonEmptySessionProperites,
2727
+ scopes: mergedScopes,
2728
+ caipAccountIds: mergedCaipAccountIds,
2729
+ sessionProperties: nonEmptySessionProperties,
2490
2730
  forceRequest
2491
2731
  }), scopes, transportType);
2492
2732
  }
2493
2733
  if (isWeb && hasExtensionInstalled && preferExtension) {
2494
2734
  const defaultTransport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this);
2495
2735
  return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({
2496
- scopes,
2497
- caipAccountIds,
2498
- sessionProperties: nonEmptySessionProperites,
2736
+ scopes: mergedScopes,
2737
+ caipAccountIds: mergedCaipAccountIds,
2738
+ sessionProperties: nonEmptySessionProperties,
2499
2739
  forceRequest
2500
2740
  }), scopes, transportType);
2501
2741
  }
2502
2742
  yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupMWP_fn).call(this);
2503
2743
  const shouldShowInstallModal = hasExtensionInstalled ? showInstallModal : !preferExtension || showInstallModal;
2504
2744
  if (secure && !shouldShowInstallModal) {
2505
- return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, deeplinkConnect_fn).call(this, scopes, caipAccountIds, nonEmptySessionProperites), scopes, transportType);
2745
+ return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, deeplinkConnect_fn).call(this, mergedScopes, mergedCaipAccountIds, nonEmptySessionProperties), scopes, transportType);
2506
2746
  }
2507
- return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, showInstallModal_fn).call(this, shouldShowInstallModal, scopes, caipAccountIds, nonEmptySessionProperites), scopes, transportType);
2747
+ return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, showInstallModal_fn).call(this, shouldShowInstallModal, mergedScopes, mergedCaipAccountIds, nonEmptySessionProperties), scopes, transportType);
2508
2748
  });
2509
2749
  }
2510
2750
  emit(event, args) {
2511
- var _a2, _b;
2512
- (_b = (_a2 = this.options.transport) == null ? void 0 : _a2.onNotification) == null ? void 0 : _b.call(_a2, { method: event, params: args });
2751
+ var _a3, _b;
2752
+ (_b = (_a3 = this.options.transport) == null ? void 0 : _a3.onNotification) == null ? void 0 : _b.call(_a3, { method: event, params: args });
2513
2753
  super.emit(event, args);
2514
2754
  }
2515
2755
  disconnect() {
2516
- return __async(this, null, function* () {
2517
- var _a2, _b, _c;
2518
- yield (_a2 = __privateGet(this, _listener)) == null ? void 0 : _a2.call(this);
2519
- (_b = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _b.call(this);
2520
- yield (_c = __privateGet(this, _transport2)) == null ? void 0 : _c.disconnect();
2521
- yield this.storage.removeTransport();
2522
- this.emit("stateChanged", "disconnected");
2523
- __privateSet(this, _listener, void 0);
2524
- __privateSet(this, _beforeUnloadListener, void 0);
2525
- __privateSet(this, _transport2, void 0);
2526
- __privateGet(this, _providerTransportWrapper).clearNotificationCallbacks();
2527
- __privateSet(this, _dappClient, void 0);
2756
+ return __async(this, arguments, function* (scopes = []) {
2757
+ var _a3, _b, _c;
2758
+ const sessionData = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getCaipSession_fn).call(this);
2759
+ const remainingScopes = scopes.length === 0 ? [] : Object.keys(sessionData.sessionScopes).filter(
2760
+ (scope) => !scopes.includes(scope)
2761
+ );
2762
+ yield (_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.disconnect(scopes);
2763
+ if (remainingScopes.length === 0) {
2764
+ yield (_b = __privateGet(this, _listener)) == null ? void 0 : _b.call(this);
2765
+ (_c = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _c.call(this);
2766
+ yield this.storage.removeTransport();
2767
+ __privateSet(this, _listener, void 0);
2768
+ __privateSet(this, _beforeUnloadListener, void 0);
2769
+ __privateSet(this, _transport2, void 0);
2770
+ __privateGet(this, _providerTransportWrapper).clearTransportNotificationListener();
2771
+ __privateSet(this, _dappClient, void 0);
2772
+ this.status = "disconnected";
2773
+ }
2528
2774
  });
2529
2775
  }
2530
2776
  invokeMethod(request) {
@@ -2536,7 +2782,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2536
2782
  });
2537
2783
  }
2538
2784
  // DRY THIS WITH REQUEST ROUTER
2539
- openDeeplinkIfNeeded() {
2785
+ openSimpleDeeplinkIfNeeded() {
2540
2786
  const { ui, mobile } = this.options;
2541
2787
  const { showInstallModal = false } = ui != null ? ui : {};
2542
2788
  const secure = isSecure();
@@ -2556,6 +2802,23 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2556
2802
  }), 10);
2557
2803
  }
2558
2804
  }
2805
+ // Provides a way for ecosystem clients (EVM, Solana, etc.) to get the current CAIP session data
2806
+ // when instantiating themselves (as they would have already missed any initial sessionChanged events emitted by ConnectMultichain)
2807
+ // without having to concern themselves with the current transport connection status.
2808
+ emitSessionChanged() {
2809
+ return __async(this, null, function* () {
2810
+ var _a3;
2811
+ const emptySession = { sessionScopes: {} };
2812
+ if (this.status !== "connected" && this.status !== "connecting") {
2813
+ this.emit("wallet_sessionChanged", emptySession);
2814
+ return;
2815
+ }
2816
+ const response = yield this.transport.request({
2817
+ method: "wallet_getSession"
2818
+ });
2819
+ this.emit("wallet_sessionChanged", (_a3 = response.result) != null ? _a3 : emptySession);
2820
+ });
2821
+ }
2559
2822
  };
2560
2823
  _provider = new WeakMap();
2561
2824
  _providerTransportWrapper = new WeakMap();
@@ -2567,7 +2830,7 @@ _sdkInfo = new WeakMap();
2567
2830
  _MetaMaskConnectMultichain_instances = new WeakSet();
2568
2831
  setupAnalytics_fn = function() {
2569
2832
  return __async(this, null, function* () {
2570
- var _a2;
2833
+ var _a3;
2571
2834
  const platform = getPlatformType();
2572
2835
  const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
2573
2836
  const isReactNative2 = platform === "react-native" /* ReactNative */;
@@ -2577,7 +2840,7 @@ setupAnalytics_fn = function() {
2577
2840
  const version = getVersion();
2578
2841
  const dappId = getDappId(this.options.dapp);
2579
2842
  const anonId = yield this.storage.getAnonId();
2580
- const { integrationType } = (_a2 = this.options.analytics) != null ? _a2 : {
2843
+ const { integrationType } = (_a3 = this.options.analytics) != null ? _a3 : {
2581
2844
  integrationType: ""
2582
2845
  };
2583
2846
  analytics2.setGlobalProperty("mmconnect_version", version);
@@ -2590,9 +2853,9 @@ setupAnalytics_fn = function() {
2590
2853
  };
2591
2854
  onTransportNotification_fn = function(payload) {
2592
2855
  return __async(this, null, function* () {
2593
- var _a2;
2856
+ var _a3;
2594
2857
  if (typeof payload === "object" && payload !== null && "method" in payload) {
2595
- this.emit(payload.method, (_a2 = payload.params) != null ? _a2 : payload.result);
2858
+ this.emit(payload.method, (_a3 = payload.params) != null ? _a3 : payload.result);
2596
2859
  }
2597
2860
  });
2598
2861
  };
@@ -2605,7 +2868,7 @@ getStoredTransport_fn = function() {
2605
2868
  if (hasExtensionInstalled) {
2606
2869
  const apiTransport = new DefaultTransport();
2607
2870
  __privateSet(this, _transport2, apiTransport);
2608
- __privateGet(this, _providerTransportWrapper).setupNotifcationListener();
2871
+ __privateGet(this, _providerTransportWrapper).setupTransportNotificationListener();
2609
2872
  __privateSet(this, _listener, apiTransport.onNotification(
2610
2873
  __privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
2611
2874
  ));
@@ -2617,7 +2880,7 @@ getStoredTransport_fn = function() {
2617
2880
  const apiTransport = new MWPTransport(dappClient, kvstore);
2618
2881
  __privateSet(this, _dappClient, dappClient);
2619
2882
  __privateSet(this, _transport2, apiTransport);
2620
- __privateGet(this, _providerTransportWrapper).setupNotifcationListener();
2883
+ __privateGet(this, _providerTransportWrapper).setupTransportNotificationListener();
2621
2884
  __privateSet(this, _listener, apiTransport.onNotification(
2622
2885
  __privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
2623
2886
  ));
@@ -2649,25 +2912,17 @@ setupTransport_fn = function() {
2649
2912
  };
2650
2913
  init_fn = function() {
2651
2914
  return __async(this, null, function* () {
2652
- var _a2;
2653
2915
  try {
2654
- if (typeof window !== "undefined" && ((_a2 = window.mmsdk) == null ? void 0 : _a2.isInitialized)) {
2655
- logger2("MetaMaskSDK: init already initialized");
2656
- } else {
2657
- yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(this);
2658
- yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupTransport_fn).call(this);
2659
- try {
2660
- const baseProps = yield getBaseAnalyticsProperties(
2661
- this.options,
2662
- this.storage
2663
- );
2664
- analytics2.track("mmconnect_initialized", baseProps);
2665
- } catch (error) {
2666
- logger2("Error tracking initialized event", error);
2667
- }
2668
- if (typeof window !== "undefined") {
2669
- window.mmsdk = this;
2670
- }
2916
+ yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(this);
2917
+ yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupTransport_fn).call(this);
2918
+ try {
2919
+ const baseProps = yield getBaseAnalyticsProperties(
2920
+ this.options,
2921
+ this.storage
2922
+ );
2923
+ analytics2.track("mmconnect_initialized", baseProps);
2924
+ } catch (error) {
2925
+ logger2("Error tracking initialized event", error);
2671
2926
  }
2672
2927
  } catch (error) {
2673
2928
  yield this.storage.removeTransport();
@@ -2703,7 +2958,7 @@ setupMWP_fn = function() {
2703
2958
  __privateSet(this, _dappClient, dappClient);
2704
2959
  const apiTransport = new MWPTransport(dappClient, kvstore);
2705
2960
  __privateSet(this, _transport2, apiTransport);
2706
- __privateGet(this, _providerTransportWrapper).setupNotifcationListener();
2961
+ __privateGet(this, _providerTransportWrapper).setupTransportNotificationListener();
2707
2962
  __privateSet(this, _listener, this.transport.onNotification(
2708
2963
  __privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
2709
2964
  ));
@@ -2712,22 +2967,20 @@ setupMWP_fn = function() {
2712
2967
  };
2713
2968
  onBeforeUnload_fn = function() {
2714
2969
  return __async(this, null, function* () {
2715
- var _a2;
2716
- if ((_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.isMounted) {
2970
+ var _a3;
2971
+ if ((_a3 = this.options.ui.factory.modal) == null ? void 0 : _a3.isMounted) {
2717
2972
  yield this.storage.removeTransport();
2718
2973
  }
2719
2974
  });
2720
2975
  };
2721
2976
  createBeforeUnloadListener_fn = function() {
2977
+ const handler = __privateMethod(this, _MetaMaskConnectMultichain_instances, onBeforeUnload_fn).bind(this);
2722
2978
  if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
2723
- window.addEventListener("beforeunload", __privateMethod(this, _MetaMaskConnectMultichain_instances, onBeforeUnload_fn).bind(this));
2979
+ window.addEventListener("beforeunload", handler);
2724
2980
  }
2725
2981
  return () => {
2726
2982
  if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined") {
2727
- window.removeEventListener(
2728
- "beforeunload",
2729
- __privateMethod(this, _MetaMaskConnectMultichain_instances, onBeforeUnload_fn).bind(this)
2730
- );
2983
+ window.removeEventListener("beforeunload", handler);
2731
2984
  }
2732
2985
  };
2733
2986
  };
@@ -2757,7 +3010,7 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds,
2757
3010
  }
2758
3011
  );
2759
3012
  (() => __async(this, null, function* () {
2760
- var _a2;
3013
+ var _a3;
2761
3014
  try {
2762
3015
  yield this.transport.connect({
2763
3016
  scopes,
@@ -2765,20 +3018,21 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds,
2765
3018
  sessionProperties
2766
3019
  });
2767
3020
  yield this.options.ui.factory.unload();
2768
- (_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
3021
+ (_a3 = this.options.ui.factory.modal) == null ? void 0 : _a3.unmount();
2769
3022
  this.status = "connected";
2770
3023
  yield this.storage.setTransport("mwp" /* MWP */);
2771
3024
  } catch (error) {
2772
3025
  if (error instanceof ProtocolError) {
2773
3026
  if (error.code !== ErrorCode.REQUEST_EXPIRED) {
2774
3027
  this.status = "disconnected";
3028
+ yield this.options.ui.factory.unload(error);
2775
3029
  reject(error);
2776
3030
  }
2777
3031
  } else {
2778
3032
  this.status = "disconnected";
2779
- reject(
2780
- error instanceof Error ? error : new Error(String(error))
2781
- );
3033
+ const normalizedError = error instanceof Error ? error : new Error(String(error));
3034
+ yield this.options.ui.factory.unload(normalizedError);
3035
+ reject(normalizedError);
2782
3036
  }
2783
3037
  }
2784
3038
  }))().catch(() => {
@@ -2805,8 +3059,8 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds,
2805
3059
  };
2806
3060
  showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
2807
3061
  return __async(this, null, function* () {
2808
- var _a2;
2809
- (_a2 = __privateGet(this, _beforeUnloadListener)) != null ? _a2 : __privateSet(this, _beforeUnloadListener, __privateMethod(this, _MetaMaskConnectMultichain_instances, createBeforeUnloadListener_fn).call(this));
3062
+ var _a3;
3063
+ (_a3 = __privateGet(this, _beforeUnloadListener)) != null ? _a3 : __privateSet(this, _beforeUnloadListener, __privateMethod(this, _MetaMaskConnectMultichain_instances, createBeforeUnloadListener_fn).call(this));
2810
3064
  if (this.options.ui.headless) {
2811
3065
  yield __privateMethod(this, _MetaMaskConnectMultichain_instances, headlessConnect_fn).call(this, scopes, caipAccountIds, sessionProperties);
2812
3066
  } else {
@@ -2865,7 +3119,7 @@ setupDefaultTransport_fn = function() {
2865
3119
  __privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
2866
3120
  ));
2867
3121
  __privateSet(this, _transport2, transport);
2868
- __privateGet(this, _providerTransportWrapper).setupNotifcationListener();
3122
+ __privateGet(this, _providerTransportWrapper).setupTransportNotificationListener();
2869
3123
  return transport;
2870
3124
  });
2871
3125
  };
@@ -2873,7 +3127,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
2873
3127
  return __async(this, null, function* () {
2874
3128
  return new Promise((resolve, reject) => __async(this, null, function* () {
2875
3129
  const dappClientMessageHandler = (payload) => {
2876
- var _a2;
3130
+ var _a3;
2877
3131
  if (typeof payload !== "object" || payload === null || !("data" in payload)) {
2878
3132
  return;
2879
3133
  }
@@ -2883,7 +3137,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
2883
3137
  this.dappClient.off("message", dappClientMessageHandler);
2884
3138
  reject(data.error);
2885
3139
  }
2886
- if ((_a2 = data == null ? void 0 : data.result) == null ? void 0 : _a2.sessionScopes) {
3140
+ if ((_a3 = data == null ? void 0 : data.result) == null ? void 0 : _a3.sessionScopes) {
2887
3141
  this.dappClient.off("message", dappClientMessageHandler);
2888
3142
  }
2889
3143
  }
@@ -2892,13 +3146,13 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
2892
3146
  let timeout;
2893
3147
  if (this.transport.isConnected()) {
2894
3148
  timeout = setTimeout(() => {
2895
- this.openDeeplinkIfNeeded();
3149
+ this.openSimpleDeeplinkIfNeeded();
2896
3150
  }, 250);
2897
3151
  } else {
2898
3152
  this.dappClient.once(
2899
3153
  "session_request",
2900
3154
  (sessionRequest) => {
2901
- var _a2;
3155
+ var _a3;
2902
3156
  const connectionRequest = {
2903
3157
  sessionRequest,
2904
3158
  metadata: {
@@ -2913,7 +3167,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
2913
3167
  connectionRequest
2914
3168
  );
2915
3169
  this.emit("display_uri", deeplink);
2916
- if ((_a2 = this.options.mobile) == null ? void 0 : _a2.preferredOpenLink) {
3170
+ if ((_a3 = this.options.mobile) == null ? void 0 : _a3.preferredOpenLink) {
2917
3171
  this.options.mobile.preferredOpenLink(deeplink, "_self");
2918
3172
  } else {
2919
3173
  openDeeplink(this.options, deeplink, universalLink);
@@ -2975,6 +3229,53 @@ handleConnection_fn = function(promise, scopes, transportType) {
2975
3229
  }));
2976
3230
  });
2977
3231
  };
3232
+ getCaipSession_fn = function() {
3233
+ return __async(this, null, function* () {
3234
+ let sessionData = {
3235
+ sessionScopes: {},
3236
+ sessionProperties: {}
3237
+ };
3238
+ if (this.status === "connected") {
3239
+ const response = yield this.transport.request({
3240
+ method: "wallet_getSession"
3241
+ });
3242
+ if (response.result) {
3243
+ sessionData = response.result;
3244
+ }
3245
+ }
3246
+ return sessionData;
3247
+ });
3248
+ };
3249
+ openConnectDeeplinkIfNeeded_fn = function() {
3250
+ return __async(this, null, function* () {
3251
+ var _a3, _b;
3252
+ const { ui } = this.options;
3253
+ const { showInstallModal = false } = ui != null ? ui : {};
3254
+ const secure = isSecure();
3255
+ const shouldOpenDeeplink = secure && !showInstallModal;
3256
+ if (!shouldOpenDeeplink) {
3257
+ return;
3258
+ }
3259
+ const storedSessionRequest = yield (_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.getStoredPendingSessionRequest();
3260
+ if (!storedSessionRequest) {
3261
+ return;
3262
+ }
3263
+ const connectionRequest = {
3264
+ sessionRequest: storedSessionRequest,
3265
+ metadata: {
3266
+ dapp: this.options.dapp,
3267
+ sdk: { version: getVersion(), platform: getPlatformType() }
3268
+ }
3269
+ };
3270
+ const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
3271
+ const universalLink = this.options.ui.factory.createConnectionUniversalLink(connectionRequest);
3272
+ if ((_b = this.options.mobile) == null ? void 0 : _b.preferredOpenLink) {
3273
+ this.options.mobile.preferredOpenLink(deeplink, "_self");
3274
+ } else {
3275
+ openDeeplink(this.options, deeplink, universalLink);
3276
+ }
3277
+ });
3278
+ };
2978
3279
  var MetaMaskConnectMultichain = _MetaMaskConnectMultichain;
2979
3280
 
2980
3281
  // src/store/index.ts
@@ -3159,7 +3460,7 @@ var Store = class extends StoreClient {
3159
3460
  // src/ui/ModalFactory.ts
3160
3461
  import MetaMaskOnboarding from "@metamask/onboarding";
3161
3462
  init_domain();
3162
- init_utils();
3463
+ init_utils2();
3163
3464
  var BaseModalFactory = class {
3164
3465
  /**
3165
3466
  * Creates a new modal factory instance.
@@ -3182,8 +3483,8 @@ var BaseModalFactory = class {
3182
3483
  }
3183
3484
  unload(error) {
3184
3485
  return __async(this, null, function* () {
3185
- var _a2, _b;
3186
- (_a2 = this.modal) == null ? void 0 : _a2.unmount();
3486
+ var _a3, _b;
3487
+ (_a3 = this.modal) == null ? void 0 : _a3.unmount();
3187
3488
  yield (_b = this.successCallback) == null ? void 0 : _b.call(this, error);
3188
3489
  });
3189
3490
  }
@@ -3253,8 +3554,8 @@ var BaseModalFactory = class {
3253
3554
  }
3254
3555
  renderInstallModal(showInstallModal, createConnectionRequest, successCallback, onDisplayUri) {
3255
3556
  return __async(this, null, function* () {
3256
- var _a2, _b;
3257
- (_a2 = this.modal) == null ? void 0 : _a2.unmount();
3557
+ var _a3, _b;
3558
+ (_a3 = this.modal) == null ? void 0 : _a3.unmount();
3258
3559
  yield this.preload();
3259
3560
  this.successCallback = successCallback;
3260
3561
  this.displayUriCallback = onDisplayUri;
@@ -3270,9 +3571,9 @@ var BaseModalFactory = class {
3270
3571
  link: qrCodeLink,
3271
3572
  sdkVersion: getVersion(),
3272
3573
  generateQRCode: (request) => __async(this, null, function* () {
3273
- var _a3;
3574
+ var _a4;
3274
3575
  const newLink = this.createConnectionDeeplink(request);
3275
- (_a3 = this.displayUriCallback) == null ? void 0 : _a3.call(this, newLink);
3576
+ (_a4 = this.displayUriCallback) == null ? void 0 : _a4.call(this, newLink);
3276
3577
  return newLink;
3277
3578
  }),
3278
3579
  onClose: this.onCloseModal.bind(this),
@@ -3286,8 +3587,8 @@ var BaseModalFactory = class {
3286
3587
  }
3287
3588
  renderOTPCodeModal(createOTPCode, successCallback, updateOTPCode) {
3288
3589
  return __async(this, null, function* () {
3289
- var _a2;
3290
- (_a2 = this.modal) == null ? void 0 : _a2.unmount();
3590
+ var _a3;
3591
+ (_a3 = this.modal) == null ? void 0 : _a3.unmount();
3291
3592
  yield this.preload();
3292
3593
  this.successCallback = successCallback;
3293
3594
  const container = this.getMountedContainer();