@web3auth/no-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 (28) hide show
  1. package/dist/lib.cjs/base/utils.js +1 -1
  2. package/dist/lib.cjs/react/context/Web3AuthInnerContext.js +21 -1
  3. package/dist/lib.cjs/react/hooks/useChain.js +16 -0
  4. package/dist/lib.cjs/react/index.js +2 -0
  5. package/dist/lib.cjs/react/solana/hooks/useSolanaWallet.js +14 -7
  6. package/dist/lib.cjs/react/wagmi/provider.js +19 -4
  7. package/dist/lib.cjs/types/base/hooks/index.d.ts +3 -0
  8. package/dist/lib.cjs/types/react/hooks/index.d.ts +1 -0
  9. package/dist/lib.cjs/types/react/hooks/useChain.d.ts +6 -0
  10. package/dist/lib.cjs/types/react/hooks/useWeb3Auth.d.ts +1 -1
  11. package/dist/lib.cjs/types/vue/composables/index.d.ts +1 -0
  12. package/dist/lib.cjs/types/vue/composables/useChain.d.ts +7 -0
  13. package/dist/lib.cjs/vue/composables/useChain.js +24 -0
  14. package/dist/lib.cjs/vue/index.js +2 -0
  15. package/dist/lib.cjs/vue/solana/composables/useSolanaWallet.js +24 -9
  16. package/dist/lib.cjs/vue/wagmi/provider.js +21 -8
  17. package/dist/lib.esm/base/utils.js +1 -1
  18. package/dist/lib.esm/react/context/Web3AuthInnerContext.js +21 -1
  19. package/dist/lib.esm/react/hooks/useChain.js +14 -0
  20. package/dist/lib.esm/react/index.js +1 -0
  21. package/dist/lib.esm/react/solana/hooks/useSolanaWallet.js +12 -7
  22. package/dist/lib.esm/react/wagmi/provider.js +18 -3
  23. package/dist/lib.esm/vue/composables/useChain.js +22 -0
  24. package/dist/lib.esm/vue/index.js +1 -0
  25. package/dist/lib.esm/vue/solana/composables/useSolanaWallet.js +25 -10
  26. package/dist/lib.esm/vue/wagmi/provider.js +21 -8
  27. package/dist/noModal.umd.min.js +1 -1
  28. package/package.json +7 -7
@@ -145,7 +145,7 @@ const getWalletServicesAnalyticsProperties = walletServicesConfig => {
145
145
  ws_default_portfolio: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig1 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig1 === void 0 ? void 0 : _walletServicesConfig1.defaultPortfolio
146
146
  };
147
147
  };
148
- const sdkVersion = "10.6.0";
148
+ const sdkVersion = "10.8.0";
149
149
  const getErrorAnalyticsProperties = error => {
150
150
  try {
151
151
  const code = error instanceof index.Web3AuthError ? error.code : error === null || error === void 0 ? void 0 : error.code;
@@ -30,6 +30,8 @@ function Web3AuthInnerProvider(params) {
30
30
  setProvider(null);
31
31
  return new noModal.Web3AuthNoModal(web3AuthOptions, initialState);
32
32
  }, [web3AuthOptions, initialState]);
33
+ const [chainId, setChainId] = react.useState(null);
34
+ const [chainNamespace, setChainNamespace] = react.useState(null);
33
35
  const [isInitializing, setIsInitializing] = react.useState(false);
34
36
  const [initError, setInitError] = react.useState(null);
35
37
  const [isConnected, setIsConnected] = react.useState(false);
@@ -45,6 +47,7 @@ function Web3AuthInnerProvider(params) {
45
47
  const controller = new AbortController();
46
48
  async function init() {
47
49
  try {
50
+ var _web3Auth$currentChai;
48
51
  setInitError(null);
49
52
  setIsInitializing(true);
50
53
  web3Auth.setAnalyticsProperties({
@@ -53,6 +56,8 @@ function Web3AuthInnerProvider(params) {
53
56
  await web3Auth.init({
54
57
  signal: controller.signal
55
58
  });
59
+ setChainId(web3Auth.currentChainId);
60
+ setChainNamespace((_web3Auth$currentChai = web3Auth.currentChain) === null || _web3Auth$currentChai === void 0 ? void 0 : _web3Auth$currentChai.chainNamespace);
56
61
  } catch (error) {
57
62
  setInitError(error);
58
63
  } finally {
@@ -64,6 +69,19 @@ function Web3AuthInnerProvider(params) {
64
69
  controller.abort();
65
70
  };
66
71
  }, [web3Auth]);
72
+ react.useEffect(() => {
73
+ const handleChainChange = async chainId => {
74
+ var _web3Auth$currentChai2;
75
+ setChainId(chainId);
76
+ setChainNamespace(web3Auth === null || web3Auth === void 0 || (_web3Auth$currentChai2 = web3Auth.currentChain) === null || _web3Auth$currentChai2 === void 0 ? void 0 : _web3Auth$currentChai2.chainNamespace);
77
+ };
78
+ if (provider) {
79
+ provider.on("chainChanged", handleChainChange);
80
+ return () => {
81
+ provider.off("chainChanged", handleChainChange);
82
+ };
83
+ }
84
+ }, [web3Auth, provider]);
67
85
  react.useEffect(() => {
68
86
  const notReadyListener = () => setStatus(constants.CONNECTOR_STATUS.NOT_READY);
69
87
  const readyListener = () => {
@@ -133,10 +151,12 @@ function Web3AuthInnerProvider(params) {
133
151
  isInitializing,
134
152
  initError,
135
153
  isMFAEnabled,
154
+ chainId,
155
+ chainNamespace,
136
156
  getPlugin,
137
157
  setIsMFAEnabled
138
158
  };
139
- }, [web3Auth, isConnected, isInitialized, provider, status, getPlugin, isInitializing, initError, isMFAEnabled, setIsMFAEnabled]);
159
+ }, [web3Auth, isConnected, isInitialized, provider, status, getPlugin, isInitializing, initError, isMFAEnabled, setIsMFAEnabled, chainId, chainNamespace]);
140
160
  return react.createElement(Web3AuthInnerContext.Provider, {
141
161
  value
142
162
  }, 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;
@@ -23,6 +23,9 @@ require('../../../providers/base-provider/CommonJRPCProvider.js');
23
23
  require('../../../providers/base-provider/commonPrivateKeyProvider.js');
24
24
  require('@web3auth/ws-embed');
25
25
  var solanaWallet = require('../../../providers/solana-provider/solanaWallet.js');
26
+ var useChain = require('../../hooks/useChain.js');
27
+ require('../../context/WalletServicesInnerContext.js');
28
+ require('../../context/Web3AuthInnerContext.js');
26
29
  var useWeb3Auth = require('../../hooks/useWeb3Auth.js');
27
30
 
28
31
  const useSolanaWallet = () => {
@@ -30,29 +33,33 @@ const useSolanaWallet = () => {
30
33
  provider,
31
34
  web3Auth
32
35
  } = useWeb3Auth.useWeb3Auth();
36
+ const {
37
+ chainNamespace
38
+ } = useChain.useChain();
33
39
  const [accounts, setAccounts] = react.useState(null);
34
40
  const solanaWallet$1 = react.useMemo(() => {
35
41
  if (!provider) return null;
42
+ if (chainNamespace !== baseControllers.CHAIN_NAMESPACES.SOLANA) return null;
36
43
  return new solanaWallet.SolanaWallet(provider);
37
- }, [provider]);
44
+ }, [provider, chainNamespace]);
38
45
  const connection = react.useMemo(() => {
39
- if (!web3Auth || !provider) return null;
46
+ if (!web3Auth || !provider || chainNamespace !== baseControllers.CHAIN_NAMESPACES.SOLANA) return null;
40
47
  return new web3_js.Connection(web3Auth.currentChain.rpcTarget);
41
- }, [web3Auth, provider]);
48
+ }, [web3Auth, provider, chainNamespace]);
42
49
  react.useEffect(() => {
43
50
  const init = async () => {
44
- var _web3Auth$currentChai;
45
- if (!solanaWallet$1) return;
46
- if (!(web3Auth !== null && web3Auth !== void 0 && (_web3Auth$currentChai = web3Auth.currentChain) !== null && _web3Auth$currentChai !== void 0 && _web3Auth$currentChai.chainNamespace) || web3Auth.currentChain.chainNamespace !== baseControllers.CHAIN_NAMESPACES.SOLANA) {
51
+ if (chainNamespace !== baseControllers.CHAIN_NAMESPACES.SOLANA) {
52
+ setAccounts(null);
47
53
  return;
48
54
  }
55
+ if (!solanaWallet$1) return;
49
56
  const accounts = await solanaWallet$1.getAccounts();
50
57
  if ((accounts === null || accounts === void 0 ? void 0 : accounts.length) > 0) {
51
58
  setAccounts(accounts);
52
59
  }
53
60
  };
54
61
  if (solanaWallet$1) init();
55
- }, [solanaWallet$1]);
62
+ }, [solanaWallet$1, chainNamespace]);
56
63
  return {
57
64
  solanaWallet: solanaWallet$1,
58
65
  accounts,
@@ -19,18 +19,21 @@ require('../../base/plugin/errors.js');
19
19
  require('../../base/plugin/IPlugin.js');
20
20
  require('@toruslabs/constants');
21
21
  require('@toruslabs/http-helpers');
22
- require('../context/WalletServicesInnerContext.js');
23
22
  require('../context/Web3AuthInnerContext.js');
23
+ require('../context/WalletServicesInnerContext.js');
24
24
  var useWeb3Auth = require('../hooks/useWeb3Auth.js');
25
25
  var useWeb3AuthDisconnect = require('../hooks/useWeb3AuthDisconnect.js');
26
26
  var constants = require('./constants.js');
27
27
 
28
28
  const _excluded = ["children"];
29
29
  const WEB3AUTH_CONNECTOR_ID = "web3auth";
30
+ function getWeb3authConnector(config) {
31
+ return config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
32
+ }
30
33
  // Helper to initialize connectors for the given wallets
31
34
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
35
  async function setupConnector(provider, config) {
33
- let connector = config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
36
+ let connector = getWeb3authConnector(config);
34
37
  if (connector) return connector;
35
38
  // Create new connector if not already existing
36
39
  connector = connectors.injected({
@@ -65,8 +68,15 @@ async function connectWeb3AuthWithWagmi(connector, config) {
65
68
  status: "connected"
66
69
  }));
67
70
  }
68
- async function disconnectWeb3AuthFromWagmi(config) {
71
+ function resetConnectorState(config) {
69
72
  config._internal.connectors.setState(prev => prev.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID));
73
+ config.connectors.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID);
74
+ }
75
+ async function disconnectWeb3AuthFromWagmi(config) {
76
+ var _config$storage3, _config$storage4;
77
+ const connector = getWeb3authConnector(config);
78
+ 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")]);
79
+ resetConnectorState(config);
70
80
  config.setState(state => _objectSpread(_objectSpread({}, state), {}, {
71
81
  chainId: state.chainId,
72
82
  connections: new Map(),
@@ -92,6 +102,12 @@ function Web3AuthWagmiProvider({
92
102
  onDisconnect: async () => {
93
103
  loglevel.log.info("Disconnected from wagmi");
94
104
  if (isConnected) await disconnect();
105
+ const connector = getWeb3authConnector(wagmiConfig);
106
+ // reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
107
+ // from the connected provider
108
+ if (connector) {
109
+ resetConnectorState(wagmiConfig);
110
+ }
95
111
  }
96
112
  });
97
113
  react.useEffect(() => {
@@ -192,7 +208,6 @@ function WagmiProvider(_ref) {
192
208
  });
193
209
  finalConfig.chains = [wagmiChains[0], ...wagmiChains.slice(1)];
194
210
  }
195
- if (!finalConfig.chains) return;
196
211
  return wagmi.createConfig(finalConfig);
197
212
  }, [config, web3Auth, isInitialized]);
198
213
  return react.createElement(wagmi.WagmiProvider, // typecast to WagmiProviderPropsBase to avoid type error
@@ -1,6 +1,9 @@
1
+ import type { ChainNamespaceType } from "../chain/IChainInterface";
1
2
  import { CONNECTOR_STATUS_TYPE, IProvider } from "../connector";
2
3
  import { IPlugin } from "../plugin";
3
4
  export interface IBaseWeb3AuthHookContext {
5
+ chainId: string | null;
6
+ chainNamespace: ChainNamespaceType | null;
4
7
  isInitialized: boolean;
5
8
  isInitializing: boolean;
6
9
  initError: unknown;
@@ -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 "../../base";
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 { ComputedRef } from "vue";
2
+ import { ChainNamespaceType } from "../../base";
3
+ export type IUseChain = {
4
+ chainId: ComputedRef<string | null>;
5
+ chainNamespace: ComputedRef<ChainNamespaceType | null>;
6
+ };
7
+ export declare const useChain: () => IUseChain;
@@ -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');
@@ -20,6 +21,7 @@ var Web3AuthProvider = require('./Web3AuthProvider.js');
20
21
 
21
22
 
22
23
 
24
+ exports.useChain = useChain.useChain;
23
25
  exports.useCheckout = useCheckout.useCheckout;
24
26
  exports.useEnableMFA = useEnableMFA.useEnableMFA;
25
27
  exports.useFunding = useFunding.useFunding;
@@ -4,6 +4,7 @@ var web3_js = require('@solana/web3.js');
4
4
  var vue = require('vue');
5
5
  var baseControllers = require('@toruslabs/base-controllers');
6
6
  var solanaWallet = require('../../../providers/solana-provider/solanaWallet.js');
7
+ var useChain = require('../../composables/useChain.js');
7
8
  require('@babel/runtime/helpers/objectSpread2');
8
9
  require('@babel/runtime/helpers/defineProperty');
9
10
  require('@segment/analytics-next');
@@ -24,12 +25,19 @@ const useSolanaWallet = () => {
24
25
  provider,
25
26
  web3Auth
26
27
  } = useWeb3Auth.useWeb3Auth();
28
+ const {
29
+ chainNamespace
30
+ } = useChain.useChain();
27
31
  const accounts = vue.ref([]);
28
32
  const solanaWallet$1 = vue.shallowRef(null);
29
33
  const connection = vue.shallowRef(null);
34
+ const isSolana = vue.computed(() => chainNamespace.value === baseControllers.CHAIN_NAMESPACES.SOLANA);
30
35
  const setupWallet = async () => {
31
- var _web3Auth$value, _web3Auth$value2;
32
- 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 !== baseControllers.CHAIN_NAMESPACES.SOLANA) {
36
+ var _web3Auth$value;
37
+ if (!isSolana.value) {
38
+ return;
39
+ }
40
+ if (!provider.value) {
33
41
  return;
34
42
  }
35
43
  solanaWallet$1.value = new solanaWallet.SolanaWallet(provider.value);
@@ -37,19 +45,26 @@ const useSolanaWallet = () => {
37
45
  if ((result === null || result === void 0 ? void 0 : result.length) > 0) {
38
46
  accounts.value = result;
39
47
  }
40
- 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);
48
+ if ((_web3Auth$value = web3Auth.value) !== null && _web3Auth$value !== void 0 && (_web3Auth$value = _web3Auth$value.currentChain) !== null && _web3Auth$value !== void 0 && _web3Auth$value.rpcTarget) {
49
+ connection.value = new web3_js.Connection(web3Auth.value.currentChain.rpcTarget);
50
+ }
51
+ };
52
+ const resetWallet = () => {
53
+ solanaWallet$1.value = null;
54
+ accounts.value = null;
55
+ connection.value = null;
41
56
  };
42
57
  if (provider.value && !solanaWallet$1.value) {
43
58
  setupWallet();
44
59
  }
45
- vue.watch(provider, async newVal => {
46
- if (!newVal && solanaWallet$1.value) {
47
- solanaWallet$1.value = null;
48
- accounts.value = null;
49
- connection.value = null;
60
+ vue.watch([provider, chainNamespace], async ([newProvider, newChainNamespace]) => {
61
+ if (!newProvider || newChainNamespace !== baseControllers.CHAIN_NAMESPACES.SOLANA) {
62
+ if (solanaWallet$1.value) {
63
+ resetWallet();
64
+ }
50
65
  return;
51
66
  }
52
- if (newVal && !solanaWallet$1.value) {
67
+ if (newProvider && !solanaWallet$1.value) {
53
68
  setupWallet();
54
69
  }
55
70
  }, {
@@ -24,10 +24,13 @@ var useWeb3AuthDisconnect = require('../composables/useWeb3AuthDisconnect.js');
24
24
  var constants = require('./constants.js');
25
25
 
26
26
  const WEB3AUTH_CONNECTOR_ID = "web3auth";
27
+ function getWeb3authConnector(config) {
28
+ return config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
29
+ }
27
30
  // Helper to initialize connectors for the given wallets
28
31
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
32
  async function setupConnector(provider, config) {
30
- let connector = config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
33
+ let connector = getWeb3authConnector(config);
31
34
  if (connector) return connector;
32
35
  // Create new connector if not already existing
33
36
  connector = connectors.injected({
@@ -62,8 +65,15 @@ async function connectWeb3AuthWithWagmi(connector, config) {
62
65
  status: "connected"
63
66
  }));
64
67
  }
65
- async function disconnectWeb3AuthFromWagmi(config) {
68
+ function resetConnectorState(config) {
66
69
  config._internal.connectors.setState(prev => prev.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID));
70
+ config.connectors.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID);
71
+ }
72
+ async function disconnectWeb3AuthFromWagmi(config) {
73
+ var _config$storage3, _config$storage4;
74
+ const connector = getWeb3authConnector(config);
75
+ 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")]);
76
+ resetConnectorState(config);
67
77
  config.setState(state => _objectSpread(_objectSpread({}, state), {}, {
68
78
  chainId: state.chainId,
69
79
  connections: new Map(),
@@ -89,6 +99,12 @@ const Web3AuthWagmiProvider = vue.defineComponent({
89
99
  onDisconnect: async () => {
90
100
  loglevel.log.info("Disconnected from wagmi");
91
101
  if (isConnected.value) await disconnect();
102
+ const connector = getWeb3authConnector(wagmiConfig);
103
+ // reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
104
+ // from the connected provider
105
+ if (connector) {
106
+ resetConnectorState(wagmiConfig);
107
+ }
92
108
  }
93
109
  });
94
110
  vue.watch(isConnected, async newIsConnected => {
@@ -223,12 +239,12 @@ const WagmiProvider = vue.defineComponent({
223
239
  }, props.config));
224
240
  }
225
241
  };
226
- vue.watch(isInitialized, newIsInitialized => {
242
+ vue.watch(isInitialized, (newIsInitialized, prevIsInitialized) => {
227
243
  var _web3Auth$value2;
228
244
  (_web3Auth$value2 = web3Auth.value) === null || _web3Auth$value2 === void 0 || _web3Auth$value2.setAnalyticsProperties({
229
245
  wagmi_enabled: true
230
246
  });
231
- if (newIsInitialized && !finalConfig.value) {
247
+ if (newIsInitialized && !prevIsInitialized) {
232
248
  finalConfig.value = defineWagmiConfig();
233
249
  hydrateWagmiConfig();
234
250
  configKey.value = auth.randomId();
@@ -245,10 +261,7 @@ const WagmiProvider = vue.defineComponent({
245
261
  };
246
262
  },
247
263
  render() {
248
- if (!this.finalConfig) return null;
249
- return vue.h(Web3AuthWagmiInnerProvider,
250
- // This key is used to remount the provider when the config changes.
251
- {
264
+ return vue.h(Web3AuthWagmiInnerProvider, {
252
265
  config: this.finalConfig,
253
266
  key: this.configKey
254
267
  }, {
@@ -145,7 +145,7 @@ const getWalletServicesAnalyticsProperties = walletServicesConfig => {
145
145
  ws_default_portfolio: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig1 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig1 === void 0 ? void 0 : _walletServicesConfig1.defaultPortfolio
146
146
  };
147
147
  };
148
- const sdkVersion = "10.6.0";
148
+ const sdkVersion = "10.8.0";
149
149
  const getErrorAnalyticsProperties = error => {
150
150
  try {
151
151
  const code = error instanceof Web3AuthError ? error.code : error === null || error === void 0 ? void 0 : error.code;
@@ -18,6 +18,8 @@ function Web3AuthInnerProvider(params) {
18
18
  setProvider(null);
19
19
  return new Web3AuthNoModal(web3AuthOptions, initialState);
20
20
  }, [web3AuthOptions, initialState]);
21
+ const [chainId, setChainId] = useState(null);
22
+ const [chainNamespace, setChainNamespace] = useState(null);
21
23
  const [isInitializing, setIsInitializing] = useState(false);
22
24
  const [initError, setInitError] = useState(null);
23
25
  const [isConnected, setIsConnected] = useState(false);
@@ -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]);
60
+ 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
  useEffect(() => {
56
74
  const notReadyListener = () => setStatus(CONNECTOR_STATUS.NOT_READY);
57
75
  const readyListener = () => {
@@ -121,10 +139,12 @@ function Web3AuthInnerProvider(params) {
121
139
  isInitializing,
122
140
  initError,
123
141
  isMFAEnabled,
142
+ chainId,
143
+ chainNamespace,
124
144
  getPlugin,
125
145
  setIsMFAEnabled
126
146
  };
127
- }, [web3Auth, isConnected, isInitialized, provider, status, getPlugin, isInitializing, initError, isMFAEnabled, setIsMFAEnabled]);
147
+ }, [web3Auth, isConnected, isInitialized, provider, status, getPlugin, isInitializing, initError, isMFAEnabled, setIsMFAEnabled, chainId, chainNamespace]);
128
148
  return createElement(Web3AuthInnerContext.Provider, {
129
149
  value
130
150
  }, 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,4 +1,5 @@
1
1
  export { Web3AuthProvider } from './Web3AuthProvider.js';
2
+ export { useChain } from './hooks/useChain.js';
2
3
  export { useCheckout } from './hooks/useCheckout.js';
3
4
  export { useEnableMFA } from './hooks/useEnableMFA.js';
4
5
  export { useFunding } from './hooks/useFunding.js';
@@ -2,6 +2,7 @@ import { Connection } from '@solana/web3.js';
2
2
  import { useState, useMemo, useEffect } from 'react';
3
3
  import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
4
4
  import { useWeb3Auth } from '../../hooks/useWeb3Auth.js';
5
+ import { useChain } from '../../hooks/useChain.js';
5
6
  import { SolanaWallet } from '../../../providers/solana-provider/solanaWallet.js';
6
7
 
7
8
  const useSolanaWallet = () => {
@@ -9,29 +10,33 @@ const useSolanaWallet = () => {
9
10
  provider,
10
11
  web3Auth
11
12
  } = useWeb3Auth();
13
+ const {
14
+ chainNamespace
15
+ } = useChain();
12
16
  const [accounts, setAccounts] = useState(null);
13
17
  const solanaWallet = useMemo(() => {
14
18
  if (!provider) return null;
19
+ if (chainNamespace !== CHAIN_NAMESPACES.SOLANA) return null;
15
20
  return new SolanaWallet(provider);
16
- }, [provider]);
21
+ }, [provider, chainNamespace]);
17
22
  const connection = useMemo(() => {
18
- if (!web3Auth || !provider) return null;
23
+ if (!web3Auth || !provider || chainNamespace !== CHAIN_NAMESPACES.SOLANA) return null;
19
24
  return new Connection(web3Auth.currentChain.rpcTarget);
20
- }, [web3Auth, provider]);
25
+ }, [web3Auth, provider, chainNamespace]);
21
26
  useEffect(() => {
22
27
  const init = async () => {
23
- var _web3Auth$currentChai;
24
- if (!solanaWallet) return;
25
- if (!(web3Auth !== null && web3Auth !== void 0 && (_web3Auth$currentChai = web3Auth.currentChain) !== null && _web3Auth$currentChai !== void 0 && _web3Auth$currentChai.chainNamespace) || web3Auth.currentChain.chainNamespace !== CHAIN_NAMESPACES.SOLANA) {
28
+ if (chainNamespace !== CHAIN_NAMESPACES.SOLANA) {
29
+ setAccounts(null);
26
30
  return;
27
31
  }
32
+ if (!solanaWallet) return;
28
33
  const accounts = await solanaWallet.getAccounts();
29
34
  if ((accounts === null || accounts === void 0 ? void 0 : accounts.length) > 0) {
30
35
  setAccounts(accounts);
31
36
  }
32
37
  };
33
38
  if (solanaWallet) init();
34
- }, [solanaWallet]);
39
+ }, [solanaWallet, chainNamespace]);
35
40
  return {
36
41
  solanaWallet,
37
42
  accounts,
@@ -13,11 +13,14 @@ import { log } from '../../base/loglevel.js';
13
13
 
14
14
  const _excluded = ["children"];
15
15
  const WEB3AUTH_CONNECTOR_ID = "web3auth";
16
+ function getWeb3authConnector(config) {
17
+ return config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
18
+ }
16
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
 
23
26
  // Create new connector if not already existing
@@ -54,8 +57,15 @@ async function connectWeb3AuthWithWagmi(connector, config) {
54
57
  status: "connected"
55
58
  }));
56
59
  }
57
- async function disconnectWeb3AuthFromWagmi(config) {
60
+ function resetConnectorState(config) {
58
61
  config._internal.connectors.setState(prev => prev.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID));
62
+ config.connectors.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID);
63
+ }
64
+ async function disconnectWeb3AuthFromWagmi(config) {
65
+ var _config$storage3, _config$storage4;
66
+ const connector = getWeb3authConnector(config);
67
+ 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")]);
68
+ resetConnectorState(config);
59
69
  config.setState(state => _objectSpread(_objectSpread({}, state), {}, {
60
70
  chainId: state.chainId,
61
71
  connections: new Map(),
@@ -81,6 +91,12 @@ function Web3AuthWagmiProvider({
81
91
  onDisconnect: async () => {
82
92
  log.info("Disconnected from wagmi");
83
93
  if (isConnected) await disconnect();
94
+ const connector = getWeb3authConnector(wagmiConfig);
95
+ // reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
96
+ // from the connected provider
97
+ if (connector) {
98
+ resetConnectorState(wagmiConfig);
99
+ }
84
100
  }
85
101
  });
86
102
  useEffect(() => {
@@ -181,7 +197,6 @@ function WagmiProvider(_ref) {
181
197
  });
182
198
  finalConfig.chains = [wagmiChains[0], ...wagmiChains.slice(1)];
183
199
  }
184
- if (!finalConfig.chains) return;
185
200
  return createConfig(finalConfig);
186
201
  }, [config, web3Auth, isInitialized]);
187
202
  return createElement(WagmiProvider$1, // typecast to WagmiProviderPropsBase to avoid type error
@@ -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 };