Skip to content

Commit

Permalink
fix(suite): fix coinmarket back navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhavel committed Dec 12, 2024
1 parent 8871dcb commit 435d651
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
};

Expand All @@ -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 }));
Expand All @@ -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"
/>
<BasicName nameId={fallbackTitle} />
Expand All @@ -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(
Expand Down

0 comments on commit 435d651

Please sign in to comment.