@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
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
var noModal = require('@web3auth/no-modal');
|
|
4
4
|
|
|
5
|
+
const version = "10.0.0-beta.4";
|
|
5
6
|
const defaultConnectorsModalConfig = {
|
|
6
7
|
hideWalletDiscovery: false,
|
|
7
8
|
connectors: {
|
|
8
9
|
[noModal.EVM_CONNECTORS.AUTH]: {
|
|
9
10
|
label: "Auth",
|
|
10
|
-
showOnModal: true
|
|
11
|
-
showOnMobile: true,
|
|
12
|
-
showOnDesktop: true
|
|
11
|
+
showOnModal: true
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
};
|
|
16
15
|
const walletRegistryUrl = "https://assets.web3auth.io/v1/wallet-registry.json";
|
|
17
16
|
|
|
18
17
|
exports.defaultConnectorsModalConfig = defaultConnectorsModalConfig;
|
|
18
|
+
exports.version = version;
|
|
19
19
|
exports.walletRegistryUrl = walletRegistryUrl;
|
|
@@ -7,6 +7,7 @@ var noModal = require('@web3auth/no-modal');
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
exports.defaultConnectorsModalConfig = config.defaultConnectorsModalConfig;
|
|
10
|
+
exports.version = config.version;
|
|
10
11
|
exports.walletRegistryUrl = config.walletRegistryUrl;
|
|
11
12
|
exports.Web3Auth = modalManager.Web3Auth;
|
|
12
13
|
Object.keys(noModal).forEach(function (k) {
|
|
@@ -26,7 +26,7 @@ class Web3Auth extends noModal.Web3AuthNoModal {
|
|
|
26
26
|
});
|
|
27
27
|
_defineProperty(this, "onSocialLogin", async params => {
|
|
28
28
|
try {
|
|
29
|
-
await this.connectTo(
|
|
29
|
+
await this.connectTo(noModal.WALLET_CONNECTORS.AUTH, params.loginParams);
|
|
30
30
|
} catch (error) {
|
|
31
31
|
noModal.log.error(`Error while connecting to connector: ${params.connector}`, error);
|
|
32
32
|
}
|
|
@@ -72,18 +72,18 @@ class Web3Auth extends noModal.Web3AuthNoModal {
|
|
|
72
72
|
if (this.options.modalConfig) this.modalConfig = this.options.modalConfig;
|
|
73
73
|
noModal.log.info("modalConfig", this.modalConfig);
|
|
74
74
|
}
|
|
75
|
-
async initModal() {
|
|
75
|
+
async initModal(options) {
|
|
76
|
+
const {
|
|
77
|
+
signal
|
|
78
|
+
} = options || {};
|
|
76
79
|
super.checkInitRequirements();
|
|
77
80
|
// get project config and wallet registry
|
|
78
81
|
const {
|
|
79
82
|
projectConfig,
|
|
80
83
|
walletRegistry
|
|
81
84
|
} = await this.getProjectAndWalletConfig();
|
|
82
|
-
this.options.uiConfig = deepmerge(noModal.cloneDeep(projectConfig.whitelabel || {}), this.options.uiConfig || {});
|
|
83
|
-
if (!this.options.uiConfig.defaultLanguage) this.options.uiConfig.defaultLanguage = utils.getUserLanguage(this.options.uiConfig.defaultLanguage);
|
|
84
|
-
if (!this.options.uiConfig.mode) this.options.uiConfig.mode = "light";
|
|
85
|
-
this.options.uiConfig = deepmerge(projectConfig.loginModal || {}, this.options.uiConfig || {});
|
|
86
85
|
// init config
|
|
86
|
+
this.initUIConfig(projectConfig);
|
|
87
87
|
super.initAccountAbstractionConfig(projectConfig);
|
|
88
88
|
super.initChainsConfig(projectConfig);
|
|
89
89
|
super.initCachedConnectorAndChainId();
|
|
@@ -96,6 +96,7 @@ class Web3Auth extends noModal.Web3AuthNoModal {
|
|
|
96
96
|
connectorListener: this,
|
|
97
97
|
web3authClientId: this.options.clientId,
|
|
98
98
|
web3authNetwork: this.options.web3AuthNetwork,
|
|
99
|
+
authBuildEnv: this.options.authBuildEnv,
|
|
99
100
|
chainNamespaces: this.getChainNamespaces(),
|
|
100
101
|
walletRegistry: filteredWalletRegistry
|
|
101
102
|
}), {
|
|
@@ -104,22 +105,31 @@ class Web3Auth extends noModal.Web3AuthNoModal {
|
|
|
104
105
|
onExternalWalletLogin: this.onExternalWalletLogin,
|
|
105
106
|
onModalVisibility: this.onModalVisibility
|
|
106
107
|
});
|
|
107
|
-
await this.loginModal.initModal();
|
|
108
|
+
await noModal.withAbort(() => this.loginModal.initModal(), signal);
|
|
108
109
|
// setup common JRPC provider
|
|
109
|
-
await this.setupCommonJRPCProvider();
|
|
110
|
+
await noModal.withAbort(() => this.setupCommonJRPCProvider(), signal);
|
|
110
111
|
// initialize connectors
|
|
111
112
|
this.on(noModal.CONNECTOR_EVENTS.CONNECTORS_UPDATED, ({
|
|
112
113
|
connectors: newConnectors
|
|
113
|
-
}) =>
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
114
|
+
}) => {
|
|
115
|
+
const onAbortHandler = () => {
|
|
116
|
+
var _this$connectors;
|
|
117
|
+
noModal.log.debug("init aborted");
|
|
118
|
+
if (((_this$connectors = this.connectors) === null || _this$connectors === void 0 ? void 0 : _this$connectors.length) > 0) {
|
|
119
|
+
super.cleanup();
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
noModal.withAbort(() => this.initConnectors({
|
|
123
|
+
connectors: newConnectors,
|
|
124
|
+
projectConfig,
|
|
125
|
+
disabledExternalWallets
|
|
126
|
+
}), signal, onAbortHandler);
|
|
120
127
|
});
|
|
128
|
+
await noModal.withAbort(() => super.loadConnectors({
|
|
129
|
+
projectConfig
|
|
130
|
+
}), signal);
|
|
121
131
|
// initialize plugins
|
|
122
|
-
await
|
|
132
|
+
await noModal.withAbort(() => super.initPlugins(), signal);
|
|
123
133
|
}
|
|
124
134
|
async connect() {
|
|
125
135
|
if (!this.loginModal) throw noModal.WalletInitializationError.notReady("Login modal is not initialized");
|
|
@@ -213,6 +223,23 @@ class Web3Auth extends noModal.Web3AuthNoModal {
|
|
|
213
223
|
walletRegistry
|
|
214
224
|
};
|
|
215
225
|
}
|
|
226
|
+
initUIConfig(projectConfig) {
|
|
227
|
+
this.options.uiConfig = deepmerge(noModal.cloneDeep(projectConfig.whitelabel || {}), this.options.uiConfig || {});
|
|
228
|
+
if (!this.options.uiConfig.defaultLanguage) this.options.uiConfig.defaultLanguage = utils.getUserLanguage(this.options.uiConfig.defaultLanguage);
|
|
229
|
+
if (!this.options.uiConfig.mode) this.options.uiConfig.mode = "light";
|
|
230
|
+
this.options.uiConfig = deepmerge(projectConfig.loginModal || {}, this.options.uiConfig);
|
|
231
|
+
// merge login methods order from project config and user config, with user config taking precedence
|
|
232
|
+
const defaultAuthConnections = projectConfig.embeddedWalletAuth.filter(x => x.isDefault).map(x => x.authConnection);
|
|
233
|
+
const mergedAuthConnections = [...(this.options.uiConfig.loginMethodsOrder || []), ...defaultAuthConnections];
|
|
234
|
+
const loginMethodsOrder = [];
|
|
235
|
+
const authConnectionSet = new Set();
|
|
236
|
+
for (const authConnection of mergedAuthConnections) {
|
|
237
|
+
if (authConnectionSet.has(authConnection)) continue;
|
|
238
|
+
authConnectionSet.add(authConnection);
|
|
239
|
+
loginMethodsOrder.push(authConnection);
|
|
240
|
+
}
|
|
241
|
+
this.options.uiConfig.loginMethodsOrder = loginMethodsOrder;
|
|
242
|
+
}
|
|
216
243
|
async initConnectors({
|
|
217
244
|
connectors,
|
|
218
245
|
projectConfig,
|
|
@@ -280,9 +307,7 @@ class Web3Auth extends noModal.Web3AuthNoModal {
|
|
|
280
307
|
groupedAuthConnectionId: groupedAuthConnectionId,
|
|
281
308
|
extraLoginOptions: authConnectionConfig.jwtParameters,
|
|
282
309
|
isDefault: true,
|
|
283
|
-
showOnModal: true
|
|
284
|
-
showOnDesktop: true,
|
|
285
|
-
showOnMobile: true
|
|
310
|
+
showOnModal: true
|
|
286
311
|
};
|
|
287
312
|
}
|
|
288
313
|
embedWalletConfigMap.set(groupedAuthConnectionId || authConnectionId, authConnectionConfig);
|
|
@@ -328,9 +353,7 @@ class Web3Auth extends noModal.Web3AuthNoModal {
|
|
|
328
353
|
// start with the default config of connector.
|
|
329
354
|
const defaultConnectorConfig = {
|
|
330
355
|
label: noModal.CONNECTOR_NAMES[connectorName] || connectorName.split("-").map(config$1.capitalizeFirstLetter).join(" "),
|
|
331
|
-
showOnModal: true
|
|
332
|
-
showOnMobile: true,
|
|
333
|
-
showOnDesktop: true
|
|
356
|
+
showOnModal: true
|
|
334
357
|
};
|
|
335
358
|
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]) || {});
|
|
336
359
|
// check if connector is configured/added by user and exist in connectors map.
|
|
@@ -378,7 +401,7 @@ class Web3Auth extends noModal.Web3AuthNoModal {
|
|
|
378
401
|
const hasExternalConnectors = connectorNames.some(connectorName => {
|
|
379
402
|
var _this$getConnector, _this$modalConfig$con5;
|
|
380
403
|
if (connectorName === noModal.WALLET_CONNECTORS.WALLET_CONNECT_V2) return true;
|
|
381
|
-
return ((_this$getConnector = this.getConnector(connectorName)) === null || _this$getConnector === void 0 ? void 0 : _this$getConnector.type) === noModal.CONNECTOR_CATEGORY.EXTERNAL && ((_this$modalConfig$con5 = this.modalConfig.connectors) === null || _this$modalConfig$con5 === void 0 ? void 0 : _this$modalConfig$con5
|
|
404
|
+
return ((_this$getConnector = this.getConnector(connectorName)) === null || _this$getConnector === void 0 ? void 0 : _this$getConnector.type) === noModal.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);
|
|
382
405
|
});
|
|
383
406
|
return {
|
|
384
407
|
hasInAppConnectors,
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
|
+
var WalletServicesInnerContext = require('./context/WalletServicesInnerContext.js');
|
|
4
5
|
var Web3AuthInnerContext = require('./context/Web3AuthInnerContext.js');
|
|
5
6
|
|
|
6
7
|
function Web3AuthProvider({
|
|
7
8
|
config,
|
|
8
9
|
children
|
|
9
10
|
}) {
|
|
11
|
+
const pluginChild = /*#__PURE__*/react.createElement(WalletServicesInnerContext.WalletServicesContextProvider, {
|
|
12
|
+
context: Web3AuthInnerContext.Web3AuthInnerContext
|
|
13
|
+
}, children);
|
|
10
14
|
return /*#__PURE__*/react.createElement(Web3AuthInnerContext.Web3AuthInnerProvider, {
|
|
11
15
|
config
|
|
12
|
-
},
|
|
16
|
+
}, pluginChild);
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
exports.Web3AuthProvider = Web3AuthProvider;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var noModal = require('@web3auth/no-modal');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
const WalletServicesContext = /*#__PURE__*/react.createContext(null);
|
|
7
|
+
function WalletServicesContextProvider({
|
|
8
|
+
children,
|
|
9
|
+
context
|
|
10
|
+
}) {
|
|
11
|
+
const web3AuthContext = react.useContext(context);
|
|
12
|
+
const {
|
|
13
|
+
getPlugin,
|
|
14
|
+
isInitialized,
|
|
15
|
+
isConnected
|
|
16
|
+
} = web3AuthContext;
|
|
17
|
+
const [ready, setReady] = react.useState(false);
|
|
18
|
+
const [connecting, setConnecting] = react.useState(false);
|
|
19
|
+
const [walletServicesPlugin, setWalletServicesPlugin] = react.useState(null);
|
|
20
|
+
react.useEffect(() => {
|
|
21
|
+
if (isInitialized) {
|
|
22
|
+
const plugin = getPlugin(noModal.EVM_PLUGINS.WALLET_SERVICES);
|
|
23
|
+
setWalletServicesPlugin(plugin);
|
|
24
|
+
}
|
|
25
|
+
}, [isInitialized, getPlugin]);
|
|
26
|
+
react.useEffect(() => {
|
|
27
|
+
if (isConnected) {
|
|
28
|
+
const plugin = getPlugin(noModal.EVM_PLUGINS.WALLET_SERVICES);
|
|
29
|
+
setWalletServicesPlugin(plugin);
|
|
30
|
+
// when rehydrating, the connectedListener may be registered after the connected event is emitted, we need to check the status here
|
|
31
|
+
if ((plugin === null || plugin === void 0 ? void 0 : plugin.status) === noModal.CONNECTOR_STATUS.CONNECTED) setReady(true);
|
|
32
|
+
}
|
|
33
|
+
}, [isConnected, getPlugin, walletServicesPlugin]);
|
|
34
|
+
react.useEffect(() => {
|
|
35
|
+
const connectedListener = () => {
|
|
36
|
+
setReady(true);
|
|
37
|
+
setConnecting(false);
|
|
38
|
+
};
|
|
39
|
+
const disconnectedListener = () => {
|
|
40
|
+
setReady(false);
|
|
41
|
+
setConnecting(false);
|
|
42
|
+
};
|
|
43
|
+
const connectingListener = () => {
|
|
44
|
+
setConnecting(true);
|
|
45
|
+
};
|
|
46
|
+
if (walletServicesPlugin) {
|
|
47
|
+
walletServicesPlugin.on(noModal.PLUGIN_EVENTS.CONNECTED, connectedListener);
|
|
48
|
+
walletServicesPlugin.on(noModal.PLUGIN_EVENTS.DISCONNECTED, disconnectedListener);
|
|
49
|
+
walletServicesPlugin.on(noModal.PLUGIN_EVENTS.CONNECTING, connectingListener);
|
|
50
|
+
}
|
|
51
|
+
return () => {
|
|
52
|
+
if (walletServicesPlugin) {
|
|
53
|
+
walletServicesPlugin.off(noModal.PLUGIN_EVENTS.CONNECTED, connectedListener);
|
|
54
|
+
walletServicesPlugin.off(noModal.PLUGIN_EVENTS.DISCONNECTED, disconnectedListener);
|
|
55
|
+
walletServicesPlugin.off(noModal.PLUGIN_EVENTS.CONNECTING, connectingListener);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}, [walletServicesPlugin]);
|
|
59
|
+
const value = react.useMemo(() => {
|
|
60
|
+
return {
|
|
61
|
+
plugin: walletServicesPlugin,
|
|
62
|
+
ready,
|
|
63
|
+
connecting
|
|
64
|
+
};
|
|
65
|
+
}, [walletServicesPlugin, ready, connecting]);
|
|
66
|
+
return /*#__PURE__*/react.createElement(WalletServicesContext.Provider, {
|
|
67
|
+
value
|
|
68
|
+
}, children);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
exports.WalletServicesContext = WalletServicesContext;
|
|
72
|
+
exports.WalletServicesContextProvider = WalletServicesContextProvider;
|
|
@@ -11,67 +11,20 @@ function Web3AuthInnerProvider(params) {
|
|
|
11
11
|
config
|
|
12
12
|
} = params;
|
|
13
13
|
const [web3Auth, setWeb3Auth] = react.useState(null);
|
|
14
|
-
const [isConnecting, setIsConnecting] = react.useState(false);
|
|
15
14
|
const [isInitializing, setIsInitializing] = react.useState(false);
|
|
16
15
|
const [initError, setInitError] = react.useState(null);
|
|
17
|
-
const [connectError, setConnectError] = react.useState(null);
|
|
18
16
|
const [isConnected, setIsConnected] = react.useState(false);
|
|
19
17
|
const [provider, setProvider] = react.useState(null);
|
|
20
|
-
const [userInfo, setUserInfo] = react.useState(null);
|
|
21
|
-
const [isMFAEnabled, setIsMFAEnabled] = react.useState(false);
|
|
22
18
|
const [isInitialized, setIsInitialized] = react.useState(false);
|
|
23
19
|
const [status, setStatus] = react.useState(null);
|
|
20
|
+
const [isMFAEnabled, setIsMFAEnabled] = react.useState(false);
|
|
24
21
|
const getPlugin = react.useCallback(name => {
|
|
25
22
|
if (!web3Auth) throw noModal.WalletInitializationError.notReady();
|
|
26
23
|
return web3Auth.getPlugin(name);
|
|
27
24
|
}, [web3Auth]);
|
|
28
|
-
const enableMFA = react.useCallback(async loginParams => {
|
|
29
|
-
if (!web3Auth) throw noModal.WalletInitializationError.notReady();
|
|
30
|
-
if (!isConnected) throw noModal.WalletLoginError.notConnectedError();
|
|
31
|
-
await web3Auth.enableMFA(loginParams);
|
|
32
|
-
const localUserInfo = await web3Auth.getUserInfo();
|
|
33
|
-
setUserInfo(localUserInfo);
|
|
34
|
-
setIsMFAEnabled(localUserInfo.isMfaEnabled || false);
|
|
35
|
-
}, [web3Auth, isConnected]);
|
|
36
|
-
const manageMFA = react.useCallback(async loginParams => {
|
|
37
|
-
if (!web3Auth) throw noModal.WalletInitializationError.notReady();
|
|
38
|
-
if (!isConnected) throw noModal.WalletLoginError.notConnectedError();
|
|
39
|
-
await web3Auth.manageMFA(loginParams);
|
|
40
|
-
}, [web3Auth, isConnected]);
|
|
41
|
-
const logout = react.useCallback(async (logoutParams = {
|
|
42
|
-
cleanup: false
|
|
43
|
-
}) => {
|
|
44
|
-
if (!web3Auth) throw noModal.WalletInitializationError.notReady();
|
|
45
|
-
if (!isConnected) throw noModal.WalletLoginError.notConnectedError();
|
|
46
|
-
await web3Auth.logout(logoutParams);
|
|
47
|
-
}, [web3Auth, isConnected]);
|
|
48
|
-
const connect = react.useCallback(async () => {
|
|
49
|
-
if (!web3Auth) throw noModal.WalletInitializationError.notReady();
|
|
50
|
-
try {
|
|
51
|
-
setConnectError(null);
|
|
52
|
-
setIsConnecting(true);
|
|
53
|
-
const localProvider = await web3Auth.connect();
|
|
54
|
-
return localProvider;
|
|
55
|
-
} catch (error) {
|
|
56
|
-
setConnectError(error);
|
|
57
|
-
throw error;
|
|
58
|
-
} finally {
|
|
59
|
-
setIsConnecting(false);
|
|
60
|
-
}
|
|
61
|
-
}, [web3Auth]);
|
|
62
|
-
const authenticateUser = react.useCallback(async () => {
|
|
63
|
-
if (!web3Auth) throw noModal.WalletInitializationError.notReady();
|
|
64
|
-
return web3Auth.authenticateUser();
|
|
65
|
-
}, [web3Auth]);
|
|
66
|
-
const switchChain = react.useCallback(chainParams => {
|
|
67
|
-
if (!web3Auth) throw noModal.WalletInitializationError.notReady();
|
|
68
|
-
return web3Auth.switchChain(chainParams);
|
|
69
|
-
}, [web3Auth]);
|
|
70
25
|
react.useEffect(() => {
|
|
71
26
|
const resetHookState = () => {
|
|
72
27
|
setProvider(null);
|
|
73
|
-
setUserInfo(null);
|
|
74
|
-
setIsMFAEnabled(false);
|
|
75
28
|
setIsConnected(false);
|
|
76
29
|
setStatus(null);
|
|
77
30
|
};
|
|
@@ -83,11 +36,14 @@ function Web3AuthInnerProvider(params) {
|
|
|
83
36
|
setWeb3Auth(web3AuthInstance);
|
|
84
37
|
}, [config]);
|
|
85
38
|
react.useEffect(() => {
|
|
39
|
+
const controller = new AbortController();
|
|
86
40
|
async function init() {
|
|
87
41
|
try {
|
|
88
42
|
setInitError(null);
|
|
89
43
|
setIsInitializing(true);
|
|
90
|
-
await web3Auth.initModal(
|
|
44
|
+
await web3Auth.initModal({
|
|
45
|
+
signal: controller.signal
|
|
46
|
+
});
|
|
91
47
|
} catch (error) {
|
|
92
48
|
setInitError(error);
|
|
93
49
|
} finally {
|
|
@@ -95,40 +51,29 @@ function Web3AuthInnerProvider(params) {
|
|
|
95
51
|
}
|
|
96
52
|
}
|
|
97
53
|
if (web3Auth) init();
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const addState = async () => {
|
|
101
|
-
setProvider(web3Auth.provider);
|
|
102
|
-
const userState = await web3Auth.getUserInfo();
|
|
103
|
-
setUserInfo(userState);
|
|
104
|
-
setIsMFAEnabled((userState === null || userState === void 0 ? void 0 : userState.isMfaEnabled) || false);
|
|
105
|
-
};
|
|
106
|
-
const resetState = () => {
|
|
107
|
-
setProvider(null);
|
|
108
|
-
setUserInfo(null);
|
|
109
|
-
setIsMFAEnabled(false);
|
|
54
|
+
return () => {
|
|
55
|
+
controller.abort();
|
|
110
56
|
};
|
|
111
|
-
|
|
112
|
-
if (isConnected) addState();else resetState();
|
|
113
|
-
}
|
|
114
|
-
}, [web3Auth, isConnected]);
|
|
57
|
+
}, [web3Auth, config]);
|
|
115
58
|
react.useEffect(() => {
|
|
116
59
|
const notReadyListener = () => setStatus(web3Auth.status);
|
|
117
60
|
const readyListener = () => {
|
|
118
61
|
setStatus(web3Auth.status);
|
|
119
62
|
setIsInitialized(true);
|
|
120
63
|
};
|
|
121
|
-
const connectedListener =
|
|
64
|
+
const connectedListener = data => {
|
|
122
65
|
setStatus(web3Auth.status);
|
|
123
66
|
// we do this because of rehydration issues. status connected is fired first but web3auth sdk is not ready yet.
|
|
124
67
|
if (web3Auth.status === noModal.CONNECTOR_STATUS.CONNECTED) {
|
|
125
68
|
setIsInitialized(true);
|
|
126
69
|
setIsConnected(true);
|
|
70
|
+
setProvider(data.provider);
|
|
127
71
|
}
|
|
128
72
|
};
|
|
129
73
|
const disconnectedListener = () => {
|
|
130
74
|
setStatus(web3Auth.status);
|
|
131
75
|
setIsConnected(false);
|
|
76
|
+
setProvider(null);
|
|
132
77
|
};
|
|
133
78
|
const connectingListener = () => {
|
|
134
79
|
setStatus(web3Auth.status);
|
|
@@ -136,6 +81,9 @@ function Web3AuthInnerProvider(params) {
|
|
|
136
81
|
const errorListener = () => {
|
|
137
82
|
setStatus(noModal.CONNECTOR_STATUS.ERRORED);
|
|
138
83
|
};
|
|
84
|
+
const mfaEnabledListener = isMFAEnabled => {
|
|
85
|
+
if (typeof isMFAEnabled === "boolean") setIsMFAEnabled(isMFAEnabled);
|
|
86
|
+
};
|
|
139
87
|
if (web3Auth) {
|
|
140
88
|
// web3Auth is initialized here.
|
|
141
89
|
setStatus(web3Auth.status);
|
|
@@ -145,6 +93,7 @@ function Web3AuthInnerProvider(params) {
|
|
|
145
93
|
web3Auth.on(noModal.CONNECTOR_EVENTS.DISCONNECTED, disconnectedListener);
|
|
146
94
|
web3Auth.on(noModal.CONNECTOR_EVENTS.CONNECTING, connectingListener);
|
|
147
95
|
web3Auth.on(noModal.CONNECTOR_EVENTS.ERRORED, errorListener);
|
|
96
|
+
web3Auth.on(noModal.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
148
97
|
}
|
|
149
98
|
return () => {
|
|
150
99
|
if (web3Auth) {
|
|
@@ -154,6 +103,8 @@ function Web3AuthInnerProvider(params) {
|
|
|
154
103
|
web3Auth.off(noModal.CONNECTOR_EVENTS.DISCONNECTED, disconnectedListener);
|
|
155
104
|
web3Auth.off(noModal.CONNECTOR_EVENTS.CONNECTING, connectingListener);
|
|
156
105
|
web3Auth.off(noModal.CONNECTOR_EVENTS.ERRORED, errorListener);
|
|
106
|
+
web3Auth.off(noModal.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
107
|
+
web3Auth.cleanup();
|
|
157
108
|
}
|
|
158
109
|
};
|
|
159
110
|
}, [web3Auth]);
|
|
@@ -163,22 +114,14 @@ function Web3AuthInnerProvider(params) {
|
|
|
163
114
|
isConnected,
|
|
164
115
|
isInitialized,
|
|
165
116
|
provider,
|
|
166
|
-
userInfo,
|
|
167
|
-
isMFAEnabled,
|
|
168
117
|
status,
|
|
169
|
-
connect,
|
|
170
|
-
enableMFA,
|
|
171
|
-
manageMFA,
|
|
172
|
-
logout,
|
|
173
|
-
authenticateUser,
|
|
174
|
-
switchChain,
|
|
175
|
-
getPlugin,
|
|
176
118
|
isInitializing,
|
|
177
|
-
isConnecting,
|
|
178
119
|
initError,
|
|
179
|
-
|
|
120
|
+
isMFAEnabled,
|
|
121
|
+
getPlugin,
|
|
122
|
+
setIsMFAEnabled
|
|
180
123
|
};
|
|
181
|
-
}, [web3Auth, isConnected,
|
|
124
|
+
}, [web3Auth, isConnected, isMFAEnabled, setIsMFAEnabled, isInitialized, provider, status, getPlugin, isInitializing, initError]);
|
|
182
125
|
return /*#__PURE__*/react.createElement(Web3AuthInnerContext.Provider, {
|
|
183
126
|
value
|
|
184
127
|
}, children);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var noModal = require('@web3auth/no-modal');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var useWalletServicesPlugin = require('./useWalletServicesPlugin.js');
|
|
6
|
+
|
|
7
|
+
const useCheckout = () => {
|
|
8
|
+
const {
|
|
9
|
+
plugin,
|
|
10
|
+
ready
|
|
11
|
+
} = useWalletServicesPlugin.useWalletServicesPlugin();
|
|
12
|
+
const [loading, setLoading] = react.useState(false);
|
|
13
|
+
const [error, setError] = react.useState(null);
|
|
14
|
+
const showCheckout = react.useCallback(async showCheckoutParams => {
|
|
15
|
+
setLoading(true);
|
|
16
|
+
setError(null);
|
|
17
|
+
try {
|
|
18
|
+
if (!plugin) throw noModal.WalletServicesPluginError.notInitialized();
|
|
19
|
+
if (!ready) throw noModal.WalletServicesPluginError.walletPluginNotConnected();
|
|
20
|
+
await plugin.showCheckout(showCheckoutParams);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
setError(error);
|
|
23
|
+
} finally {
|
|
24
|
+
setLoading(false);
|
|
25
|
+
}
|
|
26
|
+
}, [plugin, ready]);
|
|
27
|
+
return {
|
|
28
|
+
loading,
|
|
29
|
+
error,
|
|
30
|
+
showCheckout
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.useCheckout = useCheckout;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var useWeb3AuthInner = require('./useWeb3AuthInner.js');
|
|
5
|
+
|
|
6
|
+
const useEnableMFA = () => {
|
|
7
|
+
const {
|
|
8
|
+
web3Auth
|
|
9
|
+
} = useWeb3AuthInner.useWeb3AuthInner();
|
|
10
|
+
const [loading, setLoading] = react.useState(false);
|
|
11
|
+
const [error, setError] = react.useState(null);
|
|
12
|
+
const enableMFA = react.useCallback(async params => {
|
|
13
|
+
setLoading(true);
|
|
14
|
+
setError(null);
|
|
15
|
+
try {
|
|
16
|
+
await web3Auth.enableMFA(params);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
setError(error);
|
|
19
|
+
} finally {
|
|
20
|
+
setLoading(false);
|
|
21
|
+
}
|
|
22
|
+
}, [web3Auth]);
|
|
23
|
+
return {
|
|
24
|
+
loading,
|
|
25
|
+
error,
|
|
26
|
+
enableMFA
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.useEnableMFA = useEnableMFA;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var useWeb3AuthInner = require('./useWeb3AuthInner.js');
|
|
5
|
+
|
|
6
|
+
const useIdentityToken = () => {
|
|
7
|
+
const {
|
|
8
|
+
web3Auth,
|
|
9
|
+
isConnected
|
|
10
|
+
} = useWeb3AuthInner.useWeb3AuthInner();
|
|
11
|
+
const [loading, setLoading] = react.useState(false);
|
|
12
|
+
const [error, setError] = react.useState(null);
|
|
13
|
+
const [token, setToken] = react.useState(null);
|
|
14
|
+
const authenticateUser = react.useCallback(async () => {
|
|
15
|
+
setLoading(true);
|
|
16
|
+
setError(null);
|
|
17
|
+
try {
|
|
18
|
+
const userAuthInfo = await web3Auth.authenticateUser();
|
|
19
|
+
if (userAuthInfo !== null && userAuthInfo !== void 0 && userAuthInfo.idToken) {
|
|
20
|
+
setToken(userAuthInfo.idToken);
|
|
21
|
+
}
|
|
22
|
+
return userAuthInfo === null || userAuthInfo === void 0 ? void 0 : userAuthInfo.idToken;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
setError(error);
|
|
25
|
+
} finally {
|
|
26
|
+
setLoading(false);
|
|
27
|
+
}
|
|
28
|
+
}, [web3Auth]);
|
|
29
|
+
react.useEffect(() => {
|
|
30
|
+
if (!isConnected && token) {
|
|
31
|
+
setToken(null);
|
|
32
|
+
}
|
|
33
|
+
}, [isConnected, token]);
|
|
34
|
+
return {
|
|
35
|
+
loading,
|
|
36
|
+
error,
|
|
37
|
+
token,
|
|
38
|
+
authenticateUser
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
exports.useIdentityToken = useIdentityToken;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var useWeb3AuthInner = require('./useWeb3AuthInner.js');
|
|
5
|
+
|
|
6
|
+
const useManageMFA = () => {
|
|
7
|
+
const {
|
|
8
|
+
web3Auth
|
|
9
|
+
} = useWeb3AuthInner.useWeb3AuthInner();
|
|
10
|
+
const [loading, setLoading] = react.useState(false);
|
|
11
|
+
const [error, setError] = react.useState(null);
|
|
12
|
+
const manageMFA = react.useCallback(async params => {
|
|
13
|
+
setLoading(true);
|
|
14
|
+
setError(null);
|
|
15
|
+
try {
|
|
16
|
+
await web3Auth.manageMFA(params);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
setError(error);
|
|
19
|
+
} finally {
|
|
20
|
+
setLoading(false);
|
|
21
|
+
}
|
|
22
|
+
}, [web3Auth]);
|
|
23
|
+
return {
|
|
24
|
+
loading,
|
|
25
|
+
error,
|
|
26
|
+
manageMFA
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.useManageMFA = useManageMFA;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var noModal = require('@web3auth/no-modal');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var useWalletServicesPlugin = require('./useWalletServicesPlugin.js');
|
|
6
|
+
|
|
7
|
+
const useSwap = () => {
|
|
8
|
+
const {
|
|
9
|
+
plugin,
|
|
10
|
+
ready
|
|
11
|
+
} = useWalletServicesPlugin.useWalletServicesPlugin();
|
|
12
|
+
const [loading, setLoading] = react.useState(false);
|
|
13
|
+
const [error, setError] = react.useState(null);
|
|
14
|
+
const showSwap = react.useCallback(async showSwapParams => {
|
|
15
|
+
setLoading(true);
|
|
16
|
+
setError(null);
|
|
17
|
+
try {
|
|
18
|
+
if (!plugin) throw noModal.WalletServicesPluginError.notInitialized();
|
|
19
|
+
if (!ready) throw noModal.WalletServicesPluginError.walletPluginNotConnected();
|
|
20
|
+
await plugin.showSwap(showSwapParams);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
setError(error);
|
|
23
|
+
} finally {
|
|
24
|
+
setLoading(false);
|
|
25
|
+
}
|
|
26
|
+
}, [plugin, ready]);
|
|
27
|
+
return {
|
|
28
|
+
loading,
|
|
29
|
+
error,
|
|
30
|
+
showSwap
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.useSwap = useSwap;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var useWeb3AuthInner = require('./useWeb3AuthInner.js');
|
|
5
|
+
|
|
6
|
+
const useSwitchChain = () => {
|
|
7
|
+
const {
|
|
8
|
+
web3Auth
|
|
9
|
+
} = useWeb3AuthInner.useWeb3AuthInner();
|
|
10
|
+
const [loading, setLoading] = react.useState(false);
|
|
11
|
+
const [error, setError] = react.useState(null);
|
|
12
|
+
const switchChain = react.useCallback(async chainId => {
|
|
13
|
+
setLoading(true);
|
|
14
|
+
setError(null);
|
|
15
|
+
try {
|
|
16
|
+
await web3Auth.switchChain({
|
|
17
|
+
chainId
|
|
18
|
+
});
|
|
19
|
+
} catch (error) {
|
|
20
|
+
setError(error);
|
|
21
|
+
} finally {
|
|
22
|
+
setLoading(false);
|
|
23
|
+
}
|
|
24
|
+
}, [web3Auth]);
|
|
25
|
+
return {
|
|
26
|
+
loading,
|
|
27
|
+
error,
|
|
28
|
+
switchChain
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.useSwitchChain = useSwitchChain;
|