@web3auth/no-modal 11.0.0-beta.0 → 11.0.0-beta.1

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 (100) hide show
  1. package/dist/lib.cjs/account-linking/index.js +8 -0
  2. package/dist/lib.cjs/account-linking/react.js +95 -0
  3. package/dist/lib.cjs/account-linking/rest.js +54 -0
  4. package/dist/lib.cjs/account-linking/vue.js +98 -0
  5. package/dist/lib.cjs/base/analytics.js +17 -2
  6. package/dist/lib.cjs/base/connector/constants.js +2 -0
  7. package/dist/lib.cjs/base/errors/index.js +48 -0
  8. package/dist/lib.cjs/base/utils.js +15 -3
  9. package/dist/lib.cjs/connectors/auth-connector/authConnector.js +427 -50
  10. package/dist/lib.cjs/connectors/base-evm-connector/baseEvmConnector.js +42 -23
  11. package/dist/lib.cjs/connectors/base-solana-connector/baseSolanaConnector.js +41 -24
  12. package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +76 -45
  13. package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +41 -13
  14. package/dist/lib.cjs/index.js +20 -13
  15. package/dist/lib.cjs/noModal.js +811 -110
  16. package/dist/lib.cjs/plugins/wallet-services-plugin/plugin.js +1 -1
  17. package/dist/lib.cjs/providers/base-provider/baseProvider.js +65 -33
  18. package/dist/lib.cjs/react/context/useWeb3AuthInnerContextValue.js +34 -20
  19. package/dist/lib.cjs/react/hooks/useWallets.js +51 -0
  20. package/dist/lib.cjs/react/hooks/useWeb3AuthConnect.js +2 -2
  21. package/dist/lib.cjs/react/index.js +2 -0
  22. package/dist/lib.cjs/react/solana/hooks/useSolanaWallet.js +2 -2
  23. package/dist/lib.cjs/react/solana/provider.js +2 -0
  24. package/dist/lib.cjs/types/account-linking/index.d.ts +2 -0
  25. package/dist/lib.cjs/types/account-linking/interfaces.d.ts +90 -0
  26. package/dist/lib.cjs/types/account-linking/react.d.ts +19 -0
  27. package/dist/lib.cjs/types/account-linking/rest.d.ts +9 -0
  28. package/dist/lib.cjs/types/account-linking/vue.d.ts +20 -0
  29. package/dist/lib.cjs/types/base/analytics.d.ts +9 -0
  30. package/dist/lib.cjs/types/base/connector/baseConnector.d.ts +5 -0
  31. package/dist/lib.cjs/types/base/connector/constants.d.ts +2 -0
  32. package/dist/lib.cjs/types/base/connector/interfaces.d.ts +51 -6
  33. package/dist/lib.cjs/types/base/core/IWeb3Auth.d.ts +39 -2
  34. package/dist/lib.cjs/types/base/errors/index.d.ts +13 -0
  35. package/dist/lib.cjs/types/base/interfaces.d.ts +3 -1
  36. package/dist/lib.cjs/types/base/utils.d.ts +7 -1
  37. package/dist/lib.cjs/types/connectors/auth-connector/authConnector.d.ts +27 -3
  38. package/dist/lib.cjs/types/connectors/auth-connector/interface.d.ts +77 -2
  39. package/dist/lib.cjs/types/connectors/base-evm-connector/baseEvmConnector.d.ts +6 -0
  40. package/dist/lib.cjs/types/connectors/base-solana-connector/baseSolanaConnector.d.ts +6 -0
  41. package/dist/lib.cjs/types/index.d.ts +1 -0
  42. package/dist/lib.cjs/types/noModal.d.ts +104 -5
  43. package/dist/lib.cjs/types/providers/base-provider/baseProvider.d.ts +7 -0
  44. package/dist/lib.cjs/types/react/hooks/index.d.ts +1 -0
  45. package/dist/lib.cjs/types/react/hooks/useWallets.d.ts +8 -0
  46. package/dist/lib.cjs/types/vue/composables/index.d.ts +1 -0
  47. package/dist/lib.cjs/types/vue/composables/useWallets.d.ts +9 -0
  48. package/dist/lib.cjs/vue/composables/useWallets.js +52 -0
  49. package/dist/lib.cjs/vue/composables/useWeb3AuthConnect.js +2 -2
  50. package/dist/lib.cjs/vue/index.js +2 -0
  51. package/dist/lib.cjs/vue/solana/composables/useSolanaWallet.js +2 -2
  52. package/dist/lib.cjs/vue/solana/provider.js +3 -0
  53. package/dist/lib.cjs/vue/useWeb3AuthInnerContextValue.js +13 -4
  54. package/dist/lib.cjs/vue/wagmi/provider.js +19 -7
  55. package/dist/lib.esm/account-linking/index.js +1 -0
  56. package/dist/lib.esm/account-linking/react.js +74 -0
  57. package/dist/lib.esm/account-linking/rest.js +51 -0
  58. package/dist/lib.esm/account-linking/vue.js +78 -0
  59. package/dist/lib.esm/base/analytics.js +17 -2
  60. package/dist/lib.esm/base/connector/constants.js +2 -0
  61. package/dist/lib.esm/base/errors/index.js +48 -1
  62. package/dist/lib.esm/base/utils.js +16 -4
  63. package/dist/lib.esm/connectors/auth-connector/authConnector.js +386 -9
  64. package/dist/lib.esm/connectors/base-evm-connector/baseEvmConnector.js +43 -24
  65. package/dist/lib.esm/connectors/base-solana-connector/baseSolanaConnector.js +43 -26
  66. package/dist/lib.esm/connectors/coinbase-connector/coinbaseConnector.js +2 -2
  67. package/dist/lib.esm/connectors/injected-evm-connector/injectedEvmConnector.js +2 -2
  68. package/dist/lib.esm/connectors/injected-solana-connector/walletStandardConnector.js +3 -3
  69. package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +80 -49
  70. package/dist/lib.esm/connectors/wallet-connect-v2-connector/WalletConnectV2Provider.js +2 -2
  71. package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +43 -15
  72. package/dist/lib.esm/connectors/wallet-connect-v2-connector/wcSolanaWallet.js +1 -1
  73. package/dist/lib.esm/index.js +4 -3
  74. package/dist/lib.esm/noModal.js +828 -119
  75. package/dist/lib.esm/plugins/wallet-services-plugin/plugin.js +3 -3
  76. package/dist/lib.esm/providers/base-provider/baseProvider.js +68 -38
  77. package/dist/lib.esm/react/context/useWeb3AuthInnerContextValue.js +36 -21
  78. package/dist/lib.esm/react/hooks/useWallets.js +33 -0
  79. package/dist/lib.esm/react/hooks/useWeb3AuthConnect.js +2 -2
  80. package/dist/lib.esm/react/index.js +1 -0
  81. package/dist/lib.esm/react/solana/hooks/useSolanaWallet.js +2 -2
  82. package/dist/lib.esm/react/solana/provider.js +4 -1
  83. package/dist/lib.esm/react/wagmi/provider.js +1 -1
  84. package/dist/lib.esm/vue/composables/useCheckout.js +1 -1
  85. package/dist/lib.esm/vue/composables/useFunding.js +1 -1
  86. package/dist/lib.esm/vue/composables/useReceive.js +1 -1
  87. package/dist/lib.esm/vue/composables/useSwap.js +1 -1
  88. package/dist/lib.esm/vue/composables/useWalletConnectScanner.js +1 -1
  89. package/dist/lib.esm/vue/composables/useWalletUI.js +1 -1
  90. package/dist/lib.esm/vue/composables/useWallets.js +35 -0
  91. package/dist/lib.esm/vue/composables/useWeb3AuthConnect.js +2 -2
  92. package/dist/lib.esm/vue/index.js +1 -0
  93. package/dist/lib.esm/vue/solana/composables/useSignAndSendTransaction.js +1 -1
  94. package/dist/lib.esm/vue/solana/composables/useSignMessage.js +1 -1
  95. package/dist/lib.esm/vue/solana/composables/useSignTransaction.js +1 -1
  96. package/dist/lib.esm/vue/solana/composables/useSolanaWallet.js +2 -2
  97. package/dist/lib.esm/vue/solana/provider.js +4 -0
  98. package/dist/lib.esm/vue/useWeb3AuthInnerContextValue.js +12 -3
  99. package/dist/lib.esm/vue/wagmi/provider.js +20 -8
  100. package/package.json +43 -19
@@ -2,10 +2,10 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import { SafeEventEmitter } from '@web3auth/auth';
3
3
  export { BUTTON_POSITION, CONFIRMATION_STRATEGY } from '@web3auth/ws-embed';
4
4
  import { EVM_PLUGINS, PLUGIN_STATUS, PLUGIN_NAMESPACES, PLUGIN_EVENTS } from '../../base/plugin/IPlugin.js';
5
- import { WalletServicesPluginError } from '../../base/plugin/errors.js';
6
- import { CAN_AUTHORIZE_STATUSES } from '../../base/connector/connectorStatus.js';
7
5
  import { WALLET_CONNECTORS } from '../../base/wallet/index.js';
6
+ import { WalletServicesPluginError } from '../../base/plugin/errors.js';
8
7
  import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
8
+ import { CAN_AUTHORIZE_STATUSES } from '../../base/connector/connectorStatus.js';
9
9
  import { log } from '../../base/loglevel.js';
10
10
  import { ANALYTICS_EVENTS } from '../../base/analytics.js';
11
11
 
@@ -24,7 +24,7 @@ class WalletServicesPlugin extends SafeEventEmitter {
24
24
  async initWithWeb3Auth(web3auth, _whiteLabel, analytics) {
25
25
  if (this.isInitialized) return;
26
26
  if (!web3auth) throw WalletServicesPluginError.web3authRequired();
27
- if (web3auth.connection && !this.SUPPORTED_CONNECTORS.includes(web3auth.connectedConnectorName)) throw WalletServicesPluginError.notInitialized();
27
+ if (web3auth.connection && !this.SUPPORTED_CONNECTORS.includes(web3auth.primaryConnectorName)) throw WalletServicesPluginError.notInitialized();
28
28
  const currentChainConfig = web3auth.currentChain;
29
29
  if (![CHAIN_NAMESPACES.EIP155, CHAIN_NAMESPACES.SOLANA].includes(currentChainConfig === null || currentChainConfig === void 0 ? void 0 : currentChainConfig.chainNamespace)) throw WalletServicesPluginError.unsupportedChainNamespace();
30
30
  this.web3auth = web3auth;
@@ -1,6 +1,6 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
- import { BaseController, createEventEmitterProxy } from '@toruslabs/base-controllers';
3
+ import { BaseController } from '@toruslabs/base-controllers';
4
4
  import { rpcErrors } from '@web3auth/auth';
5
5
  import { EIP1193_EVENTS } from './utils.js';
6
6
  import { WalletInitializationError, WalletProviderError } from '../../base/errors/index.js';
@@ -19,6 +19,8 @@ class BaseProvider extends BaseController {
19
19
  // set to true when the keyExportEnabled flag is set by code.
20
20
  // This is to prevent the flag from being overridden by the dashboard config.
21
21
  _defineProperty(this, "keyExportFlagSetByCode", false);
22
+ _defineProperty(this, "providerEventBridges", new Map());
23
+ _defineProperty(this, "providerListenerBridgeRegistered", false);
22
24
  const {
23
25
  chain
24
26
  } = config;
@@ -90,45 +92,19 @@ class BaseProvider extends BaseController {
90
92
  })).catch(err => callback(err, null));
91
93
  }
92
94
  updateProviderEngineProxy(provider) {
95
+ if (this._providerEngineProxy === provider) return;
93
96
  if (this._providerEngineProxy) {
94
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
- this._providerEngineProxy.setTarget(provider);
96
-
97
- // we want events to propagate from Ethereum provider -> wrapper provider (e.g. CommonJRPC provider) -> SDK -> dapp
98
- // ensure that only one handler is added for each event
99
- const reEmitHandler = event => {
100
- // skip newListener event
101
- if (event === "newListener") return;
102
-
103
- // listen to the event from the Ethereum provider
104
- provider.on(event, (...args) => {
105
- // handle chainChanged event: update chainId state
106
- if (event === EIP1193_EVENTS.CHAIN_CHANGED) {
107
- const chainId = args[0];
108
- this.update({
109
- chainId
110
- });
111
- }
112
-
113
- // re-emit the event
114
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
115
- this.emit(event, ...args);
116
- });
117
- };
118
-
119
- // handle existing events
120
- this.eventNames().forEach(event => {
121
- reEmitHandler(event);
122
- });
123
- // handle when a new listener is added
124
- this.on("newListener", event => {
125
- // skip if the event already exists
126
- if (this.listenerCount(event) > 0) return;
127
- reEmitHandler(event);
128
- });
129
- } else {
130
- this._providerEngineProxy = createEventEmitterProxy(provider);
97
+ // remove all event bridges from the previous provider
98
+ this.detachProviderEventBridges(this._providerEngineProxy);
131
99
  }
100
+
101
+ // attach all event bridges to the new provider
102
+ this._providerEngineProxy = provider;
103
+ this.ensureProviderListenerBridge();
104
+ this.eventNames().forEach(event => {
105
+ this.ensureProviderEventBridge(event);
106
+ });
107
+ this.attachProviderEventBridges(provider);
132
108
  }
133
109
  setKeyExportFlag(flag) {
134
110
  if (!this.keyExportFlagSetByCode) {
@@ -143,6 +119,60 @@ class BaseProvider extends BaseController {
143
119
  getChain(chainId) {
144
120
  return this.config.chains.find(chain => chain.chainId === chainId);
145
121
  }
122
+ ensureProviderListenerBridge() {
123
+ if (this.providerListenerBridgeRegistered) return;
124
+ this.providerListenerBridgeRegistered = true;
125
+ this.on("newListener", event => {
126
+ this.ensureProviderEventBridge(event);
127
+ });
128
+ }
129
+ ensureProviderEventBridge(event) {
130
+ if (event === "newListener" || event === "removeListener" || this.providerEventBridges.has(event)) return;
131
+ const bridge = {
132
+ handler: (...args) => {
133
+ if (event === EIP1193_EVENTS.CHAIN_CHANGED) {
134
+ const chainId = args[0];
135
+ this.update({
136
+ chainId
137
+ });
138
+ }
139
+
140
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
141
+ this.emit(event, ...args);
142
+ }
143
+ };
144
+ this.providerEventBridges.set(event, bridge);
145
+ if (!this._providerEngineProxy) return;
146
+ bridge.detach = this.attachProviderEventBridge(this._providerEngineProxy, event, bridge.handler);
147
+ }
148
+ attachProviderEventBridges(provider) {
149
+ this.providerEventBridges.forEach((bridge, event) => {
150
+ if (bridge.detach) return;
151
+ bridge.detach = this.attachProviderEventBridge(provider, event, bridge.handler);
152
+ });
153
+ }
154
+ attachProviderEventBridge(provider, event, handler) {
155
+ const removableProvider = provider;
156
+ const maybeDetach = removableProvider.on(event, handler);
157
+ return typeof maybeDetach === "function" ? () => {
158
+ maybeDetach();
159
+ } : undefined;
160
+ }
161
+ detachProviderEventBridges(provider) {
162
+ this.providerEventBridges.forEach((bridge, event) => {
163
+ if (bridge.detach) {
164
+ bridge.detach();
165
+ } else {
166
+ const removableProvider = provider;
167
+ if (typeof removableProvider.removeListener === "function") {
168
+ removableProvider.removeListener(event, bridge.handler);
169
+ } else if (typeof removableProvider.off === "function") {
170
+ removableProvider.off(event, bridge.handler);
171
+ }
172
+ }
173
+ bridge.detach = undefined;
174
+ });
175
+ }
146
176
  }
147
177
 
148
178
  export { BaseProvider };
@@ -1,9 +1,24 @@
1
- import { useState, useMemo, useCallback, useEffect } from 'react';
1
+ import { useMemo, useState, useCallback, useEffect } from 'react';
2
2
  import { WalletInitializationError } from '../../base/errors/index.js';
3
- import { CONNECTOR_EVENTS, CONNECTOR_STATUS } from '../../base/connector/constants.js';
4
3
  import { LOGIN_MODE } from '../../base/constants.js';
5
4
  import { ANALYTICS_INTEGRATION_TYPE } from '../../base/analytics.js';
5
+ import { CONNECTOR_EVENTS, CONNECTOR_STATUS } from '../../base/connector/constants.js';
6
+ import { CONNECTED_STATUSES } from '../../base/connector/connectorStatus.js';
6
7
 
8
+ function getInitialState(web3Auth) {
9
+ var _web3Auth$currentChai, _web3Auth$currentChai2;
10
+ const isConnected = CONNECTED_STATUSES.includes(web3Auth.status);
11
+ const isAuthorized = web3Auth.status === CONNECTOR_STATUS.AUTHORIZED;
12
+ return {
13
+ chainId: isConnected ? web3Auth.currentChainId : null,
14
+ chainNamespace: isConnected ? (_web3Auth$currentChai = (_web3Auth$currentChai2 = web3Auth.currentChain) === null || _web3Auth$currentChai2 === void 0 ? void 0 : _web3Auth$currentChai2.chainNamespace) !== null && _web3Auth$currentChai !== void 0 ? _web3Auth$currentChai : null : null,
15
+ connection: isConnected ? web3Auth.connection : null,
16
+ isAuthorized,
17
+ isConnected,
18
+ isInitialized: isConnected,
19
+ status: web3Auth.status
20
+ };
21
+ }
7
22
  function useWeb3AuthInnerContextValue({
8
23
  Web3AuthConstructor,
9
24
  web3AuthOptions,
@@ -12,20 +27,20 @@ function useWeb3AuthInnerContextValue({
12
27
  cleanupOnUnmount = false,
13
28
  initEffectDependency
14
29
  }) {
15
- const [chainId, setChainId] = useState(null);
16
- const [chainNamespace, setChainNamespace] = useState(null);
17
- const [isInitializing, setIsInitializing] = useState(false);
18
- const [initError, setInitError] = useState(null);
19
- const [connection, setConnection] = useState(null);
20
- const [isInitialized, setIsInitialized] = useState(false);
21
- const [isMFAEnabled, setIsMFAEnabled] = useState(false);
22
30
  const web3Auth = useMemo(() => {
23
- setConnection(null);
24
31
  return new Web3AuthConstructor(web3AuthOptions, initialState);
25
32
  }, [Web3AuthConstructor, web3AuthOptions, initialState]);
26
- const [isConnected, setIsConnected] = useState(false);
27
- const [status, setStatus] = useState(null);
28
- const [isAuthorized, setIsAuthorized] = useState(false);
33
+ const initialWeb3AuthState = getInitialState(web3Auth);
34
+ const [chainId, setChainId] = useState(() => initialWeb3AuthState.chainId);
35
+ const [chainNamespace, setChainNamespace] = useState(() => initialWeb3AuthState.chainNamespace);
36
+ const [isInitializing, setIsInitializing] = useState(false);
37
+ const [initError, setInitError] = useState(null);
38
+ const [connection, setConnection] = useState(() => initialWeb3AuthState.connection);
39
+ const [isInitialized, setIsInitialized] = useState(initialWeb3AuthState.isInitialized);
40
+ const [isMFAEnabled, setIsMFAEnabled] = useState(false);
41
+ const [isConnected, setIsConnected] = useState(initialWeb3AuthState.isConnected);
42
+ const [status, setStatus] = useState(initialWeb3AuthState.status);
43
+ const [isAuthorized, setIsAuthorized] = useState(initialWeb3AuthState.isAuthorized);
29
44
  const getPlugin = useCallback(name => {
30
45
  if (!web3Auth) throw WalletInitializationError.notReady();
31
46
  return web3Auth.getPlugin(name);
@@ -34,7 +49,7 @@ function useWeb3AuthInnerContextValue({
34
49
  const controller = new AbortController();
35
50
  async function init() {
36
51
  try {
37
- var _web3Auth$currentChai;
52
+ var _web3Auth$currentChai3;
38
53
  setInitError(null);
39
54
  setIsInitializing(true);
40
55
  web3Auth.setAnalyticsProperties({
@@ -44,7 +59,7 @@ function useWeb3AuthInnerContextValue({
44
59
  signal: controller.signal
45
60
  });
46
61
  setChainId(web3Auth.currentChainId);
47
- setChainNamespace((_web3Auth$currentChai = web3Auth.currentChain) === null || _web3Auth$currentChai === void 0 ? void 0 : _web3Auth$currentChai.chainNamespace);
62
+ setChainNamespace((_web3Auth$currentChai3 = web3Auth.currentChain) === null || _web3Auth$currentChai3 === void 0 ? void 0 : _web3Auth$currentChai3.chainNamespace);
48
63
  } catch (error) {
49
64
  setInitError(error);
50
65
  } finally {
@@ -59,9 +74,9 @@ function useWeb3AuthInnerContextValue({
59
74
  useEffect(() => {
60
75
  var _connection$ethereumP;
61
76
  const handleChainChange = async nextChainId => {
62
- var _web3Auth$currentChai2;
77
+ var _web3Auth$currentChai4;
63
78
  setChainId(nextChainId);
64
- setChainNamespace((_web3Auth$currentChai2 = web3Auth.currentChain) === null || _web3Auth$currentChai2 === void 0 ? void 0 : _web3Auth$currentChai2.chainNamespace);
79
+ setChainNamespace((_web3Auth$currentChai4 = web3Auth.currentChain) === null || _web3Auth$currentChai4 === void 0 ? void 0 : _web3Auth$currentChai4.chainNamespace);
65
80
  };
66
81
  const provider = (_connection$ethereumP = connection === null || connection === void 0 ? void 0 : connection.ethereumProvider) !== null && _connection$ethereumP !== void 0 ? _connection$ethereumP : null;
67
82
  if (!provider) return undefined;
@@ -83,12 +98,12 @@ function useWeb3AuthInnerContextValue({
83
98
  setStatus(web3Auth.status);
84
99
  // we do this because of rehydration issues. status connected is fired first but web3auth sdk is not ready yet.
85
100
  if (web3Auth.status === CONNECTOR_STATUS.CONNECTED) {
86
- var _web3Auth$currentChai3, _web3Auth$currentChai4;
101
+ var _web3Auth$currentChai5, _web3Auth$currentChai6;
87
102
  setIsInitialized(true);
88
103
  setIsConnected(true);
89
104
  setConnection(web3Auth.connection);
90
105
  setChainId(web3Auth.currentChainId);
91
- setChainNamespace((_web3Auth$currentChai3 = (_web3Auth$currentChai4 = web3Auth.currentChain) === null || _web3Auth$currentChai4 === void 0 ? void 0 : _web3Auth$currentChai4.chainNamespace) !== null && _web3Auth$currentChai3 !== void 0 ? _web3Auth$currentChai3 : null);
106
+ setChainNamespace((_web3Auth$currentChai5 = (_web3Auth$currentChai6 = web3Auth.currentChain) === null || _web3Auth$currentChai6 === void 0 ? void 0 : _web3Auth$currentChai6.chainNamespace) !== null && _web3Auth$currentChai5 !== void 0 ? _web3Auth$currentChai5 : null);
92
107
  }
93
108
  };
94
109
  const disconnectedListener = () => {
@@ -119,12 +134,12 @@ function useWeb3AuthInnerContextValue({
119
134
  const consentAcceptedListener = () => {
120
135
  setStatus(web3Auth.status);
121
136
  if (web3Auth.status === CONNECTOR_STATUS.CONNECTED || web3Auth.status === CONNECTOR_STATUS.AUTHORIZED) {
122
- var _web3Auth$currentChai5, _web3Auth$currentChai6;
137
+ var _web3Auth$currentChai7, _web3Auth$currentChai8;
123
138
  setIsInitialized(true);
124
139
  setIsConnected(true);
125
140
  setConnection(web3Auth.connection);
126
141
  setChainId(web3Auth.currentChainId);
127
- setChainNamespace((_web3Auth$currentChai5 = (_web3Auth$currentChai6 = web3Auth.currentChain) === null || _web3Auth$currentChai6 === void 0 ? void 0 : _web3Auth$currentChai6.chainNamespace) !== null && _web3Auth$currentChai5 !== void 0 ? _web3Auth$currentChai5 : null);
142
+ setChainNamespace((_web3Auth$currentChai7 = (_web3Auth$currentChai8 = web3Auth.currentChain) === null || _web3Auth$currentChai8 === void 0 ? void 0 : _web3Auth$currentChai8.chainNamespace) !== null && _web3Auth$currentChai7 !== void 0 ? _web3Auth$currentChai7 : null);
128
143
  if (web3Auth.status === CONNECTOR_STATUS.AUTHORIZED) {
129
144
  setIsAuthorized(true);
130
145
  }
@@ -0,0 +1,33 @@
1
+ import { useState, useCallback } from 'react';
2
+ import { useWeb3AuthInner } from './useWeb3AuthInner.js';
3
+ import { WalletInitializationError } from '../../base/errors/index.js';
4
+
5
+ const useWallets = () => {
6
+ const {
7
+ web3Auth
8
+ } = useWeb3AuthInner();
9
+ const [loading, setLoading] = useState(false);
10
+ const [error, setError] = useState(null);
11
+ const [wallets, setWallets] = useState([]);
12
+ const syncWallets = useCallback(async () => {
13
+ if (!web3Auth) throw WalletInitializationError.notReady();
14
+ setLoading(true);
15
+ setError(null);
16
+ try {
17
+ const result = await web3Auth.getConnectedAccountsWithProviders();
18
+ setWallets(result);
19
+ } catch (err) {
20
+ setError(err);
21
+ } finally {
22
+ setLoading(false);
23
+ }
24
+ }, [web3Auth]);
25
+ return {
26
+ loading,
27
+ error,
28
+ wallets,
29
+ syncWallets
30
+ };
31
+ };
32
+
33
+ export { useWallets };
@@ -16,7 +16,7 @@ const useWeb3AuthConnect = () => {
16
16
  setConnectorName(null);
17
17
  }
18
18
  if (isConnected && !connectorName) {
19
- setConnectorName(web3Auth.connectedConnectorName);
19
+ setConnectorName(web3Auth.primaryConnectorName);
20
20
  }
21
21
  }, [isConnected, connectorName, web3Auth]);
22
22
  const connect = useCallback(async (connector, params) => {
@@ -25,7 +25,7 @@ const useWeb3AuthConnect = () => {
25
25
  try {
26
26
  const provider = await web3Auth.connectTo(connector, params);
27
27
  if (provider) {
28
- setConnectorName(web3Auth.connectedConnectorName);
28
+ setConnectorName(web3Auth.primaryConnectorName);
29
29
  }
30
30
  return provider;
31
31
  } catch (error) {
@@ -14,6 +14,7 @@ export { useWalletConnectScanner } from './hooks/useWalletConnectScanner.js';
14
14
  export { useWalletServicesContextValue } from './context/useWalletServicesContextValue.js';
15
15
  export { useWalletServicesPlugin } from './hooks/useWalletServicesPlugin.js';
16
16
  export { useWalletUI } from './hooks/useWalletUI.js';
17
+ export { useWallets } from './hooks/useWallets.js';
17
18
  export { useWeb3Auth } from './hooks/useWeb3Auth.js';
18
19
  export { useWeb3AuthConnect } from './hooks/useWeb3AuthConnect.js';
19
20
  export { useWeb3AuthDisconnect } from './hooks/useWeb3AuthDisconnect.js';
@@ -28,12 +28,12 @@ const useSolanaWallet = () => {
28
28
  return createSolanaRpc(web3Auth.currentChain.rpcTarget);
29
29
  }, [web3Auth, solanaWallet, chainNamespace]);
30
30
  const getPrivateKey = useCallback(async () => {
31
- var _web3Auth$connectedCo;
31
+ var _web3Auth$primaryConn;
32
32
  if (!web3Auth) throw new Error("Web3Auth not initialized");
33
33
  if ((connection === null || connection === void 0 ? void 0 : connection.connectorName) !== WALLET_CONNECTORS.AUTH) {
34
34
  throw new Error("getPrivateKey is only supported with the Auth connector");
35
35
  }
36
- const provider = (_web3Auth$connectedCo = web3Auth.connectedConnector) === null || _web3Auth$connectedCo === void 0 ? void 0 : _web3Auth$connectedCo.provider;
36
+ const provider = (_web3Auth$primaryConn = web3Auth.primaryConnector) === null || _web3Auth$primaryConn === void 0 ? void 0 : _web3Auth$primaryConn.provider;
37
37
  if (!provider) throw new Error("Provider not available");
38
38
  const privateKey = await provider.request({
39
39
  method: SOLANA_METHOD_TYPES.SOLANA_PRIVATE_KEY
@@ -3,8 +3,8 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
3
3
  import { createWalletStandardConnector, createClient } from '@solana/client';
4
4
  import { SolanaProvider as SolanaProvider$1 } from '@solana/react-hooks';
5
5
  import { createElement, useRef, useState, useEffect } from 'react';
6
- import { useChain } from '../hooks/useChain.js';
7
6
  import { useWeb3Auth } from '../hooks/useWeb3Auth.js';
7
+ import { useChain } from '../hooks/useChain.js';
8
8
  import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
9
9
  import { log } from '../../base/loglevel.js';
10
10
 
@@ -100,6 +100,9 @@ function useFrameworkKitSolanaClient() {
100
100
  adopt(makePlaceholder(rpc));
101
101
  return;
102
102
  }
103
+
104
+ // only reconnect for the primary connector
105
+ if (conn.connectorName !== (web3Auth === null || web3Auth === void 0 ? void 0 : web3Auth.primaryConnectorName)) return;
103
106
  try {
104
107
  const solanaWalletId = "wallet-standard:" + conn.connectorName;
105
108
  const connector = createWalletStandardConnector(solanaWallet, {
@@ -6,9 +6,9 @@ import { createConfig, WagmiProvider as WagmiProvider$1, webSocket, http, fallba
6
6
  import { injected } from 'wagmi/connectors';
7
7
  import { defaultWagmiConfig } from './constants.js';
8
8
  import { useWeb3Auth } from '../hooks/useWeb3Auth.js';
9
- import { useWeb3AuthDisconnect } from '../hooks/useWeb3AuthDisconnect.js';
10
9
  import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
11
10
  import { WalletInitializationError } from '../../base/errors/index.js';
11
+ import { useWeb3AuthDisconnect } from '../hooks/useWeb3AuthDisconnect.js';
12
12
  import { log } from '../../base/loglevel.js';
13
13
 
14
14
  const _excluded = ["children"];
@@ -1,7 +1,7 @@
1
1
  import { ref } from 'vue';
2
2
  import { useWalletServicesPlugin } from './useWalletServicesPlugin.js';
3
- import { WalletServicesPluginError } from '../../base/plugin/errors.js';
4
3
  import { log } from '../../base/loglevel.js';
4
+ import { WalletServicesPluginError } from '../../base/plugin/errors.js';
5
5
 
6
6
  const useCheckout = () => {
7
7
  const {
@@ -1,7 +1,7 @@
1
1
  import { ref } from 'vue';
2
2
  import { useWalletServicesPlugin } from './useWalletServicesPlugin.js';
3
- import { WalletServicesPluginError } from '../../base/plugin/errors.js';
4
3
  import { log } from '../../base/loglevel.js';
4
+ import { WalletServicesPluginError } from '../../base/plugin/errors.js';
5
5
 
6
6
  const useFunding = () => {
7
7
  const {
@@ -1,7 +1,7 @@
1
1
  import { ref } from 'vue';
2
2
  import { useWalletServicesPlugin } from './useWalletServicesPlugin.js';
3
- import { WalletServicesPluginError } from '../../base/plugin/errors.js';
4
3
  import { log } from '../../base/loglevel.js';
4
+ import { WalletServicesPluginError } from '../../base/plugin/errors.js';
5
5
 
6
6
  const useReceive = () => {
7
7
  const {
@@ -1,7 +1,7 @@
1
1
  import { ref } from 'vue';
2
2
  import { useWalletServicesPlugin } from './useWalletServicesPlugin.js';
3
- import { WalletServicesPluginError } from '../../base/plugin/errors.js';
4
3
  import { log } from '../../base/loglevel.js';
4
+ import { WalletServicesPluginError } from '../../base/plugin/errors.js';
5
5
 
6
6
  const useSwap = () => {
7
7
  const {
@@ -1,7 +1,7 @@
1
1
  import { ref } from 'vue';
2
2
  import { useWalletServicesPlugin } from './useWalletServicesPlugin.js';
3
- import { WalletServicesPluginError } from '../../base/plugin/errors.js';
4
3
  import { log } from '../../base/loglevel.js';
4
+ import { WalletServicesPluginError } from '../../base/plugin/errors.js';
5
5
 
6
6
  const useWalletConnectScanner = () => {
7
7
  const {
@@ -1,7 +1,7 @@
1
1
  import { ref } from 'vue';
2
2
  import { useWalletServicesPlugin } from './useWalletServicesPlugin.js';
3
- import { WalletServicesPluginError } from '../../base/plugin/errors.js';
4
3
  import { log } from '../../base/loglevel.js';
4
+ import { WalletServicesPluginError } from '../../base/plugin/errors.js';
5
5
 
6
6
  const useWalletUI = () => {
7
7
  const {
@@ -0,0 +1,35 @@
1
+ import { ref } from 'vue';
2
+ import { useWeb3AuthInner } from './useWeb3AuthInner.js';
3
+ import { WalletInitializationError } from '../../base/errors/index.js';
4
+ import { log } from '../../base/loglevel.js';
5
+
6
+ const useWallets = () => {
7
+ const {
8
+ web3Auth
9
+ } = useWeb3AuthInner();
10
+ const loading = ref(false);
11
+ const error = ref(null);
12
+ const wallets = ref([]);
13
+ const syncWallets = async () => {
14
+ if (!web3Auth.value) throw WalletInitializationError.notReady();
15
+ error.value = null;
16
+ loading.value = true;
17
+ try {
18
+ const result = await web3Auth.value.getConnectedAccountsWithProviders();
19
+ wallets.value = result;
20
+ } catch (err) {
21
+ log.error("Error getting wallets", err);
22
+ error.value = err;
23
+ } finally {
24
+ loading.value = false;
25
+ }
26
+ };
27
+ return {
28
+ loading,
29
+ error,
30
+ wallets,
31
+ syncWallets
32
+ };
33
+ };
34
+
35
+ export { useWallets };
@@ -17,7 +17,7 @@ const useWeb3AuthConnect = () => {
17
17
  }
18
18
  if (newVal && !connectorName.value) {
19
19
  var _web3Auth$value;
20
- connectorName.value = (_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.connectedConnectorName;
20
+ connectorName.value = (_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.primaryConnectorName;
21
21
  }
22
22
  }, {
23
23
  immediate: true
@@ -28,7 +28,7 @@ const useWeb3AuthConnect = () => {
28
28
  error.value = null;
29
29
  loading.value = true;
30
30
  const localProvider = await web3Auth.value.connectTo(connectorType, loginParams);
31
- connectorName.value = web3Auth.value.connectedConnectorName;
31
+ connectorName.value = web3Auth.value.primaryConnectorName;
32
32
  return localProvider;
33
33
  } catch (err) {
34
34
  log.error("Error connecting", err);
@@ -15,6 +15,7 @@ export { useSwitchChain } from './composables/useSwitchChain.js';
15
15
  export { useWalletConnectScanner } from './composables/useWalletConnectScanner.js';
16
16
  export { useWalletServicesPlugin } from './composables/useWalletServicesPlugin.js';
17
17
  export { useWalletUI } from './composables/useWalletUI.js';
18
+ export { useWallets } from './composables/useWallets.js';
18
19
  export { useWeb3Auth } from './composables/useWeb3Auth.js';
19
20
  export { useWeb3AuthConnect } from './composables/useWeb3AuthConnect.js';
20
21
  export { useWeb3AuthDisconnect } from './composables/useWeb3AuthDisconnect.js';
@@ -1,8 +1,8 @@
1
1
  import { ref } from 'vue';
2
2
  import { WalletInitializationError } from '../../../base/errors/index.js';
3
3
  import { useSolanaWallet } from './useSolanaWallet.js';
4
- import { walletSignAndSendTransaction } from '../../../base/wallet/solana.js';
5
4
  import { log } from '../../../base/loglevel.js';
5
+ import { walletSignAndSendTransaction } from '../../../base/wallet/solana.js';
6
6
 
7
7
  const useSignAndSendTransaction = () => {
8
8
  const {
@@ -1,8 +1,8 @@
1
1
  import { ref } from 'vue';
2
2
  import { useSolanaWallet } from './useSolanaWallet.js';
3
3
  import { WalletInitializationError } from '../../../base/errors/index.js';
4
- import { walletSignMessage } from '../../../base/wallet/solana.js';
5
4
  import { log } from '../../../base/loglevel.js';
5
+ import { walletSignMessage } from '../../../base/wallet/solana.js';
6
6
 
7
7
  const useSignMessage = () => {
8
8
  const {
@@ -1,8 +1,8 @@
1
1
  import { ref } from 'vue';
2
2
  import { useSolanaWallet } from './useSolanaWallet.js';
3
3
  import { WalletInitializationError } from '../../../base/errors/index.js';
4
- import { walletSignTransaction } from '../../../base/wallet/solana.js';
5
4
  import { log } from '../../../base/loglevel.js';
5
+ import { walletSignTransaction } from '../../../base/wallet/solana.js';
6
6
 
7
7
  const useSignTransaction = () => {
8
8
  const {
@@ -49,12 +49,12 @@ const useSolanaWallet = () => {
49
49
  };
50
50
  onScopeDispose(teardownWalletListeners);
51
51
  const getPrivateKey = async () => {
52
- var _connection$value2, _web3Auth$value$conne;
52
+ var _connection$value2, _web3Auth$value$prima;
53
53
  if (!web3Auth.value) throw new Error("Web3Auth not initialized");
54
54
  if (((_connection$value2 = connection.value) === null || _connection$value2 === void 0 ? void 0 : _connection$value2.connectorName) !== WALLET_CONNECTORS.AUTH) {
55
55
  throw new Error("getPrivateKey is only supported with the Auth connector");
56
56
  }
57
- const provider = (_web3Auth$value$conne = web3Auth.value.connectedConnector) === null || _web3Auth$value$conne === void 0 ? void 0 : _web3Auth$value$conne.provider;
57
+ const provider = (_web3Auth$value$prima = web3Auth.value.primaryConnector) === null || _web3Auth$value$prima === void 0 ? void 0 : _web3Auth$value$prima.provider;
58
58
  if (!provider) throw new Error("Provider not available");
59
59
  const privateKey = await provider.request({
60
60
  method: SOLANA_METHOD_TYPES.SOLANA_PRIVATE_KEY
@@ -36,6 +36,7 @@ const SolanaProvider = defineComponent({
36
36
 
37
37
  // watch for changes in the connection and chain namespace
38
38
  watch([isConnected, connection], async ([newIsConnected, newConnection]) => {
39
+ var _web3Auth$value;
39
40
  if (!newIsConnected || !(newConnection !== null && newConnection !== void 0 && newConnection.solanaWallet)) {
40
41
  if (clientRef.value) {
41
42
  await disposeClient(clientRef.value);
@@ -52,6 +53,9 @@ const SolanaProvider = defineComponent({
52
53
  chainConfig = web3Auth.value.coreOptions.chains.find(c => c.chainNamespace === CHAIN_NAMESPACES.SOLANA);
53
54
  if (!chainConfig) return;
54
55
  }
56
+
57
+ // only reconnect for the primary connector
58
+ if (newConnection.connectorName !== ((_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.primaryConnectorName)) return;
55
59
  const prevClient = clientRef.value;
56
60
  try {
57
61
  // create a wallet standard connector from connected wallet
@@ -1,9 +1,9 @@
1
1
  import { shallowRef, ref, watch } from 'vue';
2
2
  import { ANALYTICS_INTEGRATION_TYPE } from '../base/analytics.js';
3
3
  import { log } from '../base/loglevel.js';
4
- import { CONNECTOR_EVENTS, CONNECTOR_STATUS } from '../base/connector/constants.js';
5
4
  import { LOGIN_MODE } from '../base/constants.js';
6
5
  import { WalletInitializationError } from '../base/errors/index.js';
6
+ import { CONNECTOR_EVENTS, CONNECTOR_STATUS } from '../base/connector/constants.js';
7
7
 
8
8
  function useWeb3AuthInnerContextValue({
9
9
  Web3AuthConstructor,
@@ -92,7 +92,7 @@ function useWeb3AuthInnerContextValue({
92
92
  var _currentChain$chainNa, _currentChain;
93
93
  if (!isInitialized.value) isInitialized.value = true;
94
94
  isConnected.value = true;
95
- connection.value = newWeb3Auth.connection;
95
+ connection.value = web3Auth.value.connection;
96
96
  chainId.value = web3Auth.value.currentChainId;
97
97
  chainNamespace.value = (_currentChain$chainNa = (_currentChain = web3Auth.value.currentChain) === null || _currentChain === void 0 ? void 0 : _currentChain.chainNamespace) !== null && _currentChain$chainNa !== void 0 ? _currentChain$chainNa : null;
98
98
  }
@@ -110,7 +110,7 @@ function useWeb3AuthInnerContextValue({
110
110
  var _currentChain$chainNa2, _currentChain2;
111
111
  if (!isInitialized.value) isInitialized.value = true;
112
112
  isConnected.value = true;
113
- connection.value = newWeb3Auth.connection;
113
+ connection.value = web3Auth.value.connection;
114
114
  chainId.value = web3Auth.value.currentChainId;
115
115
  chainNamespace.value = (_currentChain$chainNa2 = (_currentChain2 = web3Auth.value.currentChain) === null || _currentChain2 === void 0 ? void 0 : _currentChain2.chainNamespace) !== null && _currentChain$chainNa2 !== void 0 ? _currentChain$chainNa2 : null;
116
116
  if (web3Auth.value.status === CONNECTOR_STATUS.AUTHORIZED) {
@@ -134,6 +134,13 @@ function useWeb3AuthInnerContextValue({
134
134
  const mfaEnabledListener = () => {
135
135
  isMFAEnabled.value = true;
136
136
  };
137
+ const connectionUpdatedListener = () => {
138
+ var _currentChain$chainNa3, _currentChain3;
139
+ status.value = web3Auth.value.status;
140
+ connection.value = web3Auth.value.connection;
141
+ chainId.value = web3Auth.value.currentChainId;
142
+ chainNamespace.value = (_currentChain$chainNa3 = (_currentChain3 = web3Auth.value.currentChain) === null || _currentChain3 === void 0 ? void 0 : _currentChain3.chainNamespace) !== null && _currentChain$chainNa3 !== void 0 ? _currentChain$chainNa3 : null;
143
+ };
137
144
  if (prevWeb3Auth && newWeb3Auth !== prevWeb3Auth) {
138
145
  prevWeb3Auth.removeListener(CONNECTOR_EVENTS.NOT_READY, notReadyListener);
139
146
  prevWeb3Auth.removeListener(CONNECTOR_EVENTS.READY, readyListener);
@@ -144,6 +151,7 @@ function useWeb3AuthInnerContextValue({
144
151
  prevWeb3Auth.removeListener(CONNECTOR_EVENTS.ERRORED, errorListener);
145
152
  prevWeb3Auth.removeListener(CONNECTOR_EVENTS.REHYDRATION_ERROR, errorListener);
146
153
  prevWeb3Auth.removeListener(CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
154
+ prevWeb3Auth.removeListener(CONNECTOR_EVENTS.CONNECTION_UPDATED, connectionUpdatedListener);
147
155
  if (prevWeb3Auth.loginMode === LOGIN_MODE.MODAL) {
148
156
  prevWeb3Auth.removeListener(CONNECTOR_EVENTS.CONSENT_ACCEPTED, consentAcceptedListener);
149
157
  }
@@ -159,6 +167,7 @@ function useWeb3AuthInnerContextValue({
159
167
  newWeb3Auth.on(CONNECTOR_EVENTS.ERRORED, errorListener);
160
168
  newWeb3Auth.on(CONNECTOR_EVENTS.REHYDRATION_ERROR, errorListener);
161
169
  newWeb3Auth.on(CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
170
+ newWeb3Auth.on(CONNECTOR_EVENTS.CONNECTION_UPDATED, connectionUpdatedListener);
162
171
  if (newWeb3Auth.loginMode === LOGIN_MODE.MODAL) {
163
172
  newWeb3Auth.on(CONNECTOR_EVENTS.CONSENT_ACCEPTED, consentAcceptedListener);
164
173
  }