@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.
- package/dist/lib.cjs/packages/modal/src/account-linking/index.js +12 -0
- package/dist/lib.cjs/packages/modal/src/account-linking/react.js +22 -0
- package/dist/lib.cjs/packages/modal/src/account-linking/vue.js +22 -0
- package/dist/lib.cjs/packages/modal/src/config.js +1 -1
- package/dist/lib.cjs/packages/modal/src/modalManager.js +446 -26
- package/dist/lib.cjs/packages/modal/src/react/index.js +7 -3
- package/dist/lib.cjs/packages/modal/src/react/wagmi/provider.js +27 -12
- package/dist/lib.cjs/packages/modal/src/ui/components/BottomSheet/BottomSheet.js +13 -13
- package/dist/lib.cjs/packages/modal/src/ui/components/Button/ButtonSocial/ButtonSocial.js +4 -4
- package/dist/lib.cjs/packages/modal/src/ui/components/Button/ButtonWallet/ButtonWallet.js +10 -10
- package/dist/lib.cjs/packages/modal/src/ui/components/Footer/Footer.js +7 -7
- package/dist/lib.cjs/packages/modal/src/ui/components/Image/Image.js +4 -4
- package/dist/lib.cjs/packages/modal/src/ui/components/Loader/Loader.js +28 -28
- package/dist/lib.cjs/packages/modal/src/ui/components/LoginHint/LoginHint.js +3 -3
- package/dist/lib.cjs/packages/modal/src/ui/components/Modal/Modal.js +19 -19
- package/dist/lib.cjs/packages/modal/src/ui/components/Otp/Otp.js +10 -10
- package/dist/lib.cjs/packages/modal/src/ui/components/PulseLoader/PulseLoader.js +4 -4
- package/dist/lib.cjs/packages/modal/src/ui/components/SocialLoginList/SocialLoginList.js +21 -21
- package/dist/lib.cjs/packages/modal/src/ui/components/SpinnerLoader/SpinnerLoader.js +1 -1
- package/dist/lib.cjs/packages/modal/src/ui/components/Toast/Toast.js +11 -11
- package/dist/lib.cjs/packages/modal/src/ui/containers/AccountLinking/AccountLinking.js +109 -0
- package/dist/lib.cjs/packages/modal/src/ui/containers/ConnectWallet/ConnectWallet.js +14 -3
- package/dist/lib.cjs/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletChainFilter/ConnectWalletChainFilter.js +7 -7
- package/dist/lib.cjs/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletChainNamespaceSelect/ConnectWalletChainNamespaceSelect.js +9 -9
- package/dist/lib.cjs/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletHeader/ConnectWalletHeader.js +9 -8
- package/dist/lib.cjs/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletList/ConnectWalletList.js +19 -19
- package/dist/lib.cjs/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletQrCode/ConnectWalletQrCode.js +8 -8
- package/dist/lib.cjs/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletSearch/ConnectWalletSearch.js +5 -5
- package/dist/lib.cjs/packages/modal/src/ui/containers/Embed/Embed.js +11 -11
- package/dist/lib.cjs/packages/modal/src/ui/containers/Login/Login.js +45 -41
- package/dist/lib.cjs/packages/modal/src/ui/containers/Login/LoginOtp/LoginOtp.js +11 -11
- package/dist/lib.cjs/packages/modal/src/ui/containers/Login/LoginPasswordLess/LoginPasswordLess.js +13 -13
- package/dist/lib.cjs/packages/modal/src/ui/containers/Root/Root.js +24 -9
- package/dist/lib.cjs/packages/modal/src/ui/containers/Root/RootBodySheets/RootBodySheets.js +16 -16
- package/dist/lib.cjs/packages/modal/src/ui/containers/Widget/Widget.js +6 -2
- package/dist/lib.cjs/packages/modal/src/ui/context/ModalStateContext.js +1 -0
- package/dist/lib.cjs/packages/modal/src/ui/css/index.css.js +1 -1
- package/dist/lib.cjs/packages/modal/src/ui/i18n/dutch.json.js +14 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/english.json.js +14 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/french.json.js +14 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/german.json.js +14 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/japanese.json.js +26 -12
- package/dist/lib.cjs/packages/modal/src/ui/i18n/korean.json.js +14 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/mandarin.json.js +14 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/portuguese.json.js +14 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/spanish.json.js +14 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/turkish.json.js +14 -0
- package/dist/lib.cjs/packages/modal/src/ui/interfaces.js +26 -0
- package/dist/lib.cjs/packages/modal/src/ui/loginModal.js +113 -4
- package/dist/lib.cjs/packages/modal/src/vue/index.js +7 -3
- package/dist/lib.cjs/packages/modal/src/vue/wagmi/provider.js +27 -14
- package/dist/lib.cjs/types/account-linking/index.d.ts +1 -0
- package/dist/lib.cjs/types/account-linking/react.d.ts +2 -0
- package/dist/lib.cjs/types/account-linking/vue.d.ts +2 -0
- package/dist/lib.cjs/types/modalManager.d.ts +40 -2
- package/dist/lib.cjs/types/react/hooks/index.d.ts +1 -0
- package/dist/lib.cjs/types/react/hooks/useWallets.d.ts +2 -0
- package/dist/lib.cjs/types/ui/containers/AccountLinking/AccountLinking.d.ts +6 -0
- package/dist/lib.cjs/types/ui/containers/AccountLinking/index.d.ts +1 -0
- package/dist/lib.cjs/types/ui/containers/ConnectWallet/ConnectWalletHeader/ConnectWalletHeader.type.d.ts +1 -0
- package/dist/lib.cjs/types/ui/containers/Root/Root.d.ts +1 -1
- package/dist/lib.cjs/types/ui/interfaces.d.ts +43 -8
- package/dist/lib.cjs/types/ui/loginModal.d.ts +27 -2
- package/dist/lib.cjs/types/ui/utils.d.ts +1 -1
- package/dist/lib.cjs/types/vue/composables/index.d.ts +1 -0
- package/dist/lib.cjs/types/vue/composables/useWallets.d.ts +2 -0
- package/dist/lib.esm/packages/modal/src/account-linking/index.js +1 -0
- package/dist/lib.esm/packages/modal/src/account-linking/react.js +1 -0
- package/dist/lib.esm/packages/modal/src/account-linking/vue.js +1 -0
- package/dist/lib.esm/packages/modal/src/config.js +1 -1
- package/dist/lib.esm/packages/modal/src/modalManager.js +451 -28
- package/dist/lib.esm/packages/modal/src/react/index.js +1 -1
- package/dist/lib.esm/packages/modal/src/react/wagmi/provider.js +28 -13
- package/dist/lib.esm/packages/modal/src/ui/components/BottomSheet/BottomSheet.js +13 -13
- package/dist/lib.esm/packages/modal/src/ui/components/Button/ButtonSocial/ButtonSocial.js +4 -4
- package/dist/lib.esm/packages/modal/src/ui/components/Button/ButtonWallet/ButtonWallet.js +10 -10
- package/dist/lib.esm/packages/modal/src/ui/components/Footer/Footer.js +7 -7
- package/dist/lib.esm/packages/modal/src/ui/components/Image/Image.js +4 -4
- package/dist/lib.esm/packages/modal/src/ui/components/Loader/Loader.js +28 -28
- package/dist/lib.esm/packages/modal/src/ui/components/LoginHint/LoginHint.js +3 -3
- package/dist/lib.esm/packages/modal/src/ui/components/Modal/Modal.js +19 -19
- package/dist/lib.esm/packages/modal/src/ui/components/Otp/Otp.js +10 -10
- package/dist/lib.esm/packages/modal/src/ui/components/PulseLoader/PulseLoader.js +4 -4
- package/dist/lib.esm/packages/modal/src/ui/components/SocialLoginList/SocialLoginList.js +21 -21
- package/dist/lib.esm/packages/modal/src/ui/components/SpinnerLoader/SpinnerLoader.js +1 -1
- package/dist/lib.esm/packages/modal/src/ui/components/Toast/Toast.js +11 -11
- package/dist/lib.esm/packages/modal/src/ui/containers/AccountLinking/AccountLinking.js +107 -0
- package/dist/lib.esm/packages/modal/src/ui/containers/ConnectWallet/ConnectWallet.js +14 -3
- package/dist/lib.esm/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletChainFilter/ConnectWalletChainFilter.js +7 -7
- package/dist/lib.esm/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletChainNamespaceSelect/ConnectWalletChainNamespaceSelect.js +9 -9
- package/dist/lib.esm/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletHeader/ConnectWalletHeader.js +9 -8
- package/dist/lib.esm/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletList/ConnectWalletList.js +19 -19
- package/dist/lib.esm/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletQrCode/ConnectWalletQrCode.js +8 -8
- package/dist/lib.esm/packages/modal/src/ui/containers/ConnectWallet/ConnectWalletSearch/ConnectWalletSearch.js +5 -5
- package/dist/lib.esm/packages/modal/src/ui/containers/Embed/Embed.js +11 -11
- package/dist/lib.esm/packages/modal/src/ui/containers/Login/Login.js +46 -42
- package/dist/lib.esm/packages/modal/src/ui/containers/Login/LoginOtp/LoginOtp.js +11 -11
- package/dist/lib.esm/packages/modal/src/ui/containers/Login/LoginPasswordLess/LoginPasswordLess.js +13 -13
- package/dist/lib.esm/packages/modal/src/ui/containers/Root/Root.js +24 -9
- package/dist/lib.esm/packages/modal/src/ui/containers/Root/RootBodySheets/RootBodySheets.js +16 -16
- package/dist/lib.esm/packages/modal/src/ui/containers/Widget/Widget.js +6 -2
- package/dist/lib.esm/packages/modal/src/ui/context/ModalStateContext.js +2 -1
- package/dist/lib.esm/packages/modal/src/ui/css/index.css.js +1 -1
- package/dist/lib.esm/packages/modal/src/ui/i18n/dutch.json.js +14 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/english.json.js +14 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/french.json.js +14 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/german.json.js +14 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/japanese.json.js +26 -12
- package/dist/lib.esm/packages/modal/src/ui/i18n/korean.json.js +14 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/mandarin.json.js +14 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/portuguese.json.js +14 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/spanish.json.js +14 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/turkish.json.js +14 -0
- package/dist/lib.esm/packages/modal/src/ui/interfaces.js +24 -1
- package/dist/lib.esm/packages/modal/src/ui/loginModal.js +115 -6
- package/dist/lib.esm/packages/modal/src/vue/index.js +1 -1
- package/dist/lib.esm/packages/modal/src/vue/wagmi/provider.js +28 -15
- package/package.json +42 -19
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
3
|
import { serializeError } from '@web3auth/auth';
|
|
4
|
-
import { Web3AuthNoModal, LOGIN_MODE, cloneDeep, WALLET_CONNECTORS, log, CONNECTOR_STATUS, CONNECTED_STATUSES, CONNECTOR_INITIAL_AUTHENTICATION_MODE, sdkVersion, ANALYTICS_SDK_TYPE, withAbort, CONNECTOR_EVENTS, ANALYTICS_EVENTS, getErrorAnalyticsProperties, WalletInitializationError, fetchProjectConfig, fetchWalletRegistry, WALLET_REGISTRY_URL, CONNECTOR_CATEGORY, CONNECTOR_NAMES, CONNECTOR_NAMESPACES } from '@web3auth/no-modal';
|
|
4
|
+
import { Web3AuthNoModal, LOGIN_MODE, cloneDeep, WALLET_CONNECTORS, log, CONNECTOR_STATUS, CONNECTED_STATUSES, CONNECTOR_INITIAL_AUTHENTICATION_MODE, sdkVersion, ANALYTICS_SDK_TYPE, withAbort, CONNECTOR_EVENTS, ANALYTICS_EVENTS, getErrorAnalyticsProperties, WalletInitializationError, AccountLinkingError, fetchProjectConfig, fetchWalletRegistry, WALLET_REGISTRY_URL, CONNECTOR_CATEGORY, CONNECTOR_NAMES, CONNECTOR_NAMESPACES, Web3AuthError, WalletLoginError } from '@web3auth/no-modal';
|
|
5
5
|
import deepmerge from 'deepmerge';
|
|
6
6
|
import { defaultConnectorsModalConfig } from './config.js';
|
|
7
7
|
import { AUTH_PROVIDERS_NAMES, AUTH_PROVIDERS, capitalizeFirstLetter } from './ui/config.js';
|
|
8
|
-
import { LOGIN_MODAL_EVENTS } from './ui/interfaces.js';
|
|
8
|
+
import { LOGIN_MODAL_EVENTS, ACCOUNT_LINKING_INTENT, ACCOUNT_LINKING_STATUS } from './ui/interfaces.js';
|
|
9
9
|
import { LoginModal } from './ui/loginModal.js';
|
|
10
10
|
import { getUserLanguage } from './ui/utils.js';
|
|
11
11
|
|
|
12
12
|
class Web3Auth extends Web3AuthNoModal {
|
|
13
13
|
constructor(options, initialState) {
|
|
14
|
-
var _this$options$uiConfi;
|
|
15
14
|
super(options, initialState);
|
|
16
15
|
_defineProperty(this, "loginModal", void 0);
|
|
17
16
|
_defineProperty(this, "loginMode", LOGIN_MODE.MODAL);
|
|
18
17
|
_defineProperty(this, "options", void 0);
|
|
19
18
|
_defineProperty(this, "modalConfig", cloneDeep(defaultConnectorsModalConfig));
|
|
19
|
+
_defineProperty(this, "removeAccountLinkingConnectorListeners", null);
|
|
20
|
+
_defineProperty(this, "removeAccountLinkingResetOnCloseListener", null);
|
|
21
|
+
_defineProperty(this, "accountLinkingPickerResolver", null);
|
|
22
|
+
_defineProperty(this, "removeAccountLinkingPickerCloseListener", null);
|
|
20
23
|
_defineProperty(this, "onInitExternalWallets", async params => {
|
|
21
24
|
if (params.externalWalletsInitialized) return;
|
|
22
25
|
// initialize WC connector only as other external wallets are initialized in initModal
|
|
@@ -33,6 +36,13 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
33
36
|
}
|
|
34
37
|
});
|
|
35
38
|
_defineProperty(this, "onExternalWalletLogin", async params => {
|
|
39
|
+
// If the modal is in account-linking picker mode, hand off the selected connector
|
|
40
|
+
// to the linking flow instead of running the regular login `connectTo`.
|
|
41
|
+
if (this.accountLinkingPickerResolver) {
|
|
42
|
+
const resolver = this.accountLinkingPickerResolver;
|
|
43
|
+
resolver(params.connector);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
36
46
|
try {
|
|
37
47
|
var _params$loginParams;
|
|
38
48
|
const connector = this.getConnector(params.connector, (_params$loginParams = params.loginParams) === null || _params$loginParams === void 0 ? void 0 : _params$loginParams.chainNamespace);
|
|
@@ -51,8 +61,12 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
51
61
|
}
|
|
52
62
|
});
|
|
53
63
|
_defineProperty(this, "onModalVisibility", async visibility => {
|
|
64
|
+
var _this$loginModal;
|
|
54
65
|
log.debug("is login modal visible", visibility);
|
|
55
66
|
this.emit(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, visibility);
|
|
67
|
+
if ((_this$loginModal = this.loginModal) !== null && _this$loginModal !== void 0 && _this$loginModal.hasActiveAccountLinkingSession()) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
56
70
|
|
|
57
71
|
// handle WC session refresh
|
|
58
72
|
const wcConnector = this.getConnector(WALLET_CONNECTORS.WALLET_CONNECT_V2);
|
|
@@ -112,7 +126,8 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
112
126
|
}
|
|
113
127
|
if (!this.options.uiConfig) this.options.uiConfig = {};
|
|
114
128
|
if (this.options.modalConfig) this.modalConfig = this.options.modalConfig;
|
|
115
|
-
|
|
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
|
log.info("modalConfig", this.modalConfig);
|
|
117
132
|
}
|
|
118
133
|
async init(options) {
|
|
@@ -133,7 +148,7 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
133
148
|
});
|
|
134
149
|
let trackData = {};
|
|
135
150
|
try {
|
|
136
|
-
var
|
|
151
|
+
var _authConnector$authIn, _this$coreOptions$uiC;
|
|
137
152
|
const {
|
|
138
153
|
signal
|
|
139
154
|
} = options || {};
|
|
@@ -179,7 +194,7 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
179
194
|
onAcceptConsent: this.onAcceptConsent,
|
|
180
195
|
onDeclineConsent: this.onDeclineConsent
|
|
181
196
|
});
|
|
182
|
-
this.consentRequired =
|
|
197
|
+
this.consentRequired = this.loginModal.consentRequired;
|
|
183
198
|
await withAbort(() => this.loginModal.initModal(), signal);
|
|
184
199
|
|
|
185
200
|
// setup common JRPC provider
|
|
@@ -234,9 +249,11 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
234
249
|
async connect() {
|
|
235
250
|
if (!this.loginModal) throw WalletInitializationError.notReady("Login modal is not initialized");
|
|
236
251
|
// if already connected return connection
|
|
237
|
-
if (
|
|
252
|
+
if (CONNECTED_STATUSES.includes(this.status) && this.connection) return this.connection;
|
|
238
253
|
this.loginModal.open();
|
|
239
254
|
return new Promise((resolve, reject) => {
|
|
255
|
+
// track connection started event
|
|
256
|
+
const startTime = Date.now();
|
|
240
257
|
// remove all listeners when promise is resolved or rejected.
|
|
241
258
|
// this is to prevent memory leaks if user clicks connect button multiple times.
|
|
242
259
|
const handleCompletion = () => {
|
|
@@ -249,6 +266,22 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
249
266
|
}
|
|
250
267
|
return resolve(this.connection);
|
|
251
268
|
};
|
|
269
|
+
const handleConsentAccepted = async () => {
|
|
270
|
+
try {
|
|
271
|
+
var _this$primaryConnecto;
|
|
272
|
+
// track connection completed event
|
|
273
|
+
const userInfo = await this.getUserInfo();
|
|
274
|
+
// TODO: correct event data
|
|
275
|
+
this.analytics.track(ANALYTICS_EVENTS.CONNECTION_COMPLETED, {
|
|
276
|
+
connector: (_this$primaryConnecto = this.primaryConnector) === null || _this$primaryConnecto === void 0 ? void 0 : _this$primaryConnecto.name,
|
|
277
|
+
is_mfa_enabled: userInfo === null || userInfo === void 0 ? void 0 : userInfo.isMfaEnabled,
|
|
278
|
+
duration: Date.now() - startTime
|
|
279
|
+
});
|
|
280
|
+
} catch (error) {
|
|
281
|
+
log.error("Failed to track connection completed event after consent acceptance", error);
|
|
282
|
+
}
|
|
283
|
+
handleCompletion();
|
|
284
|
+
};
|
|
252
285
|
const handleError = err => {
|
|
253
286
|
this.removeListener(CONNECTOR_EVENTS.CONNECTED, handleCompletion);
|
|
254
287
|
this.removeListener(CONNECTOR_EVENTS.AUTHORIZED, handleCompletion);
|
|
@@ -265,7 +298,7 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
265
298
|
}
|
|
266
299
|
};
|
|
267
300
|
if (this.consentRequired) {
|
|
268
|
-
this.once(CONNECTOR_EVENTS.CONSENT_ACCEPTED,
|
|
301
|
+
this.once(CONNECTOR_EVENTS.CONSENT_ACCEPTED, handleConsentAccepted);
|
|
269
302
|
}
|
|
270
303
|
if (this.coreOptions.initialAuthenticationMode === CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN) {
|
|
271
304
|
this.once(CONNECTOR_EVENTS.AUTHORIZED, handleCompletion);
|
|
@@ -279,6 +312,115 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
279
312
|
async acceptConsent() {
|
|
280
313
|
await super.completeConsentAcceptance();
|
|
281
314
|
}
|
|
315
|
+
async switchAccount(account) {
|
|
316
|
+
const authConnector = this.getMainAuthConnector();
|
|
317
|
+
const switchResult = await authConnector.switchAccount(account, {
|
|
318
|
+
activeAccount: this.activeAccount,
|
|
319
|
+
currentChainId: this.currentChainId
|
|
320
|
+
});
|
|
321
|
+
if (!switchResult) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
try {
|
|
325
|
+
var _await$this$getProjec;
|
|
326
|
+
const existingConnector = switchResult.kind === "external" ? this.getConnectedWalletConnector(switchResult.targetAccount) : null;
|
|
327
|
+
// check if the existing connector is connected and usable, then we can switch to it without re-connecting again
|
|
328
|
+
const isExistingConnectorConnected = Boolean(existingConnector && this.hasUsableConnectedSwitchConnector(existingConnector));
|
|
329
|
+
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;
|
|
330
|
+
if (switchResult.kind !== "external" || isExistingConnectorConnected) {
|
|
331
|
+
await this.runNonWalletConnectAccountAction(switchResult.targetAccount.connector, () => super.processSwitchAccountResult(authConnector, switchResult, {
|
|
332
|
+
walletConnector: isExistingConnectorConnected && existingConnector ? existingConnector : undefined,
|
|
333
|
+
projectConfig
|
|
334
|
+
}), {
|
|
335
|
+
skipSuccessScreen: true
|
|
336
|
+
});
|
|
337
|
+
await authConnector.trackSwitchAccountCompleted(switchResult.targetAccount);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const connectorToSwitchTo = await this.prepareAccountSwitchConnector(switchResult.targetAccount.connector, switchResult.activeChainId, projectConfig);
|
|
341
|
+
if (connectorToSwitchTo.name !== WALLET_CONNECTORS.WALLET_CONNECT_V2) {
|
|
342
|
+
await this.runNonWalletConnectAccountAction(switchResult.targetAccount.connector, () => super.processSwitchAccountResult(authConnector, switchResult, {
|
|
343
|
+
walletConnector: connectorToSwitchTo,
|
|
344
|
+
projectConfig
|
|
345
|
+
}), {
|
|
346
|
+
skipSuccessScreen: true
|
|
347
|
+
});
|
|
348
|
+
await authConnector.trackSwitchAccountCompleted(switchResult.targetAccount);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
await this.switchToWalletConnectV2Account(switchResult, connectorToSwitchTo, projectConfig);
|
|
352
|
+
} catch (error) {
|
|
353
|
+
await authConnector.trackSwitchAccountFailed(switchResult.targetAccount, error);
|
|
354
|
+
throw error;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
async linkAccount(params) {
|
|
358
|
+
// Pre-flight: ensure user is connected via AUTH so we fail fast before opening the modal.
|
|
359
|
+
this.getMainAuthConnector();
|
|
360
|
+
const chainId = this.resolveLinkAccountChainId(params === null || params === void 0 ? void 0 : params.chainId);
|
|
361
|
+
if (!(params !== null && params !== void 0 && params.connectorName)) {
|
|
362
|
+
const pickedConnector = await this.pickWalletForAccountLinking(chainId);
|
|
363
|
+
return this.linkAccountWithChosenConnector(pickedConnector, chainId);
|
|
364
|
+
}
|
|
365
|
+
return this.linkAccountWithChosenConnector(params.connectorName, chainId);
|
|
366
|
+
}
|
|
367
|
+
startAccountLinkingModalSession(params) {
|
|
368
|
+
if (!this.loginModal) throw WalletInitializationError.notReady("Login modal is not initialized");
|
|
369
|
+
this.loginModal.startAccountLinkingSession(params);
|
|
370
|
+
}
|
|
371
|
+
updateAccountLinkingModalSession(accountLinking) {
|
|
372
|
+
if (!this.loginModal) throw WalletInitializationError.notReady("Login modal is not initialized");
|
|
373
|
+
this.loginModal.updateAccountLinkingState(accountLinking);
|
|
374
|
+
}
|
|
375
|
+
resetAccountLinkingModalSession() {
|
|
376
|
+
if (!this.loginModal) throw WalletInitializationError.notReady("Login modal is not initialized");
|
|
377
|
+
this.loginModal.resetAccountLinkingSession();
|
|
378
|
+
}
|
|
379
|
+
formatAccountLinkingErrorMessage(error) {
|
|
380
|
+
if (error instanceof AccountLinkingError) {
|
|
381
|
+
const isUnlink = error.code >= 5406 && error.code <= 5408;
|
|
382
|
+
return isUnlink ? `[${error.code}] Account unlinking failed` : `[${error.code}] Account linking failed`;
|
|
383
|
+
}
|
|
384
|
+
return error === null || error === void 0 ? void 0 : error.message;
|
|
385
|
+
}
|
|
386
|
+
async prepareAccountLinkingConnector(connectorName, chainId) {
|
|
387
|
+
const {
|
|
388
|
+
projectConfig
|
|
389
|
+
} = await this.getProjectAndWalletConfig();
|
|
390
|
+
const connector = await super.createLinkingWalletConnector(connectorName, chainId, projectConfig);
|
|
391
|
+
if (connector.name !== WALLET_CONNECTORS.WALLET_CONNECT_V2) {
|
|
392
|
+
return connector;
|
|
393
|
+
}
|
|
394
|
+
if (!this.loginModal) throw WalletInitializationError.notReady("Login modal is not initialized");
|
|
395
|
+
this.clearAccountLinkingConnectorListeners();
|
|
396
|
+
this.removeAccountLinkingConnectorListeners = this.subscribeToAccountLinkingConnectorEvents(connector);
|
|
397
|
+
this.startAccountLinkingModalSession({
|
|
398
|
+
connectorName,
|
|
399
|
+
transportConnectorName: connector.name,
|
|
400
|
+
chainId,
|
|
401
|
+
intent: ACCOUNT_LINKING_INTENT.LINK
|
|
402
|
+
});
|
|
403
|
+
this.loginModal.open();
|
|
404
|
+
return connector;
|
|
405
|
+
}
|
|
406
|
+
async prepareAccountSwitchConnector(connectorName, chainId, projectConfig) {
|
|
407
|
+
const finalProjectConfig = projectConfig !== null && projectConfig !== void 0 ? projectConfig : (await this.getProjectAndWalletConfig()).projectConfig;
|
|
408
|
+
const connector = await super.createSwitchingWalletConnector(connectorName, chainId, finalProjectConfig);
|
|
409
|
+
if (connector.name !== WALLET_CONNECTORS.WALLET_CONNECT_V2) {
|
|
410
|
+
return connector;
|
|
411
|
+
}
|
|
412
|
+
if (!this.loginModal) throw WalletInitializationError.notReady("Login modal is not initialized");
|
|
413
|
+
this.clearAccountLinkingConnectorListeners();
|
|
414
|
+
this.removeAccountLinkingConnectorListeners = this.subscribeToAccountLinkingConnectorEvents(connector);
|
|
415
|
+
this.startAccountLinkingModalSession({
|
|
416
|
+
connectorName,
|
|
417
|
+
transportConnectorName: connector.name,
|
|
418
|
+
chainId,
|
|
419
|
+
intent: ACCOUNT_LINKING_INTENT.SWITCH
|
|
420
|
+
});
|
|
421
|
+
this.loginModal.open();
|
|
422
|
+
return connector;
|
|
423
|
+
}
|
|
282
424
|
initUIConfig(projectConfig) {
|
|
283
425
|
super.initUIConfig(projectConfig);
|
|
284
426
|
this.options.uiConfig = deepmerge(cloneDeep(projectConfig.whitelabel || {}), this.options.uiConfig || {});
|
|
@@ -301,26 +443,26 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
301
443
|
this.options.uiConfig.loginMethodsOrder = loginMethodsOrder;
|
|
302
444
|
}
|
|
303
445
|
getInitializationTrackData() {
|
|
304
|
-
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
|
|
446
|
+
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;
|
|
305
447
|
return _objectSpread(_objectSpread({}, super.getInitializationTrackData()), {}, {
|
|
306
448
|
modal_hide_wallet_discovery: (_this$modalConfig = this.modalConfig) === null || _this$modalConfig === void 0 ? void 0 : _this$modalConfig.hideWalletDiscovery,
|
|
307
449
|
modal_connectors: Object.keys(((_this$modalConfig2 = this.modalConfig) === null || _this$modalConfig2 === void 0 ? void 0 : _this$modalConfig2.connectors) || {}),
|
|
308
450
|
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[WALLET_CONNECTORS.AUTH]) === null || _this$modalConfig3 === void 0 ? void 0 : _this$modalConfig3.loginMethods) || {}),
|
|
309
451
|
// UI config
|
|
310
|
-
ui_login_methods_order: (_this$options$
|
|
311
|
-
ui_modal_z_index: (_this$options$
|
|
312
|
-
ui_display_errors_on_modal: (_this$options$
|
|
313
|
-
ui_login_grid_col: (_this$options$
|
|
314
|
-
ui_primary_button: (_this$options$
|
|
315
|
-
ui_modal_widget_type: (_this$options$
|
|
316
|
-
ui_modal_target_id_used: Boolean((_this$options$
|
|
317
|
-
ui_modal_logo_alignment: (_this$options$
|
|
318
|
-
ui_modal_border_radius_type: (_this$options$
|
|
319
|
-
ui_modal_button_radius_type: (_this$options$
|
|
320
|
-
ui_modal_sign_in_methods: (_this$options$
|
|
321
|
-
ui_modal_add_previous_login_hint: (_this$options$
|
|
322
|
-
ui_modal_display_installed_external_wallets: (_this$options$
|
|
323
|
-
ui_modal_display_external_wallets_count: (_this$options$
|
|
452
|
+
ui_login_methods_order: (_this$options$uiConfi = this.options.uiConfig) === null || _this$options$uiConfi === void 0 ? void 0 : _this$options$uiConfi.loginMethodsOrder,
|
|
453
|
+
ui_modal_z_index: (_this$options$uiConfi2 = this.options.uiConfig) === null || _this$options$uiConfi2 === void 0 ? void 0 : _this$options$uiConfi2.modalZIndex,
|
|
454
|
+
ui_display_errors_on_modal: (_this$options$uiConfi3 = this.options.uiConfig) === null || _this$options$uiConfi3 === void 0 ? void 0 : _this$options$uiConfi3.displayErrorsOnModal,
|
|
455
|
+
ui_login_grid_col: (_this$options$uiConfi4 = this.options.uiConfig) === null || _this$options$uiConfi4 === void 0 ? void 0 : _this$options$uiConfi4.loginGridCol,
|
|
456
|
+
ui_primary_button: (_this$options$uiConfi5 = this.options.uiConfig) === null || _this$options$uiConfi5 === void 0 ? void 0 : _this$options$uiConfi5.primaryButton,
|
|
457
|
+
ui_modal_widget_type: (_this$options$uiConfi6 = this.options.uiConfig) === null || _this$options$uiConfi6 === void 0 ? void 0 : _this$options$uiConfi6.widgetType,
|
|
458
|
+
ui_modal_target_id_used: Boolean((_this$options$uiConfi7 = this.options.uiConfig) === null || _this$options$uiConfi7 === void 0 ? void 0 : _this$options$uiConfi7.targetId),
|
|
459
|
+
ui_modal_logo_alignment: (_this$options$uiConfi8 = this.options.uiConfig) === null || _this$options$uiConfi8 === void 0 ? void 0 : _this$options$uiConfi8.logoAlignment,
|
|
460
|
+
ui_modal_border_radius_type: (_this$options$uiConfi9 = this.options.uiConfig) === null || _this$options$uiConfi9 === void 0 ? void 0 : _this$options$uiConfi9.borderRadiusType,
|
|
461
|
+
ui_modal_button_radius_type: (_this$options$uiConfi0 = this.options.uiConfig) === null || _this$options$uiConfi0 === void 0 ? void 0 : _this$options$uiConfi0.buttonRadiusType,
|
|
462
|
+
ui_modal_sign_in_methods: (_this$options$uiConfi1 = this.options.uiConfig) === null || _this$options$uiConfi1 === void 0 ? void 0 : _this$options$uiConfi1.signInMethods,
|
|
463
|
+
ui_modal_add_previous_login_hint: (_this$options$uiConfi10 = this.options.uiConfig) === null || _this$options$uiConfi10 === void 0 ? void 0 : _this$options$uiConfi10.addPreviousLoginHint,
|
|
464
|
+
ui_modal_display_installed_external_wallets: (_this$options$uiConfi11 = this.options.uiConfig) === null || _this$options$uiConfi11 === void 0 ? void 0 : _this$options$uiConfi11.displayInstalledExternalWallets,
|
|
465
|
+
ui_modal_display_external_wallets_count: (_this$options$uiConfi12 = this.options.uiConfig) === null || _this$options$uiConfi12 === void 0 ? void 0 : _this$options$uiConfi12.displayExternalWalletsCount
|
|
324
466
|
});
|
|
325
467
|
}
|
|
326
468
|
filterWalletRegistry(walletRegistry, projectConfig) {
|
|
@@ -593,12 +735,12 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
593
735
|
// note: not adding cachedWallet to modal if it is external wallet.
|
|
594
736
|
// adding it later if no in-app wallets are available.
|
|
595
737
|
if (connector.type === CONNECTOR_CATEGORY.IN_APP) {
|
|
596
|
-
var _this$modalConfig$con6, _this$options$
|
|
738
|
+
var _this$modalConfig$con6, _this$options$uiConfi13, _this$options$uiConfi14, _this$options$uiConfi15;
|
|
597
739
|
log.info("connectorInitResults", connectorName);
|
|
598
740
|
const loginMethods = ((_this$modalConfig$con6 = this.modalConfig.connectors[connectorName]) === null || _this$modalConfig$con6 === void 0 ? void 0 : _this$modalConfig$con6.loginMethods) || {};
|
|
599
|
-
this.loginModal.addSocialLogins(loginMethods, ((_this$options$
|
|
600
|
-
loginGridCol: ((_this$options$
|
|
601
|
-
primaryButton: ((_this$options$
|
|
741
|
+
this.loginModal.addSocialLogins(loginMethods, ((_this$options$uiConfi13 = this.options.uiConfig) === null || _this$options$uiConfi13 === void 0 ? void 0 : _this$options$uiConfi13.loginMethodsOrder) || AUTH_PROVIDERS, _objectSpread(_objectSpread({}, this.options.uiConfig), {}, {
|
|
742
|
+
loginGridCol: ((_this$options$uiConfi14 = this.options.uiConfig) === null || _this$options$uiConfi14 === void 0 ? void 0 : _this$options$uiConfi14.loginGridCol) || 3,
|
|
743
|
+
primaryButton: ((_this$options$uiConfi15 = this.options.uiConfig) === null || _this$options$uiConfi15 === void 0 ? void 0 : _this$options$uiConfi15.primaryButton) || "socialLogin"
|
|
602
744
|
}));
|
|
603
745
|
}
|
|
604
746
|
} catch (error) {
|
|
@@ -612,6 +754,7 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
612
754
|
|
|
613
755
|
// we do it like this because we don't want one slow connector to delay the load of the entire external wallet section.
|
|
614
756
|
externalConnectors.forEach(async connector => {
|
|
757
|
+
var _this$connection;
|
|
615
758
|
const connectorName = connector.name;
|
|
616
759
|
log.debug("init external wallet", this.cachedConnector, connectorName, connector.status);
|
|
617
760
|
|
|
@@ -625,7 +768,7 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
625
768
|
|
|
626
769
|
// initialize connectors
|
|
627
770
|
// skip initializing cached connector here as it is already being initialized in initModal before.
|
|
628
|
-
if (connector.status === CONNECTOR_STATUS.NOT_READY && this.cachedConnector !== connectorName) {
|
|
771
|
+
if (connector.status === CONNECTOR_STATUS.NOT_READY && this.cachedConnector !== connectorName && ((_this$connection = this.connection) === null || _this$connection === void 0 ? void 0 : _this$connection.connectorName) !== connectorName) {
|
|
629
772
|
try {
|
|
630
773
|
this.subscribeToConnectorEvents(connector);
|
|
631
774
|
const initialChain = this.getInitialChainIdForConnector(connector);
|
|
@@ -655,6 +798,286 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
655
798
|
}
|
|
656
799
|
});
|
|
657
800
|
}
|
|
801
|
+
async switchToWalletConnectV2Account(switchResult, connectorToSwitchTo, projectConfig) {
|
|
802
|
+
const authConnector = this.getMainAuthConnector();
|
|
803
|
+
try {
|
|
804
|
+
await this.runWalletConnectV2AccountAction({
|
|
805
|
+
connector: connectorToSwitchTo,
|
|
806
|
+
connectParams: {
|
|
807
|
+
chainId: switchResult.activeChainId
|
|
808
|
+
},
|
|
809
|
+
onConnected: async connector => {
|
|
810
|
+
await super.processSwitchAccountResult(authConnector, switchResult, {
|
|
811
|
+
walletConnector: connector,
|
|
812
|
+
projectConfig
|
|
813
|
+
});
|
|
814
|
+
await authConnector.trackSwitchAccountCompleted(switchResult.targetAccount);
|
|
815
|
+
return {
|
|
816
|
+
result: undefined,
|
|
817
|
+
retainConnector: true
|
|
818
|
+
};
|
|
819
|
+
},
|
|
820
|
+
intent: ACCOUNT_LINKING_INTENT.SWITCH
|
|
821
|
+
});
|
|
822
|
+
} catch (error) {
|
|
823
|
+
await authConnector.trackSwitchAccountFailed(switchResult.targetAccount, error);
|
|
824
|
+
throw error;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* Runs a link/switch action for WalletConnect v2, racing connector.connect()
|
|
830
|
+
* against a modal-close promise to cancel and clean up the WC session if the
|
|
831
|
+
* user closes the modal during QR scanning.
|
|
832
|
+
* For synchronous connectors use {@link runNonWalletConnectAccountAction}.
|
|
833
|
+
*/
|
|
834
|
+
async runWalletConnectV2AccountAction(params) {
|
|
835
|
+
if (!this.loginModal) throw WalletInitializationError.notReady("Login modal is not initialized");
|
|
836
|
+
this.clearAccountLinkingResetOnCloseListener();
|
|
837
|
+
let retainConnector = false;
|
|
838
|
+
let connectCancelled = false;
|
|
839
|
+
let removeConnectPhaseVisibilityListener = () => {};
|
|
840
|
+
const closeDuringConnectPromise = new Promise((_resolve, reject) => {
|
|
841
|
+
const handleVisibility = visibility => {
|
|
842
|
+
if (!visibility) {
|
|
843
|
+
connectCancelled = true;
|
|
844
|
+
reject(WalletLoginError.popupClosed("User closed the modal"));
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
this.on(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, handleVisibility);
|
|
848
|
+
removeConnectPhaseVisibilityListener = () => {
|
|
849
|
+
this.removeListener(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, handleVisibility);
|
|
850
|
+
};
|
|
851
|
+
});
|
|
852
|
+
const connector = params.connector;
|
|
853
|
+
const connectPromise = connector.connect(params.connectParams);
|
|
854
|
+
void connectPromise.then(async connection => {
|
|
855
|
+
if (!connectCancelled || !connection || !connector.connected || retainConnector) return undefined;
|
|
856
|
+
try {
|
|
857
|
+
await connector.disconnect({
|
|
858
|
+
cleanup: true
|
|
859
|
+
});
|
|
860
|
+
} catch (error) {
|
|
861
|
+
log.debug("Failed to disconnect cancelled WalletConnect connector during cleanup", error);
|
|
862
|
+
}
|
|
863
|
+
return undefined;
|
|
864
|
+
}).catch(() => {});
|
|
865
|
+
try {
|
|
866
|
+
const connection = await Promise.race([connectPromise, closeDuringConnectPromise]);
|
|
867
|
+
if (!connection) {
|
|
868
|
+
throw AccountLinkingError.requestFailed("Failed to connect wallet.");
|
|
869
|
+
}
|
|
870
|
+
removeConnectPhaseVisibilityListener();
|
|
871
|
+
this.updateAccountLinkingModalSession({
|
|
872
|
+
status: ACCOUNT_LINKING_STATUS.LINKING,
|
|
873
|
+
intent: params.intent,
|
|
874
|
+
walletConnectUri: "",
|
|
875
|
+
errorMessage: ""
|
|
876
|
+
});
|
|
877
|
+
const {
|
|
878
|
+
result,
|
|
879
|
+
retainConnector: shouldRetainConnector = false
|
|
880
|
+
} = await params.onConnected(connector, connection);
|
|
881
|
+
retainConnector = shouldRetainConnector;
|
|
882
|
+
this.resetAccountLinkingModalSession();
|
|
883
|
+
this.loginModal.endConnectingLoader({
|
|
884
|
+
success: true,
|
|
885
|
+
successMessage: "",
|
|
886
|
+
skipSuccessScreen: params.intent === ACCOUNT_LINKING_INTENT.SWITCH
|
|
887
|
+
});
|
|
888
|
+
return result;
|
|
889
|
+
} catch (error) {
|
|
890
|
+
const isPopupClosed = error instanceof Web3AuthError && error.code === 5114;
|
|
891
|
+
if (isPopupClosed) {
|
|
892
|
+
this.resetAccountLinkingModalSession();
|
|
893
|
+
} else {
|
|
894
|
+
const fallbackMessage = params.intent === ACCOUNT_LINKING_INTENT.SWITCH ? "Failed to switch wallet." : undefined;
|
|
895
|
+
const errorMessage = this.formatAccountLinkingErrorMessage(error) || fallbackMessage;
|
|
896
|
+
this.resetAccountLinkingModalSession();
|
|
897
|
+
this.loginModal.endConnectingLoader({
|
|
898
|
+
success: false,
|
|
899
|
+
errorMessage
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
this.installAccountLinkingResetOnCloseListener();
|
|
903
|
+
throw error;
|
|
904
|
+
} finally {
|
|
905
|
+
removeConnectPhaseVisibilityListener();
|
|
906
|
+
this.clearAccountLinkingConnectorListeners();
|
|
907
|
+
try {
|
|
908
|
+
if (!retainConnector && connector.connected) {
|
|
909
|
+
await connector.disconnect({
|
|
910
|
+
cleanup: true
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
} catch (error) {
|
|
914
|
+
log.debug("Failed to disconnect WalletConnect connector during cleanup", error);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
async linkAccountWithChosenConnector(connectorName, chainId) {
|
|
919
|
+
const connectorToLink = await this.prepareAccountLinkingConnector(connectorName, chainId);
|
|
920
|
+
if (connectorToLink.name !== WALLET_CONNECTORS.WALLET_CONNECT_V2) {
|
|
921
|
+
return this.runNonWalletConnectAccountAction(connectorName, () => super.linkAccountWithConnector(connectorName, chainId, connectorToLink), {
|
|
922
|
+
connector: connectorToLink
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
return this.runWalletConnectV2AccountAction({
|
|
926
|
+
connector: connectorToLink,
|
|
927
|
+
connectParams: {
|
|
928
|
+
chainId,
|
|
929
|
+
isAccountLinking: true
|
|
930
|
+
},
|
|
931
|
+
onConnected: async connector => ({
|
|
932
|
+
result: await super.linkAccountWithConnector(connectorName, chainId, connector)
|
|
933
|
+
}),
|
|
934
|
+
intent: ACCOUNT_LINKING_INTENT.LINK
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
pickWalletForAccountLinking(chainId) {
|
|
938
|
+
if (!this.loginModal) throw WalletInitializationError.notReady("Login modal is not initialized");
|
|
939
|
+
if (this.accountLinkingPickerResolver) {
|
|
940
|
+
throw AccountLinkingError.requestFailed("Another account linking picker is already in progress.");
|
|
941
|
+
}
|
|
942
|
+
this.loginModal.startAccountLinkingPicker({
|
|
943
|
+
chainId
|
|
944
|
+
});
|
|
945
|
+
return new Promise((resolve, reject) => {
|
|
946
|
+
const cleanup = () => {
|
|
947
|
+
this.accountLinkingPickerResolver = null;
|
|
948
|
+
if (this.removeAccountLinkingPickerCloseListener) {
|
|
949
|
+
this.removeAccountLinkingPickerCloseListener();
|
|
950
|
+
this.removeAccountLinkingPickerCloseListener = null;
|
|
951
|
+
}
|
|
952
|
+
this.loginModal.endAccountLinkingPicker();
|
|
953
|
+
};
|
|
954
|
+
const handleVisibility = visible => {
|
|
955
|
+
if (visible) return;
|
|
956
|
+
cleanup();
|
|
957
|
+
reject(WalletLoginError.popupClosed("User closed the modal"));
|
|
958
|
+
};
|
|
959
|
+
this.accountLinkingPickerResolver = connector => {
|
|
960
|
+
cleanup();
|
|
961
|
+
resolve(connector);
|
|
962
|
+
};
|
|
963
|
+
this.on(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, handleVisibility);
|
|
964
|
+
this.removeAccountLinkingPickerCloseListener = () => {
|
|
965
|
+
this.removeListener(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, handleVisibility);
|
|
966
|
+
};
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
/**
|
|
971
|
+
* Runs a link/switch action for synchronous connectors (injected wallets, already-connected).
|
|
972
|
+
* Shows the connecting loader, forwards AUTHORIZING events to the modal, and
|
|
973
|
+
* resolves/rejects the loader on completion.
|
|
974
|
+
* For WalletConnect v2 use {@link runWalletConnectV2AccountAction}.
|
|
975
|
+
*/
|
|
976
|
+
async runNonWalletConnectAccountAction(connectorName, fn, options = {}) {
|
|
977
|
+
if (!this.loginModal) throw WalletInitializationError.notReady("Login modal is not initialized");
|
|
978
|
+
const displayName = CONNECTOR_NAMES[connectorName] || connectorName;
|
|
979
|
+
this.loginModal.startConnectingLoader({
|
|
980
|
+
connector: connectorName,
|
|
981
|
+
connectorName: displayName
|
|
982
|
+
});
|
|
983
|
+
|
|
984
|
+
// Forward the AUTHORIZING event from the linking wallet connector to the modal so we can
|
|
985
|
+
// swap the loader from "connecting" to "authorizing" while the user reviews the signature
|
|
986
|
+
// request inside their wallet.
|
|
987
|
+
const handleAuthorizing = () => {
|
|
988
|
+
var _this$loginModal2;
|
|
989
|
+
return (_this$loginModal2 = this.loginModal) === null || _this$loginModal2 === void 0 ? void 0 : _this$loginModal2.markLoaderAuthorizing();
|
|
990
|
+
};
|
|
991
|
+
if (options.connector) {
|
|
992
|
+
options.connector.on(CONNECTOR_EVENTS.AUTHORIZING, handleAuthorizing);
|
|
993
|
+
}
|
|
994
|
+
try {
|
|
995
|
+
const result = await fn();
|
|
996
|
+
this.resetAccountLinkingModalSession();
|
|
997
|
+
this.loginModal.endConnectingLoader({
|
|
998
|
+
success: true,
|
|
999
|
+
skipSuccessScreen: options.skipSuccessScreen
|
|
1000
|
+
});
|
|
1001
|
+
return result;
|
|
1002
|
+
} catch (error) {
|
|
1003
|
+
const message = this.formatAccountLinkingErrorMessage(error);
|
|
1004
|
+
this.resetAccountLinkingModalSession();
|
|
1005
|
+
this.loginModal.endConnectingLoader({
|
|
1006
|
+
success: false,
|
|
1007
|
+
errorMessage: message
|
|
1008
|
+
});
|
|
1009
|
+
throw error;
|
|
1010
|
+
} finally {
|
|
1011
|
+
if (options.connector) {
|
|
1012
|
+
options.connector.removeListener(CONNECTOR_EVENTS.AUTHORIZING, handleAuthorizing);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
subscribeToAccountLinkingConnectorEvents(connector) {
|
|
1017
|
+
const handleConnecting = () => {
|
|
1018
|
+
this.updateAccountLinkingModalSession({
|
|
1019
|
+
status: ACCOUNT_LINKING_STATUS.AWAITING_CONNECTION,
|
|
1020
|
+
errorMessage: ""
|
|
1021
|
+
});
|
|
1022
|
+
};
|
|
1023
|
+
const handleConnectorDataUpdated = connectorData => {
|
|
1024
|
+
if (connectorData.connectorName !== WALLET_CONNECTORS.WALLET_CONNECT_V2) return;
|
|
1025
|
+
const walletConnectData = connectorData.data;
|
|
1026
|
+
if (!walletConnectData.uri) return;
|
|
1027
|
+
this.updateAccountLinkingModalSession({
|
|
1028
|
+
walletConnectUri: walletConnectData.uri,
|
|
1029
|
+
status: ACCOUNT_LINKING_STATUS.AWAITING_CONNECTION,
|
|
1030
|
+
errorMessage: ""
|
|
1031
|
+
});
|
|
1032
|
+
};
|
|
1033
|
+
const handleConnected = _data => {
|
|
1034
|
+
this.updateAccountLinkingModalSession({
|
|
1035
|
+
status: ACCOUNT_LINKING_STATUS.WALLET_CONNECTED,
|
|
1036
|
+
walletConnectUri: "",
|
|
1037
|
+
errorMessage: ""
|
|
1038
|
+
});
|
|
1039
|
+
};
|
|
1040
|
+
const handleErrored = error => {
|
|
1041
|
+
this.updateAccountLinkingModalSession({
|
|
1042
|
+
status: ACCOUNT_LINKING_STATUS.ERRORED,
|
|
1043
|
+
errorMessage: error.message || "Failed to connect wallet."
|
|
1044
|
+
});
|
|
1045
|
+
};
|
|
1046
|
+
connector.on(CONNECTOR_EVENTS.CONNECTING, handleConnecting);
|
|
1047
|
+
connector.on(CONNECTOR_EVENTS.CONNECTOR_DATA_UPDATED, handleConnectorDataUpdated);
|
|
1048
|
+
connector.on(CONNECTOR_EVENTS.CONNECTED, handleConnected);
|
|
1049
|
+
connector.on(CONNECTOR_EVENTS.ERRORED, handleErrored);
|
|
1050
|
+
return () => {
|
|
1051
|
+
connector.removeListener(CONNECTOR_EVENTS.CONNECTING, handleConnecting);
|
|
1052
|
+
connector.removeListener(CONNECTOR_EVENTS.CONNECTOR_DATA_UPDATED, handleConnectorDataUpdated);
|
|
1053
|
+
connector.removeListener(CONNECTOR_EVENTS.CONNECTED, handleConnected);
|
|
1054
|
+
connector.removeListener(CONNECTOR_EVENTS.ERRORED, handleErrored);
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
clearAccountLinkingConnectorListeners() {
|
|
1058
|
+
if (this.removeAccountLinkingConnectorListeners) {
|
|
1059
|
+
this.removeAccountLinkingConnectorListeners();
|
|
1060
|
+
this.removeAccountLinkingConnectorListeners = null;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
installAccountLinkingResetOnCloseListener() {
|
|
1064
|
+
this.clearAccountLinkingResetOnCloseListener();
|
|
1065
|
+
const handleVisibility = visibility => {
|
|
1066
|
+
if (visibility) return;
|
|
1067
|
+
this.resetAccountLinkingModalSession();
|
|
1068
|
+
this.clearAccountLinkingResetOnCloseListener();
|
|
1069
|
+
};
|
|
1070
|
+
this.on(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, handleVisibility);
|
|
1071
|
+
this.removeAccountLinkingResetOnCloseListener = () => {
|
|
1072
|
+
this.removeListener(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, handleVisibility);
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
clearAccountLinkingResetOnCloseListener() {
|
|
1076
|
+
if (this.removeAccountLinkingResetOnCloseListener) {
|
|
1077
|
+
this.removeAccountLinkingResetOnCloseListener();
|
|
1078
|
+
this.removeAccountLinkingResetOnCloseListener = null;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
658
1081
|
getCombinedConnectionId(authConnectionId, groupedAuthConnectionId) {
|
|
659
1082
|
let id = authConnectionId;
|
|
660
1083
|
if (groupedAuthConnectionId) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
export { useAuthTokenInfo, useChain, useCheckout, useEnableMFA, useFunding, useManageMFA, useReceive, useSwap, useSwitchChain, useWalletConnectScanner, useWalletServicesPlugin, useWalletUI, useWallets, useWeb3AuthDisconnect, useWeb3AuthUser } from '@web3auth/no-modal/react';
|
|
1
2
|
export { useWeb3Auth } from './hooks/useWeb3Auth.js';
|
|
2
3
|
export { useWeb3AuthConnect } from './hooks/useWeb3AuthConnect.js';
|
|
3
|
-
export { useAuthTokenInfo, useChain, useCheckout, useEnableMFA, useFunding, useManageMFA, useReceive, useSwap, useSwitchChain, useWalletConnectScanner, useWalletServicesPlugin, useWalletUI, useWeb3AuthDisconnect, useWeb3AuthUser } from '@web3auth/no-modal/react';
|
|
4
4
|
export { Web3AuthProvider } from './Web3AuthProvider.js';
|