@dynamic-labs/sdk-react-core 3.0.0-alpha.34 → 3.0.0-alpha.36

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 (51) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.cjs +2 -2
  3. package/package.js +2 -2
  4. package/package.json +12 -12
  5. package/src/index.cjs +5 -1
  6. package/src/index.d.ts +1 -1
  7. package/src/index.js +1 -1
  8. package/src/lib/components/OTPVerificationView/OTPVerificationView.cjs +2 -2
  9. package/src/lib/components/OTPVerificationView/OTPVerificationView.js +2 -2
  10. package/src/lib/data/api/mfa/mfa.cjs +9 -4
  11. package/src/lib/data/api/mfa/mfa.js +9 -4
  12. package/src/lib/locale/en/translation.cjs +14 -8
  13. package/src/lib/locale/en/translation.d.ts +12 -6
  14. package/src/lib/locale/en/translation.js +14 -8
  15. package/src/lib/styles/index.shadow.cjs +1 -1
  16. package/src/lib/styles/index.shadow.js +1 -1
  17. package/src/lib/utils/functions/index.d.ts +1 -0
  18. package/src/lib/utils/functions/isValidMfaRecoveryCode/index.d.ts +1 -0
  19. package/src/lib/utils/functions/isValidMfaRecoveryCode/isValidMfaRecoveryCode.cjs +11 -0
  20. package/src/lib/utils/functions/isValidMfaRecoveryCode/isValidMfaRecoveryCode.d.ts +1 -0
  21. package/src/lib/utils/functions/isValidMfaRecoveryCode/isValidMfaRecoveryCode.js +7 -0
  22. package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs +3 -1
  23. package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +3 -1
  24. package/src/lib/utils/hooks/useEmbeddedWallet/index.d.ts +1 -0
  25. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.cjs +4 -3
  26. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.d.ts +1 -1
  27. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.js +4 -3
  28. package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/index.d.ts +1 -0
  29. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.cjs +8 -5
  30. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.js +8 -5
  31. package/src/lib/utils/hooks/useSyncMfaFlow/useSyncMfaFlow.cjs +5 -1
  32. package/src/lib/utils/hooks/useSyncMfaFlow/useSyncMfaFlow.js +5 -1
  33. package/src/lib/views/MfaChooseDeviceView/MfaChooseDeviceView.cjs +27 -12
  34. package/src/lib/views/MfaChooseDeviceView/MfaChooseDeviceView.d.ts +5 -2
  35. package/src/lib/views/MfaChooseDeviceView/MfaChooseDeviceView.js +28 -13
  36. package/src/lib/views/MfaChooseDeviceView/getMfaOptions/getMfaOptions.cjs +29 -0
  37. package/src/lib/views/MfaChooseDeviceView/getMfaOptions/getMfaOptions.d.ts +11 -0
  38. package/src/lib/views/MfaChooseDeviceView/getMfaOptions/getMfaOptions.js +25 -0
  39. package/src/lib/views/MfaChooseDeviceView/getMfaOptions/index.d.ts +1 -0
  40. package/src/lib/views/MfaRecoveryView/MfaRecoveryView.cjs +12 -12
  41. package/src/lib/views/MfaRecoveryView/MfaRecoveryView.js +13 -13
  42. package/src/lib/views/MfaSecureDeviceView/MfaSecureDeviceView.cjs +1 -1
  43. package/src/lib/views/MfaSecureDeviceView/MfaSecureDeviceView.js +1 -1
  44. package/src/lib/views/MfaVerificationView/MfaVerificationView.cjs +10 -2
  45. package/src/lib/views/MfaVerificationView/MfaVerificationView.d.ts +3 -1
  46. package/src/lib/views/MfaVerificationView/MfaVerificationView.js +11 -3
  47. package/src/lib/views/viewToComponentMap.d.ts +2 -2
  48. package/src/lib/utils/functions/validateMfaRecoveryCode/index.d.ts +0 -1
  49. package/src/lib/utils/functions/validateMfaRecoveryCode/validateMfaRecoveryCode.cjs +0 -11
  50. package/src/lib/utils/functions/validateMfaRecoveryCode/validateMfaRecoveryCode.d.ts +0 -1
  51. package/src/lib/utils/functions/validateMfaRecoveryCode/validateMfaRecoveryCode.js +0 -7
@@ -1,6 +1,6 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../../_virtual/_tslib.js';
3
- import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
4
4
  import { useState } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import '../../components/Accordion/components/AccordionItem/AccordionItem.js';
@@ -19,6 +19,7 @@ import '../../utils/constants/values.js';
19
19
  import '../../shared/utils/classes/storage/localStorage.js';
20
20
  import '../../shared/utils/classes/storage/sessionStorage.js';
21
21
  import '../../shared/consts/index.js';
22
+ import { useInternalDynamicContext } from '../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.js';
22
23
  import '../../context/CaptchaContext/CaptchaContext.js';
23
24
  import '../../context/ErrorContext/ErrorContext.js';
24
25
  import '@dynamic-labs/multi-wallet';
@@ -26,6 +27,7 @@ import 'react-international-phone';
26
27
  import '../../config/ApiEndpoint.js';
27
28
  import '@dynamic-labs/store';
28
29
  import '../../locale/locale.js';
30
+ import { isValidMfaRecoveryCode } from '../../utils/functions/isValidMfaRecoveryCode/isValidMfaRecoveryCode.js';
29
31
  import '../../context/AccessDeniedContext/AccessDeniedContext.js';
30
32
  import '../../context/AccountExistsContext/AccountExistsContext.js';
31
33
  import '../../context/UserWalletsContext/UserWalletsContext.js';
@@ -82,7 +84,6 @@ import '../../widgets/DynamicBridgeWidget/views/WalletsView/components/Secondary
82
84
  import '@hcaptcha/react-hcaptcha';
83
85
  import { useMfa } from '../../utils/hooks/useMfa/useMfa.js';
84
86
  import '../../context/IpConfigurationContext/IpConfigurationContext.js';
85
- import { validateMfaRecoveryCode } from '../../utils/functions/validateMfaRecoveryCode/validateMfaRecoveryCode.js';
86
87
  import '../../context/SendBalanceContext/SendBalanceContext.js';
87
88
  import '../../context/ConnectWithOtpContext/ConnectWithOtpContext.js';
88
89
  import '../../context/ConnectWithOtpContext/constants.js';
@@ -92,36 +93,35 @@ import '../../components/InlineWidget/InlineWidget.js';
92
93
  import 'qrcode';
93
94
 
94
95
  const MfaRecoveryView = () => {
96
+ var _a;
95
97
  const { t } = useTranslation();
98
+ const { projectSettings } = useInternalDynamicContext();
96
99
  const { authRecoveryCode } = useMfa();
97
100
  const [code, setCode] = useState('');
98
- const [isValid, setIsValid] = useState(false);
101
+ const [isLoading, setIsLoading] = useState(false);
99
102
  const [error, setError] = useState('');
100
- const openHelp = () => undefined;
103
+ const supportEmail = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.general) === null || _a === void 0 ? void 0 : _a.supportEmail;
101
104
  const handleRecovery = () => __awaiter(void 0, void 0, void 0, function* () {
102
105
  if (!code) {
103
- setIsValid(false);
104
106
  return;
105
107
  }
106
108
  try {
109
+ setIsLoading(true);
107
110
  yield authRecoveryCode(code);
108
111
  }
109
112
  catch (e) {
110
113
  setError(e.message || 'Something went wrong');
111
114
  }
115
+ finally {
116
+ setIsLoading(false);
117
+ }
112
118
  });
113
119
  const handleCodeChanged = (event) => {
114
120
  const inputCode = event.target.value;
115
121
  setCode(inputCode);
116
- if (validateMfaRecoveryCode(inputCode)) {
117
- setIsValid(true);
118
- }
119
- else {
120
- setIsValid(false);
121
- setError('');
122
- }
122
+ setError('');
123
123
  };
124
- return (jsxs("div", { className: 'mfa-recovery-view', children: [error && jsx(ErrorContainer, { children: error }), !error && !isValid && (jsx(IconWithSpinner, { Icon: MfaRecoveryScreenIcon, isSpinning: !error && !isValid, iconSize: 96 })), jsx("div", { className: 'mfa-recovery-view__body', children: jsx(Typography, { variant: 'body_normal', weight: 'regular', color: 'secondary', children: t('dyn_mfa.recovery_view.body') }) }), jsxs("div", { className: 'mfa-recovery-view__actions', children: [jsx(Input, { id: 'mfa-recovery-input', "data-testid": 'mfa-recovery-input', label: t('dyn_mfa.recovery_view.input_label'), onChange: handleCodeChanged, value: code }), jsx(Button, { expanded: true, buttonVariant: 'brand-primary', disabled: !isValid, onClick: handleRecovery, dataTestId: 'mfa-recovery-submit', children: jsx(Typography, { children: t('dyn_mfa.recovery_view.button_label') }) })] }), jsxs("div", { className: 'mfa-recovery-view__get-help', children: [jsx(Typography, { variant: 'body_small', color: 'secondary', children: t('dyn_mfa.recovery_view.get_help.description') }), jsx("button", { onClick: openHelp, children: jsx(Typography, { variant: 'body_small', color: 'link', children: t('dyn_mfa.recovery_view.get_help.button_label') }) })] })] }));
124
+ return (jsxs(Fragment, { children: [error && jsx(ErrorContainer, { children: error }), jsxs("div", { className: 'mfa-recovery-view', children: [jsx(IconWithSpinner, { Icon: MfaRecoveryScreenIcon, isSpinning: isLoading, iconSize: 96 }), jsx("div", { className: 'mfa-recovery-view__body', children: jsx(Typography, { variant: 'body_normal', weight: 'regular', color: 'secondary', children: t('dyn_mfa.recovery_view.body') }) }), jsxs("div", { className: 'mfa-recovery-view__actions', children: [jsx(Input, { id: 'mfa-recovery-input', "data-testid": 'mfa-recovery-input', label: t('dyn_mfa.recovery_view.input_label'), onChange: handleCodeChanged, value: code }), jsx(Button, { expanded: true, buttonVariant: 'brand-primary', disabled: isLoading || !isValidMfaRecoveryCode(code), onClick: handleRecovery, dataTestId: 'mfa-recovery-submit', children: jsx(Typography, { children: t('dyn_mfa.recovery_view.button_label') }) })] }), supportEmail && (jsxs("div", { className: 'mfa-recovery-view__get-help', children: [jsx(Typography, { variant: 'body_small', color: 'secondary', children: t('dyn_mfa.recovery_view.get_help.description') }), jsx(Typography, { variant: 'body_small', color: 'link', children: jsx("a", { href: `mailto:${supportEmail}`, children: t('dyn_mfa.recovery_view.get_help.button_label') }) })] }))] })] }));
125
125
  };
126
126
 
127
127
  export { MfaRecoveryView };
@@ -107,7 +107,7 @@ const MfaSecureDeviceView = ({ type }) => {
107
107
  const onMfaVerificationBackClick = () => {
108
108
  setView('mfa-secure-device', { type });
109
109
  };
110
- setView('mfa-verification', { type }, {
110
+ setView('mfa-verification', { showBackButton: true, type }, {
111
111
  onBackClick: onMfaVerificationBackClick,
112
112
  });
113
113
  };
@@ -103,7 +103,7 @@ const MfaSecureDeviceView = ({ type }) => {
103
103
  const onMfaVerificationBackClick = () => {
104
104
  setView('mfa-secure-device', { type });
105
105
  };
106
- setView('mfa-verification', { type }, {
106
+ setView('mfa-verification', { showBackButton: true, type }, {
107
107
  onBackClick: onMfaVerificationBackClick,
108
108
  });
109
109
  };
@@ -51,6 +51,7 @@ require('../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
51
51
  require('@dynamic-labs/rpc-providers');
52
52
  require('../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
53
53
  require('../../components/Alert/Alert.cjs');
54
+ var TextButton = require('../../components/TextButton/TextButton.cjs');
54
55
  require('../../components/ShadowDOM/ShadowDOM.cjs');
55
56
  require('../../components/IconButton/IconButton.cjs');
56
57
  require('../../components/InlineWidget/InlineWidget.cjs');
@@ -93,7 +94,7 @@ require('../../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs');
93
94
  require('../../context/ConnectWithOtpContext/constants.cjs');
94
95
  require('../../context/ReinitializeContext/ReinitializeContextProvider.cjs');
95
96
 
96
- const MfaVerificationView = ({ type }) => {
97
+ const MfaVerificationView = ({ type, isInitialSetup = false, showBackButton = false, }) => {
97
98
  const { t } = reactI18next.useTranslation();
98
99
  const { userWithMissingInfo } = useDynamicContext.useDynamicContext();
99
100
  const { setView } = ViewContext.useViewContext();
@@ -120,7 +121,14 @@ const MfaVerificationView = ({ type }) => {
120
121
  const onSubmit = (code) => {
121
122
  setCode(code);
122
123
  };
123
- return (jsxRuntime.jsx(OTPVerificationView.OTPVerificationView, { MainIcon: passwordHero.ReactComponent, error: error, hideHeader: true, isLoading: isLoading, onPinComplete: onSubmit, isValid: Boolean(isValid), onPinChange: onCodeChange, description: t('dyn_mfa.otp_verification_view.body') }));
124
+ const onClickBack = () => {
125
+ if (!isInitialSetup) {
126
+ setView('mfa-choose-device', { isInitialSetup });
127
+ return;
128
+ }
129
+ setView('mfa-secure-device', { type });
130
+ };
131
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(OTPVerificationView.OTPVerificationView, { MainIcon: passwordHero.ReactComponent, error: error, isLoading: isLoading, onPinComplete: onSubmit, isValid: Boolean(isValid), onPinChange: onCodeChange, description: t('dyn_mfa.otp_verification_view.body'), onClickBack: showBackButton ? onClickBack : undefined }), !isInitialSetup && (jsxRuntime.jsx("div", { className: 'mfa-verification-view__choose-another-method', children: jsxRuntime.jsx(TextButton.TextButton, { className: 'mfa-verification-view__choose-another-method-button', onClick: () => setView('mfa-choose-device', { isInitialSetup }), copykey: 'dyn_mfa.otp_verification_view.choose_another_method', children: t('dyn_mfa.otp_verification_view.choose_another_method') }) }))] }));
124
132
  };
125
133
 
126
134
  exports.MfaVerificationView = MfaVerificationView;
@@ -2,5 +2,7 @@
2
2
  import { MFADeviceType } from '@dynamic-labs/sdk-api-core';
3
3
  export type MfaVerificationViewProps = {
4
4
  type?: MFADeviceType;
5
+ isInitialSetup?: boolean;
6
+ showBackButton?: boolean;
5
7
  };
6
- export declare const MfaVerificationView: ({ type }: MfaVerificationViewProps) => JSX.Element;
8
+ export declare const MfaVerificationView: ({ type, isInitialSetup, showBackButton, }: MfaVerificationViewProps) => JSX.Element;
@@ -1,6 +1,6 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../../_virtual/_tslib.js';
3
- import { jsx } from 'react/jsx-runtime';
3
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
4
4
  import { useState } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import { DynamicError } from '@dynamic-labs/utils';
@@ -47,6 +47,7 @@ import '../../context/UserFieldEditorContext/UserFieldEditorContext.js';
47
47
  import '@dynamic-labs/rpc-providers';
48
48
  import '../../components/Accordion/components/AccordionItem/AccordionItem.js';
49
49
  import '../../components/Alert/Alert.js';
50
+ import { TextButton } from '../../components/TextButton/TextButton.js';
50
51
  import '../../components/ShadowDOM/ShadowDOM.js';
51
52
  import '../../components/IconButton/IconButton.js';
52
53
  import '../../components/InlineWidget/InlineWidget.js';
@@ -89,7 +90,7 @@ import '../../context/ConnectWithOtpContext/ConnectWithOtpContext.js';
89
90
  import '../../context/ConnectWithOtpContext/constants.js';
90
91
  import '../../context/ReinitializeContext/ReinitializeContextProvider.js';
91
92
 
92
- const MfaVerificationView = ({ type }) => {
93
+ const MfaVerificationView = ({ type, isInitialSetup = false, showBackButton = false, }) => {
93
94
  const { t } = useTranslation();
94
95
  const { userWithMissingInfo } = useDynamicContext();
95
96
  const { setView } = useViewContext();
@@ -116,7 +117,14 @@ const MfaVerificationView = ({ type }) => {
116
117
  const onSubmit = (code) => {
117
118
  setCode(code);
118
119
  };
119
- return (jsx(OTPVerificationView, { MainIcon: SvgPasswordHero, error: error, hideHeader: true, isLoading: isLoading, onPinComplete: onSubmit, isValid: Boolean(isValid), onPinChange: onCodeChange, description: t('dyn_mfa.otp_verification_view.body') }));
120
+ const onClickBack = () => {
121
+ if (!isInitialSetup) {
122
+ setView('mfa-choose-device', { isInitialSetup });
123
+ return;
124
+ }
125
+ setView('mfa-secure-device', { type });
126
+ };
127
+ return (jsxs(Fragment, { children: [jsx(OTPVerificationView, { MainIcon: SvgPasswordHero, error: error, isLoading: isLoading, onPinComplete: onSubmit, isValid: Boolean(isValid), onPinChange: onCodeChange, description: t('dyn_mfa.otp_verification_view.body'), onClickBack: showBackButton ? onClickBack : undefined }), !isInitialSetup && (jsx("div", { className: 'mfa-verification-view__choose-another-method', children: jsx(TextButton, { className: 'mfa-verification-view__choose-another-method-button', onClick: () => setView('mfa-choose-device', { isInitialSetup }), copykey: 'dyn_mfa.otp_verification_view.choose_another_method', children: t('dyn_mfa.otp_verification_view.choose_another_method') }) }))] }));
120
128
  };
121
129
 
122
130
  export { MfaVerificationView };
@@ -27,11 +27,11 @@ export declare const viewToComponentMap: {
27
27
  'merge-user-accounts': import("react").FC<import("./MergeUserAccountsView/MergeUserAccountsView").MergeUserAccountsViewProps>;
28
28
  'merge-user-accounts-conflicts': import("react").FC<import("./MergeUserAccountsConflictsView/MergeUserAccountsConflictsView").MergeUserAccountsConflictsViewProps>;
29
29
  'merge-user-accounts-with-same-email': import("react").FC<import("./MergeUserAccountsWithSameEmailView/MergeUserAccountsWithSameEmailView").MergeUserAccountsWithSameEmailViewProps>;
30
- 'mfa-choose-device': () => JSX.Element;
30
+ 'mfa-choose-device': import("react").FC<import("./MfaChooseDeviceView").MfaChooseDeviceViewProps>;
31
31
  'mfa-display-backup-codes': () => JSX.Element;
32
32
  'mfa-recovery': import("react").FC;
33
33
  'mfa-secure-device': ({ type }: import("./MfaSecureDeviceView").MfaSecureDeviceViewProps) => JSX.Element;
34
- 'mfa-verification': ({ type }: import("./MfaVerificationView").MfaVerificationViewProps) => JSX.Element;
34
+ 'mfa-verification': ({ type, isInitialSetup, showBackButton, }: import("./MfaVerificationView").MfaVerificationViewProps) => JSX.Element;
35
35
  'multi-wallet-wallet-list': ({ isWalletConnectList, }: import("./WalletList").WalletListProps) => JSX.Element;
36
36
  'network-not-supported': () => JSX.Element | null;
37
37
  'network-not-supported-manual': import("react").FC;
@@ -1 +0,0 @@
1
- export { validateMfaRecoveryCode } from './validateMfaRecoveryCode';
@@ -1,11 +0,0 @@
1
- 'use client'
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- const validateMfaRecoveryCode = (text) => {
7
- const regex = /^(\w+\s){23}\w+$/;
8
- return regex.test(text);
9
- };
10
-
11
- exports.validateMfaRecoveryCode = validateMfaRecoveryCode;
@@ -1 +0,0 @@
1
- export declare const validateMfaRecoveryCode: (text: string) => boolean;
@@ -1,7 +0,0 @@
1
- 'use client'
2
- const validateMfaRecoveryCode = (text) => {
3
- const regex = /^(\w+\s){23}\w+$/;
4
- return regex.test(text);
5
- };
6
-
7
- export { validateMfaRecoveryCode };