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

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 (101) 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 +501 -70
  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 +834 -117
  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 +43 -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 +7 -1
  24. package/dist/lib.cjs/react/wagmi/provider.js +37 -5
  25. package/dist/lib.cjs/types/account-linking/index.d.ts +2 -0
  26. package/dist/lib.cjs/types/account-linking/interfaces.d.ts +90 -0
  27. package/dist/lib.cjs/types/account-linking/react.d.ts +19 -0
  28. package/dist/lib.cjs/types/account-linking/rest.d.ts +9 -0
  29. package/dist/lib.cjs/types/account-linking/vue.d.ts +20 -0
  30. package/dist/lib.cjs/types/base/analytics.d.ts +9 -0
  31. package/dist/lib.cjs/types/base/connector/baseConnector.d.ts +5 -0
  32. package/dist/lib.cjs/types/base/connector/constants.d.ts +2 -0
  33. package/dist/lib.cjs/types/base/connector/interfaces.d.ts +51 -6
  34. package/dist/lib.cjs/types/base/core/IWeb3Auth.d.ts +39 -2
  35. package/dist/lib.cjs/types/base/errors/index.d.ts +13 -0
  36. package/dist/lib.cjs/types/base/interfaces.d.ts +3 -1
  37. package/dist/lib.cjs/types/base/utils.d.ts +7 -1
  38. package/dist/lib.cjs/types/connectors/auth-connector/authConnector.d.ts +33 -3
  39. package/dist/lib.cjs/types/connectors/auth-connector/interface.d.ts +77 -2
  40. package/dist/lib.cjs/types/connectors/base-evm-connector/baseEvmConnector.d.ts +6 -0
  41. package/dist/lib.cjs/types/connectors/base-solana-connector/baseSolanaConnector.d.ts +6 -0
  42. package/dist/lib.cjs/types/index.d.ts +1 -0
  43. package/dist/lib.cjs/types/noModal.d.ts +104 -5
  44. package/dist/lib.cjs/types/providers/base-provider/baseProvider.d.ts +7 -0
  45. package/dist/lib.cjs/types/react/hooks/index.d.ts +1 -0
  46. package/dist/lib.cjs/types/react/hooks/useWallets.d.ts +8 -0
  47. package/dist/lib.cjs/types/vue/composables/index.d.ts +1 -0
  48. package/dist/lib.cjs/types/vue/composables/useWallets.d.ts +9 -0
  49. package/dist/lib.cjs/vue/composables/useWallets.js +52 -0
  50. package/dist/lib.cjs/vue/composables/useWeb3AuthConnect.js +2 -2
  51. package/dist/lib.cjs/vue/index.js +2 -0
  52. package/dist/lib.cjs/vue/solana/composables/useSolanaWallet.js +2 -2
  53. package/dist/lib.cjs/vue/solana/provider.js +50 -23
  54. package/dist/lib.cjs/vue/useWeb3AuthInnerContextValue.js +13 -4
  55. package/dist/lib.cjs/vue/wagmi/provider.js +35 -7
  56. package/dist/lib.esm/account-linking/index.js +1 -0
  57. package/dist/lib.esm/account-linking/react.js +74 -0
  58. package/dist/lib.esm/account-linking/rest.js +51 -0
  59. package/dist/lib.esm/account-linking/vue.js +78 -0
  60. package/dist/lib.esm/base/analytics.js +17 -2
  61. package/dist/lib.esm/base/connector/constants.js +2 -0
  62. package/dist/lib.esm/base/errors/index.js +48 -1
  63. package/dist/lib.esm/base/utils.js +16 -4
  64. package/dist/lib.esm/connectors/auth-connector/authConnector.js +462 -31
  65. package/dist/lib.esm/connectors/base-evm-connector/baseEvmConnector.js +43 -24
  66. package/dist/lib.esm/connectors/base-solana-connector/baseSolanaConnector.js +43 -26
  67. package/dist/lib.esm/connectors/coinbase-connector/coinbaseConnector.js +2 -2
  68. package/dist/lib.esm/connectors/injected-evm-connector/injectedEvmConnector.js +2 -2
  69. package/dist/lib.esm/connectors/injected-solana-connector/walletStandardConnector.js +3 -3
  70. package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +80 -49
  71. package/dist/lib.esm/connectors/wallet-connect-v2-connector/WalletConnectV2Provider.js +2 -2
  72. package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +43 -15
  73. package/dist/lib.esm/connectors/wallet-connect-v2-connector/wcSolanaWallet.js +1 -1
  74. package/dist/lib.esm/index.js +4 -3
  75. package/dist/lib.esm/noModal.js +851 -126
  76. package/dist/lib.esm/plugins/wallet-services-plugin/plugin.js +3 -3
  77. package/dist/lib.esm/providers/base-provider/baseProvider.js +68 -38
  78. package/dist/lib.esm/react/context/useWeb3AuthInnerContextValue.js +45 -21
  79. package/dist/lib.esm/react/hooks/useWallets.js +33 -0
  80. package/dist/lib.esm/react/hooks/useWeb3AuthConnect.js +2 -2
  81. package/dist/lib.esm/react/index.js +1 -0
  82. package/dist/lib.esm/react/solana/hooks/useSolanaWallet.js +2 -2
  83. package/dist/lib.esm/react/solana/provider.js +9 -2
  84. package/dist/lib.esm/react/wagmi/provider.js +39 -7
  85. package/dist/lib.esm/vue/composables/useCheckout.js +1 -1
  86. package/dist/lib.esm/vue/composables/useFunding.js +1 -1
  87. package/dist/lib.esm/vue/composables/useReceive.js +1 -1
  88. package/dist/lib.esm/vue/composables/useSwap.js +1 -1
  89. package/dist/lib.esm/vue/composables/useWalletConnectScanner.js +1 -1
  90. package/dist/lib.esm/vue/composables/useWalletUI.js +1 -1
  91. package/dist/lib.esm/vue/composables/useWallets.js +35 -0
  92. package/dist/lib.esm/vue/composables/useWeb3AuthConnect.js +2 -2
  93. package/dist/lib.esm/vue/index.js +1 -0
  94. package/dist/lib.esm/vue/solana/composables/useSignAndSendTransaction.js +1 -1
  95. package/dist/lib.esm/vue/solana/composables/useSignMessage.js +1 -1
  96. package/dist/lib.esm/vue/solana/composables/useSignTransaction.js +1 -1
  97. package/dist/lib.esm/vue/solana/composables/useSolanaWallet.js +2 -2
  98. package/dist/lib.esm/vue/solana/provider.js +51 -24
  99. package/dist/lib.esm/vue/useWeb3AuthInnerContextValue.js +12 -3
  100. package/dist/lib.esm/vue/wagmi/provider.js +36 -8
  101. package/package.json +44 -20
@@ -14,6 +14,8 @@ export interface BaseProviderConfig extends BaseConfig {
14
14
  export declare abstract class BaseProvider<C extends BaseProviderConfig, S extends BaseProviderState, P> extends BaseController<C, S, BaseProviderEvents<S>> implements IBaseProvider<P> {
15
15
  _providerEngineProxy: SafeEventEmitterProvider<ProviderEvents> | null;
16
16
  private keyExportFlagSetByCode;
17
+ private providerEventBridges;
18
+ private providerListenerBridgeRegistered;
17
19
  constructor({ config, state }: {
18
20
  config: C;
19
21
  state?: S;
@@ -30,6 +32,11 @@ export declare abstract class BaseProvider<C extends BaseProviderConfig, S exten
30
32
  setKeyExportFlag(flag: boolean): void;
31
33
  protected getProviderEngineProxy(): SafeEventEmitterProvider | null;
32
34
  protected getChain(chainId: string): CustomChainConfig;
35
+ private ensureProviderListenerBridge;
36
+ private ensureProviderEventBridge;
37
+ private attachProviderEventBridges;
38
+ private attachProviderEventBridge;
39
+ private detachProviderEventBridges;
33
40
  abstract setupProvider(provider: P, chainId: string): Promise<void>;
34
41
  abstract switchChain(params: {
35
42
  chainId: string;
@@ -8,6 +8,7 @@ export * from "./useReceive";
8
8
  export * from "./useSwap";
9
9
  export * from "./useSwitchChain";
10
10
  export * from "./useWalletConnectScanner";
11
+ export * from "./useWallets";
11
12
  export * from "./useWalletServicesPlugin";
12
13
  export * from "./useWalletUI";
13
14
  export * from "./useWeb3Auth";
@@ -0,0 +1,8 @@
1
+ import { ConnectedAccountsWithProviders, Web3AuthError } from "../../base";
2
+ export interface IUseWallets {
3
+ loading: boolean;
4
+ error: Web3AuthError | null;
5
+ wallets: ConnectedAccountsWithProviders[];
6
+ syncWallets(): Promise<void>;
7
+ }
8
+ export declare const useWallets: () => IUseWallets;
@@ -9,6 +9,7 @@ export * from "./useReceive";
9
9
  export * from "./useSwap";
10
10
  export * from "./useSwitchChain";
11
11
  export * from "./useWalletConnectScanner";
12
+ export * from "./useWallets";
12
13
  export * from "./useWalletServicesPlugin";
13
14
  export * from "./useWalletUI";
14
15
  export * from "./useWeb3Auth";
@@ -0,0 +1,9 @@
1
+ import { Ref } from "vue";
2
+ import { type ConnectedAccountsWithProviders, Web3AuthError } from "../../base";
3
+ export interface IUseWallets {
4
+ loading: Ref<boolean>;
5
+ error: Ref<Web3AuthError | null>;
6
+ wallets: Ref<ConnectedAccountsWithProviders[]>;
7
+ syncWallets(): Promise<void>;
8
+ }
9
+ export declare const useWallets: () => IUseWallets;
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ var vue = require('vue');
4
+ require('@babel/runtime/helpers/objectSpread2');
5
+ require('@babel/runtime/helpers/defineProperty');
6
+ require('@segment/analytics-next');
7
+ var loglevel = require('../../base/loglevel.js');
8
+ require('@toruslabs/base-controllers');
9
+ require('@toruslabs/session-manager');
10
+ require('@web3auth/auth');
11
+ var index = require('../../base/errors/index.js');
12
+ require('@toruslabs/constants');
13
+ require('@toruslabs/http-helpers');
14
+ require('../../base/constants.js');
15
+ require('../../base/wallet/index.js');
16
+ require('../../base/connector/connectorStatus.js');
17
+ require('../../base/connector/constants.js');
18
+ require('jwt-decode');
19
+ require('../../base/plugin/errors.js');
20
+ require('../../base/plugin/IPlugin.js');
21
+ var useWeb3AuthInner = require('./useWeb3AuthInner.js');
22
+
23
+ const useWallets = () => {
24
+ const {
25
+ web3Auth
26
+ } = useWeb3AuthInner.useWeb3AuthInner();
27
+ const loading = vue.ref(false);
28
+ const error = vue.ref(null);
29
+ const wallets = vue.ref([]);
30
+ const syncWallets = async () => {
31
+ if (!web3Auth.value) throw index.WalletInitializationError.notReady();
32
+ error.value = null;
33
+ loading.value = true;
34
+ try {
35
+ const result = await web3Auth.value.getConnectedAccountsWithProviders();
36
+ wallets.value = result;
37
+ } catch (err) {
38
+ loglevel.log.error("Error getting wallets", err);
39
+ error.value = err;
40
+ } finally {
41
+ loading.value = false;
42
+ }
43
+ };
44
+ return {
45
+ loading,
46
+ error,
47
+ wallets,
48
+ syncWallets
49
+ };
50
+ };
51
+
52
+ exports.useWallets = useWallets;
@@ -34,7 +34,7 @@ const useWeb3AuthConnect = () => {
34
34
  }
35
35
  if (newVal && !connectorName.value) {
36
36
  var _web3Auth$value;
37
- connectorName.value = (_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.connectedConnectorName;
37
+ connectorName.value = (_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.primaryConnectorName;
38
38
  }
39
39
  }, {
40
40
  immediate: true
@@ -45,7 +45,7 @@ const useWeb3AuthConnect = () => {
45
45
  error.value = null;
46
46
  loading.value = true;
47
47
  const localProvider = await web3Auth.value.connectTo(connectorType, loginParams);
48
- connectorName.value = web3Auth.value.connectedConnectorName;
48
+ connectorName.value = web3Auth.value.primaryConnectorName;
49
49
  return localProvider;
50
50
  } catch (err) {
51
51
  loglevel.log.error("Error connecting", err);
@@ -11,6 +11,7 @@ var useReceive = require('./composables/useReceive.js');
11
11
  var useSwap = require('./composables/useSwap.js');
12
12
  var useSwitchChain = require('./composables/useSwitchChain.js');
13
13
  var useWalletConnectScanner = require('./composables/useWalletConnectScanner.js');
14
+ var useWallets = require('./composables/useWallets.js');
14
15
  var useWalletServicesPlugin = require('./composables/useWalletServicesPlugin.js');
15
16
  var useWalletUI = require('./composables/useWalletUI.js');
16
17
  var useWeb3Auth = require('./composables/useWeb3Auth.js');
@@ -35,6 +36,7 @@ exports.useReceive = useReceive.useReceive;
35
36
  exports.useSwap = useSwap.useSwap;
36
37
  exports.useSwitchChain = useSwitchChain.useSwitchChain;
37
38
  exports.useWalletConnectScanner = useWalletConnectScanner.useWalletConnectScanner;
39
+ exports.useWallets = useWallets.useWallets;
38
40
  exports.useWalletServicesPlugin = useWalletServicesPlugin.useWalletServicesPlugin;
39
41
  exports.useWalletUI = useWalletUI.useWalletUI;
40
42
  exports.useWeb3Auth = useWeb3Auth.useWeb3Auth;
@@ -66,12 +66,12 @@ const useSolanaWallet = () => {
66
66
  };
67
67
  vue.onScopeDispose(teardownWalletListeners);
68
68
  const getPrivateKey = async () => {
69
- var _connection$value2, _web3Auth$value$conne;
69
+ var _connection$value2, _web3Auth$value$prima;
70
70
  if (!web3Auth.value) throw new Error("Web3Auth not initialized");
71
71
  if (((_connection$value2 = connection.value) === null || _connection$value2 === void 0 ? void 0 : _connection$value2.connectorName) !== index.WALLET_CONNECTORS.AUTH) {
72
72
  throw new Error("getPrivateKey is only supported with the Auth connector");
73
73
  }
74
- const provider = (_web3Auth$value$conne = web3Auth.value.connectedConnector) === null || _web3Auth$value$conne === void 0 ? void 0 : _web3Auth$value$conne.provider;
74
+ const provider = (_web3Auth$value$prima = web3Auth.value.primaryConnector) === null || _web3Auth$value$prima === void 0 ? void 0 : _web3Auth$value$prima.provider;
75
75
  if (!provider) throw new Error("Provider not available");
76
76
  const privateKey = await provider.request({
77
77
  method: wsEmbed.SOLANA_METHOD_TYPES.SOLANA_PRIVATE_KEY
@@ -19,6 +19,7 @@ require('../../base/connector/constants.js');
19
19
  require('jwt-decode');
20
20
  require('../../base/plugin/errors.js');
21
21
  require('../../base/plugin/IPlugin.js');
22
+ var useChain = require('../composables/useChain.js');
22
23
  var useWeb3Auth = require('../composables/useWeb3Auth.js');
23
24
  var constants = require('./constants.js');
24
25
 
@@ -45,55 +46,81 @@ const SolanaProvider = vue.defineComponent({
45
46
  connection,
46
47
  web3Auth
47
48
  } = useWeb3Auth.useWeb3Auth();
49
+ const {
50
+ chainId
51
+ } = useChain.useChain();
48
52
  const clientRef = vue.ref(null);
53
+ // Holds the token for the newest requested sync run. Older async runs compare against it
54
+ // before publishing results so a slower reconnect cannot overwrite a newer chain/account update.
55
+ let activeSyncToken = null;
49
56
  // provide the client to the app
50
57
  vue.provide(constants.SOLANA_CLIENT_KEY, clientRef);
51
- // watch for changes in the connection and chain namespace
52
- vue.watch([isConnected, connection], async ([newIsConnected, newConnection]) => {
53
- if (!newIsConnected || !(newConnection !== null && newConnection !== void 0 && newConnection.solanaWallet)) {
54
- if (clientRef.value) {
55
- await disposeClient(clientRef.value);
56
- clientRef.value = null;
58
+ const syncClient = async () => {
59
+ var _web3Auth$value, _web3Auth$value2;
60
+ // Only the latest async, `syncing` run should be allowed to attach its client.
61
+ // A fresh Symbol gives each run a unique identity without relying on counters.
62
+ const syncToken = Symbol("solana-client-sync");
63
+ activeSyncToken = syncToken;
64
+ const newIsConnected = isConnected.value;
65
+ const newConnection = connection.value;
66
+ const currentChain = (_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.currentChain;
67
+ if (!newIsConnected || !(newConnection !== null && newConnection !== void 0 && newConnection.solanaWallet) || (currentChain === null || currentChain === void 0 ? void 0 : currentChain.chainNamespace) !== baseControllers.CHAIN_NAMESPACES.SOLANA ||
68
+ // only reconnect for the primary connector
69
+ newConnection.connectorName !== ((_web3Auth$value2 = web3Auth.value) === null || _web3Auth$value2 === void 0 ? void 0 : _web3Auth$value2.primaryConnectorName)) {
70
+ const prevClient = clientRef.value;
71
+ clientRef.value = null;
72
+ if (prevClient) {
73
+ await disposeClient(prevClient);
57
74
  }
58
75
  return;
59
76
  }
60
- const currentChain = web3Auth.value.currentChain;
61
- let chainConfig;
62
- if ((currentChain === null || currentChain === void 0 ? void 0 : currentChain.chainNamespace) === baseControllers.CHAIN_NAMESPACES.SOLANA) {
63
- chainConfig = currentChain;
64
- } else {
65
- // use the 1st Solana chain if current chain is not solana
66
- chainConfig = web3Auth.value.coreOptions.chains.find(c => c.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA);
67
- if (!chainConfig) return;
68
- }
69
77
  const prevClient = clientRef.value;
78
+ clientRef.value = null;
79
+ if (prevClient) {
80
+ await disposeClient(prevClient);
81
+ }
82
+ let client$1 = null;
70
83
  try {
71
84
  // create a wallet standard connector from connected wallet
72
- const solanaWalletId = "wallet-standard:" + connection.value.connectorName;
73
- const connector = client.createWalletStandardConnector(connection.value.solanaWallet, {
85
+ const solanaWalletId = "wallet-standard:" + newConnection.connectorName;
86
+ const connector = client.createWalletStandardConnector(newConnection.solanaWallet, {
74
87
  id: solanaWalletId,
75
- name: connection.value.connectorName
88
+ name: newConnection.connectorName
76
89
  });
77
90
  // create a solana client
78
91
  const {
79
92
  rpcTarget,
80
93
  wsTarget
81
- } = chainConfig;
82
- const client$1 = client.createClient({
94
+ } = currentChain;
95
+ client$1 = client.createClient({
83
96
  endpoint: rpcTarget,
84
97
  websocketEndpoint: wsTarget,
85
98
  walletConnectors: [connector]
86
99
  });
87
- clientRef.value = client$1;
88
- if (prevClient) await disposeClient(prevClient);
89
100
  // connect the client to the wallet
90
101
  await client$1.actions.connectWallet(solanaWalletId, {
91
102
  autoConnect: true
92
103
  });
104
+ // If another sync started while connectWallet was in flight, this client is stale.
105
+ if (activeSyncToken !== syncToken) {
106
+ await disposeClient(client$1);
107
+ return;
108
+ }
109
+ clientRef.value = client$1;
93
110
  } catch (err) {
111
+ if (client$1) {
112
+ await disposeClient(client$1);
113
+ }
94
114
  loglevel.log.error("Failed to create or connect Solana client", err);
95
- clientRef.value = null;
115
+ // Only clear the shared ref when this failing run is still the newest one.
116
+ if (activeSyncToken === syncToken) {
117
+ clientRef.value = null;
118
+ }
96
119
  }
120
+ };
121
+ // watch for changes in the connection and active chain
122
+ vue.watch([isConnected, connection, chainId], () => {
123
+ void syncClient();
97
124
  }, {
98
125
  immediate: true
99
126
  });
@@ -105,7 +105,7 @@ function useWeb3AuthInnerContextValue({
105
105
  var _web3Auth$value$curre, _web3Auth$value$curre2;
106
106
  if (!isInitialized.value) isInitialized.value = true;
107
107
  isConnected.value = true;
108
- connection.value = newWeb3Auth.connection;
108
+ connection.value = web3Auth.value.connection;
109
109
  chainId.value = web3Auth.value.currentChainId;
110
110
  chainNamespace.value = (_web3Auth$value$curre = (_web3Auth$value$curre2 = web3Auth.value.currentChain) === null || _web3Auth$value$curre2 === void 0 ? void 0 : _web3Auth$value$curre2.chainNamespace) !== null && _web3Auth$value$curre !== void 0 ? _web3Auth$value$curre : null;
111
111
  }
@@ -123,7 +123,7 @@ function useWeb3AuthInnerContextValue({
123
123
  var _web3Auth$value$curre3, _web3Auth$value$curre4;
124
124
  if (!isInitialized.value) isInitialized.value = true;
125
125
  isConnected.value = true;
126
- connection.value = newWeb3Auth.connection;
126
+ connection.value = web3Auth.value.connection;
127
127
  chainId.value = web3Auth.value.currentChainId;
128
128
  chainNamespace.value = (_web3Auth$value$curre3 = (_web3Auth$value$curre4 = web3Auth.value.currentChain) === null || _web3Auth$value$curre4 === void 0 ? void 0 : _web3Auth$value$curre4.chainNamespace) !== null && _web3Auth$value$curre3 !== void 0 ? _web3Auth$value$curre3 : null;
129
129
  if (web3Auth.value.status === constants.CONNECTOR_STATUS.AUTHORIZED) {
@@ -147,6 +147,13 @@ function useWeb3AuthInnerContextValue({
147
147
  const mfaEnabledListener = () => {
148
148
  isMFAEnabled.value = true;
149
149
  };
150
+ const connectionUpdatedListener = () => {
151
+ var _web3Auth$value$curre5, _web3Auth$value$curre6;
152
+ status.value = web3Auth.value.status;
153
+ connection.value = web3Auth.value.connection;
154
+ chainId.value = web3Auth.value.currentChainId;
155
+ chainNamespace.value = (_web3Auth$value$curre5 = (_web3Auth$value$curre6 = web3Auth.value.currentChain) === null || _web3Auth$value$curre6 === void 0 ? void 0 : _web3Auth$value$curre6.chainNamespace) !== null && _web3Auth$value$curre5 !== void 0 ? _web3Auth$value$curre5 : null;
156
+ };
150
157
  if (prevWeb3Auth && newWeb3Auth !== prevWeb3Auth) {
151
158
  prevWeb3Auth.removeListener(constants.CONNECTOR_EVENTS.NOT_READY, notReadyListener);
152
159
  prevWeb3Auth.removeListener(constants.CONNECTOR_EVENTS.READY, readyListener);
@@ -157,6 +164,7 @@ function useWeb3AuthInnerContextValue({
157
164
  prevWeb3Auth.removeListener(constants.CONNECTOR_EVENTS.ERRORED, errorListener);
158
165
  prevWeb3Auth.removeListener(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, errorListener);
159
166
  prevWeb3Auth.removeListener(constants.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
167
+ prevWeb3Auth.removeListener(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, connectionUpdatedListener);
160
168
  if (prevWeb3Auth.loginMode === constants$1.LOGIN_MODE.MODAL) {
161
169
  prevWeb3Auth.removeListener(constants.CONNECTOR_EVENTS.CONSENT_ACCEPTED, consentAcceptedListener);
162
170
  }
@@ -172,6 +180,7 @@ function useWeb3AuthInnerContextValue({
172
180
  newWeb3Auth.on(constants.CONNECTOR_EVENTS.ERRORED, errorListener);
173
181
  newWeb3Auth.on(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, errorListener);
174
182
  newWeb3Auth.on(constants.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
183
+ newWeb3Auth.on(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, connectionUpdatedListener);
175
184
  if (newWeb3Auth.loginMode === constants$1.LOGIN_MODE.MODAL) {
176
185
  newWeb3Auth.on(constants.CONNECTOR_EVENTS.CONSENT_ACCEPTED, consentAcceptedListener);
177
186
  }
@@ -182,9 +191,9 @@ function useWeb3AuthInnerContextValue({
182
191
  vue.watch(connection, (newConnection, prevConnection) => {
183
192
  var _prevConnection$ether, _newConnection$ethere;
184
193
  const handleChainChange = newChainId => {
185
- var _web3Auth$value$curre5, _web3Auth$value;
194
+ var _web3Auth$value$curre7, _web3Auth$value;
186
195
  chainId.value = newChainId;
187
- chainNamespace.value = (_web3Auth$value$curre5 = (_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 || (_web3Auth$value = _web3Auth$value.currentChain) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.chainNamespace) !== null && _web3Auth$value$curre5 !== void 0 ? _web3Auth$value$curre5 : null;
196
+ chainNamespace.value = (_web3Auth$value$curre7 = (_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 || (_web3Auth$value = _web3Auth$value.currentChain) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.chainNamespace) !== null && _web3Auth$value$curre7 !== void 0 ? _web3Auth$value$curre7 : null;
188
197
  };
189
198
  const prevProvider = (_prevConnection$ether = prevConnection === null || prevConnection === void 0 ? void 0 : prevConnection.ethereumProvider) !== null && _prevConnection$ether !== void 0 ? _prevConnection$ether : null;
190
199
  const newProvider = (_newConnection$ethere = newConnection === null || newConnection === void 0 ? void 0 : newConnection.ethereumProvider) !== null && _newConnection$ethere !== void 0 ? _newConnection$ethere : null;
@@ -89,7 +89,8 @@ const Web3AuthWagmiProvider = vue.defineComponent({
89
89
  setup() {
90
90
  const {
91
91
  isConnected,
92
- connection
92
+ connection,
93
+ chainNamespace
93
94
  } = useWeb3Auth.useWeb3Auth();
94
95
  const {
95
96
  disconnect
@@ -98,10 +99,15 @@ const Web3AuthWagmiProvider = vue.defineComponent({
98
99
  const {
99
100
  mutate: reconnect
100
101
  } = vue$1.useReconnect();
102
+ const lastSyncedProvider = vue.shallowRef(null);
103
+ const lastSyncedConnectorName = vue.ref(null);
104
+ const suppressWagmiDisconnect = vue.ref(false);
101
105
  vue$1.useConnectionEffect({
102
106
  onDisconnect: async () => {
103
107
  loglevel.log.info("Disconnected from wagmi");
104
- if (isConnected.value) await disconnect();
108
+ const isSuppressed = suppressWagmiDisconnect.value;
109
+ suppressWagmiDisconnect.value = false;
110
+ if (!isSuppressed && isConnected.value) await disconnect();
105
111
  const connector = getWeb3authConnector(wagmiConfig);
106
112
  // reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
107
113
  // from the connected provider
@@ -110,19 +116,41 @@ const Web3AuthWagmiProvider = vue.defineComponent({
110
116
  }
111
117
  }
112
118
  });
113
- vue.watch([isConnected, connection], async () => {
114
- var _connection$value;
119
+ vue.watch([isConnected, connection, chainNamespace], async () => {
120
+ var _newConnection$ethere;
115
121
  const newIsConnected = isConnected.value;
116
- if (newIsConnected && (_connection$value = connection.value) !== null && _connection$value !== void 0 && _connection$value.ethereumProvider) {
117
- const connector = await setupConnector(connection.value.ethereumProvider, wagmiConfig);
122
+ const newConnection = connection.value;
123
+ const newEth = (_newConnection$ethere = newConnection === null || newConnection === void 0 ? void 0 : newConnection.ethereumProvider) !== null && _newConnection$ethere !== void 0 ? _newConnection$ethere : null;
124
+ const shouldBindToWagmi = newIsConnected && chainNamespace.value === baseControllers.CHAIN_NAMESPACES.EIP155 && Boolean(newConnection && newEth);
125
+ if (shouldBindToWagmi && newConnection && newEth) {
126
+ const hasSameBinding = lastSyncedProvider.value === newEth && lastSyncedConnectorName.value === newConnection.connectorName;
127
+ if (hasSameBinding && wagmiConfig.state.status === "connected") {
128
+ return;
129
+ }
130
+ if (!hasSameBinding && getWeb3authConnector(wagmiConfig)) {
131
+ if (wagmiConfig.state.status === "connected") {
132
+ suppressWagmiDisconnect.value = true;
133
+ await disconnectWeb3AuthFromWagmi(wagmiConfig);
134
+ } else {
135
+ resetConnectorState(wagmiConfig);
136
+ }
137
+ }
138
+ const connector = await setupConnector(newEth, wagmiConfig);
118
139
  if (!connector) {
119
140
  throw new Error("Failed to setup connector");
120
141
  }
121
142
  await connectWeb3AuthWithWagmi(connector, wagmiConfig);
143
+ lastSyncedProvider.value = newEth;
144
+ lastSyncedConnectorName.value = newConnection.connectorName;
122
145
  reconnect();
123
- } else if (!newIsConnected) {
146
+ } else {
147
+ lastSyncedProvider.value = null;
148
+ lastSyncedConnectorName.value = null;
124
149
  if (wagmiConfig.state.status === "connected") {
150
+ suppressWagmiDisconnect.value = true;
125
151
  await disconnectWeb3AuthFromWagmi(wagmiConfig);
152
+ } else if (getWeb3authConnector(wagmiConfig)) {
153
+ resetConnectorState(wagmiConfig);
126
154
  }
127
155
  }
128
156
  }, {
@@ -0,0 +1 @@
1
+ export { makeAccountLinkingRequest, makeAccountUnlinkingRequest } from './rest.js';
@@ -0,0 +1,74 @@
1
+ import { useState, useCallback } from 'react';
2
+ import { useWeb3AuthInner } from '../react/hooks/useWeb3AuthInner.js';
3
+ import { WalletInitializationError } from '../base/errors/index.js';
4
+ export { makeAccountLinkingRequest, makeAccountUnlinkingRequest } from './rest.js';
5
+
6
+ const useLinkAccount = () => {
7
+ const {
8
+ web3Auth
9
+ } = useWeb3AuthInner();
10
+ const [loading, setLoading] = useState(false);
11
+ const [error, setError] = useState(null);
12
+ const [linkedAccounts, setLinkedAccounts] = useState([]);
13
+ const linkAccount = useCallback(async params => {
14
+ if (!web3Auth) throw WalletInitializationError.notReady();
15
+ setLoading(true);
16
+ setError(null);
17
+ try {
18
+ const result = await web3Auth.linkAccount(params);
19
+ setLinkedAccounts(result.linkedAccounts);
20
+ return result;
21
+ } catch (err) {
22
+ setError(err);
23
+ } finally {
24
+ setLoading(false);
25
+ }
26
+ }, [web3Auth]);
27
+ const unlinkAccount = useCallback(async address => {
28
+ if (!web3Auth) throw WalletInitializationError.notReady();
29
+ setLoading(true);
30
+ setError(null);
31
+ try {
32
+ const result = await web3Auth.unlinkAccount(address);
33
+ setLinkedAccounts(result.linkedAccounts);
34
+ return result;
35
+ } catch (err) {
36
+ setError(err);
37
+ } finally {
38
+ setLoading(false);
39
+ }
40
+ }, [web3Auth]);
41
+ return {
42
+ loading,
43
+ error,
44
+ linkAccount,
45
+ unlinkAccount,
46
+ linkedAccounts
47
+ };
48
+ };
49
+ const useSwitchAccount = () => {
50
+ const {
51
+ web3Auth
52
+ } = useWeb3AuthInner();
53
+ const [loading, setLoading] = useState(false);
54
+ const [error, setError] = useState(null);
55
+ const switchAccount = useCallback(async account => {
56
+ if (!web3Auth) throw WalletInitializationError.notReady();
57
+ setLoading(true);
58
+ setError(null);
59
+ try {
60
+ await web3Auth.switchAccount(account);
61
+ } catch (err) {
62
+ setError(err);
63
+ } finally {
64
+ setLoading(false);
65
+ }
66
+ }, [web3Auth]);
67
+ return {
68
+ loading,
69
+ error,
70
+ switchAccount
71
+ };
72
+ };
73
+
74
+ export { useLinkAccount, useSwitchAccount };
@@ -0,0 +1,51 @@
1
+ import { post } from '@toruslabs/http-helpers';
2
+ import { AccountLinkingError } from '../base/errors/index.js';
3
+
4
+ /**
5
+ * Send both identity proofs to the Citadel account-linking endpoint and
6
+ * return a normalized result.
7
+ *
8
+ * Throws AccountLinkingError when the server returns an error or the request itself fails.
9
+ */
10
+ async function makeAccountLinkingRequest(authServerUrl, accessToken, payload) {
11
+ const url = `${authServerUrl}/v1/link/wallet`;
12
+ let result;
13
+ try {
14
+ result = await post(url, payload, {
15
+ headers: {
16
+ Authorization: `Bearer ${accessToken}`
17
+ }
18
+ });
19
+ } catch (cause) {
20
+ const message = cause instanceof Error ? cause.message : String(cause);
21
+ throw AccountLinkingError.requestFailed(message, cause);
22
+ }
23
+ if (!result.success) {
24
+ var _result$message;
25
+ const errMessage = (_result$message = result.message) !== null && _result$message !== void 0 ? _result$message : "Failed to link account";
26
+ throw AccountLinkingError.requestFailed(errMessage);
27
+ }
28
+ return result;
29
+ }
30
+ async function makeAccountUnlinkingRequest(authServerUrl, accessToken, payload) {
31
+ const url = `${authServerUrl}/v1/unlink`;
32
+ let result;
33
+ try {
34
+ result = await post(url, payload, {
35
+ headers: {
36
+ Authorization: `Bearer ${accessToken}`
37
+ }
38
+ });
39
+ } catch (cause) {
40
+ const message = cause instanceof Error ? cause.message : String(cause);
41
+ throw AccountLinkingError.requestFailed(message, cause);
42
+ }
43
+ if (!result.success) {
44
+ var _result$message2;
45
+ const errMessage = (_result$message2 = result.message) !== null && _result$message2 !== void 0 ? _result$message2 : "Failed to unlink account";
46
+ throw AccountLinkingError.requestFailed(errMessage);
47
+ }
48
+ return result;
49
+ }
50
+
51
+ export { makeAccountLinkingRequest, makeAccountUnlinkingRequest };
@@ -0,0 +1,78 @@
1
+ import { ref } from 'vue';
2
+ import { useWeb3AuthInner } from '../vue/composables/useWeb3AuthInner.js';
3
+ import { WalletInitializationError } from '../base/errors/index.js';
4
+ import { log } from '../base/loglevel.js';
5
+ export { makeAccountLinkingRequest, makeAccountUnlinkingRequest } from './rest.js';
6
+
7
+ const useLinkAccount = () => {
8
+ const {
9
+ web3Auth
10
+ } = useWeb3AuthInner();
11
+ const loading = ref(false);
12
+ const error = ref(null);
13
+ const linkedAccounts = ref([]);
14
+ const linkAccount = async params => {
15
+ if (!web3Auth.value) throw WalletInitializationError.notReady();
16
+ try {
17
+ error.value = null;
18
+ loading.value = true;
19
+ const result = await web3Auth.value.linkAccount(params);
20
+ linkedAccounts.value = result.linkedAccounts;
21
+ return result;
22
+ } catch (err) {
23
+ log.error("Error linking account", err);
24
+ error.value = err;
25
+ } finally {
26
+ loading.value = false;
27
+ }
28
+ };
29
+ const unlinkAccount = async address => {
30
+ if (!web3Auth.value) throw WalletInitializationError.notReady();
31
+ try {
32
+ error.value = null;
33
+ loading.value = true;
34
+ const result = await web3Auth.value.unlinkAccount(address);
35
+ linkedAccounts.value = result.linkedAccounts;
36
+ return result;
37
+ } catch (err) {
38
+ log.error("Error unlinking account", err);
39
+ error.value = err;
40
+ } finally {
41
+ loading.value = false;
42
+ }
43
+ };
44
+ return {
45
+ loading,
46
+ error,
47
+ linkAccount,
48
+ unlinkAccount,
49
+ linkedAccounts
50
+ };
51
+ };
52
+ const useSwitchAccount = () => {
53
+ const {
54
+ web3Auth
55
+ } = useWeb3AuthInner();
56
+ const loading = ref(false);
57
+ const error = ref(null);
58
+ const switchAccount = async account => {
59
+ if (!web3Auth.value) throw WalletInitializationError.notReady();
60
+ error.value = null;
61
+ loading.value = true;
62
+ try {
63
+ await web3Auth.value.switchAccount(account);
64
+ } catch (err) {
65
+ log.error("Error switching account", err);
66
+ error.value = err;
67
+ } finally {
68
+ loading.value = false;
69
+ }
70
+ };
71
+ return {
72
+ loading,
73
+ error,
74
+ switchAccount
75
+ };
76
+ };
77
+
78
+ export { useLinkAccount, useSwitchAccount };
@@ -11,6 +11,9 @@ class Analytics {
11
11
  _defineProperty(this, "enabled", true);
12
12
  }
13
13
  init() {
14
+ if (!this.enabled) {
15
+ return;
16
+ }
14
17
  if (this.isSkipped()) {
15
18
  return;
16
19
  }
@@ -74,7 +77,7 @@ class Analytics {
74
77
  isSkipped() {
75
78
  const dappOrigin = window.location.origin;
76
79
 
77
- // skip if the protocol is not http or https
80
+ // skip if the protocol is http
78
81
  if (dappOrigin.startsWith("http://")) {
79
82
  return true;
80
83
  }
@@ -115,7 +118,19 @@ const ANALYTICS_EVENTS = {
115
118
  WALLET_FUNDING_CLICKED: "Wallet Funding Clicked",
116
119
  WALLET_CHECKOUT_CLICKED: "Wallet Checkout Clicked",
117
120
  WALLET_RECEIVE_CLICKED: "Wallet Receive Clicked",
118
- WALLET_SWAP_CLICKED: "Wallet Swap Clicked"
121
+ WALLET_SWAP_CLICKED: "Wallet Swap Clicked",
122
+ // Account Linking
123
+ ACCOUNT_LINKING_STARTED: "Account Linking Started",
124
+ ACCOUNT_LINKING_COMPLETED: "Account Linking Completed",
125
+ ACCOUNT_LINKING_FAILED: "Account Linking Failed",
126
+ // Account Unlinking
127
+ ACCOUNT_UNLINKING_STARTED: "Account Unlinking Started",
128
+ ACCOUNT_UNLINKING_COMPLETED: "Account Unlinking Completed",
129
+ ACCOUNT_UNLINKING_FAILED: "Account Unlinking Failed",
130
+ // Account switch (active connected wallet)
131
+ ACCOUNT_SWITCH_STARTED: "Account Switch Started",
132
+ ACCOUNT_SWITCH_COMPLETED: "Account Switch Completed",
133
+ ACCOUNT_SWITCH_FAILED: "Account Switch Failed"
119
134
  };
120
135
  const ANALYTICS_INTEGRATION_TYPE = {
121
136
  REACT_HOOKS: "React Hooks",