Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(suite): fix coinmarket back navigation #15930

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading