@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.
- package/CHANGELOG.md +33 -0
- package/package.cjs +2 -2
- package/package.js +2 -2
- package/package.json +9 -9
- package/src/index.cjs +2 -0
- package/src/index.js +1 -0
- package/src/lib/Main.cjs +45 -6
- package/src/lib/Main.js +45 -6
- package/src/lib/assets/no-wallet-found.cjs +8 -8
- package/src/lib/assets/no-wallet-found.js +8 -8
- package/src/lib/components/LogoutButton/LogoutButton.cjs +17 -3
- package/src/lib/components/LogoutButton/LogoutButton.js +17 -3
- package/src/lib/components/PoweredByDynamic/PoweredByDynamic.cjs +9 -1
- package/src/lib/components/PoweredByDynamic/PoweredByDynamic.js +9 -1
- package/src/lib/components/SendBalancePageLayout/SendBalancePageLayout.cjs +1 -1
- package/src/lib/components/SendBalancePageLayout/SendBalancePageLayout.js +1 -1
- package/src/lib/components/Toolkit/Toolkit.cjs +3 -3
- package/src/lib/components/Toolkit/Toolkit.js +3 -3
- package/src/lib/components/Toolkit/components/MultiWalletSwitch.cjs +18 -0
- package/src/lib/components/Toolkit/components/MultiWalletSwitch.d.ts +8 -0
- package/src/lib/components/Toolkit/components/MultiWalletSwitch.js +14 -0
- package/src/lib/components/Toolkit/components/index.d.ts +1 -1
- package/src/lib/components/TransactionConfirmationPageLayout/TransactionConfirmationPageLayout.cjs +1 -1
- package/src/lib/components/TransactionConfirmationPageLayout/TransactionConfirmationPageLayout.js +1 -1
- package/src/lib/components/TransactionStatusLayout/TransactionStatusLayout.cjs +1 -1
- package/src/lib/components/TransactionStatusLayout/TransactionStatusLayout.js +1 -1
- package/src/lib/context/DynamicContext/DynamicContext.cjs +42 -12
- package/src/lib/context/DynamicContext/DynamicContext.d.ts +5 -1
- package/src/lib/context/DynamicContext/DynamicContext.js +43 -14
- package/src/lib/context/DynamicContext/helpers.cjs +5 -4
- package/src/lib/context/DynamicContext/helpers.d.ts +3 -1
- package/src/lib/context/DynamicContext/helpers.js +5 -4
- package/src/lib/context/DynamicContext/useCustomerCallbacks/types.d.ts +1 -0
- package/src/lib/context/DynamicContext/useCustomerCallbacks/useCustomerCallbacks.cjs +1 -1
- package/src/lib/context/DynamicContext/useCustomerCallbacks/useCustomerCallbacks.d.ts +2 -2
- package/src/lib/context/DynamicContext/useCustomerCallbacks/useCustomerCallbacks.js +1 -1
- package/src/lib/shared/types/index.d.ts +1 -0
- package/src/lib/shared/utils/classes/storage/localStorage.cjs +36 -24
- package/src/lib/shared/utils/classes/storage/localStorage.d.ts +16 -3
- package/src/lib/shared/utils/classes/storage/localStorage.js +37 -25
- package/src/lib/shared/utils/hooks/index.d.ts +1 -0
- package/src/lib/shared/utils/hooks/useEffectOnce/index.d.ts +1 -0
- package/src/lib/shared/utils/hooks/useEffectOnce/useEffectOnce.cjs +27 -0
- package/src/lib/shared/utils/hooks/useEffectOnce/useEffectOnce.d.ts +17 -0
- package/src/lib/shared/utils/hooks/useEffectOnce/useEffectOnce.js +23 -0
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/functions/getAuthToken/getAuthToken.cjs +2 -1
- package/src/lib/utils/functions/getAuthToken/getAuthToken.d.ts +1 -1
- package/src/lib/utils/functions/getAuthToken/getAuthToken.js +2 -1
- package/src/lib/utils/functions/storeAuthToken/index.cjs +1 -3
- package/src/lib/utils/functions/storeAuthToken/index.js +1 -3
- package/src/lib/utils/hooks/index.d.ts +2 -0
- package/src/lib/utils/hooks/multiWallet/useMultiWallet/index.d.ts +1 -0
- package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.cjs +17 -0
- package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.d.ts +8 -0
- package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.js +13 -0
- package/src/lib/utils/hooks/useApplyWalletConnectorNetwork/useApplyWalletConnectorNetwork.cjs +29 -0
- package/src/lib/utils/hooks/useApplyWalletConnectorNetwork/useApplyWalletConnectorNetwork.d.ts +5 -0
- package/src/lib/utils/hooks/useApplyWalletConnectorNetwork/useApplyWalletConnectorNetwork.js +25 -0
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.cjs +20 -5
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.d.ts +5 -2
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.js +20 -5
- package/src/lib/utils/hooks/useConnectedAccountWallet/useConnectedAccountWallet.cjs +11 -18
- package/src/lib/utils/hooks/useConnectedAccountWallet/useConnectedAccountWallet.js +11 -18
- package/src/lib/utils/hooks/useEventListener/index.d.ts +1 -0
- package/src/lib/utils/hooks/useEventListener/useEventListener.cjs +25 -0
- package/src/lib/utils/hooks/useEventListener/useEventListener.d.ts +1 -0
- package/src/lib/utils/hooks/useEventListener/useEventListener.js +21 -0
- package/src/lib/utils/hooks/usePromise/usePromise.cjs +71 -18
- package/src/lib/utils/hooks/usePromise/usePromise.d.ts +14 -0
- package/src/lib/utils/hooks/usePromise/usePromise.js +72 -19
- package/src/lib/views/EmailConfirmationWaitingView/EmailConfirmationWaitingView.cjs +1 -1
- package/src/lib/views/EmailConfirmationWaitingView/EmailConfirmationWaitingView.js +1 -1
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.cjs +9 -8
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.js +9 -8
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.cjs +5 -9
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.js +5 -9
- package/src/lib/views/NoAccess/useNoAccessText.cjs +1 -1
- package/src/lib/views/NoAccess/useNoAccessText.js +1 -1
- package/src/lib/views/WalletList/SearchNotFoundMessage/SearchNotFoundMessage.cjs +2 -1
- package/src/lib/views/WalletList/SearchNotFoundMessage/SearchNotFoundMessage.d.ts +2 -2
- package/src/lib/views/WalletList/SearchNotFoundMessage/SearchNotFoundMessage.js +2 -1
- package/src/lib/views/WalletList/WalletList.cjs +1 -1
- package/src/lib/views/WalletList/WalletList.js +1 -1
- package/src/lib/components/Toolkit/components/BrandStyleSwitch.cjs +0 -22
- package/src/lib/components/Toolkit/components/BrandStyleSwitch.d.ts +0 -2
- 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
|
-
|
|
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(
|
|
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
|
|
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(
|
|
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';
|
|
@@ -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(() => {
|
|
@@ -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
|
-
|
|
20
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
44
|
-
return JSON.parse(value);
|
|
45
|
-
}
|
|
44
|
+
return JSON.parse(value);
|
|
46
45
|
}
|
|
47
|
-
catch (
|
|
48
|
-
logger.logger.
|
|
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
|
-
|
|
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
|
-
|
|
7
|
-
|
|
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
|
-
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
40
|
-
return JSON.parse(value);
|
|
41
|
-
}
|
|
40
|
+
return JSON.parse(value);
|
|
42
41
|
}
|
|
43
|
-
catch (
|
|
44
|
-
logger.
|
|
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
|
-
|
|
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 };
|