@dynamic-labs/sdk-react-core 3.0.0-alpha.6 → 3.0.0-alpha.8

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 (86) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +10 -10
  5. package/src/index.cjs +9 -1
  6. package/src/index.d.ts +4 -1
  7. package/src/index.js +5 -1
  8. package/src/lib/Main.cjs +2 -0
  9. package/src/lib/Main.js +2 -0
  10. package/src/lib/context/DynamicContext/DynamicContext.cjs +15 -8
  11. package/src/lib/context/DynamicContext/DynamicContext.js +16 -9
  12. package/src/lib/context/DynamicContext/hooks/useTieCallbacksToEvents/useTieCallbacksToEvents.cjs +15 -6
  13. package/src/lib/context/DynamicContext/hooks/useTieCallbacksToEvents/useTieCallbacksToEvents.js +15 -6
  14. package/src/lib/context/DynamicContext/types/index.d.ts +4 -2
  15. package/src/lib/context/DynamicContext/useDynamicContext/useDynamicContext.cjs +3 -2
  16. package/src/lib/context/DynamicContext/useDynamicContext/useDynamicContext.d.ts +1 -1
  17. package/src/lib/context/DynamicContext/useDynamicContext/useDynamicContext.js +3 -2
  18. package/src/lib/context/ReinitializeContext/ReinitializeContextProvider.cjs +113 -0
  19. package/src/lib/context/ReinitializeContext/ReinitializeContextProvider.d.ts +22 -0
  20. package/src/lib/context/ReinitializeContext/ReinitializeContextProvider.js +107 -0
  21. package/src/lib/context/ReinitializeContext/index.d.ts +1 -0
  22. package/src/lib/context/WalletContext/WalletContext.cjs +1 -1
  23. package/src/lib/context/WalletContext/WalletContext.js +1 -1
  24. package/src/lib/context/WidgetRegistry/WidgetRegistryContextProvider.cjs +128 -0
  25. package/src/lib/context/WidgetRegistry/WidgetRegistryContextProvider.d.ts +6 -0
  26. package/src/lib/context/WidgetRegistry/WidgetRegistryContextProvider.js +122 -0
  27. package/src/lib/context/WidgetRegistry/index.d.ts +1 -0
  28. package/src/lib/data/api/wallets/wallets.cjs +2 -1
  29. package/src/lib/data/api/wallets/wallets.d.ts +2 -1
  30. package/src/lib/data/api/wallets/wallets.js +2 -1
  31. package/src/lib/events/dynamicEvents.d.ts +2 -1
  32. package/src/lib/events/multiWallet.d.ts +6 -0
  33. package/src/lib/store/index.d.ts +1 -1
  34. package/src/lib/store/store.cjs +6 -0
  35. package/src/lib/store/store.d.ts +1 -0
  36. package/src/lib/store/store.js +6 -1
  37. package/src/lib/styles/index.shadow.cjs +1 -1
  38. package/src/lib/styles/index.shadow.js +1 -1
  39. package/src/lib/utils/functions/index.d.ts +1 -0
  40. package/src/lib/utils/functions/logVerboseTroubleshootingMessage/index.d.ts +1 -0
  41. package/src/lib/utils/functions/logVerboseTroubleshootingMessage/logVerboseTroubleshootingMessage.cjs +28 -0
  42. package/src/lib/utils/functions/logVerboseTroubleshootingMessage/logVerboseTroubleshootingMessage.d.ts +1 -0
  43. package/src/lib/utils/functions/logVerboseTroubleshootingMessage/logVerboseTroubleshootingMessage.js +24 -0
  44. package/src/lib/utils/hooks/events/useDynamicEvents/useDynamicEvents.cjs +20 -0
  45. package/src/lib/utils/hooks/events/useDynamicEvents/useDynamicEvents.d.ts +2 -2
  46. package/src/lib/utils/hooks/events/useDynamicEvents/useDynamicEvents.js +20 -1
  47. package/src/lib/utils/hooks/index.d.ts +1 -0
  48. package/src/lib/utils/hooks/multiWallet/useVerifyOnAwaitingSignature/useVerifyOnAwaitingSignature.cjs +39 -13
  49. package/src/lib/utils/hooks/multiWallet/useVerifyOnAwaitingSignature/useVerifyOnAwaitingSignature.js +40 -14
  50. package/src/lib/utils/hooks/useHandleUnlinkWallet/useHandleUnlinkWallet.cjs +3 -1
  51. package/src/lib/utils/hooks/useHandleUnlinkWallet/useHandleUnlinkWallet.js +3 -1
  52. package/src/lib/utils/hooks/useMergeUserAccounts/useMergeUserAccounts.cjs +6 -2
  53. package/src/lib/utils/hooks/useMergeUserAccounts/useMergeUserAccounts.js +6 -2
  54. package/src/lib/utils/hooks/useRefreshUser/index.d.ts +1 -0
  55. package/src/lib/utils/hooks/useRefreshUser/useRefreshUser.cjs +90 -0
  56. package/src/lib/utils/hooks/useRefreshUser/useRefreshUser.d.ts +8 -0
  57. package/src/lib/utils/hooks/useRefreshUser/useRefreshUser.js +86 -0
  58. package/src/lib/utils/hooks/useSwitchNetwork/index.d.ts +1 -0
  59. package/src/lib/utils/hooks/useSwitchNetwork/useSwitchNetwork.cjs +26 -0
  60. package/src/lib/utils/hooks/useSwitchNetwork/useSwitchNetwork.d.ts +5 -0
  61. package/src/lib/utils/hooks/useSwitchNetwork/useSwitchNetwork.js +22 -0
  62. package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.cjs +7 -6
  63. package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.js +7 -6
  64. package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.cjs +118 -25
  65. package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.js +119 -26
  66. package/src/lib/utils/hooks/useWalletItemActions/useWalletItemActions.cjs +20 -1
  67. package/src/lib/utils/hooks/useWalletItemActions/useWalletItemActions.js +20 -1
  68. package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.cjs +4 -14
  69. package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.js +5 -15
  70. package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.cjs +3 -1
  71. package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.js +3 -1
  72. package/src/lib/views/WalletList/WalletList.cjs +1 -3
  73. package/src/lib/views/WalletList/WalletList.js +1 -3
  74. package/src/lib/views/WalletList/hooks/useTabState.cjs +6 -81
  75. package/src/lib/views/WalletList/hooks/useTabState.d.ts +6 -3
  76. package/src/lib/views/WalletList/hooks/useTabState.js +6 -81
  77. package/src/lib/widgets/DynamicMultiWalletPromptsWidget/DynamicMultiWalletPromptsWidget.cjs +5 -5
  78. package/src/lib/widgets/DynamicMultiWalletPromptsWidget/DynamicMultiWalletPromptsWidget.js +5 -5
  79. package/src/lib/widgets/DynamicWidget/components/DynamicUserProfile/DynamicUserProfile.cjs +4 -1
  80. package/src/lib/widgets/DynamicWidget/components/DynamicUserProfile/DynamicUserProfile.js +4 -1
  81. package/src/lib/widgets/DynamicWidget/prompts/PrimaryNotConnectedModal/PrimaryNotConnectedModal.cjs +1 -1
  82. package/src/lib/widgets/DynamicWidget/prompts/PrimaryNotConnectedModal/PrimaryNotConnectedModal.js +1 -1
  83. package/src/lib/views/WalletList/utils/getInitialTabIndex/getInitialTabIndex.cjs +0 -22
  84. package/src/lib/views/WalletList/utils/getInitialTabIndex/getInitialTabIndex.d.ts +0 -2
  85. package/src/lib/views/WalletList/utils/getInitialTabIndex/getInitialTabIndex.js +0 -18
  86. package/src/lib/views/WalletList/utils/getInitialTabIndex/index.d.ts +0 -1
@@ -0,0 +1,122 @@
1
+ 'use client'
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { createContext, useState, useCallback, useContext, useRef, useEffect } from 'react';
4
+ import '@dynamic-labs/wallet-connector-core';
5
+ import '@dynamic-labs/sdk-api-core';
6
+ import '../../utils/constants/values.js';
7
+ import '@dynamic-labs/utils';
8
+ import '../../../../_virtual/_tslib.js';
9
+ import '@dynamic-labs/multi-wallet';
10
+ import '../../shared/logger.js';
11
+ import '@dynamic-labs/iconic';
12
+ import '../ViewContext/ViewContext.js';
13
+ import '@dynamic-labs/wallet-book';
14
+ import '../../utils/constants/colors.js';
15
+ import '../../shared/utils/classes/storage/localStorage.js';
16
+ import '../../shared/utils/classes/storage/sessionStorage.js';
17
+ import '../../shared/consts/index.js';
18
+ import 'react-international-phone';
19
+ import '../../config/ApiEndpoint.js';
20
+ import '@dynamic-labs/store';
21
+ import '../../locale/locale.js';
22
+ import { randomString } from '../../utils/functions/randomString/randomString.js';
23
+ import '../../events/dynamicEvents.js';
24
+ import '../DynamicContext/DynamicContext.js';
25
+ import '../CaptchaContext/CaptchaContext.js';
26
+ import '../ErrorContext/ErrorContext.js';
27
+ import '../AccessDeniedContext/AccessDeniedContext.js';
28
+ import '../AccountExistsContext/AccountExistsContext.js';
29
+ import '../UserWalletsContext/UserWalletsContext.js';
30
+ import '../VerificationContext/VerificationContext.js';
31
+ import 'react-dom';
32
+ import '../WalletContext/WalletContext.js';
33
+ import '../ThemeContext/ThemeContext.js';
34
+ import '../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.js';
35
+ import '@dynamic-labs/types';
36
+ import '../LoadingContext/LoadingContext.js';
37
+ import 'yup';
38
+ import '../MockContext/MockContext.js';
39
+ import '../../views/CollectUserDataView/useFields.js';
40
+ import '../FieldsStateContext/FieldsStateContext.js';
41
+ import '../UserFieldEditorContext/UserFieldEditorContext.js';
42
+ import '@dynamic-labs/rpc-providers';
43
+ import 'react-i18next';
44
+ import '../../components/Accordion/components/AccordionItem/AccordionItem.js';
45
+ import '../../components/Alert/Alert.js';
46
+ import '../../components/ShadowDOM/ShadowDOM.js';
47
+ import '../../components/IconButton/IconButton.js';
48
+ import '../../components/InlineWidget/InlineWidget.js';
49
+ import '../../components/Input/Input.js';
50
+ import '../../components/IsBrowser/IsBrowser.js';
51
+ import '../../components/MenuList/Dropdown/Dropdown.js';
52
+ import '../../components/Transition/ZoomTransition/ZoomTransition.js';
53
+ import '../../components/Transition/SlideInUpTransition/SlideInUpTransition.js';
54
+ import '../../components/Transition/OpacityTransition/OpacityTransition.js';
55
+ import '../../components/OverlayCard/OverlayCardTarget/OverlayCardTarget.js';
56
+ import '../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.js';
57
+ import '../../components/Popper/Popper/Popper.js';
58
+ import '../../components/Popper/PopperContext/PopperContext.js';
59
+ import 'react-focus-lock';
60
+ import 'qrcode';
61
+ import 'formik';
62
+ import '../../views/WalletList/WalletList.js';
63
+ import '../SocialRedirectContext/SocialRedirectContext.js';
64
+ import '../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js';
65
+ import '@hcaptcha/react-hcaptcha';
66
+ import '../FooterAnimationContext/index.js';
67
+ import '../WalletGroupContext/WalletGroupContext.js';
68
+ import '../MfaSettingsContext/MfaSettingsContext.js';
69
+ import '../IpConfigurationContext/IpConfigurationContext.js';
70
+ import '../PasskeyContext/PasskeyContext.js';
71
+ import '../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.js';
72
+ import '../../widgets/DynamicWidget/context/DynamicWidgetContext.js';
73
+ import '../../views/TransactionConfirmationView/helpers/transactionErrorMessage.js';
74
+ import '../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js';
75
+
76
+ const widgetRegistryContext = createContext(null);
77
+ const WidgetRegistryContextProvider = ({ children, }) => {
78
+ const [registry, setRegistry] = useState({});
79
+ const registerId = useCallback((widgetId, widgetType) => {
80
+ setRegistry((prevRegistry) => (Object.assign(Object.assign({}, prevRegistry), { [widgetId]: {
81
+ type: widgetType,
82
+ } })));
83
+ }, [setRegistry]);
84
+ const removeId = useCallback((widgetId) => {
85
+ setRegistry((prevRegistry) => {
86
+ const newRegistry = Object.assign({}, prevRegistry);
87
+ delete newRegistry[widgetId];
88
+ return newRegistry;
89
+ });
90
+ }, [setRegistry]);
91
+ const checkWidgetPresence = useCallback((widgetType) => Object.values(registry).some((widget) => widget.type === widgetType), [registry]);
92
+ return (jsx(widgetRegistryContext.Provider, { value: { checkWidgetPresence, registerId, removeId }, children: children }));
93
+ };
94
+ const useWidgetRegistry = () => {
95
+ const context = useContext(widgetRegistryContext);
96
+ if (context === null) {
97
+ throw new Error('usage of useWidgetRegistry not wrapped in `WidgetRegistryContextProvider`.');
98
+ }
99
+ return context;
100
+ };
101
+ const useRegisterWidget = (widgetType, enabled = true) => {
102
+ const idRef = useRef(randomString(8));
103
+ const { registerId, removeId } = useWidgetRegistry();
104
+ useEffect(() => {
105
+ if (enabled === false) {
106
+ return;
107
+ }
108
+ registerId(idRef.current, widgetType);
109
+ return () => {
110
+ // This is disabled because eslint think we are using state value
111
+ // but this is fine because it is a ref
112
+ // eslint-disable-next-line react-hooks/exhaustive-deps
113
+ removeId(idRef.current);
114
+ };
115
+ }, [widgetType, enabled, registerId, removeId]);
116
+ };
117
+ const useWidgetRegistryCheck = (widgetType) => {
118
+ const { checkWidgetPresence } = useWidgetRegistry();
119
+ return checkWidgetPresence(widgetType);
120
+ };
121
+
122
+ export { WidgetRegistryContextProvider, useRegisterWidget, useWidgetRegistryCheck };
@@ -0,0 +1 @@
1
+ export { WidgetRegistryContextProvider, useRegisterWidget, useWidgetRegistryCheck, } from './WidgetRegistryContextProvider';
@@ -76,7 +76,7 @@ const linkWallet = (environmentId_1, _b) => _tslib.__awaiter(void 0, [environmen
76
76
  throw new utils.DynamicError(data.error);
77
77
  }
78
78
  });
79
- const unlinkWallet = (_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ environmentId, primaryWalletId, walletId, }) {
79
+ const unlinkWallet = (_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ environmentId, primaryWalletId, walletId, onSuccess, }) {
80
80
  try {
81
81
  const response = yield api.sdkApi().verifyUnlink({
82
82
  environmentId,
@@ -85,6 +85,7 @@ const unlinkWallet = (_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({
85
85
  walletId,
86
86
  },
87
87
  });
88
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess();
88
89
  const user = storeAuthTokenAndUser.storeAuthTokenAndUser(response);
89
90
  return user;
90
91
  }
@@ -6,10 +6,11 @@ export declare const storeSelectedWallet: ({ environmentId, walletId, }: {
6
6
  walletId: string;
7
7
  }) => Promise<UserProfile | undefined>;
8
8
  export declare const linkWallet: (environmentId: string, { messageToSign, network, signedMessage, publicWalletAddress, chain, walletName, walletProvider, additionalWalletAddresses, backup, password, passwordSource, }: VerifyWallet) => Promise<VerifyResponse | undefined>;
9
- export declare const unlinkWallet: ({ environmentId, primaryWalletId, walletId, }: {
9
+ export declare const unlinkWallet: ({ environmentId, primaryWalletId, walletId, onSuccess, }: {
10
10
  environmentId: string;
11
11
  primaryWalletId: string | undefined;
12
12
  walletId: string;
13
+ onSuccess?: () => void;
13
14
  }) => Promise<UserProfile | undefined>;
14
15
  export declare const transferWallet: (environmentId: string, { network, messageToSign, signedMessage, publicWalletAddress, chain, walletName, walletProvider, skipEmptyAccountCheck, }: VerifyWallet) => Promise<UserProfile | undefined>;
15
16
  export declare const verifyWallet: (environmentId: string, { messageToSign, signedMessage, publicWalletAddress, chain, walletName, walletProvider, captchaToken, network, oauth, additionalWalletAddresses, }: VerifyWallet) => Promise<VerifyResponse | undefined>;
@@ -72,7 +72,7 @@ const linkWallet = (environmentId_1, _b) => __awaiter(void 0, [environmentId_1,
72
72
  throw new DynamicError(data.error);
73
73
  }
74
74
  });
75
- const unlinkWallet = (_c) => __awaiter(void 0, [_c], void 0, function* ({ environmentId, primaryWalletId, walletId, }) {
75
+ const unlinkWallet = (_c) => __awaiter(void 0, [_c], void 0, function* ({ environmentId, primaryWalletId, walletId, onSuccess, }) {
76
76
  try {
77
77
  const response = yield sdkApi().verifyUnlink({
78
78
  environmentId,
@@ -81,6 +81,7 @@ const unlinkWallet = (_c) => __awaiter(void 0, [_c], void 0, function* ({ enviro
81
81
  walletId,
82
82
  },
83
83
  });
84
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess();
84
85
  const user = storeAuthTokenAndUser(response);
85
86
  return user;
86
87
  }
@@ -6,7 +6,8 @@ import { PasskeyEvents } from './passkey';
6
6
  import { SocialEvents } from './social';
7
7
  import { UIEvents } from './ui';
8
8
  import { WalletEvents } from './wallets';
9
+ import { MultiWalletInternalEvents } from './multiWallet';
9
10
  /** Maps internal event names to their listeners */
10
- export type DynamicEvents = AuthEvents & UIEvents & OTPEvents & WalletEvents & PasskeyEvents & SocialEvents & EmbeddedWalletEvents;
11
+ export type DynamicEvents = AuthEvents & UIEvents & OTPEvents & WalletEvents & PasskeyEvents & SocialEvents & EmbeddedWalletEvents & MultiWalletInternalEvents;
11
12
  export declare const dynamicEvents: EventEmitter<DynamicEvents, any>;
12
13
  export type DynamicEventEmitter = typeof dynamicEvents;
@@ -0,0 +1,6 @@
1
+ export type MultiWalletInternalEvents = {
2
+ triggerComputePrimaryWalletMultiWalletStateFromAccounts: (props: {
3
+ accounts: string[];
4
+ }) => void;
5
+ triggerConnectAndSign: () => void;
6
+ };
@@ -5,4 +5,4 @@ export * from './actions/userActions';
5
5
  export * from './hooks/useNetworkConfigurations';
6
6
  export * from './hooks/useProjectSettings';
7
7
  export * from './hooks/useUser';
8
- export { initializeStore } from './store';
8
+ export { initializeStore, removeStoreInstance } from './store';
@@ -17,6 +17,11 @@ const getStore = () => {
17
17
  }
18
18
  return store;
19
19
  };
20
+ const removeStoreInstance = () => {
21
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
22
+ // @ts-ignore
23
+ store = undefined;
24
+ };
20
25
  const initializeStore = ({ storageSuffix, environmentId, }) => {
21
26
  if (store) {
22
27
  return;
@@ -47,3 +52,4 @@ const getStorage = () => {
47
52
 
48
53
  exports.getStore = getStore;
49
54
  exports.initializeStore = initializeStore;
55
+ exports.removeStoreInstance = removeStoreInstance;
@@ -1,4 +1,5 @@
1
1
  import { StoreApi } from '@dynamic-labs/store';
2
2
  import { SdkStore, SdkStoreProps } from './types';
3
3
  export declare const getStore: () => StoreApi<SdkStore>;
4
+ export declare const removeStoreInstance: () => void;
4
5
  export declare const initializeStore: ({ storageSuffix, environmentId, }: SdkStoreProps) => void;
@@ -13,6 +13,11 @@ const getStore = () => {
13
13
  }
14
14
  return store;
15
15
  };
16
+ const removeStoreInstance = () => {
17
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
18
+ // @ts-ignore
19
+ store = undefined;
20
+ };
16
21
  const initializeStore = ({ storageSuffix, environmentId, }) => {
17
22
  if (store) {
18
23
  return;
@@ -41,4 +46,4 @@ const getStorage = () => {
41
46
  return window.localStorage;
42
47
  };
43
48
 
44
- export { getStore, initializeStore };
49
+ export { getStore, initializeStore, removeStoreInstance };