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 / PRODQA-1316 / Transfer from Tradershub validation #9908

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('AccountTransferModal', () => {
is_transfer_confirm: false,
should_switch_account: false,
},
general_store: { setActiveTab: jest.fn() },
},
},
});
Expand All @@ -50,6 +51,7 @@ describe('AccountTransferModal', () => {
is_transfer_confirm: false,
should_switch_account: false,
},
general_store: { setActiveTab: jest.fn() },
},
},
});
Expand All @@ -76,6 +78,7 @@ describe('AccountTransferModal', () => {
is_transfer_confirm: false,
should_switch_account: true,
},
general_store: { setActiveTab: jest.fn() },
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const AccountTransferModal = observer(({ is_modal_open, toggleModal }: TAccountT
modules: {
cashier: {
account_transfer: { is_transfer_confirm, should_switch_account, setShouldSwitchAccount },
general_store: { setActiveTab },
},
},
traders_hub: { closeModal, setSelectedAccount },
Expand All @@ -24,13 +25,18 @@ const AccountTransferModal = observer(({ is_modal_open, toggleModal }: TAccountT
const history = useHistory();

React.useEffect(() => {
if (is_modal_open) setActiveTab('account_transfer');
Copy link
Contributor Author

@heorhi-deriv heorhi-deriv Aug 30, 2023

Choose a reason for hiding this comment

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

here we set an active container as 'account_transfer' when the user is clicking on Transfer button in TH and the modal is opening
because previously we set active_container as 'deposit' by default and apply wrong validation


return () => {
setShouldSwitchAccount(false);
setSelectedAccount({});
closeModal();
if (is_modal_open) {
Copy link
Contributor Author

@heorhi-deriv heorhi-deriv Aug 30, 2023

Choose a reason for hiding this comment

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

here we do the cleanup when the user is closing the modal
!!! explanation !!!
the condition if (is_modal_open) is right, there should not be !is_modal_open, because cleanup is firing in the same lifecycle in which is_modal_open is still true.

setShouldSwitchAccount(false);
setSelectedAccount({});
setActiveTab('deposit');
closeModal();
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [is_modal_open]);

const modal_title = !is_transfer_confirm && <Localize i18n_default_text={'Transfer funds to your accounts'} />;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const AccountTransferForm = observer(
});
if (!is_ok) return message;

if (selected_from.balance && Number(selected_from.balance) < Number(amount))
if (typeof selected_from.balance !== 'undefined' && Number(selected_from.balance) < Number(amount))
Copy link
Contributor Author

@heorhi-deriv heorhi-deriv Aug 30, 2023

Choose a reason for hiding this comment

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

need to check if selected.balance is not an undefined and then can do the comparison
cannot use ?? if (selected_from.balance ?? Number(selected_from.balance) < Number(amount)) because we will jump into if condition if selected_from.balance is a truthy value

return localize('Insufficient balance');

return undefined;
Expand Down