@dynamic-labs/sdk-react-core 1.0.6 → 1.0.7

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 (38) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.cjs +3 -3
  3. package/package.js +3 -3
  4. package/package.json +12 -12
  5. package/src/index.cjs +10 -8
  6. package/src/index.js +5 -4
  7. package/src/lib/components/MenuList/Dropdown/Dropdown.cjs +1 -1
  8. package/src/lib/components/MenuList/Dropdown/Dropdown.js +1 -1
  9. package/src/lib/components/SyncPasskeyFlow/SyncPasskeyFlow.cjs +2 -2
  10. package/src/lib/components/SyncPasskeyFlow/SyncPasskeyFlow.js +2 -2
  11. package/src/lib/context/DynamicContext/DynamicContext.cjs +2 -2
  12. package/src/lib/context/DynamicContext/DynamicContext.js +2 -2
  13. package/src/lib/data/api.cjs +2 -2
  14. package/src/lib/data/api.d.ts +1 -0
  15. package/src/lib/data/api.js +2 -2
  16. package/src/lib/shared/utils/hooks/index.d.ts +5 -4
  17. package/src/lib/shared/utils/hooks/useThrottle/index.d.ts +1 -0
  18. package/src/lib/shared/utils/hooks/useThrottle/useThrottle.cjs +29 -0
  19. package/src/lib/shared/utils/hooks/useThrottle/useThrottle.d.ts +8 -0
  20. package/src/lib/shared/utils/hooks/useThrottle/useThrottle.js +25 -0
  21. package/src/lib/utils/functions/getWalletIdentifier/getWalletIdentifier.cjs +1 -1
  22. package/src/lib/utils/functions/getWalletIdentifier/getWalletIdentifier.d.ts +1 -1
  23. package/src/lib/utils/functions/getWalletIdentifier/getWalletIdentifier.js +1 -1
  24. package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.cjs +13 -2
  25. package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.js +13 -2
  26. package/src/lib/utils/hooks/useColorSchemePreference/useColorSchemePreference.cjs +1 -1
  27. package/src/lib/utils/hooks/useColorSchemePreference/useColorSchemePreference.js +1 -1
  28. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.cjs +14 -6
  29. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.js +14 -6
  30. package/src/lib/utils/hooks/useFetchProjectSettings/useFetchProjectSettings.cjs +15 -1
  31. package/src/lib/utils/hooks/useFetchProjectSettings/useFetchProjectSettings.js +16 -2
  32. package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.cjs +8 -8
  33. package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.js +8 -8
  34. package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.cjs +4 -3
  35. package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.js +4 -3
  36. package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.cjs +65 -45
  37. package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.d.ts +5 -7
  38. package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.js +66 -46
package/CHANGELOG.md CHANGED
@@ -1,4 +1,16 @@
1
1
 
2
+ ### [1.0.7](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.6...v1.0.7) (2024-01-25)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * add support for newest backpack extension ([66786ce](https://github.com/dynamic-labs/DynamicAuth/commit/66786ceb7927046c1cdb439888271f3070ca93a4))
8
+ * broken help icon in create passkey view ([2e38ea5](https://github.com/dynamic-labs/DynamicAuth/commit/2e38ea580e55f3349a2d3040d7b07bb2923631f7))
9
+ * connect to wallet with wallet connect even if network is not supported ([#4465](https://github.com/dynamic-labs/DynamicAuth/issues/4465)) ([#4472](https://github.com/dynamic-labs/DynamicAuth/issues/4472)) ([8270b94](https://github.com/dynamic-labs/DynamicAuth/commit/8270b9468c289e7c49cd2ef104fb73dfaaa9f41c))
10
+ * infinite loop when connecting with trust wallet ([#4448](https://github.com/dynamic-labs/DynamicAuth/issues/4448)) ([#4450](https://github.com/dynamic-labs/DynamicAuth/issues/4450)) ([c5ffee6](https://github.com/dynamic-labs/DynamicAuth/commit/c5ffee67a6a95ee62e779da69ce311c90575388f))
11
+ * logging in with an email linked to a third party wallet gets stu… ([#4422](https://github.com/dynamic-labs/DynamicAuth/issues/4422)) ([995889b](https://github.com/dynamic-labs/DynamicAuth/commit/995889b5d03bcbafecd6959c52a88db8d9db940e))
12
+ * switching wallet in extension caused connected flag to be false ([#4464](https://github.com/dynamic-labs/DynamicAuth/issues/4464)) ([a53dc1a](https://github.com/dynamic-labs/DynamicAuth/commit/a53dc1a9869a270c98753041cfbd587855629af4)), closes [#4454](https://github.com/dynamic-labs/DynamicAuth/issues/4454)
13
+
2
14
  ### [1.0.6](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.5...v1.0.6) (2024-01-18)
3
15
 
4
16
 
package/package.cjs CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = "1.0.6";
5
+ var version = "1.0.7";
6
6
  var dependencies = {
7
- "@dynamic-labs/iconic": "0.1.47",
8
- "@dynamic-labs/sdk-api": "0.0.333",
7
+ "@dynamic-labs/iconic": "0.1.48",
8
+ "@dynamic-labs/sdk-api": "0.0.347",
9
9
  "@hcaptcha/react-hcaptcha": "1.4.4",
10
10
  "country-list": "2.3.0",
11
11
  formik: "2.2.9",
package/package.js CHANGED
@@ -1,7 +1,7 @@
1
- var version = "1.0.6";
1
+ var version = "1.0.7";
2
2
  var dependencies = {
3
- "@dynamic-labs/iconic": "0.1.47",
4
- "@dynamic-labs/sdk-api": "0.0.333",
3
+ "@dynamic-labs/iconic": "0.1.48",
4
+ "@dynamic-labs/sdk-api": "0.0.347",
5
5
  "@hcaptcha/react-hcaptcha": "1.4.4",
6
6
  "country-list": "2.3.0",
7
7
  formik: "2.2.9",
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@dynamic-labs/sdk-react-core",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
7
7
  "directory": "packages/sdk-react-core"
8
8
  },
9
9
  "dependencies": {
10
- "@dynamic-labs/iconic": "0.1.47",
11
- "@dynamic-labs/sdk-api": "0.0.333",
10
+ "@dynamic-labs/iconic": "0.1.48",
11
+ "@dynamic-labs/sdk-api": "0.0.347",
12
12
  "@hcaptcha/react-hcaptcha": "1.4.4",
13
13
  "country-list": "2.3.0",
14
14
  "formik": "2.2.9",
@@ -17,15 +17,15 @@
17
17
  "react-focus-lock": "2.9.2",
18
18
  "react-i18next": "^13.2.0",
19
19
  "yup": "0.32.11",
20
- "@dynamic-labs/ethereum": "1.0.6",
21
- "@dynamic-labs/logger": "1.0.6",
22
- "@dynamic-labs/multi-wallet": "1.0.6",
23
- "@dynamic-labs/rpc-providers": "1.0.6",
24
- "@dynamic-labs/types": "1.0.6",
25
- "@dynamic-labs/utils": "1.0.6",
26
- "@dynamic-labs/viem-utils": "1.0.6",
27
- "@dynamic-labs/wallet-book": "1.0.6",
28
- "@dynamic-labs/wallet-connector-core": "1.0.6",
20
+ "@dynamic-labs/ethereum": "1.0.7",
21
+ "@dynamic-labs/logger": "1.0.7",
22
+ "@dynamic-labs/multi-wallet": "1.0.7",
23
+ "@dynamic-labs/rpc-providers": "1.0.7",
24
+ "@dynamic-labs/types": "1.0.7",
25
+ "@dynamic-labs/utils": "1.0.7",
26
+ "@dynamic-labs/viem-utils": "1.0.7",
27
+ "@dynamic-labs/wallet-book": "1.0.7",
28
+ "@dynamic-labs/wallet-connector-core": "1.0.7",
29
29
  "eventemitter3": "5.0.1"
30
30
  },
31
31
  "devDependencies": {
package/src/index.cjs CHANGED
@@ -38,13 +38,14 @@ var getWalletListItemLabel = require('./lib/shared/utils/functions/getWalletList
38
38
  var formatBigNumber = require('./lib/shared/utils/functions/formatBigNumber/formatBigNumber.cjs');
39
39
  var trimEnd = require('./lib/shared/utils/functions/trimEnd/trimEnd.cjs');
40
40
  var ceil = require('./lib/shared/utils/functions/ceil/ceil.cjs');
41
+ var useEffectOnce = require('./lib/shared/utils/hooks/useEffectOnce/useEffectOnce.cjs');
42
+ var useForwardedRef = require('./lib/shared/utils/hooks/useForwardedRef/useForwardedRef.cjs');
43
+ var useGlobalLoading = require('./lib/shared/utils/hooks/useGlobalLoading/useGlobalLoading.cjs');
41
44
  var useLocalStorage = require('./lib/shared/utils/hooks/useLocalStorage/useLocalStorage.cjs');
45
+ var useMediaQuery = require('./lib/shared/utils/hooks/useMediaQuery/useMediaQuery.cjs');
42
46
  var index$1 = require('./lib/shared/utils/hooks/useOnClickOutside/index.cjs');
43
47
  var usePreventPageScroll = require('./lib/shared/utils/hooks/usePreventPageScroll/usePreventPageScroll.cjs');
44
- var useGlobalLoading = require('./lib/shared/utils/hooks/useGlobalLoading/useGlobalLoading.cjs');
45
- var useMediaQuery = require('./lib/shared/utils/hooks/useMediaQuery/useMediaQuery.cjs');
46
- var useEffectOnce = require('./lib/shared/utils/hooks/useEffectOnce/useEffectOnce.cjs');
47
- var useForwardedRef = require('./lib/shared/utils/hooks/useForwardedRef/useForwardedRef.cjs');
48
+ var useThrottle = require('./lib/shared/utils/hooks/useThrottle/useThrottle.cjs');
48
49
  var localStorage = require('./lib/shared/utils/classes/storage/localStorage.cjs');
49
50
  var PhantomLedgerIcon = require('./lib/shared/assets/wallets/PhantomLedgerIcon/PhantomLedgerIcon.cjs');
50
51
  var addWallet = require('./lib/shared/assets/add-wallet.cjs');
@@ -217,13 +218,14 @@ exports.getWalletListItemLabel = getWalletListItemLabel.getWalletListItemLabel;
217
218
  exports.formatBigNumber = formatBigNumber.formatBigNumber;
218
219
  exports.trimEnd = trimEnd.trimEnd;
219
220
  exports.ceil = ceil.ceil;
221
+ exports.useEffectOnce = useEffectOnce.useEffectOnce;
222
+ exports.useForwardedRef = useForwardedRef.useForwardedRef;
223
+ exports.useGlobalLoading = useGlobalLoading.useGlobalLoading;
220
224
  exports.useLocalStorage = useLocalStorage.useLocalStorage;
225
+ exports.useMediaQuery = useMediaQuery.useMediaQuery;
221
226
  exports.useOnClickOutside = index$1.useOnClickOutside;
222
227
  exports.usePreventPageScroll = usePreventPageScroll.usePreventPageScroll;
223
- exports.useGlobalLoading = useGlobalLoading.useGlobalLoading;
224
- exports.useMediaQuery = useMediaQuery.useMediaQuery;
225
- exports.useEffectOnce = useEffectOnce.useEffectOnce;
226
- exports.useForwardedRef = useForwardedRef.useForwardedRef;
228
+ exports.useThrottle = useThrottle.useThrottle;
227
229
  exports.LocalStorage = localStorage.LocalStorage;
228
230
  exports.PhantomLedgerIcon = PhantomLedgerIcon.PhantomLedgerIcon;
229
231
  exports.AddWalletIcon = addWallet.ReactComponent;
package/src/index.js CHANGED
@@ -34,13 +34,14 @@ export { getWalletListItemLabel } from './lib/shared/utils/functions/getWalletLi
34
34
  export { formatBigNumber } from './lib/shared/utils/functions/formatBigNumber/formatBigNumber.js';
35
35
  export { trimEnd } from './lib/shared/utils/functions/trimEnd/trimEnd.js';
36
36
  export { ceil } from './lib/shared/utils/functions/ceil/ceil.js';
37
+ export { useEffectOnce } from './lib/shared/utils/hooks/useEffectOnce/useEffectOnce.js';
38
+ export { useForwardedRef } from './lib/shared/utils/hooks/useForwardedRef/useForwardedRef.js';
39
+ export { useGlobalLoading } from './lib/shared/utils/hooks/useGlobalLoading/useGlobalLoading.js';
37
40
  export { useLocalStorage } from './lib/shared/utils/hooks/useLocalStorage/useLocalStorage.js';
41
+ export { useMediaQuery } from './lib/shared/utils/hooks/useMediaQuery/useMediaQuery.js';
38
42
  export { useOnClickOutside } from './lib/shared/utils/hooks/useOnClickOutside/index.js';
39
43
  export { usePreventPageScroll } from './lib/shared/utils/hooks/usePreventPageScroll/usePreventPageScroll.js';
40
- export { useGlobalLoading } from './lib/shared/utils/hooks/useGlobalLoading/useGlobalLoading.js';
41
- export { useMediaQuery } from './lib/shared/utils/hooks/useMediaQuery/useMediaQuery.js';
42
- export { useEffectOnce } from './lib/shared/utils/hooks/useEffectOnce/useEffectOnce.js';
43
- export { useForwardedRef } from './lib/shared/utils/hooks/useForwardedRef/useForwardedRef.js';
44
+ export { useThrottle } from './lib/shared/utils/hooks/useThrottle/useThrottle.js';
44
45
  export { LocalStorage } from './lib/shared/utils/classes/storage/localStorage.js';
45
46
  export { PhantomLedgerIcon } from './lib/shared/assets/wallets/PhantomLedgerIcon/PhantomLedgerIcon.js';
46
47
  export { ReactComponent as AddWalletIcon } from './lib/shared/assets/add-wallet.js';
@@ -9,11 +9,11 @@ var classNames = require('../../../utils/functions/classNames/classNames.cjs');
9
9
  var Popper = require('../../Popper/Popper/Popper.cjs');
10
10
  var PopperContext = require('../../Popper/PopperContext/PopperContext.cjs');
11
11
  var watchToScrollInHierarchy = require('../utils/watchToScrollInHierarchy/watchToScrollInHierarchy.cjs');
12
+ var useForwardedRef = require('../../../shared/utils/hooks/useForwardedRef/useForwardedRef.cjs');
12
13
  require('../../../shared/logger.cjs');
13
14
  require('../../../shared/utils/classes/storage/localStorage.cjs');
14
15
  var index = require('../../../shared/utils/hooks/useOnClickOutside/index.cjs');
15
16
  require('@dynamic-labs/utils');
16
- var useForwardedRef = require('../../../shared/utils/hooks/useForwardedRef/useForwardedRef.cjs');
17
17
  require('@dynamic-labs/sdk-api');
18
18
  require('@dynamic-labs/iconic');
19
19
  require('@dynamic-labs/wallet-connector-core');
@@ -5,11 +5,11 @@ import { classNames } from '../../../utils/functions/classNames/classNames.js';
5
5
  import { Popper } from '../../Popper/Popper/Popper.js';
6
6
  import { usePopper } from '../../Popper/PopperContext/PopperContext.js';
7
7
  import { watchToScrollInHierarchy } from '../utils/watchToScrollInHierarchy/watchToScrollInHierarchy.js';
8
+ import { useForwardedRef } from '../../../shared/utils/hooks/useForwardedRef/useForwardedRef.js';
8
9
  import '../../../shared/logger.js';
9
10
  import '../../../shared/utils/classes/storage/localStorage.js';
10
11
  import { useOnClickOutside } from '../../../shared/utils/hooks/useOnClickOutside/index.js';
11
12
  import '@dynamic-labs/utils';
12
- import { useForwardedRef } from '../../../shared/utils/hooks/useForwardedRef/useForwardedRef.js';
13
13
  import '@dynamic-labs/sdk-api';
14
14
  import '@dynamic-labs/iconic';
15
15
  import '@dynamic-labs/wallet-connector-core';
@@ -3,13 +3,13 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _tslib = require('../../../../_virtual/_tslib.cjs');
6
- var jsxRuntime = require('react/jsx-runtime');
7
6
  var React = require('react');
8
7
  var useInternalDynamicContext = require('../../context/DynamicContext/useInternalDynamicContext.cjs');
9
8
  require('@dynamic-labs/sdk-api');
10
9
  require('../../shared/logger.cjs');
11
10
  require('@dynamic-labs/iconic');
12
11
  require('@dynamic-labs/wallet-connector-core');
12
+ require('react/jsx-runtime');
13
13
  require('../../context/ViewContext/ViewContext.cjs');
14
14
  require('@dynamic-labs/wallet-book');
15
15
  var localStorage$1 = require('../../utils/constants/localStorage.cjs');
@@ -102,7 +102,7 @@ const SyncPasskeyFlow = () => {
102
102
  user,
103
103
  createEmbeddedWallet,
104
104
  ]);
105
- return jsxRuntime.jsx(jsxRuntime.Fragment, {});
105
+ return null;
106
106
  };
107
107
 
108
108
  exports.SyncPasskeyFlow = SyncPasskeyFlow;
@@ -1,11 +1,11 @@
1
1
  import { __awaiter } from '../../../../_virtual/_tslib.js';
2
- import { jsx, Fragment } from 'react/jsx-runtime';
3
2
  import { useEffect } from 'react';
4
3
  import { useInternalDynamicContext } from '../../context/DynamicContext/useInternalDynamicContext.js';
5
4
  import '@dynamic-labs/sdk-api';
6
5
  import '../../shared/logger.js';
7
6
  import '@dynamic-labs/iconic';
8
7
  import '@dynamic-labs/wallet-connector-core';
8
+ import 'react/jsx-runtime';
9
9
  import '../../context/ViewContext/ViewContext.js';
10
10
  import '@dynamic-labs/wallet-book';
11
11
  import { LAST_USED_WALLET } from '../../utils/constants/localStorage.js';
@@ -98,7 +98,7 @@ const SyncPasskeyFlow = () => {
98
98
  user,
99
99
  createEmbeddedWallet,
100
100
  ]);
101
- return jsx(Fragment, {});
101
+ return null;
102
102
  };
103
103
 
104
104
  export { SyncPasskeyFlow };
@@ -21,8 +21,8 @@ require('../../utils/constants/colors.cjs');
21
21
  var values = require('../../utils/constants/values.cjs');
22
22
  var localStorage = require('../../shared/utils/classes/storage/localStorage.cjs');
23
23
  require('viem');
24
- var useLocalStorage = require('../../shared/utils/hooks/useLocalStorage/useLocalStorage.cjs');
25
24
  var useGlobalLoading = require('../../shared/utils/hooks/useGlobalLoading/useGlobalLoading.cjs');
25
+ var useLocalStorage = require('../../shared/utils/hooks/useLocalStorage/useLocalStorage.cjs');
26
26
  require('../../shared/consts/index.cjs');
27
27
  require('@dynamic-labs/multi-wallet');
28
28
  var getAuthToken = require('../../utils/functions/getAuthToken/getAuthToken.cjs');
@@ -118,7 +118,7 @@ const DynamicContext = React.createContext(undefined);
118
118
  /** The context provider itself we only use internally */
119
119
  const InnerDynamicContextProvider = ({ children, theme, settings, locale: locale$1, }) => {
120
120
  var _a, _b, _c, _d, _e, _f, _g, _h;
121
- const { accessDeniedMessagePrimary, accessDeniedMessageSecondary, accessDeniedButton, apiBaseUrl, enableForcedNetworkValidation: enableForcedNetworkValidationProp = false, deepLinkPreference = 'native', bridgeChains, cssOverrides, defaultNumberOfWalletsToShow = values.DEFAULT_NUMBER_OF_WALLETS_TO_SHOW, flowNetwork, initialAuthenticationMode = 'connect-and-sign', debugError = false, displaySiweStatement = true, newToWeb3WalletChainMap, enableVisitTrackingOnConnectOnly = true, environmentId, localStorageSuffix, eventsCallbacks, evmNetworks, walletsFilter, logLevel = 'WARN', notInTheListImageUrl, onboardingImageUrl, policiesConsentInnerComponent, customPrivacyPolicy, privacyPolicyUrl, signWithEmailWalletName, socialMediaLinkText, socialMediaIconUrl, socialMediaUrl, customTermsOfServices, termsOfServiceUrl, toolkitEnabled, siweStatement, shadowDOMEnabled = true, walletConnectors: walletConnectorsProp, socialProvidersFilter, showLockedWalletView = true, walletConnectPreferredChains, walletConnectorExtensions, } = settings;
121
+ const { accessDeniedMessagePrimary, accessDeniedMessageSecondary, accessDeniedButton, apiBaseUrl, enableForcedNetworkValidation: enableForcedNetworkValidationProp = false, deepLinkPreference = 'native', bridgeChains, cssOverrides, defaultNumberOfWalletsToShow = values.DEFAULT_NUMBER_OF_WALLETS_TO_SHOW, flowNetwork, initialAuthenticationMode = 'connect-and-sign', debugError = false, displaySiweStatement = true, newToWeb3WalletChainMap, enableVisitTrackingOnConnectOnly = true, environmentId, localStorageSuffix, eventsCallbacks, evmNetworks, walletsFilter, logLevel = 'WARN', notInTheListImageUrl, onboardingImageUrl, policiesConsentInnerComponent, customPrivacyPolicy, privacyPolicyUrl, signWithEmailWalletName, socialMediaLinkText, socialMediaIconUrl, socialMediaUrl, customTermsOfServices, termsOfServiceUrl, toolkitEnabled, siweStatement, shadowDOMEnabled = true, walletConnectors: walletConnectorsProp, socialProvidersFilter, showLockedWalletView = false, walletConnectPreferredChains, walletConnectorExtensions, } = settings;
122
122
  let enableForcedNetworkValidation = enableForcedNetworkValidationProp;
123
123
  if (bridgeChains) {
124
124
  enableForcedNetworkValidation = true;
@@ -17,8 +17,8 @@ import '../../utils/constants/colors.js';
17
17
  import { DEFAULT_NUMBER_OF_WALLETS_TO_SHOW } from '../../utils/constants/values.js';
18
18
  import { LocalStorage } from '../../shared/utils/classes/storage/localStorage.js';
19
19
  import 'viem';
20
- import { useLocalStorage } from '../../shared/utils/hooks/useLocalStorage/useLocalStorage.js';
21
20
  import { useGlobalLoading } from '../../shared/utils/hooks/useGlobalLoading/useGlobalLoading.js';
21
+ import { useLocalStorage } from '../../shared/utils/hooks/useLocalStorage/useLocalStorage.js';
22
22
  import '../../shared/consts/index.js';
23
23
  import '@dynamic-labs/multi-wallet';
24
24
  import { getAuthToken } from '../../utils/functions/getAuthToken/getAuthToken.js';
@@ -114,7 +114,7 @@ const DynamicContext = createContext(undefined);
114
114
  /** The context provider itself we only use internally */
115
115
  const InnerDynamicContextProvider = ({ children, theme, settings, locale, }) => {
116
116
  var _a, _b, _c, _d, _e, _f, _g, _h;
117
- const { accessDeniedMessagePrimary, accessDeniedMessageSecondary, accessDeniedButton, apiBaseUrl, enableForcedNetworkValidation: enableForcedNetworkValidationProp = false, deepLinkPreference = 'native', bridgeChains, cssOverrides, defaultNumberOfWalletsToShow = DEFAULT_NUMBER_OF_WALLETS_TO_SHOW, flowNetwork, initialAuthenticationMode = 'connect-and-sign', debugError = false, displaySiweStatement = true, newToWeb3WalletChainMap, enableVisitTrackingOnConnectOnly = true, environmentId, localStorageSuffix, eventsCallbacks, evmNetworks, walletsFilter, logLevel = 'WARN', notInTheListImageUrl, onboardingImageUrl, policiesConsentInnerComponent, customPrivacyPolicy, privacyPolicyUrl, signWithEmailWalletName, socialMediaLinkText, socialMediaIconUrl, socialMediaUrl, customTermsOfServices, termsOfServiceUrl, toolkitEnabled, siweStatement, shadowDOMEnabled = true, walletConnectors: walletConnectorsProp, socialProvidersFilter, showLockedWalletView = true, walletConnectPreferredChains, walletConnectorExtensions, } = settings;
117
+ const { accessDeniedMessagePrimary, accessDeniedMessageSecondary, accessDeniedButton, apiBaseUrl, enableForcedNetworkValidation: enableForcedNetworkValidationProp = false, deepLinkPreference = 'native', bridgeChains, cssOverrides, defaultNumberOfWalletsToShow = DEFAULT_NUMBER_OF_WALLETS_TO_SHOW, flowNetwork, initialAuthenticationMode = 'connect-and-sign', debugError = false, displaySiweStatement = true, newToWeb3WalletChainMap, enableVisitTrackingOnConnectOnly = true, environmentId, localStorageSuffix, eventsCallbacks, evmNetworks, walletsFilter, logLevel = 'WARN', notInTheListImageUrl, onboardingImageUrl, policiesConsentInnerComponent, customPrivacyPolicy, privacyPolicyUrl, signWithEmailWalletName, socialMediaLinkText, socialMediaIconUrl, socialMediaUrl, customTermsOfServices, termsOfServiceUrl, toolkitEnabled, siweStatement, shadowDOMEnabled = true, walletConnectors: walletConnectorsProp, socialProvidersFilter, showLockedWalletView = false, walletConnectPreferredChains, walletConnectorExtensions, } = settings;
118
118
  let enableForcedNetworkValidation = enableForcedNetworkValidationProp;
119
119
  if (bridgeChains) {
120
120
  enableForcedNetworkValidation = true;
@@ -430,9 +430,9 @@ const getOnrampProviders = ({ chain, environmentId, networkId, token, walletAddr
430
430
  });
431
431
  const sendDynamicProps = (environmentId, settingsToSend) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
432
432
  try {
433
- const { dynamicContextProps, dynamicWagmiSettings } = settingsToSend;
433
+ const { dynamicContextProps, dynamicWagmiSettings, frameworkSettings } = settingsToSend;
434
434
  if (dynamicContextProps) {
435
- yield sendDynamicContextSettings(environmentId, { dynamicContextProps }, helpers.isDynamicContextSessionSettingExpired, helpers.setDynamicContextSessionSettings);
435
+ yield sendDynamicContextSettings(environmentId, { dynamicContextProps, frameworkSettings }, helpers.isDynamicContextSessionSettingExpired, helpers.setDynamicContextSessionSettings);
436
436
  }
437
437
  if (dynamicWagmiSettings) {
438
438
  yield sendDynamicContextSettings(environmentId, { dynamicWagmiSettings }, helpers.isWagmiSessionSettingExpired, helpers.setWagmiSessionSettings);
@@ -70,6 +70,7 @@ export declare const getOnrampProviders: ({ chain, environmentId, networkId, tok
70
70
  export declare const sendDynamicProps: (environmentId: string, settingsToSend: {
71
71
  dynamicContextProps?: object;
72
72
  dynamicWagmiSettings?: object;
73
+ frameworkSettings?: object;
73
74
  }) => Promise<void>;
74
75
  export declare const mergeUserAccounts: (userJwt: string, environmentId: string) => Promise<string | undefined>;
75
76
  export type CreateTurnkeyEvmEmbeddedWalletProps = {
@@ -426,9 +426,9 @@ const getOnrampProviders = ({ chain, environmentId, networkId, token, walletAddr
426
426
  });
427
427
  const sendDynamicProps = (environmentId, settingsToSend) => __awaiter(void 0, void 0, void 0, function* () {
428
428
  try {
429
- const { dynamicContextProps, dynamicWagmiSettings } = settingsToSend;
429
+ const { dynamicContextProps, dynamicWagmiSettings, frameworkSettings } = settingsToSend;
430
430
  if (dynamicContextProps) {
431
- yield sendDynamicContextSettings(environmentId, { dynamicContextProps }, isDynamicContextSessionSettingExpired, setDynamicContextSessionSettings);
431
+ yield sendDynamicContextSettings(environmentId, { dynamicContextProps, frameworkSettings }, isDynamicContextSessionSettingExpired, setDynamicContextSessionSettings);
432
432
  }
433
433
  if (dynamicWagmiSettings) {
434
434
  yield sendDynamicContextSettings(environmentId, { dynamicWagmiSettings }, isWagmiSessionSettingExpired, setWagmiSessionSettings);
@@ -1,7 +1,8 @@
1
+ export { useEffectOnce } from './useEffectOnce';
2
+ export { useForwardedRef } from './useForwardedRef';
3
+ export { useGlobalLoading } from './useGlobalLoading';
1
4
  export { useLocalStorage } from './useLocalStorage';
5
+ export { useMediaQuery } from './useMediaQuery';
2
6
  export { useOnClickOutside } from './useOnClickOutside';
3
7
  export { usePreventPageScroll } from './usePreventPageScroll';
4
- export { useGlobalLoading } from './useGlobalLoading';
5
- export { useMediaQuery } from './useMediaQuery';
6
- export { useEffectOnce } from './useEffectOnce';
7
- export { useForwardedRef } from './useForwardedRef';
8
+ export * from './useThrottle';
@@ -0,0 +1 @@
1
+ export * from './useThrottle';
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+
7
+ /**
8
+ * useThrottle hook to throttle a callback function.
9
+ *
10
+ * @param callback - The callback function to be throttled. It must return void.
11
+ * @param delay - The time in milliseconds to wait before the next call.
12
+ * @returns A throttled version of the callback function.
13
+ */
14
+ const useThrottle = (callback, delay) => {
15
+ const isThrottled = React.useRef(false);
16
+ const savedCallback = React.useRef(callback);
17
+ // Remember the latest callback if it changes.
18
+ savedCallback.current = callback;
19
+ return React.useCallback((...args) => {
20
+ if (!isThrottled.current) {
21
+ savedCallback.current(...args);
22
+ isThrottled.current = true;
23
+ // Set the throttle off after the delay
24
+ setTimeout(() => (isThrottled.current = false), delay);
25
+ }
26
+ }, [delay]);
27
+ };
28
+
29
+ exports.useThrottle = useThrottle;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * useThrottle hook to throttle a callback function.
3
+ *
4
+ * @param callback - The callback function to be throttled. It must return void.
5
+ * @param delay - The time in milliseconds to wait before the next call.
6
+ * @returns A throttled version of the callback function.
7
+ */
8
+ export declare const useThrottle: <T extends (...args: unknown[]) => void>(callback: T, delay: number) => (...args: Parameters<T>) => void;
@@ -0,0 +1,25 @@
1
+ import { useRef, useCallback } from 'react';
2
+
3
+ /**
4
+ * useThrottle hook to throttle a callback function.
5
+ *
6
+ * @param callback - The callback function to be throttled. It must return void.
7
+ * @param delay - The time in milliseconds to wait before the next call.
8
+ * @returns A throttled version of the callback function.
9
+ */
10
+ const useThrottle = (callback, delay) => {
11
+ const isThrottled = useRef(false);
12
+ const savedCallback = useRef(callback);
13
+ // Remember the latest callback if it changes.
14
+ savedCallback.current = callback;
15
+ return useCallback((...args) => {
16
+ if (!isThrottled.current) {
17
+ savedCallback.current(...args);
18
+ isThrottled.current = true;
19
+ // Set the throttle off after the delay
20
+ setTimeout(() => (isThrottled.current = false), delay);
21
+ }
22
+ }, [delay]);
23
+ };
24
+
25
+ export { useThrottle };
@@ -2,6 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const getWalletIdentifier = ({ address, connector }) => `${address}+${connector.key}`;
5
+ const getWalletIdentifier = ({ address, connector, }) => `${address}+${connector.key}`;
6
6
 
7
7
  exports.getWalletIdentifier = getWalletIdentifier;
@@ -1,2 +1,2 @@
1
1
  import { Wallet } from '../../../shared';
2
- export declare const getWalletIdentifier: ({ address, connector }: Wallet) => `${string}+${string}`;
2
+ export declare const getWalletIdentifier: ({ address, connector, }: Pick<Wallet, 'address' | 'connector'>) => `${string}+${string}`;
@@ -1,3 +1,3 @@
1
- const getWalletIdentifier = ({ address, connector }) => `${address}+${connector.key}`;
1
+ const getWalletIdentifier = ({ address, connector, }) => `${address}+${connector.key}`;
2
2
 
3
3
  export { getWalletIdentifier };
@@ -9,6 +9,15 @@ var isWalletLinked = require('../../../functions/isWalletLinked/isWalletLinked.c
9
9
  var ViewContext = require('../../../../context/ViewContext/ViewContext.cjs');
10
10
  var useInternalDynamicContext = require('../../../../context/DynamicContext/useInternalDynamicContext.cjs');
11
11
  var errors = require('../../../constants/errors.cjs');
12
+ require('@dynamic-labs/sdk-api');
13
+ var logger = require('../../../../shared/logger.cjs');
14
+ require('@dynamic-labs/iconic');
15
+ require('react/jsx-runtime');
16
+ require('@dynamic-labs/wallet-book');
17
+ require('../../../constants/colors.cjs');
18
+ require('../../../../shared/utils/classes/storage/localStorage.cjs');
19
+ require('viem');
20
+ require('../../../../shared/consts/index.cjs');
12
21
 
13
22
  const useSyncPrimaryWallet = (canSync = true) => {
14
23
  const { setShowAuthFlow, isAuthenticated, authMode, connectWallet, handleLogOut, multiWalletWidgetState, primaryWallet, secondaryWallets, setMultiWalletWidgetState, setPrimaryWallet, setShowWidgetStatePopup, showLockedWalletView, showWidgetStatePopup, setSelectedWalletWithAction, } = useInternalDynamicContext.useInternalDynamicContext();
@@ -76,6 +85,10 @@ const useSyncPrimaryWallet = (canSync = true) => {
76
85
  primaryWallet.connector
77
86
  .getConnectedAccounts()
78
87
  .then((accounts) => {
88
+ logger.logger.debug('Sync primary wallet - getConnectedAccounts', {
89
+ accounts,
90
+ primaryWalletAddress: primaryWallet.address,
91
+ });
79
92
  const [connectedAddress] = accounts;
80
93
  if (!connectedAddress) {
81
94
  throw new utils.DynamicError('Missing wallet address', errors.MISSING_ADDRESS_ERROR);
@@ -100,9 +113,7 @@ const useSyncPrimaryWallet = (canSync = true) => {
100
113
  if (showLockedWalletView) {
101
114
  setShowAuthFlow(true);
102
115
  setView('wallet-locked-view');
103
- return;
104
116
  }
105
- handleLogOut();
106
117
  }
107
118
  });
108
119
  }, [
@@ -5,6 +5,15 @@ import { isWalletLinked } from '../../../functions/isWalletLinked/isWalletLinked
5
5
  import { useViewContext } from '../../../../context/ViewContext/ViewContext.js';
6
6
  import { useInternalDynamicContext } from '../../../../context/DynamicContext/useInternalDynamicContext.js';
7
7
  import { MISSING_ADDRESS_ERROR } from '../../../constants/errors.js';
8
+ import '@dynamic-labs/sdk-api';
9
+ import { logger } from '../../../../shared/logger.js';
10
+ import '@dynamic-labs/iconic';
11
+ import 'react/jsx-runtime';
12
+ import '@dynamic-labs/wallet-book';
13
+ import '../../../constants/colors.js';
14
+ import '../../../../shared/utils/classes/storage/localStorage.js';
15
+ import 'viem';
16
+ import '../../../../shared/consts/index.js';
8
17
 
9
18
  const useSyncPrimaryWallet = (canSync = true) => {
10
19
  const { setShowAuthFlow, isAuthenticated, authMode, connectWallet, handleLogOut, multiWalletWidgetState, primaryWallet, secondaryWallets, setMultiWalletWidgetState, setPrimaryWallet, setShowWidgetStatePopup, showLockedWalletView, showWidgetStatePopup, setSelectedWalletWithAction, } = useInternalDynamicContext();
@@ -72,6 +81,10 @@ const useSyncPrimaryWallet = (canSync = true) => {
72
81
  primaryWallet.connector
73
82
  .getConnectedAccounts()
74
83
  .then((accounts) => {
84
+ logger.debug('Sync primary wallet - getConnectedAccounts', {
85
+ accounts,
86
+ primaryWalletAddress: primaryWallet.address,
87
+ });
75
88
  const [connectedAddress] = accounts;
76
89
  if (!connectedAddress) {
77
90
  throw new DynamicError('Missing wallet address', MISSING_ADDRESS_ERROR);
@@ -96,9 +109,7 @@ const useSyncPrimaryWallet = (canSync = true) => {
96
109
  if (showLockedWalletView) {
97
110
  setShowAuthFlow(true);
98
111
  setView('wallet-locked-view');
99
- return;
100
112
  }
101
- handleLogOut();
102
113
  }
103
114
  });
104
115
  }, [
@@ -13,8 +13,8 @@ require('@dynamic-labs/wallet-book');
13
13
  require('../../constants/colors.cjs');
14
14
  require('../../../shared/utils/classes/storage/localStorage.cjs');
15
15
  require('viem');
16
- require('@dynamic-labs/utils');
17
16
  var useMediaQuery = require('../../../shared/utils/hooks/useMediaQuery/useMediaQuery.cjs');
17
+ require('@dynamic-labs/utils');
18
18
  require('../../../shared/consts/index.cjs');
19
19
 
20
20
  const useColorSchemePreference = () => {
@@ -9,8 +9,8 @@ import '@dynamic-labs/wallet-book';
9
9
  import '../../constants/colors.js';
10
10
  import '../../../shared/utils/classes/storage/localStorage.js';
11
11
  import 'viem';
12
- import '@dynamic-labs/utils';
13
12
  import { useMediaQuery } from '../../../shared/utils/hooks/useMediaQuery/useMediaQuery.js';
13
+ import '@dynamic-labs/utils';
14
14
  import '../../../shared/consts/index.js';
15
15
 
16
16
  const useColorSchemePreference = () => {
@@ -61,7 +61,7 @@ const useEmbeddedWallet = () => {
61
61
  internalSetShowAuthFlow,
62
62
  internalEvents,
63
63
  ]);
64
- const startEmbeddedWalletCreationFlow = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
64
+ const startEmbeddedWalletCreationFlow = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
65
65
  internalSetShowAuthFlow(true);
66
66
  setView('passkey-intro');
67
67
  return new Promise((resolve, reject) => {
@@ -70,15 +70,16 @@ const useEmbeddedWallet = () => {
70
70
  // when creating a passkey, if user cancels the passkey modal more than once
71
71
  // it will throw this DOMException, but we don't want to let user to have access
72
72
  // to the app before they've a passkey correctly setup
73
- if (error instanceof DOMException && error.name === 'NotAllowedError') {
73
+ if (error instanceof DOMException &&
74
+ error.name === 'NotAllowedError') {
74
75
  logger.logger.error('User cancelled the passkey creation.', error);
75
76
  return;
76
77
  }
77
78
  reject(error);
78
79
  });
79
80
  });
80
- });
81
- const returnEmbeddedWallet = (jwt, embeddedWalletVerifiedCredential) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
81
+ }), [internalEvents, internalSetShowAuthFlow, setView]);
82
+ const returnEmbeddedWallet = React.useCallback((jwt, embeddedWalletVerifiedCredential) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
82
83
  var _a, _b, _c, _d;
83
84
  const decodedJwt = decodeJwt.decodeJwt(jwt);
84
85
  const turnkeyWallet = findTurnkeyWallet.findTurnkeyWallet(walletConnectorOptions);
@@ -109,7 +110,7 @@ const useEmbeddedWallet = () => {
109
110
  id: embeddedWalletVerifiedCredential.id,
110
111
  };
111
112
  return Promise.resolve(passkeyWallet);
112
- });
113
+ }), [setPrimaryWalletId, walletConnectorOptions]);
113
114
  const createEmbeddedWallet = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
114
115
  var _e, _f, _g;
115
116
  const jwt = (_e = getAuthToken.getAuthToken()) !== null && _e !== void 0 ? _e : onboardingOnlyJwt;
@@ -132,14 +133,21 @@ const useEmbeddedWallet = () => {
132
133
  const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(jwt);
133
134
  // if user logged in with MM for example, just continue the flow
134
135
  if (!embeddedWalletVerifiedCredential) {
136
+ // user logged in through an email linked to a third party wallet
137
+ // at this point primary wallet is still undefined and we need to set it
138
+ if (!primaryWallet) {
139
+ setPrimaryWalletId(userWaletsCredentials[0].id);
140
+ }
135
141
  return Promise.resolve(primaryWallet);
136
142
  }
137
143
  // if user already has embedded wallet, returns it
138
144
  return returnEmbeddedWallet(jwt, embeddedWalletVerifiedCredential);
139
145
  }), [
140
- internalSetShowAuthFlow,
141
146
  onboardingOnlyJwt,
142
147
  projectSettings,
148
+ internalSetShowAuthFlow,
149
+ returnEmbeddedWallet,
150
+ startEmbeddedWalletCreationFlow,
143
151
  startPregeneratedWalletCreationFlow,
144
152
  primaryWallet,
145
153
  ]);
@@ -57,7 +57,7 @@ const useEmbeddedWallet = () => {
57
57
  internalSetShowAuthFlow,
58
58
  internalEvents,
59
59
  ]);
60
- const startEmbeddedWalletCreationFlow = () => __awaiter(void 0, void 0, void 0, function* () {
60
+ const startEmbeddedWalletCreationFlow = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
61
61
  internalSetShowAuthFlow(true);
62
62
  setView('passkey-intro');
63
63
  return new Promise((resolve, reject) => {
@@ -66,15 +66,16 @@ const useEmbeddedWallet = () => {
66
66
  // when creating a passkey, if user cancels the passkey modal more than once
67
67
  // it will throw this DOMException, but we don't want to let user to have access
68
68
  // to the app before they've a passkey correctly setup
69
- if (error instanceof DOMException && error.name === 'NotAllowedError') {
69
+ if (error instanceof DOMException &&
70
+ error.name === 'NotAllowedError') {
70
71
  logger.error('User cancelled the passkey creation.', error);
71
72
  return;
72
73
  }
73
74
  reject(error);
74
75
  });
75
76
  });
76
- });
77
- const returnEmbeddedWallet = (jwt, embeddedWalletVerifiedCredential) => __awaiter(void 0, void 0, void 0, function* () {
77
+ }), [internalEvents, internalSetShowAuthFlow, setView]);
78
+ const returnEmbeddedWallet = useCallback((jwt, embeddedWalletVerifiedCredential) => __awaiter(void 0, void 0, void 0, function* () {
78
79
  var _a, _b, _c, _d;
79
80
  const decodedJwt = decodeJwt(jwt);
80
81
  const turnkeyWallet = findTurnkeyWallet(walletConnectorOptions);
@@ -105,7 +106,7 @@ const useEmbeddedWallet = () => {
105
106
  id: embeddedWalletVerifiedCredential.id,
106
107
  };
107
108
  return Promise.resolve(passkeyWallet);
108
- });
109
+ }), [setPrimaryWalletId, walletConnectorOptions]);
109
110
  const createEmbeddedWallet = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
110
111
  var _e, _f, _g;
111
112
  const jwt = (_e = getAuthToken()) !== null && _e !== void 0 ? _e : onboardingOnlyJwt;
@@ -128,14 +129,21 @@ const useEmbeddedWallet = () => {
128
129
  const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(jwt);
129
130
  // if user logged in with MM for example, just continue the flow
130
131
  if (!embeddedWalletVerifiedCredential) {
132
+ // user logged in through an email linked to a third party wallet
133
+ // at this point primary wallet is still undefined and we need to set it
134
+ if (!primaryWallet) {
135
+ setPrimaryWalletId(userWaletsCredentials[0].id);
136
+ }
131
137
  return Promise.resolve(primaryWallet);
132
138
  }
133
139
  // if user already has embedded wallet, returns it
134
140
  return returnEmbeddedWallet(jwt, embeddedWalletVerifiedCredential);
135
141
  }), [
136
- internalSetShowAuthFlow,
137
142
  onboardingOnlyJwt,
138
143
  projectSettings,
144
+ internalSetShowAuthFlow,
145
+ returnEmbeddedWallet,
146
+ startEmbeddedWalletCreationFlow,
139
147
  startPregeneratedWalletCreationFlow,
140
148
  primaryWallet,
141
149
  ]);
@@ -16,8 +16,8 @@ var localStorage = require('../../constants/localStorage.cjs');
16
16
  require('../../constants/colors.cjs');
17
17
  var localStorage$1 = require('../../../shared/utils/classes/storage/localStorage.cjs');
18
18
  require('viem');
19
- var useLocalStorage = require('../../../shared/utils/hooks/useLocalStorage/useLocalStorage.cjs');
20
19
  var useEffectOnce = require('../../../shared/utils/hooks/useEffectOnce/useEffectOnce.cjs');
20
+ var useLocalStorage = require('../../../shared/utils/hooks/useLocalStorage/useLocalStorage.cjs');
21
21
  require('../../../shared/consts/index.cjs');
22
22
  var validators = require('../../../context/DynamicContext/validators.cjs');
23
23
 
@@ -61,6 +61,7 @@ const useFetchProjectSettings = ({ authToken, environmentId, maxRetries = 2, dyn
61
61
  const serializedDynamicContextProps = Object.assign(Object.assign({}, updatedDynamicProps), { settings: Object.assign(Object.assign({}, updatedDynamicProps.settings), { eventsCallbacks: serializedEventsCallbacks, walletConnectors: serializedWalletConnectors }) });
62
62
  api.sendDynamicProps(environmentId, {
63
63
  dynamicContextProps: serializedDynamicContextProps,
64
+ frameworkSettings: getFrameworkSettings(),
64
65
  });
65
66
  api.fetchProjectSettings(environmentId)
66
67
  .then((response) => {
@@ -123,6 +124,19 @@ const serializeWalletConnectors = (walletConnectors) => {
123
124
  return undefined;
124
125
  }
125
126
  };
127
+ const getFrameworkSettings = () => {
128
+ var _a;
129
+ return ({
130
+ nextJs: {
131
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
132
+ // @ts-ignore
133
+ version: (_a = window.next) === null || _a === void 0 ? void 0 : _a.version,
134
+ },
135
+ react: {
136
+ version: React.version,
137
+ },
138
+ });
139
+ };
126
140
 
127
141
  exports.serializeEventsCallbacks = serializeEventsCallbacks;
128
142
  exports.serializeWalletConnectors = serializeWalletConnectors;
@@ -1,4 +1,4 @@
1
- import { useState, useEffect, useMemo } from 'react';
1
+ import { useState, useEffect, useMemo, version } from 'react';
2
2
  import { DynamicError } from '@dynamic-labs/utils';
3
3
  import { sendDynamicProps, fetchProjectSettings } from '../../../data/api.js';
4
4
  import '@dynamic-labs/sdk-api';
@@ -12,8 +12,8 @@ import { PROJECT_SETTINGS_STORAGE_KEY, CONNECTED_WALLETS_INFO } from '../../cons
12
12
  import '../../constants/colors.js';
13
13
  import { LocalStorage } from '../../../shared/utils/classes/storage/localStorage.js';
14
14
  import 'viem';
15
- import { useLocalStorage } from '../../../shared/utils/hooks/useLocalStorage/useLocalStorage.js';
16
15
  import { useEffectOnce } from '../../../shared/utils/hooks/useEffectOnce/useEffectOnce.js';
16
+ import { useLocalStorage } from '../../../shared/utils/hooks/useLocalStorage/useLocalStorage.js';
17
17
  import '../../../shared/consts/index.js';
18
18
  import { validateLocalStorageExpiry } from '../../../context/DynamicContext/validators.js';
19
19
 
@@ -57,6 +57,7 @@ const useFetchProjectSettings = ({ authToken, environmentId, maxRetries = 2, dyn
57
57
  const serializedDynamicContextProps = Object.assign(Object.assign({}, updatedDynamicProps), { settings: Object.assign(Object.assign({}, updatedDynamicProps.settings), { eventsCallbacks: serializedEventsCallbacks, walletConnectors: serializedWalletConnectors }) });
58
58
  sendDynamicProps(environmentId, {
59
59
  dynamicContextProps: serializedDynamicContextProps,
60
+ frameworkSettings: getFrameworkSettings(),
60
61
  });
61
62
  fetchProjectSettings(environmentId)
62
63
  .then((response) => {
@@ -119,5 +120,18 @@ const serializeWalletConnectors = (walletConnectors) => {
119
120
  return undefined;
120
121
  }
121
122
  };
123
+ const getFrameworkSettings = () => {
124
+ var _a;
125
+ return ({
126
+ nextJs: {
127
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
128
+ // @ts-ignore
129
+ version: (_a = window.next) === null || _a === void 0 ? void 0 : _a.version,
130
+ },
131
+ react: {
132
+ version,
133
+ },
134
+ });
135
+ };
122
136
 
123
137
  export { serializeEventsCallbacks, serializeWalletConnectors, useFetchProjectSettings };
@@ -17,10 +17,10 @@ require('../../constants/colors.cjs');
17
17
  require('../../../shared/utils/classes/storage/localStorage.cjs');
18
18
  require('viem');
19
19
  require('../../../shared/consts/index.cjs');
20
- var isSameWalletName = require('../../functions/isSameWalletName/isSameWalletName.cjs');
21
- var useWalletsConnectionState = require('../useWalletsConnectionState/useWalletsConnectionState.cjs');
22
20
  require('@dynamic-labs/multi-wallet');
23
21
  var getWalletIdentifier = require('../../functions/getWalletIdentifier/getWalletIdentifier.cjs');
22
+ var isSameWalletName = require('../../functions/isSameWalletName/isSameWalletName.cjs');
23
+ var useWalletsConnectionState = require('../useWalletsConnectionState/useWalletsConnectionState.cjs');
24
24
  var reconnectSocialWallet = require('./reconnectSocialWallet.cjs');
25
25
  var createLinkedWalletsFromWalletOptions = require('./utils/createLinkedWalletsFromWalletOptions/createLinkedWalletsFromWalletOptions.cjs');
26
26
  var updateUserWalletsFromLinkedWallets = require('./utils/updateUserWalletsFromLinkedWallets/updateUserWalletsFromLinkedWallets.cjs');
@@ -66,14 +66,14 @@ const useWalletConnectors = ({ authMode, authToken, connectedWallets, walletConn
66
66
  React.useEffect(() => walletsBasedOnAuthMode.forEach((wallet) => {
67
67
  wallet.connector.initEventListener();
68
68
  }), [walletsBasedOnAuthMode]);
69
- const { connectedWalletMap, didConnectedStateLoad } = useWalletsConnectionState.useWalletsConnectionState(walletsBasedOnAuthMode);
70
- const wallets = React.useMemo(() => walletsBasedOnAuthMode.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: Boolean(connectedWalletMap[getWalletIdentifier.getWalletIdentifier(wallet)]) }))), [connectedWalletMap, walletsBasedOnAuthMode]);
69
+ const { connectedWalletsMap, didConnectedStateLoad } = useWalletsConnectionState.useWalletsConnectionState(walletsBasedOnAuthMode);
70
+ const wallets = React.useMemo(() => walletsBasedOnAuthMode.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: Boolean(connectedWalletsMap[getWalletIdentifier.getWalletIdentifier(wallet)]) }))), [connectedWalletsMap, walletsBasedOnAuthMode]);
71
71
  const { setUserWallets } = UserWalletsContext.useInternalUserWallets();
72
72
  // Keep userWallets in sync whenever linkedWallets changes
73
73
  React.useEffect(() => {
74
- setUserWallets((userWallets) => didConnectedStateLoad
75
- ? updateUserWalletsFromLinkedWallets.updateUserWalletsFromLinkedWallets(userWallets, wallets)
76
- : userWallets);
74
+ if (!didConnectedStateLoad.current)
75
+ return;
76
+ setUserWallets((userWallets) => updateUserWalletsFromLinkedWallets.updateUserWalletsFromLinkedWallets(userWallets, wallets));
77
77
  }, [didConnectedStateLoad, setUserWallets, wallets]);
78
78
  const primaryWallet = React.useMemo(() => { var _a; return (_a = wallets.find((wallet) => wallet.id === primaryWalletId)) !== null && _a !== void 0 ? _a : null; }, [primaryWalletId, wallets]);
79
79
  const secondaryWallets = React.useMemo(() => canHaveMultipleWalletsConnected
@@ -173,7 +173,7 @@ const useWalletConnectors = ({ authMode, authToken, connectedWallets, walletConn
173
173
  setQrcodeUri,
174
174
  ]);
175
175
  return {
176
- didConnectedStateLoad,
176
+ didConnectedStateLoad: didConnectedStateLoad.current,
177
177
  primaryWallet,
178
178
  secondaryWallets,
179
179
  setPrimaryWallet,
@@ -13,10 +13,10 @@ import '../../constants/colors.js';
13
13
  import '../../../shared/utils/classes/storage/localStorage.js';
14
14
  import 'viem';
15
15
  import '../../../shared/consts/index.js';
16
- import { isSameWalletName } from '../../functions/isSameWalletName/isSameWalletName.js';
17
- import { useWalletsConnectionState } from '../useWalletsConnectionState/useWalletsConnectionState.js';
18
16
  import '@dynamic-labs/multi-wallet';
19
17
  import { getWalletIdentifier } from '../../functions/getWalletIdentifier/getWalletIdentifier.js';
18
+ import { isSameWalletName } from '../../functions/isSameWalletName/isSameWalletName.js';
19
+ import { useWalletsConnectionState } from '../useWalletsConnectionState/useWalletsConnectionState.js';
20
20
  import { reconnectSocialWallet } from './reconnectSocialWallet.js';
21
21
  import { createLinkedWalletsFromWalletOptions } from './utils/createLinkedWalletsFromWalletOptions/createLinkedWalletsFromWalletOptions.js';
22
22
  import { updateUserWalletsFromLinkedWallets } from './utils/updateUserWalletsFromLinkedWallets/updateUserWalletsFromLinkedWallets.js';
@@ -62,14 +62,14 @@ const useWalletConnectors = ({ authMode, authToken, connectedWallets, walletConn
62
62
  useEffect(() => walletsBasedOnAuthMode.forEach((wallet) => {
63
63
  wallet.connector.initEventListener();
64
64
  }), [walletsBasedOnAuthMode]);
65
- const { connectedWalletMap, didConnectedStateLoad } = useWalletsConnectionState(walletsBasedOnAuthMode);
66
- const wallets = useMemo(() => walletsBasedOnAuthMode.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: Boolean(connectedWalletMap[getWalletIdentifier(wallet)]) }))), [connectedWalletMap, walletsBasedOnAuthMode]);
65
+ const { connectedWalletsMap, didConnectedStateLoad } = useWalletsConnectionState(walletsBasedOnAuthMode);
66
+ const wallets = useMemo(() => walletsBasedOnAuthMode.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: Boolean(connectedWalletsMap[getWalletIdentifier(wallet)]) }))), [connectedWalletsMap, walletsBasedOnAuthMode]);
67
67
  const { setUserWallets } = useInternalUserWallets();
68
68
  // Keep userWallets in sync whenever linkedWallets changes
69
69
  useEffect(() => {
70
- setUserWallets((userWallets) => didConnectedStateLoad
71
- ? updateUserWalletsFromLinkedWallets(userWallets, wallets)
72
- : userWallets);
70
+ if (!didConnectedStateLoad.current)
71
+ return;
72
+ setUserWallets((userWallets) => updateUserWalletsFromLinkedWallets(userWallets, wallets));
73
73
  }, [didConnectedStateLoad, setUserWallets, wallets]);
74
74
  const primaryWallet = useMemo(() => { var _a; return (_a = wallets.find((wallet) => wallet.id === primaryWalletId)) !== null && _a !== void 0 ? _a : null; }, [primaryWalletId, wallets]);
75
75
  const secondaryWallets = useMemo(() => canHaveMultipleWalletsConnected
@@ -169,7 +169,7 @@ const useWalletConnectors = ({ authMode, authToken, connectedWallets, walletConn
169
169
  setQrcodeUri,
170
170
  ]);
171
171
  return {
172
- didConnectedStateLoad,
172
+ didConnectedStateLoad: didConnectedStateLoad.current,
173
173
  primaryWallet,
174
174
  secondaryWallets,
175
175
  setPrimaryWallet,
@@ -65,12 +65,13 @@ const useWalletEventListeners = ({ handleLogOut, multiWallet, multiWalletWidgetS
65
65
  if (!primaryWallet)
66
66
  return;
67
67
  const [newAddress] = accounts;
68
- const newWallet = secondaryWallets.find((wallet) => walletConnectorCore.isSameAddress(wallet.address, newAddress, wallet.chain));
69
- if (authMode === 'connect-only') {
68
+ const changedAddress = !walletConnectorCore.isSameAddress(newAddress, primaryWallet.address, primaryWallet.chain);
69
+ if (changedAddress && authMode === 'connect-only') {
70
70
  refreshConnectedWallet(primaryWallet.id, primaryWallet.connector);
71
71
  return;
72
72
  }
73
- if (walletConnectorCore.isSameAddress(newAddress, primaryWallet.address, primaryWallet.chain)) {
73
+ const newWallet = secondaryWallets.find((wallet) => walletConnectorCore.isSameAddress(wallet.address, newAddress, wallet.chain));
74
+ if (!changedAddress) {
74
75
  setMultiWalletWidgetState('idle');
75
76
  }
76
77
  else if (!multiWallet) {
@@ -61,12 +61,13 @@ const useWalletEventListeners = ({ handleLogOut, multiWallet, multiWalletWidgetS
61
61
  if (!primaryWallet)
62
62
  return;
63
63
  const [newAddress] = accounts;
64
- const newWallet = secondaryWallets.find((wallet) => isSameAddress(wallet.address, newAddress, wallet.chain));
65
- if (authMode === 'connect-only') {
64
+ const changedAddress = !isSameAddress(newAddress, primaryWallet.address, primaryWallet.chain);
65
+ if (changedAddress && authMode === 'connect-only') {
66
66
  refreshConnectedWallet(primaryWallet.id, primaryWallet.connector);
67
67
  return;
68
68
  }
69
- if (isSameAddress(newAddress, primaryWallet.address, primaryWallet.chain)) {
69
+ const newWallet = secondaryWallets.find((wallet) => isSameAddress(wallet.address, newAddress, wallet.chain));
70
+ if (!changedAddress) {
70
71
  setMultiWalletWidgetState('idle');
71
72
  }
72
73
  else if (!multiWallet) {
@@ -4,10 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _tslib = require('../../../../../_virtual/_tslib.cjs');
6
6
  var React = require('react');
7
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
7
8
  require('@dynamic-labs/sdk-api');
8
- var logger = require('../../../shared/logger.cjs');
9
+ require('../../../shared/logger.cjs');
9
10
  require('@dynamic-labs/iconic');
10
- require('@dynamic-labs/wallet-connector-core');
11
11
  require('react/jsx-runtime');
12
12
  require('../../../context/ViewContext/ViewContext.cjs');
13
13
  require('@dynamic-labs/wallet-book');
@@ -15,6 +15,7 @@ require('../../constants/colors.cjs');
15
15
  require('../../../shared/utils/classes/storage/localStorage.cjs');
16
16
  require('viem');
17
17
  require('@dynamic-labs/utils');
18
+ var useThrottle = require('../../../shared/utils/hooks/useThrottle/useThrottle.cjs');
18
19
  require('../../../shared/consts/index.cjs');
19
20
  require('@dynamic-labs/multi-wallet');
20
21
  var getWalletIdentifier = require('../../functions/getWalletIdentifier/getWalletIdentifier.cjs');
@@ -22,65 +23,84 @@ var isWalletConnected = require('../../functions/isWalletConnected/isWalletConne
22
23
  var useEventListener = require('../useEventListener/useEventListener.cjs');
23
24
  var useWalletConnectorEvent = require('../useWalletConnectorEvent/useWalletConnectorEvent.cjs');
24
25
 
25
- const connectedWalletStateReducer = (state, connectedWalletsMap) => {
26
- // When setting to empty, unset load flag
27
- if (Object.values(connectedWalletsMap).length === 0) {
28
- if (state.didLoad === false)
29
- return state;
30
- return Object.assign(Object.assign({}, state), { connectedWalletsMap, didLoad: false });
31
- }
32
- return Object.assign(Object.assign({}, state), { connectedWalletsMap, didLoad: true });
33
- };
26
+ /**
27
+ * For the given wallet array, this returns an object mapping from each wallet's
28
+ * identifier to whether its connector recognizes it as currently connected or not.
29
+ */
30
+ const getConnectedWalletsMap = (wallets) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
31
+ const newMap = {};
32
+ yield Promise.all(wallets.map((wallet) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
33
+ newMap[getWalletIdentifier.getWalletIdentifier(wallet)] = yield isWalletConnected.isWalletConnected(wallet);
34
+ })));
35
+ return newMap;
36
+ });
34
37
  const useWalletsConnectionState = (wallets) => {
35
- const [state, setState] = React.useReducer(connectedWalletStateReducer, {
36
- connectedWalletsMap: {},
37
- didLoad: false,
38
- });
39
- const connectors = wallets.map(({ connector }) => connector);
40
- const lastCallTimestamp = React.useRef(0);
38
+ const [connectedWalletsMap, setConnectedWalletsMap] = React.useState({});
39
+ /**
40
+ * Whether the connection map has been loaded off of the current wallet array.
41
+ * Always false for empty wallet arrays.
42
+ */
43
+ const didConnectedStateLoad = React.useRef(false);
44
+ /**
45
+ * When an accountChanged event is raised, we store the incoming wallet here
46
+ * until it is finally reflected in the wallets prop.
47
+ * During this time we do not update the connectedWalletsMap.
48
+ * This way, we avoid setting the connected state of the primary wallet
49
+ * to false due to a state transition delay.
50
+ */
51
+ const incomingWalletSwitchAddress = React.useRef(undefined);
41
52
  const computeConnectedStateForWallets = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
42
- const connectedWalletsMap = {};
43
- yield Promise.all(wallets.map((wallet) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
44
- connectedWalletsMap[getWalletIdentifier.getWalletIdentifier(wallet)] =
45
- yield isWalletConnected.isWalletConnected(wallet);
46
- })));
47
- setState(connectedWalletsMap);
48
- }), [wallets]);
49
- const handleOnEventUpdate = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
50
- if (!wallets.length)
51
- return;
52
- const callTimestamp = new Date().getTime();
53
- const diffFromLastCall = callTimestamp - lastCallTimestamp.current;
54
- lastCallTimestamp.current = callTimestamp;
55
- // getConnectedAccounts trigger accountChanged event for Phantom EVM wallets
56
- // which causes a loop of calls to this function
57
- if (diffFromLastCall < 1000) {
58
- logger.logger.warn('computeConnectedStateForWallets: skipping due too many calls.');
53
+ didConnectedStateLoad.current = false;
54
+ const newMap = yield getConnectedWalletsMap(wallets);
55
+ if (Object.values(newMap).length === 0) {
56
+ setConnectedWalletsMap({});
59
57
  return;
60
58
  }
61
- computeConnectedStateForWallets();
62
- }), [computeConnectedStateForWallets, wallets.length]);
63
- useWalletConnectorEvent.useWalletConnectorEvent(connectors, 'accountChange', handleOnEventUpdate);
64
- useWalletConnectorEvent.useWalletConnectorEvent(connectors, 'disconnect', handleOnEventUpdate);
65
- useWalletConnectorEvent.useWalletConnectorEvent(connectors, 'chainChange', handleOnEventUpdate);
66
- const refreshKey = wallets.map(getWalletIdentifier.getWalletIdentifier).join('-');
59
+ didConnectedStateLoad.current = true;
60
+ // If there is an incoming account switch and it isn't yet finished,
61
+ // we don't change the map to avoid setting it to a misleading state
62
+ if (incomingWalletSwitchAddress.current) {
63
+ const accountSwitchIsComplete = wallets.some((wallet) => walletConnectorCore.isSameAddress(incomingWalletSwitchAddress.current, wallet.address, wallet.chain));
64
+ if (accountSwitchIsComplete)
65
+ incomingWalletSwitchAddress.current = undefined;
66
+ else
67
+ return;
68
+ }
69
+ setConnectedWalletsMap(newMap);
70
+ }), [wallets]);
71
+ /** A string that is unique for each possible value of the wallets prop */
72
+ const walletsHash = wallets.map(getWalletIdentifier.getWalletIdentifier).join('-');
73
+ const connectors = wallets.map(({ connector }) => connector);
74
+ // getConnectedAccounts trigger accountChanged event for Phantom EVM wallets
75
+ // which causes a loop of calls to this function, so we throttle it
76
+ const handleEvent = useThrottle.useThrottle(() => {
77
+ if (walletsHash)
78
+ computeConnectedStateForWallets();
79
+ }, 1000);
80
+ const onAccountChange = ({ accounts }) => {
81
+ incomingWalletSwitchAddress.current = accounts[0];
82
+ handleEvent();
83
+ };
84
+ useWalletConnectorEvent.useWalletConnectorEvent(connectors, 'accountChange', onAccountChange);
85
+ useWalletConnectorEvent.useWalletConnectorEvent(connectors, 'disconnect', handleEvent);
86
+ useWalletConnectorEvent.useWalletConnectorEvent(connectors, 'chainChange', handleEvent);
67
87
  React.useEffect(() => {
68
88
  computeConnectedStateForWallets();
69
89
  },
70
90
  /**
71
- * This is using a custom key to force the useEffect to run only when a connector is
72
- * added or removed from the connectors list.
91
+ * This is using a custom key to force the useEffect to run only when the ids of the
92
+ * wallets change.
73
93
  */
74
94
  // eslint-disable-next-line react-hooks/exhaustive-deps
75
- [refreshKey]);
95
+ [walletsHash]);
76
96
  /**
77
97
  * This is a workaround to detect when the user switches to another tab/extension
78
98
  * and then comes back to the dapp.
79
99
  */
80
100
  useEventListener.useEventListener('focus', computeConnectedStateForWallets);
81
101
  return {
82
- connectedWalletMap: state.connectedWalletsMap,
83
- didConnectedStateLoad: state.didLoad,
102
+ connectedWalletsMap,
103
+ didConnectedStateLoad,
84
104
  };
85
105
  };
86
106
 
@@ -1,13 +1,11 @@
1
+ import { MutableRefObject } from 'react';
1
2
  import { Wallet } from '../../../shared';
2
- type ConnectedState = {
3
- didLoad: boolean;
4
- connectedWalletsMap: {
5
- [address: string]: boolean;
6
- };
3
+ type ConnectedWalletsMap = {
4
+ [address: string]: boolean;
7
5
  };
8
6
  type WalletsConnectionStateHook = (wallets: Wallet[]) => {
9
- connectedWalletMap: ConnectedState['connectedWalletsMap'];
10
- didConnectedStateLoad: ConnectedState['didLoad'];
7
+ connectedWalletsMap: ConnectedWalletsMap;
8
+ didConnectedStateLoad: MutableRefObject<boolean>;
11
9
  };
12
10
  export declare const useWalletsConnectionState: WalletsConnectionStateHook;
13
11
  export {};
@@ -1,9 +1,9 @@
1
1
  import { __awaiter } from '../../../../../_virtual/_tslib.js';
2
- import { useReducer, useRef, useCallback, useEffect } from 'react';
2
+ import { useState, useRef, useCallback, useEffect } from 'react';
3
+ import { isSameAddress } from '@dynamic-labs/wallet-connector-core';
3
4
  import '@dynamic-labs/sdk-api';
4
- import { logger } from '../../../shared/logger.js';
5
+ import '../../../shared/logger.js';
5
6
  import '@dynamic-labs/iconic';
6
- import '@dynamic-labs/wallet-connector-core';
7
7
  import 'react/jsx-runtime';
8
8
  import '../../../context/ViewContext/ViewContext.js';
9
9
  import '@dynamic-labs/wallet-book';
@@ -11,6 +11,7 @@ import '../../constants/colors.js';
11
11
  import '../../../shared/utils/classes/storage/localStorage.js';
12
12
  import 'viem';
13
13
  import '@dynamic-labs/utils';
14
+ import { useThrottle } from '../../../shared/utils/hooks/useThrottle/useThrottle.js';
14
15
  import '../../../shared/consts/index.js';
15
16
  import '@dynamic-labs/multi-wallet';
16
17
  import { getWalletIdentifier } from '../../functions/getWalletIdentifier/getWalletIdentifier.js';
@@ -18,65 +19,84 @@ import { isWalletConnected } from '../../functions/isWalletConnected/isWalletCon
18
19
  import { useEventListener } from '../useEventListener/useEventListener.js';
19
20
  import { useWalletConnectorEvent } from '../useWalletConnectorEvent/useWalletConnectorEvent.js';
20
21
 
21
- const connectedWalletStateReducer = (state, connectedWalletsMap) => {
22
- // When setting to empty, unset load flag
23
- if (Object.values(connectedWalletsMap).length === 0) {
24
- if (state.didLoad === false)
25
- return state;
26
- return Object.assign(Object.assign({}, state), { connectedWalletsMap, didLoad: false });
27
- }
28
- return Object.assign(Object.assign({}, state), { connectedWalletsMap, didLoad: true });
29
- };
22
+ /**
23
+ * For the given wallet array, this returns an object mapping from each wallet's
24
+ * identifier to whether its connector recognizes it as currently connected or not.
25
+ */
26
+ const getConnectedWalletsMap = (wallets) => __awaiter(void 0, void 0, void 0, function* () {
27
+ const newMap = {};
28
+ yield Promise.all(wallets.map((wallet) => __awaiter(void 0, void 0, void 0, function* () {
29
+ newMap[getWalletIdentifier(wallet)] = yield isWalletConnected(wallet);
30
+ })));
31
+ return newMap;
32
+ });
30
33
  const useWalletsConnectionState = (wallets) => {
31
- const [state, setState] = useReducer(connectedWalletStateReducer, {
32
- connectedWalletsMap: {},
33
- didLoad: false,
34
- });
35
- const connectors = wallets.map(({ connector }) => connector);
36
- const lastCallTimestamp = useRef(0);
34
+ const [connectedWalletsMap, setConnectedWalletsMap] = useState({});
35
+ /**
36
+ * Whether the connection map has been loaded off of the current wallet array.
37
+ * Always false for empty wallet arrays.
38
+ */
39
+ const didConnectedStateLoad = useRef(false);
40
+ /**
41
+ * When an accountChanged event is raised, we store the incoming wallet here
42
+ * until it is finally reflected in the wallets prop.
43
+ * During this time we do not update the connectedWalletsMap.
44
+ * This way, we avoid setting the connected state of the primary wallet
45
+ * to false due to a state transition delay.
46
+ */
47
+ const incomingWalletSwitchAddress = useRef(undefined);
37
48
  const computeConnectedStateForWallets = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
38
- const connectedWalletsMap = {};
39
- yield Promise.all(wallets.map((wallet) => __awaiter(void 0, void 0, void 0, function* () {
40
- connectedWalletsMap[getWalletIdentifier(wallet)] =
41
- yield isWalletConnected(wallet);
42
- })));
43
- setState(connectedWalletsMap);
44
- }), [wallets]);
45
- const handleOnEventUpdate = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
46
- if (!wallets.length)
47
- return;
48
- const callTimestamp = new Date().getTime();
49
- const diffFromLastCall = callTimestamp - lastCallTimestamp.current;
50
- lastCallTimestamp.current = callTimestamp;
51
- // getConnectedAccounts trigger accountChanged event for Phantom EVM wallets
52
- // which causes a loop of calls to this function
53
- if (diffFromLastCall < 1000) {
54
- logger.warn('computeConnectedStateForWallets: skipping due too many calls.');
49
+ didConnectedStateLoad.current = false;
50
+ const newMap = yield getConnectedWalletsMap(wallets);
51
+ if (Object.values(newMap).length === 0) {
52
+ setConnectedWalletsMap({});
55
53
  return;
56
54
  }
57
- computeConnectedStateForWallets();
58
- }), [computeConnectedStateForWallets, wallets.length]);
59
- useWalletConnectorEvent(connectors, 'accountChange', handleOnEventUpdate);
60
- useWalletConnectorEvent(connectors, 'disconnect', handleOnEventUpdate);
61
- useWalletConnectorEvent(connectors, 'chainChange', handleOnEventUpdate);
62
- const refreshKey = wallets.map(getWalletIdentifier).join('-');
55
+ didConnectedStateLoad.current = true;
56
+ // If there is an incoming account switch and it isn't yet finished,
57
+ // we don't change the map to avoid setting it to a misleading state
58
+ if (incomingWalletSwitchAddress.current) {
59
+ const accountSwitchIsComplete = wallets.some((wallet) => isSameAddress(incomingWalletSwitchAddress.current, wallet.address, wallet.chain));
60
+ if (accountSwitchIsComplete)
61
+ incomingWalletSwitchAddress.current = undefined;
62
+ else
63
+ return;
64
+ }
65
+ setConnectedWalletsMap(newMap);
66
+ }), [wallets]);
67
+ /** A string that is unique for each possible value of the wallets prop */
68
+ const walletsHash = wallets.map(getWalletIdentifier).join('-');
69
+ const connectors = wallets.map(({ connector }) => connector);
70
+ // getConnectedAccounts trigger accountChanged event for Phantom EVM wallets
71
+ // which causes a loop of calls to this function, so we throttle it
72
+ const handleEvent = useThrottle(() => {
73
+ if (walletsHash)
74
+ computeConnectedStateForWallets();
75
+ }, 1000);
76
+ const onAccountChange = ({ accounts }) => {
77
+ incomingWalletSwitchAddress.current = accounts[0];
78
+ handleEvent();
79
+ };
80
+ useWalletConnectorEvent(connectors, 'accountChange', onAccountChange);
81
+ useWalletConnectorEvent(connectors, 'disconnect', handleEvent);
82
+ useWalletConnectorEvent(connectors, 'chainChange', handleEvent);
63
83
  useEffect(() => {
64
84
  computeConnectedStateForWallets();
65
85
  },
66
86
  /**
67
- * This is using a custom key to force the useEffect to run only when a connector is
68
- * added or removed from the connectors list.
87
+ * This is using a custom key to force the useEffect to run only when the ids of the
88
+ * wallets change.
69
89
  */
70
90
  // eslint-disable-next-line react-hooks/exhaustive-deps
71
- [refreshKey]);
91
+ [walletsHash]);
72
92
  /**
73
93
  * This is a workaround to detect when the user switches to another tab/extension
74
94
  * and then comes back to the dapp.
75
95
  */
76
96
  useEventListener('focus', computeConnectedStateForWallets);
77
97
  return {
78
- connectedWalletMap: state.connectedWalletsMap,
79
- didConnectedStateLoad: state.didLoad,
98
+ connectedWalletsMap,
99
+ didConnectedStateLoad,
80
100
  };
81
101
  };
82
102