From 223daba73a3cb7daab817a6ff9245d77420bcf47 Mon Sep 17 00:00:00 2001 From: Aizad Ridzo <103104395+aizad-deriv@users.noreply.github.com> Date: Thu, 4 Apr 2024 20:36:05 +0800 Subject: [PATCH] [WALL] Aizad / WALL-3703 / Fix email verification for MT5 Password Modal (#14469) * chore: Fix email verification onclick forgot password * chore: Added error and success block and added icon from quill-icons --- .../SentEmailContent/SentEmailContent.tsx | 4 +- .../MT5PasswordModal/MT5PasswordModal.tsx | 58 ++++++++++++++----- .../public/images/change-password-email.svg | 16 ----- 3 files changed, 44 insertions(+), 34 deletions(-) delete mode 100644 packages/wallets/src/public/images/change-password-email.svg diff --git a/packages/wallets/src/components/SentEmailContent/SentEmailContent.tsx b/packages/wallets/src/components/SentEmailContent/SentEmailContent.tsx index 675ef213a2bc..4c696d769dab 100644 --- a/packages/wallets/src/components/SentEmailContent/SentEmailContent.tsx +++ b/packages/wallets/src/components/SentEmailContent/SentEmailContent.tsx @@ -2,9 +2,9 @@ import React, { FC, Fragment, useEffect, useState } from 'react'; import { Trans } from 'react-i18next'; import { useCountdown } from 'usehooks-ts'; import { useActiveWalletAccount, useSettings, useVerifyEmail } from '@deriv/api-v2'; +import { DerivLightIcEmailSentIcon } from '@deriv/quill-icons'; import { PlatformDetails } from '../../features/cfd/constants'; import useDevice from '../../hooks/useDevice'; -import ChangePassword from '../../public/images/change-password-email.svg'; import { TPlatforms } from '../../types'; import { platformPasswordResetRedirectLink } from '../../utils/cfd'; import { WalletButton } from '../Base'; @@ -48,7 +48,7 @@ const SentEmailContent: FC = ({ description, isInvestorPa } + icon={} renderButtons={() => shouldShowResendEmailReasons && isInvestorPassword ? null : ( = ({ marketType, platform }) => { const { data: accountStatusData } = useAccountStatus(); const { data: activeWalletData } = useActiveWalletAccount(); const { data: availableMT5AccountsData } = useAvailableMT5Accounts(); + const { + error: emailVerificationError, + mutate: emailVerificationMutate, + status: emailVerificationStatus, + } = useVerifyEmail(); const { data: accountStatus } = useAccountStatus(); const { isMobile } = useDevice(); const { getModalState, hide, show } = useModal(); const { data: settingsData } = useSettings(); + const { email } = settingsData; + const [password, setPassword] = useState(''); const isMT5PasswordNotSet = accountStatusData?.is_mt5_password_not_set; @@ -128,16 +137,17 @@ const MT5PasswordModal: React.FC = ({ marketType, platform }) => { tradingPasswordChangeMutateAsync, ]); - const sendEmailVerification = useCallback( - (platform: TPlatforms.All) => { - show( - - - - ); - }, - [show] - ); + const sendEmailVerification = useCallback(() => { + if (email) { + emailVerificationMutate({ + type: 'trading_platform_mt5_password_reset', + url_parameters: { + redirect_to: platformPasswordResetRedirectLink(CFD_PLATFORMS.MT5, activeWalletData?.is_virtual), + }, + verify_email: email, + }); + } + }, [activeWalletData?.is_virtual, email, emailVerificationMutate]); const onSubmitPasswordChange = useCallback( ({ currentPassword, newPassword }: TPlatformPasswordChange) => { @@ -191,7 +201,7 @@ const MT5PasswordModal: React.FC = ({ marketType, platform }) => { } isLoading={tradingPlatformPasswordChangeLoading || createMT5AccountLoading} onPrimaryClick={onSubmit} - onSecondaryClick={() => sendEmailVerification(platform)} + onSecondaryClick={() => sendEmailVerification()} /> ); }, [ @@ -202,7 +212,6 @@ const MT5PasswordModal: React.FC = ({ marketType, platform }) => { mt5Title, onSubmit, password, - platform, sendEmailVerification, tradingPlatformPasswordChangeLoading, ]); @@ -225,7 +234,7 @@ const MT5PasswordModal: React.FC = ({ marketType, platform }) => { formError={tradingPasswordChangeError} isLoading={tradingPlatformPasswordChangeLoading} onClickSubmitPasswordChange={onSubmitPasswordChange} - sendEmailVerification={() => sendEmailVerification(platform)} + sendEmailVerification={() => sendEmailVerification()} /> ); @@ -235,7 +244,7 @@ const MT5PasswordModal: React.FC = ({ marketType, platform }) => { marketType={marketType} onPasswordChange={e => setPassword(e.target.value)} onPrimaryClick={onSubmit} - onSecondaryClick={() => sendEmailVerification(platform)} + onSecondaryClick={() => sendEmailVerification()} password={password} passwordError={createMT5AccountError?.error?.code === 'PasswordError'} platform={mt5Platform} @@ -250,13 +259,30 @@ const MT5PasswordModal: React.FC = ({ marketType, platform }) => { onSubmit, onSubmitPasswordChange, password, - platform, sendEmailVerification, updateMT5Password, tradingPasswordChangeError, tradingPlatformPasswordChangeLoading, ]); + if (emailVerificationStatus === 'error') { + return ( + + ); + } + + if (emailVerificationStatus === 'success') { + return ( + + + + ); + } + if ( createMT5AccountStatus === 'error' && createMT5AccountError?.error?.code !== 'PasswordError' && diff --git a/packages/wallets/src/public/images/change-password-email.svg b/packages/wallets/src/public/images/change-password-email.svg deleted file mode 100644 index 08d233c56ed5..000000000000 --- a/packages/wallets/src/public/images/change-password-email.svg +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - -