From 29bd7e06716f24b8cd373f974e38c9bfdecda260 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Thu, 12 Nov 2026 16:03:13 +0100 Subject: [PATCH 1/5] Keep the Wise banners until onboarding is saved --- src/libs/BankAccountUtils.ts | 22 ++++++++ .../WiseGlobalReimbursementsIntroPage.tsx | 4 -- tests/unit/BankAccountUtilsTest.ts | 50 +++++++++++++++++++ 3 files changed, 72 insertions(+), 4 deletions(-) diff --git a/src/libs/BankAccountUtils.ts b/src/libs/BankAccountUtils.ts index c5490af73a76..651922122fad 100644 --- a/src/libs/BankAccountUtils.ts +++ b/src/libs/BankAccountUtils.ts @@ -290,10 +290,27 @@ function isWiseOnboardingSubmitted(accountData: AccountData | undefined): boolea return !!accountData?.additionalData?.wise?.status; } +/** + * Whether the admin saved part of the Wise onboarding for any of their bank accounts. The server sets Wise as the provider on the first saved page, + * and from then on Wallet shows the account's setup so the admin can return to it. + */ +function hasStartedWiseOnboarding(bankAccountList: OnyxEntry): boolean { + return Object.values(bankAccountList ?? {}).some( + (bankAccount) => + bankAccount?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && + bankAccount?.accountData?.additionalData?.globalReimbursementProvider === CONST.GLOBAL_REIMBURSEMENT_PROVIDER.WISE, + ); +} + /** * Picks the bank account the Wallet global reimbursements banner points to: the most recently added eligible account. */ function getWiseGlobalReimbursementsBannerBankAccountID(bankAccountList: OnyxEntry): number | undefined { + // Once any account has a Wise setup, Wallet shows where it stands, so the banner has nothing left to promote + if (hasStartedWiseOnboarding(bankAccountList)) { + return undefined; + } + const newest = Object.values(bankAccountList ?? {}).reduce((latest, bankAccount) => { // Accounts deleted offline stay in the list until the request syncs if (bankAccount.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) { @@ -334,6 +351,11 @@ function getWorkspaceWiseGlobalReimbursementsBannerBankAccountID(policy: OnyxEnt return undefined; } + // Once any account has a Wise setup, Wallet shows where it stands, so the banner has nothing left to promote + if (hasStartedWiseOnboarding(bankAccountList)) { + return undefined; + } + // Admins without a copy of the account can't see its currency, type or verifications, so the banner stays hidden for them const bankAccount = bankAccountList?.[bankAccountID]; if (bankAccount?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || !isBankAccountEligibleForGlobalReimbursements(bankAccount?.accountData, bankAccount?.bankCurrency)) { diff --git a/src/pages/settings/Wallet/WiseGlobalReimbursementsIntroPage.tsx b/src/pages/settings/Wallet/WiseGlobalReimbursementsIntroPage.tsx index 2ee9dfe9b9c9..a5317df9351c 100644 --- a/src/pages/settings/Wallet/WiseGlobalReimbursementsIntroPage.tsx +++ b/src/pages/settings/Wallet/WiseGlobalReimbursementsIntroPage.tsx @@ -13,7 +13,6 @@ import usePermissions from '@hooks/usePermissions'; import useStyleUtils from '@hooks/useStyleUtils'; import useThemeStyles from '@hooks/useThemeStyles'; -import {dismissProductTraining} from '@libs/actions/Welcome'; import {isBankAccountEligibleForGlobalReimbursements, isWiseOnboardingPendingSubmit, isWiseOnboardingSubmitted} from '@libs/BankAccountUtils'; import createDynamicRoute from '@libs/Navigation/helpers/dynamicRoutesUtils/createDynamicRoute'; import {isWiseGlobalReimbursementsIntroOverPayReportScreen} from '@libs/Navigation/helpers/enableGlobalReimbursementsNavigationUtils'; @@ -102,9 +101,6 @@ function WiseGlobalReimbursementsIntroPage({route}: WiseGlobalReimbursementsIntr } text={translate(isOnboardingSubmitted || isWiseOnboardingPendingSubmit(bankAccount) ? 'common.continue' : 'walletPage.wiseGlobalReimbursementsIntro.getStarted')} onPress={() => { - // Starting onboarding for any account retires both banners for good - dismissProductTraining(CONST.WISE_GLOBAL_REIMBURSEMENTS_WALLET_BANNER); - dismissProductTraining(CONST.WISE_GLOBAL_REIMBURSEMENTS_WORKSPACE_BANNER); // A submitted business has nothing left to submit, so it sees where its onboarding stands instead of ending on the terms Navigation.navigate( createDynamicRoute(isOnboardingSubmitted ? DYNAMIC_ROUTES.WISE_ONBOARDING_STATUS.path : DYNAMIC_ROUTES.WISE_BUSINESS_ONBOARDING.getRoute()), diff --git a/tests/unit/BankAccountUtilsTest.ts b/tests/unit/BankAccountUtilsTest.ts index 5385bc7d08d6..47c102b1b9ea 100644 --- a/tests/unit/BankAccountUtilsTest.ts +++ b/tests/unit/BankAccountUtilsTest.ts @@ -1308,6 +1308,37 @@ describe('BankAccountUtils', () => { expect(getWiseGlobalReimbursementsBannerBankAccountID(bankAccountList)).toBe(2); }); + it('returns undefined once Wise onboarding started for any account', () => { + // Given an eligible account and an older one whose first Wise onboarding page was saved + const bankAccountList = createMock({ + accountOne: buildBankAccount(1, '2026-05-01 10:00:00'), + accountTwo: buildBankAccount(2, '2026-03-01 10:00:00', { + additionalData: {currency: CONST.CURRENCY.USD, globalReimbursementProvider: CONST.GLOBAL_REIMBURSEMENT_PROVIDER.WISE}, + }), + }); + + // When picking the account for the Wallet banner + // Then nothing is returned, because Wallet already offers to continue the started onboarding + expect(getWiseGlobalReimbursementsBannerBankAccountID(bankAccountList)).toBeUndefined(); + }); + + it('keeps the banner when the only started onboarding belongs to an account pending deletion', () => { + // Given an eligible account and an account with started Wise onboarding that was deleted offline + const bankAccountList = createMock({ + accountOne: buildBankAccount(1, '2026-03-01 10:00:00'), + accountTwo: { + ...buildBankAccount(2, '2026-05-01 10:00:00', { + additionalData: {currency: CONST.CURRENCY.USD, globalReimbursementProvider: CONST.GLOBAL_REIMBURSEMENT_PROVIDER.WISE}, + }), + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + }, + }); + + // When picking the account for the Wallet banner + // Then the eligible account is returned, since Wallet no longer offers to continue the deleted account's onboarding + expect(getWiseGlobalReimbursementsBannerBankAccountID(bankAccountList)).toBe(1); + }); + it('returns undefined when no account is eligible', () => { // Given only an account already set up for global reimbursements const bankAccountList = createMock({ @@ -1382,6 +1413,25 @@ describe('BankAccountUtils', () => { // Then nothing is returned, so the banner never points to an account queued for removal expect(getWorkspaceWiseGlobalReimbursementsBannerBankAccountID(policy, bankAccountList)).toBeUndefined(); }); + + it('returns undefined once Wise onboarding started for any account', () => { + // Given an eligible connected account and another account whose first Wise onboarding page was saved + const otherBankAccountID = 2; + const bankAccountList = createMock({ + [bankAccountID]: {accountData: eligibleAccountData}, + [otherBankAccountID]: { + accountData: { + ...eligibleAccountData, + bankAccountID: otherBankAccountID, + additionalData: {currency: CONST.CURRENCY.USD, globalReimbursementProvider: CONST.GLOBAL_REIMBURSEMENT_PROVIDER.WISE}, + }, + }, + }); + + // When picking the account for the Workspace banner + // Then nothing is returned, because Wallet already offers to continue the started onboarding + expect(getWorkspaceWiseGlobalReimbursementsBannerBankAccountID(policy, bankAccountList)).toBeUndefined(); + }); }); describe('isWiseOnboardingMoreInfoNeeded', () => { From da776f7eb1fb3612ccf5730c3fd45ee3b2eb2d2f Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Fri, 13 Nov 2026 12:24:03 +0100 Subject: [PATCH 2/5] Keep the Wise banners until the RHP closes on wide layout --- src/hooks/useLastFocusedValue.ts | 28 +++++++ .../WalletWiseGlobalReimbursementsBanner.tsx | 4 +- ...orkspaceWiseGlobalReimbursementsBanner.tsx | 4 +- tests/unit/useLastFocusedValueTest.ts | 84 +++++++++++++++++++ 4 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 src/hooks/useLastFocusedValue.ts create mode 100644 tests/unit/useLastFocusedValueTest.ts diff --git a/src/hooks/useLastFocusedValue.ts b/src/hooks/useLastFocusedValue.ts new file mode 100644 index 000000000000..f10e650d4b01 --- /dev/null +++ b/src/hooks/useLastFocusedValue.ts @@ -0,0 +1,28 @@ +import {useState} from 'react'; + +import useIsScreenFocused from './useIsScreenFocused'; +import useResponsiveLayout from './useResponsiveLayout'; + +/** + * Keeps a screen showing what the user last saw while the RHP covers part of it. + * Returns the live value while the screen has focus, and the value from when it last had focus otherwise, + * so changes made from the RHP show once it closes instead of shifting the layout visible beside it. + */ +function useLastFocusedValue(value: TValue): TValue { + const isFocused = useIsScreenFocused(); + const {shouldUseNarrowLayout} = useResponsiveLayout(); + const [lastFocusedValue, setLastFocusedValue] = useState(value); + + // On narrow layout the RHP covers the whole screen, so changes can apply while it is hidden. + // Holding them would make the screen jump as the user navigates back to it. + const shouldUseLiveValue = isFocused || shouldUseNarrowLayout; + + if (shouldUseLiveValue && !Object.is(lastFocusedValue, value)) { + // The updater form stores the value as is, even when it is a function + setLastFocusedValue(() => value); + } + + return shouldUseLiveValue ? value : lastFocusedValue; +} + +export default useLastFocusedValue; diff --git a/src/pages/settings/Wallet/WalletWiseGlobalReimbursementsBanner.tsx b/src/pages/settings/Wallet/WalletWiseGlobalReimbursementsBanner.tsx index 3989069a6774..4dbbd14a0dca 100644 --- a/src/pages/settings/Wallet/WalletWiseGlobalReimbursementsBanner.tsx +++ b/src/pages/settings/Wallet/WalletWiseGlobalReimbursementsBanner.tsx @@ -1,5 +1,6 @@ import WiseGlobalReimbursementsBanner from '@components/WiseGlobalReimbursementsBanner'; +import useLastFocusedValue from '@hooks/useLastFocusedValue'; import useLayoutSpacing from '@hooks/useLayoutSpacing'; import useOnyx from '@hooks/useOnyx'; import usePermissions from '@hooks/usePermissions'; @@ -30,7 +31,8 @@ function WalletWiseGlobalReimbursementsBanner() { const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); const [isDismissed = true] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING, {selector: isBannerDismissedSelector}); - const bankAccountID = getWiseGlobalReimbursementsBannerBankAccountID(bankAccountList); + // Saving the first onboarding page in the RHP retires the banner, so it waits for the RHP to close instead of vanishing behind it + const bankAccountID = useLastFocusedValue(getWiseGlobalReimbursementsBannerBankAccountID(bankAccountList)); if (!isBetaEnabled(CONST.BETAS.WISE_REIMBURSEMENTS) || shouldSuppressPromotionalUI || isDismissed || !bankAccountID) { return null; diff --git a/src/pages/workspace/workflows/WorkspaceWiseGlobalReimbursementsBanner.tsx b/src/pages/workspace/workflows/WorkspaceWiseGlobalReimbursementsBanner.tsx index 2bce00f4dbbd..995c7752d2d4 100644 --- a/src/pages/workspace/workflows/WorkspaceWiseGlobalReimbursementsBanner.tsx +++ b/src/pages/workspace/workflows/WorkspaceWiseGlobalReimbursementsBanner.tsx @@ -1,6 +1,7 @@ import WiseGlobalReimbursementsBanner from '@components/WiseGlobalReimbursementsBanner'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; +import useLastFocusedValue from '@hooks/useLastFocusedValue'; import useOnyx from '@hooks/useOnyx'; import usePermissions from '@hooks/usePermissions'; import usePolicy from '@hooks/usePolicy'; @@ -40,7 +41,8 @@ function WorkspaceWiseGlobalReimbursementsBanner({policyID}: WorkspaceWiseGlobal const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); const [isDismissed = true] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING, {selector: isBannerDismissedSelector}); - const bankAccountID = getWorkspaceWiseGlobalReimbursementsBannerBankAccountID(policy, bankAccountList); + // Saving the first onboarding page in the RHP retires the banner, so it waits for the RHP to close instead of vanishing behind it + const bankAccountID = useLastFocusedValue(getWorkspaceWiseGlobalReimbursementsBannerBankAccountID(policy, bankAccountList)); if (!isBetaEnabled(CONST.BETAS.WISE_REIMBURSEMENTS) || !isPolicyAdmin(policy, currentUserLogin) || shouldSuppressPromotionalUI || isDismissed || !bankAccountID) { return null; diff --git a/tests/unit/useLastFocusedValueTest.ts b/tests/unit/useLastFocusedValueTest.ts new file mode 100644 index 000000000000..110d56b0e601 --- /dev/null +++ b/tests/unit/useLastFocusedValueTest.ts @@ -0,0 +1,84 @@ +import {renderHook} from '@testing-library/react-native'; + +import useLastFocusedValue from '@hooks/useLastFocusedValue'; + +let mockIsFocused = true; +jest.mock('@hooks/useIsScreenFocused', () => ({ + __esModule: true, + default: () => mockIsFocused, +})); + +let mockShouldUseNarrowLayout = false; +jest.mock('@hooks/useResponsiveLayout', () => ({ + __esModule: true, + default: () => ({shouldUseNarrowLayout: mockShouldUseNarrowLayout}), +})); + +type HookProps = {value: number | undefined}; + +function renderBankAccountIDHook(initialBankAccountID: number | undefined) { + const initialProps: HookProps = {value: initialBankAccountID}; + return renderHook(({value}: HookProps) => useLastFocusedValue(value), {initialProps}); +} + +describe('useLastFocusedValue', () => { + beforeEach(() => { + mockIsFocused = true; + mockShouldUseNarrowLayout = false; + }); + + it('returns the live value while the screen has focus', () => { + // Given a focused screen showing a banner for bank account 1 + const {result, rerender} = renderBankAccountIDHook(1); + + // When the banner's bank account changes + rerender({value: 2}); + + // Then the change shows right away, because the user is looking at the screen + expect(result.current).toBe(2); + }); + + it('keeps the last focused value while another screen covers it', () => { + // Given a focused screen showing a banner for bank account 1 + const {result, rerender} = renderBankAccountIDHook(1); + + // When the RHP covers the screen and saving onboarding there retires the banner + mockIsFocused = false; + rerender({value: undefined}); + + // Then the banner stays, so it doesn't vanish behind the RHP + expect(result.current).toBe(1); + }); + + it('catches up once the screen is focused again', () => { + // Given a covered screen that kept bank account 1 while the banner was retired + const {result, rerender} = renderBankAccountIDHook(1); + mockIsFocused = false; + rerender({value: undefined}); + + // When the RHP closes and the screen is focused again + mockIsFocused = true; + rerender({value: undefined}); + + // Then the banner goes away, along with the RHP closing + expect(result.current).toBeUndefined(); + + // And it stays gone if the screen is covered again later + mockIsFocused = false; + rerender({value: undefined}); + expect(result.current).toBeUndefined(); + }); + + it('returns the live value on narrow layout even while another screen covers it', () => { + // Given a narrow layout screen showing a banner for bank account 1 + mockShouldUseNarrowLayout = true; + const {result, rerender} = renderBankAccountIDHook(1); + + // When the full screen RHP covers it and saving onboarding there retires the banner + mockIsFocused = false; + rerender({value: undefined}); + + // Then the banner goes away while hidden, so it doesn't jump as the user navigates back + expect(result.current).toBeUndefined(); + }); +}); From 01d99a72287b76137cc1396952ccc6fe9ff219c3 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Fri, 13 Nov 2026 12:30:58 +0100 Subject: [PATCH 3/5] Keep the Wise banners hidden while the started account's deletion is pending --- src/libs/BankAccountUtils.ts | 7 ++----- tests/unit/BankAccountUtilsTest.ts | 6 +++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/libs/BankAccountUtils.ts b/src/libs/BankAccountUtils.ts index 651922122fad..1e28eb5993ec 100644 --- a/src/libs/BankAccountUtils.ts +++ b/src/libs/BankAccountUtils.ts @@ -293,13 +293,10 @@ function isWiseOnboardingSubmitted(accountData: AccountData | undefined): boolea /** * Whether the admin saved part of the Wise onboarding for any of their bank accounts. The server sets Wise as the provider on the first saved page, * and from then on Wallet shows the account's setup so the admin can return to it. + * An account deleted offline still counts until the server removes it, so the banners don't show up before the deletion goes through. */ function hasStartedWiseOnboarding(bankAccountList: OnyxEntry): boolean { - return Object.values(bankAccountList ?? {}).some( - (bankAccount) => - bankAccount?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && - bankAccount?.accountData?.additionalData?.globalReimbursementProvider === CONST.GLOBAL_REIMBURSEMENT_PROVIDER.WISE, - ); + return Object.values(bankAccountList ?? {}).some((bankAccount) => bankAccount?.accountData?.additionalData?.globalReimbursementProvider === CONST.GLOBAL_REIMBURSEMENT_PROVIDER.WISE); } /** diff --git a/tests/unit/BankAccountUtilsTest.ts b/tests/unit/BankAccountUtilsTest.ts index 47c102b1b9ea..b78ad531d0a7 100644 --- a/tests/unit/BankAccountUtilsTest.ts +++ b/tests/unit/BankAccountUtilsTest.ts @@ -1322,7 +1322,7 @@ describe('BankAccountUtils', () => { expect(getWiseGlobalReimbursementsBannerBankAccountID(bankAccountList)).toBeUndefined(); }); - it('keeps the banner when the only started onboarding belongs to an account pending deletion', () => { + it('returns undefined while the account with started onboarding is pending deletion', () => { // Given an eligible account and an account with started Wise onboarding that was deleted offline const bankAccountList = createMock({ accountOne: buildBankAccount(1, '2026-03-01 10:00:00'), @@ -1335,8 +1335,8 @@ describe('BankAccountUtils', () => { }); // When picking the account for the Wallet banner - // Then the eligible account is returned, since Wallet no longer offers to continue the deleted account's onboarding - expect(getWiseGlobalReimbursementsBannerBankAccountID(bankAccountList)).toBe(1); + // Then nothing is returned, so the banner doesn't show up before the server confirms the deletion + expect(getWiseGlobalReimbursementsBannerBankAccountID(bankAccountList)).toBeUndefined(); }); it('returns undefined when no account is eligible', () => { From 4ddfe7f2a6368255420a4f876da7594100f14a22 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Fri, 13 Nov 2026 16:07:57 +0100 Subject: [PATCH 4/5] Cache the onboarding eligibility check in a useOnyx selector --- .../Wise/WiseBusinessOnboardingPage.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pages/settings/Wallet/EnableGlobalReimbursements/Wise/WiseBusinessOnboardingPage.tsx b/src/pages/settings/Wallet/EnableGlobalReimbursements/Wise/WiseBusinessOnboardingPage.tsx index 7141a63b78eb..4f8e3fa80321 100644 --- a/src/pages/settings/Wallet/EnableGlobalReimbursements/Wise/WiseBusinessOnboardingPage.tsx +++ b/src/pages/settings/Wallet/EnableGlobalReimbursements/Wise/WiseBusinessOnboardingPage.tsx @@ -65,6 +65,10 @@ function WiseBusinessOnboardingPage({route}: WiseBusinessOnboardingPageProps) { const [businessAccount, businessAccountMetadata] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {selector: businessAccountSelector}); const {isSaving, saveError, unsavedPageKeys} = useWiseOnboardingSaveStatus(); const bankAccount = bankAccountList?.[bankAccountID]; + // A selector, so the check is cached now that only the early return below reads it + const [isEligible = false] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, { + selector: (list) => isBankAccountEligibleForGlobalReimbursements(list?.[bankAccountID]?.accountData, list?.[bankAccountID]?.bankCurrency), + }); const {translate} = useLocalize(); const {isOffline} = useNetwork(); @@ -186,8 +190,6 @@ function WiseBusinessOnboardingPage({route}: WiseBusinessOnboardingPageProps) { setIsPrefillDone(true); } - const isEligible = isBankAccountEligibleForGlobalReimbursements(bankAccount?.accountData, bankAccount?.bankCurrency); - useEffect(() => { if (!isPrefillPending) { return; From e37b4e5fe86e27cbfbd070461a25c75f6c6a9e9b Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Fri, 13 Nov 2026 16:36:56 +0100 Subject: [PATCH 5/5] Rename useLastFocusedValue to useDeferUntilScreenRevealed and restrict it to primitives --- ...edValue.ts => useDeferUntilScreenRevealed.ts} | 16 +++++++++------- .../WalletWiseGlobalReimbursementsBanner.tsx | 4 ++-- .../WorkspaceWiseGlobalReimbursementsBanner.tsx | 4 ++-- ...est.ts => useDeferUntilScreenRevealedTest.ts} | 6 +++--- 4 files changed, 16 insertions(+), 14 deletions(-) rename src/hooks/{useLastFocusedValue.ts => useDeferUntilScreenRevealed.ts} (60%) rename tests/unit/{useLastFocusedValueTest.ts => useDeferUntilScreenRevealedTest.ts} (92%) diff --git a/src/hooks/useLastFocusedValue.ts b/src/hooks/useDeferUntilScreenRevealed.ts similarity index 60% rename from src/hooks/useLastFocusedValue.ts rename to src/hooks/useDeferUntilScreenRevealed.ts index f10e650d4b01..7ebb01d692da 100644 --- a/src/hooks/useLastFocusedValue.ts +++ b/src/hooks/useDeferUntilScreenRevealed.ts @@ -1,3 +1,5 @@ +import type {Primitive} from 'type-fest'; + import {useState} from 'react'; import useIsScreenFocused from './useIsScreenFocused'; @@ -7,22 +9,22 @@ import useResponsiveLayout from './useResponsiveLayout'; * Keeps a screen showing what the user last saw while the RHP covers part of it. * Returns the live value while the screen has focus, and the value from when it last had focus otherwise, * so changes made from the RHP show once it closes instead of shifting the layout visible beside it. + * Only primitives are accepted, since a value rebuilt on every render would never match the stored one and would set state on every render. */ -function useLastFocusedValue(value: TValue): TValue { +function useDeferUntilScreenRevealed(value: TValue): TValue { const isFocused = useIsScreenFocused(); const {shouldUseNarrowLayout} = useResponsiveLayout(); - const [lastFocusedValue, setLastFocusedValue] = useState(value); + const [deferredValue, setDeferredValue] = useState(value); // On narrow layout the RHP covers the whole screen, so changes can apply while it is hidden. // Holding them would make the screen jump as the user navigates back to it. const shouldUseLiveValue = isFocused || shouldUseNarrowLayout; - if (shouldUseLiveValue && !Object.is(lastFocusedValue, value)) { - // The updater form stores the value as is, even when it is a function - setLastFocusedValue(() => value); + if (shouldUseLiveValue && !Object.is(deferredValue, value)) { + setDeferredValue(value); } - return shouldUseLiveValue ? value : lastFocusedValue; + return shouldUseLiveValue ? value : deferredValue; } -export default useLastFocusedValue; +export default useDeferUntilScreenRevealed; diff --git a/src/pages/settings/Wallet/WalletWiseGlobalReimbursementsBanner.tsx b/src/pages/settings/Wallet/WalletWiseGlobalReimbursementsBanner.tsx index 4dbbd14a0dca..f29583f3cc2d 100644 --- a/src/pages/settings/Wallet/WalletWiseGlobalReimbursementsBanner.tsx +++ b/src/pages/settings/Wallet/WalletWiseGlobalReimbursementsBanner.tsx @@ -1,6 +1,6 @@ import WiseGlobalReimbursementsBanner from '@components/WiseGlobalReimbursementsBanner'; -import useLastFocusedValue from '@hooks/useLastFocusedValue'; +import useDeferUntilScreenRevealed from '@hooks/useDeferUntilScreenRevealed'; import useLayoutSpacing from '@hooks/useLayoutSpacing'; import useOnyx from '@hooks/useOnyx'; import usePermissions from '@hooks/usePermissions'; @@ -32,7 +32,7 @@ function WalletWiseGlobalReimbursementsBanner() { const [isDismissed = true] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING, {selector: isBannerDismissedSelector}); // Saving the first onboarding page in the RHP retires the banner, so it waits for the RHP to close instead of vanishing behind it - const bankAccountID = useLastFocusedValue(getWiseGlobalReimbursementsBannerBankAccountID(bankAccountList)); + const bankAccountID = useDeferUntilScreenRevealed(getWiseGlobalReimbursementsBannerBankAccountID(bankAccountList)); if (!isBetaEnabled(CONST.BETAS.WISE_REIMBURSEMENTS) || shouldSuppressPromotionalUI || isDismissed || !bankAccountID) { return null; diff --git a/src/pages/workspace/workflows/WorkspaceWiseGlobalReimbursementsBanner.tsx b/src/pages/workspace/workflows/WorkspaceWiseGlobalReimbursementsBanner.tsx index 995c7752d2d4..885acd8951e1 100644 --- a/src/pages/workspace/workflows/WorkspaceWiseGlobalReimbursementsBanner.tsx +++ b/src/pages/workspace/workflows/WorkspaceWiseGlobalReimbursementsBanner.tsx @@ -1,7 +1,7 @@ import WiseGlobalReimbursementsBanner from '@components/WiseGlobalReimbursementsBanner'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; -import useLastFocusedValue from '@hooks/useLastFocusedValue'; +import useDeferUntilScreenRevealed from '@hooks/useDeferUntilScreenRevealed'; import useOnyx from '@hooks/useOnyx'; import usePermissions from '@hooks/usePermissions'; import usePolicy from '@hooks/usePolicy'; @@ -42,7 +42,7 @@ function WorkspaceWiseGlobalReimbursementsBanner({policyID}: WorkspaceWiseGlobal const [isDismissed = true] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING, {selector: isBannerDismissedSelector}); // Saving the first onboarding page in the RHP retires the banner, so it waits for the RHP to close instead of vanishing behind it - const bankAccountID = useLastFocusedValue(getWorkspaceWiseGlobalReimbursementsBannerBankAccountID(policy, bankAccountList)); + const bankAccountID = useDeferUntilScreenRevealed(getWorkspaceWiseGlobalReimbursementsBannerBankAccountID(policy, bankAccountList)); if (!isBetaEnabled(CONST.BETAS.WISE_REIMBURSEMENTS) || !isPolicyAdmin(policy, currentUserLogin) || shouldSuppressPromotionalUI || isDismissed || !bankAccountID) { return null; diff --git a/tests/unit/useLastFocusedValueTest.ts b/tests/unit/useDeferUntilScreenRevealedTest.ts similarity index 92% rename from tests/unit/useLastFocusedValueTest.ts rename to tests/unit/useDeferUntilScreenRevealedTest.ts index 110d56b0e601..17added695b6 100644 --- a/tests/unit/useLastFocusedValueTest.ts +++ b/tests/unit/useDeferUntilScreenRevealedTest.ts @@ -1,6 +1,6 @@ import {renderHook} from '@testing-library/react-native'; -import useLastFocusedValue from '@hooks/useLastFocusedValue'; +import useDeferUntilScreenRevealed from '@hooks/useDeferUntilScreenRevealed'; let mockIsFocused = true; jest.mock('@hooks/useIsScreenFocused', () => ({ @@ -18,10 +18,10 @@ type HookProps = {value: number | undefined}; function renderBankAccountIDHook(initialBankAccountID: number | undefined) { const initialProps: HookProps = {value: initialBankAccountID}; - return renderHook(({value}: HookProps) => useLastFocusedValue(value), {initialProps}); + return renderHook(({value}: HookProps) => useDeferUntilScreenRevealed(value), {initialProps}); } -describe('useLastFocusedValue', () => { +describe('useDeferUntilScreenRevealed', () => { beforeEach(() => { mockIsFocused = true; mockShouldUseNarrowLayout = false;