@web3auth/modal 10.6.0 → 10.8.0

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 (29) hide show
  1. package/dist/lib.cjs/packages/modal/src/config.js +1 -1
  2. package/dist/lib.cjs/packages/modal/src/react/context/Web3AuthInnerContext.js +21 -1
  3. package/dist/lib.cjs/packages/modal/src/react/hooks/useChain.js +16 -0
  4. package/dist/lib.cjs/packages/modal/src/react/index.js +2 -0
  5. package/dist/lib.cjs/packages/modal/src/react/solana/hooks/useSolanaWallet.js +31 -6
  6. package/dist/lib.cjs/packages/modal/src/react/wagmi/provider.js +18 -2
  7. package/dist/lib.cjs/packages/modal/src/ui/components/ConnectWallet/ConnectWallet.js +1 -1
  8. package/dist/lib.cjs/packages/modal/src/vue/composables/useChain.js +24 -0
  9. package/dist/lib.cjs/packages/modal/src/vue/index.js +2 -0
  10. package/dist/lib.cjs/packages/modal/src/vue/solana/composables/useSolanaWallet.js +24 -9
  11. package/dist/lib.cjs/packages/modal/src/vue/wagmi/provider.js +18 -2
  12. package/dist/lib.cjs/types/react/hooks/index.d.ts +1 -0
  13. package/dist/lib.cjs/types/react/hooks/useChain.d.ts +6 -0
  14. package/dist/lib.cjs/types/react/hooks/useWeb3Auth.d.ts +1 -1
  15. package/dist/lib.cjs/types/vue/composables/index.d.ts +1 -0
  16. package/dist/lib.cjs/types/vue/composables/useChain.d.ts +7 -0
  17. package/dist/lib.esm/packages/modal/src/config.js +1 -1
  18. package/dist/lib.esm/packages/modal/src/react/context/Web3AuthInnerContext.js +21 -1
  19. package/dist/lib.esm/packages/modal/src/react/hooks/useChain.js +14 -0
  20. package/dist/lib.esm/packages/modal/src/react/index.js +1 -0
  21. package/dist/lib.esm/packages/modal/src/react/solana/hooks/useSolanaWallet.js +30 -7
  22. package/dist/lib.esm/packages/modal/src/react/wagmi/provider.js +18 -2
  23. package/dist/lib.esm/packages/modal/src/ui/components/ConnectWallet/ConnectWallet.js +1 -1
  24. package/dist/lib.esm/packages/modal/src/vue/composables/useChain.js +22 -0
  25. package/dist/lib.esm/packages/modal/src/vue/index.js +1 -0
  26. package/dist/lib.esm/packages/modal/src/vue/solana/composables/useSolanaWallet.js +25 -10
  27. package/dist/lib.esm/packages/modal/src/vue/wagmi/provider.js +18 -2
  28. package/dist/modal.umd.min.js +1 -1
  29. package/package.json +7 -7
@@ -2,7 +2,7 @@
2
2
 
3
3
  var noModal = require('@web3auth/no-modal');
4
4
 
5
- const version = "10.6.0";
5
+ const version = "10.8.0";
6
6
  const defaultConnectorsModalConfig = {
7
7
  hideWalletDiscovery: false,
8
8
  connectors: {
@@ -14,6 +14,8 @@ function Web3AuthInnerProvider(params) {
14
14
  const {
15
15
  web3AuthOptions
16
16
  } = config;
17
+ const [chainId, setChainId] = react.useState(null);
18
+ const [chainNamespace, setChainNamespace] = react.useState(null);
17
19
  const [isInitializing, setIsInitializing] = react.useState(false);
18
20
  const [initError, setInitError] = react.useState(null);
19
21
  const [provider, setProvider] = react.useState(null);
@@ -33,6 +35,7 @@ function Web3AuthInnerProvider(params) {
33
35
  const controller = new AbortController();
34
36
  async function init() {
35
37
  try {
38
+ var _web3Auth$currentChai;
36
39
  setInitError(null);
37
40
  setIsInitializing(true);
38
41
  web3Auth.setAnalyticsProperties({
@@ -41,6 +44,8 @@ function Web3AuthInnerProvider(params) {
41
44
  await web3Auth.init({
42
45
  signal: controller.signal
43
46
  });
47
+ setChainId(web3Auth.currentChainId);
48
+ setChainNamespace((_web3Auth$currentChai = web3Auth.currentChain) === null || _web3Auth$currentChai === void 0 ? void 0 : _web3Auth$currentChai.chainNamespace);
44
49
  } catch (error) {
45
50
  setInitError(error);
46
51
  } finally {
@@ -52,6 +57,19 @@ function Web3AuthInnerProvider(params) {
52
57
  controller.abort();
53
58
  };
54
59
  }, [web3Auth, config]);
60
+ react.useEffect(() => {
61
+ const handleChainChange = async chainId => {
62
+ var _web3Auth$currentChai2;
63
+ setChainId(chainId);
64
+ setChainNamespace(web3Auth === null || web3Auth === void 0 || (_web3Auth$currentChai2 = web3Auth.currentChain) === null || _web3Auth$currentChai2 === void 0 ? void 0 : _web3Auth$currentChai2.chainNamespace);
65
+ };
66
+ if (provider) {
67
+ provider.on("chainChanged", handleChainChange);
68
+ return () => {
69
+ provider.off("chainChanged", handleChainChange);
70
+ };
71
+ }
72
+ }, [web3Auth, provider]);
55
73
  react.useEffect(() => {
56
74
  const notReadyListener = () => setStatus(web3Auth.status);
57
75
  const readyListener = () => {
@@ -122,10 +140,12 @@ function Web3AuthInnerProvider(params) {
122
140
  isInitializing,
123
141
  initError,
124
142
  isMFAEnabled,
143
+ chainId,
144
+ chainNamespace,
125
145
  getPlugin,
126
146
  setIsMFAEnabled
127
147
  };
128
- }, [web3Auth, isConnected, isMFAEnabled, setIsMFAEnabled, isInitialized, provider, status, getPlugin, isInitializing, initError]);
148
+ }, [web3Auth, isConnected, isMFAEnabled, setIsMFAEnabled, isInitialized, provider, status, getPlugin, isInitializing, initError, chainId, chainNamespace]);
129
149
  return /*#__PURE__*/react.createElement(Web3AuthInnerContext.Provider, {
130
150
  value
131
151
  }, children);
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ var useWeb3AuthInner = require('./useWeb3AuthInner.js');
4
+
5
+ const useChain = () => {
6
+ const {
7
+ chainId,
8
+ chainNamespace
9
+ } = useWeb3AuthInner.useWeb3AuthInner();
10
+ return {
11
+ chainId,
12
+ chainNamespace
13
+ };
14
+ };
15
+
16
+ exports.useChain = useChain;
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var useChain = require('./hooks/useChain.js');
3
4
  var useCheckout = require('./hooks/useCheckout.js');
4
5
  var useEnableMFA = require('./hooks/useEnableMFA.js');
5
6
  var useFunding = require('./hooks/useFunding.js');
@@ -19,6 +20,7 @@ var Web3AuthProvider = require('./Web3AuthProvider.js');
19
20
 
20
21
 
21
22
 
23
+ exports.useChain = useChain.useChain;
22
24
  exports.useCheckout = useCheckout.useCheckout;
23
25
  exports.useEnableMFA = useEnableMFA.useEnableMFA;
24
26
  exports.useFunding = useFunding.useFunding;
@@ -3,6 +3,27 @@
3
3
  var web3_js = require('@solana/web3.js');
4
4
  var noModal = require('@web3auth/no-modal');
5
5
  var react = require('react');
6
+ var useChain = require('../../hooks/useChain.js');
7
+ require('@babel/runtime/helpers/objectSpread2');
8
+ require('@babel/runtime/helpers/defineProperty');
9
+ require('@web3auth/auth');
10
+ require('deepmerge');
11
+ require('../../../config.js');
12
+ require('../../../ui/config.js');
13
+ require('../../../ui/interfaces.js');
14
+ require('react/jsx-runtime');
15
+ require('../../../ui/css/index.css.js');
16
+ require('bowser');
17
+ require('react-dom/client');
18
+ require('@toruslabs/http-helpers');
19
+ require('clsx');
20
+ require('tailwind-merge');
21
+ require('react-i18next');
22
+ require('../../../ui/context/RootContext.js');
23
+ require('../../../ui/localeImport.js');
24
+ require('classnames');
25
+ require('react-qrcode-logo');
26
+ require('../../../ui/components/Login/Login.js');
6
27
  var useWeb3Auth = require('../../hooks/useWeb3Auth.js');
7
28
 
8
29
  const useSolanaWallet = () => {
@@ -10,19 +31,23 @@ const useSolanaWallet = () => {
10
31
  provider,
11
32
  web3Auth
12
33
  } = useWeb3Auth.useWeb3Auth();
34
+ const {
35
+ chainNamespace
36
+ } = useChain.useChain();
13
37
  const [accounts, setAccounts] = react.useState(null);
14
38
  const solanaWallet = react.useMemo(() => {
15
39
  if (!provider) return null;
40
+ if (chainNamespace !== noModal.CHAIN_NAMESPACES.SOLANA) return null;
16
41
  return new noModal.SolanaWallet(provider);
17
- }, [provider]);
42
+ }, [provider, chainNamespace]);
18
43
  const connection = react.useMemo(() => {
19
- if (!web3Auth || !provider) return null;
44
+ if (!web3Auth || !provider || chainNamespace !== noModal.CHAIN_NAMESPACES.SOLANA) return null;
20
45
  return new web3_js.Connection(web3Auth.currentChain.rpcTarget);
21
- }, [web3Auth, provider]);
46
+ }, [web3Auth, provider, chainNamespace]);
22
47
  react.useEffect(() => {
23
48
  const init = async () => {
24
- var _web3Auth$currentChai;
25
- if (!(web3Auth !== null && web3Auth !== void 0 && (_web3Auth$currentChai = web3Auth.currentChain) !== null && _web3Auth$currentChai !== void 0 && _web3Auth$currentChai.chainNamespace) || web3Auth.currentChain.chainNamespace !== noModal.CHAIN_NAMESPACES.SOLANA) {
49
+ if (chainNamespace !== noModal.CHAIN_NAMESPACES.SOLANA) {
50
+ setAccounts(null);
26
51
  return;
27
52
  }
28
53
  if (!solanaWallet) return;
@@ -32,7 +57,7 @@ const useSolanaWallet = () => {
32
57
  }
33
58
  };
34
59
  if (solanaWallet) init();
35
- }, [solanaWallet, web3Auth]);
60
+ }, [solanaWallet, chainNamespace]);
36
61
  return {
37
62
  solanaWallet,
38
63
  accounts,
@@ -32,10 +32,13 @@ var constants = require('./constants.js');
32
32
 
33
33
  const _excluded = ["children"];
34
34
  const WEB3AUTH_CONNECTOR_ID = "web3auth";
35
+ function getWeb3authConnector(config) {
36
+ return config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
37
+ }
35
38
  // Helper to initialize connectors for the given wallets
36
39
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
40
  async function setupConnector(provider, config) {
38
- let connector = config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
41
+ let connector = getWeb3authConnector(config);
39
42
  if (connector) return connector;
40
43
  // Create new connector if not already existing
41
44
  connector = connectors.injected({
@@ -70,8 +73,15 @@ async function connectWeb3AuthWithWagmi(connector, config) {
70
73
  status: "connected"
71
74
  }));
72
75
  }
73
- async function disconnectWeb3AuthFromWagmi(config) {
76
+ function resetConnectorState(config) {
74
77
  config._internal.connectors.setState(prev => prev.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID));
78
+ config.connectors.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID);
79
+ }
80
+ async function disconnectWeb3AuthFromWagmi(config) {
81
+ var _config$storage3, _config$storage4;
82
+ const connector = getWeb3authConnector(config);
83
+ await Promise.all([(_config$storage3 = config.storage) === null || _config$storage3 === void 0 ? void 0 : _config$storage3.setItem(`${connector === null || connector === void 0 ? void 0 : connector.id}.disconnected`, true), (_config$storage4 = config.storage) === null || _config$storage4 === void 0 ? void 0 : _config$storage4.removeItem("injected.connected")]);
84
+ resetConnectorState(config);
75
85
  config.setState(state => _objectSpread(_objectSpread({}, state), {}, {
76
86
  chainId: state.chainId,
77
87
  connections: new Map(),
@@ -97,6 +107,12 @@ function Web3AuthWagmiProvider({
97
107
  onDisconnect: async () => {
98
108
  noModal.log.info("Disconnected from wagmi");
99
109
  if (isConnected) await disconnect();
110
+ const connector = getWeb3authConnector(wagmiConfig);
111
+ // reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
112
+ // from the connected provider
113
+ if (connector) {
114
+ resetConnectorState(wagmiConfig);
115
+ }
100
116
  }
101
117
  });
102
118
  react.useEffect(() => {
@@ -58,7 +58,7 @@ function ConnectWallet(props) {
58
58
  }
59
59
  };
60
60
  const walletDiscoverySupported = react.useMemo(() => {
61
- const supported = walletRegistry && Object.keys(walletRegistry.default || {}).length > 0 && Object.keys(walletRegistry.others || {}).length > 0;
61
+ const supported = walletRegistry && (Object.keys(walletRegistry.default || {}).length > 0 || Object.keys(walletRegistry.others || {}).length > 0);
62
62
  return supported;
63
63
  }, [walletRegistry]);
64
64
  const allUniqueButtons = react.useMemo(() => {
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ var vue = require('vue');
4
+ var useWeb3AuthInner = require('./useWeb3AuthInner.js');
5
+
6
+ const useChain = () => {
7
+ const context = useWeb3AuthInner.useWeb3AuthInner();
8
+ const chainId = vue.computed(() => {
9
+ var _context$web3Auth$val;
10
+ if (!((_context$web3Auth$val = context.web3Auth.value) !== null && _context$web3Auth$val !== void 0 && _context$web3Auth$val.currentChain)) return null;
11
+ return context.web3Auth.value.currentChain.chainId;
12
+ });
13
+ const chainNamespace = vue.computed(() => {
14
+ var _context$web3Auth$val2;
15
+ if (!((_context$web3Auth$val2 = context.web3Auth.value) !== null && _context$web3Auth$val2 !== void 0 && _context$web3Auth$val2.currentChain)) return null;
16
+ return context.web3Auth.value.currentChain.chainNamespace;
17
+ });
18
+ return {
19
+ chainId,
20
+ chainNamespace
21
+ };
22
+ };
23
+
24
+ exports.useChain = useChain;
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var useChain = require('./composables/useChain.js');
3
4
  var useCheckout = require('./composables/useCheckout.js');
4
5
  var useEnableMFA = require('./composables/useEnableMFA.js');
5
6
  var useFunding = require('./composables/useFunding.js');
@@ -19,6 +20,7 @@ var Web3AuthProvider = require('./Web3AuthProvider.js');
19
20
 
20
21
 
21
22
 
23
+ exports.useChain = useChain.useChain;
22
24
  exports.useCheckout = useCheckout.useCheckout;
23
25
  exports.useEnableMFA = useEnableMFA.useEnableMFA;
24
26
  exports.useFunding = useFunding.useFunding;
@@ -3,6 +3,7 @@
3
3
  var web3_js = require('@solana/web3.js');
4
4
  var noModal = require('@web3auth/no-modal');
5
5
  var vue = require('vue');
6
+ var useChain = require('../../composables/useChain.js');
6
7
  require('@web3auth/no-modal/vue');
7
8
  var useWeb3Auth = require('../../composables/useWeb3Auth.js');
8
9
 
@@ -11,12 +12,19 @@ const useSolanaWallet = () => {
11
12
  provider,
12
13
  web3Auth
13
14
  } = useWeb3Auth.useWeb3Auth();
15
+ const {
16
+ chainNamespace
17
+ } = useChain.useChain();
14
18
  const accounts = vue.ref([]);
15
19
  const solanaWallet = vue.shallowRef(null);
16
20
  const connection = vue.shallowRef(null);
21
+ const isSolana = vue.computed(() => chainNamespace.value === noModal.CHAIN_NAMESPACES.SOLANA);
17
22
  const setupWallet = async () => {
18
- var _web3Auth$value, _web3Auth$value2;
19
- if (!((_web3Auth$value = web3Auth.value) !== null && _web3Auth$value !== void 0 && (_web3Auth$value = _web3Auth$value.currentChain) !== null && _web3Auth$value !== void 0 && _web3Auth$value.chainNamespace) || web3Auth.value.currentChain.chainNamespace !== noModal.CHAIN_NAMESPACES.SOLANA) {
23
+ var _web3Auth$value;
24
+ if (!isSolana.value) {
25
+ return;
26
+ }
27
+ if (!provider.value) {
20
28
  return;
21
29
  }
22
30
  solanaWallet.value = new noModal.SolanaWallet(provider.value);
@@ -24,19 +32,26 @@ const useSolanaWallet = () => {
24
32
  if ((result === null || result === void 0 ? void 0 : result.length) > 0) {
25
33
  accounts.value = result;
26
34
  }
27
- connection.value = new web3_js.Connection((_web3Auth$value2 = web3Auth.value) === null || _web3Auth$value2 === void 0 || (_web3Auth$value2 = _web3Auth$value2.currentChain) === null || _web3Auth$value2 === void 0 ? void 0 : _web3Auth$value2.rpcTarget);
35
+ if ((_web3Auth$value = web3Auth.value) !== null && _web3Auth$value !== void 0 && (_web3Auth$value = _web3Auth$value.currentChain) !== null && _web3Auth$value !== void 0 && _web3Auth$value.rpcTarget) {
36
+ connection.value = new web3_js.Connection(web3Auth.value.currentChain.rpcTarget);
37
+ }
38
+ };
39
+ const resetWallet = () => {
40
+ solanaWallet.value = null;
41
+ accounts.value = null;
42
+ connection.value = null;
28
43
  };
29
44
  if (provider.value && !solanaWallet.value) {
30
45
  setupWallet();
31
46
  }
32
- vue.watch(provider, async newVal => {
33
- if (!newVal && solanaWallet.value) {
34
- solanaWallet.value = null;
35
- accounts.value = null;
36
- connection.value = null;
47
+ vue.watch([provider, chainNamespace], async ([newProvider, newChainNamespace]) => {
48
+ if (!newProvider || newChainNamespace !== noModal.CHAIN_NAMESPACES.SOLANA) {
49
+ if (solanaWallet.value) {
50
+ resetWallet();
51
+ }
37
52
  return;
38
53
  }
39
- if (newVal && !solanaWallet.value) {
54
+ if (newProvider && !solanaWallet.value) {
40
55
  setupWallet();
41
56
  }
42
57
  }, {
@@ -14,10 +14,13 @@ var useWeb3AuthDisconnect = require('../composables/useWeb3AuthDisconnect.js');
14
14
  var constants = require('./constants.js');
15
15
 
16
16
  const WEB3AUTH_CONNECTOR_ID = "web3auth";
17
+ function getWeb3authConnector(config) {
18
+ return config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
19
+ }
17
20
  // Helper to initialize connectors for the given wallets
18
21
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
22
  async function setupConnector(provider, config) {
20
- let connector = config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
23
+ let connector = getWeb3authConnector(config);
21
24
  if (connector) return connector;
22
25
  // Create new connector if not already existing
23
26
  connector = connectors.injected({
@@ -52,8 +55,15 @@ async function connectWeb3AuthWithWagmi(connector, config) {
52
55
  status: "connected"
53
56
  }));
54
57
  }
55
- async function disconnectWeb3AuthFromWagmi(config) {
58
+ function resetConnectorState(config) {
56
59
  config._internal.connectors.setState(prev => prev.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID));
60
+ config.connectors.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID);
61
+ }
62
+ async function disconnectWeb3AuthFromWagmi(config) {
63
+ var _config$storage3, _config$storage4;
64
+ const connector = getWeb3authConnector(config);
65
+ await Promise.all([(_config$storage3 = config.storage) === null || _config$storage3 === void 0 ? void 0 : _config$storage3.setItem(`${connector === null || connector === void 0 ? void 0 : connector.id}.disconnected`, true), (_config$storage4 = config.storage) === null || _config$storage4 === void 0 ? void 0 : _config$storage4.removeItem("injected.connected")]);
66
+ resetConnectorState(config);
57
67
  config.setState(state => _objectSpread(_objectSpread({}, state), {}, {
58
68
  chainId: state.chainId,
59
69
  connections: new Map(),
@@ -79,6 +89,12 @@ const Web3AuthWagmiProvider = vue.defineComponent({
79
89
  onDisconnect: async () => {
80
90
  noModal.log.info("Disconnected from wagmi");
81
91
  if (isConnected.value) await disconnect();
92
+ const connector = getWeb3authConnector(wagmiConfig);
93
+ // reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
94
+ // from the connected provider
95
+ if (connector) {
96
+ resetConnectorState(wagmiConfig);
97
+ }
82
98
  }
83
99
  });
84
100
  vue.watch(isConnected, async newIsConnected => {
@@ -1,3 +1,4 @@
1
+ export * from "./useChain";
1
2
  export * from "./useCheckout";
2
3
  export * from "./useEnableMFA";
3
4
  export * from "./useFunding";
@@ -0,0 +1,6 @@
1
+ import { ChainNamespaceType } from "@web3auth/no-modal";
2
+ export type IUseChain = {
3
+ chainId: string | null;
4
+ chainNamespace: ChainNamespaceType | null;
5
+ };
6
+ export declare const useChain: () => IUseChain;
@@ -1,3 +1,3 @@
1
1
  import { IWeb3AuthInnerContext } from "../interfaces";
2
- export type IUseWeb3Auth = Omit<IWeb3AuthInnerContext, "isMFAEnabled" | "setIsMFAEnabled">;
2
+ export type IUseWeb3Auth = Omit<IWeb3AuthInnerContext, "isMFAEnabled" | "setIsMFAEnabled" | "chainId" | "chainNamespace">;
3
3
  export declare const useWeb3Auth: () => IUseWeb3Auth;
@@ -1,3 +1,4 @@
1
+ export * from "./useChain";
1
2
  export * from "./useCheckout";
2
3
  export * from "./useEnableMFA";
3
4
  export * from "./useFunding";
@@ -0,0 +1,7 @@
1
+ import { ChainNamespaceType } from "@web3auth/no-modal";
2
+ import { ComputedRef } from "vue";
3
+ export type IUseChain = {
4
+ chainId: ComputedRef<string | null>;
5
+ chainNamespace: ComputedRef<ChainNamespaceType | null>;
6
+ };
7
+ export declare const useChain: () => IUseChain;
@@ -1,6 +1,6 @@
1
1
  import { EVM_CONNECTORS } from '@web3auth/no-modal';
2
2
 
3
- const version = "10.6.0";
3
+ const version = "10.8.0";
4
4
  const defaultConnectorsModalConfig = {
5
5
  hideWalletDiscovery: false,
6
6
  connectors: {
@@ -12,6 +12,8 @@ function Web3AuthInnerProvider(params) {
12
12
  const {
13
13
  web3AuthOptions
14
14
  } = config;
15
+ const [chainId, setChainId] = useState(null);
16
+ const [chainNamespace, setChainNamespace] = useState(null);
15
17
  const [isInitializing, setIsInitializing] = useState(false);
16
18
  const [initError, setInitError] = useState(null);
17
19
  const [provider, setProvider] = useState(null);
@@ -31,6 +33,7 @@ function Web3AuthInnerProvider(params) {
31
33
  const controller = new AbortController();
32
34
  async function init() {
33
35
  try {
36
+ var _web3Auth$currentChai;
34
37
  setInitError(null);
35
38
  setIsInitializing(true);
36
39
  web3Auth.setAnalyticsProperties({
@@ -39,6 +42,8 @@ function Web3AuthInnerProvider(params) {
39
42
  await web3Auth.init({
40
43
  signal: controller.signal
41
44
  });
45
+ setChainId(web3Auth.currentChainId);
46
+ setChainNamespace((_web3Auth$currentChai = web3Auth.currentChain) === null || _web3Auth$currentChai === void 0 ? void 0 : _web3Auth$currentChai.chainNamespace);
42
47
  } catch (error) {
43
48
  setInitError(error);
44
49
  } finally {
@@ -50,6 +55,19 @@ function Web3AuthInnerProvider(params) {
50
55
  controller.abort();
51
56
  };
52
57
  }, [web3Auth, config]);
58
+ useEffect(() => {
59
+ const handleChainChange = async chainId => {
60
+ var _web3Auth$currentChai2;
61
+ setChainId(chainId);
62
+ setChainNamespace(web3Auth === null || web3Auth === void 0 || (_web3Auth$currentChai2 = web3Auth.currentChain) === null || _web3Auth$currentChai2 === void 0 ? void 0 : _web3Auth$currentChai2.chainNamespace);
63
+ };
64
+ if (provider) {
65
+ provider.on("chainChanged", handleChainChange);
66
+ return () => {
67
+ provider.off("chainChanged", handleChainChange);
68
+ };
69
+ }
70
+ }, [web3Auth, provider]);
53
71
  useEffect(() => {
54
72
  const notReadyListener = () => setStatus(web3Auth.status);
55
73
  const readyListener = () => {
@@ -120,10 +138,12 @@ function Web3AuthInnerProvider(params) {
120
138
  isInitializing,
121
139
  initError,
122
140
  isMFAEnabled,
141
+ chainId,
142
+ chainNamespace,
123
143
  getPlugin,
124
144
  setIsMFAEnabled
125
145
  };
126
- }, [web3Auth, isConnected, isMFAEnabled, setIsMFAEnabled, isInitialized, provider, status, getPlugin, isInitializing, initError]);
146
+ }, [web3Auth, isConnected, isMFAEnabled, setIsMFAEnabled, isInitialized, provider, status, getPlugin, isInitializing, initError, chainId, chainNamespace]);
127
147
  return /*#__PURE__*/createElement(Web3AuthInnerContext.Provider, {
128
148
  value
129
149
  }, children);
@@ -0,0 +1,14 @@
1
+ import { useWeb3AuthInner } from './useWeb3AuthInner.js';
2
+
3
+ const useChain = () => {
4
+ const {
5
+ chainId,
6
+ chainNamespace
7
+ } = useWeb3AuthInner();
8
+ return {
9
+ chainId,
10
+ chainNamespace
11
+ };
12
+ };
13
+
14
+ export { useChain };
@@ -1,3 +1,4 @@
1
+ export { useChain } from './hooks/useChain.js';
1
2
  export { useCheckout } from './hooks/useCheckout.js';
2
3
  export { useEnableMFA } from './hooks/useEnableMFA.js';
3
4
  export { useFunding } from './hooks/useFunding.js';
@@ -1,6 +1,25 @@
1
1
  import { Connection } from '@solana/web3.js';
2
- import { SolanaWallet, CHAIN_NAMESPACES } from '@web3auth/no-modal';
2
+ import { CHAIN_NAMESPACES, SolanaWallet } from '@web3auth/no-modal';
3
3
  import { useState, useMemo, useEffect } from 'react';
4
+ import { useChain } from '../../hooks/useChain.js';
5
+ import '@babel/runtime/helpers/objectSpread2';
6
+ import '@babel/runtime/helpers/defineProperty';
7
+ import '@web3auth/auth';
8
+ import 'deepmerge';
9
+ import '../../../config.js';
10
+ import '../../../ui/config.js';
11
+ import '../../../ui/css/index.css.js';
12
+ import 'bowser';
13
+ import 'react-dom/client';
14
+ import '@toruslabs/http-helpers';
15
+ import 'clsx';
16
+ import 'tailwind-merge';
17
+ import 'react/jsx-runtime';
18
+ import 'react-i18next';
19
+ import '../../../ui/localeImport.js';
20
+ import 'classnames';
21
+ import 'react-qrcode-logo';
22
+ import '../../../ui/components/Login/Login.js';
4
23
  import { useWeb3Auth } from '../../hooks/useWeb3Auth.js';
5
24
 
6
25
  const useSolanaWallet = () => {
@@ -8,19 +27,23 @@ const useSolanaWallet = () => {
8
27
  provider,
9
28
  web3Auth
10
29
  } = useWeb3Auth();
30
+ const {
31
+ chainNamespace
32
+ } = useChain();
11
33
  const [accounts, setAccounts] = useState(null);
12
34
  const solanaWallet = useMemo(() => {
13
35
  if (!provider) return null;
36
+ if (chainNamespace !== CHAIN_NAMESPACES.SOLANA) return null;
14
37
  return new SolanaWallet(provider);
15
- }, [provider]);
38
+ }, [provider, chainNamespace]);
16
39
  const connection = useMemo(() => {
17
- if (!web3Auth || !provider) return null;
40
+ if (!web3Auth || !provider || chainNamespace !== CHAIN_NAMESPACES.SOLANA) return null;
18
41
  return new Connection(web3Auth.currentChain.rpcTarget);
19
- }, [web3Auth, provider]);
42
+ }, [web3Auth, provider, chainNamespace]);
20
43
  useEffect(() => {
21
44
  const init = async () => {
22
- var _web3Auth$currentChai;
23
- if (!(web3Auth !== null && web3Auth !== void 0 && (_web3Auth$currentChai = web3Auth.currentChain) !== null && _web3Auth$currentChai !== void 0 && _web3Auth$currentChai.chainNamespace) || web3Auth.currentChain.chainNamespace !== CHAIN_NAMESPACES.SOLANA) {
45
+ if (chainNamespace !== CHAIN_NAMESPACES.SOLANA) {
46
+ setAccounts(null);
24
47
  return;
25
48
  }
26
49
  if (!solanaWallet) return;
@@ -30,7 +53,7 @@ const useSolanaWallet = () => {
30
53
  }
31
54
  };
32
55
  if (solanaWallet) init();
33
- }, [solanaWallet, web3Auth]);
56
+ }, [solanaWallet, chainNamespace]);
34
57
  return {
35
58
  solanaWallet,
36
59
  accounts,
@@ -28,11 +28,14 @@ import { defaultWagmiConfig } from './constants.js';
28
28
 
29
29
  const _excluded = ["children"];
30
30
  const WEB3AUTH_CONNECTOR_ID = "web3auth";
31
+ function getWeb3authConnector(config) {
32
+ return config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
33
+ }
31
34
 
32
35
  // Helper to initialize connectors for the given wallets
33
36
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
37
  async function setupConnector(provider, config) {
35
- let connector = config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
38
+ let connector = getWeb3authConnector(config);
36
39
  if (connector) return connector;
37
40
 
38
41
  // Create new connector if not already existing
@@ -69,8 +72,15 @@ async function connectWeb3AuthWithWagmi(connector, config) {
69
72
  status: "connected"
70
73
  }));
71
74
  }
72
- async function disconnectWeb3AuthFromWagmi(config) {
75
+ function resetConnectorState(config) {
73
76
  config._internal.connectors.setState(prev => prev.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID));
77
+ config.connectors.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID);
78
+ }
79
+ async function disconnectWeb3AuthFromWagmi(config) {
80
+ var _config$storage3, _config$storage4;
81
+ const connector = getWeb3authConnector(config);
82
+ await Promise.all([(_config$storage3 = config.storage) === null || _config$storage3 === void 0 ? void 0 : _config$storage3.setItem(`${connector === null || connector === void 0 ? void 0 : connector.id}.disconnected`, true), (_config$storage4 = config.storage) === null || _config$storage4 === void 0 ? void 0 : _config$storage4.removeItem("injected.connected")]);
83
+ resetConnectorState(config);
74
84
  config.setState(state => _objectSpread(_objectSpread({}, state), {}, {
75
85
  chainId: state.chainId,
76
86
  connections: new Map(),
@@ -96,6 +106,12 @@ function Web3AuthWagmiProvider({
96
106
  onDisconnect: async () => {
97
107
  log.info("Disconnected from wagmi");
98
108
  if (isConnected) await disconnect();
109
+ const connector = getWeb3authConnector(wagmiConfig);
110
+ // reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
111
+ // from the connected provider
112
+ if (connector) {
113
+ resetConnectorState(wagmiConfig);
114
+ }
99
115
  }
100
116
  });
101
117
  useEffect(() => {
@@ -56,7 +56,7 @@ function ConnectWallet(props) {
56
56
  }
57
57
  };
58
58
  const walletDiscoverySupported = useMemo(() => {
59
- const supported = walletRegistry && Object.keys(walletRegistry.default || {}).length > 0 && Object.keys(walletRegistry.others || {}).length > 0;
59
+ const supported = walletRegistry && (Object.keys(walletRegistry.default || {}).length > 0 || Object.keys(walletRegistry.others || {}).length > 0);
60
60
  return supported;
61
61
  }, [walletRegistry]);
62
62
  const allUniqueButtons = useMemo(() => {
@@ -0,0 +1,22 @@
1
+ import { computed } from 'vue';
2
+ import { useWeb3AuthInner } from './useWeb3AuthInner.js';
3
+
4
+ const useChain = () => {
5
+ const context = useWeb3AuthInner();
6
+ const chainId = computed(() => {
7
+ var _context$web3Auth$val;
8
+ if (!((_context$web3Auth$val = context.web3Auth.value) !== null && _context$web3Auth$val !== void 0 && _context$web3Auth$val.currentChain)) return null;
9
+ return context.web3Auth.value.currentChain.chainId;
10
+ });
11
+ const chainNamespace = computed(() => {
12
+ var _context$web3Auth$val2;
13
+ if (!((_context$web3Auth$val2 = context.web3Auth.value) !== null && _context$web3Auth$val2 !== void 0 && _context$web3Auth$val2.currentChain)) return null;
14
+ return context.web3Auth.value.currentChain.chainNamespace;
15
+ });
16
+ return {
17
+ chainId,
18
+ chainNamespace
19
+ };
20
+ };
21
+
22
+ export { useChain };
@@ -1,3 +1,4 @@
1
+ export { useChain } from './composables/useChain.js';
1
2
  export { useCheckout } from './composables/useCheckout.js';
2
3
  export { useEnableMFA } from './composables/useEnableMFA.js';
3
4
  export { useFunding } from './composables/useFunding.js';