@dynamic-labs/sdk-react-core 0.18.0-RC.14 → 0.18.0-RC.16

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 (88) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/package.cjs +2 -2
  3. package/package.js +2 -2
  4. package/package.json +9 -9
  5. package/src/index.cjs +2 -0
  6. package/src/index.js +1 -0
  7. package/src/lib/Main.cjs +45 -6
  8. package/src/lib/Main.js +45 -6
  9. package/src/lib/assets/no-wallet-found.cjs +8 -8
  10. package/src/lib/assets/no-wallet-found.js +8 -8
  11. package/src/lib/components/LogoutButton/LogoutButton.cjs +17 -3
  12. package/src/lib/components/LogoutButton/LogoutButton.js +17 -3
  13. package/src/lib/components/PoweredByDynamic/PoweredByDynamic.cjs +9 -1
  14. package/src/lib/components/PoweredByDynamic/PoweredByDynamic.js +9 -1
  15. package/src/lib/components/SendBalancePageLayout/SendBalancePageLayout.cjs +1 -1
  16. package/src/lib/components/SendBalancePageLayout/SendBalancePageLayout.js +1 -1
  17. package/src/lib/components/Toolkit/Toolkit.cjs +3 -3
  18. package/src/lib/components/Toolkit/Toolkit.js +3 -3
  19. package/src/lib/components/Toolkit/components/MultiWalletSwitch.cjs +18 -0
  20. package/src/lib/components/Toolkit/components/MultiWalletSwitch.d.ts +8 -0
  21. package/src/lib/components/Toolkit/components/MultiWalletSwitch.js +14 -0
  22. package/src/lib/components/Toolkit/components/index.d.ts +1 -1
  23. package/src/lib/components/TransactionConfirmationPageLayout/TransactionConfirmationPageLayout.cjs +1 -1
  24. package/src/lib/components/TransactionConfirmationPageLayout/TransactionConfirmationPageLayout.js +1 -1
  25. package/src/lib/components/TransactionStatusLayout/TransactionStatusLayout.cjs +1 -1
  26. package/src/lib/components/TransactionStatusLayout/TransactionStatusLayout.js +1 -1
  27. package/src/lib/context/DynamicContext/DynamicContext.cjs +42 -12
  28. package/src/lib/context/DynamicContext/DynamicContext.d.ts +5 -1
  29. package/src/lib/context/DynamicContext/DynamicContext.js +43 -14
  30. package/src/lib/context/DynamicContext/helpers.cjs +5 -4
  31. package/src/lib/context/DynamicContext/helpers.d.ts +3 -1
  32. package/src/lib/context/DynamicContext/helpers.js +5 -4
  33. package/src/lib/context/DynamicContext/useCustomerCallbacks/types.d.ts +1 -0
  34. package/src/lib/context/DynamicContext/useCustomerCallbacks/useCustomerCallbacks.cjs +1 -1
  35. package/src/lib/context/DynamicContext/useCustomerCallbacks/useCustomerCallbacks.d.ts +2 -2
  36. package/src/lib/context/DynamicContext/useCustomerCallbacks/useCustomerCallbacks.js +1 -1
  37. package/src/lib/shared/types/index.d.ts +1 -0
  38. package/src/lib/shared/utils/classes/storage/localStorage.cjs +36 -24
  39. package/src/lib/shared/utils/classes/storage/localStorage.d.ts +16 -3
  40. package/src/lib/shared/utils/classes/storage/localStorage.js +37 -25
  41. package/src/lib/shared/utils/hooks/index.d.ts +1 -0
  42. package/src/lib/shared/utils/hooks/useEffectOnce/index.d.ts +1 -0
  43. package/src/lib/shared/utils/hooks/useEffectOnce/useEffectOnce.cjs +27 -0
  44. package/src/lib/shared/utils/hooks/useEffectOnce/useEffectOnce.d.ts +17 -0
  45. package/src/lib/shared/utils/hooks/useEffectOnce/useEffectOnce.js +23 -0
  46. package/src/lib/styles/index.shadow.cjs +1 -1
  47. package/src/lib/styles/index.shadow.js +1 -1
  48. package/src/lib/utils/functions/getAuthToken/getAuthToken.cjs +2 -1
  49. package/src/lib/utils/functions/getAuthToken/getAuthToken.d.ts +1 -1
  50. package/src/lib/utils/functions/getAuthToken/getAuthToken.js +2 -1
  51. package/src/lib/utils/functions/storeAuthToken/index.cjs +1 -3
  52. package/src/lib/utils/functions/storeAuthToken/index.js +1 -3
  53. package/src/lib/utils/hooks/index.d.ts +2 -0
  54. package/src/lib/utils/hooks/multiWallet/useMultiWallet/index.d.ts +1 -0
  55. package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.cjs +17 -0
  56. package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.d.ts +8 -0
  57. package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.js +13 -0
  58. package/src/lib/utils/hooks/useApplyWalletConnectorNetwork/useApplyWalletConnectorNetwork.cjs +29 -0
  59. package/src/lib/utils/hooks/useApplyWalletConnectorNetwork/useApplyWalletConnectorNetwork.d.ts +5 -0
  60. package/src/lib/utils/hooks/useApplyWalletConnectorNetwork/useApplyWalletConnectorNetwork.js +25 -0
  61. package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.cjs +20 -5
  62. package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.d.ts +5 -2
  63. package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.js +20 -5
  64. package/src/lib/utils/hooks/useConnectedAccountWallet/useConnectedAccountWallet.cjs +11 -18
  65. package/src/lib/utils/hooks/useConnectedAccountWallet/useConnectedAccountWallet.js +11 -18
  66. package/src/lib/utils/hooks/useEventListener/index.d.ts +1 -0
  67. package/src/lib/utils/hooks/useEventListener/useEventListener.cjs +25 -0
  68. package/src/lib/utils/hooks/useEventListener/useEventListener.d.ts +1 -0
  69. package/src/lib/utils/hooks/useEventListener/useEventListener.js +21 -0
  70. package/src/lib/utils/hooks/usePromise/usePromise.cjs +71 -18
  71. package/src/lib/utils/hooks/usePromise/usePromise.d.ts +14 -0
  72. package/src/lib/utils/hooks/usePromise/usePromise.js +72 -19
  73. package/src/lib/views/EmailConfirmationWaitingView/EmailConfirmationWaitingView.cjs +1 -1
  74. package/src/lib/views/EmailConfirmationWaitingView/EmailConfirmationWaitingView.js +1 -1
  75. package/src/lib/views/NetworkNotSupported/NetworkNotSupported.cjs +9 -8
  76. package/src/lib/views/NetworkNotSupported/NetworkNotSupported.js +9 -8
  77. package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.cjs +5 -9
  78. package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.js +5 -9
  79. package/src/lib/views/NoAccess/useNoAccessText.cjs +1 -1
  80. package/src/lib/views/NoAccess/useNoAccessText.js +1 -1
  81. package/src/lib/views/WalletList/SearchNotFoundMessage/SearchNotFoundMessage.cjs +2 -1
  82. package/src/lib/views/WalletList/SearchNotFoundMessage/SearchNotFoundMessage.d.ts +2 -2
  83. package/src/lib/views/WalletList/SearchNotFoundMessage/SearchNotFoundMessage.js +2 -1
  84. package/src/lib/views/WalletList/WalletList.cjs +1 -1
  85. package/src/lib/views/WalletList/WalletList.js +1 -1
  86. package/src/lib/components/Toolkit/components/BrandStyleSwitch.cjs +0 -22
  87. package/src/lib/components/Toolkit/components/BrandStyleSwitch.d.ts +0 -2
  88. package/src/lib/components/Toolkit/components/BrandStyleSwitch.js +0 -18
@@ -12,8 +12,9 @@ require('../../shared/logger.cjs');
12
12
  require('@dynamic-labs/wallet-book');
13
13
  require('@dynamic-labs/utils');
14
14
  require('../../utils/constants/colors.cjs');
15
- var localStorage = require('../../shared/utils/classes/storage/localStorage.cjs');
15
+ require('../../shared/utils/classes/storage/localStorage.cjs');
16
16
  require('ethers');
17
+ var getAuthToken = require('../../utils/functions/getAuthToken/getAuthToken.cjs');
17
18
 
18
19
  let logoutTimer;
19
20
  const isAuthTokenExpired = (token) => {
@@ -32,7 +33,7 @@ const isAuthTokenExpired = (token) => {
32
33
  return false;
33
34
  };
34
35
  const initExpirationTime = (logout) => {
35
- const decodedJwt = decodeJwt.decodeJwt(localStorage.LocalStorage.getAuthTokenValue());
36
+ const decodedJwt = decodeJwt.decodeJwt(getAuthToken.getAuthToken());
36
37
  if (!decodedJwt)
37
38
  return clearTimeout(logoutTimer);
38
39
  const tokenExp = decodedJwt === null || decodedJwt === void 0 ? void 0 : decodedJwt.exp;
@@ -53,14 +54,14 @@ const initExpirationTime = (logout) => {
53
54
  const expiryTimeout = Math.min(expirationTimeInMs, 2147483647);
54
55
  logoutTimer = setTimeout(logout, expiryTimeout);
55
56
  };
56
- const getInitialView = ({ loginWithEmail, isBridgeFlow, isUserConnected, }) => {
57
+ const getInitialView = ({ connectedWallets, loginWithEmail, isBridgeFlow, isUserConnected, }) => {
57
58
  if (loginWithEmail) {
58
59
  return 'login-with-email-or-wallet';
59
60
  }
60
61
  if (isUserConnected) {
61
62
  return 'wallet-list';
62
63
  }
63
- if (isBridgeFlow) {
64
+ if (isBridgeFlow && !connectedWallets.length) {
64
65
  return 'bridge-welcome';
65
66
  }
66
67
  return 'wallet-list';
@@ -1,7 +1,9 @@
1
+ import { Wallet } from '../../shared';
1
2
  import { ViewType } from '../ViewContext';
2
3
  export declare const isAuthTokenExpired: (token: string) => boolean;
3
4
  export declare const initExpirationTime: (logout: VoidFunction) => void;
4
- export declare const getInitialView: ({ loginWithEmail, isBridgeFlow, isUserConnected, }: {
5
+ export declare const getInitialView: ({ connectedWallets, loginWithEmail, isBridgeFlow, isUserConnected, }: {
6
+ connectedWallets: Wallet[];
5
7
  loginWithEmail: boolean;
6
8
  isBridgeFlow: boolean;
7
9
  isUserConnected: boolean;
@@ -8,8 +8,9 @@ import '../../shared/logger.js';
8
8
  import '@dynamic-labs/wallet-book';
9
9
  import '@dynamic-labs/utils';
10
10
  import '../../utils/constants/colors.js';
11
- import { LocalStorage } from '../../shared/utils/classes/storage/localStorage.js';
11
+ import '../../shared/utils/classes/storage/localStorage.js';
12
12
  import 'ethers';
13
+ import { getAuthToken } from '../../utils/functions/getAuthToken/getAuthToken.js';
13
14
 
14
15
  let logoutTimer;
15
16
  const isAuthTokenExpired = (token) => {
@@ -28,7 +29,7 @@ const isAuthTokenExpired = (token) => {
28
29
  return false;
29
30
  };
30
31
  const initExpirationTime = (logout) => {
31
- const decodedJwt = decodeJwt(LocalStorage.getAuthTokenValue());
32
+ const decodedJwt = decodeJwt(getAuthToken());
32
33
  if (!decodedJwt)
33
34
  return clearTimeout(logoutTimer);
34
35
  const tokenExp = decodedJwt === null || decodedJwt === void 0 ? void 0 : decodedJwt.exp;
@@ -49,14 +50,14 @@ const initExpirationTime = (logout) => {
49
50
  const expiryTimeout = Math.min(expirationTimeInMs, 2147483647);
50
51
  logoutTimer = setTimeout(logout, expiryTimeout);
51
52
  };
52
- const getInitialView = ({ loginWithEmail, isBridgeFlow, isUserConnected, }) => {
53
+ const getInitialView = ({ connectedWallets, loginWithEmail, isBridgeFlow, isUserConnected, }) => {
53
54
  if (loginWithEmail) {
54
55
  return 'login-with-email-or-wallet';
55
56
  }
56
57
  if (isUserConnected) {
57
58
  return 'wallet-list';
58
59
  }
59
- if (isBridgeFlow) {
60
+ if (isBridgeFlow && !connectedWallets.length) {
60
61
  return 'bridge-welcome';
61
62
  }
62
63
  return 'wallet-list';
@@ -12,4 +12,5 @@ export type UseCustomerCallbacksArgs = {
12
12
  isAuthenticated: boolean;
13
13
  primaryWallet: Wallet | null;
14
14
  user: UserProfile | undefined;
15
+ connectedWallets: Wallet[];
15
16
  };
@@ -19,7 +19,7 @@ require('@dynamic-labs/multi-wallet');
19
19
  var getAuthToken = require('../../../utils/functions/getAuthToken/getAuthToken.cjs');
20
20
  var isConnectOnly = require('../../../utils/hooks/authenticationHooks/helpers/isConnectOnly.cjs');
21
21
 
22
- const useCustomerCallbacks = ({ callbacks: { onAuthSuccess, onLinkSuccess, onUserProfileUpdate, onConnectSuccess, }, handleLogOut, primaryWallet, user, isAuthenticated, authMode, }) => {
22
+ const useCustomerCallbacks = ({ callbacks: { onAuthSuccess, onLinkSuccess, onUserProfileUpdate, onConnectSuccess, }, handleLogOut, primaryWallet, user, isAuthenticated, authMode, connectedWallets, }) => {
23
23
  const [callbackQueue, setCallbackQueue] = React.useState([]);
24
24
  const isConnectOnlyAndCallbackIsConnectSuccess = React.useCallback((next) => isConnectOnly.isConnectOnly(user, authMode) && next === 'connectSuccess', [authMode, user]);
25
25
  React.useEffect(() => {
@@ -1,4 +1,4 @@
1
- import { Callback, UseCustomerCallbacksArgs } from './types';
2
- export declare const useCustomerCallbacks: ({ callbacks: { onAuthSuccess, onLinkSuccess, onUserProfileUpdate, onConnectSuccess, }, handleLogOut, primaryWallet, user, isAuthenticated, authMode, }: UseCustomerCallbacksArgs) => {
1
+ import type { Callback, UseCustomerCallbacksArgs } from './types';
2
+ export declare const useCustomerCallbacks: ({ callbacks: { onAuthSuccess, onLinkSuccess, onUserProfileUpdate, onConnectSuccess, }, handleLogOut, primaryWallet, user, isAuthenticated, authMode, connectedWallets, }: UseCustomerCallbacksArgs) => {
3
3
  setCallback: (callback: Callback) => void;
4
4
  };
@@ -15,7 +15,7 @@ import '@dynamic-labs/multi-wallet';
15
15
  import { getAuthToken } from '../../../utils/functions/getAuthToken/getAuthToken.js';
16
16
  import { isConnectOnly } from '../../../utils/hooks/authenticationHooks/helpers/isConnectOnly.js';
17
17
 
18
- const useCustomerCallbacks = ({ callbacks: { onAuthSuccess, onLinkSuccess, onUserProfileUpdate, onConnectSuccess, }, handleLogOut, primaryWallet, user, isAuthenticated, authMode, }) => {
18
+ const useCustomerCallbacks = ({ callbacks: { onAuthSuccess, onLinkSuccess, onUserProfileUpdate, onConnectSuccess, }, handleLogOut, primaryWallet, user, isAuthenticated, authMode, connectedWallets, }) => {
19
19
  const [callbackQueue, setCallbackQueue] = useState([]);
20
20
  const isConnectOnlyAndCallbackIsConnectSuccess = useCallback((next) => isConnectOnly(user, authMode) && next === 'connectSuccess', [authMode, user]);
21
21
  useEffect(() => {
@@ -10,6 +10,7 @@ export type Wallet = {
10
10
  connected: boolean;
11
11
  connector: WalletConnector;
12
12
  id: string;
13
+ network?: string | number;
13
14
  };
14
15
  export type WalletAction = 'select' | 'unlink';
15
16
  export type WalletWithAction = {
@@ -6,46 +6,50 @@ var localStorage = require('../../../../utils/constants/localStorage.cjs');
6
6
  require('../../../../utils/constants/colors.cjs');
7
7
  var logger = require('../../../logger.cjs');
8
8
 
9
+ const connectedKeys = {
10
+ [localStorage.AUTH_TOKEN]: [localStorage.AUTH_USER],
11
+ [localStorage.AUTH_USER]: [localStorage.AUTH_TOKEN],
12
+ };
9
13
  class LocalStorage {
10
14
  static getDynamicLSKey(key) {
11
15
  return `${key}${LocalStorage.getSuffix()}`;
12
16
  }
17
+ static validateRequest(key, fromAuxiliarAuthFunctions) {
18
+ if (key === localStorage.AUTH_TOKEN && !fromAuxiliarAuthFunctions) {
19
+ throw new Error('You cannot access AUTH_TOKEN through localStorage. Use getAuthToken/ storeAuthToken helper functions instead');
20
+ }
21
+ }
13
22
  static setSuffix(localStorageSuffix) {
14
23
  if (!LocalStorage.__suffix__) {
15
24
  const suffix = (localStorageSuffix && `_${localStorageSuffix}`) || '';
16
25
  LocalStorage.__suffix__ = suffix;
17
26
  }
18
27
  }
19
- // Will be refactored on INC-155
20
- static getAuthTokenValue() {
28
+ /**
29
+ *
30
+ * @param key
31
+ * @param getAuth - verifies if the request to get AUTH_TOKEN is comming from getAuthToken and not directly
32
+ * @returns
33
+ */
34
+ static getFromLS(key, getAuth = false) {
21
35
  if (typeof window === 'undefined') {
22
36
  return undefined;
23
37
  }
24
- const value = window.localStorage.getItem(LocalStorage.getDynamicLSKey(localStorage.AUTH_TOKEN));
25
- try {
26
- if (value) {
27
- return JSON.parse(value);
28
- }
29
- }
30
- catch (e) {
31
- logger.logger.debug(e);
32
- // Return auth token string for backwards compatibility
33
- return value || undefined;
34
- }
35
- return undefined;
36
- }
37
- static getFromLS(key) {
38
- if (typeof window === 'undefined') {
38
+ LocalStorage.validateRequest(key, getAuth);
39
+ const value = window.localStorage.getItem(LocalStorage.getDynamicLSKey(key));
40
+ if (!value) {
39
41
  return undefined;
40
42
  }
41
- const value = window.localStorage.getItem(LocalStorage.getDynamicLSKey(key));
42
43
  try {
43
- if (value) {
44
- return JSON.parse(value);
45
- }
44
+ return JSON.parse(value);
46
45
  }
47
- catch (e) {
48
- logger.logger.error(e);
46
+ catch (error) {
47
+ logger.logger.debug(`Error while parsing ${key} from local storage`, { value });
48
+ // keep it in case handleLogOut is not yet loaded when calling this method
49
+ [key]
50
+ .concat(connectedKeys[key] || [])
51
+ .forEach((_key) => LocalStorage.removeFromLS(_key));
52
+ window.dispatchEvent(new Event('logOut'));
49
53
  }
50
54
  return undefined;
51
55
  }
@@ -55,10 +59,18 @@ class LocalStorage {
55
59
  }
56
60
  return window.localStorage.removeItem(LocalStorage.getDynamicLSKey(key));
57
61
  }
58
- static setToLS(key, value) {
62
+ /**
63
+ *
64
+ * @param key
65
+ * @param value
66
+ * @param storeAuth - verifies if the request to get AUTH_TOKEN is comming from getAuthToken and not directly
67
+ * @returns
68
+ */
69
+ static setToLS(key, value, storeAuth = false) {
59
70
  if (typeof window === 'undefined') {
60
71
  return;
61
72
  }
73
+ LocalStorage.validateRequest(key, storeAuth);
62
74
  window.localStorage.setItem(LocalStorage.getDynamicLSKey(key), JSON.stringify(value));
63
75
  }
64
76
  static getKeys() {
@@ -2,11 +2,24 @@ export declare class LocalStorage {
2
2
  private static __suffix__;
3
3
  static getSuffix: () => string;
4
4
  private static getDynamicLSKey;
5
+ private static validateRequest;
5
6
  static setSuffix(localStorageSuffix?: string): void;
6
- static getAuthTokenValue(): string | undefined;
7
- static getFromLS<T = any>(key: string): T | undefined;
7
+ /**
8
+ *
9
+ * @param key
10
+ * @param getAuth - verifies if the request to get AUTH_TOKEN is comming from getAuthToken and not directly
11
+ * @returns
12
+ */
13
+ static getFromLS<T = any>(key: string, getAuth?: boolean): T | undefined;
8
14
  static removeFromLS(key: string): void;
9
- static setToLS<T = any>(key: string, value: T): void;
15
+ /**
16
+ *
17
+ * @param key
18
+ * @param value
19
+ * @param storeAuth - verifies if the request to get AUTH_TOKEN is comming from getAuthToken and not directly
20
+ * @returns
21
+ */
22
+ static setToLS<T = any>(key: string, value: T, storeAuth?: boolean): void;
10
23
  static getKeys(): string[];
11
24
  }
12
25
  export default LocalStorage;
@@ -1,47 +1,51 @@
1
- import { AUTH_TOKEN } from '../../../../utils/constants/localStorage.js';
1
+ import { AUTH_TOKEN, AUTH_USER } from '../../../../utils/constants/localStorage.js';
2
2
  import '../../../../utils/constants/colors.js';
3
3
  import { logger } from '../../../logger.js';
4
4
 
5
+ const connectedKeys = {
6
+ [AUTH_TOKEN]: [AUTH_USER],
7
+ [AUTH_USER]: [AUTH_TOKEN],
8
+ };
5
9
  class LocalStorage {
6
10
  static getDynamicLSKey(key) {
7
11
  return `${key}${LocalStorage.getSuffix()}`;
8
12
  }
13
+ static validateRequest(key, fromAuxiliarAuthFunctions) {
14
+ if (key === AUTH_TOKEN && !fromAuxiliarAuthFunctions) {
15
+ throw new Error('You cannot access AUTH_TOKEN through localStorage. Use getAuthToken/ storeAuthToken helper functions instead');
16
+ }
17
+ }
9
18
  static setSuffix(localStorageSuffix) {
10
19
  if (!LocalStorage.__suffix__) {
11
20
  const suffix = (localStorageSuffix && `_${localStorageSuffix}`) || '';
12
21
  LocalStorage.__suffix__ = suffix;
13
22
  }
14
23
  }
15
- // Will be refactored on INC-155
16
- static getAuthTokenValue() {
24
+ /**
25
+ *
26
+ * @param key
27
+ * @param getAuth - verifies if the request to get AUTH_TOKEN is comming from getAuthToken and not directly
28
+ * @returns
29
+ */
30
+ static getFromLS(key, getAuth = false) {
17
31
  if (typeof window === 'undefined') {
18
32
  return undefined;
19
33
  }
20
- const value = window.localStorage.getItem(LocalStorage.getDynamicLSKey(AUTH_TOKEN));
21
- try {
22
- if (value) {
23
- return JSON.parse(value);
24
- }
25
- }
26
- catch (e) {
27
- logger.debug(e);
28
- // Return auth token string for backwards compatibility
29
- return value || undefined;
30
- }
31
- return undefined;
32
- }
33
- static getFromLS(key) {
34
- if (typeof window === 'undefined') {
34
+ LocalStorage.validateRequest(key, getAuth);
35
+ const value = window.localStorage.getItem(LocalStorage.getDynamicLSKey(key));
36
+ if (!value) {
35
37
  return undefined;
36
38
  }
37
- const value = window.localStorage.getItem(LocalStorage.getDynamicLSKey(key));
38
39
  try {
39
- if (value) {
40
- return JSON.parse(value);
41
- }
40
+ return JSON.parse(value);
42
41
  }
43
- catch (e) {
44
- logger.error(e);
42
+ catch (error) {
43
+ logger.debug(`Error while parsing ${key} from local storage`, { value });
44
+ // keep it in case handleLogOut is not yet loaded when calling this method
45
+ [key]
46
+ .concat(connectedKeys[key] || [])
47
+ .forEach((_key) => LocalStorage.removeFromLS(_key));
48
+ window.dispatchEvent(new Event('logOut'));
45
49
  }
46
50
  return undefined;
47
51
  }
@@ -51,10 +55,18 @@ class LocalStorage {
51
55
  }
52
56
  return window.localStorage.removeItem(LocalStorage.getDynamicLSKey(key));
53
57
  }
54
- static setToLS(key, value) {
58
+ /**
59
+ *
60
+ * @param key
61
+ * @param value
62
+ * @param storeAuth - verifies if the request to get AUTH_TOKEN is comming from getAuthToken and not directly
63
+ * @returns
64
+ */
65
+ static setToLS(key, value, storeAuth = false) {
55
66
  if (typeof window === 'undefined') {
56
67
  return;
57
68
  }
69
+ LocalStorage.validateRequest(key, storeAuth);
58
70
  window.localStorage.setItem(LocalStorage.getDynamicLSKey(key), JSON.stringify(value));
59
71
  }
60
72
  static getKeys() {
@@ -3,3 +3,4 @@ export { useOnClickOutside } from './useOnClickOutside';
3
3
  export { usePreventPageScroll } from './usePreventPageScroll';
4
4
  export { useGlobalLoading } from './useGlobalLoading';
5
5
  export { useMediaQuery } from './useMediaQuery';
6
+ export { useEffectOnce } from './useEffectOnce';
@@ -0,0 +1 @@
1
+ export { useEffectOnce } from './useEffectOnce';
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+
7
+ /**
8
+ * Runs an effect function only once during component initialization.
9
+ *
10
+ * @param {Function} effect - The effect function to be executed.
11
+ * @returns {void}
12
+ *
13
+ * @example
14
+ * function ExampleComponent() {
15
+ * useEffectOnce(() => {
16
+ * console.log('Effect executed once');
17
+ * });
18
+ *
19
+ * return <div>Example Component</div>;
20
+ * }
21
+ */
22
+ const useEffectOnce = (effect) => {
23
+ // eslint-disable-next-line react-hooks/exhaustive-deps
24
+ React.useEffect(effect, []);
25
+ };
26
+
27
+ exports.useEffectOnce = useEffectOnce;
@@ -0,0 +1,17 @@
1
+ import { EffectCallback } from 'react';
2
+ /**
3
+ * Runs an effect function only once during component initialization.
4
+ *
5
+ * @param {Function} effect - The effect function to be executed.
6
+ * @returns {void}
7
+ *
8
+ * @example
9
+ * function ExampleComponent() {
10
+ * useEffectOnce(() => {
11
+ * console.log('Effect executed once');
12
+ * });
13
+ *
14
+ * return <div>Example Component</div>;
15
+ * }
16
+ */
17
+ export declare const useEffectOnce: (effect: EffectCallback) => void;
@@ -0,0 +1,23 @@
1
+ import { useEffect } from 'react';
2
+
3
+ /**
4
+ * Runs an effect function only once during component initialization.
5
+ *
6
+ * @param {Function} effect - The effect function to be executed.
7
+ * @returns {void}
8
+ *
9
+ * @example
10
+ * function ExampleComponent() {
11
+ * useEffectOnce(() => {
12
+ * console.log('Effect executed once');
13
+ * });
14
+ *
15
+ * return <div>Example Component</div>;
16
+ * }
17
+ */
18
+ const useEffectOnce = (effect) => {
19
+ // eslint-disable-next-line react-hooks/exhaustive-deps
20
+ useEffect(effect, []);
21
+ };
22
+
23
+ export { useEffectOnce };