Skip to content

Commit 38e7fa5

Browse files
inimagaOSBotify
authored andcommitted
Merge pull request #88328 from Expensify/claude-fixOnfidoCrashStaleWalletData
Fix Onfido crash from stale cached wallet data on EnablePaymentsPage (cherry picked from commit 0f44d00) (cherry-picked to staging by AndrewGable)
1 parent 1cb7dd2 commit 38e7fa5

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

src/pages/EnablePayments/EnablePayments.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useEffect} from 'react';
1+
import React, {useEffect, useRef, useState} from 'react';
22
import {View} from 'react-native';
33
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
44
import HeaderWithBackButton from '@components/HeaderWithBackButton';
@@ -30,6 +30,9 @@ function EnablePaymentsPage() {
3030
const [fundList] = useOnyx(ONYXKEYS.FUND_LIST);
3131
const paymentCardList = fundList ?? {};
3232

33+
const wasLoadingRef = useRef(false);
34+
const [hasFreshData, setHasFreshData] = useState(false);
35+
3336
useEffect(() => {
3437
if (isOffline) {
3538
return;
@@ -38,8 +41,28 @@ function EnablePaymentsPage() {
3841
openEnablePaymentsPage();
3942
}, [isOffline]);
4043

44+
// Only render step content after the fresh data loading cycle (isLoading: true → false) completes,
45+
// to avoid acting on stale cached values from a previous session.
46+
useEffect(() => {
47+
if (isOffline) {
48+
return;
49+
}
50+
51+
if (userWallet?.isLoading) {
52+
wasLoadingRef.current = true;
53+
return;
54+
}
55+
56+
if (!wasLoadingRef.current) {
57+
return;
58+
}
59+
60+
// eslint-disable-next-line react-hooks/set-state-in-effect -- we need to trigger a re-render when fresh data arrives to stop showing the loading indicator
61+
setHasFreshData(true);
62+
}, [isOffline, userWallet?.isLoading]);
63+
4164
const isUserWalletEmpty = isEmptyObject(userWallet);
42-
if (isUserWalletEmpty || userWallet?.isLoading) {
65+
if (isUserWalletEmpty || userWallet?.isLoading || (!hasFreshData && !isOffline)) {
4366
const reasonAttributes: SkeletonSpanReasonAttributes = {
4467
context: 'EnablePaymentsPage',
4568
isUserWalletEmpty,

src/pages/EnablePayments/EnablePaymentsPage.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useEffect, useRef} from 'react';
1+
import React, {useEffect, useRef, useState} from 'react';
22
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
33
import HeaderWithBackButton from '@components/HeaderWithBackButton';
44
import ScreenWrapper from '@components/ScreenWrapper';
@@ -26,6 +26,7 @@ function EnablePaymentsPage() {
2626

2727
const {isPendingOnfidoResult, hasFailedOnfido} = userWallet ?? {};
2828
const wasLoadingRef = useRef(false);
29+
const [hasFreshData, setHasFreshData] = useState(false);
2930

3031
// Always fetch fresh wallet data on mount
3132
useEffect(() => {
@@ -52,14 +53,17 @@ function EnablePaymentsPage() {
5253
return;
5354
}
5455

56+
// eslint-disable-next-line react-hooks/set-state-in-effect -- we need to trigger a re-render when fresh data arrives to stop showing the loading indicator
57+
setHasFreshData(true);
58+
5559
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
5660
if (isPendingOnfidoResult || hasFailedOnfido) {
5761
Navigation.navigate(ROUTES.SETTINGS_WALLET, {forceReplace: true});
5862
}
5963
}, [isOffline, isPendingOnfidoResult, hasFailedOnfido, userWallet?.isLoading]);
6064

6165
const isUserWalletEmpty = isEmptyObject(userWallet);
62-
if (isUserWalletEmpty || userWallet?.isLoading) {
66+
if (isUserWalletEmpty || userWallet?.isLoading || (!hasFreshData && !isOffline)) {
6367
const reasonAttributes: SkeletonSpanReasonAttributes = {
6468
context: 'EnablePaymentsPage',
6569
isUserWalletEmpty,

0 commit comments

Comments
 (0)