From 8e46efa8a820428cb5597c59f3724e7fb4ca6c73 Mon Sep 17 00:00:00 2001 From: kate-deriv Date: Thu, 17 Oct 2024 12:23:07 +0300 Subject: [PATCH] refactor: chnage selecting title logic --- .../__tests__/take-profit-history.spec.tsx | 11 +++-------- .../TakeProfitHistory/take-profit-history.tsx | 12 ++++-------- .../Containers/ContractDetails/contract-details.tsx | 2 +- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/packages/trader/src/AppV2/Components/TakeProfitHistory/__tests__/take-profit-history.spec.tsx b/packages/trader/src/AppV2/Components/TakeProfitHistory/__tests__/take-profit-history.spec.tsx index 7cea022c5e6f..70ad3b8ad79d 100644 --- a/packages/trader/src/AppV2/Components/TakeProfitHistory/__tests__/take-profit-history.spec.tsx +++ b/packages/trader/src/AppV2/Components/TakeProfitHistory/__tests__/take-profit-history.spec.tsx @@ -29,21 +29,16 @@ describe('TakeProfitHistory component', () => { expect(container).toBeEmptyDOMElement(); }); - it('renders correct History title for both TP and Sl', () => { - render(); + it('renders correct History title for both TP and Sl if is_multiplier === true', () => { + render(); expect(screen.getByText('TP & SL history')).toBeInTheDocument(); }); - it('renders correct History title for TP', () => { + it('renders correct History title for TP if is_multiplier !== true ', () => { render(); expect(screen.getByText('TP history')).toBeInTheDocument(); }); - it('renders correct History title for SL', () => { - render(); - expect(screen.getByText('SL history')).toBeInTheDocument(); - }); - it('renders the correct number of history items', () => { render(); expect(screen.getAllByText(/Test Item/)).toHaveLength(4); diff --git a/packages/trader/src/AppV2/Components/TakeProfitHistory/take-profit-history.tsx b/packages/trader/src/AppV2/Components/TakeProfitHistory/take-profit-history.tsx index 3e5f36fc7061..6a8d079938bc 100644 --- a/packages/trader/src/AppV2/Components/TakeProfitHistory/take-profit-history.tsx +++ b/packages/trader/src/AppV2/Components/TakeProfitHistory/take-profit-history.tsx @@ -11,6 +11,7 @@ type THistory = TContractStore['contract_update_history']; type TContractHistory = { currency?: string; history?: [] | THistory; + is_multiplier?: boolean; }; type TPagination = { @@ -18,22 +19,17 @@ type TPagination = { totalPageCount: number; }; -const TakeProfitHistory = ({ history = [], currency }: TContractHistory) => { +const TakeProfitHistory = ({ history = [], currency, is_multiplier }: TContractHistory) => { const [current_page, setCurrentPage] = useState(0); const items_per_page = 4; const total_pages = Math.ceil(history.length / items_per_page); - const has_tp = history.some(item => item.order_type === 'take_profit' || item.display_name === 'Take profit'); - const has_sl = history.some(item => item.order_type === 'stop_loss' || item.display_name === 'Stop loss'); const handlePageChange = React.useCallback((pagination: TPagination) => { setCurrentPage(pagination.currentPage - 1); }, []); - const getHistoryTitle = () => { - if (has_tp && has_sl) return ; - if (has_tp) return ; - if (has_sl) return ; - }; + const getHistoryTitle = () => + is_multiplier ? : ; if (!history.length) return null; diff --git a/packages/trader/src/AppV2/Containers/ContractDetails/contract-details.tsx b/packages/trader/src/AppV2/Containers/ContractDetails/contract-details.tsx index 1d5246ab39e9..79eef0979935 100644 --- a/packages/trader/src/AppV2/Containers/ContractDetails/contract-details.tsx +++ b/packages/trader/src/AppV2/Containers/ContractDetails/contract-details.tsx @@ -98,7 +98,7 @@ const ContractDetails = observer(() => { {isTpHistoryVisible && update_history.length > 0 && ( - + )} {shouldShowSell && }