@dynamic-labs/sdk-react-core 4.73.0 → 4.74.0

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 (25) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +12 -12
  5. package/src/index.d.ts +1 -1
  6. package/src/lib/context/DynamicContext/DynamicContext.cjs +1 -0
  7. package/src/lib/context/DynamicContext/DynamicContext.js +1 -0
  8. package/src/lib/context/DynamicContext/hooks/useInitialViewType/useInitialViewType.cjs +6 -1
  9. package/src/lib/context/DynamicContext/hooks/useInitialViewType/useInitialViewType.d.ts +3 -1
  10. package/src/lib/context/DynamicContext/hooks/useInitialViewType/useInitialViewType.js +6 -1
  11. package/src/lib/context/ErrorContext/hooks/useErrorText/useErrorText.cjs +1 -0
  12. package/src/lib/context/ErrorContext/hooks/useErrorText/useErrorText.js +2 -1
  13. package/src/lib/data/api/utils.cjs +31 -4
  14. package/src/lib/data/api/utils.js +31 -4
  15. package/src/lib/shared/utils/functions/hasPendingDeviceRegistration/hasPendingDeviceRegistration.cjs +8 -0
  16. package/src/lib/shared/utils/functions/hasPendingDeviceRegistration/hasPendingDeviceRegistration.d.ts +3 -0
  17. package/src/lib/shared/utils/functions/hasPendingDeviceRegistration/hasPendingDeviceRegistration.js +4 -0
  18. package/src/lib/shared/utils/functions/hasPendingDeviceRegistration/index.d.ts +1 -0
  19. package/src/lib/shared/utils/functions/hasPendingRequirements/hasPendingRequirements.cjs +7 -1
  20. package/src/lib/shared/utils/functions/hasPendingRequirements/hasPendingRequirements.d.ts +1 -1
  21. package/src/lib/shared/utils/functions/hasPendingRequirements/hasPendingRequirements.js +7 -1
  22. package/src/lib/utils/hooks/useSyncDeviceRegistrationFlow/useSyncDeviceRegistrationFlow.cjs +5 -5
  23. package/src/lib/utils/hooks/useSyncDeviceRegistrationFlow/useSyncDeviceRegistrationFlow.js +5 -5
  24. package/src/lib/widgets/DynamicWidget/views/AccountAndSecuritySettingsView/EmbeddedWalletExportSection/EmbeddedWalletExportSection.cjs +8 -2
  25. package/src/lib/widgets/DynamicWidget/views/AccountAndSecuritySettingsView/EmbeddedWalletExportSection/EmbeddedWalletExportSection.js +8 -2
package/CHANGELOG.md CHANGED
@@ -1,4 +1,34 @@
1
1
 
2
+ ## [4.74.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.73.2...v4.74.0) (2026-04-02)
3
+
4
+
5
+ ### Features
6
+
7
+ * **client:** expose waitForReady() on SdkModule ([#10771](https://github.com/dynamic-labs/dynamic-auth/issues/10771)) ([8d94615](https://github.com/dynamic-labs/dynamic-auth/commit/8d946158ab284fe338c78cfba38504b1bca91cd7))
8
+ * **waas:** wire up signed session ID reverse channel ([#10577](https://github.com/dynamic-labs/dynamic-auth/issues/10577)) ([e07815f](https://github.com/dynamic-labs/dynamic-auth/commit/e07815ff370634c8a5a674cbf27bc79782a27f1a))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **react-native:** keep WebView ref valid during URL reloads ([#10769](https://github.com/dynamic-labs/dynamic-auth/issues/10769)) ([691bef2](https://github.com/dynamic-labs/dynamic-auth/commit/691bef277c5190b7cd88d12f95e2b6fbfa827b64))
14
+ * require device registration before sdk is in logged in state ([#10831](https://github.com/dynamic-labs/dynamic-auth/issues/10831)) ([7ebae17](https://github.com/dynamic-labs/dynamic-auth/commit/7ebae17f01b9db59b88dd997d511ff84bd6b2d1a))
15
+ * **waas:** always prompt for password on cloud backup/export operations [DYNT-269] ([#10829](https://github.com/dynamic-labs/dynamic-auth/issues/10829)) ([5d2898b](https://github.com/dynamic-labs/dynamic-auth/commit/5d2898b9e6e06bbf13813b912b366f522fb66b70))
16
+ * **webview:** preserve secure storage key map during recovery clear ([#10770](https://github.com/dynamic-labs/dynamic-auth/issues/10770)) ([888bfe9](https://github.com/dynamic-labs/dynamic-auth/commit/888bfe9f27dd3b4751dddf2027a3e4d219130860))
17
+
18
+ ### [4.73.2](https://github.com/dynamic-labs/dynamic-auth/compare/v4.73.1...v4.73.2) (2026-03-31)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * use initial URL for device registration redirect detection ([#10821](https://github.com/dynamic-labs/dynamic-auth/issues/10821)) ([dbec178](https://github.com/dynamic-labs/dynamic-auth/commit/dbec178e0bad9a7e99c529b79cb0fbe0fd347904))
24
+
25
+ ### [4.73.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.73.0...v4.73.1) (2026-03-30)
26
+
27
+
28
+ ### Features
29
+
30
+ * **tempo:** add isTempoWallet type guard and TempoWallet class ([#10814](https://github.com/dynamic-labs/dynamic-auth/issues/10814)) ([1f2ec94](https://github.com/dynamic-labs/dynamic-auth/commit/1f2ec949bcfd25b2c460e07214041d06b172f12d))
31
+
2
32
  ## [4.73.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.72.0...v4.73.0) (2026-03-30)
3
33
 
4
34
 
package/package.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.73.0";
6
+ var version = "4.74.0";
7
7
  var dependencies = {
8
8
  "@dynamic-labs/sdk-api-core": "0.0.909",
9
9
  "@dynamic-labs-sdk/client": "0.19.0",
package/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client'
2
- var version = "4.73.0";
2
+ var version = "4.74.0";
3
3
  var dependencies = {
4
4
  "@dynamic-labs/sdk-api-core": "0.0.909",
5
5
  "@dynamic-labs-sdk/client": "0.19.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/sdk-react-core",
3
- "version": "4.73.0",
3
+ "version": "4.74.0",
4
4
  "dependencies": {
5
5
  "@dynamic-labs/sdk-api-core": "0.0.909",
6
6
  "@dynamic-labs-sdk/client": "0.19.0",
@@ -16,17 +16,17 @@
16
16
  "yup": "0.32.11",
17
17
  "react-international-phone": "4.5.0",
18
18
  "bs58": "5.0.0",
19
- "@dynamic-labs/assert-package-version": "4.73.0",
20
- "@dynamic-labs/iconic": "4.73.0",
21
- "@dynamic-labs/locale": "4.73.0",
22
- "@dynamic-labs/logger": "4.73.0",
23
- "@dynamic-labs/multi-wallet": "4.73.0",
24
- "@dynamic-labs/rpc-providers": "4.73.0",
25
- "@dynamic-labs/store": "4.73.0",
26
- "@dynamic-labs/types": "4.73.0",
27
- "@dynamic-labs/utils": "4.73.0",
28
- "@dynamic-labs/wallet-book": "4.73.0",
29
- "@dynamic-labs/wallet-connector-core": "4.73.0",
19
+ "@dynamic-labs/assert-package-version": "4.74.0",
20
+ "@dynamic-labs/iconic": "4.74.0",
21
+ "@dynamic-labs/locale": "4.74.0",
22
+ "@dynamic-labs/logger": "4.74.0",
23
+ "@dynamic-labs/multi-wallet": "4.74.0",
24
+ "@dynamic-labs/rpc-providers": "4.74.0",
25
+ "@dynamic-labs/store": "4.74.0",
26
+ "@dynamic-labs/types": "4.74.0",
27
+ "@dynamic-labs/utils": "4.74.0",
28
+ "@dynamic-labs/wallet-book": "4.74.0",
29
+ "@dynamic-labs/wallet-connector-core": "4.74.0",
30
30
  "eventemitter3": "5.0.1"
31
31
  },
32
32
  "devDependencies": {
package/src/index.d.ts CHANGED
@@ -104,7 +104,7 @@ export { getDefaultColor, getThemeConfig, themesData, } from './lib/context/Them
104
104
  export type {
105
105
  /** @deprecated */
106
106
  ViewType, } from './lib/context/ViewContext';
107
- export type { NotSupportedError, SandboxMaximumThresholdReachedError, NoAccessError, ChainalysisError, EmailAlreadyExistsError, UsernameAlreadyExistsError, SocialAccountAlreadyExistsError, WalletNotDeployedError, WalletUsedError, EmailVerificationError, AccountExistsError, InvalidPhoneNumberError, } from '@dynamic-labs/utils';
107
+ export type { NotSupportedError, SandboxMaximumThresholdReachedError, NoAccessError, ChainalysisError, EmailAlreadyExistsError, UsernameAlreadyExistsError, SocialAccountAlreadyExistsError, WalletNotDeployedError, WalletUsedError, EmailVerificationError, AccountExistsError, InvalidPhoneNumberError, RateLimitError, } from '@dynamic-labs/utils';
108
108
  export type { WalletConnector, Chain, } from '@dynamic-labs/wallet-connector-core';
109
109
  export type { EvmNetwork, PhoneData, OtpDestination, UserProfile,
110
110
  /** @deprecated use AuthOptions instead */
@@ -743,6 +743,7 @@ const InnerDynamicContextProvider = (props) => {
743
743
  isAuthenticated: isAuthenticated || Boolean(primaryWallet),
744
744
  isBridgeFlow,
745
745
  isMultiWalletEnabled: multiWallet,
746
+ user: user !== null && user !== void 0 ? user : userWithMissingInfo,
746
747
  });
747
748
  return (jsxRuntime.jsx(reactI18next.I18nextProvider, { i18n: i18nSDKInstance, children: jsxRuntime.jsxs(DynamicContext.Provider, { value: value, children: [(jsxRuntime.jsx("style", { nonce: cspNonce, children: main_global })), jsxRuntime.jsx(walletBook.WalletBookContextProvider, { walletBook: walletBook$1, children: jsxRuntime.jsx(ThemeContext.ThemeContextProvider, { cspNonce: cspNonce, customerTheme: parseTheme.parseTheme(theme, ((_w = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _w === void 0 ? void 0 : _w.modal) || undefined), designSettings: projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design, children: jsxRuntime.jsx(LoadingContext.LoadingContextProvider, { children: jsxRuntime.jsxs(ViewContext.ViewContextProvider, { initialViewType: initialViewType, children: [networkValidationMode === 'always' && jsxRuntime.jsx(UseNetworkValidation.UseNetworkValidation, {}), jsxRuntime.jsx(CaptchaContext.CaptchaContextProvider, { children: jsxRuntime.jsx(AccountExistsContext.AccountExistsContextProvider, { children: jsxRuntime.jsx(WalletContext.WalletContextProvider, { children: jsxRuntime.jsx(VerificationContext.VerificationProvider, { children: jsxRuntime.jsx(PasskeyContext.PasskeyContextProvider, { children: jsxRuntime.jsx(DynamicWidgetContext.DynamicWidgetContextProvider, { children: jsxRuntime.jsx(DynamicBridgeWidgetContext.DynamicBridgeWidgetContextProvider, { children: jsxRuntime.jsx(OnrampContext.OnrampContextProvider, { children: jsxRuntime.jsx(AccessDeniedContext.AccessDeniedContextProvider, { children: jsxRuntime.jsx(SendBalanceContext.SendBalanceContextProvider, { children: jsxRuntime.jsx(WalletGroupContext.WalletGroupContextProvider, { children: jsxRuntime.jsx(UserFieldEditorContext.UserFieldEditorContextProvider, { children: jsxRuntime.jsx(ConnectWithOtpProvider.ConnectWithOtpProvider, { children: jsxRuntime.jsx(PhantomRedirectContext.PhantomRedirectContextProvider, { children: jsxRuntime.jsxs(SocialRedirectContext.SocialRedirectContextProvider, { children: [jsxRuntime.jsx(app.DynamicAuthFlow, {}), jsxRuntime.jsx(OnrampWidget.OnrampWidget, {}), jsxRuntime.jsx(SyncAuthFlow.SyncAuthFlow, {}), jsxRuntime.jsx(WalletConnectorEvents.WalletConnectorEvents, { connectorProps: connectorProps }), confirmationModal, jsxRuntime.jsx(ErrorBoundaryExclude.ErrorBoundaryExclude, { children: children })] }) }) }) }) }) }) }) }) }) }) }) }) }) }) })] }) }) }) })] }) }));
748
749
  };
@@ -739,6 +739,7 @@ const InnerDynamicContextProvider = (props) => {
739
739
  isAuthenticated: isAuthenticated || Boolean(primaryWallet),
740
740
  isBridgeFlow,
741
741
  isMultiWalletEnabled: multiWallet,
742
+ user: user !== null && user !== void 0 ? user : userWithMissingInfo,
742
743
  });
743
744
  return (jsx(I18nextProvider, { i18n: i18nSDKInstance, children: jsxs(DynamicContext.Provider, { value: value, children: [(jsx("style", { nonce: cspNonce, children: css_248z })), jsx(WalletBookContextProvider, { walletBook: walletBook, children: jsx(ThemeContextProvider, { cspNonce: cspNonce, customerTheme: parseTheme(theme, ((_w = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _w === void 0 ? void 0 : _w.modal) || undefined), designSettings: projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design, children: jsx(LoadingContextProvider, { children: jsxs(ViewContextProvider, { initialViewType: initialViewType, children: [networkValidationMode === 'always' && jsx(UseNetworkValidation, {}), jsx(CaptchaContextProvider, { children: jsx(AccountExistsContextProvider, { children: jsx(WalletContextProvider, { children: jsx(VerificationProvider, { children: jsx(PasskeyContextProvider, { children: jsx(DynamicWidgetContextProvider, { children: jsx(DynamicBridgeWidgetContextProvider, { children: jsx(OnrampContextProvider, { children: jsx(AccessDeniedContextProvider, { children: jsx(SendBalanceContextProvider, { children: jsx(WalletGroupContextProvider, { children: jsx(UserFieldEditorContextProvider, { children: jsx(ConnectWithOtpProvider, { children: jsx(PhantomRedirectContextProvider, { children: jsxs(SocialRedirectContextProvider, { children: [jsx(DynamicAuthFlow, {}), jsx(OnrampWidget, {}), jsx(SyncAuthFlow, {}), jsx(WalletConnectorEvents, { connectorProps: connectorProps }), confirmationModal, jsx(ErrorBoundaryExclude, { children: children })] }) }) }) }) }) }) }) }) }) }) }) }) }) }) })] }) }) }) })] }) }));
744
745
  };
@@ -3,7 +3,12 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- const useInitialViewType = ({ isAuthenticated, bridgeOnboardingCompleted, isMultiWalletEnabled, isBridgeFlow, connectedWallets, }) => {
6
+ var hasPendingDeviceRegistration = require('../../../../shared/utils/functions/hasPendingDeviceRegistration/hasPendingDeviceRegistration.cjs');
7
+
8
+ const useInitialViewType = ({ isAuthenticated, bridgeOnboardingCompleted, isMultiWalletEnabled, isBridgeFlow, connectedWallets, user, }) => {
9
+ if (user && hasPendingDeviceRegistration.hasPendingDeviceRegistration(user)) {
10
+ return 'device-registration';
11
+ }
7
12
  // when multiwallet enabled, and user wants to link wallet
8
13
  // show wallet-list view
9
14
  if (isAuthenticated || bridgeOnboardingCompleted) {
@@ -1,3 +1,4 @@
1
+ import { UserProfile } from '@dynamic-labs/types';
1
2
  import { Wallet } from '@dynamic-labs/wallet-connector-core';
2
3
  type UseInitialViewTypeProps = {
3
4
  isAuthenticated: boolean;
@@ -5,6 +6,7 @@ type UseInitialViewTypeProps = {
5
6
  isMultiWalletEnabled: boolean;
6
7
  isBridgeFlow: boolean;
7
8
  connectedWallets: Wallet[];
9
+ user: UserProfile | undefined;
8
10
  };
9
- export declare const useInitialViewType: ({ isAuthenticated, bridgeOnboardingCompleted, isMultiWalletEnabled, isBridgeFlow, connectedWallets, }: UseInitialViewTypeProps) => "multi-wallet-wallet-list" | "wallet-list" | "bridge-welcome" | "login-with-email-or-wallet";
11
+ export declare const useInitialViewType: ({ isAuthenticated, bridgeOnboardingCompleted, isMultiWalletEnabled, isBridgeFlow, connectedWallets, user, }: UseInitialViewTypeProps) => "device-registration" | "multi-wallet-wallet-list" | "wallet-list" | "bridge-welcome" | "login-with-email-or-wallet";
10
12
  export {};
@@ -1,5 +1,10 @@
1
1
  'use client'
2
- const useInitialViewType = ({ isAuthenticated, bridgeOnboardingCompleted, isMultiWalletEnabled, isBridgeFlow, connectedWallets, }) => {
2
+ import { hasPendingDeviceRegistration } from '../../../../shared/utils/functions/hasPendingDeviceRegistration/hasPendingDeviceRegistration.js';
3
+
4
+ const useInitialViewType = ({ isAuthenticated, bridgeOnboardingCompleted, isMultiWalletEnabled, isBridgeFlow, connectedWallets, user, }) => {
5
+ if (user && hasPendingDeviceRegistration(user)) {
6
+ return 'device-registration';
7
+ }
3
8
  // when multiwallet enabled, and user wants to link wallet
4
9
  // show wallet-list view
5
10
  if (isAuthenticated || bridgeOnboardingCompleted) {
@@ -21,6 +21,7 @@ const mapErrorCodeToTranslation = {
21
21
  [utils.ErrorCode.MISSING_PUBLIC_ADDRESS]: 'dyn_error.missing_public_address',
22
22
  [utils.ErrorCode.CONNECTION_PROPOSAL_EXPIRED]: 'dyn_error.connection_proposal_expired',
23
23
  [utils.ErrorCode.SEI_NOT_ENABLED_IN_KEPLR_WALLET]: 'dyn_error.sei_not_enabled_in_keplr_wallet',
24
+ [utils.RATE_LIMIT_ERROR_CODE]: 'dyn_error.rate_limit_error',
24
25
  };
25
26
  /** A hook that listens to the error context and returns a translated value */
26
27
  const useErrorText = () => {
@@ -1,7 +1,7 @@
1
1
  'use client'
2
2
  import { useMemo } from 'react';
3
3
  import { useTranslation } from 'react-i18next';
4
- import { ErrorCode } from '@dynamic-labs/utils';
4
+ import { ErrorCode, RATE_LIMIT_ERROR_CODE } from '@dynamic-labs/utils';
5
5
  import { useErrorContext } from '../../ErrorContext.js';
6
6
 
7
7
  const mapErrorCodeToTranslation = {
@@ -17,6 +17,7 @@ const mapErrorCodeToTranslation = {
17
17
  [ErrorCode.MISSING_PUBLIC_ADDRESS]: 'dyn_error.missing_public_address',
18
18
  [ErrorCode.CONNECTION_PROPOSAL_EXPIRED]: 'dyn_error.connection_proposal_expired',
19
19
  [ErrorCode.SEI_NOT_ENABLED_IN_KEPLR_WALLET]: 'dyn_error.sei_not_enabled_in_keplr_wallet',
20
+ [RATE_LIMIT_ERROR_CODE]: 'dyn_error.rate_limit_error',
20
21
  };
21
22
  /** A hook that listens to the error context and returns a translated value */
22
23
  const useErrorText = () => {
@@ -4,6 +4,7 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../../../../_virtual/_tslib.cjs');
7
+ var utils = require('@dynamic-labs/utils');
7
8
  require('@dynamic-labs/iconic');
8
9
  require('@dynamic-labs/wallet-connector-core');
9
10
  require('react');
@@ -11,22 +12,48 @@ require('react/jsx-runtime');
11
12
  require('../../context/ViewContext/ViewContext.cjs');
12
13
  var logger = require('../../shared/logger.cjs');
13
14
  require('@dynamic-labs/wallet-book');
14
- require('@dynamic-labs/utils');
15
15
  require('../../utils/constants/colors.cjs');
16
16
  require('../../utils/constants/values.cjs');
17
17
  require('@dynamic-labs/sdk-api-core');
18
18
  require('../../shared/consts/index.cjs');
19
19
  var api = require('./api.cjs');
20
20
 
21
+ const RATE_LIMIT_MESSAGE = 'Too many requests. Please try again later.';
22
+ const NETWORK_ERROR_MESSAGE = 'Request failed. You may be sending too many requests — please wait a moment and try again.';
21
23
  const logResponseError = (e_1, message_1, ...args_1) => _tslib.__awaiter(void 0, [e_1, message_1, ...args_1], void 0, function* (e, message, logLevel = 'error') {
24
+ var _a, _b, _c, _d, _e, _f, _g;
22
25
  if (e instanceof Response) {
23
- const data = yield e.json();
24
- logger.logger[logLevel](message, { error: data.error, status: e.status });
26
+ const requestId = (_b = (_a = e.headers) === null || _a === void 0 ? void 0 : _a.get('x-dyn-request-id')) !== null && _b !== void 0 ? _b : undefined;
27
+ const cfRay = (_d = (_c = e.headers) === null || _c === void 0 ? void 0 : _c.get('cf-ray')) !== null && _d !== void 0 ? _d : undefined;
28
+ let data;
29
+ try {
30
+ data = yield e.json();
31
+ }
32
+ catch (_h) {
33
+ data = {};
34
+ }
35
+ // Normalize 429 responses regardless of body content
36
+ if (e.status === 429) {
37
+ data.code = utils.RATE_LIMIT_ERROR_CODE;
38
+ data.error = (_e = data.error) !== null && _e !== void 0 ? _e : RATE_LIMIT_MESSAGE;
39
+ }
40
+ data.code = (_f = data.code) !== null && _f !== void 0 ? _f : utils.UNKNOWN_ERROR_CODE;
41
+ data.error = (_g = data.error) !== null && _g !== void 0 ? _g : `Request failed with status ${e.status}`;
42
+ logger.logger[logLevel](message, {
43
+ cfRay,
44
+ error: data.error,
45
+ requestId,
46
+ status: e.status,
47
+ });
25
48
  return data;
26
49
  }
27
- else if (e instanceof Error) {
50
+ if (e instanceof Error) {
28
51
  logger.logger[logLevel](message, e);
29
52
  }
53
+ return {
54
+ code: utils.UNKNOWN_ERROR_CODE,
55
+ error: NETWORK_ERROR_MESSAGE,
56
+ };
30
57
  });
31
58
  const getNonce = (environmentId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
32
59
  try {
@@ -1,5 +1,6 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../../_virtual/_tslib.js';
3
+ import { RATE_LIMIT_ERROR_CODE, UNKNOWN_ERROR_CODE } from '@dynamic-labs/utils';
3
4
  import '@dynamic-labs/iconic';
4
5
  import '@dynamic-labs/wallet-connector-core';
5
6
  import 'react';
@@ -7,22 +8,48 @@ import 'react/jsx-runtime';
7
8
  import '../../context/ViewContext/ViewContext.js';
8
9
  import { logger } from '../../shared/logger.js';
9
10
  import '@dynamic-labs/wallet-book';
10
- import '@dynamic-labs/utils';
11
11
  import '../../utils/constants/colors.js';
12
12
  import '../../utils/constants/values.js';
13
13
  import '@dynamic-labs/sdk-api-core';
14
14
  import '../../shared/consts/index.js';
15
15
  import { sdkApi } from './api.js';
16
16
 
17
+ const RATE_LIMIT_MESSAGE = 'Too many requests. Please try again later.';
18
+ const NETWORK_ERROR_MESSAGE = 'Request failed. You may be sending too many requests — please wait a moment and try again.';
17
19
  const logResponseError = (e_1, message_1, ...args_1) => __awaiter(void 0, [e_1, message_1, ...args_1], void 0, function* (e, message, logLevel = 'error') {
20
+ var _a, _b, _c, _d, _e, _f, _g;
18
21
  if (e instanceof Response) {
19
- const data = yield e.json();
20
- logger[logLevel](message, { error: data.error, status: e.status });
22
+ const requestId = (_b = (_a = e.headers) === null || _a === void 0 ? void 0 : _a.get('x-dyn-request-id')) !== null && _b !== void 0 ? _b : undefined;
23
+ const cfRay = (_d = (_c = e.headers) === null || _c === void 0 ? void 0 : _c.get('cf-ray')) !== null && _d !== void 0 ? _d : undefined;
24
+ let data;
25
+ try {
26
+ data = yield e.json();
27
+ }
28
+ catch (_h) {
29
+ data = {};
30
+ }
31
+ // Normalize 429 responses regardless of body content
32
+ if (e.status === 429) {
33
+ data.code = RATE_LIMIT_ERROR_CODE;
34
+ data.error = (_e = data.error) !== null && _e !== void 0 ? _e : RATE_LIMIT_MESSAGE;
35
+ }
36
+ data.code = (_f = data.code) !== null && _f !== void 0 ? _f : UNKNOWN_ERROR_CODE;
37
+ data.error = (_g = data.error) !== null && _g !== void 0 ? _g : `Request failed with status ${e.status}`;
38
+ logger[logLevel](message, {
39
+ cfRay,
40
+ error: data.error,
41
+ requestId,
42
+ status: e.status,
43
+ });
21
44
  return data;
22
45
  }
23
- else if (e instanceof Error) {
46
+ if (e instanceof Error) {
24
47
  logger[logLevel](message, e);
25
48
  }
49
+ return {
50
+ code: UNKNOWN_ERROR_CODE,
51
+ error: NETWORK_ERROR_MESSAGE,
52
+ };
26
53
  });
27
54
  const getNonce = (environmentId) => __awaiter(void 0, void 0, void 0, function* () {
28
55
  try {
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const hasPendingDeviceRegistration = (user) => { var _a; return (_a = user.scope) === null || _a === void 0 ? void 0 : _a.includes('device:register'); };
7
+
8
+ exports.hasPendingDeviceRegistration = hasPendingDeviceRegistration;
@@ -0,0 +1,3 @@
1
+ import { SdkUser } from '@dynamic-labs/sdk-api-core';
2
+ import { UserProfile } from '@dynamic-labs/types';
3
+ export declare const hasPendingDeviceRegistration: (user: UserProfile | SdkUser) => boolean | undefined;
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ const hasPendingDeviceRegistration = (user) => { var _a; return (_a = user.scope) === null || _a === void 0 ? void 0 : _a.includes('device:register'); };
3
+
4
+ export { hasPendingDeviceRegistration };
@@ -0,0 +1 @@
1
+ export { hasPendingDeviceRegistration } from './hasPendingDeviceRegistration';
@@ -4,7 +4,13 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var hasPendingMfaAction = require('../hasPendingMfaAction/hasPendingMfaAction.cjs');
7
+ var hasPendingDeviceRegistration = require('../hasPendingDeviceRegistration/hasPendingDeviceRegistration.cjs');
7
8
 
8
- const hasPendingRequirements = (user) => { var _a; return Boolean((_a = user.missingFields) === null || _a === void 0 ? void 0 : _a.length) || hasPendingMfaAction.hasPendingMfaAction(user); };
9
+ const hasPendingRequirements = (user) => {
10
+ var _a;
11
+ return Boolean((_a = user.missingFields) === null || _a === void 0 ? void 0 : _a.length) ||
12
+ hasPendingMfaAction.hasPendingMfaAction(user) ||
13
+ hasPendingDeviceRegistration.hasPendingDeviceRegistration(user);
14
+ };
9
15
 
10
16
  exports.hasPendingRequirements = hasPendingRequirements;
@@ -1,3 +1,3 @@
1
1
  import { UserProfile } from '@dynamic-labs/types';
2
2
  import { SdkUser } from '@dynamic-labs/sdk-api-core';
3
- export declare const hasPendingRequirements: (user: UserProfile | SdkUser) => boolean;
3
+ export declare const hasPendingRequirements: (user: UserProfile | SdkUser) => boolean | undefined;
@@ -1,6 +1,12 @@
1
1
  'use client'
2
2
  import { hasPendingMfaAction } from '../hasPendingMfaAction/hasPendingMfaAction.js';
3
+ import { hasPendingDeviceRegistration } from '../hasPendingDeviceRegistration/hasPendingDeviceRegistration.js';
3
4
 
4
- const hasPendingRequirements = (user) => { var _a; return Boolean((_a = user.missingFields) === null || _a === void 0 ? void 0 : _a.length) || hasPendingMfaAction(user); };
5
+ const hasPendingRequirements = (user) => {
6
+ var _a;
7
+ return Boolean((_a = user.missingFields) === null || _a === void 0 ? void 0 : _a.length) ||
8
+ hasPendingMfaAction(user) ||
9
+ hasPendingDeviceRegistration(user);
10
+ };
5
11
 
6
12
  export { hasPendingRequirements };
@@ -18,6 +18,7 @@ require('@dynamic-labs/utils');
18
18
  require('../../constants/colors.cjs');
19
19
  require('../../constants/values.cjs');
20
20
  require('@dynamic-labs/sdk-api-core');
21
+ var hasPendingDeviceRegistration = require('../../../shared/utils/functions/hasPendingDeviceRegistration/hasPendingDeviceRegistration.cjs');
21
22
  require('../../../shared/consts/index.cjs');
22
23
  require('../../../events/dynamicEvents.cjs');
23
24
  require('../../../context/CaptchaContext/CaptchaContext.cjs');
@@ -106,7 +107,7 @@ require('../../../widgets/DynamicWidget/views/ManageTotpMfaWidgetView/ManageTotp
106
107
  require('../../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.cjs');
107
108
  require('../../../store/state/tokenBalances.cjs');
108
109
  require('../../../store/state/multichainBalances.cjs');
109
- require('../../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
110
+ var getInitialUrl = require('../../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
110
111
  var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs');
111
112
 
112
113
  /**
@@ -124,10 +125,10 @@ const useSyncDeviceRegistrationFlow = () => {
124
125
  if (!sdkHasLoaded || !userWithMissingInfo) {
125
126
  return;
126
127
  }
127
- if (!((_a = userWithMissingInfo.scope) === null || _a === void 0 ? void 0 : _a.includes('device:register'))) {
128
+ if (!hasPendingDeviceRegistration.hasPendingDeviceRegistration(userWithMissingInfo)) {
128
129
  return;
129
130
  }
130
- const url = window.location.href;
131
+ const url = ((_a = getInitialUrl.getInitialUrl()) === null || _a === void 0 ? void 0 : _a.href) || window.location.href;
131
132
  // If the user arrived via the device registration email link,
132
133
  // complete registration directly without showing the modal
133
134
  if (client.detectDeviceRegistrationRedirect({ url })) {
@@ -151,8 +152,7 @@ const useSyncDeviceRegistrationFlow = () => {
151
152
  if (deviceRegistrationModal && !deviceRegistrationModal.enabled) {
152
153
  return;
153
154
  }
154
- setShowAuthFlow(true, { ignoreIfIsEmbeddedWidget: false });
155
- clearStackAndPush('device-registration');
155
+ setShowAuthFlow(true);
156
156
  });
157
157
  syncDeviceRegistration();
158
158
  return () => {
@@ -14,6 +14,7 @@ import '@dynamic-labs/utils';
14
14
  import '../../constants/colors.js';
15
15
  import '../../constants/values.js';
16
16
  import '@dynamic-labs/sdk-api-core';
17
+ import { hasPendingDeviceRegistration } from '../../../shared/utils/functions/hasPendingDeviceRegistration/hasPendingDeviceRegistration.js';
17
18
  import '../../../shared/consts/index.js';
18
19
  import '../../../events/dynamicEvents.js';
19
20
  import '../../../context/CaptchaContext/CaptchaContext.js';
@@ -102,7 +103,7 @@ import '../../../widgets/DynamicWidget/views/ManageTotpMfaWidgetView/ManageTotpM
102
103
  import '../../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.js';
103
104
  import '../../../store/state/tokenBalances.js';
104
105
  import '../../../store/state/multichainBalances.js';
105
- import '../../../shared/utils/functions/getInitialUrl/getInitialUrl.js';
106
+ import { getInitialUrl } from '../../../shared/utils/functions/getInitialUrl/getInitialUrl.js';
106
107
  import { useInternalDynamicContext } from '../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.js';
107
108
 
108
109
  /**
@@ -120,10 +121,10 @@ const useSyncDeviceRegistrationFlow = () => {
120
121
  if (!sdkHasLoaded || !userWithMissingInfo) {
121
122
  return;
122
123
  }
123
- if (!((_a = userWithMissingInfo.scope) === null || _a === void 0 ? void 0 : _a.includes('device:register'))) {
124
+ if (!hasPendingDeviceRegistration(userWithMissingInfo)) {
124
125
  return;
125
126
  }
126
- const url = window.location.href;
127
+ const url = ((_a = getInitialUrl()) === null || _a === void 0 ? void 0 : _a.href) || window.location.href;
127
128
  // If the user arrived via the device registration email link,
128
129
  // complete registration directly without showing the modal
129
130
  if (detectDeviceRegistrationRedirect({ url })) {
@@ -147,8 +148,7 @@ const useSyncDeviceRegistrationFlow = () => {
147
148
  if (deviceRegistrationModal && !deviceRegistrationModal.enabled) {
148
149
  return;
149
150
  }
150
- setShowAuthFlow(true, { ignoreIfIsEmbeddedWidget: false });
151
- clearStackAndPush('device-registration');
151
+ setShowAuthFlow(true);
152
152
  });
153
153
  syncDeviceRegistration();
154
154
  return () => {
@@ -172,6 +172,12 @@ const EmbeddedWalletExportSection = () => {
172
172
  pushView('reset-password-flow');
173
173
  }, [setShowAuthFlow, pushView]);
174
174
  const handleExportClick = React.useCallback((recoveryPhrase) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
175
+ var _l;
176
+ logger.logger.info('Starting embedded wallet export process', {
177
+ userId: user === null || user === void 0 ? void 0 : user.userId,
178
+ walletId: wallet === null || wallet === void 0 ? void 0 : wallet.id,
179
+ walletName: (_l = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _l === void 0 ? void 0 : _l.name,
180
+ });
175
181
  const stepUpRequired = yield isStepUpRequired({
176
182
  scope: sdkApiCore.TokenScope.Walletexport,
177
183
  });
@@ -181,7 +187,7 @@ const EmbeddedWalletExportSection = () => {
181
187
  requestedScopes: [sdkApiCore.TokenScope.Walletexport],
182
188
  });
183
189
  }
184
- catch (_l) {
190
+ catch (_m) {
185
191
  return;
186
192
  }
187
193
  }
@@ -193,7 +199,7 @@ const EmbeddedWalletExportSection = () => {
193
199
  try {
194
200
  yield promptMfa({ createMfaToken: true });
195
201
  }
196
- catch (_m) {
202
+ catch (_o) {
197
203
  return;
198
204
  }
199
205
  }
@@ -168,6 +168,12 @@ const EmbeddedWalletExportSection = () => {
168
168
  pushView('reset-password-flow');
169
169
  }, [setShowAuthFlow, pushView]);
170
170
  const handleExportClick = useCallback((recoveryPhrase) => __awaiter(void 0, void 0, void 0, function* () {
171
+ var _l;
172
+ logger.info('Starting embedded wallet export process', {
173
+ userId: user === null || user === void 0 ? void 0 : user.userId,
174
+ walletId: wallet === null || wallet === void 0 ? void 0 : wallet.id,
175
+ walletName: (_l = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _l === void 0 ? void 0 : _l.name,
176
+ });
171
177
  const stepUpRequired = yield isStepUpRequired({
172
178
  scope: TokenScope.Walletexport,
173
179
  });
@@ -177,7 +183,7 @@ const EmbeddedWalletExportSection = () => {
177
183
  requestedScopes: [TokenScope.Walletexport],
178
184
  });
179
185
  }
180
- catch (_l) {
186
+ catch (_m) {
181
187
  return;
182
188
  }
183
189
  }
@@ -189,7 +195,7 @@ const EmbeddedWalletExportSection = () => {
189
195
  try {
190
196
  yield promptMfa({ createMfaToken: true });
191
197
  }
192
- catch (_m) {
198
+ catch (_o) {
193
199
  return;
194
200
  }
195
201
  }