Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Troubleshoot menu to PublicScreens #56926

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Expensify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import GrowlNotification from './components/GrowlNotification';
import RequireTwoFactorAuthenticationModal from './components/RequireTwoFactorAuthenticationModal';
import AppleAuthWrapper from './components/SignInButtons/AppleAuthWrapper';
import SplashScreenHider from './components/SplashScreenHider';
import TestToolsModal from './components/TestToolsModal';
import UpdateAppModal from './components/UpdateAppModal';
import * as CONFIG from './CONFIG';
import CONST from './CONST';
import useDebugShortcut from './hooks/useDebugShortcut';
import useIsAuthenticated from './hooks/useIsAuthenticated';
import useLocalize from './hooks/useLocalize';
import {updateLastRoute} from './libs/actions/App';
import * as EmojiPickerAction from './libs/actions/EmojiPickerAction';
Expand Down Expand Up @@ -96,6 +99,8 @@ function Expensify() {
const [focusModeNotification] = useOnyx(ONYXKEYS.FOCUS_MODE_NOTIFICATION, {initWithStoredValues: false});
const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH);

useDebugShortcut();

useEffect(() => {
if (!account?.needsTwoFactorAuthSetup || account.requiresTwoFactorAuth) {
return;
Expand All @@ -112,7 +117,7 @@ function Expensify() {
setAttemptedToOpenPublicRoom(true);
}, [isCheckingPublicRoom]);

const isAuthenticated = useMemo(() => !!(session?.authToken ?? null), [session]);
const isAuthenticated = useIsAuthenticated();
const autoAuthState = useMemo(() => session?.autoAuthState ?? '', [session]);

const shouldInit = isNavigationReady && hasAttemptedToOpenPublicRoom;
Expand Down Expand Up @@ -295,6 +300,7 @@ function Expensify() {
/>
)}
{shouldHideSplash && <SplashScreenHider onHide={onSplashHide} />}
<TestToolsModal />
</DeeplinkWrapper>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ const ROUTES = {
SETTINGS_STATUS_CLEAR_AFTER_DATE: 'settings/profile/status/clear-after/date',
SETTINGS_STATUS_CLEAR_AFTER_TIME: 'settings/profile/status/clear-after/time',
SETTINGS_TROUBLESHOOT: 'settings/troubleshoot',
SETTINGS_CONSOLE: {
CONSOLE_DEBUG: {
route: 'settings/troubleshoot/console',
getRoute: (backTo?: string) => getUrlWithBackToParam(`settings/troubleshoot/console`, backTo),
},
Expand Down
2 changes: 1 addition & 1 deletion src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const SCREENS = {
ADVANCED_FILTERS_IN_RHP: 'Search_Advanced_Filters_In_RHP',
TRANSACTION_HOLD_REASON_RHP: 'Search_Transaction_Hold_Reason_RHP',
},
CONSOLE_DEBUG: 'Console_Debug',
SETTINGS: {
ROOT: 'Settings_Root',
SHARE_CODE: 'Settings_Share_Code',
Expand All @@ -77,7 +78,6 @@ const SCREENS = {
CLOSE: 'Settings_Close',
REPORT_CARD_LOST_OR_DAMAGED: 'Settings_ReportCardLostOrDamaged',
TROUBLESHOOT: 'Settings_Troubleshoot',
CONSOLE: 'Settings_Console',
SHARE_LOG: 'Share_Log',

PROFILE: {
Expand Down
97 changes: 52 additions & 45 deletions src/components/TestToolMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import {useOnyx} from 'react-native-onyx';
import useIsAuthenticated from '@hooks/useIsAuthenticated';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ApiUtils from '@libs/ApiUtils';
import * as Network from '@userActions/Network';
import * as Session from '@userActions/Session';
import * as User from '@userActions/User';
import {isUsingStagingApi} from '@libs/ApiUtils';
import {setShouldFailAllRequests, setShouldForceOffline, setShouldSimulatePoorConnection} from '@userActions/Network';
import {expireSessionWithDelay, invalidateAuthToken, invalidateCredentials} from '@userActions/Session';
import {setIsDebugModeEnabled, setShouldUseStagingServer} from '@userActions/User';
import CONFIG from '@src/CONFIG';
import ONYXKEYS from '@src/ONYXKEYS';
import type {User as UserOnyx} from '@src/types/onyx';
Expand All @@ -28,11 +29,14 @@ function TestToolMenu() {
const [network] = useOnyx(ONYXKEYS.NETWORK);
const [user = USER_DEFAULT] = useOnyx(ONYXKEYS.USER);
const [isUsingImportedState] = useOnyx(ONYXKEYS.IS_USING_IMPORTED_STATE);
const shouldUseStagingServer = user?.shouldUseStagingServer ?? ApiUtils.isUsingStagingApi();
const shouldUseStagingServer = user?.shouldUseStagingServer ?? isUsingStagingApi();
const isDebugModeEnabled = !!user?.isDebugModeEnabled;
const styles = useThemeStyles();
const {translate} = useLocalize();

// Check if the user is authenticated to show options that require authentication
const isAuthenticated = useIsAuthenticated();

return (
<>
<Text
Expand All @@ -41,14 +45,45 @@ function TestToolMenu() {
>
{translate('initialSettingsPage.troubleshoot.testingPreferences')}
</Text>
{/* When toggled the app will be put into debug mode. */}
<TestToolRow title={translate('initialSettingsPage.troubleshoot.debugMode')}>
<Switch
accessibilityLabel={translate('initialSettingsPage.troubleshoot.debugMode')}
isOn={isDebugModeEnabled}
onToggle={() => User.setIsDebugModeEnabled(!isDebugModeEnabled)}
/>
</TestToolRow>
{isAuthenticated && (
<>
{/* When toggled the app will be put into debug mode. */}
<TestToolRow title={translate('initialSettingsPage.troubleshoot.debugMode')}>
<Switch
accessibilityLabel={translate('initialSettingsPage.troubleshoot.debugMode')}
isOn={isDebugModeEnabled}
onToggle={() => setIsDebugModeEnabled(!isDebugModeEnabled)}
/>
</TestToolRow>

{/* Instantly invalidates a user's local authToken. Useful for testing flows related to reauthentication. */}
<TestToolRow title={translate('initialSettingsPage.troubleshoot.authenticationStatus')}>
<Button
small
text={translate('initialSettingsPage.troubleshoot.invalidate')}
onPress={() => invalidateAuthToken()}
/>
</TestToolRow>

{/* Invalidate stored user auto-generated credentials. Useful for manually testing sign out logic. */}
<TestToolRow title={translate('initialSettingsPage.troubleshoot.deviceCredentials')}>
<Button
small
text={translate('initialSettingsPage.troubleshoot.destroy')}
onPress={() => invalidateCredentials()}
/>
</TestToolRow>

{/* Sends an expired session to the FE and invalidates the session by the same time in the BE. Action is delayed for 15s */}
<TestToolRow title={translate('initialSettingsPage.troubleshoot.authenticationStatus')}>
<Button
small
text={translate('initialSettingsPage.troubleshoot.invalidateWithDelay')}
onPress={() => expireSessionWithDelay()}
/>
</TestToolRow>
</>
)}

{/* Option to switch between staging and default api endpoints.
This enables QA, internal testers and external devs to take advantage of sandbox environments for 3rd party services like Plaid and Onfido.
Expand All @@ -58,7 +93,7 @@ function TestToolMenu() {
<Switch
accessibilityLabel="Use Staging Server"
isOn={shouldUseStagingServer}
onToggle={() => User.setShouldUseStagingServer(!shouldUseStagingServer)}
onToggle={() => setShouldUseStagingServer(!shouldUseStagingServer)}
/>
</TestToolRow>
)}
Expand All @@ -68,7 +103,7 @@ function TestToolMenu() {
<Switch
accessibilityLabel="Force offline"
isOn={!!network?.shouldForceOffline}
onToggle={() => Network.setShouldForceOffline(!network?.shouldForceOffline)}
onToggle={() => setShouldForceOffline(!network?.shouldForceOffline)}
disabled={!!isUsingImportedState || !!network?.shouldSimulatePoorConnection || network?.shouldFailAllRequests}
/>
</TestToolRow>
Expand All @@ -78,7 +113,7 @@ function TestToolMenu() {
<Switch
accessibilityLabel="Simulate poor internet connection"
isOn={!!network?.shouldSimulatePoorConnection}
onToggle={() => Network.setShouldSimulatePoorConnection(!network?.shouldSimulatePoorConnection, network?.poorConnectionTimeoutID)}
onToggle={() => setShouldSimulatePoorConnection(!network?.shouldSimulatePoorConnection, network?.poorConnectionTimeoutID)}
disabled={!!isUsingImportedState || !!network?.shouldFailAllRequests || network?.shouldForceOffline}
/>
</TestToolRow>
Expand All @@ -88,38 +123,10 @@ function TestToolMenu() {
<Switch
accessibilityLabel="Simulate failing network requests"
isOn={!!network?.shouldFailAllRequests}
onToggle={() => Network.setShouldFailAllRequests(!network?.shouldFailAllRequests)}
onToggle={() => setShouldFailAllRequests(!network?.shouldFailAllRequests)}
disabled={!!network?.shouldForceOffline || network?.shouldSimulatePoorConnection}
/>
</TestToolRow>

{/* Instantly invalidates a user's local authToken. Useful for testing flows related to reauthentication. */}
<TestToolRow title={translate('initialSettingsPage.troubleshoot.authenticationStatus')}>
<Button
small
text={translate('initialSettingsPage.troubleshoot.invalidate')}
onPress={() => Session.invalidateAuthToken()}
/>
</TestToolRow>

{/* Invalidate stored user auto-generated credentials. Useful for manually testing sign out logic. */}
<TestToolRow title={translate('initialSettingsPage.troubleshoot.deviceCredentials')}>
<Button
small
text={translate('initialSettingsPage.troubleshoot.destroy')}
onPress={() => Session.invalidateCredentials()}
/>
</TestToolRow>

{/* Sends an expired session to the FE and invalidates the session by the same time in the BE. Action is delayed for 15s */}
<TestToolRow title={translate('initialSettingsPage.troubleshoot.authenticationStatus')}>
<Button
small
text={translate('initialSettingsPage.troubleshoot.invalidateWithDelay')}
onPress={() => Session.expireSessionWithDelay()}
/>
</TestToolRow>

<TestCrash />
</>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/TestToolsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function TestToolsModal() {
text={translate('initialSettingsPage.debugConsole.viewConsole')}
onPress={() => {
toggleTestToolsModal();
Navigation.navigate(ROUTES.SETTINGS_CONSOLE.getRoute(Navigation.getActiveRoute()));
Navigation.navigate(ROUTES.CONSOLE_DEBUG.getRoute(Navigation.getActiveRoute()));
}}
/>
</TestToolRow>
Expand Down
26 changes: 26 additions & 0 deletions src/hooks/useDebugShortcut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {useEffect} from 'react';
import KeyboardShortcut from '@libs/KeyboardShortcut';
import toggleTestToolsModal from '@userActions/TestTool';
import CONST from '@src/CONST';

function useDebugShortcut() {
useEffect(() => {
const debugShortcutConfig = CONST.KEYBOARD_SHORTCUTS.DEBUG;
const unsubscribeDebugShortcut = KeyboardShortcut.subscribe(
debugShortcutConfig.shortcutKey,
() => toggleTestToolsModal(),
debugShortcutConfig.descriptionKey,
debugShortcutConfig.modifiers,
true,
);

return () => {
unsubscribeDebugShortcut();
};

// Rule disabled because this effect is only for component did mount & will component unmount lifecycle event
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, []);
}

export default useDebugShortcut;
11 changes: 11 additions & 0 deletions src/hooks/useIsAuthenticated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {useMemo} from 'react';
import {useOnyx} from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';

function useIsAuthenticated() {
const [session] = useOnyx(ONYXKEYS.SESSION);
const isAuthenticated = useMemo(() => !!(session?.authToken ?? null), [session]);
return isAuthenticated;
}

export default useIsAuthenticated;
13 changes: 0 additions & 13 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import OptionsListContextProvider from '@components/OptionListContextProvider';
import {SearchContextProvider} from '@components/Search/SearchContext';
import {useSearchRouterContext} from '@components/Search/SearchRouter/SearchRouterContext';
import SearchRouterModal from '@components/Search/SearchRouter/SearchRouterModal';
import TestToolsModal from '@components/TestToolsModal';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useOnboardingFlowRouter from '@hooks/useOnboardingFlow';
import {ReportIDsContextProvider} from '@hooks/useReportIDs';
Expand Down Expand Up @@ -45,7 +44,6 @@ import * as PersonalDetails from '@userActions/PersonalDetails';
import * as PriorityMode from '@userActions/PriorityMode';
import * as Report from '@userActions/Report';
import * as Session from '@userActions/Session';
import toggleTestToolsModal from '@userActions/TestTool';
import * as User from '@userActions/User';
import CONFIG from '@src/CONFIG';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -248,7 +246,6 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
const shortcutsOverviewShortcutConfig = CONST.KEYBOARD_SHORTCUTS.SHORTCUTS;
const searchShortcutConfig = CONST.KEYBOARD_SHORTCUTS.SEARCH;
const chatShortcutConfig = CONST.KEYBOARD_SHORTCUTS.NEW_CHAT;
const debugShortcutConfig = CONST.KEYBOARD_SHORTCUTS.DEBUG;
const currentUrl = getCurrentUrl();
const isLoggingInAsNewUser = !!session?.email && SessionUtils.isLoggingInAsNewUser(currentUrl, session.email);
// Sign out the current user if we're transitioning with a different user
Expand Down Expand Up @@ -364,21 +361,12 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
true,
);

const unsubscribeDebugShortcut = KeyboardShortcut.subscribe(
debugShortcutConfig.shortcutKey,
() => toggleTestToolsModal(),
debugShortcutConfig.descriptionKey,
debugShortcutConfig.modifiers,
true,
);

return () => {
unsubscribeEscapeKey();
unsubscribeOnyxModal();
unsubscribeShortcutsOverviewShortcut();
unsubscribeSearchShortcut();
unsubscribeChatShortcut();
unsubscribeDebugShortcut();
Session.cleanupSession();
};

Expand Down Expand Up @@ -627,7 +615,6 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
component={ConnectionCompletePage}
/>
</RootStack.Navigator>
<TestToolsModal />
<SearchRouterModal />
<ActiveGuidesEventListener />
</ComposeProviders>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';
import createPlatformStackNavigator from '@libs/Navigation/PlatformStackNavigation/createPlatformStackNavigator';
import type {
AddPersonalBankAccountNavigatorParamList,
ConsoleNavigatorParamList,
DebugParamList,
EditRequestNavigatorParamList,
EnablePaymentsNavigatorParamList,
Expand Down Expand Up @@ -226,6 +227,10 @@ const NewTeachersUniteNavigator = createModalStackNavigator<TeachersUniteNavigat
[SCREENS.I_AM_A_TEACHER]: () => require<ReactComponentModule>('../../../../pages/TeachersUnite/ImTeacherPage').default,
});

const ConsoleModalStackNavigator = createModalStackNavigator<ConsoleNavigatorParamList>({
[SCREENS.CONSOLE_DEBUG]: () => require<ReactComponentModule>('../../../../pages/settings/AboutPage/ConsolePage').default,
});

const SettingsModalStackNavigator = createModalStackNavigator<SettingsNavigatorParamList>({
[SCREENS.SETTINGS.SHARE_CODE]: () => require<ReactComponentModule>('../../../../pages/ShareCodePage').default,
[SCREENS.SETTINGS.PROFILE.PRONOUNS]: () => require<ReactComponentModule>('../../../../pages/settings/Profile/PronounsPage').default,
Expand All @@ -247,7 +252,7 @@ const SettingsModalStackNavigator = createModalStackNavigator<SettingsNavigatorP
[SCREENS.SETTINGS.PREFERENCES.THEME]: () => require<ReactComponentModule>('../../../../pages/settings/Preferences/ThemePage').default,
[SCREENS.SETTINGS.CLOSE]: () => require<ReactComponentModule>('../../../../pages/settings/Security/CloseAccountPage').default,
[SCREENS.SETTINGS.APP_DOWNLOAD_LINKS]: () => require<ReactComponentModule>('../../../../pages/settings/AppDownloadLinks').default,
[SCREENS.SETTINGS.CONSOLE]: () => require<ReactComponentModule>('../../../../pages/settings/AboutPage/ConsolePage').default,
[SCREENS.CONSOLE_DEBUG]: () => require<ReactComponentModule>('../../../../pages/settings/AboutPage/ConsolePage').default,
[SCREENS.SETTINGS.SHARE_LOG]: () => require<ReactComponentModule>('../../../../pages/settings/AboutPage/ShareLogPage').default,
[SCREENS.SETTINGS.WALLET.CARDS_DIGITAL_DETAILS_UPDATE_ADDRESS]: () => require<ReactComponentModule>('../../../../pages/settings/Profile/PersonalDetails/PersonalAddressPage').default,
[SCREENS.SETTINGS.WALLET.DOMAIN_CARD]: () => require<ReactComponentModule>('../../../../pages/settings/Wallet/ExpensifyCardPage').default,
Expand Down Expand Up @@ -761,4 +766,5 @@ export {
MissingPersonalDetailsModalStackNavigator,
DebugModalStackNavigator,
WorkspaceConfirmationModalStackNavigator,
ConsoleModalStackNavigator,
};
Loading