From ba2717fb7f20bdbb02f61840aca0372430ca9a4d Mon Sep 17 00:00:00 2001 From: Akmal Djumakhodjaev Date: Mon, 14 Oct 2024 21:52:32 +0800 Subject: [PATCH] fix: set default trade type when switching to vanillas and turbos (#17159) --- .../TradeTypeTabs/trade-type-tabs.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/trader/src/AppV2/Components/TradeParameters/TradeTypeTabs/trade-type-tabs.tsx b/packages/trader/src/AppV2/Components/TradeParameters/TradeTypeTabs/trade-type-tabs.tsx index 70102566b101..162564ee9ac6 100644 --- a/packages/trader/src/AppV2/Components/TradeParameters/TradeTypeTabs/trade-type-tabs.tsx +++ b/packages/trader/src/AppV2/Components/TradeParameters/TradeTypeTabs/trade-type-tabs.tsx @@ -12,9 +12,20 @@ type TTradeTypeTabsProps = { const TradeTypeTabs = observer(({ is_minimized }: TTradeTypeTabsProps) => { const { contract_type, onChange, trade_type_tab, setTradeTypeTab } = useTraderStore(); const tab_list = getTradeTypeTabsList(contract_type); - const initial_index = tab_list.findIndex(tab => - trade_type_tab ? tab.contract_type === trade_type_tab : tab.value === contract_type - ); + let initial_index = 0; + + // If the trade type tab is VANILLALONGPUT or TURBOSSHORT, keep the first tab + if ( + !( + (trade_type_tab === 'VANILLALONGPUT' && contract_type === 'vanillalongcall') || + (trade_type_tab === 'TURBOSSHORT' && contract_type === 'turboslong') + ) + ) { + initial_index = tab_list.findIndex(tab => + trade_type_tab ? tab.contract_type === trade_type_tab : tab.value === contract_type + ); + } + const initial_tab_index = initial_index < 0 ? 0 : initial_index; const [tab_index, setTabIndex] = React.useState(initial_tab_index);