@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.
Files changed (86) hide show
  1. package/dist/lib.cjs/packages/modal/src/config.js +2 -0
  2. package/dist/lib.cjs/packages/modal/src/index.js +1 -0
  3. package/dist/lib.cjs/packages/modal/src/modalManager.js +19 -21
  4. package/dist/lib.cjs/packages/modal/src/react/Web3AuthProvider.js +5 -1
  5. package/dist/lib.cjs/packages/modal/src/react/context/WalletServicesInnerContext.js +72 -0
  6. package/dist/lib.cjs/packages/modal/src/react/context/Web3AuthInnerContext.js +13 -77
  7. package/dist/lib.cjs/packages/modal/src/react/hooks/useCheckout.js +34 -0
  8. package/dist/lib.cjs/packages/modal/src/react/hooks/useEnableMFA.js +30 -0
  9. package/dist/lib.cjs/packages/modal/src/react/hooks/useIdentityToken.js +42 -0
  10. package/dist/lib.cjs/packages/modal/src/react/hooks/useManageMFA.js +30 -0
  11. package/dist/lib.cjs/packages/modal/src/react/hooks/useSwap.js +34 -0
  12. package/dist/lib.cjs/packages/modal/src/react/hooks/useSwitchChain.js +32 -0
  13. package/dist/lib.cjs/packages/modal/src/react/hooks/useWalletConnectScanner.js +34 -0
  14. package/dist/lib.cjs/packages/modal/src/react/hooks/useWalletServicesPlugin.js +12 -0
  15. package/dist/lib.cjs/packages/modal/src/react/hooks/useWalletUI.js +34 -0
  16. package/dist/lib.cjs/packages/modal/src/react/hooks/useWeb3Auth.js +21 -8
  17. package/dist/lib.cjs/packages/modal/src/react/hooks/useWeb3AuthConnect.js +43 -0
  18. package/dist/lib.cjs/packages/modal/src/react/hooks/useWeb3AuthDisconnect.js +30 -0
  19. package/dist/lib.cjs/packages/modal/src/react/hooks/useWeb3AuthInner.js +15 -0
  20. package/dist/lib.cjs/packages/modal/src/react/hooks/useWeb3AuthUser.js +50 -0
  21. package/dist/lib.cjs/packages/modal/src/react/index.js +24 -3
  22. package/dist/lib.cjs/packages/modal/src/react/wagmi/index.js +7 -0
  23. package/dist/lib.cjs/packages/modal/src/react/wagmi/provider.js +192 -0
  24. package/dist/lib.cjs/packages/modal/src/ui/components/ConnectWallet/ConnectWallet.js +5 -5
  25. package/dist/lib.cjs/packages/modal/src/ui/components/Login/Login.js +10 -13
  26. package/dist/lib.cjs/packages/modal/src/ui/components/Root/Root.js +1 -1
  27. package/dist/lib.cjs/packages/modal/src/ui/handlers/AbstractHandler.js +4 -2
  28. package/dist/lib.cjs/packages/modal/src/ui/handlers/EmailPasswordlessHandler.js +7 -4
  29. package/dist/lib.cjs/packages/modal/src/ui/handlers/SmsPasswordlessHandler.js +2 -2
  30. package/dist/lib.cjs/types/config.d.ts +1 -0
  31. package/dist/lib.cjs/types/react/context/WalletServicesInnerContext.d.ts +6 -0
  32. package/dist/lib.cjs/types/react/hooks/index.d.ts +13 -1
  33. package/dist/lib.cjs/types/react/hooks/useCheckout.d.ts +8 -0
  34. package/dist/lib.cjs/types/react/hooks/useEnableMFA.d.ts +7 -0
  35. package/dist/lib.cjs/types/react/hooks/useIdentityToken.d.ts +13 -0
  36. package/dist/lib.cjs/types/react/hooks/useManageMFA.d.ts +7 -0
  37. package/dist/lib.cjs/types/react/hooks/useSwap.d.ts +8 -0
  38. package/dist/lib.cjs/types/react/hooks/useSwitchChain.d.ts +7 -0
  39. package/dist/lib.cjs/types/react/hooks/useWalletConnectScanner.d.ts +8 -0
  40. package/dist/lib.cjs/types/react/hooks/useWalletServicesPlugin.d.ts +2 -0
  41. package/dist/lib.cjs/types/react/hooks/useWalletUI.d.ts +8 -0
  42. package/dist/lib.cjs/types/react/hooks/useWeb3Auth.d.ts +2 -1
  43. package/dist/lib.cjs/types/react/hooks/useWeb3AuthConnect.d.ts +9 -0
  44. package/dist/lib.cjs/types/react/hooks/useWeb3AuthDisconnect.d.ts +9 -0
  45. package/dist/lib.cjs/types/react/hooks/useWeb3AuthInner.d.ts +2 -0
  46. package/dist/lib.cjs/types/react/hooks/useWeb3AuthUser.d.ts +9 -0
  47. package/dist/lib.cjs/types/react/index.d.ts +0 -1
  48. package/dist/lib.cjs/types/react/interfaces.d.ts +6 -2
  49. package/dist/lib.cjs/types/react/wagmi/index.d.ts +1 -0
  50. package/dist/lib.cjs/types/react/wagmi/interface.d.ts +4 -0
  51. package/dist/lib.cjs/types/react/wagmi/provider.d.ts +4 -0
  52. package/dist/lib.cjs/types/ui/handlers/AbstractHandler.d.ts +2 -1
  53. package/dist/lib.cjs/types/ui/handlers/EmailPasswordlessHandler.d.ts +3 -1
  54. package/dist/lib.cjs/types/ui/interfaces.d.ts +3 -3
  55. package/dist/lib.esm/packages/modal/src/config.js +2 -1
  56. package/dist/lib.esm/packages/modal/src/index.js +1 -1
  57. package/dist/lib.esm/packages/modal/src/modalManager.js +21 -21
  58. package/dist/lib.esm/packages/modal/src/react/Web3AuthProvider.js +6 -2
  59. package/dist/lib.esm/packages/modal/src/react/context/WalletServicesInnerContext.js +69 -0
  60. package/dist/lib.esm/packages/modal/src/react/context/Web3AuthInnerContext.js +14 -78
  61. package/dist/lib.esm/packages/modal/src/react/hooks/useCheckout.js +32 -0
  62. package/dist/lib.esm/packages/modal/src/react/hooks/useEnableMFA.js +28 -0
  63. package/dist/lib.esm/packages/modal/src/react/hooks/useIdentityToken.js +40 -0
  64. package/dist/lib.esm/packages/modal/src/react/hooks/useManageMFA.js +28 -0
  65. package/dist/lib.esm/packages/modal/src/react/hooks/useSwap.js +32 -0
  66. package/dist/lib.esm/packages/modal/src/react/hooks/useSwitchChain.js +30 -0
  67. package/dist/lib.esm/packages/modal/src/react/hooks/useWalletConnectScanner.js +32 -0
  68. package/dist/lib.esm/packages/modal/src/react/hooks/useWalletServicesPlugin.js +10 -0
  69. package/dist/lib.esm/packages/modal/src/react/hooks/useWalletUI.js +32 -0
  70. package/dist/lib.esm/packages/modal/src/react/hooks/useWeb3Auth.js +21 -8
  71. package/dist/lib.esm/packages/modal/src/react/hooks/useWeb3AuthConnect.js +41 -0
  72. package/dist/lib.esm/packages/modal/src/react/hooks/useWeb3AuthDisconnect.js +28 -0
  73. package/dist/lib.esm/packages/modal/src/react/hooks/useWeb3AuthInner.js +13 -0
  74. package/dist/lib.esm/packages/modal/src/react/hooks/useWeb3AuthUser.js +48 -0
  75. package/dist/lib.esm/packages/modal/src/react/index.js +12 -1
  76. package/dist/lib.esm/packages/modal/src/react/wagmi/index.js +1 -0
  77. package/dist/lib.esm/packages/modal/src/react/wagmi/provider.js +192 -0
  78. package/dist/lib.esm/packages/modal/src/ui/components/ConnectWallet/ConnectWallet.js +5 -5
  79. package/dist/lib.esm/packages/modal/src/ui/components/Login/Login.js +10 -13
  80. package/dist/lib.esm/packages/modal/src/ui/components/Root/Root.js +1 -1
  81. package/dist/lib.esm/packages/modal/src/ui/handlers/AbstractHandler.js +2 -0
  82. package/dist/lib.esm/packages/modal/src/ui/handlers/EmailPasswordlessHandler.js +7 -4
  83. package/dist/lib.esm/packages/modal/src/ui/handlers/SmsPasswordlessHandler.js +2 -2
  84. package/dist/modal.umd.min.js +1 -1
  85. package/package.json +35 -10
  86. package/dist/lib.cjs/types/react/context/index.d.ts +0 -1
@@ -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 };
@@ -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 useWalletUI = () => {
6
+ const {
7
+ plugin,
8
+ ready
9
+ } = useWalletServicesPlugin();
10
+ const [loading, setLoading] = useState(false);
11
+ const [error, setError] = useState(null);
12
+ const showWalletUI = useCallback(async showWalletUiParams => {
13
+ setLoading(true);
14
+ setError(null);
15
+ try {
16
+ if (!plugin) throw WalletServicesPluginError.notInitialized();
17
+ if (!ready) throw WalletServicesPluginError.walletPluginNotConnected();
18
+ await plugin.showWalletUi(showWalletUiParams);
19
+ } catch (error) {
20
+ setError(error);
21
+ } finally {
22
+ setLoading(false);
23
+ }
24
+ }, [plugin, ready]);
25
+ return {
26
+ loading,
27
+ error,
28
+ showWalletUI
29
+ };
30
+ };
31
+
32
+ export { useWalletUI };
@@ -1,13 +1,26 @@
1
- import { WalletInitializationError } from '@web3auth/no-modal';
2
- import { useContext } from 'react';
3
- import { Web3AuthInnerContext } from '../context/Web3AuthInnerContext.js';
1
+ import { useWeb3AuthInner } from './useWeb3AuthInner.js';
4
2
 
5
3
  const useWeb3Auth = () => {
6
- const context = useContext(Web3AuthInnerContext);
7
- if (!context) {
8
- throw WalletInitializationError.fromCode(1000, "usage of useWeb3Auth not wrapped in `Web3AuthContextProvider`.");
9
- }
10
- return context;
4
+ const {
5
+ initError,
6
+ isConnected,
7
+ isInitialized,
8
+ isInitializing,
9
+ provider,
10
+ status,
11
+ web3Auth,
12
+ getPlugin
13
+ } = useWeb3AuthInner();
14
+ return {
15
+ initError,
16
+ isConnected,
17
+ isInitialized,
18
+ isInitializing,
19
+ provider,
20
+ status,
21
+ web3Auth,
22
+ getPlugin
23
+ };
11
24
  };
12
25
 
13
26
  export { useWeb3Auth };
@@ -0,0 +1,41 @@
1
+ import { useState, useEffect, useCallback } from 'react';
2
+ import { useWeb3AuthInner } from './useWeb3AuthInner.js';
3
+
4
+ const useWeb3AuthConnect = () => {
5
+ const {
6
+ web3Auth,
7
+ isConnected
8
+ } = useWeb3AuthInner();
9
+ const [loading, setLoading] = useState(false);
10
+ const [error, setError] = useState(null);
11
+ const [connectorName, setConnectorName] = useState(null);
12
+ useEffect(() => {
13
+ if (!isConnected && connectorName) {
14
+ setConnectorName(null);
15
+ }
16
+ }, [isConnected, connectorName]);
17
+ const connect = useCallback(async () => {
18
+ setLoading(true);
19
+ setError(null);
20
+ try {
21
+ const provider = await web3Auth.connect();
22
+ if (provider) {
23
+ setConnectorName(web3Auth.connectedConnectorName);
24
+ }
25
+ return provider;
26
+ } catch (error) {
27
+ setError(error);
28
+ } finally {
29
+ setLoading(false);
30
+ }
31
+ }, [web3Auth]);
32
+ return {
33
+ isConnected,
34
+ loading,
35
+ error,
36
+ connectorName,
37
+ connect
38
+ };
39
+ };
40
+
41
+ export { useWeb3AuthConnect };
@@ -0,0 +1,28 @@
1
+ import { useState, useCallback } from 'react';
2
+ import { useWeb3AuthInner } from './useWeb3AuthInner.js';
3
+
4
+ const useWeb3AuthDisconnect = () => {
5
+ const {
6
+ web3Auth
7
+ } = useWeb3AuthInner();
8
+ const [loading, setLoading] = useState(false);
9
+ const [error, setError] = useState(null);
10
+ const disconnect = useCallback(async options => {
11
+ setLoading(true);
12
+ setError(null);
13
+ try {
14
+ await web3Auth.logout(options);
15
+ } catch (error) {
16
+ setError(error);
17
+ } finally {
18
+ setLoading(false);
19
+ }
20
+ }, [web3Auth]);
21
+ return {
22
+ loading,
23
+ error,
24
+ disconnect
25
+ };
26
+ };
27
+
28
+ export { useWeb3AuthDisconnect };
@@ -0,0 +1,13 @@
1
+ import { WalletInitializationError } from '@web3auth/no-modal';
2
+ import { useContext } from 'react';
3
+ import { Web3AuthInnerContext } from '../context/Web3AuthInnerContext.js';
4
+
5
+ const useWeb3AuthInner = () => {
6
+ const context = useContext(Web3AuthInnerContext);
7
+ if (!context) {
8
+ throw WalletInitializationError.fromCode(1000, "usage of useWeb3Auth not wrapped in `Web3AuthContextProvider`.");
9
+ }
10
+ return context;
11
+ };
12
+
13
+ export { useWeb3AuthInner };
@@ -0,0 +1,48 @@
1
+ import { useState, useCallback, useEffect } from 'react';
2
+ import { useWeb3AuthInner } from './useWeb3AuthInner.js';
3
+
4
+ const useWeb3AuthUser = () => {
5
+ const {
6
+ web3Auth,
7
+ isConnected,
8
+ isMFAEnabled,
9
+ setIsMFAEnabled
10
+ } = useWeb3AuthInner();
11
+ const [userInfo, setUserInfo] = useState(null);
12
+ const [loading, setLoading] = useState(false);
13
+ const [error, setError] = useState(null);
14
+ const getUserInfo = useCallback(async () => {
15
+ setLoading(true);
16
+ setError(null);
17
+ try {
18
+ const userInfo = await web3Auth.getUserInfo();
19
+ setUserInfo(userInfo);
20
+ return userInfo;
21
+ } catch (error) {
22
+ setError(error);
23
+ } finally {
24
+ setLoading(false);
25
+ }
26
+ }, [web3Auth]);
27
+ useEffect(() => {
28
+ const saveUserInfo = async () => {
29
+ const userInfo = await getUserInfo();
30
+ setUserInfo(userInfo);
31
+ setIsMFAEnabled((userInfo === null || userInfo === void 0 ? void 0 : userInfo.isMfaEnabled) || false);
32
+ };
33
+ if (isConnected && !userInfo) saveUserInfo();
34
+ if (!isConnected && userInfo) {
35
+ setUserInfo(null);
36
+ setIsMFAEnabled(false);
37
+ }
38
+ }, [isConnected, userInfo, getUserInfo, setIsMFAEnabled]);
39
+ return {
40
+ loading,
41
+ error,
42
+ userInfo,
43
+ isMFAEnabled,
44
+ getUserInfo
45
+ };
46
+ };
47
+
48
+ export { useWeb3AuthUser };
@@ -1,3 +1,14 @@
1
- export { Web3AuthInnerContext, Web3AuthInnerProvider } from './context/Web3AuthInnerContext.js';
1
+ export { useCheckout } from './hooks/useCheckout.js';
2
+ export { useEnableMFA } from './hooks/useEnableMFA.js';
3
+ export { useIdentityToken } from './hooks/useIdentityToken.js';
4
+ export { useManageMFA } from './hooks/useManageMFA.js';
5
+ export { useSwap } from './hooks/useSwap.js';
6
+ export { useSwitchChain } from './hooks/useSwitchChain.js';
7
+ export { useWalletConnectScanner } from './hooks/useWalletConnectScanner.js';
8
+ export { useWalletServicesPlugin } from './hooks/useWalletServicesPlugin.js';
9
+ export { useWalletUI } from './hooks/useWalletUI.js';
2
10
  export { useWeb3Auth } from './hooks/useWeb3Auth.js';
11
+ export { useWeb3AuthConnect } from './hooks/useWeb3AuthConnect.js';
12
+ export { useWeb3AuthDisconnect } from './hooks/useWeb3AuthDisconnect.js';
13
+ export { useWeb3AuthUser } from './hooks/useWeb3AuthUser.js';
3
14
  export { Web3AuthProvider } from './Web3AuthProvider.js';
@@ -0,0 +1 @@
1
+ export { WagmiProvider } from './provider.js';
@@ -0,0 +1,192 @@
1
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
2
+ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
3
+ import { log } from '@web3auth/no-modal';
4
+ import { useMemo, createElement, useEffect, Fragment } from 'react';
5
+ import { defineChain, http } from 'viem';
6
+ import { createConfig, WagmiProvider as WagmiProvider$1, useConfig, useAccountEffect } from 'wagmi';
7
+ import { injected } from 'wagmi/connectors';
8
+ import '@babel/runtime/helpers/defineProperty';
9
+ import 'deepmerge';
10
+ import '../../config.js';
11
+ import '../../ui/config.js';
12
+ import '../../ui/css/index.css.js';
13
+ import '@web3auth/auth';
14
+ import 'react-dom/client';
15
+ import '@toruslabs/http-helpers';
16
+ import 'clsx';
17
+ import 'tailwind-merge';
18
+ import 'react/jsx-runtime';
19
+ import 'bowser';
20
+ import 'react-i18next';
21
+ import '../../ui/localeImport.js';
22
+ import 'classnames';
23
+ import 'react-qrcode-logo';
24
+ import '../../ui/components/Login/Login.js';
25
+ import { useWeb3Auth } from '../hooks/useWeb3Auth.js';
26
+ import { useWeb3AuthDisconnect } from '../hooks/useWeb3AuthDisconnect.js';
27
+
28
+ const _excluded = ["children"];
29
+ const WEB3AUTH_CONNECTOR_ID = "web3auth";
30
+
31
+ // Helper to initialize connectors for the given wallets
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
+ async function setupConnector(provider, config) {
34
+ let connector = config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
35
+ if (connector) return connector;
36
+
37
+ // Create new connector if not already existing
38
+ connector = injected({
39
+ target: {
40
+ provider: provider,
41
+ id: WEB3AUTH_CONNECTOR_ID,
42
+ name: "Web3Auth"
43
+ }
44
+ });
45
+ const result = config._internal.connectors.setup(connector);
46
+ config._internal.connectors.setState(current => [...current, result]);
47
+ return result;
48
+ }
49
+
50
+ // Helper to connect a wallet and update wagmi state
51
+ async function connectWeb3AuthWithWagmi(connector, config) {
52
+ var _config$storage, _config$storage2;
53
+ await Promise.all([(_config$storage = config.storage) === null || _config$storage === void 0 ? void 0 : _config$storage.removeItem(`${connector.id}.disconnected`), (_config$storage2 = config.storage) === null || _config$storage2 === void 0 ? void 0 : _config$storage2.setItem("recentConnectorId", connector.id)]);
54
+ let chainId = await connector.getChainId();
55
+ if (!config.chains.find(c => c.id === chainId)) {
56
+ chainId = config.chains[0].id;
57
+ }
58
+ const accounts = await connector.getAccounts();
59
+ const connections = new Map([[connector.uid, {
60
+ accounts: [accounts[0]],
61
+ chainId,
62
+ connector
63
+ }]]);
64
+ config.setState(state => _objectSpread(_objectSpread({}, state), {}, {
65
+ chainId,
66
+ connections,
67
+ current: connector.uid,
68
+ status: "connected"
69
+ }));
70
+ }
71
+ async function disconnectWeb3AuthFromWagmi(config) {
72
+ config._internal.connectors.setState(prev => prev.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID));
73
+ config.setState(state => _objectSpread(_objectSpread({}, state), {}, {
74
+ chainId: state.chainId,
75
+ connections: new Map(),
76
+ current: undefined,
77
+ status: "disconnected"
78
+ }));
79
+ }
80
+ function Web3AuthWagmiProvider({
81
+ children
82
+ }) {
83
+ const {
84
+ isConnected,
85
+ provider
86
+ } = useWeb3Auth();
87
+ const {
88
+ disconnect
89
+ } = useWeb3AuthDisconnect();
90
+ const wagmiConfig = useConfig();
91
+ useAccountEffect({
92
+ onDisconnect: async () => {
93
+ log.info("Disconnected from wagmi");
94
+ if (isConnected) await disconnect();
95
+ }
96
+ });
97
+ useEffect(() => {
98
+ (async () => {
99
+ if (isConnected && provider) {
100
+ const connector = await setupConnector(provider, wagmiConfig);
101
+ if (!connector) {
102
+ throw new Error("Failed to setup connector");
103
+ }
104
+ await connectWeb3AuthWithWagmi(connector, wagmiConfig);
105
+ } else if (!isConnected) {
106
+ if (wagmiConfig.state.status === "connected") {
107
+ await disconnectWeb3AuthFromWagmi(wagmiConfig);
108
+ }
109
+ }
110
+ })();
111
+ }, [isConnected, wagmiConfig, provider]);
112
+ return /*#__PURE__*/createElement(Fragment, null, children);
113
+ }
114
+ function WagmiProvider(_ref) {
115
+ let {
116
+ children
117
+ } = _ref,
118
+ props = _objectWithoutProperties(_ref, _excluded);
119
+ const {
120
+ config
121
+ } = props;
122
+ const {
123
+ web3Auth,
124
+ isInitialized
125
+ } = useWeb3Auth();
126
+ const finalConfig = useMemo(() => {
127
+ var _web3Auth$coreOptions;
128
+ const finalConfig = _objectSpread(_objectSpread({
129
+ ssr: true
130
+ }, config), {}, {
131
+ chains: undefined,
132
+ connectors: [],
133
+ transports: {},
134
+ multiInjectedProviderDiscovery: false,
135
+ client: undefined
136
+ });
137
+ const wagmiChains = [];
138
+ if (isInitialized && web3Auth !== null && web3Auth !== void 0 && (_web3Auth$coreOptions = web3Auth.coreOptions) !== null && _web3Auth$coreOptions !== void 0 && _web3Auth$coreOptions.chains) {
139
+ var _web3Auth$currentChai;
140
+ const defaultChainId = (_web3Auth$currentChai = web3Auth.currentChain) === null || _web3Auth$currentChai === void 0 ? void 0 : _web3Auth$currentChai.chainId;
141
+ const chains = web3Auth.coreOptions.chains;
142
+ chains.forEach(chain => {
143
+ const wagmiChain = defineChain({
144
+ id: Number.parseInt(chain.chainId, 16),
145
+ // id in number form
146
+ name: chain.displayName,
147
+ rpcUrls: {
148
+ default: {
149
+ http: [chain.rpcTarget],
150
+ webSocket: [chain.wsTarget]
151
+ }
152
+ },
153
+ blockExplorers: chain.blockExplorerUrl ? {
154
+ default: {
155
+ name: "explorer",
156
+ // TODO: correct name if chain config has it
157
+ url: chain.blockExplorerUrl
158
+ }
159
+ } : undefined,
160
+ nativeCurrency: {
161
+ name: chain.tickerName,
162
+ symbol: chain.ticker,
163
+ decimals: chain.decimals || 18
164
+ }
165
+ });
166
+ if (defaultChainId === chain.chainId) {
167
+ wagmiChains.unshift(wagmiChain);
168
+ } else {
169
+ wagmiChains.push(wagmiChain);
170
+ }
171
+ finalConfig.transports[wagmiChain.id] = http(chain.rpcTarget);
172
+ });
173
+ finalConfig.chains = [wagmiChains[0], ...wagmiChains.slice(1)];
174
+ }
175
+ if (!finalConfig.chains) return;
176
+ return createConfig(finalConfig);
177
+ }, [config, web3Auth, isInitialized]);
178
+
179
+ // WagmiProviderBase requires a config to initialize
180
+ // If no config is provided, it will throw an error.
181
+ if (!finalConfig) return null;
182
+ return /*#__PURE__*/createElement(WagmiProvider$1, // typecast to WagmiProviderPropsBase to avoid type error
183
+ // as we are omitting the config prop from WagmiProviderProps
184
+ // and creating a new config object with the finalConfig
185
+ _objectSpread(_objectSpread({
186
+ config: finalConfig
187
+ }, props), {}, {
188
+ reconnectOnMount: false
189
+ }), /*#__PURE__*/createElement(Web3AuthWagmiProvider, null, children));
190
+ }
191
+
192
+ export { WagmiProvider };
@@ -79,12 +79,12 @@ function ConnectWallet(props) {
79
79
  }, [allExternalButtons, customConnectorButtons, defaultButtonKeys, selectedChain]);
80
80
  const installedWalletButtons = useMemo(() => {
81
81
  const visibilityMap = connectorVisibilityMap;
82
- return Object.keys(config).reduce((acc, adapter) => {
83
- if (![WALLET_CONNECTORS.WALLET_CONNECT_V2].includes(adapter) && visibilityMap[adapter]) {
82
+ return Object.keys(config).reduce((acc, localConnector) => {
83
+ if (localConnector !== WALLET_CONNECTORS.WALLET_CONNECT_V2 && visibilityMap[localConnector]) {
84
84
  acc.push({
85
- name: adapter,
86
- displayName: config[adapter].label || adapter,
87
- hasInjectedWallet: config[adapter].isInjected,
85
+ name: localConnector,
86
+ displayName: config[localConnector].label || localConnector,
87
+ hasInjectedWallet: config[localConnector].isInjected,
88
88
  hasWalletConnect: false,
89
89
  hasInstallLinks: false
90
90
  });
@@ -157,6 +157,7 @@ function Login(props) {
157
157
  }, [socialLoginsConfig, isDark, buttonRadius]);
158
158
  const handleCustomLogin = async (authConnection, loginHint) => {
159
159
  try {
160
+ var _captchaRef$current;
160
161
  const handler = createPasswordlessHandler(authConnection, {
161
162
  loginHint,
162
163
  web3authClientId,
@@ -165,17 +166,13 @@ function Login(props) {
165
166
  authConnection,
166
167
  authBuildEnv
167
168
  });
168
- let token = "";
169
- if (authConnection === AUTH_CONNECTION.SMS_PASSWORDLESS) {
170
- var _captchaRef$current;
171
- const res = await ((_captchaRef$current = captchaRef.current) === null || _captchaRef$current === void 0 ? void 0 : _captchaRef$current.execute({
172
- async: true
173
- }));
174
- if (!res) {
175
- throw WalletLoginError.connectionError("Captcha token is required");
176
- }
177
- token = res.response;
169
+ const res = await ((_captchaRef$current = captchaRef.current) === null || _captchaRef$current === void 0 ? void 0 : _captchaRef$current.execute({
170
+ async: true
171
+ }));
172
+ if (!res) {
173
+ throw WalletLoginError.connectionError("Captcha token is required");
178
174
  }
175
+ const token = res.response;
179
176
  const result = await handler.sendVerificationCode({
180
177
  captchaToken: token
181
178
  });
@@ -200,7 +197,7 @@ function Login(props) {
200
197
  const connectorConfig = socialLoginsConfig.loginMethods[AUTH_CONNECTION.EMAIL_PASSWORDLESS];
201
198
  if (connectorConfig.isDefault) {
202
199
  return handleSocialLoginClick({
203
- connector: socialLoginsConfig.connector || "",
200
+ connector: socialLoginsConfig.connector,
204
201
  loginParams: {
205
202
  authConnection: AUTH_CONNECTION.EMAIL_PASSWORDLESS,
206
203
  authConnectionId: connectorConfig.authConnectionId,
@@ -223,7 +220,7 @@ function Login(props) {
223
220
  const connectorConfig = socialLoginsConfig.loginMethods[AUTH_CONNECTION.SMS_PASSWORDLESS];
224
221
  if (connectorConfig.isDefault) {
225
222
  return handleSocialLoginClick({
226
- connector: socialLoginsConfig.connector || "",
223
+ connector: socialLoginsConfig.connector,
227
224
  loginParams: {
228
225
  authConnection: AUTH_CONNECTION.SMS_PASSWORDLESS,
229
226
  authConnectionId: connectorConfig.authConnectionId,
@@ -285,7 +282,7 @@ function Login(props) {
285
282
  if (result !== null && result !== void 0 && (_result$data = result.data) !== null && _result$data !== void 0 && _result$data.id_token) {
286
283
  var _result$data2;
287
284
  return handleSocialLoginClick({
288
- connector: socialLoginsConfig.connector || "",
285
+ connector: socialLoginsConfig.connector,
289
286
  loginParams: {
290
287
  authConnection: authConnection,
291
288
  authConnectionId: connectorConfig.authConnectionId,
@@ -238,7 +238,7 @@ function Root(props) {
238
238
  }, [connectorVisibilityMap, chainNamespaces, config, deviceDetails.platform, isWalletConnectConnectorIncluded]);
239
239
  const installedConnectorButtons = useMemo(() => {
240
240
  const installedConnectors = Object.keys(config).reduce((acc, connector) => {
241
- if ([WALLET_CONNECTORS.WALLET_CONNECT_V2].includes(connector) || !connectorVisibilityMap[connector]) return acc;
241
+ if (connector === WALLET_CONNECTORS.WALLET_CONNECT_V2 || !connectorVisibilityMap[connector]) return acc;
242
242
  const connectorConfig = config[connector];
243
243
  acc.push({
244
244
  name: connector,
@@ -2,6 +2,7 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import { post } from '@toruslabs/http-helpers';
3
3
  import { BUILD_ENV, AUTH_CONNECTION, storageAvailable } from '@web3auth/auth';
4
4
  import { WalletInitializationError } from '@web3auth/no-modal';
5
+ import { version } from '../../config.js';
5
6
  import { PASSWORDLESS_BUILD_ENV_MAP } from '../config.js';
6
7
  import { getErrorMessages } from '../utils.js';
7
8
 
@@ -10,6 +11,7 @@ class PasswordlessHandler {
10
11
  _defineProperty(this, "authBaseApiUrl", void 0);
11
12
  _defineProperty(this, "passwordlessParams", void 0);
12
13
  _defineProperty(this, "trackingIdentifier", void 0);
14
+ _defineProperty(this, "version", `web3auth-${version.split(".")[0]}`);
13
15
  if (!params.authConnection) throw WalletInitializationError.invalidParams("authConnection is required");
14
16
  if (!params.web3authClientId) throw WalletInitializationError.invalidParams("web3authClientId is required");
15
17
  if (!params.loginHint) throw WalletInitializationError.invalidParams("loginHint is required");
@@ -10,7 +10,9 @@ class EmailPasswordlessHandler extends PasswordlessHandler {
10
10
  this.mailSent = false;
11
11
  if (this.sessionStorageAvailable) this.trackingId = (_window$sessionStorag = window.sessionStorage.getItem("trackingId")) !== null && _window$sessionStorag !== void 0 ? _window$sessionStorag : undefined;
12
12
  }
13
- async sendVerificationCode() {
13
+ async sendVerificationCode({
14
+ captchaToken
15
+ }) {
14
16
  const {
15
17
  loginHint,
16
18
  network,
@@ -23,9 +25,10 @@ class EmailPasswordlessHandler extends PasswordlessHandler {
23
25
  login_hint: loginHint,
24
26
  tracking_id: this.trackingId,
25
27
  whitelabel: this.whiteLabelParams,
26
- version: "",
28
+ version: this.version,
27
29
  network,
28
- flow_type: EMAIL_FLOW.code
30
+ flow_type: EMAIL_FLOW.code,
31
+ captcha_token: captchaToken
29
32
  };
30
33
  return super.start(finalParams);
31
34
  }
@@ -41,7 +44,7 @@ class EmailPasswordlessHandler extends PasswordlessHandler {
41
44
  code,
42
45
  connection: "email",
43
46
  tracking_id: this.trackingId,
44
- version: "",
47
+ version: this.version,
45
48
  network,
46
49
  flow_type: EMAIL_FLOW.code
47
50
  };
@@ -27,7 +27,7 @@ class SmsPasswordlessHandler extends PasswordlessHandler {
27
27
  login_hint: loginHint,
28
28
  tracking_id: this.trackingId,
29
29
  whitelabel: this.whiteLabelParams,
30
- version: "",
30
+ version: this.version,
31
31
  network,
32
32
  captcha_token: captchaToken
33
33
  };
@@ -45,7 +45,7 @@ class SmsPasswordlessHandler extends PasswordlessHandler {
45
45
  code,
46
46
  connection: this.connection,
47
47
  tracking_id: this.trackingId,
48
- version: "",
48
+ version: this.version,
49
49
  network
50
50
  };
51
51
  return super.verify(params);