@web3auth/modal 11.0.0-beta.0 → 11.0.0-beta.1

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 (118) hide show
  1. package/dist/lib.cjs/packages/modal/src/account-linking/index.js +12 -0
  2. package/dist/lib.cjs/packages/modal/src/account-linking/react.js +22 -0
  3. package/dist/lib.cjs/packages/modal/src/account-linking/vue.js +22 -0
  4. package/dist/lib.cjs/packages/modal/src/config.js +1 -1
  5. package/dist/lib.cjs/packages/modal/src/modalManager.js +446 -26
  6. package/dist/lib.cjs/packages/modal/src/react/index.js +7 -3
  7. package/dist/lib.cjs/packages/modal/src/react/wagmi/provider.js +27 -12
  8. package/dist/lib.cjs/packages/modal/src/ui/components/BottomSheet/BottomSheet.js +13 -13
  9. package/dist/lib.cjs/packages/modal/src/ui/components/Button/ButtonSocial/ButtonSocial.js +4 -4
  10. package/dist/lib.cjs/packages/modal/src/ui/components/Button/ButtonWallet/ButtonWallet.js +10 -10
  11. package/dist/lib.cjs/packages/modal/src/ui/components/Footer/Footer.js +7 -7
  12. package/dist/lib.cjs/packages/modal/src/ui/components/Image/Image.js +4 -4
  13. package/dist/lib.cjs/packages/modal/src/ui/components/Loader/Loader.js +28 -28
  14. package/dist/lib.cjs/packages/modal/src/ui/components/LoginHint/LoginHint.js +3 -3
  15. package/dist/lib.cjs/packages/modal/src/ui/components/Modal/Modal.js +19 -19
  16. package/dist/lib.cjs/packages/modal/src/ui/components/Otp/Otp.js +10 -10
  17. package/dist/lib.cjs/packages/modal/src/ui/components/PulseLoader/PulseLoader.js +4 -4
  18. package/dist/lib.cjs/packages/modal/src/ui/components/SocialLoginList/SocialLoginList.js +21 -21
  19. package/dist/lib.cjs/packages/modal/src/ui/components/SpinnerLoader/SpinnerLoader.js +1 -1
  20. package/dist/lib.cjs/packages/modal/src/ui/components/Toast/Toast.js +11 -11
  21. package/dist/lib.cjs/packages/modal/src/ui/containers/AccountLinking/AccountLinking.js +109 -0
  22. package/dist/lib.cjs/packages/modal/src/ui/containers/ConnectWallet/ConnectWallet.js +14 -3
  23. package/dist/lib.cjs/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletChainFilter/ConnectWalletChainFilter.js +7 -7
  24. package/dist/lib.cjs/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletChainNamespaceSelect/ConnectWalletChainNamespaceSelect.js +9 -9
  25. package/dist/lib.cjs/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletHeader/ConnectWalletHeader.js +9 -8
  26. package/dist/lib.cjs/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletList/ConnectWalletList.js +19 -19
  27. package/dist/lib.cjs/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletQrCode/ConnectWalletQrCode.js +8 -8
  28. package/dist/lib.cjs/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletSearch/ConnectWalletSearch.js +5 -5
  29. package/dist/lib.cjs/packages/modal/src/ui/containers/Embed/Embed.js +11 -11
  30. package/dist/lib.cjs/packages/modal/src/ui/containers/Login/Login.js +45 -41
  31. package/dist/lib.cjs/packages/modal/src/ui/containers/Login/LoginOtp/LoginOtp.js +11 -11
  32. package/dist/lib.cjs/packages/modal/src/ui/containers/Login/LoginPasswordLess/LoginPasswordLess.js +13 -13
  33. package/dist/lib.cjs/packages/modal/src/ui/containers/Root/Root.js +24 -9
  34. package/dist/lib.cjs/packages/modal/src/ui/containers/Root/RootBodySheets/RootBodySheets.js +16 -16
  35. package/dist/lib.cjs/packages/modal/src/ui/containers/Widget/Widget.js +6 -2
  36. package/dist/lib.cjs/packages/modal/src/ui/context/ModalStateContext.js +1 -0
  37. package/dist/lib.cjs/packages/modal/src/ui/css/index.css.js +1 -1
  38. package/dist/lib.cjs/packages/modal/src/ui/i18n/dutch.json.js +14 -0
  39. package/dist/lib.cjs/packages/modal/src/ui/i18n/english.json.js +14 -0
  40. package/dist/lib.cjs/packages/modal/src/ui/i18n/french.json.js +14 -0
  41. package/dist/lib.cjs/packages/modal/src/ui/i18n/german.json.js +14 -0
  42. package/dist/lib.cjs/packages/modal/src/ui/i18n/japanese.json.js +26 -12
  43. package/dist/lib.cjs/packages/modal/src/ui/i18n/korean.json.js +14 -0
  44. package/dist/lib.cjs/packages/modal/src/ui/i18n/mandarin.json.js +14 -0
  45. package/dist/lib.cjs/packages/modal/src/ui/i18n/portuguese.json.js +14 -0
  46. package/dist/lib.cjs/packages/modal/src/ui/i18n/spanish.json.js +14 -0
  47. package/dist/lib.cjs/packages/modal/src/ui/i18n/turkish.json.js +14 -0
  48. package/dist/lib.cjs/packages/modal/src/ui/interfaces.js +26 -0
  49. package/dist/lib.cjs/packages/modal/src/ui/loginModal.js +113 -4
  50. package/dist/lib.cjs/packages/modal/src/vue/index.js +7 -3
  51. package/dist/lib.cjs/packages/modal/src/vue/wagmi/provider.js +27 -14
  52. package/dist/lib.cjs/types/account-linking/index.d.ts +1 -0
  53. package/dist/lib.cjs/types/account-linking/react.d.ts +2 -0
  54. package/dist/lib.cjs/types/account-linking/vue.d.ts +2 -0
  55. package/dist/lib.cjs/types/modalManager.d.ts +40 -2
  56. package/dist/lib.cjs/types/react/hooks/index.d.ts +1 -0
  57. package/dist/lib.cjs/types/react/hooks/useWallets.d.ts +2 -0
  58. package/dist/lib.cjs/types/ui/containers/AccountLinking/AccountLinking.d.ts +6 -0
  59. package/dist/lib.cjs/types/ui/containers/AccountLinking/index.d.ts +1 -0
  60. package/dist/lib.cjs/types/ui/containers/ConnectWallet/ConnectWalletHeader/ConnectWalletHeader.type.d.ts +1 -0
  61. package/dist/lib.cjs/types/ui/containers/Root/Root.d.ts +1 -1
  62. package/dist/lib.cjs/types/ui/interfaces.d.ts +43 -8
  63. package/dist/lib.cjs/types/ui/loginModal.d.ts +27 -2
  64. package/dist/lib.cjs/types/ui/utils.d.ts +1 -1
  65. package/dist/lib.cjs/types/vue/composables/index.d.ts +1 -0
  66. package/dist/lib.cjs/types/vue/composables/useWallets.d.ts +2 -0
  67. package/dist/lib.esm/packages/modal/src/account-linking/index.js +1 -0
  68. package/dist/lib.esm/packages/modal/src/account-linking/react.js +1 -0
  69. package/dist/lib.esm/packages/modal/src/account-linking/vue.js +1 -0
  70. package/dist/lib.esm/packages/modal/src/config.js +1 -1
  71. package/dist/lib.esm/packages/modal/src/modalManager.js +451 -28
  72. package/dist/lib.esm/packages/modal/src/react/index.js +1 -1
  73. package/dist/lib.esm/packages/modal/src/react/wagmi/provider.js +28 -13
  74. package/dist/lib.esm/packages/modal/src/ui/components/BottomSheet/BottomSheet.js +13 -13
  75. package/dist/lib.esm/packages/modal/src/ui/components/Button/ButtonSocial/ButtonSocial.js +4 -4
  76. package/dist/lib.esm/packages/modal/src/ui/components/Button/ButtonWallet/ButtonWallet.js +10 -10
  77. package/dist/lib.esm/packages/modal/src/ui/components/Footer/Footer.js +7 -7
  78. package/dist/lib.esm/packages/modal/src/ui/components/Image/Image.js +4 -4
  79. package/dist/lib.esm/packages/modal/src/ui/components/Loader/Loader.js +28 -28
  80. package/dist/lib.esm/packages/modal/src/ui/components/LoginHint/LoginHint.js +3 -3
  81. package/dist/lib.esm/packages/modal/src/ui/components/Modal/Modal.js +19 -19
  82. package/dist/lib.esm/packages/modal/src/ui/components/Otp/Otp.js +10 -10
  83. package/dist/lib.esm/packages/modal/src/ui/components/PulseLoader/PulseLoader.js +4 -4
  84. package/dist/lib.esm/packages/modal/src/ui/components/SocialLoginList/SocialLoginList.js +21 -21
  85. package/dist/lib.esm/packages/modal/src/ui/components/SpinnerLoader/SpinnerLoader.js +1 -1
  86. package/dist/lib.esm/packages/modal/src/ui/components/Toast/Toast.js +11 -11
  87. package/dist/lib.esm/packages/modal/src/ui/containers/AccountLinking/AccountLinking.js +107 -0
  88. package/dist/lib.esm/packages/modal/src/ui/containers/ConnectWallet/ConnectWallet.js +14 -3
  89. package/dist/lib.esm/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletChainFilter/ConnectWalletChainFilter.js +7 -7
  90. package/dist/lib.esm/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletChainNamespaceSelect/ConnectWalletChainNamespaceSelect.js +9 -9
  91. package/dist/lib.esm/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletHeader/ConnectWalletHeader.js +9 -8
  92. package/dist/lib.esm/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletList/ConnectWalletList.js +19 -19
  93. package/dist/lib.esm/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletQrCode/ConnectWalletQrCode.js +8 -8
  94. package/dist/lib.esm/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletSearch/ConnectWalletSearch.js +5 -5
  95. package/dist/lib.esm/packages/modal/src/ui/containers/Embed/Embed.js +11 -11
  96. package/dist/lib.esm/packages/modal/src/ui/containers/Login/Login.js +46 -42
  97. package/dist/lib.esm/packages/modal/src/ui/containers/Login/LoginOtp/LoginOtp.js +11 -11
  98. package/dist/lib.esm/packages/modal/src/ui/containers/Login/LoginPasswordLess/LoginPasswordLess.js +13 -13
  99. package/dist/lib.esm/packages/modal/src/ui/containers/Root/Root.js +24 -9
  100. package/dist/lib.esm/packages/modal/src/ui/containers/Root/RootBodySheets/RootBodySheets.js +16 -16
  101. package/dist/lib.esm/packages/modal/src/ui/containers/Widget/Widget.js +6 -2
  102. package/dist/lib.esm/packages/modal/src/ui/context/ModalStateContext.js +2 -1
  103. package/dist/lib.esm/packages/modal/src/ui/css/index.css.js +1 -1
  104. package/dist/lib.esm/packages/modal/src/ui/i18n/dutch.json.js +14 -0
  105. package/dist/lib.esm/packages/modal/src/ui/i18n/english.json.js +14 -0
  106. package/dist/lib.esm/packages/modal/src/ui/i18n/french.json.js +14 -0
  107. package/dist/lib.esm/packages/modal/src/ui/i18n/german.json.js +14 -0
  108. package/dist/lib.esm/packages/modal/src/ui/i18n/japanese.json.js +26 -12
  109. package/dist/lib.esm/packages/modal/src/ui/i18n/korean.json.js +14 -0
  110. package/dist/lib.esm/packages/modal/src/ui/i18n/mandarin.json.js +14 -0
  111. package/dist/lib.esm/packages/modal/src/ui/i18n/portuguese.json.js +14 -0
  112. package/dist/lib.esm/packages/modal/src/ui/i18n/spanish.json.js +14 -0
  113. package/dist/lib.esm/packages/modal/src/ui/i18n/turkish.json.js +14 -0
  114. package/dist/lib.esm/packages/modal/src/ui/interfaces.js +24 -1
  115. package/dist/lib.esm/packages/modal/src/ui/loginModal.js +115 -6
  116. package/dist/lib.esm/packages/modal/src/vue/index.js +1 -1
  117. package/dist/lib.esm/packages/modal/src/vue/wagmi/provider.js +28 -15
  118. package/package.json +42 -19
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ var accountLinking = require('@web3auth/no-modal/account-linking');
4
+
5
+
6
+
7
+ Object.keys(accountLinking).forEach(function (k) {
8
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
9
+ enumerable: true,
10
+ get: function () { return accountLinking[k]; }
11
+ });
12
+ });
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ var react = require('@web3auth/no-modal/account-linking/react');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "makeAccountLinkingRequest", {
8
+ enumerable: true,
9
+ get: function () { return react.makeAccountLinkingRequest; }
10
+ });
11
+ Object.defineProperty(exports, "makeAccountUnlinkingRequest", {
12
+ enumerable: true,
13
+ get: function () { return react.makeAccountUnlinkingRequest; }
14
+ });
15
+ Object.defineProperty(exports, "useLinkAccount", {
16
+ enumerable: true,
17
+ get: function () { return react.useLinkAccount; }
18
+ });
19
+ Object.defineProperty(exports, "useSwitchAccount", {
20
+ enumerable: true,
21
+ get: function () { return react.useSwitchAccount; }
22
+ });
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ var vue = require('@web3auth/no-modal/account-linking/vue');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "makeAccountLinkingRequest", {
8
+ enumerable: true,
9
+ get: function () { return vue.makeAccountLinkingRequest; }
10
+ });
11
+ Object.defineProperty(exports, "makeAccountUnlinkingRequest", {
12
+ enumerable: true,
13
+ get: function () { return vue.makeAccountUnlinkingRequest; }
14
+ });
15
+ Object.defineProperty(exports, "useLinkAccount", {
16
+ enumerable: true,
17
+ get: function () { return vue.useLinkAccount; }
18
+ });
19
+ Object.defineProperty(exports, "useSwitchAccount", {
20
+ enumerable: true,
21
+ get: function () { return vue.useSwitchAccount; }
22
+ });
@@ -2,7 +2,7 @@
2
2
 
3
3
  var noModal = require('@web3auth/no-modal');
4
4
 
5
- const version = "11.0.0-beta.0";
5
+ const version = "11.0.0-beta.1";
6
6
  const defaultConnectorsModalConfig = {
7
7
  hideWalletDiscovery: false,
8
8
  connectors: {
@@ -13,12 +13,15 @@ var utils = require('./ui/utils.js');
13
13
 
14
14
  class Web3Auth extends noModal.Web3AuthNoModal {
15
15
  constructor(options, initialState) {
16
- var _this$options$uiConfi;
17
16
  super(options, initialState);
18
17
  _defineProperty(this, "loginModal", void 0);
19
18
  _defineProperty(this, "loginMode", noModal.LOGIN_MODE.MODAL);
20
19
  _defineProperty(this, "options", void 0);
21
20
  _defineProperty(this, "modalConfig", noModal.cloneDeep(config.defaultConnectorsModalConfig));
21
+ _defineProperty(this, "removeAccountLinkingConnectorListeners", null);
22
+ _defineProperty(this, "removeAccountLinkingResetOnCloseListener", null);
23
+ _defineProperty(this, "accountLinkingPickerResolver", null);
24
+ _defineProperty(this, "removeAccountLinkingPickerCloseListener", null);
22
25
  _defineProperty(this, "onInitExternalWallets", async params => {
23
26
  if (params.externalWalletsInitialized) return;
24
27
  // initialize WC connector only as other external wallets are initialized in initModal
@@ -35,6 +38,13 @@ class Web3Auth extends noModal.Web3AuthNoModal {
35
38
  }
36
39
  });
37
40
  _defineProperty(this, "onExternalWalletLogin", async params => {
41
+ // If the modal is in account-linking picker mode, hand off the selected connector
42
+ // to the linking flow instead of running the regular login `connectTo`.
43
+ if (this.accountLinkingPickerResolver) {
44
+ const resolver = this.accountLinkingPickerResolver;
45
+ resolver(params.connector);
46
+ return;
47
+ }
38
48
  try {
39
49
  var _params$loginParams;
40
50
  const connector = this.getConnector(params.connector, (_params$loginParams = params.loginParams) === null || _params$loginParams === void 0 ? void 0 : _params$loginParams.chainNamespace);
@@ -53,8 +63,12 @@ class Web3Auth extends noModal.Web3AuthNoModal {
53
63
  }
54
64
  });
55
65
  _defineProperty(this, "onModalVisibility", async visibility => {
66
+ var _this$loginModal;
56
67
  noModal.log.debug("is login modal visible", visibility);
57
68
  this.emit(interfaces.LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, visibility);
69
+ if ((_this$loginModal = this.loginModal) !== null && _this$loginModal !== void 0 && _this$loginModal.hasActiveAccountLinkingSession()) {
70
+ return;
71
+ }
58
72
  // handle WC session refresh
59
73
  const wcConnector = this.getConnector(noModal.WALLET_CONNECTORS.WALLET_CONNECT_V2);
60
74
  if (wcConnector) {
@@ -112,7 +126,8 @@ class Web3Auth extends noModal.Web3AuthNoModal {
112
126
  }
113
127
  if (!this.options.uiConfig) this.options.uiConfig = {};
114
128
  if (this.options.modalConfig) this.modalConfig = this.options.modalConfig;
115
- this.consentRequired = ((_this$options$uiConfi = this.options.uiConfig.consentConfig) === null || _this$options$uiConfi === void 0 ? void 0 : _this$options$uiConfi.required) || false;
129
+ // consent required is true if the consent required is true and the privacy policy and tnc link are set
130
+ this.consentRequired = this.options.uiConfig.consentRequired && Boolean(this.options.uiConfig.privacyPolicy) && Boolean(this.options.uiConfig.tncLink) || false;
116
131
  noModal.log.info("modalConfig", this.modalConfig);
117
132
  }
118
133
  async init(options) {
@@ -133,7 +148,7 @@ class Web3Auth extends noModal.Web3AuthNoModal {
133
148
  });
134
149
  let trackData = {};
135
150
  try {
136
- var _this$options$uiConfi2, _authConnector$authIn, _this$coreOptions$uiC;
151
+ var _authConnector$authIn, _this$coreOptions$uiC;
137
152
  const {
138
153
  signal
139
154
  } = options || {};
@@ -177,7 +192,7 @@ class Web3Auth extends noModal.Web3AuthNoModal {
177
192
  onAcceptConsent: this.onAcceptConsent,
178
193
  onDeclineConsent: this.onDeclineConsent
179
194
  });
180
- this.consentRequired = ((_this$options$uiConfi2 = this.options.uiConfig.consentConfig) === null || _this$options$uiConfi2 === void 0 ? void 0 : _this$options$uiConfi2.required) || false;
195
+ this.consentRequired = this.loginModal.consentRequired;
181
196
  await noModal.withAbort(() => this.loginModal.initModal(), signal);
182
197
  // setup common JRPC provider
183
198
  await noModal.withAbort(() => this.setupCommonJRPCProvider(), signal);
@@ -227,9 +242,11 @@ class Web3Auth extends noModal.Web3AuthNoModal {
227
242
  async connect() {
228
243
  if (!this.loginModal) throw noModal.WalletInitializationError.notReady("Login modal is not initialized");
229
244
  // if already connected return connection
230
- if (this.connectedConnectorName && noModal.CONNECTED_STATUSES.includes(this.status) && this.connection) return this.connection;
245
+ if (noModal.CONNECTED_STATUSES.includes(this.status) && this.connection) return this.connection;
231
246
  this.loginModal.open();
232
247
  return new Promise((resolve, reject) => {
248
+ // track connection started event
249
+ const startTime = Date.now();
233
250
  // remove all listeners when promise is resolved or rejected.
234
251
  // this is to prevent memory leaks if user clicks connect button multiple times.
235
252
  const handleCompletion = () => {
@@ -242,6 +259,22 @@ class Web3Auth extends noModal.Web3AuthNoModal {
242
259
  }
243
260
  return resolve(this.connection);
244
261
  };
262
+ const handleConsentAccepted = async () => {
263
+ try {
264
+ var _this$primaryConnecto;
265
+ // track connection completed event
266
+ const userInfo = await this.getUserInfo();
267
+ // TODO: correct event data
268
+ this.analytics.track(noModal.ANALYTICS_EVENTS.CONNECTION_COMPLETED, {
269
+ connector: (_this$primaryConnecto = this.primaryConnector) === null || _this$primaryConnecto === void 0 ? void 0 : _this$primaryConnecto.name,
270
+ is_mfa_enabled: userInfo === null || userInfo === void 0 ? void 0 : userInfo.isMfaEnabled,
271
+ duration: Date.now() - startTime
272
+ });
273
+ } catch (error) {
274
+ noModal.log.error("Failed to track connection completed event after consent acceptance", error);
275
+ }
276
+ handleCompletion();
277
+ };
245
278
  const handleError = err => {
246
279
  this.removeListener(noModal.CONNECTOR_EVENTS.CONNECTED, handleCompletion);
247
280
  this.removeListener(noModal.CONNECTOR_EVENTS.AUTHORIZED, handleCompletion);
@@ -258,7 +291,7 @@ class Web3Auth extends noModal.Web3AuthNoModal {
258
291
  }
259
292
  };
260
293
  if (this.consentRequired) {
261
- this.once(noModal.CONNECTOR_EVENTS.CONSENT_ACCEPTED, handleCompletion);
294
+ this.once(noModal.CONNECTOR_EVENTS.CONSENT_ACCEPTED, handleConsentAccepted);
262
295
  }
263
296
  if (this.coreOptions.initialAuthenticationMode === noModal.CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN) {
264
297
  this.once(noModal.CONNECTOR_EVENTS.AUTHORIZED, handleCompletion);
@@ -272,6 +305,115 @@ class Web3Auth extends noModal.Web3AuthNoModal {
272
305
  async acceptConsent() {
273
306
  await super.completeConsentAcceptance();
274
307
  }
308
+ async switchAccount(account) {
309
+ const authConnector = this.getMainAuthConnector();
310
+ const switchResult = await authConnector.switchAccount(account, {
311
+ activeAccount: this.activeAccount,
312
+ currentChainId: this.currentChainId
313
+ });
314
+ if (!switchResult) {
315
+ return;
316
+ }
317
+ try {
318
+ var _await$this$getProjec;
319
+ const existingConnector = switchResult.kind === "external" ? this.getConnectedWalletConnector(switchResult.targetAccount) : null;
320
+ // check if the existing connector is connected and usable, then we can switch to it without re-connecting again
321
+ const isExistingConnectorConnected = Boolean(existingConnector && this.hasUsableConnectedSwitchConnector(existingConnector));
322
+ const projectConfig = switchResult.kind === "external" && !isExistingConnectorConnected ? (_await$this$getProjec = await this.getProjectAndWalletConfig()) === null || _await$this$getProjec === void 0 ? void 0 : _await$this$getProjec.projectConfig : undefined;
323
+ if (switchResult.kind !== "external" || isExistingConnectorConnected) {
324
+ await this.runNonWalletConnectAccountAction(switchResult.targetAccount.connector, () => super.processSwitchAccountResult(authConnector, switchResult, {
325
+ walletConnector: isExistingConnectorConnected && existingConnector ? existingConnector : undefined,
326
+ projectConfig
327
+ }), {
328
+ skipSuccessScreen: true
329
+ });
330
+ await authConnector.trackSwitchAccountCompleted(switchResult.targetAccount);
331
+ return;
332
+ }
333
+ const connectorToSwitchTo = await this.prepareAccountSwitchConnector(switchResult.targetAccount.connector, switchResult.activeChainId, projectConfig);
334
+ if (connectorToSwitchTo.name !== noModal.WALLET_CONNECTORS.WALLET_CONNECT_V2) {
335
+ await this.runNonWalletConnectAccountAction(switchResult.targetAccount.connector, () => super.processSwitchAccountResult(authConnector, switchResult, {
336
+ walletConnector: connectorToSwitchTo,
337
+ projectConfig
338
+ }), {
339
+ skipSuccessScreen: true
340
+ });
341
+ await authConnector.trackSwitchAccountCompleted(switchResult.targetAccount);
342
+ return;
343
+ }
344
+ await this.switchToWalletConnectV2Account(switchResult, connectorToSwitchTo, projectConfig);
345
+ } catch (error) {
346
+ await authConnector.trackSwitchAccountFailed(switchResult.targetAccount, error);
347
+ throw error;
348
+ }
349
+ }
350
+ async linkAccount(params) {
351
+ // Pre-flight: ensure user is connected via AUTH so we fail fast before opening the modal.
352
+ this.getMainAuthConnector();
353
+ const chainId = this.resolveLinkAccountChainId(params === null || params === void 0 ? void 0 : params.chainId);
354
+ if (!(params !== null && params !== void 0 && params.connectorName)) {
355
+ const pickedConnector = await this.pickWalletForAccountLinking(chainId);
356
+ return this.linkAccountWithChosenConnector(pickedConnector, chainId);
357
+ }
358
+ return this.linkAccountWithChosenConnector(params.connectorName, chainId);
359
+ }
360
+ startAccountLinkingModalSession(params) {
361
+ if (!this.loginModal) throw noModal.WalletInitializationError.notReady("Login modal is not initialized");
362
+ this.loginModal.startAccountLinkingSession(params);
363
+ }
364
+ updateAccountLinkingModalSession(accountLinking) {
365
+ if (!this.loginModal) throw noModal.WalletInitializationError.notReady("Login modal is not initialized");
366
+ this.loginModal.updateAccountLinkingState(accountLinking);
367
+ }
368
+ resetAccountLinkingModalSession() {
369
+ if (!this.loginModal) throw noModal.WalletInitializationError.notReady("Login modal is not initialized");
370
+ this.loginModal.resetAccountLinkingSession();
371
+ }
372
+ formatAccountLinkingErrorMessage(error) {
373
+ if (error instanceof noModal.AccountLinkingError) {
374
+ const isUnlink = error.code >= 5406 && error.code <= 5408;
375
+ return isUnlink ? `[${error.code}] Account unlinking failed` : `[${error.code}] Account linking failed`;
376
+ }
377
+ return error === null || error === void 0 ? void 0 : error.message;
378
+ }
379
+ async prepareAccountLinkingConnector(connectorName, chainId) {
380
+ const {
381
+ projectConfig
382
+ } = await this.getProjectAndWalletConfig();
383
+ const connector = await super.createLinkingWalletConnector(connectorName, chainId, projectConfig);
384
+ if (connector.name !== noModal.WALLET_CONNECTORS.WALLET_CONNECT_V2) {
385
+ return connector;
386
+ }
387
+ if (!this.loginModal) throw noModal.WalletInitializationError.notReady("Login modal is not initialized");
388
+ this.clearAccountLinkingConnectorListeners();
389
+ this.removeAccountLinkingConnectorListeners = this.subscribeToAccountLinkingConnectorEvents(connector);
390
+ this.startAccountLinkingModalSession({
391
+ connectorName,
392
+ transportConnectorName: connector.name,
393
+ chainId,
394
+ intent: interfaces.ACCOUNT_LINKING_INTENT.LINK
395
+ });
396
+ this.loginModal.open();
397
+ return connector;
398
+ }
399
+ async prepareAccountSwitchConnector(connectorName, chainId, projectConfig) {
400
+ const finalProjectConfig = projectConfig !== null && projectConfig !== void 0 ? projectConfig : (await this.getProjectAndWalletConfig()).projectConfig;
401
+ const connector = await super.createSwitchingWalletConnector(connectorName, chainId, finalProjectConfig);
402
+ if (connector.name !== noModal.WALLET_CONNECTORS.WALLET_CONNECT_V2) {
403
+ return connector;
404
+ }
405
+ if (!this.loginModal) throw noModal.WalletInitializationError.notReady("Login modal is not initialized");
406
+ this.clearAccountLinkingConnectorListeners();
407
+ this.removeAccountLinkingConnectorListeners = this.subscribeToAccountLinkingConnectorEvents(connector);
408
+ this.startAccountLinkingModalSession({
409
+ connectorName,
410
+ transportConnectorName: connector.name,
411
+ chainId,
412
+ intent: interfaces.ACCOUNT_LINKING_INTENT.SWITCH
413
+ });
414
+ this.loginModal.open();
415
+ return connector;
416
+ }
275
417
  initUIConfig(projectConfig) {
276
418
  super.initUIConfig(projectConfig);
277
419
  this.options.uiConfig = deepmerge(noModal.cloneDeep(projectConfig.whitelabel || {}), this.options.uiConfig || {});
@@ -293,26 +435,26 @@ class Web3Auth extends noModal.Web3AuthNoModal {
293
435
  this.options.uiConfig.loginMethodsOrder = loginMethodsOrder;
294
436
  }
295
437
  getInitializationTrackData() {
296
- var _this$modalConfig, _this$modalConfig2, _this$modalConfig3, _this$options$uiConfi3, _this$options$uiConfi4, _this$options$uiConfi5, _this$options$uiConfi6, _this$options$uiConfi7, _this$options$uiConfi8, _this$options$uiConfi9, _this$options$uiConfi0, _this$options$uiConfi1, _this$options$uiConfi10, _this$options$uiConfi11, _this$options$uiConfi12, _this$options$uiConfi13, _this$options$uiConfi14;
438
+ var _this$modalConfig, _this$modalConfig2, _this$modalConfig3, _this$options$uiConfi, _this$options$uiConfi2, _this$options$uiConfi3, _this$options$uiConfi4, _this$options$uiConfi5, _this$options$uiConfi6, _this$options$uiConfi7, _this$options$uiConfi8, _this$options$uiConfi9, _this$options$uiConfi0, _this$options$uiConfi1, _this$options$uiConfi10, _this$options$uiConfi11, _this$options$uiConfi12;
297
439
  return _objectSpread(_objectSpread({}, super.getInitializationTrackData()), {}, {
298
440
  modal_hide_wallet_discovery: (_this$modalConfig = this.modalConfig) === null || _this$modalConfig === void 0 ? void 0 : _this$modalConfig.hideWalletDiscovery,
299
441
  modal_connectors: Object.keys(((_this$modalConfig2 = this.modalConfig) === null || _this$modalConfig2 === void 0 ? void 0 : _this$modalConfig2.connectors) || {}),
300
442
  modal_auth_connector_login_methods: Object.keys(((_this$modalConfig3 = this.modalConfig) === null || _this$modalConfig3 === void 0 || (_this$modalConfig3 = _this$modalConfig3.connectors) === null || _this$modalConfig3 === void 0 || (_this$modalConfig3 = _this$modalConfig3[noModal.WALLET_CONNECTORS.AUTH]) === null || _this$modalConfig3 === void 0 ? void 0 : _this$modalConfig3.loginMethods) || {}),
301
443
  // UI config
302
- ui_login_methods_order: (_this$options$uiConfi3 = this.options.uiConfig) === null || _this$options$uiConfi3 === void 0 ? void 0 : _this$options$uiConfi3.loginMethodsOrder,
303
- ui_modal_z_index: (_this$options$uiConfi4 = this.options.uiConfig) === null || _this$options$uiConfi4 === void 0 ? void 0 : _this$options$uiConfi4.modalZIndex,
304
- ui_display_errors_on_modal: (_this$options$uiConfi5 = this.options.uiConfig) === null || _this$options$uiConfi5 === void 0 ? void 0 : _this$options$uiConfi5.displayErrorsOnModal,
305
- ui_login_grid_col: (_this$options$uiConfi6 = this.options.uiConfig) === null || _this$options$uiConfi6 === void 0 ? void 0 : _this$options$uiConfi6.loginGridCol,
306
- ui_primary_button: (_this$options$uiConfi7 = this.options.uiConfig) === null || _this$options$uiConfi7 === void 0 ? void 0 : _this$options$uiConfi7.primaryButton,
307
- ui_modal_widget_type: (_this$options$uiConfi8 = this.options.uiConfig) === null || _this$options$uiConfi8 === void 0 ? void 0 : _this$options$uiConfi8.widgetType,
308
- ui_modal_target_id_used: Boolean((_this$options$uiConfi9 = this.options.uiConfig) === null || _this$options$uiConfi9 === void 0 ? void 0 : _this$options$uiConfi9.targetId),
309
- ui_modal_logo_alignment: (_this$options$uiConfi0 = this.options.uiConfig) === null || _this$options$uiConfi0 === void 0 ? void 0 : _this$options$uiConfi0.logoAlignment,
310
- ui_modal_border_radius_type: (_this$options$uiConfi1 = this.options.uiConfig) === null || _this$options$uiConfi1 === void 0 ? void 0 : _this$options$uiConfi1.borderRadiusType,
311
- ui_modal_button_radius_type: (_this$options$uiConfi10 = this.options.uiConfig) === null || _this$options$uiConfi10 === void 0 ? void 0 : _this$options$uiConfi10.buttonRadiusType,
312
- ui_modal_sign_in_methods: (_this$options$uiConfi11 = this.options.uiConfig) === null || _this$options$uiConfi11 === void 0 ? void 0 : _this$options$uiConfi11.signInMethods,
313
- ui_modal_add_previous_login_hint: (_this$options$uiConfi12 = this.options.uiConfig) === null || _this$options$uiConfi12 === void 0 ? void 0 : _this$options$uiConfi12.addPreviousLoginHint,
314
- ui_modal_display_installed_external_wallets: (_this$options$uiConfi13 = this.options.uiConfig) === null || _this$options$uiConfi13 === void 0 ? void 0 : _this$options$uiConfi13.displayInstalledExternalWallets,
315
- ui_modal_display_external_wallets_count: (_this$options$uiConfi14 = this.options.uiConfig) === null || _this$options$uiConfi14 === void 0 ? void 0 : _this$options$uiConfi14.displayExternalWalletsCount
444
+ ui_login_methods_order: (_this$options$uiConfi = this.options.uiConfig) === null || _this$options$uiConfi === void 0 ? void 0 : _this$options$uiConfi.loginMethodsOrder,
445
+ ui_modal_z_index: (_this$options$uiConfi2 = this.options.uiConfig) === null || _this$options$uiConfi2 === void 0 ? void 0 : _this$options$uiConfi2.modalZIndex,
446
+ ui_display_errors_on_modal: (_this$options$uiConfi3 = this.options.uiConfig) === null || _this$options$uiConfi3 === void 0 ? void 0 : _this$options$uiConfi3.displayErrorsOnModal,
447
+ ui_login_grid_col: (_this$options$uiConfi4 = this.options.uiConfig) === null || _this$options$uiConfi4 === void 0 ? void 0 : _this$options$uiConfi4.loginGridCol,
448
+ ui_primary_button: (_this$options$uiConfi5 = this.options.uiConfig) === null || _this$options$uiConfi5 === void 0 ? void 0 : _this$options$uiConfi5.primaryButton,
449
+ ui_modal_widget_type: (_this$options$uiConfi6 = this.options.uiConfig) === null || _this$options$uiConfi6 === void 0 ? void 0 : _this$options$uiConfi6.widgetType,
450
+ ui_modal_target_id_used: Boolean((_this$options$uiConfi7 = this.options.uiConfig) === null || _this$options$uiConfi7 === void 0 ? void 0 : _this$options$uiConfi7.targetId),
451
+ ui_modal_logo_alignment: (_this$options$uiConfi8 = this.options.uiConfig) === null || _this$options$uiConfi8 === void 0 ? void 0 : _this$options$uiConfi8.logoAlignment,
452
+ ui_modal_border_radius_type: (_this$options$uiConfi9 = this.options.uiConfig) === null || _this$options$uiConfi9 === void 0 ? void 0 : _this$options$uiConfi9.borderRadiusType,
453
+ ui_modal_button_radius_type: (_this$options$uiConfi0 = this.options.uiConfig) === null || _this$options$uiConfi0 === void 0 ? void 0 : _this$options$uiConfi0.buttonRadiusType,
454
+ ui_modal_sign_in_methods: (_this$options$uiConfi1 = this.options.uiConfig) === null || _this$options$uiConfi1 === void 0 ? void 0 : _this$options$uiConfi1.signInMethods,
455
+ ui_modal_add_previous_login_hint: (_this$options$uiConfi10 = this.options.uiConfig) === null || _this$options$uiConfi10 === void 0 ? void 0 : _this$options$uiConfi10.addPreviousLoginHint,
456
+ ui_modal_display_installed_external_wallets: (_this$options$uiConfi11 = this.options.uiConfig) === null || _this$options$uiConfi11 === void 0 ? void 0 : _this$options$uiConfi11.displayInstalledExternalWallets,
457
+ ui_modal_display_external_wallets_count: (_this$options$uiConfi12 = this.options.uiConfig) === null || _this$options$uiConfi12 === void 0 ? void 0 : _this$options$uiConfi12.displayExternalWalletsCount
316
458
  });
317
459
  }
318
460
  filterWalletRegistry(walletRegistry, projectConfig) {
@@ -566,12 +708,12 @@ class Web3Auth extends noModal.Web3AuthNoModal {
566
708
  // note: not adding cachedWallet to modal if it is external wallet.
567
709
  // adding it later if no in-app wallets are available.
568
710
  if (connector.type === noModal.CONNECTOR_CATEGORY.IN_APP) {
569
- var _this$modalConfig$con6, _this$options$uiConfi15, _this$options$uiConfi16, _this$options$uiConfi17;
711
+ var _this$modalConfig$con6, _this$options$uiConfi13, _this$options$uiConfi14, _this$options$uiConfi15;
570
712
  noModal.log.info("connectorInitResults", connectorName);
571
713
  const loginMethods = ((_this$modalConfig$con6 = this.modalConfig.connectors[connectorName]) === null || _this$modalConfig$con6 === void 0 ? void 0 : _this$modalConfig$con6.loginMethods) || {};
572
- this.loginModal.addSocialLogins(loginMethods, ((_this$options$uiConfi15 = this.options.uiConfig) === null || _this$options$uiConfi15 === void 0 ? void 0 : _this$options$uiConfi15.loginMethodsOrder) || config$1.AUTH_PROVIDERS, _objectSpread(_objectSpread({}, this.options.uiConfig), {}, {
573
- loginGridCol: ((_this$options$uiConfi16 = this.options.uiConfig) === null || _this$options$uiConfi16 === void 0 ? void 0 : _this$options$uiConfi16.loginGridCol) || 3,
574
- primaryButton: ((_this$options$uiConfi17 = this.options.uiConfig) === null || _this$options$uiConfi17 === void 0 ? void 0 : _this$options$uiConfi17.primaryButton) || "socialLogin"
714
+ this.loginModal.addSocialLogins(loginMethods, ((_this$options$uiConfi13 = this.options.uiConfig) === null || _this$options$uiConfi13 === void 0 ? void 0 : _this$options$uiConfi13.loginMethodsOrder) || config$1.AUTH_PROVIDERS, _objectSpread(_objectSpread({}, this.options.uiConfig), {}, {
715
+ loginGridCol: ((_this$options$uiConfi14 = this.options.uiConfig) === null || _this$options$uiConfi14 === void 0 ? void 0 : _this$options$uiConfi14.loginGridCol) || 3,
716
+ primaryButton: ((_this$options$uiConfi15 = this.options.uiConfig) === null || _this$options$uiConfi15 === void 0 ? void 0 : _this$options$uiConfi15.primaryButton) || "socialLogin"
575
717
  }));
576
718
  }
577
719
  } catch (error) {
@@ -584,6 +726,7 @@ class Web3Auth extends noModal.Web3AuthNoModal {
584
726
  const connectorChainNamespaceMap = {};
585
727
  // we do it like this because we don't want one slow connector to delay the load of the entire external wallet section.
586
728
  externalConnectors.forEach(async connector => {
729
+ var _this$connection;
587
730
  const connectorName = connector.name;
588
731
  noModal.log.debug("init external wallet", this.cachedConnector, connectorName, connector.status);
589
732
  // a wallet can support multiple chain namespaces e.g. Phantom has EvmInjected connector and WalletStandard connector.
@@ -595,7 +738,7 @@ class Web3Auth extends noModal.Web3AuthNoModal {
595
738
  }
596
739
  // initialize connectors
597
740
  // skip initializing cached connector here as it is already being initialized in initModal before.
598
- if (connector.status === noModal.CONNECTOR_STATUS.NOT_READY && this.cachedConnector !== connectorName) {
741
+ if (connector.status === noModal.CONNECTOR_STATUS.NOT_READY && this.cachedConnector !== connectorName && ((_this$connection = this.connection) === null || _this$connection === void 0 ? void 0 : _this$connection.connectorName) !== connectorName) {
599
742
  try {
600
743
  this.subscribeToConnectorEvents(connector);
601
744
  const initialChain = this.getInitialChainIdForConnector(connector);
@@ -624,6 +767,283 @@ class Web3Auth extends noModal.Web3AuthNoModal {
624
767
  }
625
768
  });
626
769
  }
770
+ async switchToWalletConnectV2Account(switchResult, connectorToSwitchTo, projectConfig) {
771
+ const authConnector = this.getMainAuthConnector();
772
+ try {
773
+ await this.runWalletConnectV2AccountAction({
774
+ connector: connectorToSwitchTo,
775
+ connectParams: {
776
+ chainId: switchResult.activeChainId
777
+ },
778
+ onConnected: async connector => {
779
+ await super.processSwitchAccountResult(authConnector, switchResult, {
780
+ walletConnector: connector,
781
+ projectConfig
782
+ });
783
+ await authConnector.trackSwitchAccountCompleted(switchResult.targetAccount);
784
+ return {
785
+ result: undefined,
786
+ retainConnector: true
787
+ };
788
+ },
789
+ intent: interfaces.ACCOUNT_LINKING_INTENT.SWITCH
790
+ });
791
+ } catch (error) {
792
+ await authConnector.trackSwitchAccountFailed(switchResult.targetAccount, error);
793
+ throw error;
794
+ }
795
+ }
796
+ /**
797
+ * Runs a link/switch action for WalletConnect v2, racing connector.connect()
798
+ * against a modal-close promise to cancel and clean up the WC session if the
799
+ * user closes the modal during QR scanning.
800
+ * For synchronous connectors use {@link runNonWalletConnectAccountAction}.
801
+ */
802
+ async runWalletConnectV2AccountAction(params) {
803
+ if (!this.loginModal) throw noModal.WalletInitializationError.notReady("Login modal is not initialized");
804
+ this.clearAccountLinkingResetOnCloseListener();
805
+ let retainConnector = false;
806
+ let connectCancelled = false;
807
+ let removeConnectPhaseVisibilityListener = () => {};
808
+ const closeDuringConnectPromise = new Promise((_resolve, reject) => {
809
+ const handleVisibility = visibility => {
810
+ if (!visibility) {
811
+ connectCancelled = true;
812
+ reject(noModal.WalletLoginError.popupClosed("User closed the modal"));
813
+ }
814
+ };
815
+ this.on(interfaces.LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, handleVisibility);
816
+ removeConnectPhaseVisibilityListener = () => {
817
+ this.removeListener(interfaces.LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, handleVisibility);
818
+ };
819
+ });
820
+ const connector = params.connector;
821
+ const connectPromise = connector.connect(params.connectParams);
822
+ void connectPromise.then(async connection => {
823
+ if (!connectCancelled || !connection || !connector.connected || retainConnector) return undefined;
824
+ try {
825
+ await connector.disconnect({
826
+ cleanup: true
827
+ });
828
+ } catch (error) {
829
+ noModal.log.debug("Failed to disconnect cancelled WalletConnect connector during cleanup", error);
830
+ }
831
+ return undefined;
832
+ }).catch(() => {});
833
+ try {
834
+ const connection = await Promise.race([connectPromise, closeDuringConnectPromise]);
835
+ if (!connection) {
836
+ throw noModal.AccountLinkingError.requestFailed("Failed to connect wallet.");
837
+ }
838
+ removeConnectPhaseVisibilityListener();
839
+ this.updateAccountLinkingModalSession({
840
+ status: interfaces.ACCOUNT_LINKING_STATUS.LINKING,
841
+ intent: params.intent,
842
+ walletConnectUri: "",
843
+ errorMessage: ""
844
+ });
845
+ const {
846
+ result,
847
+ retainConnector: shouldRetainConnector = false
848
+ } = await params.onConnected(connector, connection);
849
+ retainConnector = shouldRetainConnector;
850
+ this.resetAccountLinkingModalSession();
851
+ this.loginModal.endConnectingLoader({
852
+ success: true,
853
+ successMessage: "",
854
+ skipSuccessScreen: params.intent === interfaces.ACCOUNT_LINKING_INTENT.SWITCH
855
+ });
856
+ return result;
857
+ } catch (error) {
858
+ const isPopupClosed = error instanceof noModal.Web3AuthError && error.code === 5114;
859
+ if (isPopupClosed) {
860
+ this.resetAccountLinkingModalSession();
861
+ } else {
862
+ const fallbackMessage = params.intent === interfaces.ACCOUNT_LINKING_INTENT.SWITCH ? "Failed to switch wallet." : undefined;
863
+ const errorMessage = this.formatAccountLinkingErrorMessage(error) || fallbackMessage;
864
+ this.resetAccountLinkingModalSession();
865
+ this.loginModal.endConnectingLoader({
866
+ success: false,
867
+ errorMessage
868
+ });
869
+ }
870
+ this.installAccountLinkingResetOnCloseListener();
871
+ throw error;
872
+ } finally {
873
+ removeConnectPhaseVisibilityListener();
874
+ this.clearAccountLinkingConnectorListeners();
875
+ try {
876
+ if (!retainConnector && connector.connected) {
877
+ await connector.disconnect({
878
+ cleanup: true
879
+ });
880
+ }
881
+ } catch (error) {
882
+ noModal.log.debug("Failed to disconnect WalletConnect connector during cleanup", error);
883
+ }
884
+ }
885
+ }
886
+ async linkAccountWithChosenConnector(connectorName, chainId) {
887
+ const connectorToLink = await this.prepareAccountLinkingConnector(connectorName, chainId);
888
+ if (connectorToLink.name !== noModal.WALLET_CONNECTORS.WALLET_CONNECT_V2) {
889
+ return this.runNonWalletConnectAccountAction(connectorName, () => super.linkAccountWithConnector(connectorName, chainId, connectorToLink), {
890
+ connector: connectorToLink
891
+ });
892
+ }
893
+ return this.runWalletConnectV2AccountAction({
894
+ connector: connectorToLink,
895
+ connectParams: {
896
+ chainId,
897
+ isAccountLinking: true
898
+ },
899
+ onConnected: async connector => ({
900
+ result: await super.linkAccountWithConnector(connectorName, chainId, connector)
901
+ }),
902
+ intent: interfaces.ACCOUNT_LINKING_INTENT.LINK
903
+ });
904
+ }
905
+ pickWalletForAccountLinking(chainId) {
906
+ if (!this.loginModal) throw noModal.WalletInitializationError.notReady("Login modal is not initialized");
907
+ if (this.accountLinkingPickerResolver) {
908
+ throw noModal.AccountLinkingError.requestFailed("Another account linking picker is already in progress.");
909
+ }
910
+ this.loginModal.startAccountLinkingPicker({
911
+ chainId
912
+ });
913
+ return new Promise((resolve, reject) => {
914
+ const cleanup = () => {
915
+ this.accountLinkingPickerResolver = null;
916
+ if (this.removeAccountLinkingPickerCloseListener) {
917
+ this.removeAccountLinkingPickerCloseListener();
918
+ this.removeAccountLinkingPickerCloseListener = null;
919
+ }
920
+ this.loginModal.endAccountLinkingPicker();
921
+ };
922
+ const handleVisibility = visible => {
923
+ if (visible) return;
924
+ cleanup();
925
+ reject(noModal.WalletLoginError.popupClosed("User closed the modal"));
926
+ };
927
+ this.accountLinkingPickerResolver = connector => {
928
+ cleanup();
929
+ resolve(connector);
930
+ };
931
+ this.on(interfaces.LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, handleVisibility);
932
+ this.removeAccountLinkingPickerCloseListener = () => {
933
+ this.removeListener(interfaces.LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, handleVisibility);
934
+ };
935
+ });
936
+ }
937
+ /**
938
+ * Runs a link/switch action for synchronous connectors (injected wallets, already-connected).
939
+ * Shows the connecting loader, forwards AUTHORIZING events to the modal, and
940
+ * resolves/rejects the loader on completion.
941
+ * For WalletConnect v2 use {@link runWalletConnectV2AccountAction}.
942
+ */
943
+ async runNonWalletConnectAccountAction(connectorName, fn, options = {}) {
944
+ if (!this.loginModal) throw noModal.WalletInitializationError.notReady("Login modal is not initialized");
945
+ const displayName = noModal.CONNECTOR_NAMES[connectorName] || connectorName;
946
+ this.loginModal.startConnectingLoader({
947
+ connector: connectorName,
948
+ connectorName: displayName
949
+ });
950
+ // Forward the AUTHORIZING event from the linking wallet connector to the modal so we can
951
+ // swap the loader from "connecting" to "authorizing" while the user reviews the signature
952
+ // request inside their wallet.
953
+ const handleAuthorizing = () => {
954
+ var _this$loginModal2;
955
+ return (_this$loginModal2 = this.loginModal) === null || _this$loginModal2 === void 0 ? void 0 : _this$loginModal2.markLoaderAuthorizing();
956
+ };
957
+ if (options.connector) {
958
+ options.connector.on(noModal.CONNECTOR_EVENTS.AUTHORIZING, handleAuthorizing);
959
+ }
960
+ try {
961
+ const result = await fn();
962
+ this.resetAccountLinkingModalSession();
963
+ this.loginModal.endConnectingLoader({
964
+ success: true,
965
+ skipSuccessScreen: options.skipSuccessScreen
966
+ });
967
+ return result;
968
+ } catch (error) {
969
+ const message = this.formatAccountLinkingErrorMessage(error);
970
+ this.resetAccountLinkingModalSession();
971
+ this.loginModal.endConnectingLoader({
972
+ success: false,
973
+ errorMessage: message
974
+ });
975
+ throw error;
976
+ } finally {
977
+ if (options.connector) {
978
+ options.connector.removeListener(noModal.CONNECTOR_EVENTS.AUTHORIZING, handleAuthorizing);
979
+ }
980
+ }
981
+ }
982
+ subscribeToAccountLinkingConnectorEvents(connector) {
983
+ const handleConnecting = () => {
984
+ this.updateAccountLinkingModalSession({
985
+ status: interfaces.ACCOUNT_LINKING_STATUS.AWAITING_CONNECTION,
986
+ errorMessage: ""
987
+ });
988
+ };
989
+ const handleConnectorDataUpdated = connectorData => {
990
+ if (connectorData.connectorName !== noModal.WALLET_CONNECTORS.WALLET_CONNECT_V2) return;
991
+ const walletConnectData = connectorData.data;
992
+ if (!walletConnectData.uri) return;
993
+ this.updateAccountLinkingModalSession({
994
+ walletConnectUri: walletConnectData.uri,
995
+ status: interfaces.ACCOUNT_LINKING_STATUS.AWAITING_CONNECTION,
996
+ errorMessage: ""
997
+ });
998
+ };
999
+ const handleConnected = _data => {
1000
+ this.updateAccountLinkingModalSession({
1001
+ status: interfaces.ACCOUNT_LINKING_STATUS.WALLET_CONNECTED,
1002
+ walletConnectUri: "",
1003
+ errorMessage: ""
1004
+ });
1005
+ };
1006
+ const handleErrored = error => {
1007
+ this.updateAccountLinkingModalSession({
1008
+ status: interfaces.ACCOUNT_LINKING_STATUS.ERRORED,
1009
+ errorMessage: error.message || "Failed to connect wallet."
1010
+ });
1011
+ };
1012
+ connector.on(noModal.CONNECTOR_EVENTS.CONNECTING, handleConnecting);
1013
+ connector.on(noModal.CONNECTOR_EVENTS.CONNECTOR_DATA_UPDATED, handleConnectorDataUpdated);
1014
+ connector.on(noModal.CONNECTOR_EVENTS.CONNECTED, handleConnected);
1015
+ connector.on(noModal.CONNECTOR_EVENTS.ERRORED, handleErrored);
1016
+ return () => {
1017
+ connector.removeListener(noModal.CONNECTOR_EVENTS.CONNECTING, handleConnecting);
1018
+ connector.removeListener(noModal.CONNECTOR_EVENTS.CONNECTOR_DATA_UPDATED, handleConnectorDataUpdated);
1019
+ connector.removeListener(noModal.CONNECTOR_EVENTS.CONNECTED, handleConnected);
1020
+ connector.removeListener(noModal.CONNECTOR_EVENTS.ERRORED, handleErrored);
1021
+ };
1022
+ }
1023
+ clearAccountLinkingConnectorListeners() {
1024
+ if (this.removeAccountLinkingConnectorListeners) {
1025
+ this.removeAccountLinkingConnectorListeners();
1026
+ this.removeAccountLinkingConnectorListeners = null;
1027
+ }
1028
+ }
1029
+ installAccountLinkingResetOnCloseListener() {
1030
+ this.clearAccountLinkingResetOnCloseListener();
1031
+ const handleVisibility = visibility => {
1032
+ if (visibility) return;
1033
+ this.resetAccountLinkingModalSession();
1034
+ this.clearAccountLinkingResetOnCloseListener();
1035
+ };
1036
+ this.on(interfaces.LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, handleVisibility);
1037
+ this.removeAccountLinkingResetOnCloseListener = () => {
1038
+ this.removeListener(interfaces.LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, handleVisibility);
1039
+ };
1040
+ }
1041
+ clearAccountLinkingResetOnCloseListener() {
1042
+ if (this.removeAccountLinkingResetOnCloseListener) {
1043
+ this.removeAccountLinkingResetOnCloseListener();
1044
+ this.removeAccountLinkingResetOnCloseListener = null;
1045
+ }
1046
+ }
627
1047
  getCombinedConnectionId(authConnectionId, groupedAuthConnectionId) {
628
1048
  let id = authConnectionId;
629
1049
  if (groupedAuthConnectionId) {