From 4b0ea5e8aa3c566d404d4c2d49672abfcd0ab701 Mon Sep 17 00:00:00 2001 From: Adam Havel Date: Thu, 12 Dec 2024 09:52:32 +0100 Subject: [PATCH] fix(suite): fix coinmarket back navigation --- .../CoinmarketLayout/CoinmarketLayoutHeader.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/suite/src/views/wallet/coinmarket/common/CoinmarketLayout/CoinmarketLayoutHeader.tsx b/packages/suite/src/views/wallet/coinmarket/common/CoinmarketLayout/CoinmarketLayoutHeader.tsx index 01535f765b1..01c59ba833d 100644 --- a/packages/suite/src/views/wallet/coinmarket/common/CoinmarketLayout/CoinmarketLayoutHeader.tsx +++ b/packages/suite/src/views/wallet/coinmarket/common/CoinmarketLayout/CoinmarketLayoutHeader.tsx @@ -10,13 +10,19 @@ import { useLayout, useSelector, useTranslation, useDispatch } from 'src/hooks/s import { selectRouteName } from 'src/reducers/suite/routerReducer'; import { TranslationKey, Translation } from 'src/components/suite/Translation'; import { goto } from 'src/actions/suite/routerActions'; +import { CoinmarketTradeType } from 'src/types/coinmarket/coinmarket'; -interface CoinmarketLayoutHeaderProps extends PropsWithChildren {} - -const getBackRoute = (route: Route['name'] | undefined): Route['name'] => { +const getBackRoute = ( + route?: Route['name'], + activeSection?: CoinmarketTradeType, +): Route['name'] => { const routePrefix = 'wallet-coinmarket-'; const match = route?.match(new RegExp(`^${routePrefix}(exchange|buy|sell)-`)); + if (route === `${routePrefix}transactions`) { + return activeSection === 'exchange' ? `${routePrefix}exchange` : `${routePrefix}buy`; + } + return match ? (`${routePrefix}${match[1]}` as Route['name']) : 'wallet-index'; }; @@ -27,6 +33,7 @@ type CoinmarketPageHeaderProps = { const CoinmarketPageHeader = ({ fallbackTitle }: CoinmarketPageHeaderProps) => { const dispatch = useDispatch(); const currentRouteName = useSelector(selectRouteName); + const activeSection = useSelector(state => state.wallet.coinmarket.activeSection); const goToRoute = (route: Route['name']) => () => { dispatch(goto(route, { preserveParams: true })); @@ -39,7 +46,7 @@ const CoinmarketPageHeader = ({ fallbackTitle }: CoinmarketPageHeaderProps) => { icon="caretLeft" variant="tertiary" size="medium" - onClick={goToRoute(getBackRoute(currentRouteName))} + onClick={goToRoute(getBackRoute(currentRouteName, activeSection))} data-testid="@account-subpage/back" /> @@ -61,7 +68,7 @@ const CoinmarketPageHeader = ({ fallbackTitle }: CoinmarketPageHeaderProps) => { ); }; -export const CoinmarketLayoutHeader = ({ children }: CoinmarketLayoutHeaderProps) => { +export const CoinmarketLayoutHeader = ({ children }: PropsWithChildren) => { const { activeSection } = useSelector(state => state.wallet.coinmarket); const { translationString } = useTranslation(); const fallbackTitle = useMemo(