Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

george / rm73888 / fix Transfer button enabling when amount field is empty #6252

Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ const AccountTransferForm = ({
return undefined;
};

const shouldShowTransferButton = amount => {
return selected_from.currency === selected_to.currency ? !amount : !converter_from_amount;
};

const getAccounts = (type, { is_mt, is_dxtrade }) => {
if (type === 'from') {
if (is_mt) return mt_accounts_from;
Expand Down Expand Up @@ -421,7 +425,7 @@ const AccountTransferForm = ({
validateOnBlur={false}
enableReinitialize
>
{({ errors, handleChange, isSubmitting, touched, setFieldValue, setFieldTouched, setFieldError }) => (
{({ errors, handleChange, isSubmitting, setFieldValue, setFieldError, values }) => (
<React.Fragment>
{isSubmitting || accounts_list.length === 0 ? (
<div className='cashier__loader-wrapper'>
Expand All @@ -447,8 +451,7 @@ const AccountTransferForm = ({
onChangeTransferFrom(e);
handleChange(e);
setFieldValue('amount', '');
setFieldError('amount', '');
setFieldTouched('amount', false);
setTimeout(() => setFieldError('amount', ''));
Copy link
Contributor Author

@heorhi-deriv heorhi-deriv Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when the user tries to transfer amount between deriv_fiat and mt5 account, and then switches to mt5 -> deriv_fiat acc, validationAmount function will execute after setFieldError function and we will see "This field is required" error under the amount input, to avoid this issue we wrapped setFieldError into setTimeout to be sure that setFieldError will be executed last and there is no be an error because of empty amount field

}}
error={selected_from.error}
/>
Expand All @@ -469,8 +472,7 @@ const AccountTransferForm = ({
onChange={e => {
onChangeTransferTo(e);
setFieldValue('amount', '');
setFieldError('amount', '');
setFieldTouched('amount', false);
setTimeout(() => setFieldError('amount', ''));
}}
hint={transfer_to_hint}
error={selected_to.error}
Expand All @@ -485,13 +487,12 @@ const AccountTransferForm = ({
setErrorMessage('');
handleChange(e);
setAccountTransferAmount(e.target.value);
setFieldTouched('amount', true, false);
}}
className='cashier__input dc-input--no-placeholder account-transfer-form__input'
classNameHint='account-transfer-form__hint'
type='text'
label={localize('Amount')}
error={touched.amount && errors.amount ? errors.amount : ''}
error={errors.amount ? errors.amount : ''}
required
trailing_icon={
selected_from.currency ? (
Expand Down Expand Up @@ -591,7 +592,9 @@ const AccountTransferForm = ({
!!selected_to.error ||
!+selected_from.balance ||
!!converter_from_error ||
!!converter_to_error
!!converter_to_error ||
!!errors.amount ||
shouldShowTransferButton(values.amount)
}
primary
large
Expand Down