From 2231593dcf3e17c1bcf99a586bc2b91d4188b4ca Mon Sep 17 00:00:00 2001 From: George Usynin <103181646+heorhi-deriv@users.noreply.github.com> Date: Thu, 31 Aug 2023 08:54:52 +0300 Subject: [PATCH] george / PRODQA-1316 / Transfer from Tradershub validation (#9908) * fix: :ambulance: fix active container for TH transfer, fix insufficient balance check * test: :bug: fix tests * fix: :ambulance: fix 'Insufficient balance' condition --- .../__tests__/account-transfer-modal.spec.tsx | 3 +++ .../account-transfer-modal.tsx | 14 ++++++++++---- .../account-transfer-form.tsx | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/appstore/src/components/account-transfer-modal/__tests__/account-transfer-modal.spec.tsx b/packages/appstore/src/components/account-transfer-modal/__tests__/account-transfer-modal.spec.tsx index fe6935f8bf52..a20f72c5cdc3 100644 --- a/packages/appstore/src/components/account-transfer-modal/__tests__/account-transfer-modal.spec.tsx +++ b/packages/appstore/src/components/account-transfer-modal/__tests__/account-transfer-modal.spec.tsx @@ -25,6 +25,7 @@ describe('AccountTransferModal', () => { is_transfer_confirm: false, should_switch_account: false, }, + general_store: { setActiveTab: jest.fn() }, }, }, }); @@ -50,6 +51,7 @@ describe('AccountTransferModal', () => { is_transfer_confirm: false, should_switch_account: false, }, + general_store: { setActiveTab: jest.fn() }, }, }, }); @@ -76,6 +78,7 @@ describe('AccountTransferModal', () => { is_transfer_confirm: false, should_switch_account: true, }, + general_store: { setActiveTab: jest.fn() }, }, }, }); diff --git a/packages/appstore/src/components/account-transfer-modal/account-transfer-modal.tsx b/packages/appstore/src/components/account-transfer-modal/account-transfer-modal.tsx index bc5b0d1955c7..84fedba5c87d 100644 --- a/packages/appstore/src/components/account-transfer-modal/account-transfer-modal.tsx +++ b/packages/appstore/src/components/account-transfer-modal/account-transfer-modal.tsx @@ -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 }, @@ -24,13 +25,18 @@ const AccountTransferModal = observer(({ is_modal_open, toggleModal }: TAccountT const history = useHistory(); React.useEffect(() => { + if (is_modal_open) setActiveTab('account_transfer'); + return () => { - setShouldSwitchAccount(false); - setSelectedAccount({}); - closeModal(); + if (is_modal_open) { + setShouldSwitchAccount(false); + setSelectedAccount({}); + setActiveTab('deposit'); + closeModal(); + } }; // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [is_modal_open]); const modal_title = !is_transfer_confirm && ; diff --git a/packages/cashier/src/pages/account-transfer/account-transfer-form/account-transfer-form.tsx b/packages/cashier/src/pages/account-transfer/account-transfer-form/account-transfer-form.tsx index 15f9fcb3fab1..332f23d59f63 100644 --- a/packages/cashier/src/pages/account-transfer/account-transfer-form/account-transfer-form.tsx +++ b/packages/cashier/src/pages/account-transfer/account-transfer-form/account-transfer-form.tsx @@ -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)) return localize('Insufficient balance'); return undefined;