@web3auth/modal 10.0.0-beta.2 → 10.0.0-beta.4
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/config.js +3 -3
- package/dist/lib.cjs/packages/modal/src/index.js +1 -0
- package/dist/lib.cjs/packages/modal/src/modalManager.js +46 -23
- package/dist/lib.cjs/packages/modal/src/react/Web3AuthProvider.js +5 -1
- package/dist/lib.cjs/packages/modal/src/react/context/WalletServicesInnerContext.js +72 -0
- package/dist/lib.cjs/packages/modal/src/react/context/Web3AuthInnerContext.js +21 -78
- package/dist/lib.cjs/packages/modal/src/react/hooks/useCheckout.js +34 -0
- package/dist/lib.cjs/packages/modal/src/react/hooks/useEnableMFA.js +30 -0
- package/dist/lib.cjs/packages/modal/src/react/hooks/useIdentityToken.js +42 -0
- package/dist/lib.cjs/packages/modal/src/react/hooks/useManageMFA.js +30 -0
- package/dist/lib.cjs/packages/modal/src/react/hooks/useSwap.js +34 -0
- package/dist/lib.cjs/packages/modal/src/react/hooks/useSwitchChain.js +32 -0
- package/dist/lib.cjs/packages/modal/src/react/hooks/useWalletConnectScanner.js +34 -0
- package/dist/lib.cjs/packages/modal/src/react/hooks/useWalletServicesPlugin.js +12 -0
- package/dist/lib.cjs/packages/modal/src/react/hooks/useWalletUI.js +34 -0
- package/dist/lib.cjs/packages/modal/src/react/hooks/useWeb3Auth.js +21 -8
- package/dist/lib.cjs/packages/modal/src/react/hooks/useWeb3AuthConnect.js +43 -0
- package/dist/lib.cjs/packages/modal/src/react/hooks/useWeb3AuthDisconnect.js +30 -0
- package/dist/lib.cjs/packages/modal/src/react/hooks/useWeb3AuthInner.js +15 -0
- package/dist/lib.cjs/packages/modal/src/react/hooks/useWeb3AuthUser.js +50 -0
- package/dist/lib.cjs/packages/modal/src/react/index.js +24 -3
- package/dist/lib.cjs/packages/modal/src/react/wagmi/index.js +7 -0
- package/dist/lib.cjs/packages/modal/src/react/wagmi/provider.js +192 -0
- package/dist/lib.cjs/packages/modal/src/ui/components/BottomSheet/BottomSheet.js +1 -1
- package/dist/lib.cjs/packages/modal/src/ui/components/Button/ButtonSocial/ButtonSocial.js +1 -1
- package/dist/lib.cjs/packages/modal/src/ui/components/Button/ButtonWallet/ButtonWallet.js +12 -4
- package/dist/lib.cjs/packages/modal/src/ui/components/ConnectWallet/ConnectWallet.js +7 -7
- package/dist/lib.cjs/packages/modal/src/ui/components/ConnectWallet/ConnectWalletChainFilter/ConnectWalletChainFilter.js +3 -3
- package/dist/lib.cjs/packages/modal/src/ui/components/ConnectWallet/ConnectWalletChainNamespaceSelect/ConnectWalletChainNamespaceSelect.js +3 -3
- package/dist/lib.cjs/packages/modal/src/ui/components/ConnectWallet/ConnectWalletHeader/ConnectWalletHeader.js +1 -1
- package/dist/lib.cjs/packages/modal/src/ui/components/ConnectWallet/ConnectWalletList/ConnectWalletList.js +13 -5
- package/dist/lib.cjs/packages/modal/src/ui/components/ConnectWallet/ConnectWalletQrCode/ConnectWalletQrCode.js +1 -1
- package/dist/lib.cjs/packages/modal/src/ui/components/Image/Image.js +5 -4
- package/dist/lib.cjs/packages/modal/src/ui/components/Loader/Loader.js +1 -1
- package/dist/lib.cjs/packages/modal/src/ui/components/Login/Login.js +55 -32
- package/dist/lib.cjs/packages/modal/src/ui/components/Login/LoginPasswordLess/LoginPasswordLess.js +10 -5
- package/dist/lib.cjs/packages/modal/src/ui/components/Modal/Modal.js +1 -1
- package/dist/lib.cjs/packages/modal/src/ui/components/PulseLoader/PulseLoader.js +3 -3
- package/dist/lib.cjs/packages/modal/src/ui/components/Root/Root.js +19 -33
- package/dist/lib.cjs/packages/modal/src/ui/components/SocialLoginList/SocialLoginList.js +15 -34
- package/dist/lib.cjs/packages/modal/src/ui/components/Widget/Widget.js +2 -1
- package/dist/lib.cjs/packages/modal/src/ui/config.js +2 -1
- package/dist/lib.cjs/packages/modal/src/ui/constants.js +4 -0
- package/dist/lib.cjs/packages/modal/src/ui/css/index.css.js +1 -1
- package/dist/lib.cjs/packages/modal/src/ui/handlers/AbstractHandler.js +6 -2
- package/dist/lib.cjs/packages/modal/src/ui/handlers/EmailPasswordlessHandler.js +7 -4
- package/dist/lib.cjs/packages/modal/src/ui/handlers/SmsPasswordlessHandler.js +2 -2
- package/dist/lib.cjs/packages/modal/src/ui/i18n/dutch.json.js +32 -31
- package/dist/lib.cjs/packages/modal/src/ui/i18n/english.json.js +32 -31
- package/dist/lib.cjs/packages/modal/src/ui/i18n/french.json.js +32 -31
- package/dist/lib.cjs/packages/modal/src/ui/i18n/german.json.js +32 -31
- package/dist/lib.cjs/packages/modal/src/ui/i18n/japanese.json.js +32 -31
- package/dist/lib.cjs/packages/modal/src/ui/i18n/korean.json.js +32 -31
- package/dist/lib.cjs/packages/modal/src/ui/i18n/mandarin.json.js +32 -31
- package/dist/lib.cjs/packages/modal/src/ui/i18n/portuguese.json.js +32 -31
- package/dist/lib.cjs/packages/modal/src/ui/i18n/spanish.json.js +32 -31
- package/dist/lib.cjs/packages/modal/src/ui/i18n/turkish.json.js +32 -31
- package/dist/lib.cjs/packages/modal/src/ui/loginModal.js +5 -3
- package/dist/lib.cjs/packages/modal/src/vue/Web3AuthProvider.js +15 -3
- package/dist/lib.cjs/types/config.d.ts +1 -0
- package/dist/lib.cjs/types/interface.d.ts +3 -1
- package/dist/lib.cjs/types/modalManager.d.ts +4 -1
- package/dist/lib.cjs/types/react/context/WalletServicesInnerContext.d.ts +6 -0
- package/dist/lib.cjs/types/react/hooks/index.d.ts +13 -1
- package/dist/lib.cjs/types/react/hooks/useCheckout.d.ts +8 -0
- package/dist/lib.cjs/types/react/hooks/useEnableMFA.d.ts +7 -0
- package/dist/lib.cjs/types/react/hooks/useIdentityToken.d.ts +13 -0
- package/dist/lib.cjs/types/react/hooks/useManageMFA.d.ts +7 -0
- package/dist/lib.cjs/types/react/hooks/useSwap.d.ts +8 -0
- package/dist/lib.cjs/types/react/hooks/useSwitchChain.d.ts +7 -0
- package/dist/lib.cjs/types/react/hooks/useWalletConnectScanner.d.ts +8 -0
- package/dist/lib.cjs/types/react/hooks/useWalletServicesPlugin.d.ts +2 -0
- package/dist/lib.cjs/types/react/hooks/useWalletUI.d.ts +8 -0
- package/dist/lib.cjs/types/react/hooks/useWeb3Auth.d.ts +2 -1
- package/dist/lib.cjs/types/react/hooks/useWeb3AuthConnect.d.ts +9 -0
- package/dist/lib.cjs/types/react/hooks/useWeb3AuthDisconnect.d.ts +9 -0
- package/dist/lib.cjs/types/react/hooks/useWeb3AuthInner.d.ts +2 -0
- package/dist/lib.cjs/types/react/hooks/useWeb3AuthUser.d.ts +9 -0
- package/dist/lib.cjs/types/react/index.d.ts +0 -1
- package/dist/lib.cjs/types/react/interfaces.d.ts +6 -2
- package/dist/lib.cjs/types/react/wagmi/index.d.ts +1 -0
- package/dist/lib.cjs/types/react/wagmi/interface.d.ts +4 -0
- package/dist/lib.cjs/types/react/wagmi/provider.d.ts +4 -0
- package/dist/lib.cjs/types/ui/components/Login/Login.type.d.ts +2 -2
- package/dist/lib.cjs/types/ui/config.d.ts +1 -1
- package/dist/lib.cjs/types/ui/constants.d.ts +2 -0
- package/dist/lib.cjs/types/ui/handlers/AbstractHandler.d.ts +3 -2
- package/dist/lib.cjs/types/ui/handlers/EmailPasswordlessHandler.d.ts +3 -1
- package/dist/lib.cjs/types/ui/interfaces.d.ts +8 -6
- package/dist/lib.esm/packages/modal/src/config.js +3 -4
- package/dist/lib.esm/packages/modal/src/index.js +1 -1
- package/dist/lib.esm/packages/modal/src/modalManager.js +48 -24
- package/dist/lib.esm/packages/modal/src/react/Web3AuthProvider.js +6 -2
- package/dist/lib.esm/packages/modal/src/react/context/WalletServicesInnerContext.js +69 -0
- package/dist/lib.esm/packages/modal/src/react/context/Web3AuthInnerContext.js +22 -79
- package/dist/lib.esm/packages/modal/src/react/hooks/useCheckout.js +32 -0
- package/dist/lib.esm/packages/modal/src/react/hooks/useEnableMFA.js +28 -0
- package/dist/lib.esm/packages/modal/src/react/hooks/useIdentityToken.js +40 -0
- package/dist/lib.esm/packages/modal/src/react/hooks/useManageMFA.js +28 -0
- package/dist/lib.esm/packages/modal/src/react/hooks/useSwap.js +32 -0
- package/dist/lib.esm/packages/modal/src/react/hooks/useSwitchChain.js +30 -0
- package/dist/lib.esm/packages/modal/src/react/hooks/useWalletConnectScanner.js +32 -0
- package/dist/lib.esm/packages/modal/src/react/hooks/useWalletServicesPlugin.js +10 -0
- package/dist/lib.esm/packages/modal/src/react/hooks/useWalletUI.js +32 -0
- package/dist/lib.esm/packages/modal/src/react/hooks/useWeb3Auth.js +21 -8
- package/dist/lib.esm/packages/modal/src/react/hooks/useWeb3AuthConnect.js +41 -0
- package/dist/lib.esm/packages/modal/src/react/hooks/useWeb3AuthDisconnect.js +28 -0
- package/dist/lib.esm/packages/modal/src/react/hooks/useWeb3AuthInner.js +13 -0
- package/dist/lib.esm/packages/modal/src/react/hooks/useWeb3AuthUser.js +48 -0
- package/dist/lib.esm/packages/modal/src/react/index.js +12 -1
- package/dist/lib.esm/packages/modal/src/react/wagmi/index.js +1 -0
- package/dist/lib.esm/packages/modal/src/react/wagmi/provider.js +192 -0
- package/dist/lib.esm/packages/modal/src/ui/components/BottomSheet/BottomSheet.js +1 -1
- package/dist/lib.esm/packages/modal/src/ui/components/Button/ButtonSocial/ButtonSocial.js +1 -1
- package/dist/lib.esm/packages/modal/src/ui/components/Button/ButtonWallet/ButtonWallet.js +14 -6
- package/dist/lib.esm/packages/modal/src/ui/components/ConnectWallet/ConnectWallet.js +7 -7
- package/dist/lib.esm/packages/modal/src/ui/components/ConnectWallet/ConnectWalletChainFilter/ConnectWalletChainFilter.js +3 -3
- package/dist/lib.esm/packages/modal/src/ui/components/ConnectWallet/ConnectWalletChainNamespaceSelect/ConnectWalletChainNamespaceSelect.js +3 -3
- package/dist/lib.esm/packages/modal/src/ui/components/ConnectWallet/ConnectWalletHeader/ConnectWalletHeader.js +1 -1
- package/dist/lib.esm/packages/modal/src/ui/components/ConnectWallet/ConnectWalletList/ConnectWalletList.js +13 -5
- package/dist/lib.esm/packages/modal/src/ui/components/ConnectWallet/ConnectWalletQrCode/ConnectWalletQrCode.js +1 -1
- package/dist/lib.esm/packages/modal/src/ui/components/Image/Image.js +5 -4
- package/dist/lib.esm/packages/modal/src/ui/components/Loader/Loader.js +1 -1
- package/dist/lib.esm/packages/modal/src/ui/components/Login/Login.js +58 -32
- package/dist/lib.esm/packages/modal/src/ui/components/Login/LoginPasswordLess/LoginPasswordLess.js +11 -6
- package/dist/lib.esm/packages/modal/src/ui/components/Modal/Modal.js +1 -1
- package/dist/lib.esm/packages/modal/src/ui/components/PulseLoader/PulseLoader.js +3 -3
- package/dist/lib.esm/packages/modal/src/ui/components/Root/Root.js +19 -34
- package/dist/lib.esm/packages/modal/src/ui/components/SocialLoginList/SocialLoginList.js +16 -35
- package/dist/lib.esm/packages/modal/src/ui/components/Widget/Widget.js +3 -2
- package/dist/lib.esm/packages/modal/src/ui/config.js +2 -1
- package/dist/lib.esm/packages/modal/src/ui/constants.js +3 -1
- package/dist/lib.esm/packages/modal/src/ui/css/index.css.js +1 -1
- package/dist/lib.esm/packages/modal/src/ui/handlers/AbstractHandler.js +5 -1
- package/dist/lib.esm/packages/modal/src/ui/handlers/EmailPasswordlessHandler.js +7 -4
- package/dist/lib.esm/packages/modal/src/ui/handlers/SmsPasswordlessHandler.js +2 -2
- package/dist/lib.esm/packages/modal/src/ui/i18n/dutch.json.js +32 -31
- package/dist/lib.esm/packages/modal/src/ui/i18n/english.json.js +32 -31
- package/dist/lib.esm/packages/modal/src/ui/i18n/french.json.js +32 -31
- package/dist/lib.esm/packages/modal/src/ui/i18n/german.json.js +32 -31
- package/dist/lib.esm/packages/modal/src/ui/i18n/japanese.json.js +32 -31
- package/dist/lib.esm/packages/modal/src/ui/i18n/korean.json.js +32 -31
- package/dist/lib.esm/packages/modal/src/ui/i18n/mandarin.json.js +32 -31
- package/dist/lib.esm/packages/modal/src/ui/i18n/portuguese.json.js +32 -31
- package/dist/lib.esm/packages/modal/src/ui/i18n/spanish.json.js +32 -31
- package/dist/lib.esm/packages/modal/src/ui/i18n/turkish.json.js +32 -31
- package/dist/lib.esm/packages/modal/src/ui/loginModal.js +6 -4
- package/dist/lib.esm/packages/modal/src/vue/Web3AuthProvider.js +16 -3
- package/dist/modal.umd.min.js +1 -1
- package/dist/modal.umd.min.js.LICENSE.txt +10 -0
- package/package.json +41 -16
- package/dist/lib.cjs/types/react/context/index.d.ts +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
-
import { Web3AuthNoModal, cloneDeep, WALLET_CONNECTORS, log, CONNECTOR_STATUS, CONNECTOR_EVENTS, WalletInitializationError, fetchProjectConfig, fetchWalletRegistry, CONNECTOR_CATEGORY, CONNECTOR_NAMES, CONNECTOR_NAMESPACES } from '@web3auth/no-modal';
|
|
3
|
+
import { Web3AuthNoModal, cloneDeep, WALLET_CONNECTORS, log, CONNECTOR_STATUS, withAbort, CONNECTOR_EVENTS, WalletInitializationError, fetchProjectConfig, fetchWalletRegistry, CONNECTOR_CATEGORY, CONNECTOR_NAMES, CONNECTOR_NAMESPACES } from '@web3auth/no-modal';
|
|
4
4
|
import deepmerge from 'deepmerge';
|
|
5
5
|
import { defaultConnectorsModalConfig, walletRegistryUrl } from './config.js';
|
|
6
6
|
import { AUTH_PROVIDERS_NAMES, AUTH_PROVIDERS, capitalizeFirstLetter } from './ui/config.js';
|
|
@@ -24,7 +24,7 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
24
24
|
});
|
|
25
25
|
_defineProperty(this, "onSocialLogin", async params => {
|
|
26
26
|
try {
|
|
27
|
-
await this.connectTo(
|
|
27
|
+
await this.connectTo(WALLET_CONNECTORS.AUTH, params.loginParams);
|
|
28
28
|
} catch (error) {
|
|
29
29
|
log.error(`Error while connecting to connector: ${params.connector}`, error);
|
|
30
30
|
}
|
|
@@ -71,19 +71,19 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
71
71
|
if (this.options.modalConfig) this.modalConfig = this.options.modalConfig;
|
|
72
72
|
log.info("modalConfig", this.modalConfig);
|
|
73
73
|
}
|
|
74
|
-
async initModal() {
|
|
74
|
+
async initModal(options) {
|
|
75
|
+
const {
|
|
76
|
+
signal
|
|
77
|
+
} = options || {};
|
|
75
78
|
super.checkInitRequirements();
|
|
76
79
|
// get project config and wallet registry
|
|
77
80
|
const {
|
|
78
81
|
projectConfig,
|
|
79
82
|
walletRegistry
|
|
80
83
|
} = await this.getProjectAndWalletConfig();
|
|
81
|
-
this.options.uiConfig = deepmerge(cloneDeep(projectConfig.whitelabel || {}), this.options.uiConfig || {});
|
|
82
|
-
if (!this.options.uiConfig.defaultLanguage) this.options.uiConfig.defaultLanguage = getUserLanguage(this.options.uiConfig.defaultLanguage);
|
|
83
|
-
if (!this.options.uiConfig.mode) this.options.uiConfig.mode = "light";
|
|
84
|
-
this.options.uiConfig = deepmerge(projectConfig.loginModal || {}, this.options.uiConfig || {});
|
|
85
84
|
|
|
86
85
|
// init config
|
|
86
|
+
this.initUIConfig(projectConfig);
|
|
87
87
|
super.initAccountAbstractionConfig(projectConfig);
|
|
88
88
|
super.initChainsConfig(projectConfig);
|
|
89
89
|
super.initCachedConnectorAndChainId();
|
|
@@ -97,6 +97,7 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
97
97
|
connectorListener: this,
|
|
98
98
|
web3authClientId: this.options.clientId,
|
|
99
99
|
web3authNetwork: this.options.web3AuthNetwork,
|
|
100
|
+
authBuildEnv: this.options.authBuildEnv,
|
|
100
101
|
chainNamespaces: this.getChainNamespaces(),
|
|
101
102
|
walletRegistry: filteredWalletRegistry
|
|
102
103
|
}), {
|
|
@@ -105,25 +106,34 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
105
106
|
onExternalWalletLogin: this.onExternalWalletLogin,
|
|
106
107
|
onModalVisibility: this.onModalVisibility
|
|
107
108
|
});
|
|
108
|
-
await this.loginModal.initModal();
|
|
109
|
+
await withAbort(() => this.loginModal.initModal(), signal);
|
|
109
110
|
|
|
110
111
|
// setup common JRPC provider
|
|
111
|
-
await this.setupCommonJRPCProvider();
|
|
112
|
+
await withAbort(() => this.setupCommonJRPCProvider(), signal);
|
|
112
113
|
|
|
113
114
|
// initialize connectors
|
|
114
115
|
this.on(CONNECTOR_EVENTS.CONNECTORS_UPDATED, ({
|
|
115
116
|
connectors: newConnectors
|
|
116
|
-
}) =>
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
117
|
+
}) => {
|
|
118
|
+
const onAbortHandler = () => {
|
|
119
|
+
var _this$connectors;
|
|
120
|
+
log.debug("init aborted");
|
|
121
|
+
if (((_this$connectors = this.connectors) === null || _this$connectors === void 0 ? void 0 : _this$connectors.length) > 0) {
|
|
122
|
+
super.cleanup();
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
withAbort(() => this.initConnectors({
|
|
126
|
+
connectors: newConnectors,
|
|
127
|
+
projectConfig,
|
|
128
|
+
disabledExternalWallets
|
|
129
|
+
}), signal, onAbortHandler);
|
|
123
130
|
});
|
|
131
|
+
await withAbort(() => super.loadConnectors({
|
|
132
|
+
projectConfig
|
|
133
|
+
}), signal);
|
|
124
134
|
|
|
125
135
|
// initialize plugins
|
|
126
|
-
await
|
|
136
|
+
await withAbort(() => super.initPlugins(), signal);
|
|
127
137
|
}
|
|
128
138
|
async connect() {
|
|
129
139
|
if (!this.loginModal) throw WalletInitializationError.notReady("Login modal is not initialized");
|
|
@@ -219,6 +229,24 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
219
229
|
walletRegistry
|
|
220
230
|
};
|
|
221
231
|
}
|
|
232
|
+
initUIConfig(projectConfig) {
|
|
233
|
+
this.options.uiConfig = deepmerge(cloneDeep(projectConfig.whitelabel || {}), this.options.uiConfig || {});
|
|
234
|
+
if (!this.options.uiConfig.defaultLanguage) this.options.uiConfig.defaultLanguage = getUserLanguage(this.options.uiConfig.defaultLanguage);
|
|
235
|
+
if (!this.options.uiConfig.mode) this.options.uiConfig.mode = "light";
|
|
236
|
+
this.options.uiConfig = deepmerge(projectConfig.loginModal || {}, this.options.uiConfig);
|
|
237
|
+
|
|
238
|
+
// merge login methods order from project config and user config, with user config taking precedence
|
|
239
|
+
const defaultAuthConnections = projectConfig.embeddedWalletAuth.filter(x => x.isDefault).map(x => x.authConnection);
|
|
240
|
+
const mergedAuthConnections = [...(this.options.uiConfig.loginMethodsOrder || []), ...defaultAuthConnections];
|
|
241
|
+
const loginMethodsOrder = [];
|
|
242
|
+
const authConnectionSet = new Set();
|
|
243
|
+
for (const authConnection of mergedAuthConnections) {
|
|
244
|
+
if (authConnectionSet.has(authConnection)) continue;
|
|
245
|
+
authConnectionSet.add(authConnection);
|
|
246
|
+
loginMethodsOrder.push(authConnection);
|
|
247
|
+
}
|
|
248
|
+
this.options.uiConfig.loginMethodsOrder = loginMethodsOrder;
|
|
249
|
+
}
|
|
222
250
|
async initConnectors({
|
|
223
251
|
connectors,
|
|
224
252
|
projectConfig,
|
|
@@ -288,9 +316,7 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
288
316
|
groupedAuthConnectionId: groupedAuthConnectionId,
|
|
289
317
|
extraLoginOptions: authConnectionConfig.jwtParameters,
|
|
290
318
|
isDefault: true,
|
|
291
|
-
showOnModal: true
|
|
292
|
-
showOnDesktop: true,
|
|
293
|
-
showOnMobile: true
|
|
319
|
+
showOnModal: true
|
|
294
320
|
};
|
|
295
321
|
}
|
|
296
322
|
embedWalletConfigMap.set(groupedAuthConnectionId || authConnectionId, authConnectionConfig);
|
|
@@ -339,9 +365,7 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
339
365
|
// start with the default config of connector.
|
|
340
366
|
const defaultConnectorConfig = {
|
|
341
367
|
label: CONNECTOR_NAMES[connectorName] || connectorName.split("-").map(capitalizeFirstLetter).join(" "),
|
|
342
|
-
showOnModal: true
|
|
343
|
-
showOnMobile: true,
|
|
344
|
-
showOnDesktop: true
|
|
368
|
+
showOnModal: true
|
|
345
369
|
};
|
|
346
370
|
this.modalConfig.connectors[connectorName] = _objectSpread(_objectSpread({}, defaultConnectorConfig), ((_this$modalConfig3 = this.modalConfig) === null || _this$modalConfig3 === void 0 || (_this$modalConfig3 = _this$modalConfig3.connectors) === null || _this$modalConfig3 === void 0 ? void 0 : _this$modalConfig3[connectorName]) || {});
|
|
347
371
|
|
|
@@ -395,7 +419,7 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
395
419
|
const hasExternalConnectors = connectorNames.some(connectorName => {
|
|
396
420
|
var _this$getConnector, _this$modalConfig$con5;
|
|
397
421
|
if (connectorName === WALLET_CONNECTORS.WALLET_CONNECT_V2) return true;
|
|
398
|
-
return ((_this$getConnector = this.getConnector(connectorName)) === null || _this$getConnector === void 0 ? void 0 : _this$getConnector.type) === CONNECTOR_CATEGORY.EXTERNAL && ((_this$modalConfig$con5 = this.modalConfig.connectors) === null || _this$modalConfig$con5 === void 0 ? void 0 : _this$modalConfig$con5
|
|
422
|
+
return ((_this$getConnector = this.getConnector(connectorName)) === null || _this$getConnector === void 0 ? void 0 : _this$getConnector.type) === CONNECTOR_CATEGORY.EXTERNAL && ((_this$modalConfig$con5 = this.modalConfig.connectors) === null || _this$modalConfig$con5 === void 0 || (_this$modalConfig$con5 = _this$modalConfig$con5[connectorName]) === null || _this$modalConfig$con5 === void 0 ? void 0 : _this$modalConfig$con5.showOnModal);
|
|
399
423
|
});
|
|
400
424
|
return {
|
|
401
425
|
hasInAppConnectors,
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { createElement } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { WalletServicesContextProvider } from './context/WalletServicesInnerContext.js';
|
|
3
|
+
import { Web3AuthInnerProvider, Web3AuthInnerContext } from './context/Web3AuthInnerContext.js';
|
|
3
4
|
|
|
4
5
|
function Web3AuthProvider({
|
|
5
6
|
config,
|
|
6
7
|
children
|
|
7
8
|
}) {
|
|
9
|
+
const pluginChild = /*#__PURE__*/createElement(WalletServicesContextProvider, {
|
|
10
|
+
context: Web3AuthInnerContext
|
|
11
|
+
}, children);
|
|
8
12
|
return /*#__PURE__*/createElement(Web3AuthInnerProvider, {
|
|
9
13
|
config
|
|
10
|
-
},
|
|
14
|
+
}, pluginChild);
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
export { Web3AuthProvider };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { EVM_PLUGINS, CONNECTOR_STATUS, PLUGIN_EVENTS } from '@web3auth/no-modal';
|
|
2
|
+
import { createContext, useContext, useState, useEffect, useMemo, createElement } from 'react';
|
|
3
|
+
|
|
4
|
+
const WalletServicesContext = /*#__PURE__*/createContext(null);
|
|
5
|
+
function WalletServicesContextProvider({
|
|
6
|
+
children,
|
|
7
|
+
context
|
|
8
|
+
}) {
|
|
9
|
+
const web3AuthContext = useContext(context);
|
|
10
|
+
const {
|
|
11
|
+
getPlugin,
|
|
12
|
+
isInitialized,
|
|
13
|
+
isConnected
|
|
14
|
+
} = web3AuthContext;
|
|
15
|
+
const [ready, setReady] = useState(false);
|
|
16
|
+
const [connecting, setConnecting] = useState(false);
|
|
17
|
+
const [walletServicesPlugin, setWalletServicesPlugin] = useState(null);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (isInitialized) {
|
|
20
|
+
const plugin = getPlugin(EVM_PLUGINS.WALLET_SERVICES);
|
|
21
|
+
setWalletServicesPlugin(plugin);
|
|
22
|
+
}
|
|
23
|
+
}, [isInitialized, getPlugin]);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (isConnected) {
|
|
26
|
+
const plugin = getPlugin(EVM_PLUGINS.WALLET_SERVICES);
|
|
27
|
+
setWalletServicesPlugin(plugin);
|
|
28
|
+
// when rehydrating, the connectedListener may be registered after the connected event is emitted, we need to check the status here
|
|
29
|
+
if ((plugin === null || plugin === void 0 ? void 0 : plugin.status) === CONNECTOR_STATUS.CONNECTED) setReady(true);
|
|
30
|
+
}
|
|
31
|
+
}, [isConnected, getPlugin, walletServicesPlugin]);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const connectedListener = () => {
|
|
34
|
+
setReady(true);
|
|
35
|
+
setConnecting(false);
|
|
36
|
+
};
|
|
37
|
+
const disconnectedListener = () => {
|
|
38
|
+
setReady(false);
|
|
39
|
+
setConnecting(false);
|
|
40
|
+
};
|
|
41
|
+
const connectingListener = () => {
|
|
42
|
+
setConnecting(true);
|
|
43
|
+
};
|
|
44
|
+
if (walletServicesPlugin) {
|
|
45
|
+
walletServicesPlugin.on(PLUGIN_EVENTS.CONNECTED, connectedListener);
|
|
46
|
+
walletServicesPlugin.on(PLUGIN_EVENTS.DISCONNECTED, disconnectedListener);
|
|
47
|
+
walletServicesPlugin.on(PLUGIN_EVENTS.CONNECTING, connectingListener);
|
|
48
|
+
}
|
|
49
|
+
return () => {
|
|
50
|
+
if (walletServicesPlugin) {
|
|
51
|
+
walletServicesPlugin.off(PLUGIN_EVENTS.CONNECTED, connectedListener);
|
|
52
|
+
walletServicesPlugin.off(PLUGIN_EVENTS.DISCONNECTED, disconnectedListener);
|
|
53
|
+
walletServicesPlugin.off(PLUGIN_EVENTS.CONNECTING, connectingListener);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}, [walletServicesPlugin]);
|
|
57
|
+
const value = useMemo(() => {
|
|
58
|
+
return {
|
|
59
|
+
plugin: walletServicesPlugin,
|
|
60
|
+
ready,
|
|
61
|
+
connecting
|
|
62
|
+
};
|
|
63
|
+
}, [walletServicesPlugin, ready, connecting]);
|
|
64
|
+
return /*#__PURE__*/createElement(WalletServicesContext.Provider, {
|
|
65
|
+
value
|
|
66
|
+
}, children);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { WalletServicesContext, WalletServicesContextProvider };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WalletInitializationError,
|
|
1
|
+
import { WalletInitializationError, CONNECTOR_EVENTS, CONNECTOR_STATUS } from '@web3auth/no-modal';
|
|
2
2
|
import { createContext, useState, useCallback, useEffect, useMemo, createElement } from 'react';
|
|
3
3
|
import { Web3Auth } from '../../modalManager.js';
|
|
4
4
|
|
|
@@ -9,67 +9,20 @@ function Web3AuthInnerProvider(params) {
|
|
|
9
9
|
config
|
|
10
10
|
} = params;
|
|
11
11
|
const [web3Auth, setWeb3Auth] = useState(null);
|
|
12
|
-
const [isConnecting, setIsConnecting] = useState(false);
|
|
13
12
|
const [isInitializing, setIsInitializing] = useState(false);
|
|
14
13
|
const [initError, setInitError] = useState(null);
|
|
15
|
-
const [connectError, setConnectError] = useState(null);
|
|
16
14
|
const [isConnected, setIsConnected] = useState(false);
|
|
17
15
|
const [provider, setProvider] = useState(null);
|
|
18
|
-
const [userInfo, setUserInfo] = useState(null);
|
|
19
|
-
const [isMFAEnabled, setIsMFAEnabled] = useState(false);
|
|
20
16
|
const [isInitialized, setIsInitialized] = useState(false);
|
|
21
17
|
const [status, setStatus] = useState(null);
|
|
18
|
+
const [isMFAEnabled, setIsMFAEnabled] = useState(false);
|
|
22
19
|
const getPlugin = useCallback(name => {
|
|
23
20
|
if (!web3Auth) throw WalletInitializationError.notReady();
|
|
24
21
|
return web3Auth.getPlugin(name);
|
|
25
22
|
}, [web3Auth]);
|
|
26
|
-
const enableMFA = useCallback(async loginParams => {
|
|
27
|
-
if (!web3Auth) throw WalletInitializationError.notReady();
|
|
28
|
-
if (!isConnected) throw WalletLoginError.notConnectedError();
|
|
29
|
-
await web3Auth.enableMFA(loginParams);
|
|
30
|
-
const localUserInfo = await web3Auth.getUserInfo();
|
|
31
|
-
setUserInfo(localUserInfo);
|
|
32
|
-
setIsMFAEnabled(localUserInfo.isMfaEnabled || false);
|
|
33
|
-
}, [web3Auth, isConnected]);
|
|
34
|
-
const manageMFA = useCallback(async loginParams => {
|
|
35
|
-
if (!web3Auth) throw WalletInitializationError.notReady();
|
|
36
|
-
if (!isConnected) throw WalletLoginError.notConnectedError();
|
|
37
|
-
await web3Auth.manageMFA(loginParams);
|
|
38
|
-
}, [web3Auth, isConnected]);
|
|
39
|
-
const logout = useCallback(async (logoutParams = {
|
|
40
|
-
cleanup: false
|
|
41
|
-
}) => {
|
|
42
|
-
if (!web3Auth) throw WalletInitializationError.notReady();
|
|
43
|
-
if (!isConnected) throw WalletLoginError.notConnectedError();
|
|
44
|
-
await web3Auth.logout(logoutParams);
|
|
45
|
-
}, [web3Auth, isConnected]);
|
|
46
|
-
const connect = useCallback(async () => {
|
|
47
|
-
if (!web3Auth) throw WalletInitializationError.notReady();
|
|
48
|
-
try {
|
|
49
|
-
setConnectError(null);
|
|
50
|
-
setIsConnecting(true);
|
|
51
|
-
const localProvider = await web3Auth.connect();
|
|
52
|
-
return localProvider;
|
|
53
|
-
} catch (error) {
|
|
54
|
-
setConnectError(error);
|
|
55
|
-
throw error;
|
|
56
|
-
} finally {
|
|
57
|
-
setIsConnecting(false);
|
|
58
|
-
}
|
|
59
|
-
}, [web3Auth]);
|
|
60
|
-
const authenticateUser = useCallback(async () => {
|
|
61
|
-
if (!web3Auth) throw WalletInitializationError.notReady();
|
|
62
|
-
return web3Auth.authenticateUser();
|
|
63
|
-
}, [web3Auth]);
|
|
64
|
-
const switchChain = useCallback(chainParams => {
|
|
65
|
-
if (!web3Auth) throw WalletInitializationError.notReady();
|
|
66
|
-
return web3Auth.switchChain(chainParams);
|
|
67
|
-
}, [web3Auth]);
|
|
68
23
|
useEffect(() => {
|
|
69
24
|
const resetHookState = () => {
|
|
70
25
|
setProvider(null);
|
|
71
|
-
setUserInfo(null);
|
|
72
|
-
setIsMFAEnabled(false);
|
|
73
26
|
setIsConnected(false);
|
|
74
27
|
setStatus(null);
|
|
75
28
|
};
|
|
@@ -81,11 +34,14 @@ function Web3AuthInnerProvider(params) {
|
|
|
81
34
|
setWeb3Auth(web3AuthInstance);
|
|
82
35
|
}, [config]);
|
|
83
36
|
useEffect(() => {
|
|
37
|
+
const controller = new AbortController();
|
|
84
38
|
async function init() {
|
|
85
39
|
try {
|
|
86
40
|
setInitError(null);
|
|
87
41
|
setIsInitializing(true);
|
|
88
|
-
await web3Auth.initModal(
|
|
42
|
+
await web3Auth.initModal({
|
|
43
|
+
signal: controller.signal
|
|
44
|
+
});
|
|
89
45
|
} catch (error) {
|
|
90
46
|
setInitError(error);
|
|
91
47
|
} finally {
|
|
@@ -93,40 +49,29 @@ function Web3AuthInnerProvider(params) {
|
|
|
93
49
|
}
|
|
94
50
|
}
|
|
95
51
|
if (web3Auth) init();
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const addState = async () => {
|
|
99
|
-
setProvider(web3Auth.provider);
|
|
100
|
-
const userState = await web3Auth.getUserInfo();
|
|
101
|
-
setUserInfo(userState);
|
|
102
|
-
setIsMFAEnabled((userState === null || userState === void 0 ? void 0 : userState.isMfaEnabled) || false);
|
|
103
|
-
};
|
|
104
|
-
const resetState = () => {
|
|
105
|
-
setProvider(null);
|
|
106
|
-
setUserInfo(null);
|
|
107
|
-
setIsMFAEnabled(false);
|
|
52
|
+
return () => {
|
|
53
|
+
controller.abort();
|
|
108
54
|
};
|
|
109
|
-
|
|
110
|
-
if (isConnected) addState();else resetState();
|
|
111
|
-
}
|
|
112
|
-
}, [web3Auth, isConnected]);
|
|
55
|
+
}, [web3Auth, config]);
|
|
113
56
|
useEffect(() => {
|
|
114
57
|
const notReadyListener = () => setStatus(web3Auth.status);
|
|
115
58
|
const readyListener = () => {
|
|
116
59
|
setStatus(web3Auth.status);
|
|
117
60
|
setIsInitialized(true);
|
|
118
61
|
};
|
|
119
|
-
const connectedListener =
|
|
62
|
+
const connectedListener = data => {
|
|
120
63
|
setStatus(web3Auth.status);
|
|
121
64
|
// we do this because of rehydration issues. status connected is fired first but web3auth sdk is not ready yet.
|
|
122
65
|
if (web3Auth.status === CONNECTOR_STATUS.CONNECTED) {
|
|
123
66
|
setIsInitialized(true);
|
|
124
67
|
setIsConnected(true);
|
|
68
|
+
setProvider(data.provider);
|
|
125
69
|
}
|
|
126
70
|
};
|
|
127
71
|
const disconnectedListener = () => {
|
|
128
72
|
setStatus(web3Auth.status);
|
|
129
73
|
setIsConnected(false);
|
|
74
|
+
setProvider(null);
|
|
130
75
|
};
|
|
131
76
|
const connectingListener = () => {
|
|
132
77
|
setStatus(web3Auth.status);
|
|
@@ -134,6 +79,9 @@ function Web3AuthInnerProvider(params) {
|
|
|
134
79
|
const errorListener = () => {
|
|
135
80
|
setStatus(CONNECTOR_STATUS.ERRORED);
|
|
136
81
|
};
|
|
82
|
+
const mfaEnabledListener = isMFAEnabled => {
|
|
83
|
+
if (typeof isMFAEnabled === "boolean") setIsMFAEnabled(isMFAEnabled);
|
|
84
|
+
};
|
|
137
85
|
if (web3Auth) {
|
|
138
86
|
// web3Auth is initialized here.
|
|
139
87
|
setStatus(web3Auth.status);
|
|
@@ -143,6 +91,7 @@ function Web3AuthInnerProvider(params) {
|
|
|
143
91
|
web3Auth.on(CONNECTOR_EVENTS.DISCONNECTED, disconnectedListener);
|
|
144
92
|
web3Auth.on(CONNECTOR_EVENTS.CONNECTING, connectingListener);
|
|
145
93
|
web3Auth.on(CONNECTOR_EVENTS.ERRORED, errorListener);
|
|
94
|
+
web3Auth.on(CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
146
95
|
}
|
|
147
96
|
return () => {
|
|
148
97
|
if (web3Auth) {
|
|
@@ -152,6 +101,8 @@ function Web3AuthInnerProvider(params) {
|
|
|
152
101
|
web3Auth.off(CONNECTOR_EVENTS.DISCONNECTED, disconnectedListener);
|
|
153
102
|
web3Auth.off(CONNECTOR_EVENTS.CONNECTING, connectingListener);
|
|
154
103
|
web3Auth.off(CONNECTOR_EVENTS.ERRORED, errorListener);
|
|
104
|
+
web3Auth.off(CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
105
|
+
web3Auth.cleanup();
|
|
155
106
|
}
|
|
156
107
|
};
|
|
157
108
|
}, [web3Auth]);
|
|
@@ -161,22 +112,14 @@ function Web3AuthInnerProvider(params) {
|
|
|
161
112
|
isConnected,
|
|
162
113
|
isInitialized,
|
|
163
114
|
provider,
|
|
164
|
-
userInfo,
|
|
165
|
-
isMFAEnabled,
|
|
166
115
|
status,
|
|
167
|
-
connect,
|
|
168
|
-
enableMFA,
|
|
169
|
-
manageMFA,
|
|
170
|
-
logout,
|
|
171
|
-
authenticateUser,
|
|
172
|
-
switchChain,
|
|
173
|
-
getPlugin,
|
|
174
116
|
isInitializing,
|
|
175
|
-
isConnecting,
|
|
176
117
|
initError,
|
|
177
|
-
|
|
118
|
+
isMFAEnabled,
|
|
119
|
+
getPlugin,
|
|
120
|
+
setIsMFAEnabled
|
|
178
121
|
};
|
|
179
|
-
}, [web3Auth, isConnected,
|
|
122
|
+
}, [web3Auth, isConnected, isMFAEnabled, setIsMFAEnabled, isInitialized, provider, status, getPlugin, isInitializing, initError]);
|
|
180
123
|
return /*#__PURE__*/createElement(Web3AuthInnerContext.Provider, {
|
|
181
124
|
value
|
|
182
125
|
}, children);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WalletServicesPluginError } from '@web3auth/no-modal';
|
|
2
|
+
import { useState, useCallback } from 'react';
|
|
3
|
+
import { useWalletServicesPlugin } from './useWalletServicesPlugin.js';
|
|
4
|
+
|
|
5
|
+
const useCheckout = () => {
|
|
6
|
+
const {
|
|
7
|
+
plugin,
|
|
8
|
+
ready
|
|
9
|
+
} = useWalletServicesPlugin();
|
|
10
|
+
const [loading, setLoading] = useState(false);
|
|
11
|
+
const [error, setError] = useState(null);
|
|
12
|
+
const showCheckout = useCallback(async showCheckoutParams => {
|
|
13
|
+
setLoading(true);
|
|
14
|
+
setError(null);
|
|
15
|
+
try {
|
|
16
|
+
if (!plugin) throw WalletServicesPluginError.notInitialized();
|
|
17
|
+
if (!ready) throw WalletServicesPluginError.walletPluginNotConnected();
|
|
18
|
+
await plugin.showCheckout(showCheckoutParams);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
setError(error);
|
|
21
|
+
} finally {
|
|
22
|
+
setLoading(false);
|
|
23
|
+
}
|
|
24
|
+
}, [plugin, ready]);
|
|
25
|
+
return {
|
|
26
|
+
loading,
|
|
27
|
+
error,
|
|
28
|
+
showCheckout
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { useCheckout };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
import { useWeb3AuthInner } from './useWeb3AuthInner.js';
|
|
3
|
+
|
|
4
|
+
const useEnableMFA = () => {
|
|
5
|
+
const {
|
|
6
|
+
web3Auth
|
|
7
|
+
} = useWeb3AuthInner();
|
|
8
|
+
const [loading, setLoading] = useState(false);
|
|
9
|
+
const [error, setError] = useState(null);
|
|
10
|
+
const enableMFA = useCallback(async params => {
|
|
11
|
+
setLoading(true);
|
|
12
|
+
setError(null);
|
|
13
|
+
try {
|
|
14
|
+
await web3Auth.enableMFA(params);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
setError(error);
|
|
17
|
+
} finally {
|
|
18
|
+
setLoading(false);
|
|
19
|
+
}
|
|
20
|
+
}, [web3Auth]);
|
|
21
|
+
return {
|
|
22
|
+
loading,
|
|
23
|
+
error,
|
|
24
|
+
enableMFA
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { useEnableMFA };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import { useWeb3AuthInner } from './useWeb3AuthInner.js';
|
|
3
|
+
|
|
4
|
+
const useIdentityToken = () => {
|
|
5
|
+
const {
|
|
6
|
+
web3Auth,
|
|
7
|
+
isConnected
|
|
8
|
+
} = useWeb3AuthInner();
|
|
9
|
+
const [loading, setLoading] = useState(false);
|
|
10
|
+
const [error, setError] = useState(null);
|
|
11
|
+
const [token, setToken] = useState(null);
|
|
12
|
+
const authenticateUser = useCallback(async () => {
|
|
13
|
+
setLoading(true);
|
|
14
|
+
setError(null);
|
|
15
|
+
try {
|
|
16
|
+
const userAuthInfo = await web3Auth.authenticateUser();
|
|
17
|
+
if (userAuthInfo !== null && userAuthInfo !== void 0 && userAuthInfo.idToken) {
|
|
18
|
+
setToken(userAuthInfo.idToken);
|
|
19
|
+
}
|
|
20
|
+
return userAuthInfo === null || userAuthInfo === void 0 ? void 0 : userAuthInfo.idToken;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
setError(error);
|
|
23
|
+
} finally {
|
|
24
|
+
setLoading(false);
|
|
25
|
+
}
|
|
26
|
+
}, [web3Auth]);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (!isConnected && token) {
|
|
29
|
+
setToken(null);
|
|
30
|
+
}
|
|
31
|
+
}, [isConnected, token]);
|
|
32
|
+
return {
|
|
33
|
+
loading,
|
|
34
|
+
error,
|
|
35
|
+
token,
|
|
36
|
+
authenticateUser
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { useIdentityToken };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
import { useWeb3AuthInner } from './useWeb3AuthInner.js';
|
|
3
|
+
|
|
4
|
+
const useManageMFA = () => {
|
|
5
|
+
const {
|
|
6
|
+
web3Auth
|
|
7
|
+
} = useWeb3AuthInner();
|
|
8
|
+
const [loading, setLoading] = useState(false);
|
|
9
|
+
const [error, setError] = useState(null);
|
|
10
|
+
const manageMFA = useCallback(async params => {
|
|
11
|
+
setLoading(true);
|
|
12
|
+
setError(null);
|
|
13
|
+
try {
|
|
14
|
+
await web3Auth.manageMFA(params);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
setError(error);
|
|
17
|
+
} finally {
|
|
18
|
+
setLoading(false);
|
|
19
|
+
}
|
|
20
|
+
}, [web3Auth]);
|
|
21
|
+
return {
|
|
22
|
+
loading,
|
|
23
|
+
error,
|
|
24
|
+
manageMFA
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { useManageMFA };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WalletServicesPluginError } from '@web3auth/no-modal';
|
|
2
|
+
import { useState, useCallback } from 'react';
|
|
3
|
+
import { useWalletServicesPlugin } from './useWalletServicesPlugin.js';
|
|
4
|
+
|
|
5
|
+
const useSwap = () => {
|
|
6
|
+
const {
|
|
7
|
+
plugin,
|
|
8
|
+
ready
|
|
9
|
+
} = useWalletServicesPlugin();
|
|
10
|
+
const [loading, setLoading] = useState(false);
|
|
11
|
+
const [error, setError] = useState(null);
|
|
12
|
+
const showSwap = useCallback(async showSwapParams => {
|
|
13
|
+
setLoading(true);
|
|
14
|
+
setError(null);
|
|
15
|
+
try {
|
|
16
|
+
if (!plugin) throw WalletServicesPluginError.notInitialized();
|
|
17
|
+
if (!ready) throw WalletServicesPluginError.walletPluginNotConnected();
|
|
18
|
+
await plugin.showSwap(showSwapParams);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
setError(error);
|
|
21
|
+
} finally {
|
|
22
|
+
setLoading(false);
|
|
23
|
+
}
|
|
24
|
+
}, [plugin, ready]);
|
|
25
|
+
return {
|
|
26
|
+
loading,
|
|
27
|
+
error,
|
|
28
|
+
showSwap
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { useSwap };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
import { useWeb3AuthInner } from './useWeb3AuthInner.js';
|
|
3
|
+
|
|
4
|
+
const useSwitchChain = () => {
|
|
5
|
+
const {
|
|
6
|
+
web3Auth
|
|
7
|
+
} = useWeb3AuthInner();
|
|
8
|
+
const [loading, setLoading] = useState(false);
|
|
9
|
+
const [error, setError] = useState(null);
|
|
10
|
+
const switchChain = useCallback(async chainId => {
|
|
11
|
+
setLoading(true);
|
|
12
|
+
setError(null);
|
|
13
|
+
try {
|
|
14
|
+
await web3Auth.switchChain({
|
|
15
|
+
chainId
|
|
16
|
+
});
|
|
17
|
+
} catch (error) {
|
|
18
|
+
setError(error);
|
|
19
|
+
} finally {
|
|
20
|
+
setLoading(false);
|
|
21
|
+
}
|
|
22
|
+
}, [web3Auth]);
|
|
23
|
+
return {
|
|
24
|
+
loading,
|
|
25
|
+
error,
|
|
26
|
+
switchChain
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { useSwitchChain };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WalletServicesPluginError } from '@web3auth/no-modal';
|
|
2
|
+
import { useState, useCallback } from 'react';
|
|
3
|
+
import { useWalletServicesPlugin } from './useWalletServicesPlugin.js';
|
|
4
|
+
|
|
5
|
+
const useWalletConnectScanner = () => {
|
|
6
|
+
const {
|
|
7
|
+
plugin,
|
|
8
|
+
ready
|
|
9
|
+
} = useWalletServicesPlugin();
|
|
10
|
+
const [loading, setLoading] = useState(false);
|
|
11
|
+
const [error, setError] = useState(null);
|
|
12
|
+
const showWalletConnectScanner = useCallback(async showWalletConnectScannerParams => {
|
|
13
|
+
setLoading(true);
|
|
14
|
+
setError(null);
|
|
15
|
+
try {
|
|
16
|
+
if (!plugin) throw WalletServicesPluginError.notInitialized();
|
|
17
|
+
if (!ready) throw WalletServicesPluginError.walletPluginNotConnected();
|
|
18
|
+
await plugin.showWalletConnectScanner(showWalletConnectScannerParams);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
setError(error);
|
|
21
|
+
} finally {
|
|
22
|
+
setLoading(false);
|
|
23
|
+
}
|
|
24
|
+
}, [plugin, ready]);
|
|
25
|
+
return {
|
|
26
|
+
loading,
|
|
27
|
+
error,
|
|
28
|
+
showWalletConnectScanner
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { useWalletConnectScanner };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { WalletServicesContext } from '../context/WalletServicesInnerContext.js';
|
|
3
|
+
|
|
4
|
+
const useWalletServicesPlugin = () => {
|
|
5
|
+
const context = useContext(WalletServicesContext);
|
|
6
|
+
if (!context) throw new Error("WalletServicesContext not found");
|
|
7
|
+
return context;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { useWalletServicesPlugin };
|