@web3auth/modal 10.0.0-beta.3 → 10.0.0-beta.5
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 +2 -0
- package/dist/lib.cjs/packages/modal/src/index.js +1 -0
- package/dist/lib.cjs/packages/modal/src/modalManager.js +19 -21
- 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 +13 -77
- 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/ConnectWallet/ConnectWallet.js +5 -5
- package/dist/lib.cjs/packages/modal/src/ui/components/Login/Login.js +10 -13
- package/dist/lib.cjs/packages/modal/src/ui/components/Root/Root.js +1 -1
- package/dist/lib.cjs/packages/modal/src/ui/handlers/AbstractHandler.js +4 -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/types/config.d.ts +1 -0
- 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/handlers/AbstractHandler.d.ts +2 -1
- package/dist/lib.cjs/types/ui/handlers/EmailPasswordlessHandler.d.ts +3 -1
- package/dist/lib.cjs/types/ui/interfaces.d.ts +3 -3
- package/dist/lib.esm/packages/modal/src/config.js +2 -1
- package/dist/lib.esm/packages/modal/src/index.js +1 -1
- package/dist/lib.esm/packages/modal/src/modalManager.js +21 -21
- 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 +14 -78
- 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/ConnectWallet/ConnectWallet.js +5 -5
- package/dist/lib.esm/packages/modal/src/ui/components/Login/Login.js +10 -13
- package/dist/lib.esm/packages/modal/src/ui/components/Root/Root.js +1 -1
- package/dist/lib.esm/packages/modal/src/ui/handlers/AbstractHandler.js +2 -0
- 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/modal.umd.min.js +1 -1
- package/package.json +35 -10
- package/dist/lib.cjs/types/react/context/index.d.ts +0 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var noModal = require('@web3auth/no-modal');
|
|
4
4
|
|
|
5
|
+
const version = "10.0.0-beta.5";
|
|
5
6
|
const defaultConnectorsModalConfig = {
|
|
6
7
|
hideWalletDiscovery: false,
|
|
7
8
|
connectors: {
|
|
@@ -14,4 +15,5 @@ const defaultConnectorsModalConfig = {
|
|
|
14
15
|
const walletRegistryUrl = "https://assets.web3auth.io/v1/wallet-registry.json";
|
|
15
16
|
|
|
16
17
|
exports.defaultConnectorsModalConfig = defaultConnectorsModalConfig;
|
|
18
|
+
exports.version = version;
|
|
17
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
|
}
|
|
@@ -190,32 +190,30 @@ class Web3Auth extends noModal.Web3AuthNoModal {
|
|
|
190
190
|
};
|
|
191
191
|
}
|
|
192
192
|
async getProjectAndWalletConfig() {
|
|
193
|
-
var _this$modalConfig;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
} catch (e) {
|
|
205
|
-
noModal.log.error("Failed to fetch project configurations", e);
|
|
206
|
-
throw noModal.WalletInitializationError.notReady("failed to fetch project configurations", e);
|
|
193
|
+
var _this$options$account, _this$modalConfig;
|
|
194
|
+
const [projectConfigResult, walletRegistryResult] = await Promise.allSettled([noModal.fetchProjectConfig({
|
|
195
|
+
clientId: this.options.clientId,
|
|
196
|
+
web3AuthNetwork: this.options.web3AuthNetwork,
|
|
197
|
+
aaProvider: (_this$options$account = this.options.accountAbstractionConfig) === null || _this$options$account === void 0 ? void 0 : _this$options$account.smartAccountType,
|
|
198
|
+
authBuildEnv: this.options.authBuildEnv
|
|
199
|
+
}), noModal.fetchWalletRegistry(config.walletRegistryUrl)]);
|
|
200
|
+
// handle project config result
|
|
201
|
+
if (projectConfigResult.status === "rejected") {
|
|
202
|
+
noModal.log.error("Failed to fetch project configurations", projectConfigResult.reason);
|
|
203
|
+
throw noModal.WalletInitializationError.notReady("failed to fetch project configurations", projectConfigResult.reason);
|
|
207
204
|
}
|
|
208
|
-
|
|
205
|
+
const projectConfig = projectConfigResult.value;
|
|
206
|
+
// handle wallet registry result
|
|
209
207
|
let walletRegistry = {
|
|
210
208
|
others: {},
|
|
211
209
|
default: {}
|
|
212
210
|
};
|
|
213
211
|
const isExternalWalletEnabled = Boolean(projectConfig.externalWalletAuth);
|
|
214
212
|
if (isExternalWalletEnabled && !((_this$modalConfig = this.modalConfig) !== null && _this$modalConfig !== void 0 && _this$modalConfig.hideWalletDiscovery)) {
|
|
215
|
-
|
|
216
|
-
walletRegistry =
|
|
217
|
-
}
|
|
218
|
-
noModal.log.error("Failed to fetch wallet registry",
|
|
213
|
+
if (walletRegistryResult.status === "fulfilled") {
|
|
214
|
+
walletRegistry = walletRegistryResult.value;
|
|
215
|
+
} else {
|
|
216
|
+
noModal.log.error("Failed to fetch wallet registry", walletRegistryResult.reason);
|
|
219
217
|
}
|
|
220
218
|
}
|
|
221
219
|
return {
|
|
@@ -401,7 +399,7 @@ class Web3Auth extends noModal.Web3AuthNoModal {
|
|
|
401
399
|
const hasExternalConnectors = connectorNames.some(connectorName => {
|
|
402
400
|
var _this$getConnector, _this$modalConfig$con5;
|
|
403
401
|
if (connectorName === noModal.WALLET_CONNECTORS.WALLET_CONNECT_V2) return true;
|
|
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 ? void 0 : _this$modalConfig$con5
|
|
402
|
+
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);
|
|
405
403
|
});
|
|
406
404
|
return {
|
|
407
405
|
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
|
};
|
|
@@ -102,39 +55,25 @@ function Web3AuthInnerProvider(params) {
|
|
|
102
55
|
controller.abort();
|
|
103
56
|
};
|
|
104
57
|
}, [web3Auth, config]);
|
|
105
|
-
react.useEffect(() => {
|
|
106
|
-
const addState = async () => {
|
|
107
|
-
setProvider(web3Auth.provider);
|
|
108
|
-
const userState = await web3Auth.getUserInfo();
|
|
109
|
-
setUserInfo(userState);
|
|
110
|
-
setIsMFAEnabled((userState === null || userState === void 0 ? void 0 : userState.isMfaEnabled) || false);
|
|
111
|
-
};
|
|
112
|
-
const resetState = () => {
|
|
113
|
-
setProvider(null);
|
|
114
|
-
setUserInfo(null);
|
|
115
|
-
setIsMFAEnabled(false);
|
|
116
|
-
};
|
|
117
|
-
if (web3Auth) {
|
|
118
|
-
if (isConnected) addState();else resetState();
|
|
119
|
-
}
|
|
120
|
-
}, [web3Auth, isConnected]);
|
|
121
58
|
react.useEffect(() => {
|
|
122
59
|
const notReadyListener = () => setStatus(web3Auth.status);
|
|
123
60
|
const readyListener = () => {
|
|
124
61
|
setStatus(web3Auth.status);
|
|
125
62
|
setIsInitialized(true);
|
|
126
63
|
};
|
|
127
|
-
const connectedListener =
|
|
64
|
+
const connectedListener = data => {
|
|
128
65
|
setStatus(web3Auth.status);
|
|
129
66
|
// we do this because of rehydration issues. status connected is fired first but web3auth sdk is not ready yet.
|
|
130
67
|
if (web3Auth.status === noModal.CONNECTOR_STATUS.CONNECTED) {
|
|
131
68
|
setIsInitialized(true);
|
|
132
69
|
setIsConnected(true);
|
|
70
|
+
setProvider(data.provider);
|
|
133
71
|
}
|
|
134
72
|
};
|
|
135
73
|
const disconnectedListener = () => {
|
|
136
74
|
setStatus(web3Auth.status);
|
|
137
75
|
setIsConnected(false);
|
|
76
|
+
setProvider(null);
|
|
138
77
|
};
|
|
139
78
|
const connectingListener = () => {
|
|
140
79
|
setStatus(web3Auth.status);
|
|
@@ -142,6 +81,9 @@ function Web3AuthInnerProvider(params) {
|
|
|
142
81
|
const errorListener = () => {
|
|
143
82
|
setStatus(noModal.CONNECTOR_STATUS.ERRORED);
|
|
144
83
|
};
|
|
84
|
+
const mfaEnabledListener = isMFAEnabled => {
|
|
85
|
+
if (typeof isMFAEnabled === "boolean") setIsMFAEnabled(isMFAEnabled);
|
|
86
|
+
};
|
|
145
87
|
if (web3Auth) {
|
|
146
88
|
// web3Auth is initialized here.
|
|
147
89
|
setStatus(web3Auth.status);
|
|
@@ -151,6 +93,7 @@ function Web3AuthInnerProvider(params) {
|
|
|
151
93
|
web3Auth.on(noModal.CONNECTOR_EVENTS.DISCONNECTED, disconnectedListener);
|
|
152
94
|
web3Auth.on(noModal.CONNECTOR_EVENTS.CONNECTING, connectingListener);
|
|
153
95
|
web3Auth.on(noModal.CONNECTOR_EVENTS.ERRORED, errorListener);
|
|
96
|
+
web3Auth.on(noModal.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
154
97
|
}
|
|
155
98
|
return () => {
|
|
156
99
|
if (web3Auth) {
|
|
@@ -160,6 +103,7 @@ function Web3AuthInnerProvider(params) {
|
|
|
160
103
|
web3Auth.off(noModal.CONNECTOR_EVENTS.DISCONNECTED, disconnectedListener);
|
|
161
104
|
web3Auth.off(noModal.CONNECTOR_EVENTS.CONNECTING, connectingListener);
|
|
162
105
|
web3Auth.off(noModal.CONNECTOR_EVENTS.ERRORED, errorListener);
|
|
106
|
+
web3Auth.off(noModal.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
163
107
|
web3Auth.cleanup();
|
|
164
108
|
}
|
|
165
109
|
};
|
|
@@ -170,22 +114,14 @@ function Web3AuthInnerProvider(params) {
|
|
|
170
114
|
isConnected,
|
|
171
115
|
isInitialized,
|
|
172
116
|
provider,
|
|
173
|
-
userInfo,
|
|
174
|
-
isMFAEnabled,
|
|
175
117
|
status,
|
|
176
|
-
connect,
|
|
177
|
-
enableMFA,
|
|
178
|
-
manageMFA,
|
|
179
|
-
logout,
|
|
180
|
-
authenticateUser,
|
|
181
|
-
switchChain,
|
|
182
|
-
getPlugin,
|
|
183
118
|
isInitializing,
|
|
184
|
-
isConnecting,
|
|
185
119
|
initError,
|
|
186
|
-
|
|
120
|
+
isMFAEnabled,
|
|
121
|
+
getPlugin,
|
|
122
|
+
setIsMFAEnabled
|
|
187
123
|
};
|
|
188
|
-
}, [web3Auth, isConnected,
|
|
124
|
+
}, [web3Auth, isConnected, isMFAEnabled, setIsMFAEnabled, isInitialized, provider, status, getPlugin, isInitializing, initError]);
|
|
189
125
|
return /*#__PURE__*/react.createElement(Web3AuthInnerContext.Provider, {
|
|
190
126
|
value
|
|
191
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;
|
|
@@ -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 useWalletConnectScanner = () => {
|
|
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 showWalletConnectScanner = react.useCallback(async showWalletConnectScannerParams => {
|
|
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.showWalletConnectScanner(showWalletConnectScannerParams);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
setError(error);
|
|
23
|
+
} finally {
|
|
24
|
+
setLoading(false);
|
|
25
|
+
}
|
|
26
|
+
}, [plugin, ready]);
|
|
27
|
+
return {
|
|
28
|
+
loading,
|
|
29
|
+
error,
|
|
30
|
+
showWalletConnectScanner
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.useWalletConnectScanner = useWalletConnectScanner;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var WalletServicesInnerContext = require('../context/WalletServicesInnerContext.js');
|
|
5
|
+
|
|
6
|
+
const useWalletServicesPlugin = () => {
|
|
7
|
+
const context = react.useContext(WalletServicesInnerContext.WalletServicesContext);
|
|
8
|
+
if (!context) throw new Error("WalletServicesContext not found");
|
|
9
|
+
return context;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
exports.useWalletServicesPlugin = useWalletServicesPlugin;
|
|
@@ -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 useWalletUI = () => {
|
|
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 showWalletUI = react.useCallback(async showWalletUiParams => {
|
|
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.showWalletUi(showWalletUiParams);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
setError(error);
|
|
23
|
+
} finally {
|
|
24
|
+
setLoading(false);
|
|
25
|
+
}
|
|
26
|
+
}, [plugin, ready]);
|
|
27
|
+
return {
|
|
28
|
+
loading,
|
|
29
|
+
error,
|
|
30
|
+
showWalletUI
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.useWalletUI = useWalletUI;
|
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var react = require('react');
|
|
5
|
-
var Web3AuthInnerContext = require('../context/Web3AuthInnerContext.js');
|
|
3
|
+
var useWeb3AuthInner = require('./useWeb3AuthInner.js');
|
|
6
4
|
|
|
7
5
|
const useWeb3Auth = () => {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
const {
|
|
7
|
+
initError,
|
|
8
|
+
isConnected,
|
|
9
|
+
isInitialized,
|
|
10
|
+
isInitializing,
|
|
11
|
+
provider,
|
|
12
|
+
status,
|
|
13
|
+
web3Auth,
|
|
14
|
+
getPlugin
|
|
15
|
+
} = useWeb3AuthInner.useWeb3AuthInner();
|
|
16
|
+
return {
|
|
17
|
+
initError,
|
|
18
|
+
isConnected,
|
|
19
|
+
isInitialized,
|
|
20
|
+
isInitializing,
|
|
21
|
+
provider,
|
|
22
|
+
status,
|
|
23
|
+
web3Auth,
|
|
24
|
+
getPlugin
|
|
25
|
+
};
|
|
13
26
|
};
|
|
14
27
|
|
|
15
28
|
exports.useWeb3Auth = useWeb3Auth;
|