diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 0cc958404a3dd..95b83bc5a5e60 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -434,6 +434,12 @@ const ONYXKEYS = { /** Indicates whether we should mask fragile user data while exporting onyx state or not */ SHOULD_MASK_ONYX_STATE: 'shouldMaskOnyxState', + /** Indicates whether we should use the staging version of the secure API server */ + SHOULD_USE_STAGING_SERVER: 'shouldUseStagingServer', + + /** Indicates whether the debug mode is currently enabled */ + IS_DEBUG_MODE_ENABLED: 'isDebugModeEnabled', + /** Stores new group chat draft */ NEW_GROUP_CHAT_DRAFT: 'newGroupChatDraft', @@ -1203,6 +1209,8 @@ type OnyxValuesMapping = { [ONYXKEYS.SHOULD_STORE_LOGS]: boolean; [ONYXKEYS.SHOULD_RECORD_TROUBLESHOOT_DATA]: boolean; [ONYXKEYS.SHOULD_MASK_ONYX_STATE]: boolean; + [ONYXKEYS.SHOULD_USE_STAGING_SERVER]: boolean; + [ONYXKEYS.IS_DEBUG_MODE_ENABLED]: boolean; [ONYXKEYS.CACHED_PDF_PATHS]: Record; [ONYXKEYS.POLICY_OWNERSHIP_CHANGE_CHECKS]: Record; [ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE]: OnyxTypes.QuickAction; diff --git a/src/components/AccountSwitcher.tsx b/src/components/AccountSwitcher.tsx index 834cf97e5d36b..3dfb1bc10a954 100644 --- a/src/components/AccountSwitcher.tsx +++ b/src/components/AccountSwitcher.tsx @@ -45,6 +45,7 @@ function AccountSwitcher({isScreenFocused}: AccountSwitcherProps) { const {shouldUseNarrowLayout} = useResponsiveLayout(); const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true}); const [accountID] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false, selector: (onyxSession) => onyxSession?.accountID}); + const [isDebugModeEnabled] = useOnyx(ONYXKEYS.IS_DEBUG_MODE_ENABLED, {canBeMissing: true}); const buttonRef = useRef(null); const {windowHeight} = useWindowDimensions(); @@ -224,7 +225,7 @@ function AccountSwitcher({isScreenFocused}: AccountSwitcherProps) { > {Str.removeSMSDomain(currentUserPersonalDetails?.login ?? '')} - {!!account?.isDebugModeEnabled && ( + {!!isDebugModeEnabled && ( ; + shouldUseStagingServer: OnyxEntry; }; type ImageRendererProps = ImageRendererWithOnyxProps & CustomRendererProps; @@ -150,16 +149,16 @@ ImageRenderer.displayName = 'ImageRenderer'; const ImageRendererMemorize = memo( ImageRenderer, - (prevProps, nextProps) => prevProps.tnode.attributes === nextProps.tnode.attributes && prevProps.account?.shouldUseStagingServer === nextProps.account?.shouldUseStagingServer, + (prevProps, nextProps) => prevProps.tnode.attributes === nextProps.tnode.attributes && prevProps.shouldUseStagingServer === nextProps.shouldUseStagingServer, ); function ImageRendererWrapper(props: CustomRendererProps) { - const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false}); + const [shouldUseStagingServer] = useOnyx(ONYXKEYS.SHOULD_USE_STAGING_SERVER, {canBeMissing: true}); return ( ); } diff --git a/src/components/Navigation/NavigationTabBar/index.tsx b/src/components/Navigation/NavigationTabBar/index.tsx index 88d6c51fa27e6..fccf408f6447e 100644 --- a/src/components/Navigation/NavigationTabBar/index.tsx +++ b/src/components/Navigation/NavigationTabBar/index.tsx @@ -54,7 +54,7 @@ function NavigationTabBar({selectedTab, isTooltipAllowed = false, isTopLevelBar const {translate, preferredLocale} = useLocalize(); const {indicatorColor: workspacesTabIndicatorColor, status: workspacesTabIndicatorStatus} = useWorkspacesTabIndicatorStatus(); const {orderedReportIDs} = useSidebarOrderedReports(); - const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false}); + const [isDebugModeEnabled] = useOnyx(ONYXKEYS.IS_DEBUG_MODE_ENABLED, {canBeMissing: true}); const [savedSearches] = useOnyx(ONYXKEYS.SAVED_SEARCHES, {canBeMissing: true}); const navigationState = useNavigationState(findFocusedRoute); const initialNavigationRouteState = getWorkspaceNavigationRouteState(); @@ -102,7 +102,7 @@ function NavigationTabBar({selectedTab, isTooltipAllowed = false, isTopLevelBar }, [navigationState]); // On a wide layout DebugTabView should be rendered only within the navigation tab bar displayed directly on screens. - const shouldRenderDebugTabViewOnWideLayout = !!account?.isDebugModeEnabled && !isTopLevelBar; + const shouldRenderDebugTabViewOnWideLayout = !!isDebugModeEnabled && !isTopLevelBar; useEffect(() => { setChatTabBrickRoad(getChatTabBrickRoad(orderedReportIDs, reportAttributes)); @@ -310,7 +310,7 @@ function NavigationTabBar({selectedTab, isTooltipAllowed = false, isTopLevelBar return ( <> - {!!account?.isDebugModeEnabled && ( + {!!isDebugModeEnabled && ( { // We only use the value of shouldUseStagingServer to determine which server we should point to. // Since they aren't connected to a UI anywhere, it's OK to use connectWithoutView() Onyx.connectWithoutView({ - key: ONYXKEYS.ACCOUNT, + key: ONYXKEYS.SHOULD_USE_STAGING_SERVER, callback: (value) => { // Toggling between APIs is not allowed on production and internal dev environment if (ENV_NAME === CONST.ENVIRONMENT.PRODUCTION || CONFIG.IS_USING_LOCAL_WEB) { @@ -27,7 +27,7 @@ getEnvironment().then((envName) => { } const defaultToggleState = ENV_NAME === CONST.ENVIRONMENT.STAGING || ENV_NAME === CONST.ENVIRONMENT.ADHOC; - shouldUseStagingServer = value?.shouldUseStagingServer ?? defaultToggleState; + shouldUseStagingServer = value ?? defaultToggleState; }, }); }); diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index 960876ff3edbf..2a9912777c982 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -62,14 +62,6 @@ Onyx.connectWithoutView({ }, }); -let preservedShouldUseStagingServer: boolean | undefined; -Onyx.connect({ - key: ONYXKEYS.ACCOUNT, - callback: (value) => { - preservedShouldUseStagingServer = value?.shouldUseStagingServer; - }, -}); - // hasLoadedAppPromise is used in the "reconnectApp" function and is not directly associated with the View, // so retrieving it using Onyx.connectWithoutView is correct. let resolveHasLoadedAppPromise: () => void; @@ -123,6 +115,8 @@ const KEYS_TO_PRESERVE: OnyxKey[] = [ ONYXKEYS.CREDENTIALS, ONYXKEYS.PRESERVED_USER_SESSION, ONYXKEYS.HYBRID_APP, + ONYXKEYS.SHOULD_USE_STAGING_SERVER, + ONYXKEYS.IS_DEBUG_MODE_ENABLED, ]; /* @@ -617,7 +611,6 @@ function setPreservedUserSession(session: OnyxTypes.Session) { function clearOnyxAndResetApp(shouldNavigateToHomepage?: boolean) { // The value of isUsingImportedState will be lost once Onyx is cleared, so we need to store it const isStateImported = isUsingImportedState; - const shouldUseStagingServer = preservedShouldUseStagingServer; const sequentialQueue = getAll(); rollbackOngoingRequest(); @@ -637,10 +630,6 @@ function clearOnyxAndResetApp(shouldNavigateToHomepage?: boolean) { Onyx.set(ONYXKEYS.SESSION, preservedUserSession); Onyx.set(ONYXKEYS.PRESERVED_USER_SESSION, null); } - - if (shouldUseStagingServer) { - Onyx.set(ONYXKEYS.ACCOUNT, {shouldUseStagingServer}); - } }) .then(() => { // Requests in a sequential queue should be called even if the Onyx state is reset, so we do not lose any pending data. diff --git a/src/libs/actions/Delegate.ts b/src/libs/actions/Delegate.ts index dde956df777a4..fe38066f02e71 100644 --- a/src/libs/actions/Delegate.ts +++ b/src/libs/actions/Delegate.ts @@ -75,6 +75,8 @@ const KEYS_TO_PRESERVE_DELEGATE_ACCESS = [ // 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.NETWORK, + ONYXKEYS.SHOULD_USE_STAGING_SERVER, + ONYXKEYS.IS_DEBUG_MODE_ENABLED, ]; /** diff --git a/src/libs/actions/HybridApp/types.ts b/src/libs/actions/HybridApp/types.ts index 5d4ab1431cbc7..0236e8b7cc858 100644 --- a/src/libs/actions/HybridApp/types.ts +++ b/src/libs/actions/HybridApp/types.ts @@ -5,7 +5,7 @@ import type HybridApp from '@src/types/onyx/HybridApp'; type HybridAppSettings = { [ONYXKEYS.HYBRID_APP]: HybridApp; [ONYXKEYS.NVP_TRY_NEW_DOT]?: TryNewDot; - [ONYXKEYS.ACCOUNT]?: {shouldUseStagingServer: boolean}; + [ONYXKEYS.SHOULD_USE_STAGING_SERVER]?: boolean; }; export default HybridAppSettings; diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index c82c1960656e2..e874f1327f9f9 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -28,7 +28,8 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { keysToPreserve.push(ONYXKEYS.PREFERRED_THEME); keysToPreserve.push(ONYXKEYS.ACTIVE_CLIENTS); keysToPreserve.push(ONYXKEYS.DEVICE_ID); - keysToPreserve.push(ONYXKEYS.ACCOUNT); + keysToPreserve.push(ONYXKEYS.SHOULD_USE_STAGING_SERVER); + keysToPreserve.push(ONYXKEYS.IS_DEBUG_MODE_ENABLED); // After signing out, set ourselves as offline if we were offline before logging out and we are not forcing it. // If we are forcing offline, ignore it while signed out, otherwise it would require a refresh because there's no way to toggle the switch to go back online while signed out. diff --git a/src/libs/actions/User.ts b/src/libs/actions/User.ts index f0ff3bba111d4..2e0c8797a13a3 100644 --- a/src/libs/actions/User.ts +++ b/src/libs/actions/User.ts @@ -1022,7 +1022,7 @@ function setShouldUseStagingServer(shouldUseStagingServer: boolean) { if (CONFIG.IS_HYBRID_APP) { HybridAppModule.shouldUseStaging(shouldUseStagingServer); } - Onyx.merge(ONYXKEYS.ACCOUNT, {shouldUseStagingServer}); + Onyx.set(ONYXKEYS.SHOULD_USE_STAGING_SERVER, shouldUseStagingServer); } function togglePlatformMute(platform: Platform, mutedPlatforms: Partial>) { @@ -1405,7 +1405,7 @@ function requestRefund() { } function setIsDebugModeEnabled(isDebugModeEnabled: boolean) { - Onyx.merge(ONYXKEYS.ACCOUNT, {isDebugModeEnabled}); + Onyx.set(ONYXKEYS.IS_DEBUG_MODE_ENABLED, isDebugModeEnabled); } function setShouldBlockTransactionThreadReportCreation(shouldBlockTransactionThreadReportCreation: boolean) { diff --git a/src/pages/ProfilePage.tsx b/src/pages/ProfilePage.tsx index ce1caebff9a54..b23b0e784e0fd 100755 --- a/src/pages/ProfilePage.tsx +++ b/src/pages/ProfilePage.tsx @@ -70,7 +70,7 @@ function ProfilePage({route}: ProfilePageProps) { const [personalDetailsMetadata] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_METADATA, {canBeMissing: true}); const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false}); const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true}); - const isDebugModeEnabled = !!account?.isDebugModeEnabled; + const [isDebugModeEnabled = false] = useOnyx(ONYXKEYS.IS_DEBUG_MODE_ENABLED, {canBeMissing: true}); const guideCalendarLink = account?.guideDetails?.calendarLink ?? ''; const accountID = Number(route.params?.accountID ?? CONST.DEFAULT_NUMBER_ID); diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index 4a5fb05ff6fb0..375dc2a0dd4ea 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -165,7 +165,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, {canBeMissing: true}); - const [isDebugModeEnabled] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => !!account?.isDebugModeEnabled, canBeMissing: false}); + const [isDebugModeEnabled = false] = useOnyx(ONYXKEYS.IS_DEBUG_MODE_ENABLED, {canBeMissing: true}); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: false}); const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false}); const [isLastMemberLeavingGroupModalVisible, setIsLastMemberLeavingGroupModalVisible] = useState(false); diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index 140fa0e36304b..dc91049d57d50 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -147,7 +147,7 @@ function BaseReportActionContextMenu({ }); const transactionID = getLinkedTransactionID(reportActionID, reportID); const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transactionID)}`, {canBeMissing: true}); - const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false}); + const [isDebugModeEnabled] = useOnyx(ONYXKEYS.IS_DEBUG_MODE_ENABLED, {canBeMissing: true}); const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true}); const [originalReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${originalReportID}`, {canBeMissing: true}); const isOriginalReportArchived = useReportIsArchived(originalReportID); @@ -232,7 +232,7 @@ function BaseReportActionContextMenu({ isProduction, moneyRequestAction, areHoldRequirementsMet, - account, + isDebugModeEnabled, iouTransaction, }), ); diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index dddf6422fcf97..98a3c0a5258fc 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -132,7 +132,7 @@ import { import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ROUTES from '@src/ROUTES'; -import type {Account, Beta, Card, Download as DownloadOnyx, OnyxInputOrEntry, ReportAction, ReportActionReactions, Report as ReportType, Transaction} from '@src/types/onyx'; +import type {Beta, Card, Download as DownloadOnyx, OnyxInputOrEntry, ReportAction, ReportActionReactions, Report as ReportType, Transaction} from '@src/types/onyx'; import type IconAsset from '@src/types/utils/IconAsset'; import KeyboardUtils from '@src/utils/keyboard'; import type {ContextMenuAnchor} from './ReportActionContextMenu'; @@ -175,7 +175,7 @@ type ShouldShow = (args: { isProduction: boolean; moneyRequestAction: ReportAction | undefined; areHoldRequirementsMet: boolean; - account: OnyxEntry; + isDebugModeEnabled: OnyxEntry; iouTransaction: OnyxEntry; }) => boolean; @@ -826,7 +826,7 @@ const ContextMenuActions: ContextMenuAction[] = [ isAnonymousAction: true, textTranslateKey: 'debug.debug', icon: Expensicons.Bug, - shouldShow: ({type, account}) => [CONST.CONTEXT_MENU_TYPES.REPORT_ACTION, CONST.CONTEXT_MENU_TYPES.REPORT].some((value) => value === type) && !!account?.isDebugModeEnabled, + shouldShow: ({type, isDebugModeEnabled}) => [CONST.CONTEXT_MENU_TYPES.REPORT_ACTION, CONST.CONTEXT_MENU_TYPES.REPORT].some((value) => value === type) && !!isDebugModeEnabled, onPress: (closePopover, {reportID, reportAction}) => { if (reportAction) { Navigation.navigate(ROUTES.DEBUG_REPORT_ACTION.getRoute(reportID, reportAction.reportActionID)); diff --git a/src/types/onyx/Account.ts b/src/types/onyx/Account.ts index 32348f7106210..0ba960d3b0ec9 100644 --- a/src/types/onyx/Account.ts +++ b/src/types/onyx/Account.ts @@ -202,9 +202,6 @@ type Account = { /** Whether or not the user is subscribed to news updates */ isSubscribedToNewsletter?: boolean; - /** Whether we should use the staging version of the secure API server */ - shouldUseStagingServer?: boolean; - /** Whether we should block the transaction thread report creation */ shouldBlockTransactionThreadReportCreation?: boolean; @@ -226,9 +223,6 @@ type Account = { /** Whether the user is an Expensify Guide */ isGuide?: boolean; - /** Whether the debug mode is currently enabled */ - isDebugModeEnabled?: boolean; - /** If user has accessible policies on a private domain */ hasAccessibleDomainPolicies?: boolean; diff --git a/tests/ui/BottomTabBarTest.tsx b/tests/ui/BottomTabBarTest.tsx index 56f2ed0589057..d09ec07fd0adc 100644 --- a/tests/ui/BottomTabBarTest.tsx +++ b/tests/ui/BottomTabBarTest.tsx @@ -26,7 +26,7 @@ describe('NavigationTabBar', () => { describe('Home tab', () => { describe('Debug mode enabled', () => { beforeEach(() => { - Onyx.set(ONYXKEYS.ACCOUNT, {isDebugModeEnabled: true}); + Onyx.set(ONYXKEYS.IS_DEBUG_MODE_ENABLED, true); }); describe('Has GBR', () => { it('renders DebugTabView', async () => { @@ -81,7 +81,7 @@ describe('NavigationTabBar', () => { describe('Settings tab', () => { describe('Debug mode enabled', () => { beforeEach(() => { - Onyx.set(ONYXKEYS.ACCOUNT, {isDebugModeEnabled: true}); + Onyx.set(ONYXKEYS.IS_DEBUG_MODE_ENABLED, true); }); describe('Has GBR', () => { it('renders DebugTabView', async () => {