From cb10c8a7086389244f1dbb6241098775d0e21eda Mon Sep 17 00:00:00 2001 From: heorhi-deriv Date: Thu, 31 Oct 2024 13:31:27 +0300 Subject: [PATCH] fix(wallets): :ambulance: allow adding an account with common password --- .../WalletPasswordField.tsx | 23 ++++++++++++------- .../WalletPasswordFieldLazy.tsx | 1 + .../MT5PasswordModal/MT5PasswordModal.tsx | 1 + .../screens/EnterPassword/EnterPassword.tsx | 10 ++++---- .../__test__/EnterPassword.spec.tsx | 6 ----- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/packages/wallets/src/components/Base/WalletPasswordField/WalletPasswordField.tsx b/packages/wallets/src/components/Base/WalletPasswordField/WalletPasswordField.tsx index 5be9cba5668a..99d1f9a8aded 100644 --- a/packages/wallets/src/components/Base/WalletPasswordField/WalletPasswordField.tsx +++ b/packages/wallets/src/components/Base/WalletPasswordField/WalletPasswordField.tsx @@ -20,11 +20,15 @@ import PasswordMeter from './PasswordMeter'; import PasswordViewerIcon from './PasswordViewerIcon'; import './WalletPasswordField.scss'; -export const validatePassword = ( - password: string, - mt5Policy: boolean, - localize: ReturnType['localize'] -) => { +type TValidatePasswordProps = { + isMT5PasswordNotSet?: boolean; + localize: ReturnType['localize']; + mt5Policy: boolean; + password: string; +}; + +export const validatePassword = (values: TValidatePasswordProps) => { + const { isMT5PasswordNotSet, localize, mt5Policy, password } = values; const score = mt5Policy ? calculateScoreMT5(password) : calculateScoreCFD(password); let validationErrorMessage = ''; @@ -38,7 +42,9 @@ export const validatePassword = ( } else { cfdSchema(localize).validateSync(password); } - validationErrorMessage = getWarningMessages(localize)[feedback.warning as passwordKeys] ?? ''; + validationErrorMessage = isMT5PasswordNotSet + ? getWarningMessages(localize)[feedback.warning as passwordKeys] ?? '' + : ''; } catch (err) { if (err instanceof ValidationError) { validationErrorMessage = err?.message; @@ -50,6 +56,7 @@ export const validatePassword = ( const WalletPasswordField: React.FC = ({ autoComplete, + isMT5PasswordNotSet, label, mt5Policy = false, name = 'walletPasswordField', @@ -67,8 +74,8 @@ const WalletPasswordField: React.FC = ({ const [errorMessage, setErrorMessage] = useState(''); const { score, validationErrorMessage } = useMemo( - () => validatePassword(password, mt5Policy, localize), - [password, mt5Policy, localize] + () => validatePassword({ isMT5PasswordNotSet, localize, mt5Policy, password }), + [password, mt5Policy, localize, isMT5PasswordNotSet] ); const passwordValidation = mt5Policy ? !validPasswordMT5(password) : !validPassword(password); diff --git a/packages/wallets/src/components/Base/WalletPasswordFieldLazy/WalletPasswordFieldLazy.tsx b/packages/wallets/src/components/Base/WalletPasswordFieldLazy/WalletPasswordFieldLazy.tsx index 722ca5a7798c..4e133a8f26cb 100644 --- a/packages/wallets/src/components/Base/WalletPasswordFieldLazy/WalletPasswordFieldLazy.tsx +++ b/packages/wallets/src/components/Base/WalletPasswordFieldLazy/WalletPasswordFieldLazy.tsx @@ -3,6 +3,7 @@ import { Loader } from '@deriv-com/ui'; import { WalletTextFieldProps } from '../WalletTextField/WalletTextField'; export interface WalletPasswordFieldProps extends WalletTextFieldProps { + isMT5PasswordNotSet?: boolean; mt5Policy?: boolean; // This prop is used to utilize the new password validation for MT5. password: string; passwordError?: boolean; diff --git a/packages/wallets/src/features/cfd/modals/MT5PasswordModal/MT5PasswordModal.tsx b/packages/wallets/src/features/cfd/modals/MT5PasswordModal/MT5PasswordModal.tsx index f17c5b054e9d..409f8b3c2b32 100644 --- a/packages/wallets/src/features/cfd/modals/MT5PasswordModal/MT5PasswordModal.tsx +++ b/packages/wallets/src/features/cfd/modals/MT5PasswordModal/MT5PasswordModal.tsx @@ -292,6 +292,7 @@ const MT5PasswordModal: React.FC = ({ isVirtual, marketType, platform, p return ( = ({ isForgotPasswordLoading, isLoading, + isMT5PasswordNotSet, isTncChecked = true, isVirtual, marketType, @@ -48,8 +50,6 @@ const EnterPassword: React.FC = ({ const { localize } = useTranslations(); const { data } = useActiveWalletAccount(); - const isMT5 = platform === CFD_PLATFORMS.MT5; - const disableButton = isMT5 ? !validPasswordMT5(password) : !validPassword(password); const accountType = data?.is_virtual ? localize('Demo') : localize('Real'); const title = PlatformDetails[platform].title; const marketTypeTitle = @@ -60,6 +60,7 @@ const EnterPassword: React.FC = ({ 'Hint: You may have entered your Deriv password, which is different from your {{title}} password.', { title } ); + const isAddAccountBtnDisabled = !password || isLoading || !isTncChecked; useEffect(() => { if (passwordError) { @@ -89,6 +90,7 @@ const EnterPassword: React.FC = ({ /> = ({