diff --git a/src/libs/GetPhysicalCardUtils.ts b/src/libs/GetPhysicalCardUtils.ts index 57a9d773cc9d..9d77858cb2a9 100644 --- a/src/libs/GetPhysicalCardUtils.ts +++ b/src/libs/GetPhysicalCardUtils.ts @@ -1,4 +1,3 @@ -import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import {Login} from '@src/types/onyx'; import Navigation from './Navigation/Navigation'; @@ -82,7 +81,7 @@ function setCurrentRoute(currentRoute: string, domain: string, privatePersonalDe } // Redirect the user if he's not allowed to be on the current step - Navigation.navigate(expectedRoute, CONST.NAVIGATION.ACTION_TYPE.REPLACE); + Navigation.goBack(expectedRoute); } /** diff --git a/src/libs/Navigation/linkTo.ts b/src/libs/Navigation/linkTo.ts index 1a4aa2d0cfb7..d26a42ef3994 100644 --- a/src/libs/Navigation/linkTo.ts +++ b/src/libs/Navigation/linkTo.ts @@ -103,11 +103,6 @@ export default function linkTo(navigation: NavigationContainerRef card.isVirtual) || {}; - const physicalCard = _.find(domainCards, (card) => !card.isVirtual) || {}; + const domainCards = useMemo(() => cardList && CardUtils.getDomainCards(cardList)[domain], [cardList, domain]); + const virtualCard = useMemo(() => (domainCards && _.find(domainCards, (card) => card.isVirtual)) || {}, [domainCards]); + const physicalCard = useMemo(() => (domainCards && _.find(domainCards, (card) => !card.isVirtual)) || {}, [domainCards]); const [isLoading, setIsLoading] = useState(false); + const [isNotFound, setIsNotFound] = useState(false); const [details, setDetails] = useState({}); const [cardDetailsError, setCardDetailsError] = useState(''); - if (_.isEmpty(virtualCard) && _.isEmpty(physicalCard)) { - return Navigation.goBack(ROUTES.SETTINGS_WALLET)} />; - } + useEffect(() => { + if (!cardList) { + return; + } + setIsNotFound(_.isEmpty(virtualCard) && _.isEmpty(physicalCard)); + }, [cardList, physicalCard, virtualCard]); const formattedAvailableSpendAmount = CurrencyUtils.convertToDisplayString(physicalCard.availableSpend || virtualCard.availableSpend || 0); @@ -166,6 +170,10 @@ function ExpensifyCardPage({ const hasDetectedIndividualFraud = _.some(domainCards, (card) => card.fraud === CONST.EXPENSIFY_CARD.FRAUD_TYPES.INDIVIDUAL); const cardDetailsErrorObject = cardDetailsError ? {error: cardDetailsError} : {}; + if (isNotFound) { + return Navigation.goBack(ROUTES.SETTINGS_WALLET)} />; + } + return (