@dynamic-labs/sdk-react-core 2.1.0-alpha.15 → 2.1.0-alpha.17

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 (102) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.cjs +3 -2
  3. package/package.js +3 -2
  4. package/package.json +13 -12
  5. package/src/index.cjs +0 -2
  6. package/src/index.d.ts +1 -3
  7. package/src/index.js +0 -1
  8. package/src/lib/components/Portal/Portal.cjs +3 -1
  9. package/src/lib/components/Portal/Portal.js +3 -1
  10. package/src/lib/context/DynamicContext/DynamicContext.cjs +20 -14
  11. package/src/lib/context/DynamicContext/DynamicContext.d.ts +2 -1
  12. package/src/lib/context/DynamicContext/DynamicContext.js +20 -14
  13. package/src/lib/context/DynamicContext/hooks/useHandleLogout/types.d.ts +0 -1
  14. package/src/lib/context/DynamicContext/hooks/useHandleLogout/useHandleLogout.cjs +5 -1
  15. package/src/lib/context/DynamicContext/hooks/useHandleLogout/useHandleLogout.js +5 -1
  16. package/src/lib/context/DynamicContext/types/index.d.ts +4 -1
  17. package/src/lib/context/DynamicContext/useDynamicContext/useDynamicContext.cjs +2 -1
  18. package/src/lib/context/DynamicContext/useDynamicContext/useDynamicContext.d.ts +1 -1
  19. package/src/lib/context/DynamicContext/useDynamicContext/useDynamicContext.js +2 -1
  20. package/src/lib/context/DynamicContext/validators/validators.cjs +0 -29
  21. package/src/lib/context/DynamicContext/validators/validators.d.ts +0 -2
  22. package/src/lib/context/DynamicContext/validators/validators.js +1 -29
  23. package/src/lib/context/ViewContext/types/index.d.ts +1 -1
  24. package/src/lib/locale/en/translation.cjs +18 -0
  25. package/src/lib/locale/en/translation.d.ts +18 -0
  26. package/src/lib/locale/en/translation.js +18 -0
  27. package/src/lib/shared/utils/classes/storage/localStorage.cjs +1 -8
  28. package/src/lib/shared/utils/classes/storage/localStorage.js +2 -9
  29. package/src/lib/shared/utils/functions/index.d.ts +0 -1
  30. package/src/lib/shared/utils/functions/wallet/createWallet.d.ts +0 -4
  31. package/src/lib/store/actions/storeActions/index.d.ts +1 -0
  32. package/src/lib/store/actions/storeActions/storeActions.cjs +10 -0
  33. package/src/lib/store/actions/storeActions/storeActions.d.ts +1 -0
  34. package/src/lib/store/actions/storeActions/storeActions.js +6 -0
  35. package/src/lib/store/actions/userActions/index.d.ts +1 -0
  36. package/src/lib/store/actions/userActions/userActions.cjs +10 -0
  37. package/src/lib/store/actions/userActions/userActions.d.ts +7 -0
  38. package/src/lib/store/actions/userActions/userActions.js +6 -0
  39. package/src/lib/store/hooks/useUser/index.d.ts +1 -0
  40. package/src/lib/store/hooks/useUser/useUser.cjs +12 -0
  41. package/src/lib/store/hooks/useUser/useUser.d.ts +1 -0
  42. package/src/lib/store/hooks/useUser/useUser.js +8 -0
  43. package/src/lib/store/index.d.ts +4 -0
  44. package/src/lib/store/store.cjs +24 -0
  45. package/src/lib/store/store.d.ts +13 -0
  46. package/src/lib/store/store.js +19 -0
  47. package/src/lib/store/types.d.ts +4 -0
  48. package/src/lib/store/utils/createStore/createStore.cjs +21 -0
  49. package/src/lib/store/utils/createStore/createStore.d.ts +16 -0
  50. package/src/lib/store/utils/createStore/createStore.js +17 -0
  51. package/src/lib/store/utils/createStore/index.d.ts +1 -0
  52. package/src/lib/store/utils/syncLegacyStorage/index.d.ts +1 -0
  53. package/src/lib/store/utils/syncLegacyStorage/syncLegacyStorage.cjs +30 -0
  54. package/src/lib/store/utils/syncLegacyStorage/syncLegacyStorage.d.ts +2 -0
  55. package/src/lib/store/utils/syncLegacyStorage/syncLegacyStorage.js +26 -0
  56. package/src/lib/styles/index.shadow.cjs +1 -1
  57. package/src/lib/styles/index.shadow.js +1 -1
  58. package/src/lib/utils/constants/index.d.ts +1 -1
  59. package/src/lib/utils/constants/localStorage.cjs +2 -2
  60. package/src/lib/utils/constants/localStorage.d.ts +1 -1
  61. package/src/lib/utils/constants/localStorage.js +2 -2
  62. package/src/lib/utils/functions/downloadFile/downloadFile.cjs +15 -0
  63. package/src/lib/utils/functions/downloadFile/downloadFile.d.ts +1 -0
  64. package/src/lib/utils/functions/downloadFile/downloadFile.js +11 -0
  65. package/src/lib/utils/functions/downloadFile/index.d.ts +1 -0
  66. package/src/lib/utils/functions/index.d.ts +1 -0
  67. package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs +4 -2
  68. package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +4 -2
  69. package/src/lib/utils/hooks/useDynamicLayoutData/useDynamicLayoutData.cjs +4 -0
  70. package/src/lib/utils/hooks/useDynamicLayoutData/useDynamicLayoutData.js +4 -0
  71. package/src/lib/utils/hooks/useHandleUnlinkWallet/useHandleUnlinkWallet.cjs +6 -3
  72. package/src/lib/utils/hooks/useHandleUnlinkWallet/useHandleUnlinkWallet.d.ts +1 -4
  73. package/src/lib/utils/hooks/useHandleUnlinkWallet/useHandleUnlinkWallet.js +5 -2
  74. package/src/lib/utils/hooks/usePrimaryWalletId/usePrimaryWalletId.cjs +6 -2
  75. package/src/lib/utils/hooks/usePrimaryWalletId/usePrimaryWalletId.d.ts +1 -4
  76. package/src/lib/utils/hooks/usePrimaryWalletId/usePrimaryWalletId.js +5 -1
  77. package/src/lib/utils/hooks/useWalletConnectorOptions/useWalletConnectorOptions.cjs +2 -1
  78. package/src/lib/utils/hooks/useWalletConnectorOptions/useWalletConnectorOptions.d.ts +3 -2
  79. package/src/lib/utils/hooks/useWalletConnectorOptions/useWalletConnectorOptions.js +2 -1
  80. package/src/lib/views/CreatePasswordView/SavePasswordStep/SavePasswordStep.cjs +5 -10
  81. package/src/lib/views/CreatePasswordView/SavePasswordStep/SavePasswordStep.js +5 -10
  82. package/src/lib/views/MfaDisplayBackupCodesView/MfaDisplayBackupCodesView.cjs +111 -0
  83. package/src/lib/views/MfaDisplayBackupCodesView/MfaDisplayBackupCodesView.d.ts +2 -0
  84. package/src/lib/views/MfaDisplayBackupCodesView/MfaDisplayBackupCodesView.js +107 -0
  85. package/src/lib/views/MfaDisplayBackupCodesView/index.d.ts +1 -0
  86. package/src/lib/views/MfaVerificationView/MfaVerificationView.cjs +3 -3
  87. package/src/lib/views/MfaVerificationView/MfaVerificationView.js +3 -3
  88. package/src/lib/views/WalletList/WalletListGridTabs/WalletListGridTabs.cjs +1 -1
  89. package/src/lib/views/WalletList/WalletListGridTabs/WalletListGridTabs.js +1 -1
  90. package/src/lib/views/WalletList/hooks/useTabState.cjs +4 -1
  91. package/src/lib/views/WalletList/hooks/useTabState.js +4 -1
  92. package/src/lib/views/WalletList/utils/getInitialTabIndex/getInitialTabIndex.cjs +22 -0
  93. package/src/lib/views/WalletList/utils/getInitialTabIndex/getInitialTabIndex.d.ts +2 -0
  94. package/src/lib/views/WalletList/utils/getInitialTabIndex/getInitialTabIndex.js +18 -0
  95. package/src/lib/views/WalletList/utils/getInitialTabIndex/index.d.ts +1 -0
  96. package/src/lib/views/viewToComponentMap.cjs +2 -0
  97. package/src/lib/views/viewToComponentMap.d.ts +1 -0
  98. package/src/lib/views/viewToComponentMap.js +2 -0
  99. package/src/lib/shared/utils/functions/validateType/index.d.ts +0 -1
  100. package/src/lib/shared/utils/functions/validateType/validateType.cjs +0 -30
  101. package/src/lib/shared/utils/functions/validateType/validateType.d.ts +0 -1
  102. package/src/lib/shared/utils/functions/validateType/validateType.js +0 -26
@@ -3,34 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- require('@dynamic-labs/sdk-api-core');
7
- require('../../../shared/logger.cjs');
8
- var validateType = require('../../../shared/utils/functions/validateType/validateType.cjs');
9
- require('@dynamic-labs/iconic');
10
- require('@dynamic-labs/wallet-connector-core');
11
- require('react/jsx-runtime');
12
- require('../../ViewContext/ViewContext.cjs');
13
- require('react');
14
- require('@dynamic-labs/wallet-book');
15
- require('../../../utils/constants/colors.cjs');
16
- require('../../../utils/constants/values.cjs');
17
- require('../../../shared/utils/classes/storage/localStorage.cjs');
18
- require('@dynamic-labs/utils');
19
- require('../../../shared/consts/index.cjs');
20
-
21
- // TODO: need validation for optional fields
22
- // https://linear.app/dynamic-labs/issue/DYN-1461
23
- const validateAuthUser = (data) => validateType.validateType(data, {
24
- environmentId: 'environmentId',
25
- lastVerifiedCredentialId: 'lastAuthenticatedAccountId',
26
- userId: 'userId',
27
- verifiedCredentials: [
28
- {
29
- format: 'format',
30
- id: 'id',
31
- },
32
- ],
33
- });
34
6
  const validateLocalStorageExpiry = (data) => {
35
7
  if (!data)
36
8
  return false;
@@ -41,5 +13,4 @@ const validateLocalStorageExpiry = (data) => {
41
13
  return true;
42
14
  };
43
15
 
44
- exports.validateAuthUser = validateAuthUser;
45
16
  exports.validateLocalStorageExpiry = validateLocalStorageExpiry;
@@ -1,4 +1,2 @@
1
- import { UserProfile } from '@dynamic-labs/types';
2
1
  import { LocalStorageNetworks, LocalStorageNonce, LocalStorageSettings } from '../../../shared';
3
- export declare const validateAuthUser: (data: UserProfile | undefined) => boolean;
4
2
  export declare const validateLocalStorageExpiry: (data: LocalStorageNonce | LocalStorageNetworks | LocalStorageSettings | undefined) => boolean;
@@ -1,32 +1,4 @@
1
1
  'use client'
2
- import '@dynamic-labs/sdk-api-core';
3
- import '../../../shared/logger.js';
4
- import { validateType } from '../../../shared/utils/functions/validateType/validateType.js';
5
- import '@dynamic-labs/iconic';
6
- import '@dynamic-labs/wallet-connector-core';
7
- import 'react/jsx-runtime';
8
- import '../../ViewContext/ViewContext.js';
9
- import 'react';
10
- import '@dynamic-labs/wallet-book';
11
- import '../../../utils/constants/colors.js';
12
- import '../../../utils/constants/values.js';
13
- import '../../../shared/utils/classes/storage/localStorage.js';
14
- import '@dynamic-labs/utils';
15
- import '../../../shared/consts/index.js';
16
-
17
- // TODO: need validation for optional fields
18
- // https://linear.app/dynamic-labs/issue/DYN-1461
19
- const validateAuthUser = (data) => validateType(data, {
20
- environmentId: 'environmentId',
21
- lastVerifiedCredentialId: 'lastAuthenticatedAccountId',
22
- userId: 'userId',
23
- verifiedCredentials: [
24
- {
25
- format: 'format',
26
- id: 'id',
27
- },
28
- ],
29
- });
30
2
  const validateLocalStorageExpiry = (data) => {
31
3
  if (!data)
32
4
  return false;
@@ -37,4 +9,4 @@ const validateLocalStorageExpiry = (data) => {
37
9
  return true;
38
10
  };
39
11
 
40
- export { validateAuthUser, validateLocalStorageExpiry };
12
+ export { validateLocalStorageExpiry };
@@ -1,6 +1,6 @@
1
1
  import { FC } from 'react';
2
2
  import { viewToComponentMap } from '../../../views/viewToComponentMap';
3
- export type ViewType = 'select-hardware-wallet' | 'captcha' | 'chainalysis-blocked-wallet' | 'collect-user-data' | 'collect-user-data-login-no-wallet' | 'login-with-email-or-wallet-full-wallet-list' | 'login-with-email-or-wallet' | 'login-with-wallet-only' | 'login-with-email-verification' | 'login-with-sms-verification' | 'network-not-supported' | 'network-not-supported-manual' | 'no-access' | 'no-qr-not-installed' | 'pending-connect' | 'pending-signature-without-back-button' | 'pending-signature' | 'qr-code' | 'update-email' | 'verify-email' | 'verify-sms' | 'wallet-connect-mobile-wallets-list' | 'wallet-list' | 'multi-wallet-wallet-list' | 'wallet-sign' | 'wallet-used' | 'wallet-group' | 'select-wallet-in-wallet-group' | 'wait-for-email-confirmation-view' | 'email-wallet-otp-verification-view' | 'social-redirect-view' | 'wallet-locked-view' | 'social-wrong-account' | 'gate-blocked-wallet' | 'bridge-welcome' | 'bridge-summary' | 'bridge-next-wallet-connection' | 'account-exists' | 'merge-user-accounts' | 'merge-user-accounts-conflicts' | 'merge-user-accounts-with-same-email' | 'mfa-choose-device' | 'mfa-secure-device' | 'mfa-verification' | 'wallet-cannot-be-transferred' | 'passkey-intro' | 'passkey-recovery-add-email' | 'passkey-recovery-start' | 'passkey-recovery-bundle' | 'passkey-recovery-complete' | 'passkey-new-domain-detected' | 'embedded-reveal-view' | 'embedded-reveal-account-view' | 'embedded-wallet-auth-choice' | 'rename-passkey' | 'wallet-redirect-view' | 'create-password-view' | 'wallet-claim-intro' | 'farcaster-connect-view';
3
+ export type ViewType = 'select-hardware-wallet' | 'captcha' | 'chainalysis-blocked-wallet' | 'collect-user-data' | 'collect-user-data-login-no-wallet' | 'login-with-email-or-wallet-full-wallet-list' | 'login-with-email-or-wallet' | 'login-with-wallet-only' | 'login-with-email-verification' | 'login-with-sms-verification' | 'network-not-supported' | 'network-not-supported-manual' | 'no-access' | 'no-qr-not-installed' | 'pending-connect' | 'pending-signature-without-back-button' | 'pending-signature' | 'qr-code' | 'update-email' | 'verify-email' | 'verify-sms' | 'wallet-connect-mobile-wallets-list' | 'wallet-list' | 'multi-wallet-wallet-list' | 'wallet-sign' | 'wallet-used' | 'wallet-group' | 'select-wallet-in-wallet-group' | 'wait-for-email-confirmation-view' | 'email-wallet-otp-verification-view' | 'social-redirect-view' | 'wallet-locked-view' | 'social-wrong-account' | 'gate-blocked-wallet' | 'bridge-welcome' | 'bridge-summary' | 'bridge-next-wallet-connection' | 'account-exists' | 'merge-user-accounts' | 'merge-user-accounts-conflicts' | 'merge-user-accounts-with-same-email' | 'mfa-choose-device' | 'mfa-secure-device' | 'mfa-verification' | 'mfa-display-backup-codes' | 'wallet-cannot-be-transferred' | 'passkey-intro' | 'passkey-recovery-add-email' | 'passkey-recovery-start' | 'passkey-recovery-bundle' | 'passkey-recovery-complete' | 'passkey-new-domain-detected' | 'embedded-reveal-view' | 'embedded-reveal-account-view' | 'embedded-wallet-auth-choice' | 'rename-passkey' | 'wallet-redirect-view' | 'create-password-view' | 'wallet-claim-intro' | 'farcaster-connect-view';
4
4
  export type ViewMapConstraint = Record<ViewType, FC<any>>;
5
5
  type ComponentProps<T extends FC<any>> = T extends FC<infer P> ? P : never;
6
6
  export type ViewMap = typeof viewToComponentMap;
@@ -846,6 +846,15 @@ const translation = {
846
846
  sms_code_description:
847
847
  'Use your preferred authenticator app such as Authy, Google Authenticator, etc.',
848
848
  },
849
+ display_backup_codes_view: {
850
+ title: 'Back up your codes',
851
+ body: 'Backup codes help recover your account if you lose access to your device.',
852
+ warning: 'You won’t be able to see these again',
853
+ copy_all: 'Copy all',
854
+ download: 'Download',
855
+ checkbox: 'I have safely stored a copy of my password',
856
+ complete: 'Complete',
857
+ },
849
858
  otp_verification_view: {
850
859
  title: 'Confirm verification code',
851
860
  body: 'Enter the verification code generated by your authenticator app',
@@ -867,6 +876,15 @@ const translation = {
867
876
  sms_code: 'SMS code',
868
877
  sms_code_description: 'Use your preferred authenticator app such as Authy, Google Authenticator, etc.',
869
878
  },
879
+ display_backup_codes_view: {
880
+ title: 'Back up your codes',
881
+ body: 'Backup codes help recover your account if you lose access to your device.',
882
+ warning: 'You won’t be able to see these again',
883
+ copy_all: 'Copy all',
884
+ download: 'Download',
885
+ checkbox: 'I have safely stored a copy of my password',
886
+ complete: 'Complete',
887
+ },
870
888
  otp_verification_view: {
871
889
  title: 'Confirm verification code',
872
890
  body: 'Enter the verification code generated by your authenticator app',
@@ -842,6 +842,15 @@ export declare const translation: {
842
842
  sms_code_description:
843
843
  'Use your preferred authenticator app such as Authy, Google Authenticator, etc.',
844
844
  },
845
+ display_backup_codes_view: {
846
+ title: 'Back up your codes',
847
+ body: 'Backup codes help recover your account if you lose access to your device.',
848
+ warning: 'You won’t be able to see these again',
849
+ copy_all: 'Copy all',
850
+ download: 'Download',
851
+ checkbox: 'I have safely stored a copy of my password',
852
+ complete: 'Complete',
853
+ },
845
854
  otp_verification_view: {
846
855
  title: 'Confirm verification code',
847
856
  body: 'Enter the verification code generated by your authenticator app',
@@ -863,6 +872,15 @@ export declare const translation: {
863
872
  sms_code: string;
864
873
  sms_code_description: string;
865
874
  };
875
+ display_backup_codes_view: {
876
+ title: string;
877
+ body: string;
878
+ warning: string;
879
+ copy_all: string;
880
+ download: string;
881
+ checkbox: string;
882
+ complete: string;
883
+ };
866
884
  otp_verification_view: {
867
885
  title: string;
868
886
  body: string;
@@ -842,6 +842,15 @@ const translation = {
842
842
  sms_code_description:
843
843
  'Use your preferred authenticator app such as Authy, Google Authenticator, etc.',
844
844
  },
845
+ display_backup_codes_view: {
846
+ title: 'Back up your codes',
847
+ body: 'Backup codes help recover your account if you lose access to your device.',
848
+ warning: 'You won’t be able to see these again',
849
+ copy_all: 'Copy all',
850
+ download: 'Download',
851
+ checkbox: 'I have safely stored a copy of my password',
852
+ complete: 'Complete',
853
+ },
845
854
  otp_verification_view: {
846
855
  title: 'Confirm verification code',
847
856
  body: 'Enter the verification code generated by your authenticator app',
@@ -863,6 +872,15 @@ const translation = {
863
872
  sms_code: 'SMS code',
864
873
  sms_code_description: 'Use your preferred authenticator app such as Authy, Google Authenticator, etc.',
865
874
  },
875
+ display_backup_codes_view: {
876
+ title: 'Back up your codes',
877
+ body: 'Backup codes help recover your account if you lose access to your device.',
878
+ warning: 'You won’t be able to see these again',
879
+ copy_all: 'Copy all',
880
+ download: 'Download',
881
+ checkbox: 'I have safely stored a copy of my password',
882
+ complete: 'Complete',
883
+ },
866
884
  otp_verification_view: {
867
885
  title: 'Confirm verification code',
868
886
  body: 'Enter the verification code generated by your authenticator app',
@@ -9,10 +9,6 @@ require('../../../../utils/constants/colors.cjs');
9
9
  require('../../../../utils/constants/values.cjs');
10
10
  var logger = require('../../../logger.cjs');
11
11
 
12
- const connectedKeys = {
13
- [localStorage.AUTH_TOKEN]: [localStorage.AUTH_USER],
14
- [localStorage.AUTH_USER]: [localStorage.AUTH_TOKEN],
15
- };
16
12
  class LocalStorage {
17
13
  static getDynamicLSKey(key) {
18
14
  return `${key}${LocalStorage.getSuffix()}`;
@@ -48,10 +44,7 @@ class LocalStorage {
48
44
  }
49
45
  catch (error) {
50
46
  logger.logger.debug(`Error while parsing ${key} from local storage`, { value });
51
- // keep it in case handleLogOut is not yet loaded when calling this method
52
- [key]
53
- .concat(connectedKeys[key] || [])
54
- .forEach((_key) => LocalStorage.removeFromLS(_key));
47
+ LocalStorage.removeFromLS(key);
55
48
  dynamicEvents.dynamicEvents.emit('triggerLogout');
56
49
  }
57
50
  return undefined;
@@ -1,14 +1,10 @@
1
1
  'use client'
2
2
  import { dynamicEvents } from '../../../../events/dynamicEvents.js';
3
- import { AUTH_TOKEN, AUTH_USER } from '../../../../utils/constants/localStorage.js';
3
+ import { AUTH_TOKEN } from '../../../../utils/constants/localStorage.js';
4
4
  import '../../../../utils/constants/colors.js';
5
5
  import '../../../../utils/constants/values.js';
6
6
  import { logger } from '../../../logger.js';
7
7
 
8
- const connectedKeys = {
9
- [AUTH_TOKEN]: [AUTH_USER],
10
- [AUTH_USER]: [AUTH_TOKEN],
11
- };
12
8
  class LocalStorage {
13
9
  static getDynamicLSKey(key) {
14
10
  return `${key}${LocalStorage.getSuffix()}`;
@@ -44,10 +40,7 @@ class LocalStorage {
44
40
  }
45
41
  catch (error) {
46
42
  logger.debug(`Error while parsing ${key} from local storage`, { value });
47
- // keep it in case handleLogOut is not yet loaded when calling this method
48
- [key]
49
- .concat(connectedKeys[key] || [])
50
- .forEach((_key) => LocalStorage.removeFromLS(_key));
43
+ LocalStorage.removeFromLS(key);
51
44
  dynamicEvents.emit('triggerLogout');
52
45
  }
53
46
  return undefined;
@@ -1,6 +1,5 @@
1
1
  export * from './decodeJwt';
2
2
  export * from './decodeMinJwt';
3
- export * from './validateType';
4
3
  export * from './chain';
5
4
  export * from './wallet';
6
5
  export * from './getValueByKey';
@@ -1,4 +0,0 @@
1
- import { WalletBookSchema } from '@dynamic-labs/wallet-book';
2
- import type { WalletConnector } from '@dynamic-labs/wallet-connector-core';
3
- import { WalletOption } from '../../../types';
4
- export declare const createWallet: (walletBook: WalletBookSchema, wallet: WalletConnector) => WalletOption;
@@ -0,0 +1 @@
1
+ export { clearStore } from './storeActions';
@@ -0,0 +1,10 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var store = require('../../store.cjs');
7
+
8
+ const clearStore = () => store.getStore().setState(store.getStore().getInitialState());
9
+
10
+ exports.clearStore = clearStore;
@@ -0,0 +1 @@
1
+ export declare const clearStore: () => void;
@@ -0,0 +1,6 @@
1
+ 'use client'
2
+ import { getStore } from '../../store.js';
3
+
4
+ const clearStore = () => getStore().setState(getStore().getInitialState());
5
+
6
+ export { clearStore };
@@ -0,0 +1 @@
1
+ export { getUser, setUser, removeUser, type GetUserAction, type RemoveUserAction, type SetUserAction, } from './userActions';
@@ -0,0 +1,10 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var store = require('../../store.cjs');
7
+
8
+ const setUser = (user) => store.getStore().setState({ user });
9
+
10
+ exports.setUser = setUser;
@@ -0,0 +1,7 @@
1
+ import { UserProfile } from '@dynamic-labs/types';
2
+ export type SetUserAction = (user: UserProfile) => void;
3
+ export type GetUserAction = () => UserProfile | undefined;
4
+ export type RemoveUserAction = () => void;
5
+ export declare const setUser: SetUserAction;
6
+ export declare const getUser: GetUserAction;
7
+ export declare const removeUser: RemoveUserAction;
@@ -0,0 +1,6 @@
1
+ 'use client'
2
+ import { getStore } from '../../store.js';
3
+
4
+ const setUser = (user) => getStore().setState({ user });
5
+
6
+ export { setUser };
@@ -0,0 +1 @@
1
+ export { useUser } from './useUser';
@@ -0,0 +1,12 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var zustand = require('zustand');
7
+ var shallow = require('zustand/react/shallow');
8
+ var store = require('../../store.cjs');
9
+
10
+ const useUser = () => zustand.useStore(store.getStore(), shallow.useShallow((state) => state.user));
11
+
12
+ exports.useUser = useUser;
@@ -0,0 +1 @@
1
+ export declare const useUser: () => import("dist/packages/types/src").UserProfile | undefined;
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ import { useStore } from 'zustand';
3
+ import { useShallow } from 'zustand/react/shallow';
4
+ import { getStore } from '../../store.js';
5
+
6
+ const useUser = () => useStore(getStore(), useShallow((state) => state.user));
7
+
8
+ export { useUser };
@@ -0,0 +1,4 @@
1
+ export * from './actions/userActions';
2
+ export * from './actions/storeActions';
3
+ export * from './hooks/useUser';
4
+ export { initializeStore } from './store';
@@ -0,0 +1,24 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var createStore = require('./utils/createStore/createStore.cjs');
7
+ var syncLegacyStorage = require('./utils/syncLegacyStorage/syncLegacyStorage.cjs');
8
+
9
+ let store;
10
+ const getStore = () => {
11
+ if (!store) {
12
+ throw new Error('Store not initialized');
13
+ }
14
+ return store;
15
+ };
16
+ const initializeStore = (props) => {
17
+ if (store) {
18
+ return;
19
+ }
20
+ store = syncLegacyStorage.syncLegacyStorage(createStore.createStore(props));
21
+ };
22
+
23
+ exports.getStore = getStore;
24
+ exports.initializeStore = initializeStore;
@@ -0,0 +1,13 @@
1
+ import { CreateStoreProps } from './utils/createStore';
2
+ export declare const getStore: () => Omit<import("zustand").StoreApi<import("./types").Store>, "persist"> & {
3
+ persist: {
4
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<import("./types").Store, import("./types").Store>>) => void;
5
+ clearStorage: () => void;
6
+ rehydrate: () => void | Promise<void>;
7
+ hasHydrated: () => boolean;
8
+ onHydrate: (fn: (state: import("./types").Store) => void) => () => void;
9
+ onFinishHydration: (fn: (state: import("./types").Store) => void) => () => void;
10
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<import("./types").Store, import("./types").Store>>;
11
+ };
12
+ };
13
+ export declare const initializeStore: (props?: CreateStoreProps) => void;
@@ -0,0 +1,19 @@
1
+ 'use client'
2
+ import { createStore } from './utils/createStore/createStore.js';
3
+ import { syncLegacyStorage } from './utils/syncLegacyStorage/syncLegacyStorage.js';
4
+
5
+ let store;
6
+ const getStore = () => {
7
+ if (!store) {
8
+ throw new Error('Store not initialized');
9
+ }
10
+ return store;
11
+ };
12
+ const initializeStore = (props) => {
13
+ if (store) {
14
+ return;
15
+ }
16
+ store = syncLegacyStorage(createStore(props));
17
+ };
18
+
19
+ export { getStore, initializeStore };
@@ -0,0 +1,4 @@
1
+ import { UserProfile } from '@dynamic-labs/types';
2
+ export type Store = {
3
+ user: UserProfile | undefined;
4
+ };
@@ -0,0 +1,21 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var zustand = require('zustand');
7
+ var middleware = require('zustand/middleware');
8
+ var localStorage = require('../../../utils/constants/localStorage.cjs');
9
+ require('../../../utils/constants/colors.cjs');
10
+ require('../../../utils/constants/values.cjs');
11
+
12
+ const createStore = ({ storageSuffix } = {}) => zustand.createStore(middleware.persist(() => ({
13
+ user: undefined,
14
+ }), {
15
+ name: storageSuffix
16
+ ? `${localStorage.STORE_STORAGE_KEY}_${storageSuffix}`
17
+ : localStorage.STORE_STORAGE_KEY,
18
+ version: 0,
19
+ }));
20
+
21
+ exports.createStore = createStore;
@@ -0,0 +1,16 @@
1
+ import { Store } from '../../types';
2
+ export type CreateStoreProps = {
3
+ storageSuffix?: string;
4
+ };
5
+ export declare const createStore: ({ storageSuffix }?: CreateStoreProps) => Omit<import("zustand").StoreApi<Store>, "persist"> & {
6
+ persist: {
7
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<Store, Store>>) => void;
8
+ clearStorage: () => void;
9
+ rehydrate: () => void | Promise<void>;
10
+ hasHydrated: () => boolean;
11
+ onHydrate: (fn: (state: Store) => void) => () => void;
12
+ onFinishHydration: (fn: (state: Store) => void) => () => void;
13
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<Store, Store>>;
14
+ };
15
+ };
16
+ export type CoreStore = ReturnType<typeof createStore>;
@@ -0,0 +1,17 @@
1
+ 'use client'
2
+ import { createStore as createStore$1 } from 'zustand';
3
+ import { persist } from 'zustand/middleware';
4
+ import { STORE_STORAGE_KEY } from '../../../utils/constants/localStorage.js';
5
+ import '../../../utils/constants/colors.js';
6
+ import '../../../utils/constants/values.js';
7
+
8
+ const createStore = ({ storageSuffix } = {}) => createStore$1(persist(() => ({
9
+ user: undefined,
10
+ }), {
11
+ name: storageSuffix
12
+ ? `${STORE_STORAGE_KEY}_${storageSuffix}`
13
+ : STORE_STORAGE_KEY,
14
+ version: 0,
15
+ }));
16
+
17
+ export { createStore };
@@ -0,0 +1 @@
1
+ export { type CoreStore, type CreateStoreProps, createStore, } from './createStore';
@@ -0,0 +1 @@
1
+ export { syncLegacyStorage } from './syncLegacyStorage';
@@ -0,0 +1,30 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ require('@dynamic-labs/sdk-api-core');
7
+ require('../../../shared/logger.cjs');
8
+ require('@dynamic-labs/iconic');
9
+ require('@dynamic-labs/wallet-connector-core');
10
+ require('react/jsx-runtime');
11
+ require('../../../context/ViewContext/ViewContext.cjs');
12
+ require('react');
13
+ require('@dynamic-labs/wallet-book');
14
+ require('../../../utils/constants/colors.cjs');
15
+ require('../../../utils/constants/values.cjs');
16
+ var localStorage = require('../../../shared/utils/classes/storage/localStorage.cjs');
17
+ require('@dynamic-labs/utils');
18
+ require('../../../shared/consts/index.cjs');
19
+
20
+ const AUTH_USER = 'dynamic_authenticated_user';
21
+ const syncLegacyStorage = (store) => {
22
+ const legacyUser = localStorage.LocalStorage.getFromLS(AUTH_USER);
23
+ if (Boolean(legacyUser) && !store.getState().user) {
24
+ store.setState({ user: legacyUser });
25
+ localStorage.LocalStorage.removeFromLS(AUTH_USER);
26
+ }
27
+ return store;
28
+ };
29
+
30
+ exports.syncLegacyStorage = syncLegacyStorage;
@@ -0,0 +1,2 @@
1
+ import { CoreStore } from '../createStore';
2
+ export declare const syncLegacyStorage: (store: CoreStore) => CoreStore;
@@ -0,0 +1,26 @@
1
+ 'use client'
2
+ import '@dynamic-labs/sdk-api-core';
3
+ import '../../../shared/logger.js';
4
+ import '@dynamic-labs/iconic';
5
+ import '@dynamic-labs/wallet-connector-core';
6
+ import 'react/jsx-runtime';
7
+ import '../../../context/ViewContext/ViewContext.js';
8
+ import 'react';
9
+ import '@dynamic-labs/wallet-book';
10
+ import '../../../utils/constants/colors.js';
11
+ import '../../../utils/constants/values.js';
12
+ import { LocalStorage } from '../../../shared/utils/classes/storage/localStorage.js';
13
+ import '@dynamic-labs/utils';
14
+ import '../../../shared/consts/index.js';
15
+
16
+ const AUTH_USER = 'dynamic_authenticated_user';
17
+ const syncLegacyStorage = (store) => {
18
+ const legacyUser = LocalStorage.getFromLS(AUTH_USER);
19
+ if (Boolean(legacyUser) && !store.getState().user) {
20
+ store.setState({ user: legacyUser });
21
+ LocalStorage.removeFromLS(AUTH_USER);
22
+ }
23
+ return store;
24
+ };
25
+
26
+ export { syncLegacyStorage };