@dynamic-labs/sdk-react-core 4.6.0 → 4.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/package.cjs +2 -2
  3. package/package.js +2 -2
  4. package/package.json +12 -12
  5. package/src/lib/components/UserProfile/UserProfile.cjs +8 -1
  6. package/src/lib/components/UserProfile/UserProfile.js +8 -1
  7. package/src/lib/context/DynamicContext/DynamicContext.cjs +0 -12
  8. package/src/lib/context/DynamicContext/DynamicContext.js +0 -12
  9. package/src/lib/context/SocialRedirectContext/hooks/useRedirectSocialHandler/useRedirectSocialHandler.cjs +1 -1
  10. package/src/lib/context/SocialRedirectContext/hooks/useRedirectSocialHandler/useRedirectSocialHandler.js +1 -1
  11. package/src/lib/data/api/api.cjs +3 -4
  12. package/src/lib/data/api/api.js +3 -4
  13. package/src/lib/modals/SignMessageConfirmationModal/SignMessageConfirmationModal.cjs +1 -1
  14. package/src/lib/modals/SignMessageConfirmationModal/SignMessageConfirmationModal.js +1 -1
  15. package/src/lib/store/internalImplementation/store.cjs +0 -2
  16. package/src/lib/store/internalImplementation/store.js +0 -2
  17. package/src/lib/store/state/projectSettings/projectSettings.cjs +14 -3
  18. package/src/lib/store/state/projectSettings/projectSettings.js +15 -5
  19. package/src/lib/utils/functions/isCookieEnabled/isCookieEnabled.cjs +6 -6
  20. package/src/lib/utils/functions/isCookieEnabled/isCookieEnabled.d.ts +2 -1
  21. package/src/lib/utils/functions/isCookieEnabled/isCookieEnabled.js +7 -7
  22. package/src/lib/utils/functions/storeAuthToken/storeAuthToken.cjs +3 -1
  23. package/src/lib/utils/functions/storeAuthToken/storeAuthToken.js +3 -1
  24. package/src/lib/utils/hooks/useResetCookieLocalStorage/useResetCookieLocalStorage.cjs +7 -4
  25. package/src/lib/utils/hooks/useResetCookieLocalStorage/useResetCookieLocalStorage.js +7 -4
  26. package/src/lib/utils/hooks/useValidateSession/handleUserDataOutOfSync/handleUserDataOutOfSync.cjs +2 -2
  27. package/src/lib/utils/hooks/useValidateSession/handleUserDataOutOfSync/handleUserDataOutOfSync.d.ts +3 -1
  28. package/src/lib/utils/hooks/useValidateSession/handleUserDataOutOfSync/handleUserDataOutOfSync.js +2 -2
  29. package/src/lib/utils/hooks/useValidateSession/useValidateSession.cjs +16 -6
  30. package/src/lib/utils/hooks/useValidateSession/useValidateSession.js +17 -7
  31. package/src/lib/views/Passkey/PasskeyRecovery/AddRecoveryEmail/AddRecoveryEmail.cjs +1 -1
  32. package/src/lib/views/Passkey/PasskeyRecovery/AddRecoveryEmail/AddRecoveryEmail.js +1 -1
  33. package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.cjs +1 -1
  34. package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.js +1 -1
  35. package/src/lib/views/WalletList/WalletList.cjs +1 -1
  36. package/src/lib/views/WalletList/WalletList.js +1 -1
  37. package/src/lib/widgets/DynamicWidget/views/ManageMfaWidgetView/ManageMfaWidgetView.cjs +1 -1
  38. package/src/lib/widgets/DynamicWidget/views/ManageMfaWidgetView/ManageMfaWidgetView.js +1 -1
  39. package/src/lib/store/internalImplementation/utils/clearExpiredData/clearExpiredData.cjs +0 -24
  40. package/src/lib/store/internalImplementation/utils/clearExpiredData/clearExpiredData.d.ts +0 -3
  41. package/src/lib/store/internalImplementation/utils/clearExpiredData/clearExpiredData.js +0 -20
  42. package/src/lib/store/internalImplementation/utils/clearExpiredData/index.d.ts +0 -1
package/CHANGELOG.md CHANGED
@@ -1,4 +1,14 @@
1
1
 
2
+ ### [4.6.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.6.0...v4.6.1) (2025-02-11)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * do not show undefined subdomains ([#8060](https://github.com/dynamic-labs/dynamic-auth/issues/8060)) ([ec7ca3d](https://github.com/dynamic-labs/dynamic-auth/commit/ec7ca3d1284422f54f3a1275e1983d50912bcc34))
8
+ * ensure project settings is present on is-cookie-enabled ([#8057](https://github.com/dynamic-labs/dynamic-auth/issues/8057)) ([81c6495](https://github.com/dynamic-labs/dynamic-auth/commit/81c64957031633c00c9e5ecaf304269605202abb))
9
+ * prevent user profile widget from automatically opening when linking a new wallet ([#8020](https://github.com/dynamic-labs/dynamic-auth/issues/8020)) ([4f05ac9](https://github.com/dynamic-labs/dynamic-auth/commit/4f05ac9fdc5a2fc415567dff1b33ddffd0478804))
10
+ * project settings loading and cookie setting check ([#8056](https://github.com/dynamic-labs/dynamic-auth/issues/8056)) ([457a298](https://github.com/dynamic-labs/dynamic-auth/commit/457a298ff11387ca858f85fb19d6c421e02fcc88))
11
+
2
12
  ## [4.6.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.5.3...v4.6.0) (2025-02-10)
3
13
 
4
14
 
package/package.cjs CHANGED
@@ -3,9 +3,9 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.6.0";
6
+ var version = "4.6.1";
7
7
  var dependencies = {
8
- "@dynamic-labs/sdk-api-core": "0.0.615",
8
+ "@dynamic-labs/sdk-api-core": "0.0.622",
9
9
  "@hcaptcha/react-hcaptcha": "1.4.4",
10
10
  "@thumbmarkjs/thumbmarkjs": "0.16.0",
11
11
  "country-list": "2.3.0",
package/package.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use client'
2
- var version = "4.6.0";
2
+ var version = "4.6.1";
3
3
  var dependencies = {
4
- "@dynamic-labs/sdk-api-core": "0.0.615",
4
+ "@dynamic-labs/sdk-api-core": "0.0.622",
5
5
  "@hcaptcha/react-hcaptcha": "1.4.4",
6
6
  "@thumbmarkjs/thumbmarkjs": "0.16.0",
7
7
  "country-list": "2.3.0",
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@dynamic-labs/sdk-react-core",
3
- "version": "4.6.0",
3
+ "version": "4.6.1",
4
4
  "dependencies": {
5
- "@dynamic-labs/sdk-api-core": "0.0.615",
5
+ "@dynamic-labs/sdk-api-core": "0.0.622",
6
6
  "@hcaptcha/react-hcaptcha": "1.4.4",
7
7
  "@thumbmarkjs/thumbmarkjs": "0.16.0",
8
8
  "country-list": "2.3.0",
@@ -14,16 +14,16 @@
14
14
  "yup": "0.32.11",
15
15
  "react-international-phone": "4.2.5",
16
16
  "bs58": "5.0.0",
17
- "@dynamic-labs/assert-package-version": "4.6.0",
18
- "@dynamic-labs/iconic": "4.6.0",
19
- "@dynamic-labs/logger": "4.6.0",
20
- "@dynamic-labs/multi-wallet": "4.6.0",
21
- "@dynamic-labs/rpc-providers": "4.6.0",
22
- "@dynamic-labs/store": "4.6.0",
23
- "@dynamic-labs/types": "4.6.0",
24
- "@dynamic-labs/utils": "4.6.0",
25
- "@dynamic-labs/wallet-book": "4.6.0",
26
- "@dynamic-labs/wallet-connector-core": "4.6.0",
17
+ "@dynamic-labs/assert-package-version": "4.6.1",
18
+ "@dynamic-labs/iconic": "4.6.1",
19
+ "@dynamic-labs/logger": "4.6.1",
20
+ "@dynamic-labs/multi-wallet": "4.6.1",
21
+ "@dynamic-labs/rpc-providers": "4.6.1",
22
+ "@dynamic-labs/store": "4.6.1",
23
+ "@dynamic-labs/types": "4.6.1",
24
+ "@dynamic-labs/utils": "4.6.1",
25
+ "@dynamic-labs/wallet-book": "4.6.1",
26
+ "@dynamic-labs/wallet-connector-core": "4.6.1",
27
27
  "eventemitter3": "5.0.1"
28
28
  },
29
29
  "devDependencies": {
@@ -155,10 +155,17 @@ const UserProfile = ({ rootClassName }) => {
155
155
  // Use name instead of label here because the back-end doesn't set label
156
156
  let fieldLabel = name;
157
157
  if (name === fields.NAME_SERVICE_FIELD_NAME) {
158
+ // Field should not render if ENS domain is not set
159
+ if (!ensDomain) {
160
+ return null;
161
+ }
158
162
  fieldLabel = t('dyn_subdomain_field.label');
159
- if (ensDomain) {
163
+ if (fieldValue !== '') {
160
164
  fieldValue = `${fieldValue}.${ensDomain}`;
161
165
  }
166
+ else {
167
+ fieldValue = '';
168
+ }
162
169
  }
163
170
  return (jsxRuntime.jsx(UserProfileField.UserProfileField, { name: name, label: fieldLabel, value: fieldValue }, name));
164
171
  }
@@ -151,10 +151,17 @@ const UserProfile = ({ rootClassName }) => {
151
151
  // Use name instead of label here because the back-end doesn't set label
152
152
  let fieldLabel = name;
153
153
  if (name === NAME_SERVICE_FIELD_NAME) {
154
+ // Field should not render if ENS domain is not set
155
+ if (!ensDomain) {
156
+ return null;
157
+ }
154
158
  fieldLabel = t('dyn_subdomain_field.label');
155
- if (ensDomain) {
159
+ if (fieldValue !== '') {
156
160
  fieldValue = `${fieldValue}.${ensDomain}`;
157
161
  }
162
+ else {
163
+ fieldValue = '';
164
+ }
158
165
  }
159
166
  return (jsx(UserProfileField, { name: name, label: fieldLabel, value: fieldValue }, name));
160
167
  }
@@ -725,18 +725,6 @@ const InnerDynamicContextProvider = (props) => {
725
725
  id: `project-settings-${environmentId}`,
726
726
  type: 'application/json',
727
727
  });
728
- // DYN-1140 - Opens Widget when multiWalletWidgetState changes
729
- React.useEffect(() => {
730
- // If statement to secure SingleWallet widget
731
- if (!multiWallet && multiWalletWidgetState !== 'awaiting_account_switch') {
732
- return;
733
- }
734
- // We need to make sure that the user is logged in so that we do not try to display the widget before authorization
735
- if (user$1 && multiWalletWidgetState !== 'idle' && !showDynamicUserProfile) {
736
- setShowDynamicUserProfile(true);
737
- }
738
- // eslint-disable-next-line react-hooks/exhaustive-deps
739
- }, [multiWallet, multiWalletWidgetState, showDynamicUserProfile]);
740
728
  return (jsxRuntime.jsx(reactI18next.I18nextProvider, { i18n: i18nSDKInstance, children: jsxRuntime.jsx(DynamicContext.Provider, { value: value, children: jsxRuntime.jsx(walletBook.WalletBookContextProvider, { walletBook: walletBook$1, children: jsxRuntime.jsx(ThemeContext.ThemeContextProvider, { customerTheme: parseTheme.parseTheme(theme, ((_p = projectSettings$1 === null || projectSettings$1 === void 0 ? void 0 : projectSettings$1.design) === null || _p === void 0 ? void 0 : _p.modal) || undefined), designSettings: projectSettings$1 === null || projectSettings$1 === void 0 ? void 0 : projectSettings$1.design, children: jsxRuntime.jsx(LoadingContext.LoadingContextProvider, { children: jsxRuntime.jsxs(ViewContext.ViewContextProvider, { initialViewType: helpers.getInitialViewType({
741
729
  bridgeOnboardingCompleted,
742
730
  connectedWallets,
@@ -721,18 +721,6 @@ const InnerDynamicContextProvider = (props) => {
721
721
  id: `project-settings-${environmentId}`,
722
722
  type: 'application/json',
723
723
  });
724
- // DYN-1140 - Opens Widget when multiWalletWidgetState changes
725
- useEffect(() => {
726
- // If statement to secure SingleWallet widget
727
- if (!multiWallet && multiWalletWidgetState !== 'awaiting_account_switch') {
728
- return;
729
- }
730
- // We need to make sure that the user is logged in so that we do not try to display the widget before authorization
731
- if (user && multiWalletWidgetState !== 'idle' && !showDynamicUserProfile) {
732
- setShowDynamicUserProfile(true);
733
- }
734
- // eslint-disable-next-line react-hooks/exhaustive-deps
735
- }, [multiWallet, multiWalletWidgetState, showDynamicUserProfile]);
736
724
  return (jsx(I18nextProvider, { i18n: i18nSDKInstance, children: jsx(DynamicContext.Provider, { value: value, children: jsx(WalletBookContextProvider, { walletBook: walletBook, children: jsx(ThemeContextProvider, { customerTheme: parseTheme(theme, ((_p = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _p === void 0 ? void 0 : _p.modal) || undefined), designSettings: projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design, children: jsx(LoadingContextProvider, { children: jsxs(ViewContextProvider, { initialViewType: getInitialViewType({
737
725
  bridgeOnboardingCompleted,
738
726
  connectedWallets,
@@ -51,7 +51,6 @@ require('../../../../views/CollectUserDataView/useFields.cjs');
51
51
  require('../../../FieldsStateContext/FieldsStateContext.cjs');
52
52
  require('../../../UserFieldEditorContext/UserFieldEditorContext.cjs');
53
53
  require('@dynamic-labs/rpc-providers');
54
- var useEffectOnce = require('../../../../utils/hooks/useEffectOnce/useEffectOnce.cjs');
55
54
  require('../../../../store/state/loadingAndLifecycle.cjs');
56
55
  require('@dynamic-labs/store');
57
56
  require('../../../../store/state/walletOptions/walletOptions.cjs');
@@ -76,6 +75,7 @@ require('qrcode');
76
75
  require('../../../WalletContext/WalletContext.cjs');
77
76
  require('formik');
78
77
  require('../../../../utils/hooks/useSubdomainCheck/useSubdomainCheck.cjs');
78
+ var useEffectOnce = require('../../../../utils/hooks/useEffectOnce/useEffectOnce.cjs');
79
79
  require('../../../WalletGroupContext/WalletGroupContext.cjs');
80
80
  require('../../../IpConfigurationContext/IpConfigurationContext.cjs');
81
81
  require('../../../ConnectWithOtpContext/ConnectWithOtpContext.cjs');
@@ -47,7 +47,6 @@ import '../../../../views/CollectUserDataView/useFields.js';
47
47
  import '../../../FieldsStateContext/FieldsStateContext.js';
48
48
  import '../../../UserFieldEditorContext/UserFieldEditorContext.js';
49
49
  import '@dynamic-labs/rpc-providers';
50
- import { useEffectOnce } from '../../../../utils/hooks/useEffectOnce/useEffectOnce.js';
51
50
  import '../../../../store/state/loadingAndLifecycle.js';
52
51
  import '@dynamic-labs/store';
53
52
  import '../../../../store/state/walletOptions/walletOptions.js';
@@ -72,6 +71,7 @@ import 'qrcode';
72
71
  import '../../../WalletContext/WalletContext.js';
73
72
  import 'formik';
74
73
  import '../../../../utils/hooks/useSubdomainCheck/useSubdomainCheck.js';
74
+ import { useEffectOnce } from '../../../../utils/hooks/useEffectOnce/useEffectOnce.js';
75
75
  import '../../../WalletGroupContext/WalletGroupContext.js';
76
76
  import '../../../IpConfigurationContext/IpConfigurationContext.js';
77
77
  import '../../../ConnectWithOtpContext/ConnectWithOtpContext.js';
@@ -24,8 +24,8 @@ require('@dynamic-labs/wallet-book');
24
24
  require('../../shared/consts/index.cjs');
25
25
  require('../../store/state/nonce/nonce.cjs');
26
26
  var isCookieEnabled = require('../../utils/functions/isCookieEnabled/isCookieEnabled.cjs');
27
+ var projectSettings = require('../../store/state/projectSettings/projectSettings.cjs');
27
28
  require('../../store/state/user/user.cjs');
28
- require('../../store/state/projectSettings/projectSettings.cjs');
29
29
  require('../../locale/locale.cjs');
30
30
  require('../../store/state/dynamicContextProps/dynamicContextProps.cjs');
31
31
  require('../../store/state/primaryWalletId/primaryWalletId.cjs');
@@ -43,9 +43,8 @@ const sdkApi = ({ customHeaders } = {}) => {
43
43
  if (deviceFingerprint) {
44
44
  settings.headers['x-dyn-device-fingerprint'] = deviceFingerprint;
45
45
  }
46
- const credentials = isCookieEnabled.isCookieEnabled()
47
- ? 'include'
48
- : undefined;
46
+ const projectSettings$1 = projectSettings.getProjectSettings();
47
+ const credentials = projectSettings$1 && isCookieEnabled.isCookieEnabled(projectSettings$1) ? 'include' : undefined;
49
48
  settings.headers['x-dyn-version'] = `WalletKit/${version.VERSION}`;
50
49
  settings.headers['x-dyn-api-version'] = `API/${version.API_VERSION}`;
51
50
  return new sdkApiCore.SDKApi(new sdkApiCore.Configuration(Object.assign(Object.assign({}, settings), { credentials, fetchApi: utils.FetchService.fetch })));
@@ -20,8 +20,8 @@ import '@dynamic-labs/wallet-book';
20
20
  import '../../shared/consts/index.js';
21
21
  import '../../store/state/nonce/nonce.js';
22
22
  import { isCookieEnabled } from '../../utils/functions/isCookieEnabled/isCookieEnabled.js';
23
+ import { getProjectSettings } from '../../store/state/projectSettings/projectSettings.js';
23
24
  import '../../store/state/user/user.js';
24
- import '../../store/state/projectSettings/projectSettings.js';
25
25
  import '../../locale/locale.js';
26
26
  import '../../store/state/dynamicContextProps/dynamicContextProps.js';
27
27
  import '../../store/state/primaryWalletId/primaryWalletId.js';
@@ -39,9 +39,8 @@ const sdkApi = ({ customHeaders } = {}) => {
39
39
  if (deviceFingerprint) {
40
40
  settings.headers['x-dyn-device-fingerprint'] = deviceFingerprint;
41
41
  }
42
- const credentials = isCookieEnabled()
43
- ? 'include'
44
- : undefined;
42
+ const projectSettings = getProjectSettings();
43
+ const credentials = projectSettings && isCookieEnabled(projectSettings) ? 'include' : undefined;
45
44
  settings.headers['x-dyn-version'] = `WalletKit/${VERSION}`;
46
45
  settings.headers['x-dyn-api-version'] = `API/${API_VERSION}`;
47
46
  return new SDKApi(new Configuration(Object.assign(Object.assign({}, settings), { credentials, fetchApi: FetchService.fetch })));
@@ -64,7 +64,6 @@ require('../../views/CollectUserDataView/useFields.cjs');
64
64
  require('../../context/FieldsStateContext/FieldsStateContext.cjs');
65
65
  require('../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
66
66
  require('@dynamic-labs/rpc-providers');
67
- var useEffectOnce = require('../../utils/hooks/useEffectOnce/useEffectOnce.cjs');
68
67
  require('../../store/state/loadingAndLifecycle.cjs');
69
68
  require('@dynamic-labs/store');
70
69
  require('../../store/state/walletOptions/walletOptions.cjs');
@@ -93,6 +92,7 @@ var ModalHeader = require('../../components/ModalHeader/ModalHeader.cjs');
93
92
  require('../../store/state/sendBalances.cjs');
94
93
  require('../../components/Input/Input.cjs');
95
94
  require('../../components/OverlayCard/OverlayCard.cjs');
95
+ var useEffectOnce = require('../../utils/hooks/useEffectOnce/useEffectOnce.cjs');
96
96
  require('../../views/TransactionConfirmationView/TransactionConfirmationView.cjs');
97
97
  var PasskeyContext = require('../../context/PasskeyContext/PasskeyContext.cjs');
98
98
  require('../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs');
@@ -60,7 +60,6 @@ import '../../views/CollectUserDataView/useFields.js';
60
60
  import '../../context/FieldsStateContext/FieldsStateContext.js';
61
61
  import '../../context/UserFieldEditorContext/UserFieldEditorContext.js';
62
62
  import '@dynamic-labs/rpc-providers';
63
- import { useEffectOnce } from '../../utils/hooks/useEffectOnce/useEffectOnce.js';
64
63
  import '../../store/state/loadingAndLifecycle.js';
65
64
  import '@dynamic-labs/store';
66
65
  import '../../store/state/walletOptions/walletOptions.js';
@@ -89,6 +88,7 @@ import { ModalHeader } from '../../components/ModalHeader/ModalHeader.js';
89
88
  import '../../store/state/sendBalances.js';
90
89
  import '../../components/Input/Input.js';
91
90
  import '../../components/OverlayCard/OverlayCard.js';
91
+ import { useEffectOnce } from '../../utils/hooks/useEffectOnce/useEffectOnce.js';
92
92
  import '../../views/TransactionConfirmationView/TransactionConfirmationView.js';
93
93
  import { usePasskeyContext } from '../../context/PasskeyContext/PasskeyContext.js';
94
94
  import '../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js';
@@ -10,7 +10,6 @@ require('../../utils/constants/colors.cjs');
10
10
  require('../../utils/constants/values.cjs');
11
11
  var stateConfig = require('../stateConfig.cjs');
12
12
  var version = require('../../../version.cjs');
13
- var clearExpiredData = require('./utils/clearExpiredData/clearExpiredData.cjs');
14
13
  var syncLegacyStorage = require('./utils/syncLegacyStorage/syncLegacyStorage.cjs');
15
14
 
16
15
  let store;
@@ -43,7 +42,6 @@ const initializeStore = (props) => {
43
42
  store: store$1.createStore(() => stateConfig.createInitialStates(props)),
44
43
  version: utils.formatVersion(version.VERSION, 'major.minor'),
45
44
  }));
46
- clearExpiredData.clearExpiredData(store);
47
45
  };
48
46
  const getStorage = () => {
49
47
  if (typeof localStorage === 'undefined') {
@@ -6,7 +6,6 @@ import '../../utils/constants/colors.js';
6
6
  import '../../utils/constants/values.js';
7
7
  import { transformStateForLocalStorage, createInitialStates } from '../stateConfig.js';
8
8
  import { VERSION } from '../../../version.js';
9
- import { clearExpiredData } from './utils/clearExpiredData/clearExpiredData.js';
10
9
  import { syncLegacyStorage } from './utils/syncLegacyStorage/syncLegacyStorage.js';
11
10
 
12
11
  let store;
@@ -39,7 +38,6 @@ const initializeStore = (props) => {
39
38
  store: createStore(() => createInitialStates(props)),
40
39
  version: formatVersion(VERSION, 'major.minor'),
41
40
  }));
42
- clearExpiredData(store);
43
41
  };
44
42
  const getStorage = () => {
45
43
  if (typeof localStorage === 'undefined') {
@@ -10,6 +10,7 @@ require('../../../config/ApiEndpoint.cjs');
10
10
  require('../../../utils/constants/values.cjs');
11
11
  require('@dynamic-labs/multi-wallet');
12
12
  require('../../../shared/logger.cjs');
13
+ var localStorage = require('../../../utils/constants/localStorage.cjs');
13
14
  require('../../../utils/constants/colors.cjs');
14
15
  require('react-international-phone');
15
16
  require('@dynamic-labs/iconic');
@@ -22,7 +23,7 @@ require('../../../shared/consts/index.cjs');
22
23
  require('../nonce/nonce.cjs');
23
24
  var dynamicContextProps = require('../dynamicContextProps/dynamicContextProps.cjs');
24
25
  require('../primaryWalletId/primaryWalletId.cjs');
25
- require('../user/user.cjs');
26
+ var user = require('../user/user.cjs');
26
27
  var settings = require('../../../data/api/settings/settings.cjs');
27
28
  require('../../../locale/locale.cjs');
28
29
  var useDynamicEvents = require('../../../utils/hooks/events/useDynamicEvents/useDynamicEvents.cjs');
@@ -97,9 +98,18 @@ var createStoreState = require('../../internalImplementation/utils/createStoreSt
97
98
 
98
99
  const { getProjectSettings: getProjectSettingsRaw, setProjectSettings, useProjectSettings: useProjectSettingsRaw, resetProjectSettings, } = createStoreState.createStoreState('projectSettings');
99
100
  const getProjectSettings = () => getProjectSettingsRaw().settings;
101
+ const getProjectSettingsExpireAt = () => getProjectSettingsRaw().expiresAt;
100
102
  const useProjectSettings = () => useProjectSettingsRaw().settings;
101
103
  const useFetchProjectSettings = ({ retries = 2, } = {}) => {
102
- const lsSettingsExists = Boolean(useProjectSettings());
104
+ const originalProjectSettings = getProjectSettings();
105
+ const expiresAt = getProjectSettingsExpireAt();
106
+ const isProjectSettingsPresent = Boolean(originalProjectSettings);
107
+ const didProjectSettingsExpire = expiresAt ? expiresAt < Date.now() : false;
108
+ const hasUser = user.getUser() !== undefined;
109
+ const hasConnectedWallet = (utils.StorageService.getItem(localStorage.CONNECTED_WALLETS_INFO) || []).length > 0;
110
+ const enableProjectSettingsFetch = !isProjectSettingsPresent ||
111
+ didProjectSettingsExpire ||
112
+ (hasUser === false && hasConnectedWallet === false);
103
113
  const environmentId = dynamicContextProps.useEnvironmentId();
104
114
  const { retrigger } = usePromise.usePromise(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
105
115
  const settings$1 = yield settings.fetchProjectSettings(environmentId);
@@ -108,7 +118,7 @@ const useFetchProjectSettings = ({ retries = 2, } = {}) => {
108
118
  return settings$1;
109
119
  }), {
110
120
  deps: [environmentId],
111
- enabled: !lsSettingsExists,
121
+ enabled: enableProjectSettingsFetch,
112
122
  onResolve: (projectSettings) => {
113
123
  const expiry = new Date().getTime() + 60000 * 5;
114
124
  setProjectSettings({
@@ -123,6 +133,7 @@ const useFetchProjectSettings = ({ retries = 2, } = {}) => {
123
133
  };
124
134
 
125
135
  exports.getProjectSettings = getProjectSettings;
136
+ exports.getProjectSettingsExpireAt = getProjectSettingsExpireAt;
126
137
  exports.resetProjectSettings = resetProjectSettings;
127
138
  exports.setProjectSettings = setProjectSettings;
128
139
  exports.useFetchProjectSettings = useFetchProjectSettings;
@@ -1,11 +1,12 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../../../_virtual/_tslib.js';
3
- import { DynamicError } from '@dynamic-labs/utils';
3
+ import { StorageService, DynamicError } from '@dynamic-labs/utils';
4
4
  import '@dynamic-labs/sdk-api-core';
5
5
  import '../../../config/ApiEndpoint.js';
6
6
  import '../../../utils/constants/values.js';
7
7
  import '@dynamic-labs/multi-wallet';
8
8
  import '../../../shared/logger.js';
9
+ import { CONNECTED_WALLETS_INFO } from '../../../utils/constants/localStorage.js';
9
10
  import '../../../utils/constants/colors.js';
10
11
  import 'react-international-phone';
11
12
  import '@dynamic-labs/iconic';
@@ -18,7 +19,7 @@ import '../../../shared/consts/index.js';
18
19
  import '../nonce/nonce.js';
19
20
  import { useEnvironmentId } from '../dynamicContextProps/dynamicContextProps.js';
20
21
  import '../primaryWalletId/primaryWalletId.js';
21
- import '../user/user.js';
22
+ import { getUser } from '../user/user.js';
22
23
  import { fetchProjectSettings } from '../../../data/api/settings/settings.js';
23
24
  import '../../../locale/locale.js';
24
25
  import { useDynamicEvents } from '../../../utils/hooks/events/useDynamicEvents/useDynamicEvents.js';
@@ -93,9 +94,18 @@ import { createStoreState } from '../../internalImplementation/utils/createStore
93
94
 
94
95
  const { getProjectSettings: getProjectSettingsRaw, setProjectSettings, useProjectSettings: useProjectSettingsRaw, resetProjectSettings, } = createStoreState('projectSettings');
95
96
  const getProjectSettings = () => getProjectSettingsRaw().settings;
97
+ const getProjectSettingsExpireAt = () => getProjectSettingsRaw().expiresAt;
96
98
  const useProjectSettings = () => useProjectSettingsRaw().settings;
97
99
  const useFetchProjectSettings = ({ retries = 2, } = {}) => {
98
- const lsSettingsExists = Boolean(useProjectSettings());
100
+ const originalProjectSettings = getProjectSettings();
101
+ const expiresAt = getProjectSettingsExpireAt();
102
+ const isProjectSettingsPresent = Boolean(originalProjectSettings);
103
+ const didProjectSettingsExpire = expiresAt ? expiresAt < Date.now() : false;
104
+ const hasUser = getUser() !== undefined;
105
+ const hasConnectedWallet = (StorageService.getItem(CONNECTED_WALLETS_INFO) || []).length > 0;
106
+ const enableProjectSettingsFetch = !isProjectSettingsPresent ||
107
+ didProjectSettingsExpire ||
108
+ (hasUser === false && hasConnectedWallet === false);
99
109
  const environmentId = useEnvironmentId();
100
110
  const { retrigger } = usePromise(() => __awaiter(void 0, void 0, void 0, function* () {
101
111
  const settings = yield fetchProjectSettings(environmentId);
@@ -104,7 +114,7 @@ const useFetchProjectSettings = ({ retries = 2, } = {}) => {
104
114
  return settings;
105
115
  }), {
106
116
  deps: [environmentId],
107
- enabled: !lsSettingsExists,
117
+ enabled: enableProjectSettingsFetch,
108
118
  onResolve: (projectSettings) => {
109
119
  const expiry = new Date().getTime() + 60000 * 5;
110
120
  setProjectSettings({
@@ -118,4 +128,4 @@ const useFetchProjectSettings = ({ retries = 2, } = {}) => {
118
128
  return { refetchProjectSettings: retrigger };
119
129
  };
120
130
 
121
- export { getProjectSettings, resetProjectSettings, setProjectSettings, useFetchProjectSettings, useProjectSettings };
131
+ export { getProjectSettings, getProjectSettingsExpireAt, resetProjectSettings, setProjectSettings, useFetchProjectSettings, useProjectSettings };
@@ -5,10 +5,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var sdkApiCore = require('@dynamic-labs/sdk-api-core');
7
7
  var utils = require('@dynamic-labs/utils');
8
- var projectSettings = require('../../../store/state/projectSettings/projectSettings.cjs');
9
8
 
10
- const isCookieEnabled = () => {
11
- var _a, _b, _c;
9
+ const isCookieEnabled = (projectSettings) => {
10
+ var _a, _b;
11
+ utils.assertDefined(projectSettings, 'projectSettings is required');
12
12
  /**
13
13
  * There is no cookie on native mobile applications
14
14
  * so this feature must be disabled for native mobile
@@ -16,13 +16,13 @@ const isCookieEnabled = () => {
16
16
  if (utils.PlatformService.isNativeMobile) {
17
17
  return false;
18
18
  }
19
- const securitySettings = (_a = projectSettings.getProjectSettings()) === null || _a === void 0 ? void 0 : _a.security;
19
+ const securitySettings = projectSettings.security;
20
20
  if (!securitySettings)
21
21
  return false;
22
22
  // client uses Dynamic cookies
23
- const dynamicCookiesEnabled = (((_b = securitySettings.auth) === null || _b === void 0 ? void 0 : _b.storage) || []).includes(sdkApiCore.AuthStorageEnum.Cookie);
23
+ const dynamicCookiesEnabled = (((_a = securitySettings.auth) === null || _a === void 0 ? void 0 : _a.storage) || []).includes(sdkApiCore.AuthStorageEnum.Cookie);
24
24
  // BYO JWT client puts their non-Dynamic JWT in a cookie
25
- const byoJwtCookieEnabled = Boolean((_c = securitySettings.externalAuth) === null || _c === void 0 ? void 0 : _c.cookieName);
25
+ const byoJwtCookieEnabled = Boolean((_b = securitySettings.externalAuth) === null || _b === void 0 ? void 0 : _b.cookieName);
26
26
  // should return true for both of these scenarios
27
27
  // because we also need to do `credentials: true` in api.ts when
28
28
  // a byo jwt client sets their named cookie for their jwt and
@@ -1 +1,2 @@
1
- export declare const isCookieEnabled: () => boolean;
1
+ import { ProjectSettings } from '@dynamic-labs/sdk-api-core';
2
+ export declare const isCookieEnabled: (projectSettings: ProjectSettings) => boolean;
@@ -1,10 +1,10 @@
1
1
  'use client'
2
2
  import { AuthStorageEnum } from '@dynamic-labs/sdk-api-core';
3
- import { PlatformService } from '@dynamic-labs/utils';
4
- import { getProjectSettings } from '../../../store/state/projectSettings/projectSettings.js';
3
+ import { assertDefined, PlatformService } from '@dynamic-labs/utils';
5
4
 
6
- const isCookieEnabled = () => {
7
- var _a, _b, _c;
5
+ const isCookieEnabled = (projectSettings) => {
6
+ var _a, _b;
7
+ assertDefined(projectSettings, 'projectSettings is required');
8
8
  /**
9
9
  * There is no cookie on native mobile applications
10
10
  * so this feature must be disabled for native mobile
@@ -12,13 +12,13 @@ const isCookieEnabled = () => {
12
12
  if (PlatformService.isNativeMobile) {
13
13
  return false;
14
14
  }
15
- const securitySettings = (_a = getProjectSettings()) === null || _a === void 0 ? void 0 : _a.security;
15
+ const securitySettings = projectSettings.security;
16
16
  if (!securitySettings)
17
17
  return false;
18
18
  // client uses Dynamic cookies
19
- const dynamicCookiesEnabled = (((_b = securitySettings.auth) === null || _b === void 0 ? void 0 : _b.storage) || []).includes(AuthStorageEnum.Cookie);
19
+ const dynamicCookiesEnabled = (((_a = securitySettings.auth) === null || _a === void 0 ? void 0 : _a.storage) || []).includes(AuthStorageEnum.Cookie);
20
20
  // BYO JWT client puts their non-Dynamic JWT in a cookie
21
- const byoJwtCookieEnabled = Boolean((_c = securitySettings.externalAuth) === null || _c === void 0 ? void 0 : _c.cookieName);
21
+ const byoJwtCookieEnabled = Boolean((_b = securitySettings.externalAuth) === null || _b === void 0 ? void 0 : _b.cookieName);
22
22
  // should return true for both of these scenarios
23
23
  // because we also need to do `credentials: true` in api.ts when
24
24
  // a byo jwt client sets their named cookie for their jwt and
@@ -8,6 +8,7 @@ var localStorage = require('../../constants/localStorage.cjs');
8
8
  var values = require('../../constants/values.cjs');
9
9
  var isCookieEnabled = require('../isCookieEnabled/isCookieEnabled.cjs');
10
10
  var storeExpiresAt = require('../storeExpiresAt/storeExpiresAt.cjs');
11
+ var projectSettings = require('../../../store/state/projectSettings/projectSettings.cjs');
11
12
 
12
13
  const storeAuthToken = ({ jwt, minifiedJwt, expiresAt, }) => {
13
14
  // expiresAt is always sent back by the backend, regardless of whether jwt/minifiedJwt are sent or not
@@ -20,7 +21,8 @@ const storeAuthToken = ({ jwt, minifiedJwt, expiresAt, }) => {
20
21
  utils.StorageService.setItem(localStorage.AUTH_MIN_TOKEN, minifiedJwt, {
21
22
  priority: ['secureStorage', 'localStorage'],
22
23
  });
23
- if (isCookieEnabled.isCookieEnabled()) {
24
+ const projectSettings$1 = projectSettings.getProjectSettings();
25
+ if (projectSettings$1 && isCookieEnabled.isCookieEnabled(projectSettings$1)) {
24
26
  // if cookie is enabled, but the backend returns a JWT, then use JS to store the cookie
25
27
  const expireDate = new Date(expiresAt * 1000).toUTCString();
26
28
  const authCookie = `${values.DYNAMIC_AUTH_COOKIE_NAME}=${minifiedJwt}; expires=${expireDate}; path=/; SameSite=Lax`;
@@ -4,6 +4,7 @@ import { AUTH_TOKEN, AUTH_MIN_TOKEN } from '../../constants/localStorage.js';
4
4
  import { DYNAMIC_AUTH_COOKIE_NAME } from '../../constants/values.js';
5
5
  import { isCookieEnabled } from '../isCookieEnabled/isCookieEnabled.js';
6
6
  import { storeExpiresAt } from '../storeExpiresAt/storeExpiresAt.js';
7
+ import { getProjectSettings } from '../../../store/state/projectSettings/projectSettings.js';
7
8
 
8
9
  const storeAuthToken = ({ jwt, minifiedJwt, expiresAt, }) => {
9
10
  // expiresAt is always sent back by the backend, regardless of whether jwt/minifiedJwt are sent or not
@@ -16,7 +17,8 @@ const storeAuthToken = ({ jwt, minifiedJwt, expiresAt, }) => {
16
17
  StorageService.setItem(AUTH_MIN_TOKEN, minifiedJwt, {
17
18
  priority: ['secureStorage', 'localStorage'],
18
19
  });
19
- if (isCookieEnabled()) {
20
+ const projectSettings = getProjectSettings();
21
+ if (projectSettings && isCookieEnabled(projectSettings)) {
20
22
  // if cookie is enabled, but the backend returns a JWT, then use JS to store the cookie
21
23
  const expireDate = new Date(expiresAt * 1000).toUTCString();
22
24
  const authCookie = `${DYNAMIC_AUTH_COOKIE_NAME}=${minifiedJwt}; expires=${expireDate}; path=/; SameSite=Lax`;
@@ -20,10 +20,10 @@ require('@dynamic-labs/multi-wallet');
20
20
  require('react-international-phone');
21
21
  require('../../../store/state/nonce/nonce.cjs');
22
22
  var isCookieEnabled = require('../../functions/isCookieEnabled/isCookieEnabled.cjs');
23
+ var projectSettings = require('../../../store/state/projectSettings/projectSettings.cjs');
23
24
  var updatePrimaryWalletId = require('../../functions/updatePrimaryWalletId/updatePrimaryWalletId.cjs');
24
25
  require('../../../config/ApiEndpoint.cjs');
25
26
  var user = require('../../../store/state/user/user.cjs');
26
- var projectSettings = require('../../../store/state/projectSettings/projectSettings.cjs');
27
27
  require('../../../locale/locale.cjs');
28
28
  var user$1 = require('../../../data/api/user/user.cjs');
29
29
  var useDynamicEvents = require('../events/useDynamicEvents/useDynamicEvents.cjs');
@@ -61,7 +61,10 @@ const useResetCookieLocalStorage = () => {
61
61
  * so attempt to set it here.
62
62
  */
63
63
  const maybeInitUserRefresh = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
64
- if (!user$2 && isCookieEnabled.isCookieEnabled() && !hasLoggedOut.current) {
64
+ if (!user$2 &&
65
+ projectSettings$1 &&
66
+ isCookieEnabled.isCookieEnabled(projectSettings$1) &&
67
+ !hasLoggedOut.current) {
65
68
  // Disable all next calls to this method
66
69
  didRefreshUserRef.current = true;
67
70
  try {
@@ -86,8 +89,8 @@ const useResetCookieLocalStorage = () => {
86
89
  setIsLoading(false);
87
90
  }
88
91
  });
89
- // Ensure this effect only runs once
90
- if (didRefreshUserRef.current)
92
+ // Ensure this effect only runs once projectSettings is available
93
+ if (didRefreshUserRef.current || !projectSettings$1)
91
94
  return;
92
95
  maybeInitUserRefresh();
93
96
  }, [user$2, projectSettings$1, environmentId]);
@@ -16,10 +16,10 @@ import '@dynamic-labs/multi-wallet';
16
16
  import 'react-international-phone';
17
17
  import '../../../store/state/nonce/nonce.js';
18
18
  import { isCookieEnabled } from '../../functions/isCookieEnabled/isCookieEnabled.js';
19
+ import { useProjectSettings } from '../../../store/state/projectSettings/projectSettings.js';
19
20
  import { updatePrimaryWalletId } from '../../functions/updatePrimaryWalletId/updatePrimaryWalletId.js';
20
21
  import '../../../config/ApiEndpoint.js';
21
22
  import { getUser } from '../../../store/state/user/user.js';
22
- import { useProjectSettings } from '../../../store/state/projectSettings/projectSettings.js';
23
23
  import '../../../locale/locale.js';
24
24
  import { refreshUserJwt } from '../../../data/api/user/user.js';
25
25
  import { useInternalDynamicEvents } from '../events/useDynamicEvents/useDynamicEvents.js';
@@ -57,7 +57,10 @@ const useResetCookieLocalStorage = () => {
57
57
  * so attempt to set it here.
58
58
  */
59
59
  const maybeInitUserRefresh = () => __awaiter(void 0, void 0, void 0, function* () {
60
- if (!user && isCookieEnabled() && !hasLoggedOut.current) {
60
+ if (!user &&
61
+ projectSettings &&
62
+ isCookieEnabled(projectSettings) &&
63
+ !hasLoggedOut.current) {
61
64
  // Disable all next calls to this method
62
65
  didRefreshUserRef.current = true;
63
66
  try {
@@ -82,8 +85,8 @@ const useResetCookieLocalStorage = () => {
82
85
  setIsLoading(false);
83
86
  }
84
87
  });
85
- // Ensure this effect only runs once
86
- if (didRefreshUserRef.current)
88
+ // Ensure this effect only runs once projectSettings is available
89
+ if (didRefreshUserRef.current || !projectSettings)
87
90
  return;
88
91
  maybeInitUserRefresh();
89
92
  }, [user, projectSettings, environmentId]);
@@ -16,8 +16,8 @@ var getAuthToken = require('../../../functions/getAuthToken/getAuthToken.cjs');
16
16
  * Detects mismatch between user and auth token.
17
17
  * @returns true if there is no mismatch.
18
18
  */
19
- const handleUserDataOutOfSync = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ environmentId, logout, }) {
20
- const cookieEnabled = isCookieEnabled.isCookieEnabled();
19
+ const handleUserDataOutOfSync = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ environmentId, logout, projectSettings, }) {
20
+ const cookieEnabled = isCookieEnabled.isCookieEnabled(projectSettings);
21
21
  const authToken = getAuthToken.getAuthToken();
22
22
  const user$2 = user.getUser();
23
23
  if (authToken || !user$2) {
@@ -1,9 +1,11 @@
1
+ import { ProjectSettings } from '@dynamic-labs/sdk-api-core';
1
2
  export type HandleUserDataOutOfSyncParams = {
2
3
  environmentId: string;
3
4
  logout: (reason: string, params: any) => Promise<void>;
5
+ projectSettings: ProjectSettings;
4
6
  };
5
7
  /**
6
8
  * Detects mismatch between user and auth token.
7
9
  * @returns true if there is no mismatch.
8
10
  */
9
- export declare const handleUserDataOutOfSync: ({ environmentId, logout, }: HandleUserDataOutOfSyncParams) => Promise<boolean>;
11
+ export declare const handleUserDataOutOfSync: ({ environmentId, logout, projectSettings, }: HandleUserDataOutOfSyncParams) => Promise<boolean>;
@@ -12,8 +12,8 @@ import { getAuthToken } from '../../../functions/getAuthToken/getAuthToken.js';
12
12
  * Detects mismatch between user and auth token.
13
13
  * @returns true if there is no mismatch.
14
14
  */
15
- const handleUserDataOutOfSync = (_a) => __awaiter(void 0, [_a], void 0, function* ({ environmentId, logout, }) {
16
- const cookieEnabled = isCookieEnabled();
15
+ const handleUserDataOutOfSync = (_a) => __awaiter(void 0, [_a], void 0, function* ({ environmentId, logout, projectSettings, }) {
16
+ const cookieEnabled = isCookieEnabled(projectSettings);
17
17
  const authToken = getAuthToken();
18
18
  const user = getUser();
19
19
  if (authToken || !user) {
@@ -6,24 +6,27 @@ Object.defineProperty(exports, '__esModule', { value: true });
6
6
  var _tslib = require('../../../../../_virtual/_tslib.cjs');
7
7
  var React = require('react');
8
8
  var logger = require('../../../shared/logger.cjs');
9
- var useEffectOnce = require('../useEffectOnce/useEffectOnce.cjs');
10
9
  var loadingAndLifecycle = require('../../../store/state/loadingAndLifecycle.cjs');
11
10
  var useDynamicEvents = require('../events/useDynamicEvents/useDynamicEvents.cjs');
11
+ var projectSettings = require('../../../store/state/projectSettings/projectSettings.cjs');
12
12
  var handleStoreAndEnvironmentMismatch = require('./handleStoreAndEnvironmentMismatch/handleStoreAndEnvironmentMismatch.cjs');
13
13
  var handleUserDataOutOfSync = require('./handleUserDataOutOfSync/handleUserDataOutOfSync.cjs');
14
14
  var handleStoreVersionChanged = require('./handleStoreVersionChanged/handleStoreVersionChanged.cjs');
15
15
 
16
16
  const useValidateSession = ({ environmentId, handleLogOut }) => {
17
+ const didRunRef = React.useRef(false);
18
+ const projectSettings$1 = projectSettings.useProjectSettings();
17
19
  const logout = React.useCallback(
18
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
21
  (reason, params) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
20
- logger.logger.debug(`Logging out due to invalid session - Reason: ${reason}`, Object.assign({}, params));
22
+ logger.logger.info(`Logging out due to invalid session - Reason: ${reason}`, Object.assign({}, params));
21
23
  return handleLogOut();
22
24
  }), [handleLogOut]);
23
- const validateSession = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
25
+ const validateSession = React.useCallback((projectSettings) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
24
26
  const params = {
25
27
  environmentId,
26
28
  logout,
29
+ projectSettings,
27
30
  };
28
31
  yield Promise.all([
29
32
  handleStoreAndEnvironmentMismatch.handleStoreAndEnvironmentMismatch(params),
@@ -33,10 +36,17 @@ const useValidateSession = ({ environmentId, handleLogOut }) => {
33
36
  // Regardless of whether we logged out or not, session validation is now complete
34
37
  loadingAndLifecycle.setLoadingAndLifecycle({ sessionValidation: true });
35
38
  }), [logout, environmentId]);
36
- useEffectOnce.useEffectOnce(() => {
37
- validateSession();
39
+ React.useEffect(() => {
40
+ if (didRunRef.current || !projectSettings$1)
41
+ return;
42
+ didRunRef.current = true;
43
+ validateSession(projectSettings$1);
44
+ }, [validateSession, projectSettings$1]);
45
+ useDynamicEvents.useInternalDynamicEvents('triggerSessionValidation', () => {
46
+ if (!projectSettings$1)
47
+ return;
48
+ validateSession(projectSettings$1);
38
49
  });
39
- useDynamicEvents.useInternalDynamicEvents('triggerSessionValidation', validateSession);
40
50
  };
41
51
 
42
52
  exports.useValidateSession = useValidateSession;
@@ -1,25 +1,28 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../../../_virtual/_tslib.js';
3
- import { useCallback } from 'react';
3
+ import { useRef, useCallback, useEffect } from 'react';
4
4
  import { logger } from '../../../shared/logger.js';
5
- import { useEffectOnce } from '../useEffectOnce/useEffectOnce.js';
6
5
  import { setLoadingAndLifecycle } from '../../../store/state/loadingAndLifecycle.js';
7
6
  import { useInternalDynamicEvents } from '../events/useDynamicEvents/useDynamicEvents.js';
7
+ import { useProjectSettings } from '../../../store/state/projectSettings/projectSettings.js';
8
8
  import { handleStoreAndEnvironmentMismatch } from './handleStoreAndEnvironmentMismatch/handleStoreAndEnvironmentMismatch.js';
9
9
  import { handleUserDataOutOfSync } from './handleUserDataOutOfSync/handleUserDataOutOfSync.js';
10
10
  import { handleStoreVersionChanged } from './handleStoreVersionChanged/handleStoreVersionChanged.js';
11
11
 
12
12
  const useValidateSession = ({ environmentId, handleLogOut }) => {
13
+ const didRunRef = useRef(false);
14
+ const projectSettings = useProjectSettings();
13
15
  const logout = useCallback(
14
16
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
17
  (reason, params) => __awaiter(void 0, void 0, void 0, function* () {
16
- logger.debug(`Logging out due to invalid session - Reason: ${reason}`, Object.assign({}, params));
18
+ logger.info(`Logging out due to invalid session - Reason: ${reason}`, Object.assign({}, params));
17
19
  return handleLogOut();
18
20
  }), [handleLogOut]);
19
- const validateSession = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
21
+ const validateSession = useCallback((projectSettings) => __awaiter(void 0, void 0, void 0, function* () {
20
22
  const params = {
21
23
  environmentId,
22
24
  logout,
25
+ projectSettings,
23
26
  };
24
27
  yield Promise.all([
25
28
  handleStoreAndEnvironmentMismatch(params),
@@ -29,10 +32,17 @@ const useValidateSession = ({ environmentId, handleLogOut }) => {
29
32
  // Regardless of whether we logged out or not, session validation is now complete
30
33
  setLoadingAndLifecycle({ sessionValidation: true });
31
34
  }), [logout, environmentId]);
32
- useEffectOnce(() => {
33
- validateSession();
35
+ useEffect(() => {
36
+ if (didRunRef.current || !projectSettings)
37
+ return;
38
+ didRunRef.current = true;
39
+ validateSession(projectSettings);
40
+ }, [validateSession, projectSettings]);
41
+ useInternalDynamicEvents('triggerSessionValidation', () => {
42
+ if (!projectSettings)
43
+ return;
44
+ validateSession(projectSettings);
34
45
  });
35
- useInternalDynamicEvents('triggerSessionValidation', validateSession);
36
46
  };
37
47
 
38
48
  export { useValidateSession };
@@ -57,7 +57,6 @@ require('../../../CollectUserDataView/useFields.cjs');
57
57
  require('../../../../context/FieldsStateContext/FieldsStateContext.cjs');
58
58
  require('../../../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
59
59
  require('@dynamic-labs/rpc-providers');
60
- var useEffectOnce = require('../../../../utils/hooks/useEffectOnce/useEffectOnce.cjs');
61
60
  require('../../../../store/state/loadingAndLifecycle.cjs');
62
61
  require('@dynamic-labs/store');
63
62
  require('../../../../store/state/walletOptions/walletOptions.cjs');
@@ -81,6 +80,7 @@ var ModalHeader = require('../../../../components/ModalHeader/ModalHeader.cjs');
81
80
  require('../../../../store/state/sendBalances.cjs');
82
81
  require('../../../../components/Input/Input.cjs');
83
82
  require('../../../../components/OverlayCard/OverlayCard.cjs');
83
+ var useEffectOnce = require('../../../../utils/hooks/useEffectOnce/useEffectOnce.cjs');
84
84
  require('../../../TransactionConfirmationView/TransactionConfirmationView.cjs');
85
85
  require('../../../../context/PasskeyContext/PasskeyContext.cjs');
86
86
  require('../../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs');
@@ -53,7 +53,6 @@ import '../../../CollectUserDataView/useFields.js';
53
53
  import '../../../../context/FieldsStateContext/FieldsStateContext.js';
54
54
  import '../../../../context/UserFieldEditorContext/UserFieldEditorContext.js';
55
55
  import '@dynamic-labs/rpc-providers';
56
- import { useEffectOnce } from '../../../../utils/hooks/useEffectOnce/useEffectOnce.js';
57
56
  import '../../../../store/state/loadingAndLifecycle.js';
58
57
  import '@dynamic-labs/store';
59
58
  import '../../../../store/state/walletOptions/walletOptions.js';
@@ -77,6 +76,7 @@ import { ModalHeader } from '../../../../components/ModalHeader/ModalHeader.js';
77
76
  import '../../../../store/state/sendBalances.js';
78
77
  import '../../../../components/Input/Input.js';
79
78
  import '../../../../components/OverlayCard/OverlayCard.js';
79
+ import { useEffectOnce } from '../../../../utils/hooks/useEffectOnce/useEffectOnce.js';
80
80
  import '../../../TransactionConfirmationView/TransactionConfirmationView.js';
81
81
  import '../../../../context/PasskeyContext/PasskeyContext.js';
82
82
  import '../../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js';
@@ -55,7 +55,6 @@ require('../CollectUserDataView/useFields.cjs');
55
55
  require('../../context/FieldsStateContext/FieldsStateContext.cjs');
56
56
  require('../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
57
57
  require('@dynamic-labs/rpc-providers');
58
- var useEffectOnce = require('../../utils/hooks/useEffectOnce/useEffectOnce.cjs');
59
58
  require('../../store/state/loadingAndLifecycle.cjs');
60
59
  require('@dynamic-labs/store');
61
60
  require('../../store/state/walletOptions/walletOptions.cjs');
@@ -80,6 +79,7 @@ require('qrcode');
80
79
  var useFetchCurrency = require('../../widgets/DynamicWidget/hooks/useFetchCurrency/useFetchCurrency.cjs');
81
80
  require('formik');
82
81
  require('../../utils/hooks/useSubdomainCheck/useSubdomainCheck.cjs');
82
+ var useEffectOnce = require('../../utils/hooks/useEffectOnce/useEffectOnce.cjs');
83
83
  require('../../context/WalletGroupContext/WalletGroupContext.cjs');
84
84
  require('../../context/IpConfigurationContext/IpConfigurationContext.cjs');
85
85
  require('../../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs');
@@ -51,7 +51,6 @@ import '../CollectUserDataView/useFields.js';
51
51
  import '../../context/FieldsStateContext/FieldsStateContext.js';
52
52
  import '../../context/UserFieldEditorContext/UserFieldEditorContext.js';
53
53
  import '@dynamic-labs/rpc-providers';
54
- import { useEffectOnce } from '../../utils/hooks/useEffectOnce/useEffectOnce.js';
55
54
  import '../../store/state/loadingAndLifecycle.js';
56
55
  import '@dynamic-labs/store';
57
56
  import '../../store/state/walletOptions/walletOptions.js';
@@ -76,6 +75,7 @@ import 'qrcode';
76
75
  import { useFetchCurrency } from '../../widgets/DynamicWidget/hooks/useFetchCurrency/useFetchCurrency.js';
77
76
  import 'formik';
78
77
  import '../../utils/hooks/useSubdomainCheck/useSubdomainCheck.js';
78
+ import { useEffectOnce } from '../../utils/hooks/useEffectOnce/useEffectOnce.js';
79
79
  import '../../context/WalletGroupContext/WalletGroupContext.js';
80
80
  import '../../context/IpConfigurationContext/IpConfigurationContext.js';
81
81
  import '../../context/ConnectWithOtpContext/ConnectWithOtpContext.js';
@@ -55,7 +55,6 @@ require('../CollectUserDataView/useFields.cjs');
55
55
  require('../../context/FieldsStateContext/FieldsStateContext.cjs');
56
56
  require('../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
57
57
  require('@dynamic-labs/rpc-providers');
58
- var useEffectOnce = require('../../utils/hooks/useEffectOnce/useEffectOnce.cjs');
59
58
  require('../../store/state/loadingAndLifecycle.cjs');
60
59
  require('@dynamic-labs/store');
61
60
  require('../../store/state/walletOptions/walletOptions.cjs');
@@ -80,6 +79,7 @@ require('qrcode');
80
79
  require('formik');
81
80
  require('../../utils/hooks/useSubdomainCheck/useSubdomainCheck.cjs');
82
81
  var DefaultFooter = require('../../layout/DynamicAuthLayout/DefaultFooter/DefaultFooter.cjs');
82
+ var useEffectOnce = require('../../utils/hooks/useEffectOnce/useEffectOnce.cjs');
83
83
  var useWalletList = require('../../utils/hooks/useWalletList/useWalletList.cjs');
84
84
  var SearchNotFoundMessage = require('./SearchNotFoundMessage/SearchNotFoundMessage.cjs');
85
85
  var WalletListGridTabs = require('./WalletListGridTabs/WalletListGridTabs.cjs');
@@ -51,7 +51,6 @@ import '../CollectUserDataView/useFields.js';
51
51
  import '../../context/FieldsStateContext/FieldsStateContext.js';
52
52
  import '../../context/UserFieldEditorContext/UserFieldEditorContext.js';
53
53
  import '@dynamic-labs/rpc-providers';
54
- import { useEffectOnce } from '../../utils/hooks/useEffectOnce/useEffectOnce.js';
55
54
  import '../../store/state/loadingAndLifecycle.js';
56
55
  import '@dynamic-labs/store';
57
56
  import '../../store/state/walletOptions/walletOptions.js';
@@ -76,6 +75,7 @@ import 'qrcode';
76
75
  import 'formik';
77
76
  import '../../utils/hooks/useSubdomainCheck/useSubdomainCheck.js';
78
77
  import { DefaultFooter } from '../../layout/DynamicAuthLayout/DefaultFooter/DefaultFooter.js';
78
+ import { useEffectOnce } from '../../utils/hooks/useEffectOnce/useEffectOnce.js';
79
79
  import { useWalletList } from '../../utils/hooks/useWalletList/useWalletList.js';
80
80
  import { SearchNotFoundMessage } from './SearchNotFoundMessage/SearchNotFoundMessage.js';
81
81
  import { WalletListGridTabs } from './WalletListGridTabs/WalletListGridTabs.js';
@@ -56,7 +56,6 @@ require('../../../../views/CollectUserDataView/useFields.cjs');
56
56
  require('../../../../context/FieldsStateContext/FieldsStateContext.cjs');
57
57
  require('../../../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
58
58
  require('@dynamic-labs/rpc-providers');
59
- var useEffectOnce = require('../../../../utils/hooks/useEffectOnce/useEffectOnce.cjs');
60
59
  require('../../../../store/state/loadingAndLifecycle.cjs');
61
60
  require('@dynamic-labs/store');
62
61
  require('../../../../store/state/walletOptions/walletOptions.cjs');
@@ -80,6 +79,7 @@ var ModalHeader = require('../../../../components/ModalHeader/ModalHeader.cjs');
80
79
  require('../../../../store/state/sendBalances.cjs');
81
80
  require('../../../../components/Input/Input.cjs');
82
81
  require('../../../../components/OverlayCard/OverlayCard.cjs');
82
+ var useEffectOnce = require('../../../../utils/hooks/useEffectOnce/useEffectOnce.cjs');
83
83
  require('../../../../views/TransactionConfirmationView/TransactionConfirmationView.cjs');
84
84
  require('../../../../context/PasskeyContext/PasskeyContext.cjs');
85
85
  require('../ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs');
@@ -52,7 +52,6 @@ import '../../../../views/CollectUserDataView/useFields.js';
52
52
  import '../../../../context/FieldsStateContext/FieldsStateContext.js';
53
53
  import '../../../../context/UserFieldEditorContext/UserFieldEditorContext.js';
54
54
  import '@dynamic-labs/rpc-providers';
55
- import { useEffectOnce } from '../../../../utils/hooks/useEffectOnce/useEffectOnce.js';
56
55
  import '../../../../store/state/loadingAndLifecycle.js';
57
56
  import '@dynamic-labs/store';
58
57
  import '../../../../store/state/walletOptions/walletOptions.js';
@@ -76,6 +75,7 @@ import { ModalHeader } from '../../../../components/ModalHeader/ModalHeader.js';
76
75
  import '../../../../store/state/sendBalances.js';
77
76
  import '../../../../components/Input/Input.js';
78
77
  import '../../../../components/OverlayCard/OverlayCard.js';
78
+ import { useEffectOnce } from '../../../../utils/hooks/useEffectOnce/useEffectOnce.js';
79
79
  import '../../../../views/TransactionConfirmationView/TransactionConfirmationView.js';
80
80
  import '../../../../context/PasskeyContext/PasskeyContext.js';
81
81
  import '../ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js';
@@ -1,24 +0,0 @@
1
- 'use client'
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var utils = require('@dynamic-labs/utils');
7
- var localStorage = require('../../../../utils/constants/localStorage.cjs');
8
-
9
- const clearExpiredData = (store) => {
10
- const { projectSettings, user } = store.getState();
11
- // TODO: we can clean this up once we move wallet info to the store
12
- const [connectedWalletData] = utils.StorageService.getItem(localStorage.CONNECTED_WALLETS_INFO) || [];
13
- const shouldRemoveSettingsAndConfigs = !user && !connectedWalletData;
14
- const isExpired = (value) => shouldRemoveSettingsAndConfigs ||
15
- (value.expiresAt && value.expiresAt < Date.now());
16
- if (isExpired(projectSettings)) {
17
- store.setState({
18
- projectSettings: store.getInitialState().projectSettings,
19
- });
20
- }
21
- return store;
22
- };
23
-
24
- exports.clearExpiredData = clearExpiredData;
@@ -1,3 +0,0 @@
1
- import { StoreApi } from '@dynamic-labs/store';
2
- import { SdkStore } from '../../../types';
3
- export declare const clearExpiredData: (store: StoreApi<SdkStore>) => StoreApi<SdkStore>;
@@ -1,20 +0,0 @@
1
- 'use client'
2
- import { StorageService } from '@dynamic-labs/utils';
3
- import { CONNECTED_WALLETS_INFO } from '../../../../utils/constants/localStorage.js';
4
-
5
- const clearExpiredData = (store) => {
6
- const { projectSettings, user } = store.getState();
7
- // TODO: we can clean this up once we move wallet info to the store
8
- const [connectedWalletData] = StorageService.getItem(CONNECTED_WALLETS_INFO) || [];
9
- const shouldRemoveSettingsAndConfigs = !user && !connectedWalletData;
10
- const isExpired = (value) => shouldRemoveSettingsAndConfigs ||
11
- (value.expiresAt && value.expiresAt < Date.now());
12
- if (isExpired(projectSettings)) {
13
- store.setState({
14
- projectSettings: store.getInitialState().projectSettings,
15
- });
16
- }
17
- return store;
18
- };
19
-
20
- export { clearExpiredData };
@@ -1 +0,0 @@
1
- export { clearExpiredData } from './clearExpiredData';