Skip to content
8 changes: 5 additions & 3 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1316,11 +1316,13 @@ const ROUTES = {
},
SETTINGS_WALLET_REPORT_CARD_LOST_OR_DAMAGED: {
route: 'settings/wallet/card/:cardID/report-card-lost-or-damaged',
getRoute: (cardID: string) => `settings/wallet/card/${cardID}/report-card-lost-or-damaged` as const,
getRoute: (cardID: string, isFromDomainCardDetail?: boolean) =>
`settings/wallet/card/${cardID}/report-card-lost-or-damaged${isFromDomainCardDetail ? '?isFromDomainCardDetail=true' : ''}` as const,
},
SETTINGS_WALLET_REPORT_CARD_LOST_OR_DAMAGED_CONFIRM_MAGIC_CODE: {
route: 'settings/wallet/card/:cardID/report-card-lost-or-damaged/:reason/confirm-magic-code',
getRoute: (cardID: string, reason: ReplacementReason) => `settings/wallet/card/${cardID}/report-card-lost-or-damaged/${reason}/confirm-magic-code` as const,
getRoute: (cardID: string, reason: ReplacementReason, isFromDomainCardDetail?: boolean) =>
`settings/wallet/card/${cardID}/report-card-lost-or-damaged/${reason}/confirm-magic-code${isFromDomainCardDetail ? '?isFromDomainCardDetail=true' : ''}` as const,
},
SETTINGS_WALLET_CARD_CHANGE_PIN: {
route: 'settings/wallet/card/:cardID/change-pin',
Expand All @@ -1332,7 +1334,7 @@ const ROUTES = {
},
SETTINGS_WALLET_CARD_ACTIVATE: {
route: 'settings/wallet/card/:cardID/activate',
getRoute: (cardID: string) => `settings/wallet/card/${cardID}/activate` as const,
getRoute: (cardID: string, isFromDomainCardDetail?: boolean) => `settings/wallet/card/${cardID}/activate${isFromDomainCardDetail ? '?isFromDomainCardDetail=true' : ''}` as const,
},
SETTINGS_WALLET_TRAVEL_CVV: 'settings/wallet/travel-cvv',
SETTINGS_WALLET_TRAVEL_CVV_VERIFY_ACCOUNT: `settings/wallet/travel-cvv/${VERIFY_ACCOUNT}`,
Expand Down
9 changes: 5 additions & 4 deletions src/components/ScreenWrapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {ForwardedFSClassProps} from '@libs/Fullstory/types';
import getPlatform from '@libs/getPlatform';
import mergeRefs from '@libs/mergeRefs';
import NarrowPaneContext from '@libs/Navigation/AppNavigator/Navigators/NarrowPaneContext';
import doesInitialURLMatchActiveRoute from '@libs/Navigation/helpers/doesInitialURLMatchActiveRoute';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackNavigationProp} from '@libs/Navigation/PlatformStackNavigation/types';
import type {ReportsSplitNavigatorParamList, RightModalNavigatorParamList, RootNavigatorParamList} from '@libs/Navigation/types';
Expand Down Expand Up @@ -191,20 +192,20 @@ function ScreenWrapper({
useEffect(() => {
Navigation.isNavigationReady().then(() => setInitialActiveRouteWithoutParams(Navigation.getActiveRouteWithoutParams()));
}, []);
const initialURLWithoutParams = initialURL?.replaceAll(/\?.*/g, '');
const doesInitialURLMatchActiveRoute = !!initialURLWithoutParams?.endsWith(Navigation.getActiveRouteWithoutParams() || initialActiveRouteWithoutParams);
const activeRouteWithoutParams = Navigation.getActiveRouteWithoutParams() || initialActiveRouteWithoutParams;
const initialURLMatchesActiveRoute = doesInitialURLMatchActiveRoute(initialURL, activeRouteWithoutParams);

// A multifactor authentication flow (e.g. Face ID to reveal UK/EU card details) renders in an independent navigation tree
// overlaid above the single NewDot entry, and each MFA screen renders its own ScreenWrapper. Navigation.getActiveRouteWithoutParams()
// still reports the underlying NewDot route while the overlay is up, so doesInitialURLMatchActiveRoute is true on the MFA screens too.
// still reports the underlying NewDot route while the overlay is up, so initialURLMatchesActiveRoute is true on the MFA screens too.
// usePreventRemove calls e.preventDefault() unconditionally whenever the guard is active, so guarding these instances would consume the
// MFA navigator's own stack actions (e.g. replacing the magic-code page with the Face ID prompt, or popping the outcome screen on close),
// blocking transitions within the flow. Guard only the outer NewDot ScreenWrapper, never the ScreenWrappers inside the MFA overlay.
// NavigationRouteContext is undefined when tests mock @react-navigation/native without re-exporting it, so fall back to a noop context to keep useContext valid.
const route = useContext(NavigationRouteContext ?? FallbackRouteContext);
const isMfaOverlayScreen = !!route && MFA_OVERLAY_SCREENS.has(route.name);

usePreventRemove(isSingleNewDotEntry && doesInitialURLMatchActiveRoute && !shouldBlockSingleEntryOldAppExit && !isMfaOverlayScreen, () => {
usePreventRemove(isSingleNewDotEntry && initialURLMatchesActiveRoute && !shouldBlockSingleEntryOldAppExit && !isMfaOverlayScreen, () => {
if (!CONFIG.IS_HYBRID_APP) {
return;
}
Expand Down
26 changes: 26 additions & 0 deletions src/libs/Navigation/helpers/doesInitialURLMatchActiveRoute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type {Route} from '@src/ROUTES';

/**
* Reporting a card lost from a card deep-linked by OldDot (settings/card/:cardID) deletes the original card and lands the
* user on the replacement card's route. The cardID segment changes, so a plain comparison would no longer match the initial
* URL. Normalize the cardID segment so the same card-detail screen still counts as a match regardless of which card is shown.
*/
function normalizeDomainCardDetailRoute(path: string): string {
return path.replace(/(^|\/)settings\/card\/[^/?]+/, '$1settings/card/:cardID');
}

/**
* Whether the initial URL that launched NewDot still matches the currently active route. Used to decide whether the
* HybridApp single-entry back handoff should fire (i.e. the user is still on the screen OldDot deep-linked into).
*/
function doesInitialURLMatchActiveRoute(initialURL: Route | null, activeRouteWithoutParams: string): boolean {
const initialURLWithoutParams = initialURL?.replaceAll(/\?.*/g, '');

if (!initialURLWithoutParams) {
return false;
}

return normalizeDomainCardDetailRoute(initialURLWithoutParams).endsWith(normalizeDomainCardDetailRoute(activeRouteWithoutParams));
}
Comment on lines +16 to +24

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: this approach feels a bit ad hoc, but I can't think of a better way.


export default doesInitialURLMatchActiveRoute;
9 changes: 9 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ type SettingsNavigatorParamList = {
[SCREENS.SETTINGS.WALLET.CARD_ACTIVATE]: {
/** cardID of selected card */
cardID: string;

/** Whether the flow was launched from the top-level DomainCard route (deep-linked from OldDot) rather than the Settings wallet card route */
isFromDomainCardDetail?: string;
};
[SCREENS.SETTINGS.WALLET.CARD_CHANGE_PIN]: {
/** cardID of selected card */
Expand Down Expand Up @@ -1222,13 +1225,19 @@ type SettingsNavigatorParamList = {
[SCREENS.SETTINGS.REPORT_CARD_LOST_OR_DAMAGED]: {
/** cardID of selected card */
cardID: string;

/** Whether the flow was launched from the top-level DomainCard route (deep-linked from OldDot) rather than the Settings wallet card route */
isFromDomainCardDetail?: string;
};
[SCREENS.SETTINGS.REPORT_CARD_LOST_OR_DAMAGED_CONFIRM_MAGIC_CODE]: {
/** cardID of selected card */
cardID: string;

/** Reason for replacing the card */
reason: ReplacementReason;

/** Whether the flow was launched from the top-level DomainCard route (deep-linked from OldDot) rather than the Settings wallet card route */
isFromDomainCardDetail?: string;
};
[SCREENS.SETTINGS.DYNAMIC_KEYBOARD_SHORTCUTS]: undefined;
[SCREENS.WORKSPACE.TAX_CREATE]: {
Expand Down
9 changes: 7 additions & 2 deletions src/pages/settings/Wallet/ActivatePhysicalCardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ type ActivatePhysicalCardPageProps = PlatformStackScreenProps<SettingsNavigatorP

function ActivatePhysicalCardPage({
route: {
params: {cardID = ''},
params: {cardID = '', isFromDomainCardDetail},
},
}: ActivatePhysicalCardPageProps) {
return <ActivatePhysicalCardPageBase cardID={cardID} />;
return (
<ActivatePhysicalCardPageBase
cardID={cardID}
isFromDomainCardDetail={!!isFromDomainCardDetail}
/>
);
}

export default ActivatePhysicalCardPage;
18 changes: 13 additions & 5 deletions src/pages/settings/Wallet/ActivatePhysicalCardPageBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ import {getEmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject';
type ActivatePhysicalCardPageBaseProps = {
cardID?: string;
navigateBackTo?: Route;

/** Whether the flow was launched from the top-level DomainCard route (deep-linked from OldDot) rather than the Settings wallet card route */
isFromDomainCardDetail?: boolean;
};

const LAST_FOUR_DIGITS_LENGTH = 4;

function ActivatePhysicalCardPageBase({cardID = '', navigateBackTo}: ActivatePhysicalCardPageBaseProps) {
function ActivatePhysicalCardPageBase({cardID = '', navigateBackTo, isFromDomainCardDetail = false}: ActivatePhysicalCardPageBaseProps) {
const theme = useTheme();
const styles = useThemeStyles();
const {isExtraSmallScreenHeight} = useResponsiveLayout();
Expand All @@ -48,15 +51,18 @@ function ActivatePhysicalCardPageBase({cardID = '', navigateBackTo}: ActivatePhy
const activateCardCodeInputRef = useRef<MagicCodeInputHandle>(null);

/**
* If state of the card is CONST.EXPENSIFY_CARD.STATE.OPEN, navigate to card details screen.
* If state of the card is CONST.EXPENSIFY_CARD.STATE.OPEN, return to the card details screen.
*/
useEffect(() => {
if (inactiveCard?.state !== CONST.EXPENSIFY_CARD.STATE.OPEN || inactiveCard?.isLoading) {
return;
}

Navigation.navigate(ROUTES.SETTINGS_WALLET_DOMAIN_CARD.getRoute(cardID));
}, [cardID, cardList, inactiveCard?.isLoading, inactiveCard?.state]);
// Collapse the activate flow back onto the existing card route instead of pushing a new one, so the user is not left
// with a duplicate card details screen and a stale route to back through.
const cardDetailRoute = isFromDomainCardDetail ? ROUTES.SETTINGS_DOMAIN_CARD_DETAIL.getRoute(cardID) : ROUTES.SETTINGS_WALLET_DOMAIN_CARD.getRoute(cardID);
Navigation.goBack(cardDetailRoute, {compareParams: false});
}, [cardID, cardList, inactiveCard?.isLoading, inactiveCard?.state, isFromDomainCardDetail]);

useEffect(() => {
if (!inactiveCard?.cardID) {
Expand Down Expand Up @@ -100,7 +106,9 @@ function ActivatePhysicalCardPageBase({cardID = '', navigateBackTo}: ActivatePhy
return (
<IllustratedHeaderPageLayout
title={translate('activateCardPage.activateCard')}
onBackButtonPress={() => Navigation.goBack(navigateBackTo ?? ROUTES.SETTINGS_WALLET_DOMAIN_CARD.getRoute(cardID))}
onBackButtonPress={() =>
Navigation.goBack(navigateBackTo ?? (isFromDomainCardDetail ? ROUTES.SETTINGS_DOMAIN_CARD_DETAIL.getRoute(cardID) : ROUTES.SETTINGS_WALLET_DOMAIN_CARD.getRoute(cardID)))
}
backgroundColor={theme.PAGE_THEMES[SCREENS.SETTINGS.PREFERENCES.ROOT].backgroundColor}
illustration={LottieAnimations.Magician}
scrollViewContainerStyles={[styles.mnh100]}
Expand Down
37 changes: 35 additions & 2 deletions src/pages/settings/Wallet/ExpensifyCardPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {View} from 'react-native';
import type {OnyxCollection} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import cardScarf from '@assets/images/card-scarf.svg';
import ActivityIndicator from '@components/ActivityIndicator';
import AddToWalletButton from '@components/AddToWalletButton/index';
import Button from '@components/Button';
import CardPreview from '@components/CardPreview';
Expand Down Expand Up @@ -63,6 +64,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type {Policy} from '@src/types/onyx';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import {useExpensifyCardActions, useExpensifyCardState} from './ExpensifyCardContextProvider';

type ExpensifyCardPageProps =
Expand Down Expand Up @@ -94,6 +96,9 @@ function ExpensifyCardPage({route}: ExpensifyCardPageProps) {
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const [countryByIp] = useOnyx(ONYXKEYS.COUNTRY);
const cardList = useNonPersonalCardList();
const [, cardListResult] = useOnyx(ONYXKEYS.CARD_LIST);
const [hasLoadedApp] = useOnyx(ONYXKEYS.HAS_LOADED_APP);
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP);
const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${cardList?.[cardID]?.fundID}`);
const styles = useThemeStyles();
const {isOffline} = useNetwork();
Expand Down Expand Up @@ -272,6 +277,27 @@ function ExpensifyCardPage({route}: ExpensifyCardPageProps) {

const navigateToTransactions = () => navigateToCardTransactions(cardID);

// Show the loading indicator instead of the NotFoundPage while the card could still arrive: Before the app has loaded for the first time (hasLoadedApp),
// while an OpenApp/reconnect is in flight (isLoadingApp), or while CARD_LIST is still hydrating.
const isLoadingCardData = !currentCard && (!hasLoadedApp || !!isLoadingApp || isLoadingOnyxValue(cardListResult));

if (isLoadingCardData) {
return (
<ScreenWrapper testID="ExpensifyCardPage">
<HeaderWithBackButton
title={pageTitle}
onBackButtonPress={() => Navigation.closeRHPFlow()}
/>
<View style={[styles.flex1, styles.justifyContentCenter, styles.alignItemsCenter]}>
<ActivityIndicator
size={CONST.ACTIVITY_INDICATOR_SIZE.LARGE}
reasonAttributes={{context: 'ExpensifyCardPage', isOffline, hasLoadedApp: !!hasLoadedApp, isLoadingApp: !!isLoadingApp}}
/>
</View>
</ScreenWrapper>
);
}

if (!currentCard) {
return <NotFoundPage onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WALLET)} />;
}
Expand Down Expand Up @@ -606,7 +632,12 @@ function ExpensifyCardPage({route}: ExpensifyCardPageProps) {
showLockedAccountModal();
return;
}
Navigation.navigate(ROUTES.SETTINGS_WALLET_REPORT_CARD_LOST_OR_DAMAGED.getRoute(String(currentPhysicalCard?.cardID)));
Navigation.navigate(
ROUTES.SETTINGS_WALLET_REPORT_CARD_LOST_OR_DAMAGED.getRoute(
String(currentPhysicalCard?.cardID),
route.name === SCREENS.DOMAIN_CARD.DOMAIN_CARD_DETAIL,
),
);
}}
/>
)}
Expand Down Expand Up @@ -638,7 +669,9 @@ function ExpensifyCardPage({route}: ExpensifyCardPageProps) {
success
large
style={[styles.w100, styles.p5]}
onPress={() => Navigation.navigate(ROUTES.SETTINGS_WALLET_CARD_ACTIVATE.getRoute(String(currentPhysicalCard?.cardID)))}
onPress={() =>
Navigation.navigate(ROUTES.SETTINGS_WALLET_CARD_ACTIVATE.getRoute(String(currentPhysicalCard?.cardID), route.name === SCREENS.DOMAIN_CARD.DOMAIN_CARD_DETAIL))
}
text={translate('activateCardPage.activatePhysicalCard')}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ReportCardLostConfirmMagicCodePageProps = PlatformStackScreenProps<Settings

function ReportCardLostConfirmMagicCodePage({
route: {
params: {cardID = '', reason = 'damaged'},
params: {cardID = '', reason = 'damaged', isFromDomainCardDetail},
},
}: ReportCardLostConfirmMagicCodePageProps) {
const {translate} = useLocalize();
Expand Down Expand Up @@ -65,9 +65,16 @@ function ReportCardLostConfirmMagicCodePage({
>
<HeaderWithBackButton
title={translate('common.success')}
onBackButtonPress={() => Navigation.navigate(ROUTES.SETTINGS_WALLET_DOMAIN_CARD.getRoute(newCardID))}
onBackButtonPress={() =>
Navigation.goBack(isFromDomainCardDetail ? ROUTES.SETTINGS_DOMAIN_CARD_DETAIL.getRoute(newCardID) : ROUTES.SETTINGS_WALLET_DOMAIN_CARD.getRoute(newCardID), {
compareParams: false,
})
}
/>
<SuccessReportCardLost
cardID={newCardID}
isFromDomainCardDetail={!!isFromDomainCardDetail}
/>
<SuccessReportCardLost cardID={newCardID} />
</ScreenWrapper>
);
}
Expand Down
7 changes: 4 additions & 3 deletions src/pages/settings/Wallet/ReportCardLostPage.tsx

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: it might be a separate issue, but the virtual card deactivation flow leads to a not found page.

Steps:

  1. Settings > Connected Cards > Show details
  2. Report virtual card fraud > Deactivate Card
  3. Enter magic code > Verify > Got it, thanks!
  4. Tap back arrow several times

Expected result: it lands in the OD
Actual result: it shows a not found page.

Screen_recording_20260623_113830.webm

@QichenZhu QichenZhu Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed as a pre-existing issue based on my testing with the virtual card flow on v9.4.15-3.

Not able to test the physical card flow due to limitations of my account.

v9.4.15-3.mov

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type ReportCardLostPageProps = PlatformStackScreenProps<SettingsNavigatorParamLi

function ReportCardLostPage({
route: {
params: {cardID = ''},
params: {cardID = '', isFromDomainCardDetail},
},
}: ReportCardLostPageProps) {
const styles = useThemeStyles();
Expand Down Expand Up @@ -100,7 +100,7 @@ function ReportCardLostPage({
setShouldShowAddressError(true);
return;
}
Navigation.navigate(ROUTES.SETTINGS_WALLET_REPORT_CARD_LOST_OR_DAMAGED_CONFIRM_MAGIC_CODE.getRoute(cardID, reason?.key ?? OPTIONS_KEYS.DAMAGED));
Navigation.navigate(ROUTES.SETTINGS_WALLET_REPORT_CARD_LOST_OR_DAMAGED_CONFIRM_MAGIC_CODE.getRoute(cardID, reason?.key ?? OPTIONS_KEYS.DAMAGED, !!isFromDomainCardDetail));
};

const handleOptionSelect = (value: string) => {
Expand All @@ -117,7 +117,8 @@ function ReportCardLostPage({
return;
}

Navigation.goBack(ROUTES.SETTINGS_WALLET_DOMAIN_CARD.getRoute(cardID));
const cardDetailRoute = isFromDomainCardDetail ? ROUTES.SETTINGS_DOMAIN_CARD_DETAIL.getRoute(cardID) : ROUTES.SETTINGS_WALLET_DOMAIN_CARD.getRoute(cardID);
Navigation.goBack(cardDetailRoute, {compareParams: false});
};

const isDamaged = reason?.key === OPTIONS_KEYS.DAMAGED;
Expand Down
7 changes: 5 additions & 2 deletions src/pages/settings/Wallet/SuccessReportCardLost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import ROUTES from '@src/ROUTES';

function SuccessReportCardLost({cardID}: {cardID: string}) {
function SuccessReportCardLost({cardID, isFromDomainCardDetail = false}: {cardID: string; isFromDomainCardDetail?: boolean}) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand All @@ -20,7 +20,10 @@ function SuccessReportCardLost({cardID}: {cardID: string}) {
illustration={illustrations.CardReplacementSuccess}
shouldShowButton
onButtonPress={() => {
Navigation.navigate(ROUTES.SETTINGS_WALLET_DOMAIN_CARD.getRoute(cardID), {forceReplace: true});
// Going back with compareParams: false collapses the flow onto the deleted card route and
// replaces its cardID with the replacement card instead of a stale/NotFound route.
const cardDetailRoute = isFromDomainCardDetail ? ROUTES.SETTINGS_DOMAIN_CARD_DETAIL.getRoute(cardID) : ROUTES.SETTINGS_WALLET_DOMAIN_CARD.getRoute(cardID);
Navigation.goBack(cardDetailRoute, {compareParams: false});
}}
buttonText={translate('common.buttonConfirm')}
containerStyle={styles.h100}
Expand Down
Loading