diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index f46b97c39a03..71afedaef8ba 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -31,7 +31,7 @@ const ONYXKEYS = { DEVICE_ID: 'deviceID', /** Boolean flag set whenever the sidebar has loaded */ - IS_SIDEBAR_LOADED: 'isSidebarLoaded', + RAM_ONLY_IS_SIDEBAR_LOADED: 'isSidebarLoaded', /** Boolean flag set whenever we are searching for reports in the server */ RAM_ONLY_IS_SEARCHING_FOR_REPORTS: 'isSearchingForReports', @@ -210,7 +210,7 @@ const ONYXKEYS = { NVP_PREFERRED_LOCALE: 'nvp_preferredLocale', /** Whether the app is currently loading a translation */ - ARE_TRANSLATIONS_LOADING: 'areTranslationsLoading', + RAM_ONLY_ARE_TRANSLATIONS_LOADING: 'areTranslationsLoading', /** Whether the user has tried focus mode yet */ NVP_TRY_FOCUS_MODE: 'nvp_tryFocusMode', @@ -547,7 +547,7 @@ const ONYXKEYS = { ASSIGN_CARD: 'assignCard', /** Stores the information if mobile selection mode is active */ - MOBILE_SELECTION_MODE: 'mobileSelectionMode', + RAM_ONLY_MOBILE_SELECTION_MODE: 'mobileSelectionMode', NVP_PRIVATE_CANCELLATION_DETAILS: 'nvp_private_cancellationDetails', @@ -802,7 +802,7 @@ const ONYXKEYS = { NVP_EXPENSIFY_REPORT_PDF_FILENAME: 'nvp_expensify_report_PDFFilename_', /** Stores the information about the state of issuing a new card */ - ISSUE_NEW_EXPENSIFY_CARD: 'issueNewExpensifyCard_', + RAM_ONLY_ISSUE_NEW_EXPENSIFY_CARD: 'issueNewExpensifyCard_', /** Used for identifying user as admin of a domain */ SHARED_NVP_PRIVATE_ADMIN_ACCESS: 'sharedNVP_private_admin_access_', @@ -1288,7 +1288,7 @@ type OnyxCollectionValuesMapping = { [ONYXKEYS.COLLECTION.LAST_SELECTED_FEED]: OnyxTypes.CompanyCardFeedWithDomainID; [ONYXKEYS.COLLECTION.LAST_SELECTED_EXPENSIFY_CARD_FEED]: OnyxTypes.FundID; [ONYXKEYS.COLLECTION.NVP_EXPENSIFY_ON_CARD_WAITLIST]: OnyxTypes.CardOnWaitlist; - [ONYXKEYS.COLLECTION.ISSUE_NEW_EXPENSIFY_CARD]: OnyxTypes.IssueNewCard; + [ONYXKEYS.COLLECTION.RAM_ONLY_ISSUE_NEW_EXPENSIFY_CARD]: OnyxTypes.IssueNewCard; [ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_ADMIN_ACCESS]: boolean; [ONYXKEYS.COLLECTION.SAML_METADATA]: OnyxTypes.SamlMetadata; [ONYXKEYS.COLLECTION.DOMAIN_PENDING_ACTIONS]: OnyxTypes.DomainPendingActions; @@ -1312,7 +1312,7 @@ type OnyxValuesMapping = { [ONYXKEYS.RECENTLY_USED_CURRENCIES]: string[]; [ONYXKEYS.ACTIVE_CLIENTS]: string[]; [ONYXKEYS.DEVICE_ID]: string; - [ONYXKEYS.IS_SIDEBAR_LOADED]: boolean; + [ONYXKEYS.RAM_ONLY_IS_SIDEBAR_LOADED]: boolean; [ONYXKEYS.PERSISTED_REQUESTS]: OnyxTypes.AnyRequest[]; [ONYXKEYS.PERSISTED_ONGOING_REQUESTS]: OnyxTypes.AnyRequest; [ONYXKEYS.CURRENT_DATE]: string; @@ -1379,7 +1379,7 @@ type OnyxValuesMapping = { [ONYXKEYS.ONFIDO_TOKEN]: string; [ONYXKEYS.ONFIDO_APPLICANT_ID]: string; [ONYXKEYS.NVP_PREFERRED_LOCALE]: OnyxTypes.Locale; - [ONYXKEYS.ARE_TRANSLATIONS_LOADING]: boolean; + [ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING]: boolean; [ONYXKEYS.NVP_ACTIVE_POLICY_ID]: string; [ONYXKEYS.NVP_DISMISSED_REFERRAL_BANNERS]: OnyxTypes.DismissedReferralBanners; [ONYXKEYS.NVP_HAS_SEEN_TRACK_TRAINING]: boolean; @@ -1413,11 +1413,11 @@ type OnyxValuesMapping = { [ONYXKEYS.IS_LOADING_SHARE_BANK_ACCOUNTS]: boolean; [ONYXKEYS.IS_LOADING_BULK_CHANGE_APPROVER_PAGE]: boolean; [ONYXKEYS.IS_LOADING_POLICY_CODING_RULES_PREVIEW]: boolean; + [ONYXKEYS.IS_LOADING_REPORT_DATA]: boolean; [ONYXKEYS.IS_SEARCH_FILTERS_CARD_DATA_LOADED]: boolean; [ONYXKEYS.IS_LOADING_SUBSCRIPTION_DATA]: boolean; [ONYXKEYS.IS_PENDING_UPDATE_PERSONAL_KARMA]: boolean; [ONYXKEYS.IS_SEARCH_PAGE_DATA_LOADED]: boolean; - [ONYXKEYS.IS_LOADING_REPORT_DATA]: boolean; [ONYXKEYS.IS_TEST_TOOLS_MODAL_OPEN]: boolean; [ONYXKEYS.IS_LOADING_APP]: boolean; [ONYXKEYS.HAS_LOADED_APP]: boolean; @@ -1467,7 +1467,7 @@ type OnyxValuesMapping = { [ONYXKEYS.ADD_NEW_COMPANY_CARD]: OnyxTypes.AddNewCompanyCardFeed; [ONYXKEYS.ADD_NEW_PERSONAL_CARD]: OnyxTypes.AddNewPersonalCard; [ONYXKEYS.ASSIGN_CARD]: OnyxTypes.AssignCard; - [ONYXKEYS.MOBILE_SELECTION_MODE]: boolean; + [ONYXKEYS.RAM_ONLY_MOBILE_SELECTION_MODE]: boolean; [ONYXKEYS.DUPLICATE_WORKSPACE]: OnyxTypes.DuplicateWorkspace; [ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL]: string; [ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL]: string; diff --git a/src/components/LocaleContextProvider.tsx b/src/components/LocaleContextProvider.tsx index 7991e9067317..ef2c053eb5e5 100644 --- a/src/components/LocaleContextProvider.tsx +++ b/src/components/LocaleContextProvider.tsx @@ -82,7 +82,7 @@ const COLLATOR_OPTIONS: Intl.CollatorOptions = {usage: 'sort', sensitivity: 'var function LocaleContextProvider({children}: LocaleContextProviderProps) { const currentUserPersonalDetails = useCurrentUserPersonalDetails(); - const [areTranslationsLoading = true] = useOnyx(ONYXKEYS.ARE_TRANSLATIONS_LOADING, {initWithStoredValues: false}); + const [areTranslationsLoading = true] = useOnyx(ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING); const [countryCodeByIP = 1] = useOnyx(ONYXKEYS.COUNTRY_CODE); const [nvpPreferredLocale, nvpPreferredLocaleMetadata] = useOnyx(ONYXKEYS.NVP_PREFERRED_LOCALE); const [currentLocale, setCurrentLocale] = useState(() => IntlStore.getCurrentLocale()); diff --git a/src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx b/src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx index f1e9ff633a65..b594bca1fe17 100644 --- a/src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx +++ b/src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx @@ -60,7 +60,7 @@ function TransactionGroupListExpanded({ const {windowWidth} = useWindowDimensions(); const currentUserDetails = useCurrentUserPersonalDetails(); const {translate} = useLocalize(); - const [isMobileSelectionModeEnabled] = useOnyx(ONYXKEYS.MOBILE_SELECTION_MODE); + const [isMobileSelectionModeEnabled] = useOnyx(ONYXKEYS.RAM_ONLY_MOBILE_SELECTION_MODE); const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); const [betas] = useOnyx(ONYXKEYS.BETAS); const [visibleColumns] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM, {selector: columnsSelector}); diff --git a/src/hooks/useMobileSelectionMode.ts b/src/hooks/useMobileSelectionMode.ts index 51f13dc21653..6a75424c74e4 100644 --- a/src/hooks/useMobileSelectionMode.ts +++ b/src/hooks/useMobileSelectionMode.ts @@ -5,7 +5,7 @@ import useOnyx from './useOnyx'; import usePrevious from './usePrevious'; export default function useMobileSelectionMode(onTurnOffSelectionMode = () => {}) { - const [isSelectionModeEnabled = false] = useOnyx(ONYXKEYS.MOBILE_SELECTION_MODE, {initWithStoredValues: false}); + const [isSelectionModeEnabled = false] = useOnyx(ONYXKEYS.RAM_ONLY_MOBILE_SELECTION_MODE); const initialSelectionModeValueRef = useRef(isSelectionModeEnabled); const prevIsSelectionModeEnabled = usePrevious(isSelectionModeEnabled); diff --git a/src/hooks/useSearchBackPress/index.android.ts b/src/hooks/useSearchBackPress/index.android.ts index 4e677b0b7620..b6880b4cd5a9 100644 --- a/src/hooks/useSearchBackPress/index.android.ts +++ b/src/hooks/useSearchBackPress/index.android.ts @@ -7,7 +7,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type UseSearchBackPress from './types'; const useSearchBackPress: UseSearchBackPress = ({onClearSelection, onNavigationCallBack}) => { - const [selectionMode] = useOnyx(ONYXKEYS.MOBILE_SELECTION_MODE); + const [selectionMode] = useOnyx(ONYXKEYS.RAM_ONLY_MOBILE_SELECTION_MODE); useFocusEffect( useCallback(() => { const onBackPress = () => { diff --git a/src/languages/IntlStore.ts b/src/languages/IntlStore.ts index 345ccefb887a..b4870c4fb813 100644 --- a/src/languages/IntlStore.ts +++ b/src/languages/IntlStore.ts @@ -24,7 +24,7 @@ import type zhHans from './zh-hans'; // This function was added here to avoid circular dependencies function setAreTranslationsLoading(areTranslationsLoading: boolean) { // eslint-disable-next-line rulesdir/prefer-actions-set-data - Onyx.set(ONYXKEYS.ARE_TRANSLATIONS_LOADING, areTranslationsLoading); + Onyx.set(ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING, areTranslationsLoading); } class IntlStore { diff --git a/src/libs/PersonalDetailsUtils.ts b/src/libs/PersonalDetailsUtils.ts index 91a0544b6afe..6f0dbdb582c6 100644 --- a/src/libs/PersonalDetailsUtils.ts +++ b/src/libs/PersonalDetailsUtils.ts @@ -41,7 +41,7 @@ let hiddenTranslation = ''; let youTranslation = ''; Onyx.connect({ - key: ONYXKEYS.ARE_TRANSLATIONS_LOADING, + key: ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING, callback: (value) => { if (value ?? true) { return; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 802f1fc7b4e5..f05e6b48d230 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1245,8 +1245,7 @@ let hiddenTranslation = ''; let unavailableTranslation = ''; Onyx.connect({ - key: ONYXKEYS.ARE_TRANSLATIONS_LOADING, - initWithStoredValues: false, + key: ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING, callback: (value) => { if (value ?? true) { return; diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index e816aa9c91ae..82a90babd548 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -53,9 +53,8 @@ Onyx.connectWithoutView({ // `useOnyx` would trigger extra rerenders without affecting the View, so `Onyx.connectWithoutView` is used instead let isSidebarLoaded: boolean | undefined; Onyx.connectWithoutView({ - key: ONYXKEYS.IS_SIDEBAR_LOADED, + key: ONYXKEYS.RAM_ONLY_IS_SIDEBAR_LOADED, callback: (val) => (isSidebarLoaded = val), - initWithStoredValues: false, }); // `isUsingImportedState` is used in `openApp`, `reconnectApp`, and `clearOnyxAndResetApp` to prevent API calls when using imported state. @@ -122,9 +121,9 @@ Onyx.connectWithoutView({ const KEYS_TO_PRESERVE: OnyxKey[] = [ ONYXKEYS.ACCOUNT, - ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, ONYXKEYS.IS_LOADING_APP, - ONYXKEYS.IS_SIDEBAR_LOADED, + ONYXKEYS.RAM_ONLY_IS_SIDEBAR_LOADED, + ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, ONYXKEYS.MODAL, ONYXKEYS.NETWORK, ONYXKEYS.SESSION, @@ -223,7 +222,7 @@ function setSidebarLoaded() { return; } - Onyx.set(ONYXKEYS.IS_SIDEBAR_LOADED, true); + Onyx.set(ONYXKEYS.RAM_ONLY_IS_SIDEBAR_LOADED, true); } function setAppLoading(isLoading: boolean) { diff --git a/src/libs/actions/Card.ts b/src/libs/actions/Card.ts index 800de5426f5c..bb355173f9e2 100644 --- a/src/libs/actions/Card.ts +++ b/src/libs/actions/Card.ts @@ -749,7 +749,7 @@ function getCardDefaultName(userName?: string) { } function setIssueNewCardStepAndData({data, isEditing, step, policyID, isChangeAssigneeDisabled}: IssueNewCardFlowData) { - Onyx.merge(`${ONYXKEYS.COLLECTION.ISSUE_NEW_EXPENSIFY_CARD}${policyID}`, { + Onyx.merge(`${ONYXKEYS.COLLECTION.RAM_ONLY_ISSUE_NEW_EXPENSIFY_CARD}${policyID}`, { data, isEditing, currentStep: step, @@ -765,7 +765,7 @@ function setDraftInviteAccountID(assigneeEmail: string | undefined, assigneeAcco } function clearIssueNewCardFlow(policyID: string | undefined) { - Onyx.set(`${ONYXKEYS.COLLECTION.ISSUE_NEW_EXPENSIFY_CARD}${policyID}`, { + Onyx.set(`${ONYXKEYS.COLLECTION.RAM_ONLY_ISSUE_NEW_EXPENSIFY_CARD}${policyID}`, { currentStep: null, data: {}, isSuccessful: false, @@ -778,7 +778,7 @@ function clearIssueNewCardFormData() { } function clearIssueNewCardError(policyID: string | undefined) { - Onyx.merge(`${ONYXKEYS.COLLECTION.ISSUE_NEW_EXPENSIFY_CARD}${policyID}`, {errors: null}); + Onyx.merge(`${ONYXKEYS.COLLECTION.RAM_ONLY_ISSUE_NEW_EXPENSIFY_CARD}${policyID}`, {errors: null}); } function buildCardListUpdates(workspaceAccountID: number, cardID: number, cardUpdateData: CardListUpdateData, shouldUpdateCardList: boolean): CardOnyxUpdate[] { @@ -1368,10 +1368,10 @@ function issueExpensifyCard( const {assigneeEmail, limit, limitType, cardTitle, cardType, validFrom, validThru} = data; - const optimisticData: Array> = [ + const optimisticData: Array> = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.ISSUE_NEW_EXPENSIFY_CARD}${policyID}`, + key: `${ONYXKEYS.COLLECTION.RAM_ONLY_ISSUE_NEW_EXPENSIFY_CARD}${policyID}`, value: { isLoading: true, errors: null, @@ -1380,10 +1380,10 @@ function issueExpensifyCard( }, ]; - const successData: Array> = [ + const successData: Array> = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.ISSUE_NEW_EXPENSIFY_CARD}${policyID}`, + key: `${ONYXKEYS.COLLECTION.RAM_ONLY_ISSUE_NEW_EXPENSIFY_CARD}${policyID}`, value: { isLoading: false, isSuccessful: true, @@ -1391,10 +1391,10 @@ function issueExpensifyCard( }, ]; - const failureData: Array> = [ + const failureData: Array> = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.ISSUE_NEW_EXPENSIFY_CARD}${policyID}`, + key: `${ONYXKEYS.COLLECTION.RAM_ONLY_ISSUE_NEW_EXPENSIFY_CARD}${policyID}`, value: { isLoading: false, errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), diff --git a/src/libs/actions/Delegate.ts b/src/libs/actions/Delegate.ts index 2c66412bc1fd..a31097d7e3a7 100644 --- a/src/libs/actions/Delegate.ts +++ b/src/libs/actions/Delegate.ts @@ -24,7 +24,7 @@ const KEYS_TO_PRESERVE_DELEGATE_ACCESS = [ ONYXKEYS.NVP_TRY_FOCUS_MODE, ONYXKEYS.PREFERRED_THEME, ONYXKEYS.NVP_PREFERRED_LOCALE, - ONYXKEYS.ARE_TRANSLATIONS_LOADING, + ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING, ONYXKEYS.SESSION, ONYXKEYS.STASHED_SESSION, ONYXKEYS.HAS_LOADED_APP, @@ -33,7 +33,7 @@ const KEYS_TO_PRESERVE_DELEGATE_ACCESS = [ // We need to preserve the sidebar loaded state since we never unmount the sidebar when connecting as a delegate // This allows the report screen to load correctly when the delegate token expires and the delegate is returned to their original account. - ONYXKEYS.IS_SIDEBAR_LOADED, + ONYXKEYS.RAM_ONLY_IS_SIDEBAR_LOADED, ONYXKEYS.NETWORK, ONYXKEYS.SHOULD_USE_STAGING_SERVER, ONYXKEYS.IS_DEBUG_MODE_ENABLED, diff --git a/src/libs/actions/MobileSelectionMode.ts b/src/libs/actions/MobileSelectionMode.ts index 65c6e463461b..d21fdca0da8a 100644 --- a/src/libs/actions/MobileSelectionMode.ts +++ b/src/libs/actions/MobileSelectionMode.ts @@ -2,11 +2,11 @@ import Onyx from 'react-native-onyx'; import ONYXKEYS from '@src/ONYXKEYS'; const turnOnMobileSelectionMode = () => { - Onyx.merge(ONYXKEYS.MOBILE_SELECTION_MODE, true); + Onyx.merge(ONYXKEYS.RAM_ONLY_MOBILE_SELECTION_MODE, true); }; const turnOffMobileSelectionMode = () => { - Onyx.merge(ONYXKEYS.MOBILE_SELECTION_MODE, false); + Onyx.merge(ONYXKEYS.RAM_ONLY_MOBILE_SELECTION_MODE, false); }; export {turnOnMobileSelectionMode, turnOffMobileSelectionMode}; diff --git a/src/libs/actions/OnyxDerived/index.ts b/src/libs/actions/OnyxDerived/index.ts index ac245f116b1b..57950c582d5f 100644 --- a/src/libs/actions/OnyxDerived/index.ts +++ b/src/libs/actions/OnyxDerived/index.ts @@ -115,8 +115,7 @@ function init() { } else if (dependencyOnyxKey === ONYXKEYS.NVP_PREFERRED_LOCALE) { // Special case for locale, we want to recompute derived values when the locale change actually loads. Onyx.connectWithoutView({ - key: ONYXKEYS.ARE_TRANSLATIONS_LOADING, - initWithStoredValues: false, + key: ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING, callback: (value) => { if (value ?? true) { Log.info(`[OnyxDerived] translations are still loading, not recomputing derived value for ${key}`); diff --git a/src/libs/actions/QueuedOnyxUpdates.ts b/src/libs/actions/QueuedOnyxUpdates.ts index be2a1480ccec..62ce86816243 100644 --- a/src/libs/actions/QueuedOnyxUpdates.ts +++ b/src/libs/actions/QueuedOnyxUpdates.ts @@ -38,12 +38,12 @@ function flushQueue(): Promise { ONYXKEYS.NVP_TRY_FOCUS_MODE, ONYXKEYS.PREFERRED_THEME, ONYXKEYS.NVP_PREFERRED_LOCALE, - ONYXKEYS.ARE_TRANSLATIONS_LOADING, + ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING, ONYXKEYS.SESSION, ONYXKEYS.IS_LOADING_APP, ONYXKEYS.HAS_LOADED_APP, ONYXKEYS.CREDENTIALS, - ONYXKEYS.IS_SIDEBAR_LOADED, + ONYXKEYS.RAM_ONLY_IS_SIDEBAR_LOADED, ONYXKEYS.ACCOUNT, ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, ONYXKEYS.MODAL, diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 7c598de7718e..91ad7b0d601b 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -300,7 +300,7 @@ const KEYS_TO_PRESERVE_SUPPORTAL = [ ONYXKEYS.NVP_TRY_FOCUS_MODE, ONYXKEYS.PREFERRED_THEME, ONYXKEYS.NVP_PREFERRED_LOCALE, - ONYXKEYS.ARE_TRANSLATIONS_LOADING, + ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING, ONYXKEYS.SESSION, ONYXKEYS.STASHED_SESSION, ONYXKEYS.HAS_LOADED_APP, @@ -309,7 +309,7 @@ const KEYS_TO_PRESERVE_SUPPORTAL = [ // We need to preserve the sidebar loaded state since we never unmount the sidebar when connecting as a delegate // This allows the report screen to load correctly when the delegate token expires and the delegate is returned to their original account. - ONYXKEYS.IS_SIDEBAR_LOADED, + ONYXKEYS.RAM_ONLY_IS_SIDEBAR_LOADED, ONYXKEYS.NETWORK, ONYXKEYS.SHOULD_USE_STAGING_SERVER, ONYXKEYS.IS_DEBUG_MODE_ENABLED, diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index 8fcf14765ab0..c07a8cbccbf5 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -50,7 +50,7 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { // flashes of unwanted default state. const keysToPreserve: OnyxKey[] = []; keysToPreserve.push(ONYXKEYS.NVP_PREFERRED_LOCALE); - keysToPreserve.push(ONYXKEYS.ARE_TRANSLATIONS_LOADING); + keysToPreserve.push(ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING); keysToPreserve.push(ONYXKEYS.PREFERRED_THEME); keysToPreserve.push(ONYXKEYS.ACTIVE_CLIENTS); keysToPreserve.push(ONYXKEYS.DEVICE_ID); diff --git a/src/libs/actions/Wallet.ts b/src/libs/actions/Wallet.ts index 27625e744cd6..f1d6aa424d44 100644 --- a/src/libs/actions/Wallet.ts +++ b/src/libs/actions/Wallet.ts @@ -206,7 +206,27 @@ function openInitialSettingsPage() { * Fetches data when the user opens the EnablePaymentsPage */ function openEnablePaymentsPage() { - API.read(READ_COMMANDS.OPEN_ENABLE_PAYMENTS_PAGE, null); + const optimisticData: Array> = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.USER_WALLET, + value: { + isLoading: true, + }, + }, + ]; + + const finallyData: Array> = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.USER_WALLET, + value: { + isLoading: false, + }, + }, + ]; + + API.read(READ_COMMANDS.OPEN_ENABLE_PAYMENTS_PAGE, null, {optimisticData, finallyData}); } function updateCurrentStep(currentStep: ValueOf | null) { diff --git a/src/pages/EnablePayments/EnablePayments.tsx b/src/pages/EnablePayments/EnablePayments.tsx index a4d8ee60bbfd..abacc0da2d83 100644 --- a/src/pages/EnablePayments/EnablePayments.tsx +++ b/src/pages/EnablePayments/EnablePayments.tsx @@ -35,13 +35,11 @@ function EnablePaymentsPage() { return; } - if (isEmptyObject(userWallet)) { - openEnablePaymentsPage(); - } - }, [isOffline, userWallet]); + openEnablePaymentsPage(); + }, [isOffline]); const isUserWalletEmpty = isEmptyObject(userWallet); - if (isUserWalletEmpty) { + if (isUserWalletEmpty || userWallet?.isLoading) { const reasonAttributes: SkeletonSpanReasonAttributes = { context: 'EnablePaymentsPage', isUserWalletEmpty, diff --git a/src/pages/EnablePayments/EnablePaymentsPage.tsx b/src/pages/EnablePayments/EnablePaymentsPage.tsx index 6968aa048569..af0c83086376 100644 --- a/src/pages/EnablePayments/EnablePaymentsPage.tsx +++ b/src/pages/EnablePayments/EnablePaymentsPage.tsx @@ -1,4 +1,4 @@ -import React, {useEffect} from 'react'; +import React, {useEffect, useRef} from 'react'; import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; @@ -22,30 +22,44 @@ import TermsStep from './TermsStep'; function EnablePaymentsPage() { const {translate} = useLocalize(); const {isOffline} = useNetwork(); - const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET, { - // We want to refresh the wallet each time the user attempts to activate the wallet so we won't use the - // stored values here. - initWithStoredValues: false, - }); + const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET); const {isPendingOnfidoResult, hasFailedOnfido} = userWallet ?? {}; + const wasLoadingRef = useRef(false); + // Always fetch fresh wallet data on mount useEffect(() => { if (isOffline) { return; } + openEnablePaymentsPage(); + }, [isOffline]); + + // Only redirect after the fresh data loading cycle (isLoading: true → false) completes, + // to avoid acting on stale cached values from a previous session. + useEffect(() => { + if (isOffline) { + return; + } + + if (userWallet?.isLoading) { + wasLoadingRef.current = true; + return; + } + + if (!wasLoadingRef.current) { + return; + } + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing if (isPendingOnfidoResult || hasFailedOnfido) { Navigation.navigate(ROUTES.SETTINGS_WALLET, {forceReplace: true}); - return; } - - openEnablePaymentsPage(); - }, [isOffline, isPendingOnfidoResult, hasFailedOnfido]); + }, [isOffline, isPendingOnfidoResult, hasFailedOnfido, userWallet?.isLoading]); const isUserWalletEmpty = isEmptyObject(userWallet); - if (isUserWalletEmpty) { + if (isUserWalletEmpty || userWallet?.isLoading) { const reasonAttributes: SkeletonSpanReasonAttributes = { context: 'EnablePaymentsPage', isUserWalletEmpty, diff --git a/src/pages/ValidateLoginPage/index.website.tsx b/src/pages/ValidateLoginPage/index.website.tsx index 4fe5ad2a7ca1..3081b9ed9744 100644 --- a/src/pages/ValidateLoginPage/index.website.tsx +++ b/src/pages/ValidateLoginPage/index.website.tsx @@ -1,4 +1,4 @@ -import React, {useEffect} from 'react'; +import React, {useEffect, useState} from 'react'; import type {OnyxEntry} from 'react-native-onyx'; import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; import ExpiredValidateCodeModal from '@components/ValidateCode/ExpiredValidateCodeModal'; @@ -26,10 +26,13 @@ function ValidateLoginPage({ const login = credentials?.login; const isSignedIn = !!session?.authToken && session?.authTokenType !== CONST.AUTH_TOKEN_TYPES.ANONYMOUS; - // To ensure that the previous autoAuthState does not impact the rendering of the current magic link page, the autoAuthState prop sets initWithStoredValues to false. - // This is done unless the user is signed in, in which case the page will be remounted upon successful sign-in, as explained in Session.initAutoAuthState. - const [autoAuthState] = useOnyx(ONYXKEYS.SESSION, {initWithStoredValues: isSignedIn, selector: autoAuthStateSelector}); - const autoAuthStateWithDefault = autoAuthState ?? CONST.AUTO_AUTH_STATE.NOT_STARTED; + // When not signed in, ignore stored autoAuthState on the first render to prevent stale values + // (e.g. FAILED from a previous magic link attempt) from briefly rendering incorrect UI. + // Once initAutoAuthState() runs in the useEffect, the state is set to true and real values are used. + const [hasInitialized, setHasInitialized] = useState(isSignedIn); + const [autoAuthState] = useOnyx(ONYXKEYS.SESSION, {selector: autoAuthStateSelector}); + const effectiveAutoAuthState = hasInitialized ? autoAuthState : undefined; + const autoAuthStateWithDefault = effectiveAutoAuthState ?? CONST.AUTO_AUTH_STATE.NOT_STARTED; const is2FARequired = !!account?.requiresTwoFactorAuth; const cachedAccountID = credentials?.accountID; const isUserClickedSignIn = !login && isSignedIn && (autoAuthStateWithDefault === CONST.AUTO_AUTH_STATE.SIGNING_IN || autoAuthStateWithDefault === CONST.AUTO_AUTH_STATE.JUST_SIGNED_IN); @@ -38,6 +41,8 @@ function ValidateLoginPage({ const [preferredLocale] = useOnyx(ONYXKEYS.NVP_PREFERRED_LOCALE); useEffect(() => { + setHasInitialized(true); + if (isUserClickedSignIn) { // The user clicked the option to sign in the current tab Navigation.isNavigationReady().then(() => { @@ -82,13 +87,13 @@ function ValidateLoginPage({ )} {autoAuthStateWithDefault === CONST.AUTO_AUTH_STATE.JUST_SIGNED_IN && isSignedIn && !exitTo && !!login && } {/* If session.autoAuthState isn't available yet, we use shouldStartSignInWithValidateCode to conditionally render the component instead of local autoAuthState which contains a default value of NOT_STARTED */} - {(!autoAuthState ? !shouldStartSignInWithValidateCode : autoAuthStateWithDefault === CONST.AUTO_AUTH_STATE.NOT_STARTED && !isNavigatingToExitTo) && ( + {(!effectiveAutoAuthState ? !shouldStartSignInWithValidateCode : autoAuthStateWithDefault === CONST.AUTO_AUTH_STATE.NOT_STARTED && !isNavigatingToExitTo) && ( )} - {(!autoAuthState ? shouldStartSignInWithValidateCode : autoAuthStateWithDefault === CONST.AUTO_AUTH_STATE.SIGNING_IN) && ( + {(!effectiveAutoAuthState ? shouldStartSignInWithValidateCode : autoAuthStateWithDefault === CONST.AUTO_AUTH_STATE.SIGNING_IN) && ( { diff --git a/src/pages/workspace/expensifyCard/issueNew/IssueNewCardConfirmMagicCodePage.tsx b/src/pages/workspace/expensifyCard/issueNew/IssueNewCardConfirmMagicCodePage.tsx index b2c2e01fe5d9..242fc4626e02 100644 --- a/src/pages/workspace/expensifyCard/issueNew/IssueNewCardConfirmMagicCodePage.tsx +++ b/src/pages/workspace/expensifyCard/issueNew/IssueNewCardConfirmMagicCodePage.tsx @@ -26,7 +26,7 @@ function IssueNewCardConfirmMagicCodePage({route}: IssueNewCardConfirmMagicCodeP const [account] = useOnyx(ONYXKEYS.ACCOUNT); const [session] = useOnyx(ONYXKEYS.SESSION); const primaryLogin = account?.primaryLogin ?? session?.email ?? ''; - const [issueNewCard] = useOnyx(`${ONYXKEYS.COLLECTION.ISSUE_NEW_EXPENSIFY_CARD}${policyID}`); + const [issueNewCard] = useOnyx(`${ONYXKEYS.COLLECTION.RAM_ONLY_ISSUE_NEW_EXPENSIFY_CARD}${policyID}`); const validateError = getLatestErrorMessageField(issueNewCard); const data = issueNewCard?.data; const isSuccessful = issueNewCard?.isSuccessful; diff --git a/src/pages/workspace/expensifyCard/issueNew/IssueNewCardPage.tsx b/src/pages/workspace/expensifyCard/issueNew/IssueNewCardPage.tsx index ac6bd562bfbe..cc39f988df40 100644 --- a/src/pages/workspace/expensifyCard/issueNew/IssueNewCardPage.tsx +++ b/src/pages/workspace/expensifyCard/issueNew/IssueNewCardPage.tsx @@ -46,7 +46,7 @@ function getStartStepIndex(issueNewCard: OnyxEntry): number { function IssueNewCardPage({policy, route}: IssueNewCardPageProps) { const policyID = policy?.id; - const [issueNewCard] = useOnyx(`${ONYXKEYS.COLLECTION.ISSUE_NEW_EXPENSIFY_CARD}${policyID}`, {initWithStoredValues: false}); + const [issueNewCard] = useOnyx(`${ONYXKEYS.COLLECTION.RAM_ONLY_ISSUE_NEW_EXPENSIFY_CARD}${policyID}`); const {currentStep} = issueNewCard ?? {}; const backTo = route?.params?.backTo; const {isDelegateAccessRestricted} = useDelegateNoAccessState(); diff --git a/src/pages/workspace/expensifyCard/issueNew/LimitTypeStep.tsx b/src/pages/workspace/expensifyCard/issueNew/LimitTypeStep.tsx index 941339de9921..6e634ee2a96c 100644 --- a/src/pages/workspace/expensifyCard/issueNew/LimitTypeStep.tsx +++ b/src/pages/workspace/expensifyCard/issueNew/LimitTypeStep.tsx @@ -38,7 +38,7 @@ function LimitTypeStep({policy, stepNames, startStepIndex}: LimitTypeStepProps) const {translate} = useLocalize(); const styles = useThemeStyles(); const policyID = policy?.id; - const [issueNewCard] = useOnyx(`${ONYXKEYS.COLLECTION.ISSUE_NEW_EXPENSIFY_CARD}${policyID}`); + const [issueNewCard] = useOnyx(`${ONYXKEYS.COLLECTION.RAM_ONLY_ISSUE_NEW_EXPENSIFY_CARD}${policyID}`); const formRef = useRef(null); const areApprovalsConfigured = getApprovalWorkflow(policy) !== CONST.POLICY.APPROVAL_MODE.OPTIONAL; diff --git a/src/pages/workspace/expensifyCard/issueNew/SetExpiryOptionsStep.tsx b/src/pages/workspace/expensifyCard/issueNew/SetExpiryOptionsStep.tsx index 78ad0e1bd6f6..1b49efb79427 100644 --- a/src/pages/workspace/expensifyCard/issueNew/SetExpiryOptionsStep.tsx +++ b/src/pages/workspace/expensifyCard/issueNew/SetExpiryOptionsStep.tsx @@ -33,7 +33,7 @@ function SetExpiryOptionsStep({policy, stepNames, startStepIndex}: SetExpiryOpti const {translate} = useLocalize(); const styles = useThemeStyles(); const policyID = policy?.id; - const [issueNewCard] = useOnyx(`${ONYXKEYS.COLLECTION.ISSUE_NEW_EXPENSIFY_CARD}${policyID}`); + const [issueNewCard] = useOnyx(`${ONYXKEYS.COLLECTION.RAM_ONLY_ISSUE_NEW_EXPENSIFY_CARD}${policyID}`); const personalDetails = usePersonalDetails(); const assigneePersonalDetails = Object.values(personalDetails ?? {}).find((detail) => detail?.login === issueNewCard?.data?.assigneeEmail); diff --git a/src/setup/index.ts b/src/setup/index.ts index 0daed09b2bcb..49785d8449ff 100644 --- a/src/setup/index.ts +++ b/src/setup/index.ts @@ -48,7 +48,7 @@ export default function () { [ONYXKEYS.SESSION]: {loading: false}, [ONYXKEYS.ACCOUNT]: CONST.DEFAULT_ACCOUNT_DATA, [ONYXKEYS.NETWORK]: CONST.DEFAULT_NETWORK_DATA, - [ONYXKEYS.IS_SIDEBAR_LOADED]: false, + [ONYXKEYS.RAM_ONLY_IS_SIDEBAR_LOADED]: false, [ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT]: true, [ONYXKEYS.MODAL]: { isVisible: false, @@ -61,6 +61,10 @@ export default function () { skippableCollectionMemberIDs: CONST.SKIPPABLE_COLLECTION_MEMBER_IDS, snapshotMergeKeys: ['pendingAction', 'pendingFields'], ramOnlyKeys: [ + ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING, + ONYXKEYS.RAM_ONLY_MOBILE_SELECTION_MODE, + ONYXKEYS.RAM_ONLY_IS_SIDEBAR_LOADED, + ONYXKEYS.COLLECTION.RAM_ONLY_ISSUE_NEW_EXPENSIFY_CARD, ONYXKEYS.DERIVED.RAM_ONLY_SORTED_REPORT_ACTIONS, ONYXKEYS.RAM_ONLY_UPDATE_AVAILABLE, ONYXKEYS.RAM_ONLY_UPDATE_REQUIRED, diff --git a/src/types/onyx/UserWallet.ts b/src/types/onyx/UserWallet.ts index eb1b11c7adb0..c67e5b529c37 100644 --- a/src/types/onyx/UserWallet.ts +++ b/src/types/onyx/UserWallet.ts @@ -63,6 +63,9 @@ type UserWallet = { /** The type of setup for adding the bank account */ setupType?: SetupType; + + /** Whether the wallet data is currently being loaded from the server */ + isLoading?: boolean; }; export default UserWallet; diff --git a/tests/actions/QueuedOnyxUpdatesTest.ts b/tests/actions/QueuedOnyxUpdatesTest.ts index d9959d31f6d4..5a7190f42945 100644 --- a/tests/actions/QueuedOnyxUpdatesTest.ts +++ b/tests/actions/QueuedOnyxUpdatesTest.ts @@ -13,7 +13,7 @@ const queuedOnyxUpdates: Array< | typeof ONYXKEYS.SESSION | typeof ONYXKEYS.IS_LOADING_APP | typeof ONYXKEYS.CREDENTIALS - | typeof ONYXKEYS.IS_SIDEBAR_LOADED + | typeof ONYXKEYS.RAM_ONLY_IS_SIDEBAR_LOADED | typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS > @@ -42,7 +42,7 @@ const queuedOnyxUpdates: Array< }, onyxMethod: 'merge', }, - {key: ONYXKEYS.IS_SIDEBAR_LOADED, value: true, onyxMethod: 'merge'}, + {key: ONYXKEYS.RAM_ONLY_IS_SIDEBAR_LOADED, value: true, onyxMethod: 'merge'}, {key: `${ONYXKEYS.COLLECTION.REPORT}2175919089355165`, value: {reportID: 'reportID'}, onyxMethod: 'merge'}, { key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2175919089355165`, @@ -106,7 +106,7 @@ describe('actions/QueuedOnyxUpdates', () => { await testOnyxKeyValue(ONYXKEYS.SESSION); await testOnyxKeyValue(ONYXKEYS.IS_LOADING_APP); await testOnyxKeyValue(ONYXKEYS.CREDENTIALS); - await testOnyxKeyValue(ONYXKEYS.IS_SIDEBAR_LOADED); + await testOnyxKeyValue(ONYXKEYS.RAM_ONLY_IS_SIDEBAR_LOADED); await new Promise((resolve) => { const connection = Onyx.connect({ @@ -151,7 +151,7 @@ describe('actions/QueuedOnyxUpdates', () => { await testOnyxKeyValue(ONYXKEYS.SESSION); await testOnyxKeyValue(ONYXKEYS.IS_LOADING_APP); await testOnyxKeyValue(ONYXKEYS.CREDENTIALS); - await testOnyxKeyValue(ONYXKEYS.IS_SIDEBAR_LOADED); + await testOnyxKeyValue(ONYXKEYS.RAM_ONLY_IS_SIDEBAR_LOADED); await new Promise((resolve) => { const connection = Onyx.connect({ diff --git a/tests/ui/ReportActionsViewTest.tsx b/tests/ui/ReportActionsViewTest.tsx index a54817dec5fe..8983c0705aaa 100644 --- a/tests/ui/ReportActionsViewTest.tsx +++ b/tests/ui/ReportActionsViewTest.tsx @@ -199,7 +199,7 @@ describe('ReportActionsView', () => { if (key === ONYXKEYS.IS_LOADING_APP) { return [false, {status: 'loaded'}]; } - if (key === ONYXKEYS.ARE_TRANSLATIONS_LOADING) { + if (key === ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING) { return [false, {status: 'loaded'}]; } if (key.includes('reportMetadata')) { @@ -233,7 +233,7 @@ describe('ReportActionsView', () => { if (key === ONYXKEYS.IS_LOADING_APP) { return [true, {status: 'loaded'}]; } - if (key === ONYXKEYS.ARE_TRANSLATIONS_LOADING) { + if (key === ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING) { return [false, {status: 'loaded'}]; } if (key.includes('reportMetadata')) { @@ -270,7 +270,7 @@ describe('ReportActionsView', () => { if (key === ONYXKEYS.IS_LOADING_APP) { return [false, {status: 'loaded'}]; } - if (key === ONYXKEYS.ARE_TRANSLATIONS_LOADING) { + if (key === ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING) { return [false, {status: 'loaded'}]; } if (key.includes('reportMetadata')) { @@ -302,7 +302,7 @@ describe('ReportActionsView', () => { if (key === ONYXKEYS.IS_LOADING_APP) { return [true, {status: 'loaded'}]; } - if (key === ONYXKEYS.ARE_TRANSLATIONS_LOADING) { + if (key === ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING) { return [false, {status: 'loaded'}]; } if (key.includes('reportMetadata')) { @@ -334,7 +334,7 @@ describe('ReportActionsView', () => { if (key === ONYXKEYS.IS_LOADING_APP) { return [false, {status: 'loaded'}]; } - if (key === ONYXKEYS.ARE_TRANSLATIONS_LOADING) { + if (key === ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING) { return [false, {status: 'loaded'}]; } if (key.includes('reportMetadata')) { @@ -400,7 +400,7 @@ describe('ReportActionsView', () => { if (key === ONYXKEYS.IS_LOADING_APP) { return [false, {status: 'loaded'}]; } - if (key === ONYXKEYS.ARE_TRANSLATIONS_LOADING) { + if (key === ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING) { return [false, {status: 'loaded'}]; } if (key.includes('reportMetadata')) { diff --git a/tests/unit/LocalizeTests.ts b/tests/unit/LocalizeTests.ts index dc84bec2c1ac..b97d26ca4283 100644 --- a/tests/unit/LocalizeTests.ts +++ b/tests/unit/LocalizeTests.ts @@ -56,7 +56,7 @@ describe('localize', () => { Onyx.init({ keys: { NVP_PREFERRED_LOCALE: ONYXKEYS.NVP_PREFERRED_LOCALE, - ARE_TRANSLATIONS_LOADING: ONYXKEYS.ARE_TRANSLATIONS_LOADING, + ARE_TRANSLATIONS_LOADING: ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING, SESSION: ONYXKEYS.SESSION, }, }); diff --git a/tests/unit/OnyxDerivedTest.tsx b/tests/unit/OnyxDerivedTest.tsx index f3d974cf974c..142bad735f98 100644 --- a/tests/unit/OnyxDerivedTest.tsx +++ b/tests/unit/OnyxDerivedTest.tsx @@ -38,7 +38,7 @@ describe('OnyxDerived', () => { beforeEach(async () => { // The reportAttributes locale connection uses initWithStoredValues: false, // so it doesn't fire after Onyx.clear(). Setting this triggers recomputation. - await Onyx.set(ONYXKEYS.ARE_TRANSLATIONS_LOADING, false); + await Onyx.set(ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING, false); await waitForBatchedUpdates(); });