From 5eaa292a55b8e2213dddce2f129a76cb8bab98ab Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Tue, 22 Oct 2024 15:57:34 +0200 Subject: [PATCH 01/95] Implement POC of NewDot login page on HybridApp --- src/Expensify.tsx | 5 +- src/ONYXKEYS.ts | 4 ++ src/components/InitialURLContextProvider.tsx | 7 ++- .../Navigation/AppNavigator/PublicScreens.tsx | 4 +- .../Navigation/AppNavigator/index.native.tsx | 19 ++++-- src/libs/actions/Session/index.ts | 62 +++++++++++++------ .../ValidateCodeForm/BaseValidateCodeForm.tsx | 34 ++++++++-- src/types/modules/react-native.d.ts | 2 + 8 files changed, 102 insertions(+), 35 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index e07b03a6d405..aa374ff935ae 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -96,6 +96,7 @@ function Expensify() { const [screenShareRequest] = useOnyx(ONYXKEYS.SCREEN_SHARE_REQUEST); const [focusModeNotification] = useOnyx(ONYXKEYS.FOCUS_MODE_NOTIFICATION, {initWithStoredValues: false}); const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH); + const [useNewDotSignInPage] = useOnyx(ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE); useEffect(() => { if (!account?.needsTwoFactorAuthSetup || account.requiresTwoFactorAuth) { @@ -119,7 +120,9 @@ function Expensify() { const shouldInit = isNavigationReady && hasAttemptedToOpenPublicRoom; const shouldHideSplash = shouldInit && - (NativeModules.HybridAppModule ? splashScreenState === CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN && isAuthenticated : splashScreenState === CONST.BOOT_SPLASH_STATE.VISIBLE); + (NativeModules.HybridAppModule + ? splashScreenState === CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN && (isAuthenticated || useNewDotSignInPage) + : splashScreenState === CONST.BOOT_SPLASH_STATE.VISIBLE); const initializeClient = () => { if (!Visibility.isVisible()) { diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index d083a46d7760..4e04139e4c18 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -444,6 +444,9 @@ const ONYXKEYS = { /** Company cards custom names */ NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES: 'nvp_expensify_ccCustomNames', + /** Stores the information if HybridApp uses NewDot's sign in flow */ + USE_NEWDOT_SIGN_IN_PAGE: 'useNewDotSignInPage', + /** Collection Keys */ COLLECTION: { DOWNLOAD: 'download_', @@ -1007,6 +1010,7 @@ type OnyxValuesMapping = { [ONYXKEYS.IS_USING_IMPORTED_STATE]: boolean; [ONYXKEYS.SHOULD_SHOW_SAVED_SEARCH_RENAME_TOOLTIP]: boolean; [ONYXKEYS.NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES]: Record; + [ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE]: boolean; }; type OnyxValues = OnyxValuesMapping & OnyxCollectionValuesMapping & OnyxFormValuesMapping & OnyxFormDraftValuesMapping; diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index 85ad54ca6c94..f026f2de53f9 100644 --- a/src/components/InitialURLContextProvider.tsx +++ b/src/components/InitialURLContextProvider.tsx @@ -31,9 +31,10 @@ function InitialURLContextProvider({children, url}: InitialURLContextProviderPro useEffect(() => { if (url) { - const route = signInAfterTransitionFromOldDot(url); - setInitialURL(route); - setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); + signInAfterTransitionFromOldDot(url).then((route) => { + setInitialURL(route); + setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); + }); return; } Linking.getInitialURL().then((initURL) => { diff --git a/src/libs/Navigation/AppNavigator/PublicScreens.tsx b/src/libs/Navigation/AppNavigator/PublicScreens.tsx index cfd41a4b1fa0..faf6563a0ef3 100644 --- a/src/libs/Navigation/AppNavigator/PublicScreens.tsx +++ b/src/libs/Navigation/AppNavigator/PublicScreens.tsx @@ -1,9 +1,7 @@ import {createStackNavigator} from '@react-navigation/stack'; import React from 'react'; -import {NativeModules} from 'react-native'; import type {PublicScreensParamList} from '@navigation/types'; import ConnectionCompletePage from '@pages/ConnectionCompletePage'; -import SessionExpiredPage from '@pages/ErrorPage/SessionExpiredPage'; import LogInWithShortLivedAuthTokenPage from '@pages/LogInWithShortLivedAuthTokenPage'; import AppleSignInDesktopPage from '@pages/signin/AppleSignInDesktopPage'; import GoogleSignInDesktopPage from '@pages/signin/GoogleSignInDesktopPage'; @@ -24,7 +22,7 @@ function PublicScreens() { { + if (!NativeModules.HybridAppModule) { + return authenticated; + } + + return useNewDotLoginPage === false && authenticated; + }, [authenticated, useNewDotLoginPage]); useEffect(() => { - if (!NativeModules.HybridAppModule || !initialURL) { + if (!NativeModules.HybridAppModule || !initialURL || !shouldShowAuthScreens) { return; } @@ -21,9 +32,9 @@ function AppNavigator({authenticated}: AppNavigatorProps) { Navigation.navigate(Navigation.parseHybridAppUrl(initialURL)); setInitialURL(undefined); }); - }, [initialURL, setInitialURL]); + }, [initialURL, setInitialURL, shouldShowAuthScreens]); - if (authenticated) { + if (shouldShowAuthScreens) { const AuthScreens = require('./AuthScreens').default; // These are the protected screens and only accessible when an authToken is present diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 37488442525d..1972908fcb1e 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -209,7 +209,7 @@ function signOutAndRedirectToSignIn(shouldResetToHome?: boolean, shouldStashSess if (!isAnonymousUser()) { // In the HybridApp, we want the Old Dot to handle the sign out process if (NativeModules.HybridAppModule && killHybridApp) { - NativeModules.HybridAppModule.closeReactNativeApp(true, false); + NativeModules.HybridAppModule.signOutFromOldDot(); return; } // We'll only call signOut if we're not stashing the session and this is not a supportal session, @@ -482,29 +482,51 @@ function signUpUser() { function signInAfterTransitionFromOldDot(transitionURL: string) { const [route, queryParams] = transitionURL.split('?'); + const queryParamsObject = queryParams + ? Object.fromEntries( + queryParams.split('&').map((param) => { + const [key, value] = param.split('='); + return [key, value]; + }), + ) + : {}; + + const {useNewDotSignInPage, isSingleNewDotEntry} = queryParamsObject; + + const clearOnyxBeforeSignIn = () => { + if (useNewDotSignInPage !== 'true') { + return Promise.resolve(); + } - const {email, authToken, encryptedAuthToken, accountID, autoGeneratedLogin, autoGeneratedPassword, clearOnyxOnStart, completedHybridAppOnboarding} = Object.fromEntries( - queryParams.split('&').map((param) => { - const [key, value] = param.split('='); - return [key, value]; - }), - ); - - const setSessionDataAndOpenApp = () => { - Onyx.multiSet({ - [ONYXKEYS.SESSION]: {email, authToken, encryptedAuthToken: decodeURIComponent(encryptedAuthToken), accountID: Number(accountID)}, - [ONYXKEYS.CREDENTIALS]: {autoGeneratedLogin, autoGeneratedPassword}, - [ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {completedHybridAppOnboarding: completedHybridAppOnboarding === 'true'}}, - }).then(App.openApp); + return Onyx.clear(); }; - if (clearOnyxOnStart === 'true') { - Onyx.clear(KEYS_TO_PRESERVE).then(setSessionDataAndOpenApp); - } else { - setSessionDataAndOpenApp(); - } + const initAppAfterTransition = () => { + if (useNewDotSignInPage === 'true') { + return Promise.resolve(); + } + + return App.openApp(); + }; + + const setSessionDataAndOpenApp = new Promise((resolve) => { + clearOnyxBeforeSignIn() + .then(() => + Onyx.multiSet({ + [ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE]: useNewDotSignInPage === 'true', + [ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {dismissed: 'true'}}, // This data is mocked and should be returned by BeginSignUp/SignInUser API commands + }), + ) + .then(initAppAfterTransition) + .catch((error) => { + Log.hmmm('[HybridApp] Initialization of HybridApp has failed. Forcing transition', {error}); + }) + .finally(() => { + resolve(`${route}?singleNewDotEntry=${isSingleNewDotEntry}` as Route); + }); + }); - return route as Route; + return setSessionDataAndOpenApp; } /** diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index f73c0a1602fb..8b196673d729 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -1,7 +1,7 @@ import {useIsFocused} from '@react-navigation/native'; -import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react'; +import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react'; import type {ForwardedRef} from 'react'; -import {View} from 'react-native'; +import {NativeModules, View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import Button from '@components/Button'; import SafariFormWrapper from '@components/Form/SafariFormWrapper'; @@ -30,6 +30,7 @@ import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; import type ValidateCodeFormProps from './types'; type BaseValidateCodeFormProps = WithToggleVisibilityViewProps & @@ -61,6 +62,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const [timeRemaining, setTimeRemaining] = useState(CONST.REQUEST_CODE_DELAY as number); const [recoveryCode, setRecoveryCode] = useState(''); const [needToClearError, setNeedToClearError] = useState(!!account?.errors); + const [tryNewDot, tryNewDotMetadata] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); const prevRequiresTwoFactorAuth = usePrevious(account?.requiresTwoFactorAuth); const prevValidateCode = usePrevious(credentials?.validateCode); @@ -74,6 +76,30 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const shouldDisableResendValidateCode = isOffline ?? account?.isLoading; const isValidateCodeFormSubmitting = AccountUtils.isValidateCodeFormSubmitting(account); + const isLoading = useMemo(() => { + if (!NativeModules.HybridAppModule || !session?.authToken) { + return isValidateCodeFormSubmitting; + } + + if (isLoadingOnyxValue(tryNewDotMetadata)) { + return true; + } + + return (tryNewDot?.classicRedirect.dismissed === true || tryNewDot?.classicRedirect.dismissed === 'true') && !!session.authToken; + }, [isValidateCodeFormSubmitting, session?.authToken, tryNewDot, tryNewDotMetadata]); + + useEffect(() => { + if (!NativeModules.HybridAppModule || isValidateCodeFormSubmitting || !session?.authToken) { + return; + } + + if (tryNewDot?.classicRedirect.dismissed === true || tryNewDot?.classicRedirect.dismissed === 'true') { + if (credentials?.autoGeneratedLogin && credentials?.autoGeneratedPassword) { + NativeModules.HybridAppModule.signInToOldDot(credentials?.autoGeneratedLogin, credentials?.autoGeneratedPassword); + } + } + }, [credentials?.autoGeneratedLogin, credentials?.autoGeneratedPassword, isValidateCodeFormSubmitting, session?.authToken, tryNewDot?.classicRedirect.dismissed]); + useEffect(() => { if (!(inputValidateCodeRef.current && hasError && (session?.autoAuthState === CONST.AUTO_AUTH_STATE.FAILED || account?.isLoading))) { return; @@ -335,7 +361,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco style={[styles.mt2]} onPress={switchBetween2faAndRecoveryCode} hoverDimmingValue={1} - disabled={isValidateCodeFormSubmitting} + disabled={isLoading} role={CONST.ROLE.BUTTON} accessibilityLabel={isUsingRecoveryCode ? translate('recoveryCodeForm.use2fa') : translate('recoveryCodeForm.useRecoveryCode')} > @@ -394,7 +420,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco large style={[styles.mv3]} text={translate('common.signIn')} - isLoading={isValidateCodeFormSubmitting} + isLoading={isLoading} onPress={validateAndSubmitForm} /> diff --git a/src/types/modules/react-native.d.ts b/src/types/modules/react-native.d.ts index 40c5b72ce1e4..6389ed0f50be 100644 --- a/src/types/modules/react-native.d.ts +++ b/src/types/modules/react-native.d.ts @@ -8,6 +8,8 @@ import type StartupTimer from '@libs/StartupTimer/types'; type HybridAppModule = { closeReactNativeApp: (shouldSignOut: boolean, shouldSetNVP: boolean) => void; completeOnboarding: (status: boolean) => void; + signInToOldDot: (autoGeneratedLogin: string, autoGeneratedPassword: string) => void; + signOutFromOldDot: () => void; exitApp: () => void; }; From f81ec86898ab6cf54a45e3d3191223f845d962e2 Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 29 Oct 2024 12:59:42 +0100 Subject: [PATCH 02/95] fix android crash --- src/libs/actions/Session/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 1972908fcb1e..96bd7589d288 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -210,7 +210,6 @@ function signOutAndRedirectToSignIn(shouldResetToHome?: boolean, shouldStashSess // In the HybridApp, we want the Old Dot to handle the sign out process if (NativeModules.HybridAppModule && killHybridApp) { NativeModules.HybridAppModule.signOutFromOldDot(); - return; } // We'll only call signOut if we're not stashing the session and this is not a supportal session, // otherwise we'll call the API to invalidate the autogenerated credentials used for infinite From 290748d4e0318f98fac86053d57547e436ec164a Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 29 Oct 2024 16:25:53 +0100 Subject: [PATCH 03/95] add HybridApp onyx key --- src/ONYXKEYS.ts | 3 +++ src/types/onyx/HybridApp.ts | 7 +++++++ src/types/onyx/index.ts | 2 ++ 3 files changed, 12 insertions(+) create mode 100644 src/types/onyx/HybridApp.ts diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 6c73d8cdee37..02d6c15fb856 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -451,6 +451,8 @@ const ONYXKEYS = { /** Stores the information if HybridApp uses NewDot's sign in flow */ USE_NEWDOT_SIGN_IN_PAGE: 'useNewDotSignInPage', + HYBRID_APP: 'hybridApp', + /** Collection Keys */ COLLECTION: { DOWNLOAD: 'download_', @@ -1016,6 +1018,7 @@ type OnyxValuesMapping = { [ONYXKEYS.SHOULD_SHOW_SAVED_SEARCH_RENAME_TOOLTIP]: boolean; [ONYXKEYS.NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES]: Record; [ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE]: boolean; + [ONYXKEYS.HYBRID_APP]: OnyxTypes.HybridApp; }; type OnyxValues = OnyxValuesMapping & OnyxCollectionValuesMapping & OnyxFormValuesMapping & OnyxFormDraftValuesMapping; diff --git a/src/types/onyx/HybridApp.ts b/src/types/onyx/HybridApp.ts new file mode 100644 index 000000000000..e7d4c08f82db --- /dev/null +++ b/src/types/onyx/HybridApp.ts @@ -0,0 +1,7 @@ +/** */ +type HybridApp = { + /** */ + isSigningIn?: boolean; +}; + +export default HybridApp; diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index fe559aab3aa9..99d8f33897a1 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -24,6 +24,7 @@ import type ExpensifyCardSettings from './ExpensifyCardSettings'; import type FrequentlyUsedEmoji from './FrequentlyUsedEmoji'; import type {FundList} from './Fund'; import type Fund from './Fund'; +import type HybridApp from './HybridApp'; import type ImportedSpreadsheet from './ImportedSpreadsheet'; import type IntroSelected from './IntroSelected'; import type InvitedEmailsToAccountIDs from './InvitedEmailsToAccountIDs'; @@ -235,4 +236,5 @@ export type { RecentSearchItem, ImportedSpreadsheet, ValidateMagicCodeAction, + HybridApp, }; From 05c4573c1c008eb47c91147af8aff71eb209624f Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 31 Oct 2024 12:03:17 +0100 Subject: [PATCH 04/95] wip - sending native events --- src/App.tsx | 2 ++ src/CONST.ts | 15 +++++++++++++++ src/libs/HybridApp.ts | 19 +++++++++++++++++++ src/libs/actions/HybridApp.ts | 12 ++++++++++++ src/types/onyx/HybridApp.ts | 3 +++ 5 files changed, 51 insertions(+) create mode 100644 src/libs/HybridApp.ts create mode 100644 src/libs/actions/HybridApp.ts diff --git a/src/App.tsx b/src/App.tsx index 177cc00c7dee..4e5f8bb858f8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -36,6 +36,7 @@ import Expensify from './Expensify'; import useDefaultDragAndDrop from './hooks/useDefaultDragAndDrop'; import {ReportIDsContextProvider} from './hooks/useReportIDs'; import OnyxUpdateManager from './libs/actions/OnyxUpdateManager'; +import {init} from './libs/HybridApp'; import {ReportAttachmentsProvider} from './pages/home/report/ReportAttachmentsContext'; import type {Route} from './ROUTES'; import {SplashScreenStateContextProvider} from './SplashScreenStateContext'; @@ -59,6 +60,7 @@ const StrictModeWrapper = CONFIG.USE_REACT_STRICT_MODE_IN_DEV ? React.StrictMode function App({url}: AppProps) { useDefaultDragAndDrop(); OnyxUpdateManager(); + init(); return ( diff --git a/src/CONST.ts b/src/CONST.ts index 9f7940e17c23..01c195682c75 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -4424,6 +4424,9 @@ const CONST = { }, EVENTS: { SCROLLING: 'scrolling', + HYBRID_APP: { + ON_SIGN_IN_FINISHED: 'onSignInFinished', + }, }, CHAT_HEADER_LOADER_HEIGHT: 36, @@ -5973,6 +5976,18 @@ const CONST = { HIDDEN: `hidden`, }, + OLD_DOT_SIGN_IN_STATE: { + NOT_STARTED: 'notStarted', + STARTED: 'started', + FINISHED: 'finished', + }, + + NEW_DOT_SIGN_IN_STATE: { + NOT_STARTED: 'notStarted', + STARTED: 'started', + FINISHED: 'finished', + }, + CSV_IMPORT_COLUMNS: { EMAIL: 'email', NAME: 'name', diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts new file mode 100644 index 000000000000..3d63adf2dc7b --- /dev/null +++ b/src/libs/HybridApp.ts @@ -0,0 +1,19 @@ +import {DeviceEventEmitter, NativeModules} from 'react-native'; +import CONST from '@src/CONST'; +import {setIsSigningIn} from './actions/HybridApp'; +import type {Init} from './ActiveClientManager/types'; +import Log from './Log'; + +const init: Init = () => { + if (!NativeModules.HybridAppModule) { + return; + } + + // Setup event listeners + DeviceEventEmitter.addListener(CONST.EVENTS.HYBRID_APP.ON_SIGN_IN_FINISHED, () => { + Log.info('[HybridApp] `onSignInFinished` event received', true); + setIsSigningIn(false); + }); +}; + +export {init}; diff --git a/src/libs/actions/HybridApp.ts b/src/libs/actions/HybridApp.ts new file mode 100644 index 000000000000..940c562cd67e --- /dev/null +++ b/src/libs/actions/HybridApp.ts @@ -0,0 +1,12 @@ +import Onyx from 'react-native-onyx'; +import ONYXKEYS from '@src/ONYXKEYS'; + +function setIsSigningIn(isSigningIn: boolean) { + Onyx.merge(ONYXKEYS.HYBRID_APP, {isSigningIn}); +} + +function setReadyToShowAuthScreens(readyToShowAuthScreens: boolean) { + Onyx.merge(ONYXKEYS.HYBRID_APP, {readyToShowAuthScreens}); +} + +export {setIsSigningIn, setReadyToShowAuthScreens}; diff --git a/src/types/onyx/HybridApp.ts b/src/types/onyx/HybridApp.ts index e7d4c08f82db..0b5bf1868e35 100644 --- a/src/types/onyx/HybridApp.ts +++ b/src/types/onyx/HybridApp.ts @@ -2,6 +2,9 @@ type HybridApp = { /** */ isSigningIn?: boolean; + + /** */ + readyToShowAuthScreens?: boolean; }; export default HybridApp; From bb05ef91b9c84f0892ea470e62f90237a9e75130 Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 31 Oct 2024 12:57:57 +0100 Subject: [PATCH 05/95] js logic --- src/Expensify.tsx | 10 +-- .../Navigation/AppNavigator/index.native.tsx | 28 ++++++- src/libs/actions/Session/index.ts | 8 +- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 80 +++++++++++++++---- 4 files changed, 97 insertions(+), 29 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index aa374ff935ae..cd249b055d07 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -118,11 +118,11 @@ function Expensify() { const autoAuthState = useMemo(() => session?.autoAuthState ?? '', [session]); const shouldInit = isNavigationReady && hasAttemptedToOpenPublicRoom; - const shouldHideSplash = - shouldInit && - (NativeModules.HybridAppModule - ? splashScreenState === CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN && (isAuthenticated || useNewDotSignInPage) - : splashScreenState === CONST.BOOT_SPLASH_STATE.VISIBLE); + const shouldHideSplash = true; + // shouldInit && + // (NativeModules.HybridAppModule + // ? splashScreenState === CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN && (isAuthenticated || useNewDotSignInPage) + // : splashScreenState === CONST.BOOT_SPLASH_STATE.VISIBLE); const initializeClient = () => { if (!Visibility.isVisible()) { diff --git a/src/libs/Navigation/AppNavigator/index.native.tsx b/src/libs/Navigation/AppNavigator/index.native.tsx index 5c5bafebacbd..0038ea8a39da 100644 --- a/src/libs/Navigation/AppNavigator/index.native.tsx +++ b/src/libs/Navigation/AppNavigator/index.native.tsx @@ -4,6 +4,7 @@ import {useOnyx} from 'react-native-onyx'; import {InitialURLContext} from '@components/InitialURLContextProvider'; import Navigation from '@libs/Navigation/Navigation'; import ONYXKEYS from '@src/ONYXKEYS'; +import {TryNewDot} from '@src/types/onyx'; import type ReactComponentModule from '@src/types/utils/ReactComponentModule'; type AppNavigatorProps = { @@ -11,17 +12,38 @@ type AppNavigatorProps = { authenticated: boolean; }; +function shouldUseOldApp(tryNewDot?: TryNewDot) { + return tryNewDot?.classicRedirect.dismissed === true || tryNewDot?.classicRedirect.dismissed === 'true'; +} + function AppNavigator({authenticated}: AppNavigatorProps) { const {initialURL, setInitialURL} = useContext(InitialURLContext); - const [useNewDotLoginPage] = useOnyx(ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE); + const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); + const [useNewDotSignInPage] = useOnyx(ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE); + /** + * kiedy chcemy pokazać auth screens: + * - logujemy do OD + * - nie chcemy wcale + * - logujemy do ND + * - gdy jesteśmy authenticated (po odpaleniu signInToOldDot) + * - przechodzimy z OD do ND + * - od razu o ile jesteśmy zalogowani, ale powinniśmy być zawsze + */ const shouldShowAuthScreens = useMemo(() => { if (!NativeModules.HybridAppModule) { return authenticated; } + if (shouldUseOldApp(tryNewDot)) { + return false; + } + + console.log('dupa dupa dupa', authenticated, hybridApp?.readyToShowAuthScreens); + return authenticated && (!useNewDotSignInPage || hybridApp?.readyToShowAuthScreens); + }, [authenticated, hybridApp?.readyToShowAuthScreens, tryNewDot, useNewDotSignInPage]); - return useNewDotLoginPage === false && authenticated; - }, [authenticated, useNewDotLoginPage]); + console.log('dupa should show auth screens', shouldShowAuthScreens); useEffect(() => { if (!NativeModules.HybridAppModule || !initialURL || !shouldShowAuthScreens) { diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 96bd7589d288..847d24299c48 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -39,9 +39,10 @@ import * as SessionUtils from '@libs/SessionUtils'; import {clearSoundAssetsCache} from '@libs/Sound'; import Timers from '@libs/Timers'; import {hideContextMenu} from '@pages/home/report/ContextMenu/ReportActionContextMenu'; -import {KEYS_TO_PRESERVE, openApp} from '@userActions/App'; import * as App from '@userActions/App'; +import {KEYS_TO_PRESERVE, openApp} from '@userActions/App'; import * as Device from '@userActions/Device'; +import {setReadyToShowAuthScreens} from '@userActions/HybridApp'; import * as PriorityMode from '@userActions/PriorityMode'; import redirectToSignIn from '@userActions/SignInRedirect'; import Timing from '@userActions/Timing'; @@ -494,6 +495,7 @@ function signInAfterTransitionFromOldDot(transitionURL: string) { const clearOnyxBeforeSignIn = () => { if (useNewDotSignInPage !== 'true') { + setReadyToShowAuthScreens(true); return Promise.resolve(); } @@ -508,7 +510,7 @@ function signInAfterTransitionFromOldDot(transitionURL: string) { return App.openApp(); }; - const setSessionDataAndOpenApp = new Promise((resolve) => { + return new Promise((resolve) => { clearOnyxBeforeSignIn() .then(() => Onyx.multiSet({ @@ -524,8 +526,6 @@ function signInAfterTransitionFromOldDot(transitionURL: string) { resolve(`${route}?singleNewDotEntry=${isSingleNewDotEntry}` as Route); }); }); - - return setSessionDataAndOpenApp; } /** diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 8b196673d729..24aff5360146 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -1,8 +1,9 @@ import {useIsFocused} from '@react-navigation/native'; -import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react'; +import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react'; import type {ForwardedRef} from 'react'; import {NativeModules, View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; +import type {ValueOf} from 'type-fest'; import Button from '@components/Button'; import SafariFormWrapper from '@components/Form/SafariFormWrapper'; import FormHelpMessage from '@components/FormHelpMessage'; @@ -24,11 +25,13 @@ import * as ErrorUtils from '@libs/ErrorUtils'; import * as ValidationUtils from '@libs/ValidationUtils'; import ChangeExpensifyLoginLink from '@pages/signin/ChangeExpensifyLoginLink'; import Terms from '@pages/signin/Terms'; +import {setIsSigningIn, setReadyToShowAuthScreens} from '@userActions/HybridApp'; import * as SessionActions from '@userActions/Session'; import * as User from '@userActions/User'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {TryNewDot} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; import type ValidateCodeFormProps from './types'; @@ -47,10 +50,14 @@ type ValidateCodeFormVariant = 'validateCode' | 'twoFactorAuthCode' | 'recoveryC type FormError = Partial>; +function shouldUseOldApp(tryNewDot?: TryNewDot) { + return tryNewDot?.classicRedirect.dismissed === true || tryNewDot?.classicRedirect.dismissed === 'true'; +} + function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingRecoveryCode, isVisible}: BaseValidateCodeFormProps, forwardedRef: ForwardedRef) { const [account] = useOnyx(ONYXKEYS.ACCOUNT); const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); - const [session] = useOnyx(ONYXKEYS.SESSION); + const [session, sessionMetadata] = useOnyx(ONYXKEYS.SESSION); const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); @@ -62,7 +69,12 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const [timeRemaining, setTimeRemaining] = useState(CONST.REQUEST_CODE_DELAY as number); const [recoveryCode, setRecoveryCode] = useState(''); const [needToClearError, setNeedToClearError] = useState(!!account?.errors); - const [tryNewDot, tryNewDotMetadata] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); + const [oldDotSignInState, setOldDotSignInState] = useState>(CONST.OLD_DOT_SIGN_IN_STATE.NOT_STARTED); + const [newDotSignInState, setNewDotSignInState] = useState>(CONST.NEW_DOT_SIGN_IN_STATE.NOT_STARTED); + + const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); + const [useNewDotSignInPage] = useOnyx(ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE); const prevRequiresTwoFactorAuth = usePrevious(account?.requiresTwoFactorAuth); const prevValidateCode = usePrevious(credentials?.validateCode); @@ -76,29 +88,62 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const shouldDisableResendValidateCode = isOffline ?? account?.isLoading; const isValidateCodeFormSubmitting = AccountUtils.isValidateCodeFormSubmitting(account); - const isLoading = useMemo(() => { - if (!NativeModules.HybridAppModule || !session?.authToken) { - return isValidateCodeFormSubmitting; + /** + * ustawianie stanu logowania ND na finished, jak używamy strony logowania + */ + useEffect(() => { + if (!NativeModules.HybridAppModule || !useNewDotSignInPage) { + return; } - if (isLoadingOnyxValue(tryNewDotMetadata)) { - return true; + if (isLoadingOnyxValue(sessionMetadata)) { + return; } - return (tryNewDot?.classicRedirect.dismissed === true || tryNewDot?.classicRedirect.dismissed === 'true') && !!session.authToken; - }, [isValidateCodeFormSubmitting, session?.authToken, tryNewDot, tryNewDotMetadata]); + if (newDotSignInState === CONST.NEW_DOT_SIGN_IN_STATE.STARTED && !isValidateCodeFormSubmitting && !!session?.authToken) { + setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.FINISHED); + } + }, [newDotSignInState, isValidateCodeFormSubmitting, session?.authToken, sessionMetadata, useNewDotSignInPage]); + /** + * ustawianie stanu logowania OD na finished, jak używamy strony logowania + */ useEffect(() => { - if (!NativeModules.HybridAppModule || isValidateCodeFormSubmitting || !session?.authToken) { + if (!NativeModules.HybridAppModule || !useNewDotSignInPage) { return; } - if (tryNewDot?.classicRedirect.dismissed === true || tryNewDot?.classicRedirect.dismissed === 'true') { - if (credentials?.autoGeneratedLogin && credentials?.autoGeneratedPassword) { - NativeModules.HybridAppModule.signInToOldDot(credentials?.autoGeneratedLogin, credentials?.autoGeneratedPassword); + if (oldDotSignInState === CONST.OLD_DOT_SIGN_IN_STATE.STARTED && !hybridApp?.isSigningIn) { + setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.FINISHED); + } + }, [hybridApp?.isSigningIn, oldDotSignInState, useNewDotSignInPage]); + + /** + * główny efekt obsługujacy kilka rzeczy + * - odpalanie OD sign in po skończeniu logowania do ND + * - jak chcemy używać ND to w tym momencie jesteśmy gotowi i pokazujemy auth screens + * - jeśli skońćzyło się logowanie do OD i chcemy używać starej apki to zamykamy RN + */ + useEffect(() => { + if (!NativeModules.HybridAppModule || !useNewDotSignInPage) { + return; + } + + if (newDotSignInState === CONST.NEW_DOT_SIGN_IN_STATE.FINISHED && oldDotSignInState === CONST.OLD_DOT_SIGN_IN_STATE.NOT_STARTED) { + if (shouldUseOldApp(tryNewDot)) { + setIsSigningIn(true); + } else { + setReadyToShowAuthScreens(true); } + + setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.STARTED); + NativeModules.HybridAppModule.signInToOldDot(credentials?.autoGeneratedLogin ?? '', credentials?.autoGeneratedPassword ?? ''); + } + + if (oldDotSignInState === CONST.OLD_DOT_SIGN_IN_STATE.FINISHED && shouldUseOldApp(tryNewDot)) { + NativeModules.HybridAppModule.closeReactNativeApp(false, false); } - }, [credentials?.autoGeneratedLogin, credentials?.autoGeneratedPassword, isValidateCodeFormSubmitting, session?.authToken, tryNewDot?.classicRedirect.dismissed]); + }, [account?.isLoading, credentials?.autoGeneratedLogin, credentials?.autoGeneratedPassword, newDotSignInState, oldDotSignInState, tryNewDot, useNewDotSignInPage]); useEffect(() => { if (!(inputValidateCodeRef.current && hasError && (session?.autoAuthState === CONST.AUTO_AUTH_STATE.FAILED || account?.isLoading))) { @@ -308,6 +353,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const recoveryCodeOr2faCode = isUsingRecoveryCode ? recoveryCode : twoFactorAuthCode; + setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.STARTED); const accountID = credentials?.accountID; if (accountID) { SessionActions.signInWithValidateCode(accountID, validateCode, recoveryCodeOr2faCode); @@ -361,7 +407,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco style={[styles.mt2]} onPress={switchBetween2faAndRecoveryCode} hoverDimmingValue={1} - disabled={isLoading} + disabled={isValidateCodeFormSubmitting} role={CONST.ROLE.BUTTON} accessibilityLabel={isUsingRecoveryCode ? translate('recoveryCodeForm.use2fa') : translate('recoveryCodeForm.useRecoveryCode')} > @@ -420,7 +466,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco large style={[styles.mv3]} text={translate('common.signIn')} - isLoading={isLoading} + isLoading={shouldUseOldApp(tryNewDot) ? isValidateCodeFormSubmitting || hybridApp?.isSigningIn : isValidateCodeFormSubmitting} onPress={validateAndSubmitForm} /> From 94ebb8fea73d4a9f68e9a76b153570dfba40a3b5 Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 31 Oct 2024 13:29:12 +0100 Subject: [PATCH 06/95] fix switching to new experience --- src/libs/Navigation/AppNavigator/index.native.tsx | 3 --- src/libs/actions/Session/index.ts | 9 +++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/index.native.tsx b/src/libs/Navigation/AppNavigator/index.native.tsx index 0038ea8a39da..124bd28d3376 100644 --- a/src/libs/Navigation/AppNavigator/index.native.tsx +++ b/src/libs/Navigation/AppNavigator/index.native.tsx @@ -39,12 +39,9 @@ function AppNavigator({authenticated}: AppNavigatorProps) { return false; } - console.log('dupa dupa dupa', authenticated, hybridApp?.readyToShowAuthScreens); return authenticated && (!useNewDotSignInPage || hybridApp?.readyToShowAuthScreens); }, [authenticated, hybridApp?.readyToShowAuthScreens, tryNewDot, useNewDotSignInPage]); - console.log('dupa should show auth screens', shouldShowAuthScreens); - useEffect(() => { if (!NativeModules.HybridAppModule || !initialURL || !shouldShowAuthScreens) { return; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 847d24299c48..5bf732886679 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -512,12 +512,13 @@ function signInAfterTransitionFromOldDot(transitionURL: string) { return new Promise((resolve) => { clearOnyxBeforeSignIn() - .then(() => + .then(() => { + const dismissed = useNewDotSignInPage === 'true' ? 'false' : 'false'; Onyx.multiSet({ [ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE]: useNewDotSignInPage === 'true', - [ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {dismissed: 'true'}}, // This data is mocked and should be returned by BeginSignUp/SignInUser API commands - }), - ) + [ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {dismissed}}, // This data is mocked and should be returned by BeginSignUp/SignInUser API commands + }); + }) .then(initAppAfterTransition) .catch((error) => { Log.hmmm('[HybridApp] Initialization of HybridApp has failed. Forcing transition', {error}); From a9ff5866198e48b44b5736a500bf434b8a8851a3 Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 31 Oct 2024 14:12:24 +0100 Subject: [PATCH 07/95] block switching when still signing in to OD --- src/libs/HybridApp.ts | 3 ++- src/libs/actions/HybridApp.ts | 6 +++++- src/pages/settings/InitialSettingsPage.tsx | 4 ++++ src/types/onyx/HybridApp.ts | 3 +++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 3d63adf2dc7b..9b2c51369da0 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -1,6 +1,6 @@ import {DeviceEventEmitter, NativeModules} from 'react-native'; import CONST from '@src/CONST'; -import {setIsSigningIn} from './actions/HybridApp'; +import {setIsSigningIn, setReadyToSwitchToClassicExperience} from './actions/HybridApp'; import type {Init} from './ActiveClientManager/types'; import Log from './Log'; @@ -13,6 +13,7 @@ const init: Init = () => { DeviceEventEmitter.addListener(CONST.EVENTS.HYBRID_APP.ON_SIGN_IN_FINISHED, () => { Log.info('[HybridApp] `onSignInFinished` event received', true); setIsSigningIn(false); + setReadyToSwitchToClassicExperience(true); }); }; diff --git a/src/libs/actions/HybridApp.ts b/src/libs/actions/HybridApp.ts index 940c562cd67e..c2a8554486ff 100644 --- a/src/libs/actions/HybridApp.ts +++ b/src/libs/actions/HybridApp.ts @@ -9,4 +9,8 @@ function setReadyToShowAuthScreens(readyToShowAuthScreens: boolean) { Onyx.merge(ONYXKEYS.HYBRID_APP, {readyToShowAuthScreens}); } -export {setIsSigningIn, setReadyToShowAuthScreens}; +function setReadyToSwitchToClassicExperience(readyToSwitchToClassicExperience: boolean) { + Onyx.merge(ONYXKEYS.HYBRID_APP, {readyToSwitchToClassicExperience}); +} + +export {setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience}; diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 8c1d68e0a95b..9c6dad757214 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -82,6 +82,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST); const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); const network = useNetwork(); const theme = useTheme(); @@ -236,6 +237,9 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr ...(NativeModules.HybridAppModule ? { action: () => { + if (!hybridApp?.readyToSwitchToClassicExperience) { + return; + } NativeModules.HybridAppModule.closeReactNativeApp(false, true); setInitialURL(undefined); }, diff --git a/src/types/onyx/HybridApp.ts b/src/types/onyx/HybridApp.ts index 0b5bf1868e35..7f58c5664152 100644 --- a/src/types/onyx/HybridApp.ts +++ b/src/types/onyx/HybridApp.ts @@ -5,6 +5,9 @@ type HybridApp = { /** */ readyToShowAuthScreens?: boolean; + + /** */ + readyToSwitchToClassicExperience?: boolean; }; export default HybridApp; From ec6315eb5631c3ff6a34aa5eb9e403a029763d22 Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 31 Oct 2024 14:16:00 +0100 Subject: [PATCH 08/95] reset onyx values on start --- src/libs/actions/Session/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 5bf732886679..38ec1b736fd0 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -517,6 +517,11 @@ function signInAfterTransitionFromOldDot(transitionURL: string) { Onyx.multiSet({ [ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE]: useNewDotSignInPage === 'true', [ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {dismissed}}, // This data is mocked and should be returned by BeginSignUp/SignInUser API commands + [ONYXKEYS.HYBRID_APP]: { + readyToSwitchToClassicExperience: false, + readyToShowAuthScreens: useNewDotSignInPage !== 'true', + isSigningIn: false, + }, }); }) .then(initAppAfterTransition) From e1562bb0d80181d0d8922eb916f0063ebc00172f Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 31 Oct 2024 15:44:52 +0100 Subject: [PATCH 09/95] preserve HYBRID_APP onyx key when signing out --- src/libs/actions/HybridApp.ts | 6 ++++- src/libs/actions/SignInRedirect.ts | 1 + src/pages/settings/InitialSettingsPage.tsx | 4 +++- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 24 +++++++++++++++++-- src/types/onyx/HybridApp.ts | 3 +++ 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/HybridApp.ts b/src/libs/actions/HybridApp.ts index c2a8554486ff..2d4fdd93621d 100644 --- a/src/libs/actions/HybridApp.ts +++ b/src/libs/actions/HybridApp.ts @@ -13,4 +13,8 @@ function setReadyToSwitchToClassicExperience(readyToSwitchToClassicExperience: b Onyx.merge(ONYXKEYS.HYBRID_APP, {readyToSwitchToClassicExperience}); } -export {setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience}; +function setShouldResetSigningInLogic(shouldResetSigningInLogic: boolean) { + Onyx.merge(ONYXKEYS.HYBRID_APP, {shouldResetSigningInLogic}); +} + +export {setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setShouldResetSigningInLogic}; diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index 4d8b60265f29..2996c9939175 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -22,6 +22,7 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { keysToPreserve.push(ONYXKEYS.NVP_PREFERRED_LOCALE); keysToPreserve.push(ONYXKEYS.ACTIVE_CLIENTS); keysToPreserve.push(ONYXKEYS.DEVICE_ID); + keysToPreserve.push(ONYXKEYS.HYBRID_APP); // 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/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 9c6dad757214..cb2c0c677e3f 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -37,6 +37,7 @@ import {hasGlobalWorkspaceSettingsRBR} from '@libs/WorkspacesSettingsUtils'; import * as ReportActionContextMenu from '@pages/home/report/ContextMenu/ReportActionContextMenu'; import variables from '@styles/variables'; import * as App from '@userActions/App'; +import {setShouldResetSigningInLogic} from '@userActions/HybridApp'; import * as Link from '@userActions/Link'; import * as PaymentMethods from '@userActions/PaymentMethods'; import * as Session from '@userActions/Session'; @@ -269,12 +270,13 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr translationKey: signOutTranslationKey, icon: Expensicons.Exit, action: () => { + setShouldResetSigningInLogic(true); signOut(false); }, }, ], }; - }, [styles.pt4, signOut, setInitialURL]); + }, [styles.pt4, hybridApp?.readyToSwitchToClassicExperience, setInitialURL, signOut]); /** * Retuns JSX.Element with menu items diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 24aff5360146..0987f223209d 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -2,7 +2,7 @@ import {useIsFocused} from '@react-navigation/native'; import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react'; import type {ForwardedRef} from 'react'; import {NativeModules, View} from 'react-native'; -import {useOnyx} from 'react-native-onyx'; +import Onyx, {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import Button from '@components/Button'; import SafariFormWrapper from '@components/Form/SafariFormWrapper'; @@ -25,7 +25,7 @@ import * as ErrorUtils from '@libs/ErrorUtils'; import * as ValidationUtils from '@libs/ValidationUtils'; import ChangeExpensifyLoginLink from '@pages/signin/ChangeExpensifyLoginLink'; import Terms from '@pages/signin/Terms'; -import {setIsSigningIn, setReadyToShowAuthScreens} from '@userActions/HybridApp'; +import {setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setShouldResetSigningInLogic} from '@userActions/HybridApp'; import * as SessionActions from '@userActions/Session'; import * as User from '@userActions/User'; import CONST from '@src/CONST'; @@ -88,6 +88,23 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const shouldDisableResendValidateCode = isOffline ?? account?.isLoading; const isValidateCodeFormSubmitting = AccountUtils.isValidateCodeFormSubmitting(account); + useEffect(() => { + if (!NativeModules.HybridAppModule) { + return; + } + if (!hybridApp?.shouldResetSigningInLogic) { + return; + } + + setReadyToShowAuthScreens(false); + setReadyToSwitchToClassicExperience(false); + setIsSigningIn(false); + Onyx.merge(ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE, true); + setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.NOT_STARTED); + setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.NOT_STARTED); + setShouldResetSigningInLogic(false); + }, [hybridApp?.shouldResetSigningInLogic]); + /** * ustawianie stanu logowania ND na finished, jak używamy strony logowania */ @@ -129,6 +146,8 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco return; } + console.log('[HybridApp] newDotSignInState', newDotSignInState); + console.log('[HybridApp] oldDotSignInState', oldDotSignInState); if (newDotSignInState === CONST.NEW_DOT_SIGN_IN_STATE.FINISHED && oldDotSignInState === CONST.OLD_DOT_SIGN_IN_STATE.NOT_STARTED) { if (shouldUseOldApp(tryNewDot)) { setIsSigningIn(true); @@ -136,6 +155,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco setReadyToShowAuthScreens(true); } + console.log('[HybridApp] signInToOldDot'); setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.STARTED); NativeModules.HybridAppModule.signInToOldDot(credentials?.autoGeneratedLogin ?? '', credentials?.autoGeneratedPassword ?? ''); } diff --git a/src/types/onyx/HybridApp.ts b/src/types/onyx/HybridApp.ts index 7f58c5664152..9c239b8bab75 100644 --- a/src/types/onyx/HybridApp.ts +++ b/src/types/onyx/HybridApp.ts @@ -8,6 +8,9 @@ type HybridApp = { /** */ readyToSwitchToClassicExperience?: boolean; + + /** */ + shouldResetSigningInLogic?: boolean; }; export default HybridApp; From efde8055c86cac722c997980cf4f6c6bdf7f33d3 Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 31 Oct 2024 15:57:25 +0100 Subject: [PATCH 10/95] fix --- src/libs/actions/Session/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 38ec1b736fd0..b34f50b50e96 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -513,12 +513,12 @@ function signInAfterTransitionFromOldDot(transitionURL: string) { return new Promise((resolve) => { clearOnyxBeforeSignIn() .then(() => { - const dismissed = useNewDotSignInPage === 'true' ? 'false' : 'false'; + const dismissed = useNewDotSignInPage === 'true' ? 'true' : 'false'; Onyx.multiSet({ [ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE]: useNewDotSignInPage === 'true', [ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {dismissed}}, // This data is mocked and should be returned by BeginSignUp/SignInUser API commands [ONYXKEYS.HYBRID_APP]: { - readyToSwitchToClassicExperience: false, + readyToSwitchToClassicExperience: useNewDotSignInPage !== 'true', readyToShowAuthScreens: useNewDotSignInPage !== 'true', isSigningIn: false, }, From a1b9e1a2c5debbcf58eaead078b18171970bd31a Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 31 Oct 2024 18:00:15 +0100 Subject: [PATCH 11/95] move part of resetting logic --- src/Expensify.tsx | 10 +++++----- src/libs/actions/Session/index.ts | 5 ----- src/pages/settings/InitialSettingsPage.tsx | 8 ++++++-- .../signin/ValidateCodeForm/BaseValidateCodeForm.tsx | 4 ---- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index cd249b055d07..aa374ff935ae 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -118,11 +118,11 @@ function Expensify() { const autoAuthState = useMemo(() => session?.autoAuthState ?? '', [session]); const shouldInit = isNavigationReady && hasAttemptedToOpenPublicRoom; - const shouldHideSplash = true; - // shouldInit && - // (NativeModules.HybridAppModule - // ? splashScreenState === CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN && (isAuthenticated || useNewDotSignInPage) - // : splashScreenState === CONST.BOOT_SPLASH_STATE.VISIBLE); + const shouldHideSplash = + shouldInit && + (NativeModules.HybridAppModule + ? splashScreenState === CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN && (isAuthenticated || useNewDotSignInPage) + : splashScreenState === CONST.BOOT_SPLASH_STATE.VISIBLE); const initializeClient = () => { if (!Visibility.isVisible()) { diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index b34f50b50e96..a0e688643de9 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -517,11 +517,6 @@ function signInAfterTransitionFromOldDot(transitionURL: string) { Onyx.multiSet({ [ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE]: useNewDotSignInPage === 'true', [ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {dismissed}}, // This data is mocked and should be returned by BeginSignUp/SignInUser API commands - [ONYXKEYS.HYBRID_APP]: { - readyToSwitchToClassicExperience: useNewDotSignInPage !== 'true', - readyToShowAuthScreens: useNewDotSignInPage !== 'true', - isSigningIn: false, - }, }); }) .then(initAppAfterTransition) diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index cb2c0c677e3f..58d7310e894d 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -3,7 +3,7 @@ import React, {useCallback, useContext, useEffect, useLayoutEffect, useMemo, use // eslint-disable-next-line no-restricted-imports import type {GestureResponderEvent, ScrollView as RNScrollView, ScrollViewProps, StyleProp, ViewStyle} from 'react-native'; import {NativeModules, View} from 'react-native'; -import {useOnyx} from 'react-native-onyx'; +import Onyx, {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import AccountSwitcher from '@components/AccountSwitcher'; import AccountSwitcherSkeletonView from '@components/AccountSwitcherSkeletonView'; @@ -37,7 +37,7 @@ import {hasGlobalWorkspaceSettingsRBR} from '@libs/WorkspacesSettingsUtils'; import * as ReportActionContextMenu from '@pages/home/report/ContextMenu/ReportActionContextMenu'; import variables from '@styles/variables'; import * as App from '@userActions/App'; -import {setShouldResetSigningInLogic} from '@userActions/HybridApp'; +import {setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setShouldResetSigningInLogic} from '@userActions/HybridApp'; import * as Link from '@userActions/Link'; import * as PaymentMethods from '@userActions/PaymentMethods'; import * as Session from '@userActions/Session'; @@ -271,6 +271,10 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr icon: Expensicons.Exit, action: () => { setShouldResetSigningInLogic(true); + setReadyToShowAuthScreens(false); + setReadyToSwitchToClassicExperience(false); + setIsSigningIn(false); + Onyx.merge(ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE, true); signOut(false); }, }, diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 0987f223209d..83efaac1099c 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -96,10 +96,6 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco return; } - setReadyToShowAuthScreens(false); - setReadyToSwitchToClassicExperience(false); - setIsSigningIn(false); - Onyx.merge(ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE, true); setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.NOT_STARTED); setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.NOT_STARTED); setShouldResetSigningInLogic(false); From 3ad1b62cae38bab09b155fef72c7112a23c3ec69 Mon Sep 17 00:00:00 2001 From: war-in Date: Mon, 4 Nov 2024 10:05:23 +0100 Subject: [PATCH 12/95] move useNewDotSignInPage to HybridApp key --- src/Expensify.tsx | 4 ++-- src/ONYXKEYS.ts | 4 ---- src/libs/Navigation/AppNavigator/index.native.tsx | 5 ++--- src/libs/actions/Session/index.ts | 2 +- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 13 ++++++------- src/types/onyx/HybridApp.ts | 3 +++ 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index aa374ff935ae..c0db92069108 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -96,7 +96,7 @@ function Expensify() { const [screenShareRequest] = useOnyx(ONYXKEYS.SCREEN_SHARE_REQUEST); const [focusModeNotification] = useOnyx(ONYXKEYS.FOCUS_MODE_NOTIFICATION, {initWithStoredValues: false}); const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH); - const [useNewDotSignInPage] = useOnyx(ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); useEffect(() => { if (!account?.needsTwoFactorAuthSetup || account.requiresTwoFactorAuth) { @@ -121,7 +121,7 @@ function Expensify() { const shouldHideSplash = shouldInit && (NativeModules.HybridAppModule - ? splashScreenState === CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN && (isAuthenticated || useNewDotSignInPage) + ? splashScreenState === CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN && (isAuthenticated || hybridApp?.useNewDotSignInPage) : splashScreenState === CONST.BOOT_SPLASH_STATE.VISIBLE); const initializeClient = () => { diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 2222ace5c411..b94d3afe94f0 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -452,9 +452,6 @@ const ONYXKEYS = { /** Company cards custom names */ NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES: 'nvp_expensify_ccCustomNames', - /** Stores the information if HybridApp uses NewDot's sign in flow */ - USE_NEWDOT_SIGN_IN_PAGE: 'useNewDotSignInPage', - HYBRID_APP: 'hybridApp', /** Collection Keys */ @@ -1026,7 +1023,6 @@ type OnyxValuesMapping = { [ONYXKEYS.IS_USING_IMPORTED_STATE]: boolean; [ONYXKEYS.SHOULD_SHOW_SAVED_SEARCH_RENAME_TOOLTIP]: boolean; [ONYXKEYS.NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES]: Record; - [ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE]: boolean; [ONYXKEYS.HYBRID_APP]: OnyxTypes.HybridApp; }; type OnyxValues = OnyxValuesMapping & OnyxCollectionValuesMapping & OnyxFormValuesMapping & OnyxFormDraftValuesMapping; diff --git a/src/libs/Navigation/AppNavigator/index.native.tsx b/src/libs/Navigation/AppNavigator/index.native.tsx index 124bd28d3376..022b3bffd2cb 100644 --- a/src/libs/Navigation/AppNavigator/index.native.tsx +++ b/src/libs/Navigation/AppNavigator/index.native.tsx @@ -20,7 +20,6 @@ function AppNavigator({authenticated}: AppNavigatorProps) { const {initialURL, setInitialURL} = useContext(InitialURLContext); const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); - const [useNewDotSignInPage] = useOnyx(ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE); /** * kiedy chcemy pokazać auth screens: @@ -39,8 +38,8 @@ function AppNavigator({authenticated}: AppNavigatorProps) { return false; } - return authenticated && (!useNewDotSignInPage || hybridApp?.readyToShowAuthScreens); - }, [authenticated, hybridApp?.readyToShowAuthScreens, tryNewDot, useNewDotSignInPage]); + return authenticated && (!hybridApp?.useNewDotSignInPage || hybridApp?.readyToShowAuthScreens); + }, [authenticated, hybridApp?.readyToShowAuthScreens, tryNewDot, hybridApp?.useNewDotSignInPage]); useEffect(() => { if (!NativeModules.HybridAppModule || !initialURL || !shouldShowAuthScreens) { diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index a0e688643de9..6f27144b433d 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -515,7 +515,7 @@ function signInAfterTransitionFromOldDot(transitionURL: string) { .then(() => { const dismissed = useNewDotSignInPage === 'true' ? 'true' : 'false'; Onyx.multiSet({ - [ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE]: useNewDotSignInPage === 'true', + [ONYXKEYS.HYBRID_APP]: {useNewDotSignInPage: useNewDotSignInPage === 'true'}, [ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {dismissed}}, // This data is mocked and should be returned by BeginSignUp/SignInUser API commands }); }) diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 83efaac1099c..661deac5f5a7 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -74,7 +74,6 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); - const [useNewDotSignInPage] = useOnyx(ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE); const prevRequiresTwoFactorAuth = usePrevious(account?.requiresTwoFactorAuth); const prevValidateCode = usePrevious(credentials?.validateCode); @@ -105,7 +104,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * ustawianie stanu logowania ND na finished, jak używamy strony logowania */ useEffect(() => { - if (!NativeModules.HybridAppModule || !useNewDotSignInPage) { + if (!NativeModules.HybridAppModule || !hybridApp?.useNewDotSignInPage) { return; } @@ -116,20 +115,20 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco if (newDotSignInState === CONST.NEW_DOT_SIGN_IN_STATE.STARTED && !isValidateCodeFormSubmitting && !!session?.authToken) { setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.FINISHED); } - }, [newDotSignInState, isValidateCodeFormSubmitting, session?.authToken, sessionMetadata, useNewDotSignInPage]); + }, [newDotSignInState, isValidateCodeFormSubmitting, session?.authToken, sessionMetadata, hybridApp?.useNewDotSignInPage]); /** * ustawianie stanu logowania OD na finished, jak używamy strony logowania */ useEffect(() => { - if (!NativeModules.HybridAppModule || !useNewDotSignInPage) { + if (!NativeModules.HybridAppModule || !hybridApp?.useNewDotSignInPage) { return; } if (oldDotSignInState === CONST.OLD_DOT_SIGN_IN_STATE.STARTED && !hybridApp?.isSigningIn) { setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.FINISHED); } - }, [hybridApp?.isSigningIn, oldDotSignInState, useNewDotSignInPage]); + }, [hybridApp?.isSigningIn, oldDotSignInState, hybridApp?.useNewDotSignInPage]); /** * główny efekt obsługujacy kilka rzeczy @@ -138,7 +137,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * - jeśli skońćzyło się logowanie do OD i chcemy używać starej apki to zamykamy RN */ useEffect(() => { - if (!NativeModules.HybridAppModule || !useNewDotSignInPage) { + if (!NativeModules.HybridAppModule || !hybridApp?.useNewDotSignInPage) { return; } @@ -159,7 +158,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco if (oldDotSignInState === CONST.OLD_DOT_SIGN_IN_STATE.FINISHED && shouldUseOldApp(tryNewDot)) { NativeModules.HybridAppModule.closeReactNativeApp(false, false); } - }, [account?.isLoading, credentials?.autoGeneratedLogin, credentials?.autoGeneratedPassword, newDotSignInState, oldDotSignInState, tryNewDot, useNewDotSignInPage]); + }, [account?.isLoading, credentials?.autoGeneratedLogin, credentials?.autoGeneratedPassword, newDotSignInState, oldDotSignInState, tryNewDot, hybridApp?.useNewDotSignInPage]); useEffect(() => { if (!(inputValidateCodeRef.current && hasError && (session?.autoAuthState === CONST.AUTO_AUTH_STATE.FAILED || account?.isLoading))) { diff --git a/src/types/onyx/HybridApp.ts b/src/types/onyx/HybridApp.ts index 9c239b8bab75..75a9ba1da97d 100644 --- a/src/types/onyx/HybridApp.ts +++ b/src/types/onyx/HybridApp.ts @@ -1,5 +1,8 @@ /** */ type HybridApp = { + /** Stores the information if HybridApp uses NewDot's sign in flow */ + useNewDotSignInPage?: boolean; + /** */ isSigningIn?: boolean; From f9b0e5aa8541321f84a5d141a71257eef661d632 Mon Sep 17 00:00:00 2001 From: war-in Date: Mon, 4 Nov 2024 10:37:12 +0100 Subject: [PATCH 13/95] fix lint & typecheck --- src/App.tsx | 4 ++-- src/Expensify.tsx | 2 +- src/libs/HybridApp.ts | 2 +- .../Navigation/AppNavigator/index.native.tsx | 2 +- src/libs/actions/HybridApp.ts | 6 +++++- src/libs/actions/Session/index.ts | 16 ++++++---------- src/pages/settings/InitialSettingsPage.tsx | 7 ++++--- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 18 ++++++------------ 8 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 4e5f8bb858f8..a308512a40a5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -36,7 +36,7 @@ import Expensify from './Expensify'; import useDefaultDragAndDrop from './hooks/useDefaultDragAndDrop'; import {ReportIDsContextProvider} from './hooks/useReportIDs'; import OnyxUpdateManager from './libs/actions/OnyxUpdateManager'; -import {init} from './libs/HybridApp'; +import HybridApp from './libs/HybridApp'; import {ReportAttachmentsProvider} from './pages/home/report/ReportAttachmentsContext'; import type {Route} from './ROUTES'; import {SplashScreenStateContextProvider} from './SplashScreenStateContext'; @@ -60,7 +60,7 @@ const StrictModeWrapper = CONFIG.USE_REACT_STRICT_MODE_IN_DEV ? React.StrictMode function App({url}: AppProps) { useDefaultDragAndDrop(); OnyxUpdateManager(); - init(); + HybridApp.init(); return ( diff --git a/src/Expensify.tsx b/src/Expensify.tsx index c0db92069108..5d9ab88f6806 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -121,7 +121,7 @@ function Expensify() { const shouldHideSplash = shouldInit && (NativeModules.HybridAppModule - ? splashScreenState === CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN && (isAuthenticated || hybridApp?.useNewDotSignInPage) + ? splashScreenState === CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN && (isAuthenticated || !!hybridApp?.useNewDotSignInPage) : splashScreenState === CONST.BOOT_SPLASH_STATE.VISIBLE); const initializeClient = () => { diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 9b2c51369da0..79c3608c1fcc 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -17,4 +17,4 @@ const init: Init = () => { }); }; -export {init}; +export default {init}; diff --git a/src/libs/Navigation/AppNavigator/index.native.tsx b/src/libs/Navigation/AppNavigator/index.native.tsx index 022b3bffd2cb..7af3e7305662 100644 --- a/src/libs/Navigation/AppNavigator/index.native.tsx +++ b/src/libs/Navigation/AppNavigator/index.native.tsx @@ -4,7 +4,7 @@ import {useOnyx} from 'react-native-onyx'; import {InitialURLContext} from '@components/InitialURLContextProvider'; import Navigation from '@libs/Navigation/Navigation'; import ONYXKEYS from '@src/ONYXKEYS'; -import {TryNewDot} from '@src/types/onyx'; +import type {TryNewDot} from '@src/types/onyx'; import type ReactComponentModule from '@src/types/utils/ReactComponentModule'; type AppNavigatorProps = { diff --git a/src/libs/actions/HybridApp.ts b/src/libs/actions/HybridApp.ts index 2d4fdd93621d..0dcd7bf11696 100644 --- a/src/libs/actions/HybridApp.ts +++ b/src/libs/actions/HybridApp.ts @@ -17,4 +17,8 @@ function setShouldResetSigningInLogic(shouldResetSigningInLogic: boolean) { Onyx.merge(ONYXKEYS.HYBRID_APP, {shouldResetSigningInLogic}); } -export {setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setShouldResetSigningInLogic}; +function setUseNewDotSignInPage(useNewDotSignInPage: boolean) { + Onyx.merge(ONYXKEYS.HYBRID_APP, {useNewDotSignInPage}); +} + +export {setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setShouldResetSigningInLogic, setUseNewDotSignInPage}; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 6f27144b433d..17f513dc34ce 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -482,16 +482,12 @@ function signUpUser() { function signInAfterTransitionFromOldDot(transitionURL: string) { const [route, queryParams] = transitionURL.split('?'); - const queryParamsObject = queryParams - ? Object.fromEntries( - queryParams.split('&').map((param) => { - const [key, value] = param.split('='); - return [key, value]; - }), - ) - : {}; - - const {useNewDotSignInPage, isSingleNewDotEntry} = queryParamsObject; + const {useNewDotSignInPage, isSingleNewDotEntry} = Object.fromEntries( + queryParams.split('&').map((param) => { + const [key, value] = param.split('='); + return [key, value]; + }), + ); const clearOnyxBeforeSignIn = () => { if (useNewDotSignInPage !== 'true') { diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 58d7310e894d..3c0be0e20eef 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -3,7 +3,7 @@ import React, {useCallback, useContext, useEffect, useLayoutEffect, useMemo, use // eslint-disable-next-line no-restricted-imports import type {GestureResponderEvent, ScrollView as RNScrollView, ScrollViewProps, StyleProp, ViewStyle} from 'react-native'; import {NativeModules, View} from 'react-native'; -import Onyx, {useOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import AccountSwitcher from '@components/AccountSwitcher'; import AccountSwitcherSkeletonView from '@components/AccountSwitcherSkeletonView'; @@ -37,7 +37,7 @@ import {hasGlobalWorkspaceSettingsRBR} from '@libs/WorkspacesSettingsUtils'; import * as ReportActionContextMenu from '@pages/home/report/ContextMenu/ReportActionContextMenu'; import variables from '@styles/variables'; import * as App from '@userActions/App'; -import {setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setShouldResetSigningInLogic} from '@userActions/HybridApp'; +import {setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setShouldResetSigningInLogic, setUseNewDotSignInPage} from '@userActions/HybridApp'; import * as Link from '@userActions/Link'; import * as PaymentMethods from '@userActions/PaymentMethods'; import * as Session from '@userActions/Session'; @@ -274,7 +274,8 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr setReadyToShowAuthScreens(false); setReadyToSwitchToClassicExperience(false); setIsSigningIn(false); - Onyx.merge(ONYXKEYS.USE_NEWDOT_SIGN_IN_PAGE, true); + setUseNewDotSignInPage(true); + signOut(false); }, }, diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 661deac5f5a7..31c2ae8d2b1d 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -2,7 +2,7 @@ import {useIsFocused} from '@react-navigation/native'; import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react'; import type {ForwardedRef} from 'react'; import {NativeModules, View} from 'react-native'; -import Onyx, {useOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import Button from '@components/Button'; import SafariFormWrapper from '@components/Form/SafariFormWrapper'; @@ -25,7 +25,7 @@ import * as ErrorUtils from '@libs/ErrorUtils'; import * as ValidationUtils from '@libs/ValidationUtils'; import ChangeExpensifyLoginLink from '@pages/signin/ChangeExpensifyLoginLink'; import Terms from '@pages/signin/Terms'; -import {setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setShouldResetSigningInLogic} from '@userActions/HybridApp'; +import {setIsSigningIn, setReadyToShowAuthScreens, setShouldResetSigningInLogic} from '@userActions/HybridApp'; import * as SessionActions from '@userActions/Session'; import * as User from '@userActions/User'; import CONST from '@src/CONST'; @@ -33,7 +33,6 @@ import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import type {TryNewDot} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; -import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; import type ValidateCodeFormProps from './types'; type BaseValidateCodeFormProps = WithToggleVisibilityViewProps & @@ -57,7 +56,9 @@ function shouldUseOldApp(tryNewDot?: TryNewDot) { function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingRecoveryCode, isVisible}: BaseValidateCodeFormProps, forwardedRef: ForwardedRef) { const [account] = useOnyx(ONYXKEYS.ACCOUNT); const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); - const [session, sessionMetadata] = useOnyx(ONYXKEYS.SESSION); + const [session] = useOnyx(ONYXKEYS.SESSION); + const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); @@ -72,9 +73,6 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const [oldDotSignInState, setOldDotSignInState] = useState>(CONST.OLD_DOT_SIGN_IN_STATE.NOT_STARTED); const [newDotSignInState, setNewDotSignInState] = useState>(CONST.NEW_DOT_SIGN_IN_STATE.NOT_STARTED); - const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); - const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); - const prevRequiresTwoFactorAuth = usePrevious(account?.requiresTwoFactorAuth); const prevValidateCode = usePrevious(credentials?.validateCode); @@ -108,14 +106,10 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco return; } - if (isLoadingOnyxValue(sessionMetadata)) { - return; - } - if (newDotSignInState === CONST.NEW_DOT_SIGN_IN_STATE.STARTED && !isValidateCodeFormSubmitting && !!session?.authToken) { setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.FINISHED); } - }, [newDotSignInState, isValidateCodeFormSubmitting, session?.authToken, sessionMetadata, hybridApp?.useNewDotSignInPage]); + }, [newDotSignInState, isValidateCodeFormSubmitting, session?.authToken, hybridApp?.useNewDotSignInPage]); /** * ustawianie stanu logowania OD na finished, jak używamy strony logowania From 377b6869707aa98b64b4e9617bb62e54fef273c7 Mon Sep 17 00:00:00 2001 From: war-in Date: Mon, 4 Nov 2024 11:56:47 +0100 Subject: [PATCH 14/95] correctly set onyx props when switching from OD --- src/libs/actions/Session/index.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 17f513dc34ce..4ca9a2ab2398 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -42,7 +42,7 @@ import {hideContextMenu} from '@pages/home/report/ContextMenu/ReportActionContex import * as App from '@userActions/App'; import {KEYS_TO_PRESERVE, openApp} from '@userActions/App'; import * as Device from '@userActions/Device'; -import {setReadyToShowAuthScreens} from '@userActions/HybridApp'; +import {setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience} from '@userActions/HybridApp'; import * as PriorityMode from '@userActions/PriorityMode'; import redirectToSignIn from '@userActions/SignInRedirect'; import Timing from '@userActions/Timing'; @@ -482,16 +482,19 @@ function signUpUser() { function signInAfterTransitionFromOldDot(transitionURL: string) { const [route, queryParams] = transitionURL.split('?'); - const {useNewDotSignInPage, isSingleNewDotEntry} = Object.fromEntries( - queryParams.split('&').map((param) => { - const [key, value] = param.split('='); - return [key, value]; - }), - ); + const {useNewDotSignInPage, isSingleNewDotEntry} = queryParams + ? Object.fromEntries( + queryParams.split('&').map((param) => { + const [key, value] = param.split('='); + return [key, value]; + }), + ) + : {useNewDotSignInPage: undefined, isSingleNewDotEntry: undefined}; const clearOnyxBeforeSignIn = () => { if (useNewDotSignInPage !== 'true') { setReadyToShowAuthScreens(true); + setReadyToSwitchToClassicExperience(true); return Promise.resolve(); } @@ -509,7 +512,7 @@ function signInAfterTransitionFromOldDot(transitionURL: string) { return new Promise((resolve) => { clearOnyxBeforeSignIn() .then(() => { - const dismissed = useNewDotSignInPage === 'true' ? 'true' : 'false'; + const dismissed = useNewDotSignInPage === 'true' ? 'false' : 'false'; Onyx.multiSet({ [ONYXKEYS.HYBRID_APP]: {useNewDotSignInPage: useNewDotSignInPage === 'true'}, [ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {dismissed}}, // This data is mocked and should be returned by BeginSignUp/SignInUser API commands From 90f7c0f8b7215810381871c7e5aa8624b19ffff2 Mon Sep 17 00:00:00 2001 From: war-in Date: Mon, 4 Nov 2024 13:42:58 +0100 Subject: [PATCH 15/95] don't set HybridApp key in onyx (merge it) --- src/libs/actions/Session/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 4ca9a2ab2398..cbc4ab4dc052 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -42,7 +42,7 @@ import {hideContextMenu} from '@pages/home/report/ContextMenu/ReportActionContex import * as App from '@userActions/App'; import {KEYS_TO_PRESERVE, openApp} from '@userActions/App'; import * as Device from '@userActions/Device'; -import {setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience} from '@userActions/HybridApp'; +import {setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setUseNewDotSignInPage} from '@userActions/HybridApp'; import * as PriorityMode from '@userActions/PriorityMode'; import redirectToSignIn from '@userActions/SignInRedirect'; import Timing from '@userActions/Timing'; @@ -512,9 +512,9 @@ function signInAfterTransitionFromOldDot(transitionURL: string) { return new Promise((resolve) => { clearOnyxBeforeSignIn() .then(() => { - const dismissed = useNewDotSignInPage === 'true' ? 'false' : 'false'; + setUseNewDotSignInPage(useNewDotSignInPage === 'true'); + const dismissed = useNewDotSignInPage === 'true' ? 'true' : 'false'; Onyx.multiSet({ - [ONYXKEYS.HYBRID_APP]: {useNewDotSignInPage: useNewDotSignInPage === 'true'}, [ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {dismissed}}, // This data is mocked and should be returned by BeginSignUp/SignInUser API commands }); }) From 4b3e539a48974d8d3a91fe3ee7815207e7a83e0b Mon Sep 17 00:00:00 2001 From: war-in Date: Mon, 4 Nov 2024 16:56:19 +0100 Subject: [PATCH 16/95] send error message on failed OD login --- src/libs/HybridApp.ts | 9 ++++--- src/libs/actions/HybridApp.ts | 6 ++++- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 25 ++++++++++++++++--- src/types/onyx/HybridApp.ts | 3 +++ 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 79c3608c1fcc..b500dc1ad1a7 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -1,6 +1,6 @@ import {DeviceEventEmitter, NativeModules} from 'react-native'; import CONST from '@src/CONST'; -import {setIsSigningIn, setReadyToSwitchToClassicExperience} from './actions/HybridApp'; +import {setIsSigningIn, setOldDotSignInError, setReadyToSwitchToClassicExperience} from './actions/HybridApp'; import type {Init} from './ActiveClientManager/types'; import Log from './Log'; @@ -10,9 +10,12 @@ const init: Init = () => { } // Setup event listeners - DeviceEventEmitter.addListener(CONST.EVENTS.HYBRID_APP.ON_SIGN_IN_FINISHED, () => { - Log.info('[HybridApp] `onSignInFinished` event received', true); + DeviceEventEmitter.addListener(CONST.EVENTS.HYBRID_APP.ON_SIGN_IN_FINISHED, (data) => { + Log.info(`[HybridApp] onSignInFinished event received with data: ${data}`, true); + const eventData = JSON.parse(data as string) as {errorMessage: string}; + setIsSigningIn(false); + setOldDotSignInError(eventData.errorMessage); setReadyToSwitchToClassicExperience(true); }); }; diff --git a/src/libs/actions/HybridApp.ts b/src/libs/actions/HybridApp.ts index 0dcd7bf11696..9bf7c79694a1 100644 --- a/src/libs/actions/HybridApp.ts +++ b/src/libs/actions/HybridApp.ts @@ -5,6 +5,10 @@ function setIsSigningIn(isSigningIn: boolean) { Onyx.merge(ONYXKEYS.HYBRID_APP, {isSigningIn}); } +function setOldDotSignInError(oldDotSignInError: string) { + Onyx.merge(ONYXKEYS.HYBRID_APP, {oldDotSignInError}); +} + function setReadyToShowAuthScreens(readyToShowAuthScreens: boolean) { Onyx.merge(ONYXKEYS.HYBRID_APP, {readyToShowAuthScreens}); } @@ -21,4 +25,4 @@ function setUseNewDotSignInPage(useNewDotSignInPage: boolean) { Onyx.merge(ONYXKEYS.HYBRID_APP, {useNewDotSignInPage}); } -export {setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setShouldResetSigningInLogic, setUseNewDotSignInPage}; +export {setOldDotSignInError, setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setShouldResetSigningInLogic, setUseNewDotSignInPage}; diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 31c2ae8d2b1d..148ad852a85d 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -137,7 +137,12 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco console.log('[HybridApp] newDotSignInState', newDotSignInState); console.log('[HybridApp] oldDotSignInState', oldDotSignInState); - if (newDotSignInState === CONST.NEW_DOT_SIGN_IN_STATE.FINISHED && oldDotSignInState === CONST.OLD_DOT_SIGN_IN_STATE.NOT_STARTED) { + if ( + newDotSignInState === CONST.NEW_DOT_SIGN_IN_STATE.FINISHED && + oldDotSignInState === CONST.OLD_DOT_SIGN_IN_STATE.NOT_STARTED && + credentials?.autoGeneratedLogin && + credentials?.autoGeneratedPassword + ) { if (shouldUseOldApp(tryNewDot)) { setIsSigningIn(true); } else { @@ -146,13 +151,26 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco console.log('[HybridApp] signInToOldDot'); setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.STARTED); - NativeModules.HybridAppModule.signInToOldDot(credentials?.autoGeneratedLogin ?? '', credentials?.autoGeneratedPassword ?? ''); + NativeModules.HybridAppModule.signInToOldDot(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); } + console.log('[Hybridapp] should use old app', shouldUseOldApp(tryNewDot)); if (oldDotSignInState === CONST.OLD_DOT_SIGN_IN_STATE.FINISHED && shouldUseOldApp(tryNewDot)) { + if (hybridApp?.oldDotSignInError) { + return; + } NativeModules.HybridAppModule.closeReactNativeApp(false, false); } - }, [account?.isLoading, credentials?.autoGeneratedLogin, credentials?.autoGeneratedPassword, newDotSignInState, oldDotSignInState, tryNewDot, hybridApp?.useNewDotSignInPage]); + }, [ + account?.isLoading, + credentials?.autoGeneratedLogin, + credentials?.autoGeneratedPassword, + newDotSignInState, + oldDotSignInState, + tryNewDot, + hybridApp?.useNewDotSignInPage, + hybridApp?.oldDotSignInError, + ]); useEffect(() => { if (!(inputValidateCodeRef.current && hasError && (session?.autoAuthState === CONST.AUTO_AUTH_STATE.FAILED || account?.isLoading))) { @@ -444,6 +462,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco testID="validateCode" /> {hasError && } + {!!hybridApp?.oldDotSignInError && } {timeRemaining > 0 && !isOffline ? ( diff --git a/src/types/onyx/HybridApp.ts b/src/types/onyx/HybridApp.ts index 75a9ba1da97d..8e248f4148b4 100644 --- a/src/types/onyx/HybridApp.ts +++ b/src/types/onyx/HybridApp.ts @@ -6,6 +6,9 @@ type HybridApp = { /** */ isSigningIn?: boolean; + /** */ + oldDotSignInError?: string | null; + /** */ readyToShowAuthScreens?: boolean; From 026ac7bacad45c7466f116d391ee70b59f1f0d56 Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 5 Nov 2024 11:28:13 +0100 Subject: [PATCH 17/95] add useOldDot const --- src/libs/actions/Session/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index cbc4ab4dc052..81d61530bcce 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -513,7 +513,8 @@ function signInAfterTransitionFromOldDot(transitionURL: string) { clearOnyxBeforeSignIn() .then(() => { setUseNewDotSignInPage(useNewDotSignInPage === 'true'); - const dismissed = useNewDotSignInPage === 'true' ? 'true' : 'false'; + const useOldDot = 'true'; + const dismissed = useNewDotSignInPage === 'true' ? useOldDot : 'false'; Onyx.multiSet({ [ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {dismissed}}, // This data is mocked and should be returned by BeginSignUp/SignInUser API commands }); From d976148e4bafa8b3fcc5d6a11d280048383e17ad Mon Sep 17 00:00:00 2001 From: Jan Nowakowski <56261019+jnowakow@users.noreply.github.com> Date: Thu, 7 Nov 2024 13:54:19 +0100 Subject: [PATCH 18/95] Bootsplash logic in hybridapp (#132) * Implement ND bootsplash logic * Rename param * Adress review --- src/Expensify.tsx | 6 ++++-- src/libs/actions/HybridApp.ts | 6 +++++- src/libs/actions/Session/index.ts | 7 ++++--- src/types/onyx/HybridApp.ts | 3 +++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 5d9ab88f6806..24647a6c5d6a 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -117,10 +117,12 @@ function Expensify() { const isAuthenticated = useMemo(() => !!(session?.authToken ?? null), [session]); const autoAuthState = useMemo(() => session?.autoAuthState ?? '', [session]); - const shouldInit = isNavigationReady && hasAttemptedToOpenPublicRoom; + const shouldInit = !!NativeModules.HybridAppModule + ? !hybridApp?.loggedOutFromOldDot && isNavigationReady && hasAttemptedToOpenPublicRoom + : isNavigationReady && hasAttemptedToOpenPublicRoom; const shouldHideSplash = shouldInit && - (NativeModules.HybridAppModule + (!!NativeModules.HybridAppModule ? splashScreenState === CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN && (isAuthenticated || !!hybridApp?.useNewDotSignInPage) : splashScreenState === CONST.BOOT_SPLASH_STATE.VISIBLE); diff --git a/src/libs/actions/HybridApp.ts b/src/libs/actions/HybridApp.ts index 9bf7c79694a1..db9dd1b08584 100644 --- a/src/libs/actions/HybridApp.ts +++ b/src/libs/actions/HybridApp.ts @@ -25,4 +25,8 @@ function setUseNewDotSignInPage(useNewDotSignInPage: boolean) { Onyx.merge(ONYXKEYS.HYBRID_APP, {useNewDotSignInPage}); } -export {setOldDotSignInError, setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setShouldResetSigningInLogic, setUseNewDotSignInPage}; +function setLoggedOutFromOldDot(loggedOutFromOldDot: boolean) { + Onyx.merge(ONYXKEYS.HYBRID_APP, {loggedOutFromOldDot}); +} + +export {setOldDotSignInError, setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setShouldResetSigningInLogic, setUseNewDotSignInPage, setLoggedOutFromOldDot}; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 81d61530bcce..91e597d10164 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -42,7 +42,7 @@ import {hideContextMenu} from '@pages/home/report/ContextMenu/ReportActionContex import * as App from '@userActions/App'; import {KEYS_TO_PRESERVE, openApp} from '@userActions/App'; import * as Device from '@userActions/Device'; -import {setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setUseNewDotSignInPage} from '@userActions/HybridApp'; +import {setLoggedOutFromOldDot, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setUseNewDotSignInPage} from '@userActions/HybridApp'; import * as PriorityMode from '@userActions/PriorityMode'; import redirectToSignIn from '@userActions/SignInRedirect'; import Timing from '@userActions/Timing'; @@ -482,14 +482,14 @@ function signUpUser() { function signInAfterTransitionFromOldDot(transitionURL: string) { const [route, queryParams] = transitionURL.split('?'); - const {useNewDotSignInPage, isSingleNewDotEntry} = queryParams + const {useNewDotSignInPage, isSingleNewDotEntry, loggedOutFromOldDot} = queryParams ? Object.fromEntries( queryParams.split('&').map((param) => { const [key, value] = param.split('='); return [key, value]; }), ) - : {useNewDotSignInPage: undefined, isSingleNewDotEntry: undefined}; + : {useNewDotSignInPage: undefined, isSingleNewDotEntry: undefined, loggedOutFromOldDot: undefined}; const clearOnyxBeforeSignIn = () => { if (useNewDotSignInPage !== 'true') { @@ -513,6 +513,7 @@ function signInAfterTransitionFromOldDot(transitionURL: string) { clearOnyxBeforeSignIn() .then(() => { setUseNewDotSignInPage(useNewDotSignInPage === 'true'); + setLoggedOutFromOldDot(loggedOutFromOldDot === 'true'); const useOldDot = 'true'; const dismissed = useNewDotSignInPage === 'true' ? useOldDot : 'false'; Onyx.multiSet({ diff --git a/src/types/onyx/HybridApp.ts b/src/types/onyx/HybridApp.ts index 8e248f4148b4..d77412caaf37 100644 --- a/src/types/onyx/HybridApp.ts +++ b/src/types/onyx/HybridApp.ts @@ -17,6 +17,9 @@ type HybridApp = { /** */ shouldResetSigningInLogic?: boolean; + + /** stores infromation if last log out was performed from OldDot */ + loggedOutFromOldDot?: boolean; }; export default HybridApp; From a78141d885ec2b4dad0eccfddb8ff9d750faea16 Mon Sep 17 00:00:00 2001 From: war-in Date: Wed, 13 Nov 2024 11:23:46 +0100 Subject: [PATCH 19/95] fix clearing onyx --- src/libs/actions/Session/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index ae7fb378943c..c9a9531bc2ba 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -499,7 +499,7 @@ function signInAfterTransitionFromOldDot(transitionURL: string) { return Promise.resolve(); } - return Onyx.clear(KEYS_TO_PRESERVE); + return Onyx.clear(); }; const initAppAfterTransition = () => { From deaba6fca7def8751e341a89c9bbf291e07c8b6a Mon Sep 17 00:00:00 2001 From: Mateusz Rajski <60450261+mateuuszzzzz@users.noreply.github.com> Date: Wed, 13 Nov 2024 11:54:12 +0100 Subject: [PATCH 20/95] [HybridApp] Do not use query params in AppProp URL (#125) * Add hybridAppSettings AppProp * Unify how we pass data on both platforms * fix after merge * fix comments --------- Co-authored-by: war-in --- src/App.tsx | 12 ++++-- src/Expensify.tsx | 4 +- src/ONYXKEYS.ts | 4 -- src/components/InitialURLContextProvider.tsx | 13 ++++--- src/hooks/useOnboardingFlow.ts | 2 +- src/libs/TripReservationUtils.ts | 4 +- .../{HybridApp.ts => HybridApp/index.ts} | 16 +++++++- src/libs/actions/HybridApp/types.ts | 12 ++++++ src/libs/actions/Session/index.ts | 37 +++++++++---------- src/types/onyx/HybridApp.ts | 6 +++ 10 files changed, 71 insertions(+), 39 deletions(-) rename src/libs/actions/{HybridApp.ts => HybridApp/index.ts} (69%) create mode 100644 src/libs/actions/HybridApp/types.ts diff --git a/src/App.tsx b/src/App.tsx index 5132d8390421..74fc3c3637e5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -41,9 +41,12 @@ import {ReportAttachmentsProvider} from './pages/home/report/ReportAttachmentsCo import type {Route} from './ROUTES'; import {SplashScreenStateContextProvider} from './SplashScreenStateContext'; +/** + * URL and settings passed to our top-level React Native component by HybridApp. Will always be undefined in "pure" NewDot builds. + */ type AppProps = { - /** URL passed to our top-level React Native component by HybridApp. Will always be undefined in "pure" NewDot builds. */ url?: Route; + hybridAppSettings?: string; }; LogBox.ignoreLogs([ @@ -59,7 +62,7 @@ const fill = {flex: 1}; const StrictModeWrapper = CONFIG.USE_REACT_STRICT_MODE_IN_DEV ? React.StrictMode : ({children}: {children: React.ReactElement}) => children; -function App({url}: AppProps) { +function App({url, hybridAppSettings}: AppProps) { useDefaultDragAndDrop(); OnyxUpdateManager(); HybridApp.init(); @@ -67,7 +70,10 @@ function App({url}: AppProps) { return ( - + !!(session?.authToken ?? null), [session]); const autoAuthState = useMemo(() => session?.autoAuthState ?? '', [session]); - const shouldInit = !!NativeModules.HybridAppModule + const shouldInit = NativeModules.HybridAppModule ? !hybridApp?.loggedOutFromOldDot && isNavigationReady && hasAttemptedToOpenPublicRoom : isNavigationReady && hasAttemptedToOpenPublicRoom; const shouldHideSplash = shouldInit && - (!!NativeModules.HybridAppModule + (NativeModules.HybridAppModule ? splashScreenState === CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN && (isAuthenticated || !!hybridApp?.useNewDotSignInPage) : splashScreenState === CONST.BOOT_SPLASH_STATE.VISIBLE); diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index c8b5c83774bc..0693ef26c69b 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -449,9 +449,6 @@ const ONYXKEYS = { /** Stores recently used currencies */ RECENTLY_USED_CURRENCIES: 'nvp_recentlyUsedCurrencies', - /** States whether we transitioned from OldDot to show only certain group of screens. It should be undefined on pure NewDot. */ - IS_SINGLE_NEW_DOT_ENTRY: 'isSingleNewDotEntry', - /** Company cards custom names */ NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES: 'nvp_expensify_ccCustomNames', @@ -1026,7 +1023,6 @@ type OnyxValuesMapping = { [ONYXKEYS.APPROVAL_WORKFLOW]: OnyxTypes.ApprovalWorkflowOnyx; [ONYXKEYS.IMPORTED_SPREADSHEET]: OnyxTypes.ImportedSpreadsheet; [ONYXKEYS.LAST_ROUTE]: string; - [ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY]: boolean | undefined; [ONYXKEYS.IS_USING_IMPORTED_STATE]: boolean; [ONYXKEYS.SHOULD_SHOW_SAVED_SEARCH_RENAME_TOOLTIP]: boolean; [ONYXKEYS.NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES]: Record; diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index adf361a2573d..cf5094e0fcc8 100644 --- a/src/components/InitialURLContextProvider.tsx +++ b/src/components/InitialURLContextProvider.tsx @@ -18,20 +18,21 @@ const InitialURLContext = createContext({ }); type InitialURLContextProviderProps = { - /** URL passed to our top-level React Native component by HybridApp. Will always be undefined in "pure" NewDot builds. */ url?: Route; + hybridAppSettings?: string; + /** Children passed to the context provider */ children: ReactNode; }; -function InitialURLContextProvider({children, url}: InitialURLContextProviderProps) { - const [initialURL, setInitialURL] = useState(); +function InitialURLContextProvider({children, url, hybridAppSettings}: InitialURLContextProviderProps) { + const [initialURL, setInitialURL] = useState(url); const {setSplashScreenState} = useSplashScreenStateContext(); useEffect(() => { - if (url) { - signInAfterTransitionFromOldDot(url).then((route) => { + if (url && hybridAppSettings) { + signInAfterTransitionFromOldDot(url, hybridAppSettings).then((route) => { setInitialURL(route); setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); }); @@ -40,7 +41,7 @@ function InitialURLContextProvider({children, url}: InitialURLContextProviderPro Linking.getInitialURL().then((initURL) => { setInitialURL(initURL as Route); }); - }, [setSplashScreenState, url]); + }, [hybridAppSettings, setSplashScreenState, url]); const initialUrlContext = useMemo( () => ({ diff --git a/src/hooks/useOnboardingFlow.ts b/src/hooks/useOnboardingFlow.ts index 66ef088d0e4f..9a2f57451d37 100644 --- a/src/hooks/useOnboardingFlow.ts +++ b/src/hooks/useOnboardingFlow.ts @@ -21,7 +21,7 @@ function useOnboardingFlowRouter() { selector: hasCompletedHybridAppOnboardingFlowSelector, }); - const [isSingleNewDotEntry, isSingleNewDotEntryMetadata] = useOnyx(ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY); + const [isSingleNewDotEntry, isSingleNewDotEntryMetadata] = useOnyx(ONYXKEYS.HYBRID_APP, {selector: (data) => data?.isSingleNewDotEntry}); useEffect(() => { if (isLoadingOnyxValue(isOnboardingCompletedMetadata)) { diff --git a/src/libs/TripReservationUtils.ts b/src/libs/TripReservationUtils.ts index f2ce5113af81..9c9947644e7f 100644 --- a/src/libs/TripReservationUtils.ts +++ b/src/libs/TripReservationUtils.ts @@ -44,9 +44,9 @@ Onyx.connect({ let isSingleNewDotEntry: boolean | undefined; Onyx.connect({ - key: ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY, + key: ONYXKEYS.HYBRID_APP, callback: (val) => { - isSingleNewDotEntry = val; + isSingleNewDotEntry = val?.isSingleNewDotEntry; }, }); diff --git a/src/libs/actions/HybridApp.ts b/src/libs/actions/HybridApp/index.ts similarity index 69% rename from src/libs/actions/HybridApp.ts rename to src/libs/actions/HybridApp/index.ts index db9dd1b08584..42a9468ec1bf 100644 --- a/src/libs/actions/HybridApp.ts +++ b/src/libs/actions/HybridApp/index.ts @@ -1,5 +1,10 @@ import Onyx from 'react-native-onyx'; import ONYXKEYS from '@src/ONYXKEYS'; +import type HybridAppSettings from './types'; + +function parseHybridAppSettings(hybridAppSettings: string): HybridAppSettings { + return JSON.parse(hybridAppSettings) as HybridAppSettings; +} function setIsSigningIn(isSigningIn: boolean) { Onyx.merge(ONYXKEYS.HYBRID_APP, {isSigningIn}); @@ -29,4 +34,13 @@ function setLoggedOutFromOldDot(loggedOutFromOldDot: boolean) { Onyx.merge(ONYXKEYS.HYBRID_APP, {loggedOutFromOldDot}); } -export {setOldDotSignInError, setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setShouldResetSigningInLogic, setUseNewDotSignInPage, setLoggedOutFromOldDot}; +export { + parseHybridAppSettings, + setOldDotSignInError, + setIsSigningIn, + setReadyToShowAuthScreens, + setReadyToSwitchToClassicExperience, + setShouldResetSigningInLogic, + setUseNewDotSignInPage, + setLoggedOutFromOldDot, +}; diff --git a/src/libs/actions/HybridApp/types.ts b/src/libs/actions/HybridApp/types.ts new file mode 100644 index 000000000000..dc99313344c8 --- /dev/null +++ b/src/libs/actions/HybridApp/types.ts @@ -0,0 +1,12 @@ +import type ONYXKEYS from '@src/ONYXKEYS'; +import type {TryNewDot} from '@src/types/onyx'; +import type HybridApp from '@src/types/onyx/HybridApp'; + +type HybridAppSettings = { + initialOnyxValues: { + [ONYXKEYS.HYBRID_APP]: HybridApp; + [ONYXKEYS.NVP_TRYNEWDOT]?: TryNewDot; + }; +}; + +export default HybridAppSettings; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index c9a9531bc2ba..b60416268749 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -43,7 +43,7 @@ import * as App from '@userActions/App'; import {KEYS_TO_PRESERVE, openApp} from '@userActions/App'; import {KEYS_TO_PRESERVE_DELEGATE_ACCESS} from '@userActions/Delegate'; import * as Device from '@userActions/Device'; -import {setLoggedOutFromOldDot, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setUseNewDotSignInPage} from '@userActions/HybridApp'; +import {parseHybridAppSettings, setLoggedOutFromOldDot, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setUseNewDotSignInPage} from '@userActions/HybridApp'; import * as PriorityMode from '@userActions/PriorityMode'; import redirectToSignIn from '@userActions/SignInRedirect'; import Timing from '@userActions/Timing'; @@ -481,19 +481,13 @@ function signUpUser() { API.write(WRITE_COMMANDS.SIGN_UP_USER, params, {optimisticData, successData, failureData}); } -function signInAfterTransitionFromOldDot(transitionURL: string) { - const [route, queryParams] = transitionURL.split('?'); - const {useNewDotSignInPage, isSingleNewDotEntry, loggedOutFromOldDot, shouldRemoveDelegatedAccess} = queryParams - ? Object.fromEntries( - queryParams.split('&').map((param) => { - const [key, value] = param.split('='); - return [key, value]; - }), - ) - : {useNewDotSignInPage: undefined, isSingleNewDotEntry: undefined, loggedOutFromOldDot: undefined, shouldRemoveDelegatedAccess: undefined}; +function signInAfterTransitionFromOldDot(route: Route, hybridAppSettings: string) { + const parsedHybridAppSettings = parseHybridAppSettings(hybridAppSettings); + const {initialOnyxValues} = parsedHybridAppSettings; + const {hybridApp, ...newDotOnyxValues} = initialOnyxValues; const clearOnyxBeforeSignIn = () => { - if (useNewDotSignInPage !== 'true') { + if (!hybridApp.useNewDotSignInPage) { setReadyToShowAuthScreens(true); setReadyToSwitchToClassicExperience(true); return Promise.resolve(); @@ -503,7 +497,7 @@ function signInAfterTransitionFromOldDot(transitionURL: string) { }; const initAppAfterTransition = () => { - if (useNewDotSignInPage === 'true') { + if (hybridApp.useNewDotSignInPage) { return Promise.resolve(); } @@ -512,19 +506,22 @@ function signInAfterTransitionFromOldDot(transitionURL: string) { return new Promise((resolve) => { clearOnyxBeforeSignIn() + .then(() => Onyx.merge(ONYXKEYS.HYBRID_APP, hybridApp)) + .then(() => Onyx.multiSet(newDotOnyxValues)) .then(() => { - if (!shouldRemoveDelegatedAccess) { + if (!hybridApp.shouldRemoveDelegatedAccess) { return; } return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS); }) .then(() => { - setUseNewDotSignInPage(useNewDotSignInPage === 'true'); - setLoggedOutFromOldDot(loggedOutFromOldDot === 'true'); + // This data is mocked and should be returned by BeginSignUp/SignInUser API commands + setUseNewDotSignInPage(!!hybridApp.useNewDotSignInPage); + setLoggedOutFromOldDot(!!hybridApp.loggedOutFromOldDot); const useOldDot = 'true'; - const dismissed = useNewDotSignInPage === 'true' ? useOldDot : 'false'; - Onyx.multiSet({ - [ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {dismissed}}, // This data is mocked and should be returned by BeginSignUp/SignInUser API commands + const dismissed = hybridApp.useNewDotSignInPage ? useOldDot : 'false'; + return Onyx.multiSet({ + [ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {dismissed}}, }); }) .then(initAppAfterTransition) @@ -532,7 +529,7 @@ function signInAfterTransitionFromOldDot(transitionURL: string) { Log.hmmm('[HybridApp] Initialization of HybridApp has failed. Forcing transition', {error}); }) .finally(() => { - resolve(`${route}?singleNewDotEntry=${isSingleNewDotEntry}` as Route); + resolve(`${route}?singleNewDotEntry=${hybridApp.isSingleNewDotEntry}` as Route); }); }); } diff --git a/src/types/onyx/HybridApp.ts b/src/types/onyx/HybridApp.ts index d77412caaf37..4e39ba1326be 100644 --- a/src/types/onyx/HybridApp.ts +++ b/src/types/onyx/HybridApp.ts @@ -18,8 +18,14 @@ type HybridApp = { /** */ shouldResetSigningInLogic?: boolean; + /** States whether we transitioned from OldDot to show only certain group of screens. It should be undefined on pure NewDot. */ + isSingleNewDotEntry?: boolean; + /** stores infromation if last log out was performed from OldDot */ loggedOutFromOldDot?: boolean; + + /** */ + shouldRemoveDelegatedAccess?: boolean; }; export default HybridApp; From f2e3bb4a24ac799b780e927bec927951142aa271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Warcho=C5=82?= <61014013+war-in@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:22:55 +0100 Subject: [PATCH 21/95] Handle OD sing-in errors (#136) * wip * block switching when error returned * make goBack work correctly * validate code form and SignIn button works (but require further investigation) * show error when unable to switch to OD * adjust new sign-up flow * add comment --------- Co-authored-by: war-in --- src/CONST.ts | 2 + src/libs/HybridApp.ts | 5 +- src/libs/actions/HybridApp/index.ts | 2 +- src/pages/settings/InitialSettingsPage.tsx | 34 ++++++++++--- src/pages/signin/SignUpWelcomeForm.tsx | 6 ++- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 50 ++++++++++++++++--- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 6f4a8c7fefe1..9466ebd667aa 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -6139,12 +6139,14 @@ const CONST = { NOT_STARTED: 'notStarted', STARTED: 'started', FINISHED: 'finished', + WAITING_FOR_SIGN_OUT: 'waitingForSignOut', }, NEW_DOT_SIGN_IN_STATE: { NOT_STARTED: 'notStarted', STARTED: 'started', FINISHED: 'finished', + WAITING_FOR_SIGN_OUT: 'waitingForSignOut', }, CSV_IMPORT_COLUMNS: { diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index b500dc1ad1a7..16ff02aff4ad 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -16,7 +16,10 @@ const init: Init = () => { setIsSigningIn(false); setOldDotSignInError(eventData.errorMessage); - setReadyToSwitchToClassicExperience(true); + + if (eventData.errorMessage === null) { + setReadyToSwitchToClassicExperience(true); + } }); }; diff --git a/src/libs/actions/HybridApp/index.ts b/src/libs/actions/HybridApp/index.ts index 42a9468ec1bf..b73c5b964969 100644 --- a/src/libs/actions/HybridApp/index.ts +++ b/src/libs/actions/HybridApp/index.ts @@ -10,7 +10,7 @@ function setIsSigningIn(isSigningIn: boolean) { Onyx.merge(ONYXKEYS.HYBRID_APP, {isSigningIn}); } -function setOldDotSignInError(oldDotSignInError: string) { +function setOldDotSignInError(oldDotSignInError: string | null) { Onyx.merge(ONYXKEYS.HYBRID_APP, {oldDotSignInError}); } diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 3c0be0e20eef..ea4db7a20956 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -1,8 +1,9 @@ import {useRoute} from '@react-navigation/native'; import React, {useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState} from 'react'; +import type {ReactNode} from 'react'; // eslint-disable-next-line no-restricted-imports import type {GestureResponderEvent, ScrollView as RNScrollView, ScrollViewProps, StyleProp, ViewStyle} from 'react-native'; -import {NativeModules, View} from 'react-native'; +import {ActivityIndicator, NativeModules, View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import AccountSwitcher from '@components/AccountSwitcher'; @@ -37,10 +38,11 @@ import {hasGlobalWorkspaceSettingsRBR} from '@libs/WorkspacesSettingsUtils'; import * as ReportActionContextMenu from '@pages/home/report/ContextMenu/ReportActionContextMenu'; import variables from '@styles/variables'; import * as App from '@userActions/App'; -import {setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setShouldResetSigningInLogic, setUseNewDotSignInPage} from '@userActions/HybridApp'; +import {setIsSigningIn, setOldDotSignInError, setShouldResetSigningInLogic} from '@userActions/HybridApp'; import * as Link from '@userActions/Link'; import * as PaymentMethods from '@userActions/PaymentMethods'; import * as Session from '@userActions/Session'; +import {signOutAndRedirectToSignIn} from '@userActions/Session'; import * as Wallet from '@userActions/Wallet'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; @@ -71,6 +73,8 @@ type MenuData = { iconRight?: IconAsset; badgeText?: string; badgeStyle?: ViewStyle; + shouldShowRightComponent?: boolean; + rightComponent?: ReactNode; }; type Menu = {sectionStyle: StyleProp; sectionTranslationKey: TranslationPaths; items: MenuData[]}; @@ -84,6 +88,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS); const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); + const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); const network = useNetwork(); const theme = useTheme(); @@ -235,10 +240,26 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr { translationKey: 'exitSurvey.goToExpensifyClassic', icon: Expensicons.ExpensifyLogoNew, + shouldShowRightComponent: hybridApp?.isSigningIn, + rightComponent: ( + + ), + brickRoadIndicator: hybridApp?.oldDotSignInError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined, ...(NativeModules.HybridAppModule ? { action: () => { if (!hybridApp?.readyToSwitchToClassicExperience) { + if (credentials?.autoGeneratedLogin && credentials?.autoGeneratedPassword) { + // jeszcze logika handlująca poprawne zalogowanie, jak po takim kliknięciu się zaloguje to zamykaj apkę!!!! + NativeModules.HybridAppModule.signInToOldDot(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); + setIsSigningIn(true); + setOldDotSignInError(null); + } else { + signOutAndRedirectToSignIn(undefined, undefined, false); + } return; } NativeModules.HybridAppModule.closeReactNativeApp(false, true); @@ -271,17 +292,12 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr icon: Expensicons.Exit, action: () => { setShouldResetSigningInLogic(true); - setReadyToShowAuthScreens(false); - setReadyToSwitchToClassicExperience(false); - setIsSigningIn(false); - setUseNewDotSignInPage(true); - signOut(false); }, }, ], }; - }, [styles.pt4, hybridApp?.readyToSwitchToClassicExperience, setInitialURL, signOut]); + }, [styles.pt4, hybridApp?.isSigningIn, hybridApp?.oldDotSignInError, hybridApp?.readyToSwitchToClassicExperience, theme.spinner, credentials, setInitialURL, signOut]); /** * Retuns JSX.Element with menu items @@ -344,6 +360,8 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr !!item.routeName && !!(activeCentralPaneRoute.name.toLowerCase().replaceAll('_', '') === item.routeName.toLowerCase().replaceAll('/', '')) } + shouldShowRightComponent={item.shouldShowRightComponent} + rightComponent={item.rightComponent} iconRight={item.iconRight} shouldShowRightIcon={item.shouldShowRightIcon} shouldIconUseAutoWidthStyle diff --git a/src/pages/signin/SignUpWelcomeForm.tsx b/src/pages/signin/SignUpWelcomeForm.tsx index 1f8687c218b7..b83ffe90bfd5 100644 --- a/src/pages/signin/SignUpWelcomeForm.tsx +++ b/src/pages/signin/SignUpWelcomeForm.tsx @@ -7,6 +7,7 @@ import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; import * as ErrorUtils from '@libs/ErrorUtils'; +import {setReadyToShowAuthScreens} from '@userActions/HybridApp'; import * as Session from '@userActions/Session'; import ONYXKEYS from '@src/ONYXKEYS'; import ChangeExpensifyLoginLink from './ChangeExpensifyLoginLink'; @@ -28,7 +29,10 @@ function SignUpWelcomeForm() { large text={translate('welcomeSignUpForm.join')} isLoading={account?.isLoading} - onPress={() => Session.signUpUser()} + onPress={() => { + Session.signUpUser(); + setReadyToShowAuthScreens(true); + }} pressOnEnter style={[styles.mb2]} /> diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 148ad852a85d..4e40f4535d40 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -2,7 +2,7 @@ import {useIsFocused} from '@react-navigation/native'; import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react'; import type {ForwardedRef} from 'react'; import {NativeModules, View} from 'react-native'; -import {useOnyx} from 'react-native-onyx'; +import Onyx, {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import Button from '@components/Button'; import SafariFormWrapper from '@components/Form/SafariFormWrapper'; @@ -25,8 +25,16 @@ import * as ErrorUtils from '@libs/ErrorUtils'; import * as ValidationUtils from '@libs/ValidationUtils'; import ChangeExpensifyLoginLink from '@pages/signin/ChangeExpensifyLoginLink'; import Terms from '@pages/signin/Terms'; -import {setIsSigningIn, setReadyToShowAuthScreens, setShouldResetSigningInLogic} from '@userActions/HybridApp'; +import { + setIsSigningIn, + setOldDotSignInError, + setReadyToShowAuthScreens, + setReadyToSwitchToClassicExperience, + setShouldResetSigningInLogic, + setUseNewDotSignInPage, +} from '@userActions/HybridApp'; import * as SessionActions from '@userActions/Session'; +import {signOut} from '@userActions/Session'; import * as User from '@userActions/User'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; @@ -80,7 +88,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const input2FARef = useRef(); const timerRef = useRef(); - const hasError = !!account && !isEmptyObject(account?.errors) && !needToClearError; + const hasError = (!!account && !isEmptyObject(account?.errors) && !needToClearError) || !!hybridApp?.oldDotSignInError; const isLoadingResendValidationForm = account?.loadingForm === CONST.FORMS.RESEND_VALIDATE_CODE_FORM; const shouldDisableResendValidateCode = isOffline ?? account?.isLoading; const isValidateCodeFormSubmitting = AccountUtils.isValidateCodeFormSubmitting(account); @@ -92,6 +100,12 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco if (!hybridApp?.shouldResetSigningInLogic) { return; } + console.log('[HybridApp] Resetting sign in flow'); + setReadyToShowAuthScreens(false); + setReadyToSwitchToClassicExperience(false); + setIsSigningIn(false); + setUseNewDotSignInPage(true); + setOldDotSignInError(null); setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.NOT_STARTED); setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.NOT_STARTED); @@ -107,6 +121,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco } if (newDotSignInState === CONST.NEW_DOT_SIGN_IN_STATE.STARTED && !isValidateCodeFormSubmitting && !!session?.authToken) { + console.log('[HybridApp] session auth token', session?.authToken); setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.FINISHED); } }, [newDotSignInState, isValidateCodeFormSubmitting, session?.authToken, hybridApp?.useNewDotSignInPage]); @@ -251,6 +266,9 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * Trigger the reset validate code flow and ensure the 2FA input field is reset to avoid it being permanently hidden */ const resendValidateCode = () => { + setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.NOT_STARTED); + setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.NOT_STARTED); + setOldDotSignInError(null); User.resendValidateCode(credentials?.login ?? ''); inputValidateCodeRef.current?.clear(); // Give feedback to the user to let them know the email was sent so that they don't spam the button. @@ -273,8 +291,13 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco */ const clearSignInData = useCallback(() => { clearLocalSignInData(); + if (session?.authToken) { + signOut(); + Onyx.set(ONYXKEYS.SESSION, null); + } SessionActions.clearSignInData(); - }, [clearLocalSignInData]); + setShouldResetSigningInLogic(true); + }, [clearLocalSignInData, session?.authToken]); useImperativeHandle(forwardedRef, () => ({ clearSignInData, @@ -330,6 +353,20 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * Check that all the form fields are valid, then trigger the submit callback */ const validateAndSubmitForm = useCallback(() => { + if (session?.authToken) { + setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.WAITING_FOR_SIGN_OUT); + setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.WAITING_FOR_SIGN_OUT); + signOut(); + Onyx.merge(ONYXKEYS.SESSION, { + authToken: null, + }).then(() => { + setIsSigningIn(false); + setOldDotSignInError(null); + setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.NOT_STARTED); + setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.STARTED); + }); + } + if (account?.isLoading) { return; } @@ -387,7 +424,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco } else { SessionActions.signIn(validateCode, recoveryCodeOr2faCode); } - }, [account, credentials, twoFactorAuthCode, validateCode, isUsingRecoveryCode, recoveryCode]); + }, [session?.authToken, account?.isLoading, account?.errors, account?.requiresTwoFactorAuth, isUsingRecoveryCode, recoveryCode, twoFactorAuthCode, credentials?.accountID, validateCode]); return ( @@ -461,8 +498,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco key="validateCode" testID="validateCode" /> - {hasError && } - {!!hybridApp?.oldDotSignInError && } + {hasError && } {timeRemaining > 0 && !isOffline ? ( From 8859b6cd6dfa9da18dd583bcc09e1548b28bf5a0 Mon Sep 17 00:00:00 2001 From: war-in Date: Wed, 13 Nov 2024 13:40:09 +0100 Subject: [PATCH 22/95] add disabled to button --- src/pages/settings/InitialSettingsPage.tsx | 26 ++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index ea4db7a20956..3546559f257d 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -75,6 +75,7 @@ type MenuData = { badgeStyle?: ViewStyle; shouldShowRightComponent?: boolean; rightComponent?: ReactNode; + disabled?: boolean; }; type Menu = {sectionStyle: StyleProp; sectionTranslationKey: TranslationPaths; items: MenuData[]}; @@ -241,13 +242,15 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr translationKey: 'exitSurvey.goToExpensifyClassic', icon: Expensicons.ExpensifyLogoNew, shouldShowRightComponent: hybridApp?.isSigningIn, + disabled: !!hybridApp?.isSigningIn, rightComponent: ( - + + + ), - brickRoadIndicator: hybridApp?.oldDotSignInError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined, ...(NativeModules.HybridAppModule ? { action: () => { @@ -297,7 +300,16 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr }, ], }; - }, [styles.pt4, hybridApp?.isSigningIn, hybridApp?.oldDotSignInError, hybridApp?.readyToSwitchToClassicExperience, theme.spinner, credentials, setInitialURL, signOut]); + }, [ + styles.pt4, + styles.popoverMenuIcon, + theme.spinner, + hybridApp?.readyToSwitchToClassicExperience, + setInitialURL, + credentials?.autoGeneratedLogin, + credentials?.autoGeneratedPassword, + signOut, + ]); /** * Retuns JSX.Element with menu items @@ -334,7 +346,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr title={keyTitle} icon={item.icon} iconType={item.iconType} - disabled={isExecuting} + disabled={isExecuting || item.disabled} onPress={singleExecution(() => { if (item.action) { item.action(); From a3436bc73e25d274f00cd65854ccba2256484855 Mon Sep 17 00:00:00 2001 From: war-in Date: Wed, 13 Nov 2024 16:33:39 +0100 Subject: [PATCH 23/95] move sign in state to HybridApp key --- src/CONST.ts | 9 +-- src/libs/actions/HybridApp/index.ts | 12 ++++ src/libs/actions/Session/index.ts | 12 +++- src/libs/actions/SignInRedirect.ts | 3 +- src/pages/settings/InitialSettingsPage.tsx | 12 ++-- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 55 ++++++++++--------- src/types/onyx/HybridApp.ts | 9 +++ 7 files changed, 69 insertions(+), 43 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 9466ebd667aa..679597cca181 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -6135,14 +6135,7 @@ const CONST = { HIDDEN: `hidden`, }, - OLD_DOT_SIGN_IN_STATE: { - NOT_STARTED: 'notStarted', - STARTED: 'started', - FINISHED: 'finished', - WAITING_FOR_SIGN_OUT: 'waitingForSignOut', - }, - - NEW_DOT_SIGN_IN_STATE: { + HYBRID_APP_SIGN_IN_STATE: { NOT_STARTED: 'notStarted', STARTED: 'started', FINISHED: 'finished', diff --git a/src/libs/actions/HybridApp/index.ts b/src/libs/actions/HybridApp/index.ts index b73c5b964969..486b7a0e79d7 100644 --- a/src/libs/actions/HybridApp/index.ts +++ b/src/libs/actions/HybridApp/index.ts @@ -1,4 +1,6 @@ import Onyx from 'react-native-onyx'; +import type {ValueOf} from 'type-fest'; +import type CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type HybridAppSettings from './types'; @@ -34,6 +36,14 @@ function setLoggedOutFromOldDot(loggedOutFromOldDot: boolean) { Onyx.merge(ONYXKEYS.HYBRID_APP, {loggedOutFromOldDot}); } +function setNewDotSignInState(newDotSignInState: ValueOf) { + Onyx.merge(ONYXKEYS.HYBRID_APP, {newDotSignInState}); +} + +function setOldDotSignInState(oldDotSignInState: ValueOf) { + Onyx.merge(ONYXKEYS.HYBRID_APP, {oldDotSignInState}); +} + export { parseHybridAppSettings, setOldDotSignInError, @@ -43,4 +53,6 @@ export { setShouldResetSigningInLogic, setUseNewDotSignInPage, setLoggedOutFromOldDot, + setNewDotSignInState, + setOldDotSignInState, }; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index b60416268749..01e96e7e1a4a 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -43,7 +43,15 @@ import * as App from '@userActions/App'; import {KEYS_TO_PRESERVE, openApp} from '@userActions/App'; import {KEYS_TO_PRESERVE_DELEGATE_ACCESS} from '@userActions/Delegate'; import * as Device from '@userActions/Device'; -import {parseHybridAppSettings, setLoggedOutFromOldDot, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setUseNewDotSignInPage} from '@userActions/HybridApp'; +import { + parseHybridAppSettings, + setLoggedOutFromOldDot, + setNewDotSignInState, + setOldDotSignInState, + setReadyToShowAuthScreens, + setReadyToSwitchToClassicExperience, + setUseNewDotSignInPage, +} from '@userActions/HybridApp'; import * as PriorityMode from '@userActions/PriorityMode'; import redirectToSignIn from '@userActions/SignInRedirect'; import Timing from '@userActions/Timing'; @@ -498,6 +506,8 @@ function signInAfterTransitionFromOldDot(route: Route, hybridAppSettings: string const initAppAfterTransition = () => { if (hybridApp.useNewDotSignInPage) { + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); return Promise.resolve(); } diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index 2996c9939175..e612b56aa794 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -2,6 +2,7 @@ import Onyx from 'react-native-onyx'; import * as ErrorUtils from '@libs/ErrorUtils'; import type {OnyxKey} from '@src/ONYXKEYS'; import ONYXKEYS from '@src/ONYXKEYS'; +import {setUseNewDotSignInPage} from './HybridApp'; import * as Policy from './Policy/Policy'; let currentIsOffline: boolean | undefined; @@ -22,7 +23,6 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { keysToPreserve.push(ONYXKEYS.NVP_PREFERRED_LOCALE); keysToPreserve.push(ONYXKEYS.ACTIVE_CLIENTS); keysToPreserve.push(ONYXKEYS.DEVICE_ID); - keysToPreserve.push(ONYXKEYS.HYBRID_APP); // 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. @@ -38,6 +38,7 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { // `Onyx.clear` reinitializes the Onyx instance with initial values so use `Onyx.merge` instead of `Onyx.set` Onyx.merge(ONYXKEYS.SESSION, {errors: ErrorUtils.getMicroSecondOnyxErrorWithMessage(errorMessage)}); + setUseNewDotSignInPage(true); }); } diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 3546559f257d..95388841638c 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -38,7 +38,7 @@ import {hasGlobalWorkspaceSettingsRBR} from '@libs/WorkspacesSettingsUtils'; import * as ReportActionContextMenu from '@pages/home/report/ContextMenu/ReportActionContextMenu'; import variables from '@styles/variables'; import * as App from '@userActions/App'; -import {setIsSigningIn, setOldDotSignInError, setShouldResetSigningInLogic} from '@userActions/HybridApp'; +import {setIsSigningIn, setNewDotSignInState, setOldDotSignInError, setOldDotSignInState} from '@userActions/HybridApp'; import * as Link from '@userActions/Link'; import * as PaymentMethods from '@userActions/PaymentMethods'; import * as Session from '@userActions/Session'; @@ -262,6 +262,8 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr setOldDotSignInError(null); } else { signOutAndRedirectToSignIn(undefined, undefined, false); + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); } return; } @@ -293,18 +295,16 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr { translationKey: signOutTranslationKey, icon: Expensicons.Exit, - action: () => { - setShouldResetSigningInLogic(true); - signOut(false); - }, + action: () => signOut(false), }, ], }; }, [ styles.pt4, styles.popoverMenuIcon, - theme.spinner, + hybridApp?.isSigningIn, hybridApp?.readyToSwitchToClassicExperience, + theme.spinner, setInitialURL, credentials?.autoGeneratedLogin, credentials?.autoGeneratedPassword, diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 4e40f4535d40..08b0aebe488e 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -3,7 +3,6 @@ import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, import type {ForwardedRef} from 'react'; import {NativeModules, View} from 'react-native'; import Onyx, {useOnyx} from 'react-native-onyx'; -import type {ValueOf} from 'type-fest'; import Button from '@components/Button'; import SafariFormWrapper from '@components/Form/SafariFormWrapper'; import FormHelpMessage from '@components/FormHelpMessage'; @@ -27,7 +26,9 @@ import ChangeExpensifyLoginLink from '@pages/signin/ChangeExpensifyLoginLink'; import Terms from '@pages/signin/Terms'; import { setIsSigningIn, + setNewDotSignInState, setOldDotSignInError, + setOldDotSignInState, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setShouldResetSigningInLogic, @@ -66,7 +67,9 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); const [session] = useOnyx(ONYXKEYS.SESSION); const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); - const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP, { + initialValue: {oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED, newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED}, + }); const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); @@ -78,8 +81,6 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const [timeRemaining, setTimeRemaining] = useState(CONST.REQUEST_CODE_DELAY as number); const [recoveryCode, setRecoveryCode] = useState(''); const [needToClearError, setNeedToClearError] = useState(!!account?.errors); - const [oldDotSignInState, setOldDotSignInState] = useState>(CONST.OLD_DOT_SIGN_IN_STATE.NOT_STARTED); - const [newDotSignInState, setNewDotSignInState] = useState>(CONST.NEW_DOT_SIGN_IN_STATE.NOT_STARTED); const prevRequiresTwoFactorAuth = usePrevious(account?.requiresTwoFactorAuth); const prevValidateCode = usePrevious(credentials?.validateCode); @@ -107,8 +108,8 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco setUseNewDotSignInPage(true); setOldDotSignInError(null); - setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.NOT_STARTED); - setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.NOT_STARTED); + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); setShouldResetSigningInLogic(false); }, [hybridApp?.shouldResetSigningInLogic]); @@ -120,11 +121,11 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco return; } - if (newDotSignInState === CONST.NEW_DOT_SIGN_IN_STATE.STARTED && !isValidateCodeFormSubmitting && !!session?.authToken) { + if (hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED && !isValidateCodeFormSubmitting && !!session?.authToken) { console.log('[HybridApp] session auth token', session?.authToken); - setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.FINISHED); + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); } - }, [newDotSignInState, isValidateCodeFormSubmitting, session?.authToken, hybridApp?.useNewDotSignInPage]); + }, [isValidateCodeFormSubmitting, session?.authToken, hybridApp?.useNewDotSignInPage, hybridApp?.newDotSignInState]); /** * ustawianie stanu logowania OD na finished, jak używamy strony logowania @@ -134,10 +135,10 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco return; } - if (oldDotSignInState === CONST.OLD_DOT_SIGN_IN_STATE.STARTED && !hybridApp?.isSigningIn) { - setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.FINISHED); + if (hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED && !hybridApp?.isSigningIn) { + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); } - }, [hybridApp?.isSigningIn, oldDotSignInState, hybridApp?.useNewDotSignInPage]); + }, [hybridApp?.isSigningIn, hybridApp?.useNewDotSignInPage, hybridApp?.oldDotSignInState]); /** * główny efekt obsługujacy kilka rzeczy @@ -150,11 +151,11 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco return; } - console.log('[HybridApp] newDotSignInState', newDotSignInState); - console.log('[HybridApp] oldDotSignInState', oldDotSignInState); + console.log('[HybridApp] newDotSignInState', hybridApp?.newDotSignInState); + console.log('[HybridApp] oldDotSignInState', hybridApp?.oldDotSignInState); if ( - newDotSignInState === CONST.NEW_DOT_SIGN_IN_STATE.FINISHED && - oldDotSignInState === CONST.OLD_DOT_SIGN_IN_STATE.NOT_STARTED && + hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && + hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED && credentials?.autoGeneratedLogin && credentials?.autoGeneratedPassword ) { @@ -165,12 +166,12 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco } console.log('[HybridApp] signInToOldDot'); - setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.STARTED); + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); NativeModules.HybridAppModule.signInToOldDot(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); } console.log('[Hybridapp] should use old app', shouldUseOldApp(tryNewDot)); - if (oldDotSignInState === CONST.OLD_DOT_SIGN_IN_STATE.FINISHED && shouldUseOldApp(tryNewDot)) { + if (hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && shouldUseOldApp(tryNewDot)) { if (hybridApp?.oldDotSignInError) { return; } @@ -180,11 +181,11 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco account?.isLoading, credentials?.autoGeneratedLogin, credentials?.autoGeneratedPassword, - newDotSignInState, - oldDotSignInState, tryNewDot, hybridApp?.useNewDotSignInPage, hybridApp?.oldDotSignInError, + hybridApp?.newDotSignInState, + hybridApp?.oldDotSignInState, ]); useEffect(() => { @@ -266,8 +267,8 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * Trigger the reset validate code flow and ensure the 2FA input field is reset to avoid it being permanently hidden */ const resendValidateCode = () => { - setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.NOT_STARTED); - setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.NOT_STARTED); + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); setOldDotSignInError(null); User.resendValidateCode(credentials?.login ?? ''); inputValidateCodeRef.current?.clear(); @@ -354,16 +355,16 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco */ const validateAndSubmitForm = useCallback(() => { if (session?.authToken) { - setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.WAITING_FOR_SIGN_OUT); - setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.WAITING_FOR_SIGN_OUT); + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.WAITING_FOR_SIGN_OUT); + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.WAITING_FOR_SIGN_OUT); signOut(); Onyx.merge(ONYXKEYS.SESSION, { authToken: null, }).then(() => { setIsSigningIn(false); setOldDotSignInError(null); - setOldDotSignInState(CONST.OLD_DOT_SIGN_IN_STATE.NOT_STARTED); - setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.STARTED); + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); }); } @@ -417,7 +418,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const recoveryCodeOr2faCode = isUsingRecoveryCode ? recoveryCode : twoFactorAuthCode; - setNewDotSignInState(CONST.NEW_DOT_SIGN_IN_STATE.STARTED); + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); const accountID = credentials?.accountID; if (accountID) { SessionActions.signInWithValidateCode(accountID, validateCode, recoveryCodeOr2faCode); diff --git a/src/types/onyx/HybridApp.ts b/src/types/onyx/HybridApp.ts index 4e39ba1326be..5eeb84f9a314 100644 --- a/src/types/onyx/HybridApp.ts +++ b/src/types/onyx/HybridApp.ts @@ -1,3 +1,6 @@ +import type {ValueOf} from 'type-fest'; +import type CONST from '@src/CONST'; + /** */ type HybridApp = { /** Stores the information if HybridApp uses NewDot's sign in flow */ @@ -26,6 +29,12 @@ type HybridApp = { /** */ shouldRemoveDelegatedAccess?: boolean; + + /** */ + newDotSignInState?: ValueOf; + + /** */ + oldDotSignInState?: ValueOf; }; export default HybridApp; From 703c31d1baec03f10c59e64b50d8806495d4b930 Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 14 Nov 2024 14:56:42 +0100 Subject: [PATCH 24/95] add loading indicator and error modal --- src/CONST.ts | 3 ++ src/libs/HybridApp.ts | 21 ++++++++- src/pages/settings/InitialSettingsPage.tsx | 44 ++++++++++++------- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 16 +------ 4 files changed, 54 insertions(+), 30 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 679597cca181..0922f57bc3d6 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -6140,6 +6140,9 @@ const CONST = { STARTED: 'started', FINISHED: 'finished', WAITING_FOR_SIGN_OUT: 'waitingForSignOut', + RETRYING_AFTER_FAILURE: 'retryingAfterFailure', + FAILED_AGAIN: 'failedAgain', + BLOCKED: 'blocked', }, CSV_IMPORT_COLUMNS: { diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 16ff02aff4ad..924eac9130aa 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -1,9 +1,27 @@ import {DeviceEventEmitter, NativeModules} from 'react-native'; +import Onyx, {OnyxEntry} from 'react-native-onyx'; import CONST from '@src/CONST'; -import {setIsSigningIn, setOldDotSignInError, setReadyToSwitchToClassicExperience} from './actions/HybridApp'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {HybridApp} from '@src/types/onyx'; +import {setIsSigningIn, setOldDotSignInError, setOldDotSignInState, setReadyToSwitchToClassicExperience} from './actions/HybridApp'; import type {Init} from './ActiveClientManager/types'; import Log from './Log'; +let currentHybridApp: OnyxEntry; +Onyx.connect({ + key: ONYXKEYS.HYBRID_APP, + callback: (hybridApp) => { + if (currentHybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.RETRYING_AFTER_FAILURE && hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED) { + if (hybridApp?.oldDotSignInError) { + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FAILED_AGAIN); + } else { + NativeModules.HybridAppModule.closeReactNativeApp(false, true); + } + } + currentHybridApp = hybridApp; + }, +}); + const init: Init = () => { if (!NativeModules.HybridAppModule) { return; @@ -16,6 +34,7 @@ const init: Init = () => { setIsSigningIn(false); setOldDotSignInError(eventData.errorMessage); + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); if (eventData.errorMessage === null) { setReadyToSwitchToClassicExperience(true); diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 95388841638c..5ebe39086f8c 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -241,8 +241,8 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr { translationKey: 'exitSurvey.goToExpensifyClassic', icon: Expensicons.ExpensifyLogoNew, - shouldShowRightComponent: hybridApp?.isSigningIn, - disabled: !!hybridApp?.isSigningIn, + shouldShowRightComponent: hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.RETRYING_AFTER_FAILURE, + disabled: hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.RETRYING_AFTER_FAILURE, rightComponent: ( { - if (!hybridApp?.readyToSwitchToClassicExperience) { - if (credentials?.autoGeneratedLogin && credentials?.autoGeneratedPassword) { - // jeszcze logika handlująca poprawne zalogowanie, jak po takim kliknięciu się zaloguje to zamykaj apkę!!!! - NativeModules.HybridAppModule.signInToOldDot(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); - setIsSigningIn(true); - setOldDotSignInError(null); - } else { - signOutAndRedirectToSignIn(undefined, undefined, false); - setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - } + console.log('[HybridApp] ready to switch', hybridApp); + if (hybridApp?.readyToSwitchToClassicExperience) { + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.BLOCKED); + NativeModules.HybridAppModule.closeReactNativeApp(false, true); + setInitialURL(undefined); return; } - NativeModules.HybridAppModule.closeReactNativeApp(false, true); - setInitialURL(undefined); + + if (credentials?.autoGeneratedLogin && credentials?.autoGeneratedPassword) { + NativeModules.HybridAppModule.signInToOldDot(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); + setIsSigningIn(true); + setOldDotSignInError(null); + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.RETRYING_AFTER_FAILURE); + } else { + signOutAndRedirectToSignIn(undefined, undefined, false); + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); + } }, } : { @@ -475,6 +478,17 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr onConfirm={() => signOut(true)} onCancel={() => toggleSignoutConfirmModal(false)} /> + { + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); + }} + shouldShowCancelButton={false} + /> ); diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 08b0aebe488e..9a071ab9e305 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -127,19 +127,6 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco } }, [isValidateCodeFormSubmitting, session?.authToken, hybridApp?.useNewDotSignInPage, hybridApp?.newDotSignInState]); - /** - * ustawianie stanu logowania OD na finished, jak używamy strony logowania - */ - useEffect(() => { - if (!NativeModules.HybridAppModule || !hybridApp?.useNewDotSignInPage) { - return; - } - - if (hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED && !hybridApp?.isSigningIn) { - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); - } - }, [hybridApp?.isSigningIn, hybridApp?.useNewDotSignInPage, hybridApp?.oldDotSignInState]); - /** * główny efekt obsługujacy kilka rzeczy * - odpalanie OD sign in po skończeniu logowania do ND @@ -147,7 +134,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * - jeśli skońćzyło się logowanie do OD i chcemy używać starej apki to zamykamy RN */ useEffect(() => { - if (!NativeModules.HybridAppModule || !hybridApp?.useNewDotSignInPage) { + if (!NativeModules.HybridAppModule || !hybridApp?.useNewDotSignInPage || hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.BLOCKED) { return; } @@ -175,6 +162,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco if (hybridApp?.oldDotSignInError) { return; } + console.log('closing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); NativeModules.HybridAppModule.closeReactNativeApp(false, false); } }, [ From 1f6a0e16c5a155a41f306807453efc7d87c31262 Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 14 Nov 2024 17:38:41 +0100 Subject: [PATCH 25/95] move sign in logic to HybridApp.ts --- src/CONST.ts | 1 - src/libs/HybridApp.ts | 95 +++++++++++++++++- src/libs/actions/SignInRedirect.ts | 1 + src/pages/settings/InitialSettingsPage.tsx | 23 ++--- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 99 +------------------ 5 files changed, 103 insertions(+), 116 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 0922f57bc3d6..8ce03a631c3b 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -6142,7 +6142,6 @@ const CONST = { WAITING_FOR_SIGN_OUT: 'waitingForSignOut', RETRYING_AFTER_FAILURE: 'retryingAfterFailure', FAILED_AGAIN: 'failedAgain', - BLOCKED: 'blocked', }, CSV_IMPORT_COLUMNS: { diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 924eac9130aa..4ebc9563df53 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -1,16 +1,65 @@ import {DeviceEventEmitter, NativeModules} from 'react-native'; -import Onyx, {OnyxEntry} from 'react-native-onyx'; +import Onyx from 'react-native-onyx'; +import type {OnyxEntry} from 'react-native-onyx'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {HybridApp} from '@src/types/onyx'; -import {setIsSigningIn, setOldDotSignInError, setOldDotSignInState, setReadyToSwitchToClassicExperience} from './actions/HybridApp'; +import type {Credentials, HybridApp, Session, TryNewDot} from '@src/types/onyx'; +import { + setIsSigningIn, + setNewDotSignInState, + setOldDotSignInError, + setOldDotSignInState, + setReadyToShowAuthScreens, + setReadyToSwitchToClassicExperience, + setShouldResetSigningInLogic, + setUseNewDotSignInPage, +} from './actions/HybridApp'; import type {Init} from './ActiveClientManager/types'; import Log from './Log'; +function shouldUseOldApp(tryNewDot?: TryNewDot) { + return tryNewDot?.classicRedirect.dismissed === true || tryNewDot?.classicRedirect.dismissed === 'true'; +} + +let tryNewDot: OnyxEntry; +Onyx.connect({ + key: ONYXKEYS.NVP_TRYNEWDOT, + callback: (newTryNewDot) => { + tryNewDot = newTryNewDot; + }, +}); + +let credentials: OnyxEntry; +Onyx.connect({ + key: ONYXKEYS.CREDENTIALS, + callback: (newCredentials) => { + credentials = newCredentials; + }, +}); + let currentHybridApp: OnyxEntry; Onyx.connect({ key: ONYXKEYS.HYBRID_APP, callback: (hybridApp) => { + if (!NativeModules.HybridAppModule) { + return; + } + + // reset sign in logic + if (hybridApp?.shouldResetSigningInLogic) { + console.log('[HybridApp] Resetting sign in flow'); + setReadyToShowAuthScreens(false); + setReadyToSwitchToClassicExperience(false); + setIsSigningIn(false); + setUseNewDotSignInPage(true); + setOldDotSignInError(null); + + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); + setShouldResetSigningInLogic(false); + return; + } + if (currentHybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.RETRYING_AFTER_FAILURE && hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED) { if (hybridApp?.oldDotSignInError) { setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FAILED_AGAIN); @@ -18,10 +67,48 @@ Onyx.connect({ NativeModules.HybridAppModule.closeReactNativeApp(false, true); } } + + console.log('[Hybridapp] should use old app', shouldUseOldApp(tryNewDot)); + if (hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && shouldUseOldApp(tryNewDot)) { + if (hybridApp?.oldDotSignInError) { + return; + } + console.log('closing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); + NativeModules.HybridAppModule.closeReactNativeApp(false, false); + } + + if ( + hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && + hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED && + credentials?.autoGeneratedLogin && + credentials?.autoGeneratedPassword + ) { + if (shouldUseOldApp(tryNewDot)) { + setIsSigningIn(true); + } else { + setReadyToShowAuthScreens(true); + } + + console.log('[HybridApp] signInToOldDot'); + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); + NativeModules.HybridAppModule.signInToOldDot(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); + } + currentHybridApp = hybridApp; }, }); +let currentSession: OnyxEntry; +Onyx.connect({ + key: ONYXKEYS.SESSION, + callback: (session: OnyxEntry) => { + if (!currentSession?.authToken && session?.authToken && currentHybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED) { + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); + } + currentSession = session; + }, +}); + const init: Init = () => { if (!NativeModules.HybridAppModule) { return; @@ -43,3 +130,5 @@ const init: Init = () => { }; export default {init}; + +export {shouldUseOldApp}; diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index e612b56aa794..3042ddda6845 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -23,6 +23,7 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { keysToPreserve.push(ONYXKEYS.NVP_PREFERRED_LOCALE); keysToPreserve.push(ONYXKEYS.ACTIVE_CLIENTS); keysToPreserve.push(ONYXKEYS.DEVICE_ID); + keysToPreserve.push(ONYXKEYS.HYBRID_APP); // 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/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 5ebe39086f8c..e441c6b9c09f 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -38,7 +38,7 @@ import {hasGlobalWorkspaceSettingsRBR} from '@libs/WorkspacesSettingsUtils'; import * as ReportActionContextMenu from '@pages/home/report/ContextMenu/ReportActionContextMenu'; import variables from '@styles/variables'; import * as App from '@userActions/App'; -import {setIsSigningIn, setNewDotSignInState, setOldDotSignInError, setOldDotSignInState} from '@userActions/HybridApp'; +import {setIsSigningIn, setNewDotSignInState, setOldDotSignInError, setOldDotSignInState, setShouldResetSigningInLogic} from '@userActions/HybridApp'; import * as Link from '@userActions/Link'; import * as PaymentMethods from '@userActions/PaymentMethods'; import * as Session from '@userActions/Session'; @@ -256,7 +256,6 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr action: () => { console.log('[HybridApp] ready to switch', hybridApp); if (hybridApp?.readyToSwitchToClassicExperience) { - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.BLOCKED); NativeModules.HybridAppModule.closeReactNativeApp(false, true); setInitialURL(undefined); return; @@ -269,8 +268,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.RETRYING_AFTER_FAILURE); } else { signOutAndRedirectToSignIn(undefined, undefined, false); - setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); + setShouldResetSigningInLogic(true); } }, } @@ -298,21 +296,14 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr { translationKey: signOutTranslationKey, icon: Expensicons.Exit, - action: () => signOut(false), + action: () => { + signOut(false); + setShouldResetSigningInLogic(true); + }, }, ], }; - }, [ - styles.pt4, - styles.popoverMenuIcon, - hybridApp?.isSigningIn, - hybridApp?.readyToSwitchToClassicExperience, - theme.spinner, - setInitialURL, - credentials?.autoGeneratedLogin, - credentials?.autoGeneratedPassword, - signOut, - ]); + }, [styles.pt4, styles.popoverMenuIcon, hybridApp, theme.spinner, credentials?.autoGeneratedLogin, credentials?.autoGeneratedPassword, setInitialURL, signOut]); /** * Retuns JSX.Element with menu items diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 9a071ab9e305..51ffb03ec81b 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -21,26 +21,17 @@ import useThemeStyles from '@hooks/useThemeStyles'; import AccountUtils from '@libs/AccountUtils'; import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus'; import * as ErrorUtils from '@libs/ErrorUtils'; +import {shouldUseOldApp} from '@libs/HybridApp'; import * as ValidationUtils from '@libs/ValidationUtils'; import ChangeExpensifyLoginLink from '@pages/signin/ChangeExpensifyLoginLink'; import Terms from '@pages/signin/Terms'; -import { - setIsSigningIn, - setNewDotSignInState, - setOldDotSignInError, - setOldDotSignInState, - setReadyToShowAuthScreens, - setReadyToSwitchToClassicExperience, - setShouldResetSigningInLogic, - setUseNewDotSignInPage, -} from '@userActions/HybridApp'; +import {setIsSigningIn, setNewDotSignInState, setOldDotSignInError, setOldDotSignInState, setShouldResetSigningInLogic} from '@userActions/HybridApp'; import * as SessionActions from '@userActions/Session'; import {signOut} from '@userActions/Session'; import * as User from '@userActions/User'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {TryNewDot} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import type ValidateCodeFormProps from './types'; @@ -58,10 +49,6 @@ type ValidateCodeFormVariant = 'validateCode' | 'twoFactorAuthCode' | 'recoveryC type FormError = Partial>; -function shouldUseOldApp(tryNewDot?: TryNewDot) { - return tryNewDot?.classicRedirect.dismissed === true || tryNewDot?.classicRedirect.dismissed === 'true'; -} - function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingRecoveryCode, isVisible}: BaseValidateCodeFormProps, forwardedRef: ForwardedRef) { const [account] = useOnyx(ONYXKEYS.ACCOUNT); const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); @@ -94,87 +81,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const shouldDisableResendValidateCode = isOffline ?? account?.isLoading; const isValidateCodeFormSubmitting = AccountUtils.isValidateCodeFormSubmitting(account); - useEffect(() => { - if (!NativeModules.HybridAppModule) { - return; - } - if (!hybridApp?.shouldResetSigningInLogic) { - return; - } - console.log('[HybridApp] Resetting sign in flow'); - setReadyToShowAuthScreens(false); - setReadyToSwitchToClassicExperience(false); - setIsSigningIn(false); - setUseNewDotSignInPage(true); - setOldDotSignInError(null); - - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - setShouldResetSigningInLogic(false); - }, [hybridApp?.shouldResetSigningInLogic]); - - /** - * ustawianie stanu logowania ND na finished, jak używamy strony logowania - */ - useEffect(() => { - if (!NativeModules.HybridAppModule || !hybridApp?.useNewDotSignInPage) { - return; - } - - if (hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED && !isValidateCodeFormSubmitting && !!session?.authToken) { - console.log('[HybridApp] session auth token', session?.authToken); - setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); - } - }, [isValidateCodeFormSubmitting, session?.authToken, hybridApp?.useNewDotSignInPage, hybridApp?.newDotSignInState]); - - /** - * główny efekt obsługujacy kilka rzeczy - * - odpalanie OD sign in po skończeniu logowania do ND - * - jak chcemy używać ND to w tym momencie jesteśmy gotowi i pokazujemy auth screens - * - jeśli skońćzyło się logowanie do OD i chcemy używać starej apki to zamykamy RN - */ - useEffect(() => { - if (!NativeModules.HybridAppModule || !hybridApp?.useNewDotSignInPage || hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.BLOCKED) { - return; - } - - console.log('[HybridApp] newDotSignInState', hybridApp?.newDotSignInState); - console.log('[HybridApp] oldDotSignInState', hybridApp?.oldDotSignInState); - if ( - hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && - hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED && - credentials?.autoGeneratedLogin && - credentials?.autoGeneratedPassword - ) { - if (shouldUseOldApp(tryNewDot)) { - setIsSigningIn(true); - } else { - setReadyToShowAuthScreens(true); - } - - console.log('[HybridApp] signInToOldDot'); - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); - NativeModules.HybridAppModule.signInToOldDot(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); - } - - console.log('[Hybridapp] should use old app', shouldUseOldApp(tryNewDot)); - if (hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && shouldUseOldApp(tryNewDot)) { - if (hybridApp?.oldDotSignInError) { - return; - } - console.log('closing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); - NativeModules.HybridAppModule.closeReactNativeApp(false, false); - } - }, [ - account?.isLoading, - credentials?.autoGeneratedLogin, - credentials?.autoGeneratedPassword, - tryNewDot, - hybridApp?.useNewDotSignInPage, - hybridApp?.oldDotSignInError, - hybridApp?.newDotSignInState, - hybridApp?.oldDotSignInState, - ]); + console.log('[HybridApp] hybridApp', hybridApp); useEffect(() => { if (!(inputValidateCodeRef.current && hasError && (session?.autoAuthState === CONST.AUTO_AUTH_STATE.FAILED || account?.isLoading))) { From 63a3de843ddb6de4d62cda2142f920cb57063eb1 Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 14 Nov 2024 18:18:59 +0100 Subject: [PATCH 26/95] fix lint --- src/pages/settings/InitialSettingsPage.tsx | 2 +- src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index e441c6b9c09f..a9924831c022 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -38,7 +38,7 @@ import {hasGlobalWorkspaceSettingsRBR} from '@libs/WorkspacesSettingsUtils'; import * as ReportActionContextMenu from '@pages/home/report/ContextMenu/ReportActionContextMenu'; import variables from '@styles/variables'; import * as App from '@userActions/App'; -import {setIsSigningIn, setNewDotSignInState, setOldDotSignInError, setOldDotSignInState, setShouldResetSigningInLogic} from '@userActions/HybridApp'; +import {setIsSigningIn, setOldDotSignInError, setOldDotSignInState, setShouldResetSigningInLogic} from '@userActions/HybridApp'; import * as Link from '@userActions/Link'; import * as PaymentMethods from '@userActions/PaymentMethods'; import * as Session from '@userActions/Session'; diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 51ffb03ec81b..894ce2b7ac02 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -1,7 +1,7 @@ import {useIsFocused} from '@react-navigation/native'; import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react'; import type {ForwardedRef} from 'react'; -import {NativeModules, View} from 'react-native'; +import {View} from 'react-native'; import Onyx, {useOnyx} from 'react-native-onyx'; import Button from '@components/Button'; import SafariFormWrapper from '@components/Form/SafariFormWrapper'; From 1a99fd116608b63139730326787d0d53a4a77326 Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Wed, 20 Nov 2024 15:25:23 +0100 Subject: [PATCH 27/95] Prevent closing NewDot on first transition with button --- src/libs/HybridApp.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 4ebc9563df53..d5a3d8d96bf7 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -64,12 +64,17 @@ Onyx.connect({ if (hybridApp?.oldDotSignInError) { setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FAILED_AGAIN); } else { + console.debug('Closing, but why', {currentHybridApp, hybridApp}); NativeModules.HybridAppModule.closeReactNativeApp(false, true); } } console.log('[Hybridapp] should use old app', shouldUseOldApp(tryNewDot)); - if (hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && shouldUseOldApp(tryNewDot)) { + if ( + currentHybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED && + hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && + shouldUseOldApp(tryNewDot) + ) { if (hybridApp?.oldDotSignInError) { return; } From 0e601bd55e59833968e955ca2cbc95d8c9f1eeae Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 21 Nov 2024 15:20:50 +0100 Subject: [PATCH 28/95] use "tryNewDot" value to determine which app should be opened --- src/libs/API/types.ts | 4 +- src/libs/HybridApp.ts | 132 ++++++++++++++++-------------- src/libs/actions/Session/index.ts | 17 ++-- src/types/onyx/Response.ts | 3 + src/types/onyx/TryNewDot.ts | 2 +- 5 files changed, 87 insertions(+), 71 deletions(-) diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index bd8a58555617..53144d406813 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -91,7 +91,6 @@ const WRITE_COMMANDS = { REQUEST_NEW_VALIDATE_CODE: 'RequestNewValidateCode', SIGN_IN_WITH_APPLE: 'SignInWithApple', SIGN_IN_WITH_GOOGLE: 'SignInWithGoogle', - SIGN_IN_USER: 'SigninUser', SIGN_IN_USER_WITH_LINK: 'SigninUserWithLink', SEARCH: 'Search', REQUEST_UNLINK_VALIDATION_LINK: 'RequestUnlinkValidationLink', @@ -515,7 +514,6 @@ type WriteCommandParameters = { [WRITE_COMMANDS.REQUEST_NEW_VALIDATE_CODE]: Parameters.RequestNewValidateCodeParams; [WRITE_COMMANDS.SIGN_IN_WITH_APPLE]: Parameters.BeginAppleSignInParams; [WRITE_COMMANDS.SIGN_IN_WITH_GOOGLE]: Parameters.BeginGoogleSignInParams; - [WRITE_COMMANDS.SIGN_IN_USER]: SignInUserParams; [WRITE_COMMANDS.SIGN_IN_USER_WITH_LINK]: Parameters.SignInUserWithLinkParams; [WRITE_COMMANDS.REQUEST_UNLINK_VALIDATION_LINK]: Parameters.RequestUnlinkValidationLinkParams; [WRITE_COMMANDS.UNLINK_LOGIN]: Parameters.UnlinkLoginParams; @@ -1025,6 +1023,7 @@ const SIDE_EFFECT_REQUEST_COMMANDS = { DISCONNECT_AS_DELEGATE: 'DisconnectAsDelegate', COMPLETE_HYBRID_APP_ONBOARDING: 'CompleteHybridAppOnboarding', CONNECT_POLICY_TO_QUICKBOOKS_DESKTOP: 'ConnectPolicyToQuickbooksDesktop', + SIGN_IN_USER: 'SigninUser', } as const; type SideEffectRequestCommand = ValueOf; @@ -1045,6 +1044,7 @@ type SideEffectRequestCommandParameters = { [SIDE_EFFECT_REQUEST_COMMANDS.DISCONNECT_AS_DELEGATE]: EmptyObject; [SIDE_EFFECT_REQUEST_COMMANDS.COMPLETE_HYBRID_APP_ONBOARDING]: EmptyObject; [SIDE_EFFECT_REQUEST_COMMANDS.CONNECT_POLICY_TO_QUICKBOOKS_DESKTOP]: Parameters.ConnectPolicyToQuickBooksDesktopParams; + [SIDE_EFFECT_REQUEST_COMMANDS.SIGN_IN_USER]: SignInUserParams; }; type ApiRequestCommandParameters = WriteCommandParameters & ReadCommandParameters & SideEffectRequestCommandParameters; diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index d5a3d8d96bf7..45f464c25afd 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -18,17 +18,9 @@ import type {Init} from './ActiveClientManager/types'; import Log from './Log'; function shouldUseOldApp(tryNewDot?: TryNewDot) { - return tryNewDot?.classicRedirect.dismissed === true || tryNewDot?.classicRedirect.dismissed === 'true'; + return tryNewDot?.classicRedirect.dismissed === true; } -let tryNewDot: OnyxEntry; -Onyx.connect({ - key: ONYXKEYS.NVP_TRYNEWDOT, - callback: (newTryNewDot) => { - tryNewDot = newTryNewDot; - }, -}); - let credentials: OnyxEntry; Onyx.connect({ key: ONYXKEYS.CREDENTIALS, @@ -38,70 +30,86 @@ Onyx.connect({ }); let currentHybridApp: OnyxEntry; +let currentTryNewDot: OnyxEntry; + Onyx.connect({ key: ONYXKEYS.HYBRID_APP, callback: (hybridApp) => { - if (!NativeModules.HybridAppModule) { - return; - } + handleSignInFlow(hybridApp, currentTryNewDot); + }, +}); - // reset sign in logic - if (hybridApp?.shouldResetSigningInLogic) { - console.log('[HybridApp] Resetting sign in flow'); - setReadyToShowAuthScreens(false); - setReadyToSwitchToClassicExperience(false); - setIsSigningIn(false); - setUseNewDotSignInPage(true); - setOldDotSignInError(null); - - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - setShouldResetSigningInLogic(false); - return; - } +Onyx.connect({ + key: ONYXKEYS.NVP_TRYNEWDOT, + callback: (tryNewDot) => { + handleSignInFlow(currentHybridApp, tryNewDot); + }, +}); - if (currentHybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.RETRYING_AFTER_FAILURE && hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED) { - if (hybridApp?.oldDotSignInError) { - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FAILED_AGAIN); - } else { - console.debug('Closing, but why', {currentHybridApp, hybridApp}); - NativeModules.HybridAppModule.closeReactNativeApp(false, true); - } +function handleSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry) { + if (!NativeModules.HybridAppModule) { + return; + } + + // reset sign in logic + if (hybridApp?.shouldResetSigningInLogic) { + console.log('[HybridApp] Resetting sign in flow'); + setReadyToShowAuthScreens(false); + setReadyToSwitchToClassicExperience(false); + setIsSigningIn(false); + setUseNewDotSignInPage(true); + setOldDotSignInError(null); + + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); + setShouldResetSigningInLogic(false); + return; + } + + if (currentHybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.RETRYING_AFTER_FAILURE && hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED) { + if (hybridApp?.oldDotSignInError) { + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FAILED_AGAIN); + } else { + console.debug('Closing, but why', {currentHybridApp, hybridApp}); + NativeModules.HybridAppModule.closeReactNativeApp(false, true); } + } - console.log('[Hybridapp] should use old app', shouldUseOldApp(tryNewDot)); - if ( - currentHybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED && - hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && - shouldUseOldApp(tryNewDot) - ) { - if (hybridApp?.oldDotSignInError) { - return; - } - console.log('closing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); - NativeModules.HybridAppModule.closeReactNativeApp(false, false); + console.log('[Hybridapp] should use old app', shouldUseOldApp(tryNewDot)); + if ( + currentHybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED && + hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && + tryNewDot !== undefined && + shouldUseOldApp(tryNewDot) + ) { + if (hybridApp?.oldDotSignInError) { + return; } + console.log('closing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); + NativeModules.HybridAppModule.closeReactNativeApp(false, false); + } - if ( - hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && - hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED && - credentials?.autoGeneratedLogin && - credentials?.autoGeneratedPassword - ) { - if (shouldUseOldApp(tryNewDot)) { - setIsSigningIn(true); - } else { - setReadyToShowAuthScreens(true); - } - - console.log('[HybridApp] signInToOldDot'); - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); - NativeModules.HybridAppModule.signInToOldDot(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); + if ( + hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && + hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED && + credentials?.autoGeneratedLogin && + credentials?.autoGeneratedPassword && + tryNewDot !== undefined + ) { + if (shouldUseOldApp(tryNewDot)) { + setIsSigningIn(true); + } else { + setReadyToShowAuthScreens(true); } - currentHybridApp = hybridApp; - }, -}); + console.log('[HybridApp] signInToOldDot'); + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); + NativeModules.HybridAppModule.signInToOldDot(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); + } + + currentHybridApp = hybridApp; + currentTryNewDot = tryNewDot; +} let currentSession: OnyxEntry; Onyx.connect({ diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 87de3dd3675d..b05405911133 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -528,11 +528,6 @@ function signInAfterTransitionFromOldDot(route: Route, hybridAppSettings: string // This data is mocked and should be returned by BeginSignUp/SignInUser API commands setUseNewDotSignInPage(!!hybridApp.useNewDotSignInPage); setLoggedOutFromOldDot(!!hybridApp.loggedOutFromOldDot); - const useOldDot = 'true'; - const dismissed = hybridApp.useNewDotSignInPage ? useOldDot : 'false'; - return Onyx.multiSet({ - [ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {dismissed}}, - }); }) .then(initAppAfterTransition) .catch((error) => { @@ -642,7 +637,17 @@ function signIn(validateCode: string, twoFactorAuthCode?: string) { params.validateCode = validateCode || credentials.validateCode; } - API.write(WRITE_COMMANDS.SIGN_IN_USER, params, {optimisticData, successData, failureData}); + // eslint-disable-next-line rulesdir/no-api-side-effects-method + API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.SIGN_IN_USER, params, { + optimisticData, + successData, + failureData, + }).then((response) => { + if (!response) { + return; + } + Onyx.merge(ONYXKEYS.NVP_TRYNEWDOT, {classicRedirect: {dismissed: !response.tryNewDot}}); + }); }); } diff --git a/src/types/onyx/Response.ts b/src/types/onyx/Response.ts index ce9acbaaccc6..ca39aa2563b5 100644 --- a/src/types/onyx/Response.ts +++ b/src/types/onyx/Response.ts @@ -83,6 +83,9 @@ type Response = { /** If there is newer data to load for pagination commands */ hasNewerActions?: boolean; + + /** [HybridApp] Determines which app should be opened, NewDot or OldDot */ + tryNewDot?: boolean; }; export default Response; diff --git a/src/types/onyx/TryNewDot.ts b/src/types/onyx/TryNewDot.ts index 67ea66d255d8..a5261a694da4 100644 --- a/src/types/onyx/TryNewDot.ts +++ b/src/types/onyx/TryNewDot.ts @@ -9,7 +9,7 @@ type TryNewDot = { /** * Indicates if transistion from OldDot to NewDot should happen in HybridApp. */ - dismissed: boolean | string; + dismissed: boolean; /** * Indicates timestamp of an action. */ From 1c0c219a4900a21754452f55b4d9c3f2bd3cf9b6 Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 21 Nov 2024 16:57:46 +0100 Subject: [PATCH 29/95] first step to fix deeplinks --- src/libs/Navigation/AppNavigator/index.native.tsx | 2 +- src/libs/actions/Session/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/index.native.tsx b/src/libs/Navigation/AppNavigator/index.native.tsx index 7af3e7305662..bc95c4531756 100644 --- a/src/libs/Navigation/AppNavigator/index.native.tsx +++ b/src/libs/Navigation/AppNavigator/index.native.tsx @@ -13,7 +13,7 @@ type AppNavigatorProps = { }; function shouldUseOldApp(tryNewDot?: TryNewDot) { - return tryNewDot?.classicRedirect.dismissed === true || tryNewDot?.classicRedirect.dismissed === 'true'; + return tryNewDot?.classicRedirect.dismissed === true; } function AppNavigator({authenticated}: AppNavigatorProps) { diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index b05405911133..1a61a8adec7c 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -534,7 +534,7 @@ function signInAfterTransitionFromOldDot(route: Route, hybridAppSettings: string Log.hmmm('[HybridApp] Initialization of HybridApp has failed. Forcing transition', {error}); }) .finally(() => { - resolve(`${route}?singleNewDotEntry=${hybridApp.isSingleNewDotEntry}` as Route); + resolve(`${route}${hybridApp.isSingleNewDotEntry ? '?singleNewDotEntry=true' : ''}` as Route); }); }); } From 417096876c679955f9354bd971df91f14ff1fb15 Mon Sep 17 00:00:00 2001 From: war-in Date: Wed, 27 Nov 2024 11:43:46 +0100 Subject: [PATCH 30/95] improve openApp flow --- .../Navigation/AppNavigator/AuthScreens.tsx | 17 +++++++---------- src/libs/actions/Session/index.ts | 15 +-------------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index 689945da099e..819e8ac29ffe 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -294,16 +294,13 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie setDidPusherInit(true); }); - // In Hybrid App we decide to call one of those method when booting ND and we don't want to duplicate calls - if (!NativeModules.HybridAppModule) { - // If we are on this screen then we are "logged in", but the user might not have "just logged in". They could be reopening the app - // or returning from background. If so, we'll assume they have some app data already and we can call reconnectApp() instead of openApp(). - if (SessionUtils.didUserLogInDuringSession()) { - App.openApp(); - } else { - Log.info('[AuthScreens] Sending ReconnectApp'); - App.reconnectApp(initialLastUpdateIDAppliedToClient); - } + // If we are on this screen then we are "logged in", but the user might not have "just logged in". They could be reopening the app + // or returning from background. If so, we'll assume they have some app data already and we can call reconnectApp() instead of openApp(). + if (SessionUtils.didUserLogInDuringSession()) { + App.openApp(); + } else { + Log.info('[AuthScreens] Sending ReconnectApp'); + App.reconnectApp(initialLastUpdateIDAppliedToClient); } PriorityMode.autoSwitchToFocusMode(); diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index ea106f8c9dda..80ff373d3d72 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -489,15 +489,6 @@ function signUpUser() { API.write(WRITE_COMMANDS.SIGN_UP_USER, params, {optimisticData, successData, failureData}); } -function getLastUpdateIDAppliedToClient(): Promise { - return new Promise((resolve) => { - Onyx.connect({ - key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, - callback: (value) => resolve(value ?? 0), - }); - }); -} - function signInAfterTransitionFromOldDot(route: Route, hybridAppSettings: string) { const parsedHybridAppSettings = parseHybridAppSettings(hybridAppSettings); const {initialOnyxValues} = parsedHybridAppSettings; @@ -517,12 +508,8 @@ function signInAfterTransitionFromOldDot(route: Route, hybridAppSettings: string if (hybridApp.useNewDotSignInPage) { setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - return Promise.resolve(); } - - return getLastUpdateIDAppliedToClient().then((lastUpdateId) => { - return App.reconnectApp(lastUpdateId); - }); + return Promise.resolve(); }; return new Promise((resolve) => { From 50c3fede85c436057b9cc6e177337dbb9d9f2d8c Mon Sep 17 00:00:00 2001 From: Mateusz Rajski <60450261+mateuuszzzzz@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:27:35 +0100 Subject: [PATCH 31/95] [HybridApp] Clean code (#143) * Simplify HybridApp.ts * Use early returns * Rearrange HybridApp module * Remove redundant keys * Remove unused import --- src/components/InitialURLContextProvider.tsx | 6 +- src/libs/HybridApp.ts | 118 +++++++----------- src/libs/actions/HybridApp/index.ts | 75 ++++++++--- src/libs/actions/Session/index.ts | 30 +---- src/pages/settings/InitialSettingsPage.tsx | 16 +-- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 29 +++-- src/types/onyx/HybridApp.ts | 21 +--- 7 files changed, 139 insertions(+), 156 deletions(-) diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index a111928ae094..b89a842d1420 100644 --- a/src/components/InitialURLContextProvider.tsx +++ b/src/components/InitialURLContextProvider.tsx @@ -32,7 +32,7 @@ type InitialURLContextProviderProps = { }; function InitialURLContextProvider({children, url, hybridAppSettings}: InitialURLContextProviderProps) { - const [initialURL, setInitialURL] = useState(url); + const [initialURL, setInitialURL] = useState | undefined>(url); const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH); const {splashScreenState, setSplashScreenState} = useSplashScreenStateContext(); @@ -66,8 +66,8 @@ function InitialURLContextProvider({children, url, hybridAppSettings}: InitialUR const initialUrlContext = useMemo( () => ({ - initialURL, - setInitialURL, + initialURL: initialURL === CONST.HYBRID_APP.REORDERING_REACT_NATIVE_ACTIVITY_TO_FRONT ? undefined : initialURL, + setInitialURL: setInitialURL as React.Dispatch>, }), [initialURL], ); diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 45f464c25afd..4a5dea653714 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -4,37 +4,17 @@ import type {OnyxEntry} from 'react-native-onyx'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Credentials, HybridApp, Session, TryNewDot} from '@src/types/onyx'; -import { - setIsSigningIn, - setNewDotSignInState, - setOldDotSignInError, - setOldDotSignInState, - setReadyToShowAuthScreens, - setReadyToSwitchToClassicExperience, - setShouldResetSigningInLogic, - setUseNewDotSignInPage, -} from './actions/HybridApp'; +import * as HybridAppActions from './actions/HybridApp'; import type {Init} from './ActiveClientManager/types'; import Log from './Log'; -function shouldUseOldApp(tryNewDot?: TryNewDot) { - return tryNewDot?.classicRedirect.dismissed === true; -} - -let credentials: OnyxEntry; -Onyx.connect({ - key: ONYXKEYS.CREDENTIALS, - callback: (newCredentials) => { - credentials = newCredentials; - }, -}); - let currentHybridApp: OnyxEntry; let currentTryNewDot: OnyxEntry; Onyx.connect({ key: ONYXKEYS.HYBRID_APP, callback: (hybridApp) => { + console.debug('Last hybridApp value', {hybridApp}); handleSignInFlow(hybridApp, currentTryNewDot); }, }); @@ -42,40 +22,50 @@ Onyx.connect({ Onyx.connect({ key: ONYXKEYS.NVP_TRYNEWDOT, callback: (tryNewDot) => { + console.debug('Last tryNewDot value', {tryNewDot}); handleSignInFlow(currentHybridApp, tryNewDot); }, }); +let currentSession: OnyxEntry; +Onyx.connect({ + key: ONYXKEYS.SESSION, + callback: (session: OnyxEntry) => { + if (!currentSession?.authToken && session?.authToken && currentHybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED) { + HybridAppActions.setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); + } + currentSession = session; + }, +}); + +let credentials: OnyxEntry; +Onyx.connect({ + key: ONYXKEYS.CREDENTIALS, + callback: (newCredentials) => { + credentials = newCredentials; + }, +}); + +function shouldUseOldApp(tryNewDot?: TryNewDot) { + return tryNewDot?.classicRedirect.dismissed === true; +} + function handleSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry) { if (!NativeModules.HybridAppModule) { return; } - // reset sign in logic - if (hybridApp?.shouldResetSigningInLogic) { - console.log('[HybridApp] Resetting sign in flow'); - setReadyToShowAuthScreens(false); - setReadyToSwitchToClassicExperience(false); - setIsSigningIn(false); - setUseNewDotSignInPage(true); - setOldDotSignInError(null); - - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - setShouldResetSigningInLogic(false); - return; - } - if (currentHybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.RETRYING_AFTER_FAILURE && hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED) { if (hybridApp?.oldDotSignInError) { - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FAILED_AGAIN); - } else { - console.debug('Closing, but why', {currentHybridApp, hybridApp}); - NativeModules.HybridAppModule.closeReactNativeApp(false, true); + Log.info('[HybridApp] Unable to open OldDot. Sign-in has failed again'); + HybridAppActions.setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FAILED_AGAIN); + return; } + + Log.info('[HybridApp] Closing NewDot as retrying sign-in to OldDot succeeded'); + NativeModules.HybridAppModule.closeReactNativeApp(false, true); } - console.log('[Hybridapp] should use old app', shouldUseOldApp(tryNewDot)); if ( currentHybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED && hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && @@ -83,9 +73,11 @@ function handleSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry< shouldUseOldApp(tryNewDot) ) { if (hybridApp?.oldDotSignInError) { + Log.info('[HybridApp] Unable to open OldDot. Sign-in has failed'); return; } - console.log('closing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); + + Log.info('[HybridApp] Closing NewDot as sign-in to OldDot succeeded'); NativeModules.HybridAppModule.closeReactNativeApp(false, false); } @@ -96,31 +88,24 @@ function handleSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry< credentials?.autoGeneratedPassword && tryNewDot !== undefined ) { - if (shouldUseOldApp(tryNewDot)) { - setIsSigningIn(true); - } else { - setReadyToShowAuthScreens(true); + if (!shouldUseOldApp(tryNewDot)) { + Log.info('[HybridApp] The user should see NewDot. There is no need to block the user on the `SignInPage` until the sign-in process is completed on the OldDot side.'); + HybridAppActions.setReadyToShowAuthScreens(true); } - console.log('[HybridApp] signInToOldDot'); - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); - NativeModules.HybridAppModule.signInToOldDot(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); + Log.info(`[HybridApp] Performing sign-in${shouldUseOldApp(tryNewDot) ? '' : ' (in background)'} on OldDot side`); + HybridAppActions.startOldDotSignIn(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); } currentHybridApp = hybridApp; currentTryNewDot = tryNewDot; } -let currentSession: OnyxEntry; -Onyx.connect({ - key: ONYXKEYS.SESSION, - callback: (session: OnyxEntry) => { - if (!currentSession?.authToken && session?.authToken && currentHybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED) { - setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); - } - currentSession = session; - }, -}); +function onOldDotSignInFinished(data: string) { + const eventData = JSON.parse(data) as {errorMessage: string}; + Log.info(`[HybridApp] onSignInFinished event received`, true, {eventData}); + HybridAppActions.finishOldDotSignIn(eventData.errorMessage); +} const init: Init = () => { if (!NativeModules.HybridAppModule) { @@ -128,18 +113,7 @@ const init: Init = () => { } // Setup event listeners - DeviceEventEmitter.addListener(CONST.EVENTS.HYBRID_APP.ON_SIGN_IN_FINISHED, (data) => { - Log.info(`[HybridApp] onSignInFinished event received with data: ${data}`, true); - const eventData = JSON.parse(data as string) as {errorMessage: string}; - - setIsSigningIn(false); - setOldDotSignInError(eventData.errorMessage); - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); - - if (eventData.errorMessage === null) { - setReadyToSwitchToClassicExperience(true); - } - }); + DeviceEventEmitter.addListener(CONST.EVENTS.HYBRID_APP.ON_SIGN_IN_FINISHED, onOldDotSignInFinished); }; export default {init}; diff --git a/src/libs/actions/HybridApp/index.ts b/src/libs/actions/HybridApp/index.ts index 486b7a0e79d7..8ef4dfeca492 100644 --- a/src/libs/actions/HybridApp/index.ts +++ b/src/libs/actions/HybridApp/index.ts @@ -1,17 +1,15 @@ +import {NativeModules} from 'react-native'; import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; -import type CONST from '@src/CONST'; +import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {HybridApp} from '@src/types/onyx'; import type HybridAppSettings from './types'; function parseHybridAppSettings(hybridAppSettings: string): HybridAppSettings { return JSON.parse(hybridAppSettings) as HybridAppSettings; } -function setIsSigningIn(isSigningIn: boolean) { - Onyx.merge(ONYXKEYS.HYBRID_APP, {isSigningIn}); -} - function setOldDotSignInError(oldDotSignInError: string | null) { Onyx.merge(ONYXKEYS.HYBRID_APP, {oldDotSignInError}); } @@ -20,14 +18,6 @@ function setReadyToShowAuthScreens(readyToShowAuthScreens: boolean) { Onyx.merge(ONYXKEYS.HYBRID_APP, {readyToShowAuthScreens}); } -function setReadyToSwitchToClassicExperience(readyToSwitchToClassicExperience: boolean) { - Onyx.merge(ONYXKEYS.HYBRID_APP, {readyToSwitchToClassicExperience}); -} - -function setShouldResetSigningInLogic(shouldResetSigningInLogic: boolean) { - Onyx.merge(ONYXKEYS.HYBRID_APP, {shouldResetSigningInLogic}); -} - function setUseNewDotSignInPage(useNewDotSignInPage: boolean) { Onyx.merge(ONYXKEYS.HYBRID_APP, {useNewDotSignInPage}); } @@ -44,15 +34,68 @@ function setOldDotSignInState(oldDotSignInState: ValueOf { if (!hybridApp.useNewDotSignInPage) { - setReadyToShowAuthScreens(true); - setReadyToSwitchToClassicExperience(true); return Promise.resolve(); } return Onyx.clear(); }; - const initAppAfterTransition = () => { - if (hybridApp.useNewDotSignInPage) { - setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - } - return Promise.resolve(); - }; - return new Promise((resolve) => { clearOnyxBeforeSignIn() - .then(() => Onyx.merge(ONYXKEYS.HYBRID_APP, hybridApp)) + .then(() => HybridAppActions.prepareHybridAppAfterTransitionToNewDot(hybridApp)) .then(() => Onyx.multiSet(newDotOnyxValues)) .then(() => { if (!hybridApp.shouldRemoveDelegatedAccess) { @@ -523,11 +505,9 @@ function signInAfterTransitionFromOldDot(route: Route, hybridAppSettings: string return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS); }) .then(() => { - // This data is mocked and should be returned by BeginSignUp/SignInUser API commands - setUseNewDotSignInPage(!!hybridApp.useNewDotSignInPage); - setLoggedOutFromOldDot(!!hybridApp.loggedOutFromOldDot); + HybridAppActions.setUseNewDotSignInPage(!!hybridApp.useNewDotSignInPage); + HybridAppActions.setLoggedOutFromOldDot(!!hybridApp.loggedOutFromOldDot); }) - .then(initAppAfterTransition) .catch((error) => { Log.hmmm('[HybridApp] Initialization of HybridApp has failed. Forcing transition', {error}); }) diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 03065d4e6cce..05d9e240e978 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -38,7 +38,7 @@ import {hasGlobalWorkspaceSettingsRBR} from '@libs/WorkspacesSettingsUtils'; import * as ReportActionContextMenu from '@pages/home/report/ContextMenu/ReportActionContextMenu'; import variables from '@styles/variables'; import * as App from '@userActions/App'; -import {setIsSigningIn, setOldDotSignInError, setOldDotSignInState, setShouldResetSigningInLogic} from '@userActions/HybridApp'; +import * as HybridAppActions from '@userActions/HybridApp'; import * as Link from '@userActions/Link'; import * as PaymentMethods from '@userActions/PaymentMethods'; import * as Session from '@userActions/Session'; @@ -256,21 +256,17 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr ...(NativeModules.HybridAppModule ? { action: () => { - console.log('[HybridApp] ready to switch', hybridApp); - if (hybridApp?.readyToSwitchToClassicExperience) { + if (hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && !hybridApp?.oldDotSignInError) { NativeModules.HybridAppModule.closeReactNativeApp(false, true); setInitialURL(undefined); return; } if (credentials?.autoGeneratedLogin && credentials?.autoGeneratedPassword) { - NativeModules.HybridAppModule.signInToOldDot(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); - setIsSigningIn(true); - setOldDotSignInError(null); - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.RETRYING_AFTER_FAILURE); + HybridAppActions.retryOldDotSignInAfterFailure(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); } else { signOutAndRedirectToSignIn(undefined, undefined, false); - setShouldResetSigningInLogic(true); + HybridAppActions.resetHybridAppSignInState(); } }, } @@ -306,7 +302,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr icon: Expensicons.Exit, action: () => { signOut(false); - setShouldResetSigningInLogic(true); + HybridAppActions.resetHybridAppSignInState(); }, }, ], @@ -484,7 +480,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr confirmText={translate('workspace.upgrade.completed.gotIt')} isVisible={hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FAILED_AGAIN} onConfirm={() => { - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); + HybridAppActions.setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); }} shouldShowCancelButton={false} /> diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 894ce2b7ac02..4157c51ce125 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -25,7 +25,7 @@ import {shouldUseOldApp} from '@libs/HybridApp'; import * as ValidationUtils from '@libs/ValidationUtils'; import ChangeExpensifyLoginLink from '@pages/signin/ChangeExpensifyLoginLink'; import Terms from '@pages/signin/Terms'; -import {setIsSigningIn, setNewDotSignInState, setOldDotSignInError, setOldDotSignInState, setShouldResetSigningInLogic} from '@userActions/HybridApp'; +import * as HybridAppActions from '@userActions/HybridApp'; import * as SessionActions from '@userActions/Session'; import {signOut} from '@userActions/Session'; import * as User from '@userActions/User'; @@ -81,8 +81,6 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const shouldDisableResendValidateCode = isOffline ?? account?.isLoading; const isValidateCodeFormSubmitting = AccountUtils.isValidateCodeFormSubmitting(account); - console.log('[HybridApp] hybridApp', hybridApp); - useEffect(() => { if (!(inputValidateCodeRef.current && hasError && (session?.autoAuthState === CONST.AUTO_AUTH_STATE.FAILED || account?.isLoading))) { return; @@ -162,9 +160,9 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * Trigger the reset validate code flow and ensure the 2FA input field is reset to avoid it being permanently hidden */ const resendValidateCode = () => { - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - setOldDotSignInError(null); + HybridAppActions.setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); + HybridAppActions.setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); + HybridAppActions.setOldDotSignInError(null); User.resendValidateCode(credentials?.login ?? ''); inputValidateCodeRef.current?.clear(); // Give feedback to the user to let them know the email was sent so that they don't spam the button. @@ -192,7 +190,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco Onyx.set(ONYXKEYS.SESSION, null); } SessionActions.clearSignInData(); - setShouldResetSigningInLogic(true); + HybridAppActions.resetHybridAppSignInState(); }, [clearLocalSignInData, session?.authToken]); useImperativeHandle(forwardedRef, () => ({ @@ -250,16 +248,15 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco */ const validateAndSubmitForm = useCallback(() => { if (session?.authToken) { - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.WAITING_FOR_SIGN_OUT); - setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.WAITING_FOR_SIGN_OUT); + HybridAppActions.setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.WAITING_FOR_SIGN_OUT); + HybridAppActions.setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.WAITING_FOR_SIGN_OUT); signOut(); Onyx.merge(ONYXKEYS.SESSION, { authToken: null, }).then(() => { - setIsSigningIn(false); - setOldDotSignInError(null); - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); + HybridAppActions.setOldDotSignInError(null); + HybridAppActions.setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); + HybridAppActions.setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); }); } @@ -313,7 +310,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const recoveryCodeOr2faCode = isUsingRecoveryCode ? recoveryCode : twoFactorAuthCode; - setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); + HybridAppActions.setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); const accountID = credentials?.accountID; if (accountID) { SessionActions.signInWithValidateCode(accountID, validateCode, recoveryCodeOr2faCode); @@ -426,7 +423,9 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco large style={[styles.mv3]} text={translate('common.signIn')} - isLoading={shouldUseOldApp(tryNewDot) ? isValidateCodeFormSubmitting || hybridApp?.isSigningIn : isValidateCodeFormSubmitting} + isLoading={ + shouldUseOldApp(tryNewDot) ? isValidateCodeFormSubmitting || hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED : isValidateCodeFormSubmitting + } onPress={validateAndSubmitForm} /> diff --git a/src/types/onyx/HybridApp.ts b/src/types/onyx/HybridApp.ts index 5eeb84f9a314..688ac01d05ed 100644 --- a/src/types/onyx/HybridApp.ts +++ b/src/types/onyx/HybridApp.ts @@ -3,25 +3,16 @@ import type CONST from '@src/CONST'; /** */ type HybridApp = { - /** Stores the information if HybridApp uses NewDot's sign in flow */ + /** Stores the information if HybridApp uses NewDot's sign-in flow */ useNewDotSignInPage?: boolean; - /** */ - isSigningIn?: boolean; - - /** */ + /** Stores the information about error that occurred on OldDot side during sign-in */ oldDotSignInError?: string | null; - /** */ + /** Tells if we can show AuthScreens */ readyToShowAuthScreens?: boolean; - /** */ - readyToSwitchToClassicExperience?: boolean; - - /** */ - shouldResetSigningInLogic?: boolean; - - /** States whether we transitioned from OldDot to show only certain group of screens. It should be undefined on pure NewDot. */ + /** States whether we transitioned from OldDot to show only certain group of screens */ isSingleNewDotEntry?: boolean; /** stores infromation if last log out was performed from OldDot */ @@ -30,10 +21,10 @@ type HybridApp = { /** */ shouldRemoveDelegatedAccess?: boolean; - /** */ + /** Describes current stage of NewDot sign-in */ newDotSignInState?: ValueOf; - /** */ + /** Describes current stage of OldDot sign-in */ oldDotSignInState?: ValueOf; }; From fb82b65c568e3d8ad0c39d301771b42cb2f8b058 Mon Sep 17 00:00:00 2001 From: Mateusz Rajski <60450261+mateuuszzzzz@users.noreply.github.com> Date: Thu, 28 Nov 2024 08:31:28 +0100 Subject: [PATCH 32/95] [HybridApp] Refactor `SignInPage` PR v2 (#144) * Simplify HybridApp.ts * Use early returns * Rearrange HybridApp module * Remove redundant keys * Remove unused import * Refactor remaining parts of code * Do not init with useEffect * Remove console.debug * Reduce repeating code * Remove unused import * reset sign-in logic on sign out --------- Co-authored-by: war-in --- src/libs/HybridApp.ts | 9 +-- .../Navigation/AppNavigator/AuthScreens.tsx | 2 +- src/libs/actions/HybridApp/index.ts | 73 ++++++++++++++----- src/libs/actions/Session/index.ts | 5 -- src/libs/actions/SignInRedirect.ts | 8 +- src/pages/settings/InitialSettingsPage.tsx | 4 +- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 34 +++------ 7 files changed, 80 insertions(+), 55 deletions(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 4a5dea653714..720698c2d712 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -14,16 +14,14 @@ let currentTryNewDot: OnyxEntry; Onyx.connect({ key: ONYXKEYS.HYBRID_APP, callback: (hybridApp) => { - console.debug('Last hybridApp value', {hybridApp}); - handleSignInFlow(hybridApp, currentTryNewDot); + handleChangeInHybridAppSignInFlow(hybridApp, currentTryNewDot); }, }); Onyx.connect({ key: ONYXKEYS.NVP_TRYNEWDOT, callback: (tryNewDot) => { - console.debug('Last tryNewDot value', {tryNewDot}); - handleSignInFlow(currentHybridApp, tryNewDot); + handleChangeInHybridAppSignInFlow(currentHybridApp, tryNewDot); }, }); @@ -50,7 +48,7 @@ function shouldUseOldApp(tryNewDot?: TryNewDot) { return tryNewDot?.classicRedirect.dismissed === true; } -function handleSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry) { +function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry) { if (!NativeModules.HybridAppModule) { return; } @@ -112,7 +110,6 @@ const init: Init = () => { return; } - // Setup event listeners DeviceEventEmitter.addListener(CONST.EVENTS.HYBRID_APP.ON_SIGN_IN_FINISHED, onOldDotSignInFinished); }; diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index 819e8ac29ffe..0e909b5ca614 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -1,6 +1,6 @@ import {findFocusedRoute} from '@react-navigation/native'; import React, {memo, useEffect, useMemo, useRef, useState} from 'react'; -import {NativeModules, View} from 'react-native'; +import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import Onyx, {withOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; diff --git a/src/libs/actions/HybridApp/index.ts b/src/libs/actions/HybridApp/index.ts index 8ef4dfeca492..66e3ef1f5a5a 100644 --- a/src/libs/actions/HybridApp/index.ts +++ b/src/libs/actions/HybridApp/index.ts @@ -1,49 +1,80 @@ import {NativeModules} from 'react-native'; import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; +import * as Session from '@userActions/Session'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {HybridApp} from '@src/types/onyx'; import type HybridAppSettings from './types'; +/* + * Parses initial settings passed from OldDot app + */ function parseHybridAppSettings(hybridAppSettings: string): HybridAppSettings { return JSON.parse(hybridAppSettings) as HybridAppSettings; } -function setOldDotSignInError(oldDotSignInError: string | null) { - Onyx.merge(ONYXKEYS.HYBRID_APP, {oldDotSignInError}); -} - +/* + * Changes value of `readyToShowAuthScreens` + */ function setReadyToShowAuthScreens(readyToShowAuthScreens: boolean) { Onyx.merge(ONYXKEYS.HYBRID_APP, {readyToShowAuthScreens}); } -function setUseNewDotSignInPage(useNewDotSignInPage: boolean) { - Onyx.merge(ONYXKEYS.HYBRID_APP, {useNewDotSignInPage}); -} - -function setLoggedOutFromOldDot(loggedOutFromOldDot: boolean) { - Onyx.merge(ONYXKEYS.HYBRID_APP, {loggedOutFromOldDot}); -} - +/* + * Changes NewDot sign-in state + */ function setNewDotSignInState(newDotSignInState: ValueOf) { Onyx.merge(ONYXKEYS.HYBRID_APP, {newDotSignInState}); } +/* + * Changes OldDot sign-in state + */ function setOldDotSignInState(oldDotSignInState: ValueOf) { Onyx.merge(ONYXKEYS.HYBRID_APP, {oldDotSignInState}); } -function resetHybridAppSignInState() { +/* + * Starts HybridApp sign-in flow from the beginning. + * In certain cases, it can perform sign-out if necessary + */ +function resetSignInFlow(signOut = false) { + if (signOut) { + Onyx.merge(ONYXKEYS.HYBRID_APP, { + oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.WAITING_FOR_SIGN_OUT, + newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.WAITING_FOR_SIGN_OUT, + }); + + Session.signOut(); + + Onyx.merge(ONYXKEYS.SESSION, null); + } + Onyx.merge(ONYXKEYS.HYBRID_APP, { readyToShowAuthScreens: false, + oldDotSignInError: null, + oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED, + newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED, + }); +} + +/* + * Sets proper sign-in state after sign-out on NewDot side + */ +function resetStateAfterSignOut() { + Onyx.merge(ONYXKEYS.HYBRID_APP, { useNewDotSignInPage: true, + readyToShowAuthScreens: false, oldDotSignInError: null, oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED, newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED, }); } +/* + * Starts OldDot sign-in flow + */ function startOldDotSignIn(autoGeneratedLogin: string, autoGeneratedPassword: string) { Onyx.merge(ONYXKEYS.HYBRID_APP, { oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.STARTED, @@ -52,6 +83,9 @@ function startOldDotSignIn(autoGeneratedLogin: string, autoGeneratedPassword: st NativeModules.HybridAppModule.signInToOldDot(autoGeneratedLogin, autoGeneratedPassword); } +/* + * Retries sign-in on OldDot side + */ function retryOldDotSignInAfterFailure(autoGeneratedLogin: string, autoGeneratedPassword: string) { Onyx.merge(ONYXKEYS.HYBRID_APP, { oldDotSignInError: null, @@ -61,6 +95,9 @@ function retryOldDotSignInAfterFailure(autoGeneratedLogin: string, autoGenerated NativeModules.HybridAppModule.signInToOldDot(autoGeneratedLogin, autoGeneratedPassword); } +/* + * Updates Onyx state after successful OldDot sign-in + */ function finishOldDotSignIn(errorMessage: string | null) { Onyx.merge(ONYXKEYS.HYBRID_APP, { oldDotSignInError: errorMessage, @@ -68,6 +105,9 @@ function finishOldDotSignIn(errorMessage: string | null) { }); } +/* + * Updates Onyx state after start of React Native runtime based on initial `useNewDotSignInPage` value + */ function prepareHybridAppAfterTransitionToNewDot(hybridApp: HybridApp) { if (hybridApp?.useNewDotSignInPage) { return Onyx.merge(ONYXKEYS.HYBRID_APP, { @@ -79,6 +119,7 @@ function prepareHybridAppAfterTransitionToNewDot(hybridApp: HybridApp) { }); } + // When we transition with useNewDotSignInPage === false, it means that we're already authenticated on NewDot side. return Onyx.merge(ONYXKEYS.HYBRID_APP, { ...hybridApp, readyToShowAuthScreens: true, @@ -87,15 +128,13 @@ function prepareHybridAppAfterTransitionToNewDot(hybridApp: HybridApp) { export { parseHybridAppSettings, - setOldDotSignInError, setReadyToShowAuthScreens, - setUseNewDotSignInPage, - setLoggedOutFromOldDot, setNewDotSignInState, setOldDotSignInState, - resetHybridAppSignInState, + resetSignInFlow, retryOldDotSignInAfterFailure, finishOldDotSignIn, startOldDotSignIn, prepareHybridAppAfterTransitionToNewDot, + resetStateAfterSignOut, }; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 1f0e0f5a8eec..c89d9fb76ffd 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -39,7 +39,6 @@ import * as SessionUtils from '@libs/SessionUtils'; import {clearSoundAssetsCache} from '@libs/Sound'; import Timers from '@libs/Timers'; import {hideContextMenu} from '@pages/home/report/ContextMenu/ReportActionContextMenu'; -import * as App from '@userActions/App'; import {KEYS_TO_PRESERVE, openApp} from '@userActions/App'; import {KEYS_TO_PRESERVE_DELEGATE_ACCESS} from '@userActions/Delegate'; import * as Device from '@userActions/Device'; @@ -504,10 +503,6 @@ function signInAfterTransitionFromOldDot(route: Route, hybridAppSettings: string } return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS); }) - .then(() => { - HybridAppActions.setUseNewDotSignInPage(!!hybridApp.useNewDotSignInPage); - HybridAppActions.setLoggedOutFromOldDot(!!hybridApp.loggedOutFromOldDot); - }) .catch((error) => { Log.hmmm('[HybridApp] Initialization of HybridApp has failed. Forcing transition', {error}); }) diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index 3042ddda6845..48734e79456d 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -1,8 +1,9 @@ +import {NativeModules} from 'react-native'; import Onyx from 'react-native-onyx'; import * as ErrorUtils from '@libs/ErrorUtils'; import type {OnyxKey} from '@src/ONYXKEYS'; import ONYXKEYS from '@src/ONYXKEYS'; -import {setUseNewDotSignInPage} from './HybridApp'; +import * as HybridAppActions from './HybridApp'; import * as Policy from './Policy/Policy'; let currentIsOffline: boolean | undefined; @@ -39,7 +40,10 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { // `Onyx.clear` reinitializes the Onyx instance with initial values so use `Onyx.merge` instead of `Onyx.set` Onyx.merge(ONYXKEYS.SESSION, {errors: ErrorUtils.getMicroSecondOnyxErrorWithMessage(errorMessage)}); - setUseNewDotSignInPage(true); + + if (NativeModules.HybridAppModule) { + HybridAppActions.resetStateAfterSignOut(); + } }); } diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 05d9e240e978..61206e84695d 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -266,7 +266,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr HybridAppActions.retryOldDotSignInAfterFailure(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); } else { signOutAndRedirectToSignIn(undefined, undefined, false); - HybridAppActions.resetHybridAppSignInState(); + HybridAppActions.resetStateAfterSignOut(); } }, } @@ -302,7 +302,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr icon: Expensicons.Exit, action: () => { signOut(false); - HybridAppActions.resetHybridAppSignInState(); + HybridAppActions.resetStateAfterSignOut(); }, }, ], diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 4157c51ce125..9dd5082c08ca 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -1,8 +1,8 @@ import {useIsFocused} from '@react-navigation/native'; import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react'; import type {ForwardedRef} from 'react'; -import {View} from 'react-native'; -import Onyx, {useOnyx} from 'react-native-onyx'; +import {NativeModules, View} from 'react-native'; +import {useOnyx} from 'react-native-onyx'; import Button from '@components/Button'; import SafariFormWrapper from '@components/Form/SafariFormWrapper'; import FormHelpMessage from '@components/FormHelpMessage'; @@ -27,7 +27,6 @@ import ChangeExpensifyLoginLink from '@pages/signin/ChangeExpensifyLoginLink'; import Terms from '@pages/signin/Terms'; import * as HybridAppActions from '@userActions/HybridApp'; import * as SessionActions from '@userActions/Session'; -import {signOut} from '@userActions/Session'; import * as User from '@userActions/User'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; @@ -160,9 +159,10 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * Trigger the reset validate code flow and ensure the 2FA input field is reset to avoid it being permanently hidden */ const resendValidateCode = () => { - HybridAppActions.setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - HybridAppActions.setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - HybridAppActions.setOldDotSignInError(null); + if (NativeModules.HybridAppModule) { + HybridAppActions.resetSignInFlow(); + } + User.resendValidateCode(credentials?.login ?? ''); inputValidateCodeRef.current?.clear(); // Give feedback to the user to let them know the email was sent so that they don't spam the button. @@ -184,13 +184,12 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * Clears local and Onyx sign in states */ const clearSignInData = useCallback(() => { - clearLocalSignInData(); - if (session?.authToken) { - signOut(); - Onyx.set(ONYXKEYS.SESSION, null); + if (NativeModules.HybridAppModule && session?.authToken) { + HybridAppActions.resetSignInFlow(true); } + + clearLocalSignInData(); SessionActions.clearSignInData(); - HybridAppActions.resetHybridAppSignInState(); }, [clearLocalSignInData, session?.authToken]); useImperativeHandle(forwardedRef, () => ({ @@ -247,17 +246,8 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * Check that all the form fields are valid, then trigger the submit callback */ const validateAndSubmitForm = useCallback(() => { - if (session?.authToken) { - HybridAppActions.setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.WAITING_FOR_SIGN_OUT); - HybridAppActions.setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.WAITING_FOR_SIGN_OUT); - signOut(); - Onyx.merge(ONYXKEYS.SESSION, { - authToken: null, - }).then(() => { - HybridAppActions.setOldDotSignInError(null); - HybridAppActions.setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED); - HybridAppActions.setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); - }); + if (NativeModules.HybridAppModule && session?.authToken) { + HybridAppActions.resetSignInFlow(true); } if (account?.isLoading) { From ecb93e274ae6dd3ee313c3cdc0cfa66a1f18936c Mon Sep 17 00:00:00 2001 From: war-in Date: Wed, 27 Nov 2024 15:33:07 +0100 Subject: [PATCH 33/95] fix part of signup flow --- src/pages/settings/InitialSettingsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 61206e84695d..8f97b2ebba94 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -265,7 +265,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr if (credentials?.autoGeneratedLogin && credentials?.autoGeneratedPassword) { HybridAppActions.retryOldDotSignInAfterFailure(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); } else { - signOutAndRedirectToSignIn(undefined, undefined, false); + signOutAndRedirectToSignIn(false, false, false); HybridAppActions.resetStateAfterSignOut(); } }, From 6f926fe1fca95d87f50f05165b2ee9a1762ca171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Warcho=C5=82?= <61014013+war-in@users.noreply.github.com> Date: Thu, 28 Nov 2024 14:43:15 +0100 Subject: [PATCH 34/95] [SignIn Page] New user flow (#145) Co-authored-by: war-in --- src/libs/HybridApp.ts | 2 +- src/libs/actions/HybridApp/index.ts | 14 +++++++-- src/pages/settings/InitialSettingsPage.tsx | 35 +++++++++++++++++----- src/types/modules/react-native.d.ts | 2 +- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 720698c2d712..257191af8eca 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -76,7 +76,7 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryN } Log.info('[HybridApp] Closing NewDot as sign-in to OldDot succeeded'); - NativeModules.HybridAppModule.closeReactNativeApp(false, false); + NativeModules.HybridAppModule.closeReactNativeApp(false, true); } if ( diff --git a/src/libs/actions/HybridApp/index.ts b/src/libs/actions/HybridApp/index.ts index 66e3ef1f5a5a..073cf2f3ae8a 100644 --- a/src/libs/actions/HybridApp/index.ts +++ b/src/libs/actions/HybridApp/index.ts @@ -80,19 +80,27 @@ function startOldDotSignIn(autoGeneratedLogin: string, autoGeneratedPassword: st oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.STARTED, }); - NativeModules.HybridAppModule.signInToOldDot(autoGeneratedLogin, autoGeneratedPassword); + NativeModules.HybridAppModule.signInToOldDot(autoGeneratedLogin, autoGeneratedPassword, false, '', '', '', ''); } /* * Retries sign-in on OldDot side */ -function retryOldDotSignInAfterFailure(autoGeneratedLogin: string, autoGeneratedPassword: string) { +function retryOldDotSignInAfterFailure( + autoGeneratedLogin: string, + autoGeneratedPassword: string, + isNewUser: boolean, + authToken: string, + encryptedAuthToken: string, + email: string, + policyID: string, +) { Onyx.merge(ONYXKEYS.HYBRID_APP, { oldDotSignInError: null, oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.RETRYING_AFTER_FAILURE, }); - NativeModules.HybridAppModule.signInToOldDot(autoGeneratedLogin, autoGeneratedPassword); + NativeModules.HybridAppModule.signInToOldDot(autoGeneratedLogin, autoGeneratedPassword, isNewUser, authToken, encryptedAuthToken, email, policyID); } /* diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 8f97b2ebba94..e8ca15a45659 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -32,6 +32,7 @@ import useWaitForNavigation from '@hooks/useWaitForNavigation'; import {resetExitSurveyForm} from '@libs/actions/ExitSurvey'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import Navigation from '@libs/Navigation/Navigation'; +import {getCurrentUserEmail} from '@libs/Network/NetworkStore'; import * as SubscriptionUtils from '@libs/SubscriptionUtils'; import * as UserUtils from '@libs/UserUtils'; import {hasGlobalWorkspaceSettingsRBR} from '@libs/WorkspacesSettingsUtils'; @@ -42,7 +43,6 @@ import * as HybridAppActions from '@userActions/HybridApp'; import * as Link from '@userActions/Link'; import * as PaymentMethods from '@userActions/PaymentMethods'; import * as Session from '@userActions/Session'; -import {signOutAndRedirectToSignIn} from '@userActions/Session'; import * as Wallet from '@userActions/Wallet'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; @@ -91,6 +91,8 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); + const [session] = useOnyx(ONYXKEYS.SESSION); + const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID); const network = useNetwork(); const theme = useTheme(); @@ -262,12 +264,15 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr return; } - if (credentials?.autoGeneratedLogin && credentials?.autoGeneratedPassword) { - HybridAppActions.retryOldDotSignInAfterFailure(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); - } else { - signOutAndRedirectToSignIn(false, false, false); - HybridAppActions.resetStateAfterSignOut(); - } + HybridAppActions.retryOldDotSignInAfterFailure( + credentials?.autoGeneratedLogin ?? '', + credentials?.autoGeneratedPassword ?? '', + !credentials?.autoGeneratedLogin, + session?.authToken ?? '', + session?.encryptedAuthToken ?? '', + getCurrentUserEmail() ?? '', + activePolicyID ?? '', + ); }, } : { @@ -307,7 +312,21 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr }, ], }; - }, [styles.pt4, styles.popoverMenuIcon, hybridApp, theme.spinner, credentials?.autoGeneratedLogin, credentials?.autoGeneratedPassword, setInitialURL, signOut, shouldOpenBookACall]); + }, [ + styles.pt4, + styles.popoverMenuIcon, + hybridApp?.oldDotSignInState, + hybridApp?.oldDotSignInError, + theme.spinner, + credentials?.autoGeneratedLogin, + credentials?.autoGeneratedPassword, + session?.authToken, + session?.encryptedAuthToken, + activePolicyID, + setInitialURL, + shouldOpenBookACall, + signOut, + ]); /** * Retuns JSX.Element with menu items diff --git a/src/types/modules/react-native.d.ts b/src/types/modules/react-native.d.ts index d2603de1edf3..7d083c07076b 100644 --- a/src/types/modules/react-native.d.ts +++ b/src/types/modules/react-native.d.ts @@ -9,7 +9,7 @@ type HybridAppModule = { closeReactNativeApp: (shouldSignOut: boolean, shouldSetNVP: boolean) => void; completeOnboarding: (status: boolean) => void; switchAccount: (newDotCurrentAccount: string) => void; - signInToOldDot: (autoGeneratedLogin: string, autoGeneratedPassword: string) => void; + signInToOldDot: (autoGeneratedLogin: string, autoGeneratedPassword: string, isNewUser: boolean, authToken: string, encryptedAuthToken: string, email: string, policyID: string) => void; signOutFromOldDot: () => void; exitApp: () => void; }; From 90c0954bcb93621a2a29e8978bc86de65e861137 Mon Sep 17 00:00:00 2001 From: war-in Date: Mon, 2 Dec 2024 13:53:31 +0100 Subject: [PATCH 35/95] fix isSingleNewDotEntry logic (travel feature) --- src/libs/Navigation/AppNavigator/index.native.tsx | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/index.native.tsx b/src/libs/Navigation/AppNavigator/index.native.tsx index bc95c4531756..16c867afb622 100644 --- a/src/libs/Navigation/AppNavigator/index.native.tsx +++ b/src/libs/Navigation/AppNavigator/index.native.tsx @@ -21,25 +21,16 @@ function AppNavigator({authenticated}: AppNavigatorProps) { const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); - /** - * kiedy chcemy pokazać auth screens: - * - logujemy do OD - * - nie chcemy wcale - * - logujemy do ND - * - gdy jesteśmy authenticated (po odpaleniu signInToOldDot) - * - przechodzimy z OD do ND - * - od razu o ile jesteśmy zalogowani, ale powinniśmy być zawsze - */ const shouldShowAuthScreens = useMemo(() => { if (!NativeModules.HybridAppModule) { return authenticated; } - if (shouldUseOldApp(tryNewDot)) { + if (shouldUseOldApp(tryNewDot) && !hybridApp?.isSingleNewDotEntry) { return false; } return authenticated && (!hybridApp?.useNewDotSignInPage || hybridApp?.readyToShowAuthScreens); - }, [authenticated, hybridApp?.readyToShowAuthScreens, tryNewDot, hybridApp?.useNewDotSignInPage]); + }, [tryNewDot, hybridApp?.isSingleNewDotEntry, hybridApp?.useNewDotSignInPage, hybridApp?.readyToShowAuthScreens, authenticated]); useEffect(() => { if (!NativeModules.HybridAppModule || !initialURL || !shouldShowAuthScreens) { From 9cfbaf5bb3e2f8c63f65885b08a637978473f2f3 Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Thu, 5 Dec 2024 15:54:13 +0100 Subject: [PATCH 36/95] Rename argument --- src/libs/actions/Session/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 9cc89a8d896b..a69fe0a75a88 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -212,12 +212,12 @@ function hasAuthToken(): boolean { return !!session.authToken; } -function signOutAndRedirectToSignIn(shouldResetToHome?: boolean, shouldStashSession?: boolean, killHybridApp = true) { +function signOutAndRedirectToSignIn(shouldResetToHome?: boolean, shouldStashSession?: boolean, shouldSignOutFromOldDot = true) { Log.info('Redirecting to Sign In because signOut() was called'); hideContextMenu(false); if (!isAnonymousUser()) { // In the HybridApp, we want the Old Dot to handle the sign out process - if (NativeModules.HybridAppModule && killHybridApp) { + if (NativeModules.HybridAppModule && shouldSignOutFromOldDot) { NativeModules.HybridAppModule.signOutFromOldDot(); } // We'll only call signOut if we're not stashing the session and this is not a supportal session, From 85eddb238e7e5965af19d5d02955ec366f437230 Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Thu, 5 Dec 2024 15:56:55 +0100 Subject: [PATCH 37/95] Change function name --- src/components/InitialURLContextProvider.tsx | 4 ++-- src/libs/actions/Session/index.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index b89a842d1420..61f18de4d034 100644 --- a/src/components/InitialURLContextProvider.tsx +++ b/src/components/InitialURLContextProvider.tsx @@ -3,7 +3,7 @@ import type {ReactNode} from 'react'; import {Linking} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; -import {signInAfterTransitionFromOldDot} from '@libs/actions/Session'; +import {setupNewDotAfterTransitionFromOldDot} from '@libs/actions/Session'; import Navigation from '@navigation/Navigation'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -53,7 +53,7 @@ function InitialURLContextProvider({children, url, hybridAppSettings}: InitialUR } if (url && hybridAppSettings) { - signInAfterTransitionFromOldDot(url, hybridAppSettings).then((route) => { + setupNewDotAfterTransitionFromOldDot(url, hybridAppSettings).then((route) => { setInitialURL(route); setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); }); diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index a69fe0a75a88..7c09abc55951 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -488,7 +488,7 @@ function signUpUser() { API.write(WRITE_COMMANDS.SIGN_UP_USER, params, {optimisticData, successData, failureData}); } -function signInAfterTransitionFromOldDot(route: Route, hybridAppSettings: string) { +function setupNewDotAfterTransitionFromOldDot(route: Route, hybridAppSettings: string) { const parsedHybridAppSettings = HybridAppActions.parseHybridAppSettings(hybridAppSettings); const {initialOnyxValues} = parsedHybridAppSettings; const {hybridApp, ...newDotOnyxValues} = initialOnyxValues; @@ -1165,5 +1165,5 @@ export { isSupportAuthToken, hasStashedSession, signUpUser, - signInAfterTransitionFromOldDot, + setupNewDotAfterTransitionFromOldDot, }; From 68ed5168bb4eaac39b13ed1fe66cb8c180867884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Warcho=C5=82?= <61014013+war-in@users.noreply.github.com> Date: Mon, 9 Dec 2024 13:41:39 +0100 Subject: [PATCH 38/95] Dont sign in in old dot (#150) * wip * wip * remove comment * clean * remove unused parameters and fix sign up flow * block sign in logic when OD sign-in was performed * simplify blocking logic * fix crash when switching apps * Fix bug where OpenApp is called after opening app from background --------- Co-authored-by: war-in Co-authored-by: Mateusz Rajski --- src/App.tsx | 2 - src/CONST.ts | 3 - src/components/InitialURLContextProvider.tsx | 19 +++- src/libs/API/types.ts | 4 +- src/libs/HybridApp.ts | 103 +++++++----------- .../Navigation/AppNavigator/PublicScreens.tsx | 1 - .../Navigation/AppNavigator/index.native.tsx | 7 +- src/libs/actions/HybridApp/index.ts | 93 +--------------- src/libs/actions/Session/index.ts | 36 ++++-- src/libs/actions/SignInRedirect.ts | 6 - src/pages/settings/InitialSettingsPage.tsx | 72 +----------- src/pages/signin/SignUpWelcomeForm.tsx | 4 +- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 21 +--- src/types/modules/react-native.d.ts | 2 +- src/types/onyx/HybridApp.ts | 8 +- 15 files changed, 105 insertions(+), 276 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 0f09216a3fe6..34d4acb6c4d6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -36,7 +36,6 @@ import Expensify from './Expensify'; import useDefaultDragAndDrop from './hooks/useDefaultDragAndDrop'; import {ReportIDsContextProvider} from './hooks/useReportIDs'; import OnyxUpdateManager from './libs/actions/OnyxUpdateManager'; -import HybridApp from './libs/HybridApp'; import {ReportAttachmentsProvider} from './pages/home/report/ReportAttachmentsContext'; import type {Route} from './ROUTES'; import {SplashScreenStateContextProvider} from './SplashScreenStateContext'; @@ -65,7 +64,6 @@ const StrictModeWrapper = CONFIG.USE_REACT_STRICT_MODE_IN_DEV ? React.StrictMode function App({url, hybridAppSettings}: AppProps) { useDefaultDragAndDrop(); OnyxUpdateManager(); - HybridApp.init(); return ( diff --git a/src/CONST.ts b/src/CONST.ts index 6964fd99fd53..5cd9499d0e0f 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -6299,9 +6299,6 @@ const CONST = { NOT_STARTED: 'notStarted', STARTED: 'started', FINISHED: 'finished', - WAITING_FOR_SIGN_OUT: 'waitingForSignOut', - RETRYING_AFTER_FAILURE: 'retryingAfterFailure', - FAILED_AGAIN: 'failedAgain', }, CSV_IMPORT_COLUMNS: { diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index 61f18de4d034..d6162231c694 100644 --- a/src/components/InitialURLContextProvider.tsx +++ b/src/components/InitialURLContextProvider.tsx @@ -1,4 +1,4 @@ -import React, {createContext, useEffect, useMemo, useState} from 'react'; +import React, {createContext, useEffect, useMemo, useRef, useState} from 'react'; import type {ReactNode} from 'react'; import {Linking} from 'react-native'; import {useOnyx} from 'react-native-onyx'; @@ -9,6 +9,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; import {useSplashScreenStateContext} from '@src/SplashScreenStateContext'; +import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; type InitialUrlContextType = { initialURL: Route | undefined; @@ -35,6 +36,9 @@ function InitialURLContextProvider({children, url, hybridAppSettings}: InitialUR const [initialURL, setInitialURL] = useState | undefined>(url); const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH); const {splashScreenState, setSplashScreenState} = useSplashScreenStateContext(); + const [tryNewDot, tryNewDotMetadata] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); + // We use `setupCalled` ref to guarantee that `signInAfterTransitionFromOldDot` is called once. + const setupCalled = useRef(false); useEffect(() => { if (url !== CONST.HYBRID_APP.REORDERING_REACT_NATIVE_ACTIVITY_TO_FRONT) { @@ -53,16 +57,19 @@ function InitialURLContextProvider({children, url, hybridAppSettings}: InitialUR } if (url && hybridAppSettings) { - setupNewDotAfterTransitionFromOldDot(url, hybridAppSettings).then((route) => { - setInitialURL(route); - setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); - }); + if (!isLoadingOnyxValue(tryNewDotMetadata) && !setupCalled.current) { + setupCalled.current = true; + setupNewDotAfterTransitionFromOldDot(url, hybridAppSettings, tryNewDot).then((route) => { + setInitialURL(route); + setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); + }); + } return; } Linking.getInitialURL().then((initURL) => { setInitialURL(initURL as Route); }); - }, [hybridAppSettings, setSplashScreenState, url]); + }, [hybridAppSettings, setSplashScreenState, tryNewDot, tryNewDotMetadata, url]); const initialUrlContext = useMemo( () => ({ diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index c0485fcbd1b5..a5014c67091d 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -306,7 +306,6 @@ const WRITE_COMMANDS = { TRANSACTION_MERGE: 'Transaction_Merge', RESOLVE_DUPLICATES: 'ResolveDuplicates', UPDATE_SUBSCRIPTION_TYPE: 'UpdateSubscriptionType', - SIGN_UP_USER: 'SignUpUser', UPDATE_SUBSCRIPTION_AUTO_RENEW: 'UpdateSubscriptionAutoRenew', UPDATE_SUBSCRIPTION_ADD_NEW_USERS_AUTOMATICALLY: 'UpdateSubscriptionAddNewUsersAutomatically', UPDATE_SUBSCRIPTION_SIZE: 'UpdateSubscriptionSize', @@ -756,7 +755,6 @@ type WriteCommandParameters = { [WRITE_COMMANDS.TRANSACTION_MERGE]: Parameters.TransactionMergeParams; [WRITE_COMMANDS.RESOLVE_DUPLICATES]: Parameters.ResolveDuplicatesParams; [WRITE_COMMANDS.UPDATE_SUBSCRIPTION_TYPE]: Parameters.UpdateSubscriptionTypeParams; - [WRITE_COMMANDS.SIGN_UP_USER]: Parameters.SignUpUserParams; [WRITE_COMMANDS.UPDATE_SUBSCRIPTION_AUTO_RENEW]: Parameters.UpdateSubscriptionAutoRenewParams; [WRITE_COMMANDS.UPDATE_SUBSCRIPTION_ADD_NEW_USERS_AUTOMATICALLY]: Parameters.UpdateSubscriptionAddNewUsersAutomaticallyParams; [WRITE_COMMANDS.UPDATE_SUBSCRIPTION_SIZE]: Parameters.UpdateSubscriptionSizeParams; @@ -1030,6 +1028,7 @@ const SIDE_EFFECT_REQUEST_COMMANDS = { COMPLETE_HYBRID_APP_ONBOARDING: 'CompleteHybridAppOnboarding', CONNECT_POLICY_TO_QUICKBOOKS_DESKTOP: 'ConnectPolicyToQuickbooksDesktop', SIGN_IN_USER: 'SigninUser', + SIGN_UP_USER: 'SignUpUser', // PayMoneyRequestOnSearch only works online (pattern C) and we need to play the success sound only when the request is successful PAY_MONEY_REQUEST_ON_SEARCH: 'PayMoneyRequestOnSearch', @@ -1054,6 +1053,7 @@ type SideEffectRequestCommandParameters = { [SIDE_EFFECT_REQUEST_COMMANDS.COMPLETE_HYBRID_APP_ONBOARDING]: EmptyObject; [SIDE_EFFECT_REQUEST_COMMANDS.CONNECT_POLICY_TO_QUICKBOOKS_DESKTOP]: Parameters.ConnectPolicyToQuickBooksDesktopParams; [SIDE_EFFECT_REQUEST_COMMANDS.SIGN_IN_USER]: SignInUserParams; + [SIDE_EFFECT_REQUEST_COMMANDS.SIGN_UP_USER]: Parameters.SignUpUserParams; [SIDE_EFFECT_REQUEST_COMMANDS.PAY_MONEY_REQUEST_ON_SEARCH]: Parameters.PayMoneyRequestOnSearchParams; }; diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 257191af8eca..99843665f1d7 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -1,27 +1,36 @@ -import {DeviceEventEmitter, NativeModules} from 'react-native'; +import {NativeModules} from 'react-native'; import Onyx from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Credentials, HybridApp, Session, TryNewDot} from '@src/types/onyx'; import * as HybridAppActions from './actions/HybridApp'; -import type {Init} from './ActiveClientManager/types'; import Log from './Log'; +import {getCurrentUserEmail} from './Network/NetworkStore'; let currentHybridApp: OnyxEntry; let currentTryNewDot: OnyxEntry; +let currentCredentials: OnyxEntry; Onyx.connect({ key: ONYXKEYS.HYBRID_APP, callback: (hybridApp) => { - handleChangeInHybridAppSignInFlow(hybridApp, currentTryNewDot); + handleChangeInHybridAppSignInFlow(hybridApp, currentTryNewDot, currentCredentials); }, }); Onyx.connect({ key: ONYXKEYS.NVP_TRYNEWDOT, callback: (tryNewDot) => { - handleChangeInHybridAppSignInFlow(currentHybridApp, tryNewDot); + handleChangeInHybridAppSignInFlow(currentHybridApp, tryNewDot, currentCredentials); + }, +}); + +Onyx.connect({ + key: ONYXKEYS.CREDENTIALS, + callback: (credentials) => { + currentCredentials = credentials; + handleChangeInHybridAppSignInFlow(currentHybridApp, currentTryNewDot, credentials); }, }); @@ -36,11 +45,11 @@ Onyx.connect({ }, }); -let credentials: OnyxEntry; +let activePolicyID: OnyxEntry; Onyx.connect({ - key: ONYXKEYS.CREDENTIALS, - callback: (newCredentials) => { - credentials = newCredentials; + key: ONYXKEYS.NVP_ACTIVE_POLICY_ID, + callback: (newActivePolicyID) => { + activePolicyID = newActivePolicyID; }, }); @@ -48,71 +57,39 @@ function shouldUseOldApp(tryNewDot?: TryNewDot) { return tryNewDot?.classicRedirect.dismissed === true; } -function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry) { +function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry, credentials: OnyxEntry) { if (!NativeModules.HybridAppModule) { return; } - if (currentHybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.RETRYING_AFTER_FAILURE && hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED) { - if (hybridApp?.oldDotSignInError) { - Log.info('[HybridApp] Unable to open OldDot. Sign-in has failed again'); - HybridAppActions.setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FAILED_AGAIN); - return; - } - - Log.info('[HybridApp] Closing NewDot as retrying sign-in to OldDot succeeded'); - NativeModules.HybridAppModule.closeReactNativeApp(false, true); - } - - if ( - currentHybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED && - hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && - tryNewDot !== undefined && - shouldUseOldApp(tryNewDot) - ) { - if (hybridApp?.oldDotSignInError) { - Log.info('[HybridApp] Unable to open OldDot. Sign-in has failed'); - return; - } - - Log.info('[HybridApp] Closing NewDot as sign-in to OldDot succeeded'); - NativeModules.HybridAppModule.closeReactNativeApp(false, true); + if (!hybridApp?.useNewDotSignInPage) { + currentHybridApp = hybridApp; + currentTryNewDot = tryNewDot; + return; } - if ( - hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && - hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED && - credentials?.autoGeneratedLogin && - credentials?.autoGeneratedPassword && - tryNewDot !== undefined - ) { - if (!shouldUseOldApp(tryNewDot)) { - Log.info('[HybridApp] The user should see NewDot. There is no need to block the user on the `SignInPage` until the sign-in process is completed on the OldDot side.'); - HybridAppActions.setReadyToShowAuthScreens(true); - } - + if (hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && tryNewDot !== undefined && !!credentials?.autoGeneratedLogin && !!credentials?.autoGeneratedPassword) { Log.info(`[HybridApp] Performing sign-in${shouldUseOldApp(tryNewDot) ? '' : ' (in background)'} on OldDot side`); - HybridAppActions.startOldDotSignIn(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); + NativeModules.HybridAppModule.signInToOldDot( + credentials.autoGeneratedLogin, + credentials.autoGeneratedPassword, + currentSession?.authToken ?? '', + currentSession?.encryptedAuthToken ?? '', + getCurrentUserEmail() ?? '', + activePolicyID ?? '', + ); + HybridAppActions.setUseNewDotSignInPage(false).then(() => { + if (shouldUseOldApp(tryNewDot)) { + NativeModules.HybridAppModule.closeReactNativeApp(false, false); + } else { + Log.info('[HybridApp] The user should see NewDot. There is no need to block the user on the `SignInPage` until the sign-in process is completed on the OldDot side.'); + HybridAppActions.setReadyToShowAuthScreens(true); + } + }); } currentHybridApp = hybridApp; currentTryNewDot = tryNewDot; } -function onOldDotSignInFinished(data: string) { - const eventData = JSON.parse(data) as {errorMessage: string}; - Log.info(`[HybridApp] onSignInFinished event received`, true, {eventData}); - HybridAppActions.finishOldDotSignIn(eventData.errorMessage); -} - -const init: Init = () => { - if (!NativeModules.HybridAppModule) { - return; - } - - DeviceEventEmitter.addListener(CONST.EVENTS.HYBRID_APP.ON_SIGN_IN_FINISHED, onOldDotSignInFinished); -}; - -export default {init}; - -export {shouldUseOldApp}; +export default {shouldUseOldApp}; diff --git a/src/libs/Navigation/AppNavigator/PublicScreens.tsx b/src/libs/Navigation/AppNavigator/PublicScreens.tsx index fa880a5246f2..3a4e867e8e84 100644 --- a/src/libs/Navigation/AppNavigator/PublicScreens.tsx +++ b/src/libs/Navigation/AppNavigator/PublicScreens.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import {NativeModules} from 'react-native'; import createPlatformStackNavigator from '@libs/Navigation/PlatformStackNavigation/createPlatformStackNavigator'; import type {PublicScreensParamList} from '@navigation/types'; import ConnectionCompletePage from '@pages/ConnectionCompletePage'; diff --git a/src/libs/Navigation/AppNavigator/index.native.tsx b/src/libs/Navigation/AppNavigator/index.native.tsx index 16c867afb622..48f1ef2f2dd5 100644 --- a/src/libs/Navigation/AppNavigator/index.native.tsx +++ b/src/libs/Navigation/AppNavigator/index.native.tsx @@ -2,6 +2,7 @@ import React, {memo, useContext, useEffect, useMemo} from 'react'; import {NativeModules} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import {InitialURLContext} from '@components/InitialURLContextProvider'; +import HybridApp from '@libs/HybridApp'; import Navigation from '@libs/Navigation/Navigation'; import ONYXKEYS from '@src/ONYXKEYS'; import type {TryNewDot} from '@src/types/onyx'; @@ -12,10 +13,6 @@ type AppNavigatorProps = { authenticated: boolean; }; -function shouldUseOldApp(tryNewDot?: TryNewDot) { - return tryNewDot?.classicRedirect.dismissed === true; -} - function AppNavigator({authenticated}: AppNavigatorProps) { const {initialURL, setInitialURL} = useContext(InitialURLContext); const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); @@ -25,7 +22,7 @@ function AppNavigator({authenticated}: AppNavigatorProps) { if (!NativeModules.HybridAppModule) { return authenticated; } - if (shouldUseOldApp(tryNewDot) && !hybridApp?.isSingleNewDotEntry) { + if (HybridApp.shouldUseOldApp(tryNewDot) && !hybridApp?.isSingleNewDotEntry) { return false; } diff --git a/src/libs/actions/HybridApp/index.ts b/src/libs/actions/HybridApp/index.ts index 073cf2f3ae8a..0bcda22b8b2c 100644 --- a/src/libs/actions/HybridApp/index.ts +++ b/src/libs/actions/HybridApp/index.ts @@ -1,7 +1,5 @@ -import {NativeModules} from 'react-native'; import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; -import * as Session from '@userActions/Session'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {HybridApp} from '@src/types/onyx'; @@ -28,88 +26,18 @@ function setNewDotSignInState(newDotSignInState: ValueOf) { - Onyx.merge(ONYXKEYS.HYBRID_APP, {oldDotSignInState}); +function setUseNewDotSignInPage(useNewDotSignInPage: boolean) { + return Onyx.merge(ONYXKEYS.HYBRID_APP, {useNewDotSignInPage}); } /* * Starts HybridApp sign-in flow from the beginning. - * In certain cases, it can perform sign-out if necessary */ -function resetSignInFlow(signOut = false) { - if (signOut) { - Onyx.merge(ONYXKEYS.HYBRID_APP, { - oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.WAITING_FOR_SIGN_OUT, - newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.WAITING_FOR_SIGN_OUT, - }); - - Session.signOut(); - - Onyx.merge(ONYXKEYS.SESSION, null); - } - +function resetSignInFlow() { Onyx.merge(ONYXKEYS.HYBRID_APP, { readyToShowAuthScreens: false, - oldDotSignInError: null, - oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED, newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED, - }); -} - -/* - * Sets proper sign-in state after sign-out on NewDot side - */ -function resetStateAfterSignOut() { - Onyx.merge(ONYXKEYS.HYBRID_APP, { useNewDotSignInPage: true, - readyToShowAuthScreens: false, - oldDotSignInError: null, - oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED, - newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED, - }); -} - -/* - * Starts OldDot sign-in flow - */ -function startOldDotSignIn(autoGeneratedLogin: string, autoGeneratedPassword: string) { - Onyx.merge(ONYXKEYS.HYBRID_APP, { - oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.STARTED, - }); - - NativeModules.HybridAppModule.signInToOldDot(autoGeneratedLogin, autoGeneratedPassword, false, '', '', '', ''); -} - -/* - * Retries sign-in on OldDot side - */ -function retryOldDotSignInAfterFailure( - autoGeneratedLogin: string, - autoGeneratedPassword: string, - isNewUser: boolean, - authToken: string, - encryptedAuthToken: string, - email: string, - policyID: string, -) { - Onyx.merge(ONYXKEYS.HYBRID_APP, { - oldDotSignInError: null, - oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.RETRYING_AFTER_FAILURE, - }); - - NativeModules.HybridAppModule.signInToOldDot(autoGeneratedLogin, autoGeneratedPassword, isNewUser, authToken, encryptedAuthToken, email, policyID); -} - -/* - * Updates Onyx state after successful OldDot sign-in - */ -function finishOldDotSignIn(errorMessage: string | null) { - Onyx.merge(ONYXKEYS.HYBRID_APP, { - oldDotSignInError: errorMessage, - oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED, }); } @@ -121,8 +49,6 @@ function prepareHybridAppAfterTransitionToNewDot(hybridApp: HybridApp) { return Onyx.merge(ONYXKEYS.HYBRID_APP, { ...hybridApp, readyToShowAuthScreens: false, - oldDotSignInError: null, - oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED, newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED, }); } @@ -134,15 +60,4 @@ function prepareHybridAppAfterTransitionToNewDot(hybridApp: HybridApp) { }); } -export { - parseHybridAppSettings, - setReadyToShowAuthScreens, - setNewDotSignInState, - setOldDotSignInState, - resetSignInFlow, - retryOldDotSignInAfterFailure, - finishOldDotSignIn, - startOldDotSignIn, - prepareHybridAppAfterTransitionToNewDot, - resetStateAfterSignOut, -}; +export {parseHybridAppSettings, setReadyToShowAuthScreens, setNewDotSignInState, resetSignInFlow, prepareHybridAppAfterTransitionToNewDot, setUseNewDotSignInPage}; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 7c09abc55951..5c71e562c1cb 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -37,6 +37,7 @@ import NetworkConnection from '@libs/NetworkConnection'; import * as Pusher from '@libs/Pusher/pusher'; import * as ReportUtils from '@libs/ReportUtils'; import * as SessionUtils from '@libs/SessionUtils'; +import {resetDidUserLogInDuringSession} from '@libs/SessionUtils'; import {clearSoundAssetsCache} from '@libs/Sound'; import Timers from '@libs/Timers'; import {hideContextMenu} from '@pages/home/report/ContextMenu/ReportActionContextMenu'; @@ -54,6 +55,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {HybridAppRoute, Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; +import type {TryNewDot} from '@src/types/onyx'; import type Credentials from '@src/types/onyx/Credentials'; import type Session from '@src/types/onyx/Session'; import type {AutoAuthState} from '@src/types/onyx/Session'; @@ -485,10 +487,16 @@ function signUpUser() { const params: SignUpUserParams = {email: credentials.login, preferredLocale}; - API.write(WRITE_COMMANDS.SIGN_UP_USER, params, {optimisticData, successData, failureData}); + // eslint-disable-next-line rulesdir/no-api-side-effects-method + API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.SIGN_UP_USER, params, {optimisticData, successData, failureData}).then((response) => { + if (!response) { + return; + } + Onyx.merge(ONYXKEYS.NVP_TRYNEWDOT, {classicRedirect: {dismissed: !response.tryNewDot}}); + }); } -function setupNewDotAfterTransitionFromOldDot(route: Route, hybridAppSettings: string) { +function setupNewDotAfterTransitionFromOldDot(route: Route, hybridAppSettings: string, tryNewDot: TryNewDot | undefined) { const parsedHybridAppSettings = HybridAppActions.parseHybridAppSettings(hybridAppSettings); const {initialOnyxValues} = parsedHybridAppSettings; const {hybridApp, ...newDotOnyxValues} = initialOnyxValues; @@ -501,16 +509,28 @@ function setupNewDotAfterTransitionFromOldDot(route: Route, hybridAppSettings: s return Onyx.clear(); }; + const resetDidUserLoginDuringSessionIfNeeded = () => { + if (newDotOnyxValues.nvp_tryNewDot === undefined || tryNewDot?.classicRedirect.dismissed !== true) { + return Promise.resolve(); + } + + Log.info("[HybridApp] OpenApp hasn't been called yet. Calling `resetDidUserLogInDuringSession`"); + resetDidUserLogInDuringSession(); + }; + + const handleDelegateAccess = () => { + if (!hybridApp.shouldRemoveDelegatedAccess) { + return; + } + return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS); + }; + return new Promise((resolve) => { clearOnyxBeforeSignIn() .then(() => HybridAppActions.prepareHybridAppAfterTransitionToNewDot(hybridApp)) + .then(resetDidUserLoginDuringSessionIfNeeded) .then(() => Onyx.multiSet(newDotOnyxValues)) - .then(() => { - if (!hybridApp.shouldRemoveDelegatedAccess) { - return; - } - return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS); - }) + .then(handleDelegateAccess) .catch((error) => { Log.hmmm('[HybridApp] Initialization of HybridApp has failed. Forcing transition', {error}); }) diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index ca4cf7529d47..2c81fe01fb0f 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -1,9 +1,7 @@ -import {NativeModules} from 'react-native'; import Onyx from 'react-native-onyx'; import * as ErrorUtils from '@libs/ErrorUtils'; import type {OnyxKey} from '@src/ONYXKEYS'; import ONYXKEYS from '@src/ONYXKEYS'; -import * as HybridAppActions from './HybridApp'; import * as Policy from './Policy/Policy'; let currentIsOffline: boolean | undefined; @@ -41,10 +39,6 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { // `Onyx.clear` reinitializes the Onyx instance with initial values so use `Onyx.merge` instead of `Onyx.set` Onyx.merge(ONYXKEYS.SESSION, {errors: ErrorUtils.getMicroSecondOnyxErrorWithMessage(errorMessage)}); - - if (NativeModules.HybridAppModule) { - HybridAppActions.resetStateAfterSignOut(); - } }); } diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 6d1a557890fe..07071736cd10 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -1,9 +1,8 @@ import {useRoute} from '@react-navigation/native'; import React, {useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState} from 'react'; -import type {ReactNode} from 'react'; // eslint-disable-next-line no-restricted-imports import type {GestureResponderEvent, ScrollView as RNScrollView, ScrollViewProps, StyleProp, ViewStyle} from 'react-native'; -import {ActivityIndicator, NativeModules, View} from 'react-native'; +import {NativeModules, View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import AccountSwitcher from '@components/AccountSwitcher'; @@ -33,7 +32,6 @@ import useWaitForNavigation from '@hooks/useWaitForNavigation'; import {resetExitSurveyForm} from '@libs/actions/ExitSurvey'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import Navigation from '@libs/Navigation/Navigation'; -import {getCurrentUserEmail} from '@libs/Network/NetworkStore'; import * as SubscriptionUtils from '@libs/SubscriptionUtils'; import * as UserUtils from '@libs/UserUtils'; import {hasGlobalWorkspaceSettingsRBR} from '@libs/WorkspacesSettingsUtils'; @@ -74,9 +72,6 @@ type MenuData = { iconRight?: IconAsset; badgeText?: string; badgeStyle?: ViewStyle; - shouldShowRightComponent?: boolean; - rightComponent?: ReactNode; - disabled?: boolean; }; type Menu = {sectionStyle: StyleProp; sectionTranslationKey: TranslationPaths; items: MenuData[]}; @@ -89,11 +84,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST); const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS); - const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); - const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); - const [session] = useOnyx(ONYXKEYS.SESSION); - const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID); const [isActingAsDelegate] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => !!account?.delegatedAccess?.delegate}); @@ -250,34 +241,11 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr { translationKey: 'exitSurvey.goToExpensifyClassic', icon: Expensicons.ExpensifyLogoNew, - shouldShowRightComponent: hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.RETRYING_AFTER_FAILURE, - disabled: hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.RETRYING_AFTER_FAILURE, - rightComponent: ( - - - - ), ...(NativeModules.HybridAppModule ? { action: () => { - if (hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && !hybridApp?.oldDotSignInError) { - NativeModules.HybridAppModule.closeReactNativeApp(false, true); - setInitialURL(undefined); - return; - } - - HybridAppActions.retryOldDotSignInAfterFailure( - credentials?.autoGeneratedLogin ?? '', - credentials?.autoGeneratedPassword ?? '', - !credentials?.autoGeneratedLogin, - session?.authToken ?? '', - session?.encryptedAuthToken ?? '', - getCurrentUserEmail() ?? '', - activePolicyID ?? '', - ); + NativeModules.HybridAppModule.closeReactNativeApp(false, true); + setInitialURL(undefined); }, } : { @@ -316,27 +284,12 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr icon: Expensicons.Exit, action: () => { signOut(false); - HybridAppActions.resetStateAfterSignOut(); + HybridAppActions.resetSignInFlow(); }, }, ], }; - }, [ - styles.pt4, - styles.popoverMenuIcon, - hybridApp?.oldDotSignInState, - hybridApp?.oldDotSignInError, - theme.spinner, - credentials?.autoGeneratedLogin, - credentials?.autoGeneratedPassword, - session?.authToken, - session?.encryptedAuthToken, - activePolicyID, - setInitialURL, - shouldOpenBookACall, - signOut, - isActingAsDelegate - ]); + }, [styles.pt4, setInitialURL, shouldOpenBookACall, signOut, isActingAsDelegate]); /** * Retuns JSX.Element with menu items @@ -373,7 +326,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr title={keyTitle} icon={item.icon} iconType={item.iconType} - disabled={isExecuting || item.disabled} + disabled={isExecuting} onPress={singleExecution(() => { if (item.action) { item.action(); @@ -399,8 +352,6 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr !!item.routeName && !!(activeCentralPaneRoute.name.toLowerCase().replaceAll('_', '') === item.routeName.toLowerCase().replaceAll('/', '')) } - shouldShowRightComponent={item.shouldShowRightComponent} - rightComponent={item.rightComponent} iconRight={item.iconRight} shouldShowRightIcon={item.shouldShowRightIcon} shouldIconUseAutoWidthStyle @@ -503,17 +454,6 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr onConfirm={() => signOut(true)} onCancel={() => toggleSignoutConfirmModal(false)} /> - { - HybridAppActions.setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); - }} - shouldShowCancelButton={false} - /> { + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); Session.signUpUser(); setReadyToShowAuthScreens(true); }} diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 9dd5082c08ca..64b4d83284a6 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -21,7 +21,6 @@ import useThemeStyles from '@hooks/useThemeStyles'; import AccountUtils from '@libs/AccountUtils'; import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus'; import * as ErrorUtils from '@libs/ErrorUtils'; -import {shouldUseOldApp} from '@libs/HybridApp'; import * as ValidationUtils from '@libs/ValidationUtils'; import ChangeExpensifyLoginLink from '@pages/signin/ChangeExpensifyLoginLink'; import Terms from '@pages/signin/Terms'; @@ -52,10 +51,6 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const [account] = useOnyx(ONYXKEYS.ACCOUNT); const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); const [session] = useOnyx(ONYXKEYS.SESSION); - const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); - const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP, { - initialValue: {oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED, newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED}, - }); const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); @@ -75,7 +70,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const input2FARef = useRef(); const timerRef = useRef(); - const hasError = (!!account && !isEmptyObject(account?.errors) && !needToClearError) || !!hybridApp?.oldDotSignInError; + const hasError = !!account && !isEmptyObject(account?.errors) && !needToClearError; const isLoadingResendValidationForm = account?.loadingForm === CONST.FORMS.RESEND_VALIDATE_CODE_FORM; const shouldDisableResendValidateCode = isOffline ?? account?.isLoading; const isValidateCodeFormSubmitting = AccountUtils.isValidateCodeFormSubmitting(account); @@ -184,13 +179,9 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * Clears local and Onyx sign in states */ const clearSignInData = useCallback(() => { - if (NativeModules.HybridAppModule && session?.authToken) { - HybridAppActions.resetSignInFlow(true); - } - clearLocalSignInData(); SessionActions.clearSignInData(); - }, [clearLocalSignInData, session?.authToken]); + }, [clearLocalSignInData]); useImperativeHandle(forwardedRef, () => ({ clearSignInData, @@ -247,7 +238,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco */ const validateAndSubmitForm = useCallback(() => { if (NativeModules.HybridAppModule && session?.authToken) { - HybridAppActions.resetSignInFlow(true); + HybridAppActions.resetSignInFlow(); } if (account?.isLoading) { @@ -381,7 +372,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco key="validateCode" testID="validateCode" /> - {hasError && } + {hasError && } {timeRemaining > 0 && !isOffline ? ( @@ -413,9 +404,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco large style={[styles.mv3]} text={translate('common.signIn')} - isLoading={ - shouldUseOldApp(tryNewDot) ? isValidateCodeFormSubmitting || hybridApp?.oldDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED : isValidateCodeFormSubmitting - } + isLoading={isValidateCodeFormSubmitting} onPress={validateAndSubmitForm} /> diff --git a/src/types/modules/react-native.d.ts b/src/types/modules/react-native.d.ts index 7d083c07076b..a1b2b0c587b8 100644 --- a/src/types/modules/react-native.d.ts +++ b/src/types/modules/react-native.d.ts @@ -9,7 +9,7 @@ type HybridAppModule = { closeReactNativeApp: (shouldSignOut: boolean, shouldSetNVP: boolean) => void; completeOnboarding: (status: boolean) => void; switchAccount: (newDotCurrentAccount: string) => void; - signInToOldDot: (autoGeneratedLogin: string, autoGeneratedPassword: string, isNewUser: boolean, authToken: string, encryptedAuthToken: string, email: string, policyID: string) => void; + signInToOldDot: (autoGeneratedLogin: string, autoGeneratedPassword: string, authToken: string, encryptedAuthToken: string, email: string, policyID: string) => void; signOutFromOldDot: () => void; exitApp: () => void; }; diff --git a/src/types/onyx/HybridApp.ts b/src/types/onyx/HybridApp.ts index 688ac01d05ed..d7ab1b0cf61f 100644 --- a/src/types/onyx/HybridApp.ts +++ b/src/types/onyx/HybridApp.ts @@ -6,16 +6,13 @@ type HybridApp = { /** Stores the information if HybridApp uses NewDot's sign-in flow */ useNewDotSignInPage?: boolean; - /** Stores the information about error that occurred on OldDot side during sign-in */ - oldDotSignInError?: string | null; - /** Tells if we can show AuthScreens */ readyToShowAuthScreens?: boolean; /** States whether we transitioned from OldDot to show only certain group of screens */ isSingleNewDotEntry?: boolean; - /** stores infromation if last log out was performed from OldDot */ + /** Stores information if last log out was performed from OldDot */ loggedOutFromOldDot?: boolean; /** */ @@ -23,9 +20,6 @@ type HybridApp = { /** Describes current stage of NewDot sign-in */ newDotSignInState?: ValueOf; - - /** Describes current stage of OldDot sign-in */ - oldDotSignInState?: ValueOf; }; export default HybridApp; From 9450d21ef6794b33b2ffa843a6281ffad05ea696 Mon Sep 17 00:00:00 2001 From: war-in Date: Mon, 9 Dec 2024 15:04:44 +0100 Subject: [PATCH 39/95] clear onyx but leave same data as when signing out --- src/libs/actions/Session/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 5c71e562c1cb..3323e5a5270a 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -506,7 +506,7 @@ function setupNewDotAfterTransitionFromOldDot(route: Route, hybridAppSettings: s return Promise.resolve(); } - return Onyx.clear(); + return redirectToSignIn(); }; const resetDidUserLoginDuringSessionIfNeeded = () => { From 62b861ccdb396f235e3f6c42e2381a5d30485bd2 Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Tue, 10 Dec 2024 14:24:17 +0100 Subject: [PATCH 40/95] Improve data fetching on OldDot side --- src/libs/HybridApp.ts | 1 - src/types/modules/react-native.d.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 99843665f1d7..60e6debeec96 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -74,7 +74,6 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryN credentials.autoGeneratedLogin, credentials.autoGeneratedPassword, currentSession?.authToken ?? '', - currentSession?.encryptedAuthToken ?? '', getCurrentUserEmail() ?? '', activePolicyID ?? '', ); diff --git a/src/types/modules/react-native.d.ts b/src/types/modules/react-native.d.ts index a1b2b0c587b8..cfab342c5c26 100644 --- a/src/types/modules/react-native.d.ts +++ b/src/types/modules/react-native.d.ts @@ -9,7 +9,7 @@ type HybridAppModule = { closeReactNativeApp: (shouldSignOut: boolean, shouldSetNVP: boolean) => void; completeOnboarding: (status: boolean) => void; switchAccount: (newDotCurrentAccount: string) => void; - signInToOldDot: (autoGeneratedLogin: string, autoGeneratedPassword: string, authToken: string, encryptedAuthToken: string, email: string, policyID: string) => void; + signInToOldDot: (autoGeneratedLogin: string, autoGeneratedPassword: string, authToken: string, email: string, policyID: string) => void; signOutFromOldDot: () => void; exitApp: () => void; }; From 892dec22757fa20e7b0b2ec6776480a468a0a926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Warcho=C5=82?= <61014013+war-in@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:50:49 +0100 Subject: [PATCH 41/95] Add named params in HybridAppModule methods (#153) * make HybridAppModule methods readable * improve another method --------- Co-authored-by: war-in --- src/components/ScreenWrapper.tsx | 2 +- src/libs/HybridApp.ts | 16 ++++++++-------- src/libs/TripReservationUtils.ts | 2 +- src/libs/actions/Delegate.ts | 4 ++-- src/libs/actions/Welcome/index.ts | 2 +- src/pages/ErrorPage/SessionExpiredPage.tsx | 2 +- src/pages/settings/InitialSettingsPage.tsx | 2 +- src/types/modules/react-native.d.ts | 8 ++++---- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/components/ScreenWrapper.tsx b/src/components/ScreenWrapper.tsx index 09315bfb8a8e..1e3df2a34817 100644 --- a/src/components/ScreenWrapper.tsx +++ b/src/components/ScreenWrapper.tsx @@ -177,7 +177,7 @@ function ScreenWrapper( }, [route?.params]); UNSTABLE_usePreventRemove(shouldReturnToOldDot, () => { - NativeModules.HybridAppModule?.closeReactNativeApp(false, false); + NativeModules.HybridAppModule?.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); }); const panResponder = useRef( diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 60e6debeec96..85b137bf6d50 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -70,16 +70,16 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryN if (hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && tryNewDot !== undefined && !!credentials?.autoGeneratedLogin && !!credentials?.autoGeneratedPassword) { Log.info(`[HybridApp] Performing sign-in${shouldUseOldApp(tryNewDot) ? '' : ' (in background)'} on OldDot side`); - NativeModules.HybridAppModule.signInToOldDot( - credentials.autoGeneratedLogin, - credentials.autoGeneratedPassword, - currentSession?.authToken ?? '', - getCurrentUserEmail() ?? '', - activePolicyID ?? '', - ); + NativeModules.HybridAppModule.signInToOldDot({ + autoGeneratedLogin: credentials.autoGeneratedLogin, + autoGeneratedPassword: credentials.autoGeneratedPassword, + authToken: currentSession?.authToken ?? '', + email: getCurrentUserEmail() ?? '', + policyID: activePolicyID ?? '', + }); HybridAppActions.setUseNewDotSignInPage(false).then(() => { if (shouldUseOldApp(tryNewDot)) { - NativeModules.HybridAppModule.closeReactNativeApp(false, false); + NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); } else { Log.info('[HybridApp] The user should see NewDot. There is no need to block the user on the `SignInPage` until the sign-in process is completed on the OldDot side.'); HybridAppActions.setReadyToShowAuthScreens(true); diff --git a/src/libs/TripReservationUtils.ts b/src/libs/TripReservationUtils.ts index 9c9947644e7f..275a0a965c24 100644 --- a/src/libs/TripReservationUtils.ts +++ b/src/libs/TripReservationUtils.ts @@ -108,7 +108,7 @@ function bookATrip(translate: LocaleContextProps['translate'], setCtaErrorMessag } Log.info('[HybridApp] Returning to OldDot after opening TravelDot'); - NativeModules.HybridAppModule.closeReactNativeApp(false, false); + NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); }) ?.catch(() => { setCtaErrorMessage(translate('travel.errorMessage')); diff --git a/src/libs/actions/Delegate.ts b/src/libs/actions/Delegate.ts index f99400d87d3e..3901c63ad8dd 100644 --- a/src/libs/actions/Delegate.ts +++ b/src/libs/actions/Delegate.ts @@ -140,7 +140,7 @@ function connect(email: string) { confirmReadyToOpenApp(); openApp(); - NativeModules.HybridAppModule.switchAccount(email); + NativeModules.HybridAppModule.switchAccount({newDotCurrentAccount: email}); }); }) .catch((error) => { @@ -210,7 +210,7 @@ function disconnect() { confirmReadyToOpenApp(); openApp(); - NativeModules.HybridAppModule.switchAccount(getCurrentUserEmail() ?? ''); + NativeModules.HybridAppModule.switchAccount({newDotCurrentAccount: getCurrentUserEmail() ?? ''}); }); }) .catch((error) => { diff --git a/src/libs/actions/Welcome/index.ts b/src/libs/actions/Welcome/index.ts index f91ab98f7b1d..6febdf5f3e60 100644 --- a/src/libs/actions/Welcome/index.ts +++ b/src/libs/actions/Welcome/index.ts @@ -145,7 +145,7 @@ function completeHybridAppOnboarding() { // No matter what the response is, we want to mark the onboarding as completed (user saw the explanation modal) Log.info(`[HybridApp] Onboarding status has changed. Propagating new value to OldDot`, true); - NativeModules.HybridAppModule.completeOnboarding(true); + NativeModules.HybridAppModule.completeOnboarding({status: true}); }); } diff --git a/src/pages/ErrorPage/SessionExpiredPage.tsx b/src/pages/ErrorPage/SessionExpiredPage.tsx index 5ccf70c40ab6..906c32dbb102 100644 --- a/src/pages/ErrorPage/SessionExpiredPage.tsx +++ b/src/pages/ErrorPage/SessionExpiredPage.tsx @@ -37,7 +37,7 @@ function SessionExpiredPage() { Navigation.goBack(); return; } - NativeModules.HybridAppModule.closeReactNativeApp(true, false); + NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: true, shouldSetNVP: false}); }} > {translate('deeplinkWrapper.signIn')} diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 07071736cd10..0bc86426455a 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -244,7 +244,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr ...(NativeModules.HybridAppModule ? { action: () => { - NativeModules.HybridAppModule.closeReactNativeApp(false, true); + NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); setInitialURL(undefined); }, } diff --git a/src/types/modules/react-native.d.ts b/src/types/modules/react-native.d.ts index cfab342c5c26..d3a17c73fced 100644 --- a/src/types/modules/react-native.d.ts +++ b/src/types/modules/react-native.d.ts @@ -6,10 +6,10 @@ import type {ShortcutManagerModule} from '@libs/ShortcutManager'; import type StartupTimer from '@libs/StartupTimer/types'; type HybridAppModule = { - closeReactNativeApp: (shouldSignOut: boolean, shouldSetNVP: boolean) => void; - completeOnboarding: (status: boolean) => void; - switchAccount: (newDotCurrentAccount: string) => void; - signInToOldDot: (autoGeneratedLogin: string, autoGeneratedPassword: string, authToken: string, email: string, policyID: string) => void; + closeReactNativeApp: ({shouldSignOut: boolean, shouldSetNVP: boolean}) => void; + completeOnboarding: ({status: boolean}) => void; + switchAccount: ({newDotCurrentAccount: string}) => void; + signInToOldDot: ({autoGeneratedLogin: string, autoGeneratedPassword: string, authToken: string, email: string, policyID: string}) => void; signOutFromOldDot: () => void; exitApp: () => void; }; From 1e113cdc365af73caa917cab0c5ab2de669faad0 Mon Sep 17 00:00:00 2001 From: war-in Date: Wed, 22 Jan 2025 14:45:22 +0100 Subject: [PATCH 42/95] fix after merge --- .../Navigation/AppNavigator/AuthScreens.tsx | 2 +- src/libs/actions/Delegate.ts | 8 +-- src/libs/actions/Session/index.ts | 58 ++++++++----------- 3 files changed, 29 insertions(+), 39 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index d09a21aeee82..28655e8d1bfe 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -1,6 +1,6 @@ import {findFocusedRoute} from '@react-navigation/native'; import React, {memo, useEffect, useMemo, useRef, useState} from 'react'; -import {View} from 'react-native'; +import {NativeModules, View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import Onyx, {withOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; diff --git a/src/libs/actions/Delegate.ts b/src/libs/actions/Delegate.ts index 24c81d62b486..5d7e3a67f0b9 100644 --- a/src/libs/actions/Delegate.ts +++ b/src/libs/actions/Delegate.ts @@ -157,8 +157,9 @@ function connect(email: string) { NetworkStore.setAuthToken(response?.restrictedToken ?? null); confirmReadyToOpenApp(); - // TODO: use object here - openApp().then(() => NativeModules.HybridAppModule.switchAccount(email, restrictedToken, policyID, String(previousAccountID))); + openApp().then(() => + NativeModules.HybridAppModule.switchAccount({newDotCurrentAccountEmail: email, authToken: restrictedToken, policyID, accountID: String(previousAccountID)}), + ); }); }) .catch((error) => { @@ -241,8 +242,7 @@ function disconnect() { confirmReadyToOpenApp(); - // TODO: use object here - openApp().then(() => NativeModules.HybridAppModule.switchAccount(requesterEmail, authToken, '', '')); + openApp().then(() => NativeModules.HybridAppModule.switchAccount({newDotCurrentAccountEmail: requesterEmail, authToken, policyID: '', accountID: ''})); }); }) .catch((error) => { diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index aabd8909ba93..565483c93f75 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -43,9 +43,7 @@ import {resetDidUserLogInDuringSession} from '@libs/SessionUtils'; import {clearSoundAssetsCache} from '@libs/Sound'; import Timers from '@libs/Timers'; import {hideContextMenu} from '@pages/home/report/ContextMenu/ReportActionContextMenu'; -import {KEYS_TO_PRESERVE, openApp, reconnectApp} from '@userActions/App'; import {KEYS_TO_PRESERVE, openApp} from '@userActions/App'; -import {KEYS_TO_PRESERVE_DELEGATE_ACCESS} from '@userActions/Delegate'; import * as Device from '@userActions/Device'; import * as HybridAppActions from '@userActions/HybridApp'; import * as PriorityMode from '@userActions/PriorityMode'; @@ -538,41 +536,33 @@ function setupNewDotAfterTransitionFromOldDot(route: Route, hybridAppSettings: s return new Promise((resolve) => { clearOnyxBeforeSignIn() - .then(() => { - // This section controls copilot changes - const currentUserEmail = getCurrentUserEmail(); - - // If ND and OD account are the same - do nothing - if (email === currentUserEmail) { - return; - } - - // If account was changed to original one on OD side - clear onyx - if (!oldDotOriginalAccountEmail) { - return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS); - } - - // If we're already logged in - do nothing, data will be set in next step - if (currentUserEmail) { - return; - } - - // If we're not logged in - set stashed data - return Onyx.multiSet({ - [ONYXKEYS.STASHED_CREDENTIALS]: {autoGeneratedLogin, autoGeneratedPassword}, - }); - }) + // .then(() => { + // // This section controls copilot changes + // const currentUserEmail = getCurrentUserEmail(); + // + // // If ND and OD account are the same - do nothing + // if (email === currentUserEmail) { + // return; + // } + // + // // If account was changed to original one on OD side - clear onyx + // if (!oldDotOriginalAccountEmail) { + // return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS); + // } + // + // // If we're already logged in - do nothing, data will be set in next step + // if (currentUserEmail) { + // return; + // } + // + // // If we're not logged in - set stashed data + // return Onyx.multiSet({ + // [ONYXKEYS.STASHED_CREDENTIALS]: {autoGeneratedLogin, autoGeneratedPassword}, + // }); + // }) .then(() => HybridAppActions.prepareHybridAppAfterTransitionToNewDot(hybridApp)) .then(resetDidUserLoginDuringSessionIfNeeded) .then(() => Onyx.multiSet(newDotOnyxValues)) - .then(() => { - if (clearOnyxOnStart === 'true') { - return openApp(); - } - return getLastUpdateIDAppliedToClient().then((lastUpdateId) => { - return reconnectApp(lastUpdateId); - }); - }) .catch((error) => { Log.hmmm('[HybridApp] Initialization of HybridApp has failed. Forcing transition', {error}); }) From 1cc1cd182323e2f5516ffc8b7304f24db7010c27 Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 23 Jan 2025 15:36:41 +0100 Subject: [PATCH 43/95] adjust copilot to new sign in flow --- src/libs/actions/Session/index.ts | 60 ++++++++++++++++++------------- src/types/onyx/HybridApp.ts | 21 +++++++++++ 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 565483c93f75..499dafe93ffc 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -44,6 +44,7 @@ import {clearSoundAssetsCache} from '@libs/Sound'; import Timers from '@libs/Timers'; import {hideContextMenu} from '@pages/home/report/ContextMenu/ReportActionContextMenu'; import {KEYS_TO_PRESERVE, openApp} from '@userActions/App'; +import {KEYS_TO_PRESERVE_DELEGATE_ACCESS} from '@userActions/Delegate'; import * as Device from '@userActions/Device'; import * as HybridAppActions from '@userActions/HybridApp'; import * as PriorityMode from '@userActions/PriorityMode'; @@ -536,30 +537,41 @@ function setupNewDotAfterTransitionFromOldDot(route: Route, hybridAppSettings: s return new Promise((resolve) => { clearOnyxBeforeSignIn() - // .then(() => { - // // This section controls copilot changes - // const currentUserEmail = getCurrentUserEmail(); - // - // // If ND and OD account are the same - do nothing - // if (email === currentUserEmail) { - // return; - // } - // - // // If account was changed to original one on OD side - clear onyx - // if (!oldDotOriginalAccountEmail) { - // return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS); - // } - // - // // If we're already logged in - do nothing, data will be set in next step - // if (currentUserEmail) { - // return; - // } - // - // // If we're not logged in - set stashed data - // return Onyx.multiSet({ - // [ONYXKEYS.STASHED_CREDENTIALS]: {autoGeneratedLogin, autoGeneratedPassword}, - // }); - // }) + .then(() => { + // This section controls copilot changes + const currentUserEmail = getCurrentUserEmail(); + + // If ND and OD account are the same - do nothing + if (hybridApp?.delegateAccessData?.oldDotCurrentUserEmail === currentUserEmail) { + return; + } + + const stashedData = hybridApp?.delegateAccessData?.isDelegateAccess + ? { + [ONYXKEYS.STASHED_CREDENTIALS]: credentials, + [ONYXKEYS.STASHED_SESSION]: session, + } + : { + [ONYXKEYS.STASHED_CREDENTIALS]: {}, + [ONYXKEYS.STASHED_SESSION]: {}, + }; + + // Account was changed on OD side - clear onyx and apply data + return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS).then(() => + Onyx.multiSet({ + ...stashedData, + [ONYXKEYS.SESSION]: { + email: hybridApp?.delegateAccessData?.oldDotCurrentUserEmail, + authToken: hybridApp?.delegateAccessData?.oldDotCurrentAuthToken, + encryptedAuthToken: decodeURIComponent(hybridApp?.delegateAccessData?.oldDotCurrentEncryptedAuthToken ?? ''), + accountID: hybridApp?.delegateAccessData?.oldDotCurrentAccountID, + }, + [ONYXKEYS.CREDENTIALS]: {autoGeneratedLogin: credentials?.autoGeneratedLogin, autoGeneratedPassword: credentials?.autoGeneratedPassword}, + }) + .then(() => Onyx.merge(ONYXKEYS.ACCOUNT, {primaryLogin: hybridApp?.delegateAccessData?.oldDotCurrentUserEmail})) + .then(() => openApp()), + ); + }) .then(() => HybridAppActions.prepareHybridAppAfterTransitionToNewDot(hybridApp)) .then(resetDidUserLoginDuringSessionIfNeeded) .then(() => Onyx.multiSet(newDotOnyxValues)) diff --git a/src/types/onyx/HybridApp.ts b/src/types/onyx/HybridApp.ts index d7ab1b0cf61f..825389ec38fb 100644 --- a/src/types/onyx/HybridApp.ts +++ b/src/types/onyx/HybridApp.ts @@ -1,6 +1,24 @@ import type {ValueOf} from 'type-fest'; import type CONST from '@src/CONST'; +/** */ +type HybridAppDelegateAccessData = { + /** */ + isDelegateAccess?: boolean; + + /** */ + oldDotCurrentUserEmail?: string; + + /** */ + oldDotCurrentAuthToken?: string; + + /** */ + oldDotCurrentEncryptedAuthToken?: string; + + /** */ + oldDotCurrentAccountID?: number; +}; + /** */ type HybridApp = { /** Stores the information if HybridApp uses NewDot's sign-in flow */ @@ -20,6 +38,9 @@ type HybridApp = { /** Describes current stage of NewDot sign-in */ newDotSignInState?: ValueOf; + + /** */ + delegateAccessData?: HybridAppDelegateAccessData; }; export default HybridApp; From 4f3a35e7dc92ca7cca77f6cfbf9d050780e0682a Mon Sep 17 00:00:00 2001 From: war-in Date: Mon, 3 Feb 2025 12:38:37 +0100 Subject: [PATCH 44/95] post-merge fixes --- src/libs/actions/Travel.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Travel.ts b/src/libs/actions/Travel.ts index 1886885587c4..814a274bafdb 100644 --- a/src/libs/actions/Travel.ts +++ b/src/libs/actions/Travel.ts @@ -44,9 +44,9 @@ Onyx.connect({ let isSingleNewDotEntry: boolean | undefined; Onyx.connect({ - key: ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY, + key: ONYXKEYS.HYBRID_APP, callback: (val) => { - isSingleNewDotEntry = val; + isSingleNewDotEntry = val?.isSingleNewDotEntry; }, }); @@ -137,7 +137,7 @@ function bookATrip(translate: LocaleContextProps['translate'], setCtaErrorMessag } Log.info('[HybridApp] Returning to OldDot after opening TravelDot'); - NativeModules.HybridAppModule.closeReactNativeApp(false, false); + NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); }) ?.catch(() => { setCtaErrorMessage(translate('travel.errorMessage')); From 708d8ed5a2b94c15440f9a39c51f008d19fab8b7 Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 6 Feb 2025 16:31:22 +0100 Subject: [PATCH 45/95] post-merge fixes --- src/components/BookTravelButton.tsx | 10 +++++----- .../OnboardingEmployees/BaseOnboardingEmployees.tsx | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/BookTravelButton.tsx b/src/components/BookTravelButton.tsx index 1953acde8ad4..f20b26fb4c0e 100644 --- a/src/components/BookTravelButton.tsx +++ b/src/components/BookTravelButton.tsx @@ -41,7 +41,7 @@ function BookTravelButton({text}: BookTravelButtonProps) { // Flag indicating whether NewDot was launched exclusively for Travel, // e.g., when the user selects "Trips" from the Expensify Classic menu in HybridApp. - const [wasNewDotLaunchedJustForTravel] = useOnyx(ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); const bookATrip = useCallback(() => { setErrorMessage(''); @@ -63,14 +63,14 @@ function BookTravelButton({text}: BookTravelButtonProps) { openTravelDotLink(policy?.id) ?.then(() => { // When a user selects "Trips" in the Expensify Classic menu, the HybridApp opens the ManageTrips page in NewDot. - // The wasNewDotLaunchedJustForTravel flag indicates if NewDot was launched solely for this purpose. - if (!NativeModules.HybridAppModule || !wasNewDotLaunchedJustForTravel) { + // The isSingleNewDotEntry flag indicates if NewDot was launched solely for this purpose. + if (!NativeModules.HybridAppModule || !hybridApp?.isSingleNewDotEntry) { return; } // Close NewDot if it was opened only for Travel, as its purpose is now fulfilled. Log.info('[HybridApp] Returning to OldDot after opening TravelDot'); - NativeModules.HybridAppModule.closeReactNativeApp(false, false); + NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); setRootStatusBarEnabled(false); }) ?.catch(() => { @@ -92,7 +92,7 @@ function BookTravelButton({text}: BookTravelButtonProps) { Navigation.navigate(ROUTES.TRAVEL_DOMAIN_SELECTOR); } } - }, [policy, wasNewDotLaunchedJustForTravel, travelSettings, translate, primaryLogin, setRootStatusBarEnabled]); + }, [primaryLogin, policy, travelSettings?.hasAcceptedTerms, translate, hybridApp?.isSingleNewDotEntry, setRootStatusBarEnabled]); return ( <> diff --git a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx index 1a4b9bd79e61..7eaeb85431ff 100644 --- a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx +++ b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx @@ -107,7 +107,7 @@ function BaseOnboardingEmployees({shouldUseNativeStyles, route}: BaseOnboardingE ); } - NativeModules.HybridAppModule.closeReactNativeApp(false, true); + NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); setRootStatusBarEnabled(false); }} pressOnEnter From 793608ff20bfca27a87427cba986b4ff4548198d Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 6 Feb 2025 17:34:08 +0100 Subject: [PATCH 46/95] fix status bar when signing into OldDot --- src/components/BookTravelButton.tsx | 9 ++++----- src/components/CustomStatusBarAndBackground/index.tsx | 5 ++++- src/components/InitialURLContextProvider.tsx | 2 ++ src/components/ScreenWrapper.tsx | 5 ++--- src/libs/HybridApp.ts | 2 ++ src/libs/actions/HybridApp/index.ts | 6 +++++- .../OnboardingEmployees/BaseOnboardingEmployees.tsx | 7 +++---- src/pages/settings/InitialSettingsPage.tsx | 7 +++---- src/types/onyx/HybridApp.ts | 3 +++ 9 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/components/BookTravelButton.tsx b/src/components/BookTravelButton.tsx index f20b26fb4c0e..68cb96eea165 100644 --- a/src/components/BookTravelButton.tsx +++ b/src/components/BookTravelButton.tsx @@ -1,5 +1,5 @@ import {Str} from 'expensify-common'; -import React, {useCallback, useContext, useState} from 'react'; +import React, {useCallback, useState} from 'react'; import {NativeModules} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import useLocalize from '@hooks/useLocalize'; @@ -10,12 +10,12 @@ import {cleanupTravelProvisioningSession} from '@libs/actions/Travel'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import {getAdminsPrivateEmailDomains} from '@libs/PolicyUtils'; +import {setIsRootStatusBarEnabled} from '@userActions/HybridApp'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import Button from './Button'; -import CustomStatusBarAndBackgroundContext from './CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import DotIndicatorMessage from './DotIndicatorMessage'; type BookTravelButtonProps = { @@ -37,7 +37,6 @@ function BookTravelButton({text}: BookTravelButtonProps) { const [travelSettings] = useOnyx(ONYXKEYS.NVP_TRAVEL_SETTINGS); const [account] = useOnyx(ONYXKEYS.ACCOUNT); const primaryLogin = account?.primaryLogin; - const {setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext); // Flag indicating whether NewDot was launched exclusively for Travel, // e.g., when the user selects "Trips" from the Expensify Classic menu in HybridApp. @@ -71,7 +70,7 @@ function BookTravelButton({text}: BookTravelButtonProps) { // Close NewDot if it was opened only for Travel, as its purpose is now fulfilled. Log.info('[HybridApp] Returning to OldDot after opening TravelDot'); NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); - setRootStatusBarEnabled(false); + setIsRootStatusBarEnabled(false); }) ?.catch(() => { setErrorMessage(translate('travel.errorMessage')); @@ -92,7 +91,7 @@ function BookTravelButton({text}: BookTravelButtonProps) { Navigation.navigate(ROUTES.TRAVEL_DOMAIN_SELECTOR); } } - }, [primaryLogin, policy, travelSettings?.hasAcceptedTerms, translate, hybridApp?.isSingleNewDotEntry, setRootStatusBarEnabled]); + }, [primaryLogin, policy, travelSettings?.hasAcceptedTerms, translate, hybridApp?.isSingleNewDotEntry]); return ( <> diff --git a/src/components/CustomStatusBarAndBackground/index.tsx b/src/components/CustomStatusBarAndBackground/index.tsx index ac1fc77dff96..2e92019d2f61 100644 --- a/src/components/CustomStatusBarAndBackground/index.tsx +++ b/src/components/CustomStatusBarAndBackground/index.tsx @@ -5,6 +5,8 @@ import useTheme from '@hooks/useTheme'; import {navigationRef} from '@libs/Navigation/Navigation'; import StatusBar from '@libs/StatusBar'; import type {StatusBarStyle} from '@styles/index'; +import ONYXKEYS from '@src/ONYXKEYS'; +import {useOnyx} from '../../../__mocks__/react-native-onyx'; import CustomStatusBarAndBackgroundContext from './CustomStatusBarAndBackgroundContext'; import updateGlobalBackgroundColor from './updateGlobalBackgroundColor'; import updateStatusBarAppearance from './updateStatusBarAppearance'; @@ -19,8 +21,9 @@ function CustomStatusBarAndBackground({isNested = false}: CustomStatusBarAndBack const {isRootStatusBarEnabled, setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext); const theme = useTheme(); const [statusBarStyle, setStatusBarStyle] = useState(); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); - const isDisabled = !isNested && !isRootStatusBarEnabled; + const isDisabled = (!hybridApp?.isRootStatusBarEnabled ?? false) || (!isNested && !isRootStatusBarEnabled); // Disable the root status bar when a nested status bar is rendered useEffect(() => { diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index d6162231c694..c61a3c42edb6 100644 --- a/src/components/InitialURLContextProvider.tsx +++ b/src/components/InitialURLContextProvider.tsx @@ -5,6 +5,7 @@ import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import {setupNewDotAfterTransitionFromOldDot} from '@libs/actions/Session'; import Navigation from '@navigation/Navigation'; +import {setIsRootStatusBarEnabled} from '@userActions/HybridApp'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; @@ -56,6 +57,7 @@ function InitialURLContextProvider({children, url, hybridAppSettings}: InitialUR return; } + setIsRootStatusBarEnabled(true); if (url && hybridAppSettings) { if (!isLoadingOnyxValue(tryNewDotMetadata) && !setupCalled.current) { setupCalled.current = true; diff --git a/src/components/ScreenWrapper.tsx b/src/components/ScreenWrapper.tsx index 9851fb7c8afb..ee57ab66c41b 100644 --- a/src/components/ScreenWrapper.tsx +++ b/src/components/ScreenWrapper.tsx @@ -16,10 +16,10 @@ import {isMobile, isMobileWebKit, isSafari} from '@libs/Browser'; import type {PlatformStackNavigationProp} from '@libs/Navigation/PlatformStackNavigation/types'; import type {AuthScreensParamList, RootStackParamList} from '@libs/Navigation/types'; import addViewportResizeListener from '@libs/VisualViewport'; +import {setIsRootStatusBarEnabled} from '@userActions/HybridApp'; import toggleTestToolsModal from '@userActions/TestTool'; import CONST from '@src/CONST'; import CustomDevMenu from './CustomDevMenu'; -import CustomStatusBarAndBackgroundContext from './CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import FocusTrapForScreens from './FocusTrap/FocusTrapForScreen'; import type FocusTrapForScreenProps from './FocusTrap/FocusTrapForScreen/FocusTrapProps'; import HeaderGap from './HeaderGap'; @@ -153,7 +153,6 @@ function ScreenWrapper( const {windowHeight} = useWindowDimensions(shouldUseCachedViewportHeight); // since Modals are drawn in separate native view hierarchy we should always add paddings const ignoreInsetsConsumption = !useContext(ModalContext).default; - const {setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext); // We need to use isSmallScreenWidth instead of shouldUseNarrowLayout for a case where we want to show the offline indicator only on small screens // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth @@ -173,7 +172,7 @@ function ScreenWrapper( UNSTABLE_usePreventRemove(shouldReturnToOldDot, () => { NativeModules.HybridAppModule?.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); - setRootStatusBarEnabled(false); + setIsRootStatusBarEnabled(false); }); const panResponder = useRef( diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 85b137bf6d50..177762ba34b8 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -5,6 +5,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Credentials, HybridApp, Session, TryNewDot} from '@src/types/onyx'; import * as HybridAppActions from './actions/HybridApp'; +import {setIsRootStatusBarEnabled} from './actions/HybridApp'; import Log from './Log'; import {getCurrentUserEmail} from './Network/NetworkStore'; @@ -80,6 +81,7 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryN HybridAppActions.setUseNewDotSignInPage(false).then(() => { if (shouldUseOldApp(tryNewDot)) { NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); + setIsRootStatusBarEnabled(false); } else { Log.info('[HybridApp] The user should see NewDot. There is no need to block the user on the `SignInPage` until the sign-in process is completed on the OldDot side.'); HybridAppActions.setReadyToShowAuthScreens(true); diff --git a/src/libs/actions/HybridApp/index.ts b/src/libs/actions/HybridApp/index.ts index 0bcda22b8b2c..271b91aa99ee 100644 --- a/src/libs/actions/HybridApp/index.ts +++ b/src/libs/actions/HybridApp/index.ts @@ -30,6 +30,10 @@ function setUseNewDotSignInPage(useNewDotSignInPage: boolean) { return Onyx.merge(ONYXKEYS.HYBRID_APP, {useNewDotSignInPage}); } +function setIsRootStatusBarEnabled(isRootStatusBarEnabled: boolean) { + return Onyx.merge(ONYXKEYS.HYBRID_APP, {isRootStatusBarEnabled}); +} + /* * Starts HybridApp sign-in flow from the beginning. */ @@ -60,4 +64,4 @@ function prepareHybridAppAfterTransitionToNewDot(hybridApp: HybridApp) { }); } -export {parseHybridAppSettings, setReadyToShowAuthScreens, setNewDotSignInState, resetSignInFlow, prepareHybridAppAfterTransitionToNewDot, setUseNewDotSignInPage}; +export {parseHybridAppSettings, setReadyToShowAuthScreens, setNewDotSignInState, resetSignInFlow, prepareHybridAppAfterTransitionToNewDot, setUseNewDotSignInPage, setIsRootStatusBarEnabled}; diff --git a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx index 7eaeb85431ff..6a5f9ccf4c57 100644 --- a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx +++ b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx @@ -1,8 +1,7 @@ -import React, {useContext, useMemo, useState} from 'react'; +import React, {useMemo, useState} from 'react'; import {NativeModules} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import Button from '@components/Button'; -import CustomStatusBarAndBackgroundContext from '@components/CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import FormHelpMessage from '@components/FormHelpMessage'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; @@ -15,6 +14,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import {isPaidGroupPolicy} from '@libs/PolicyUtils'; +import {setIsRootStatusBarEnabled} from '@userActions/HybridApp'; import {createWorkspace, generatePolicyID} from '@userActions/Policy/Policy'; import {completeOnboarding} from '@userActions/Report'; import {setOnboardingAdminsChatReportID, setOnboardingCompanySize, setOnboardingPolicyID} from '@userActions/Welcome'; @@ -35,7 +35,6 @@ function BaseOnboardingEmployees({shouldUseNativeStyles, route}: BaseOnboardingE const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID); const [onboardingAdminsChatReportID] = useOnyx(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID); const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); - const {setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext); const paidGroupPolicy = Object.values(allPolicies ?? {}).find(isPaidGroupPolicy); @@ -108,7 +107,7 @@ function BaseOnboardingEmployees({shouldUseNativeStyles, route}: BaseOnboardingE } NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); - setRootStatusBarEnabled(false); + setIsRootStatusBarEnabled(false); }} pressOnEnter /> diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index e71c492881fa..de259a5734fb 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -8,7 +8,6 @@ import type {ValueOf} from 'type-fest'; import AccountSwitcher from '@components/AccountSwitcher'; import AccountSwitcherSkeletonView from '@components/AccountSwitcherSkeletonView'; import ConfirmModal from '@components/ConfirmModal'; -import CustomStatusBarAndBackgroundContext from '@components/CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import DelegateNoAccessModal from '@components/DelegateNoAccessModal'; import Icon from '@components/Icon'; import * as Expensicons from '@components/Icon/Expensicons'; @@ -40,6 +39,7 @@ import * as ReportActionContextMenu from '@pages/home/report/ContextMenu/ReportA import variables from '@styles/variables'; import {confirmReadyToOpenApp} from '@userActions/App'; import * as HybridAppActions from '@userActions/HybridApp'; +import {setIsRootStatusBarEnabled} from '@userActions/HybridApp'; import {buildOldDotURL, openExternalLink, openOldDotLink} from '@userActions/Link'; import {hasPaymentMethodError} from '@userActions/PaymentMethods'; import {isSupportAuthToken, signOutAndRedirectToSignIn} from '@userActions/Session'; @@ -102,7 +102,6 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr const emojiCode = currentUserPersonalDetails?.status?.emojiCode ?? ''; const [allConnectionSyncProgresses] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}`); const {setInitialURL} = useContext(InitialURLContext); - const {setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext); const [privateSubscription] = useOnyx(ONYXKEYS.NVP_PRIVATE_SUBSCRIPTION); const subscriptionPlan = useSubscriptionPlan(); @@ -246,7 +245,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr action: () => { NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); setInitialURL(undefined); - setRootStatusBarEnabled(false); + setIsRootStatusBarEnabled(false); }, } : { @@ -290,7 +289,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr }, ], }; - }, [styles.pt4, setInitialURL, setRootStatusBarEnabled, isActingAsDelegate, shouldOpenBookACall, signOut]); + }, [styles.pt4, setInitialURL, isActingAsDelegate, shouldOpenBookACall, signOut]); /** * Retuns JSX.Element with menu items diff --git a/src/types/onyx/HybridApp.ts b/src/types/onyx/HybridApp.ts index 825389ec38fb..816d9227bfaf 100644 --- a/src/types/onyx/HybridApp.ts +++ b/src/types/onyx/HybridApp.ts @@ -41,6 +41,9 @@ type HybridApp = { /** */ delegateAccessData?: HybridAppDelegateAccessData; + + /** */ + isRootStatusBarEnabled?: boolean; }; export default HybridApp; From d9bb31f6fc227e4dfd58df40668519ff1d37d092 Mon Sep 17 00:00:00 2001 From: war-in Date: Mon, 17 Mar 2025 14:27:15 +0100 Subject: [PATCH 47/95] post-merge fixes --- .../ReactNativeHybridApp.kt | 14 ++++++++++++++ modules/hybrid-app/ios/ReactNativeHybridApp.mm | 9 ++++++++- .../src/NativeReactNativeHybridApp.ts | 2 ++ modules/hybrid-app/src/index.native.ts | 6 ++++++ modules/hybrid-app/src/index.ts | 8 ++++++++ modules/hybrid-app/src/types.ts | 2 ++ src/Expensify.tsx | 4 +--- .../CustomStatusBarAndBackground/index.tsx | 2 +- src/components/InitialURLContextProvider.tsx | 3 ++- src/components/ScreenWrapper.tsx | 5 +++-- src/libs/HybridApp.ts | 11 +++++------ .../Navigation/AppNavigator/PublicScreens.tsx | 1 - .../subscribePushNotification/index.ts | 4 ++-- src/libs/actions/HybridApp/index.ts | 6 +----- src/libs/actions/Session/index.ts | 18 +----------------- .../BaseOnboardingEmployees.tsx | 7 ++++--- src/pages/settings/InitialSettingsPage.tsx | 2 +- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 7 ++++--- src/types/onyx/HybridApp.ts | 3 --- 19 files changed, 65 insertions(+), 49 deletions(-) diff --git a/modules/hybrid-app/android/src/main/java/com/expensify/reactnativehybridapp/ReactNativeHybridApp.kt b/modules/hybrid-app/android/src/main/java/com/expensify/reactnativehybridapp/ReactNativeHybridApp.kt index da3f745f4564..2dc273fea218 100644 --- a/modules/hybrid-app/android/src/main/java/com/expensify/reactnativehybridapp/ReactNativeHybridApp.kt +++ b/modules/hybrid-app/android/src/main/java/com/expensify/reactnativehybridapp/ReactNativeHybridApp.kt @@ -28,4 +28,18 @@ class ReactNativeHybridApp(reactContext: ReactApplicationContext) : ) { Log.d(NAME, "`switchAccount` should never be called in standalone `New Expensify` app") } + + override fun signInToOldDot( + autoGeneratedLogin: String, + autoGeneratedPassword: String, + authToken: String, + email: String, + policyID: String + ) { + Log.d(NAME, "`signInToOldDot` should never be called in standalone `New Expensify` app") + } + + override fun signOutFromOldDot() { + Log.d(NAME, "`signOutFromOldDot` should never be called in standalone `New Expensify` app") + } } diff --git a/modules/hybrid-app/ios/ReactNativeHybridApp.mm b/modules/hybrid-app/ios/ReactNativeHybridApp.mm index 8b55a73be5a3..1515f7486631 100644 --- a/modules/hybrid-app/ios/ReactNativeHybridApp.mm +++ b/modules/hybrid-app/ios/ReactNativeHybridApp.mm @@ -13,13 +13,20 @@ - (void)closeReactNativeApp:(BOOL)shouldSignOut shouldSetNVP:(BOOL)shouldSetNVP - (void)completeOnboarding:(BOOL)status { NSLog(@"[ReactNativeHybridApp] `completeOnboarding` should never be called in standalone `New Expensify` app"); - } - (void)switchAccount:(NSString *)newDotCurrentAccountEmail authToken:(NSString *)authToken policyID:(NSString *)policyID accountID:(NSString *)accountID { NSLog(@"[ReactNativeHybridApp] `switchAccount` should never be called in standalone `New Expensify` app"); } +- (void)signInToOldDot:(NSString *)autoGeneratedLogin autoGeneratedPassword:(NSString *)autoGeneratedPassword authToken:(NSString *)authToken email:(NSString *)email policyID:(NSString *)policyID { + NSLog(@"[ReactNativeHybridApp] `signInToOldDot` should never be called in standalone `New Expensify` app"); +} + +- (void)signOutFromOldDot { + NSLog(@"[ReactNativeHybridApp] `signOutFromOldDot` should never be called in standalone `New Expensify` app"); +} + - (std::shared_ptr)getTurboModule: (const facebook::react::ObjCTurboModule::InitParams &)params { diff --git a/modules/hybrid-app/src/NativeReactNativeHybridApp.ts b/modules/hybrid-app/src/NativeReactNativeHybridApp.ts index f9041c557717..f5d29403eb9f 100644 --- a/modules/hybrid-app/src/NativeReactNativeHybridApp.ts +++ b/modules/hybrid-app/src/NativeReactNativeHybridApp.ts @@ -7,6 +7,8 @@ export interface Spec extends TurboModule { closeReactNativeApp: (shouldSignOut: boolean, shouldSetNVP: boolean) => void; completeOnboarding: (status: boolean) => void; switchAccount: (newDotCurrentAccountEmail: string, authToken: string, policyID: string, accountID: string) => void; + signInToOldDot: (autoGeneratedLogin: string, autoGeneratedPassword: string, authToken: string, email: string, policyID: string) => void; + signOutFromOldDot: () => void; } export default TurboModuleRegistry.getEnforcing('ReactNativeHybridApp'); diff --git a/modules/hybrid-app/src/index.native.ts b/modules/hybrid-app/src/index.native.ts index 956cb5784dfc..3ba899af6ad3 100644 --- a/modules/hybrid-app/src/index.native.ts +++ b/modules/hybrid-app/src/index.native.ts @@ -14,6 +14,12 @@ const HybridAppModule: HybridAppModuleType = { switchAccount({newDotCurrentAccountEmail, authToken, policyID, accountID}) { ReactNativeHybridApp.switchAccount(newDotCurrentAccountEmail, authToken, policyID, accountID); }, + signInToOldDot({autoGeneratedLogin, autoGeneratedPassword, authToken, email, policyID}) { + ReactNativeHybridApp.signInToOldDot(autoGeneratedLogin, autoGeneratedPassword, authToken, email, policyID); + }, + signOutFromOldDot() { + ReactNativeHybridApp.signOutFromOldDot(); + }, }; export default HybridAppModule; diff --git a/modules/hybrid-app/src/index.ts b/modules/hybrid-app/src/index.ts index 6316ee8fb960..f6638aec92c9 100644 --- a/modules/hybrid-app/src/index.ts +++ b/modules/hybrid-app/src/index.ts @@ -16,6 +16,14 @@ const HybridAppModule: HybridAppModuleType = { // eslint-disable-next-line no-console console.warn('HybridAppModule: `switchAccount` should never be called on web'); }, + signInToOldDot() { + // eslint-disable-next-line no-console + console.warn('HybridAppModule: `signInToOldDot` should never be called on web'); + }, + signOutFromOldDot() { + // eslint-disable-next-line no-console + console.warn('HybridAppModule: `signOutFromOldDot` should never be called on web'); + }, }; export default HybridAppModule; diff --git a/modules/hybrid-app/src/types.ts b/modules/hybrid-app/src/types.ts index 5fef691d3a48..58db8459fc06 100644 --- a/modules/hybrid-app/src/types.ts +++ b/modules/hybrid-app/src/types.ts @@ -3,6 +3,8 @@ type HybridAppModuleType = { closeReactNativeApp: (args: {shouldSignOut: boolean; shouldSetNVP: boolean}) => void; completeOnboarding: (args: {status: boolean}) => void; switchAccount: (args: {newDotCurrentAccountEmail: string; authToken: string; policyID: string; accountID: string}) => void; + signInToOldDot: (args: {autoGeneratedLogin: string; autoGeneratedPassword: string; authToken: string; email: string; policyID: string}) => void; + signOutFromOldDot: () => void; }; export default HybridAppModuleType; diff --git a/src/Expensify.tsx b/src/Expensify.tsx index e0161b97c9a5..f88acdf3eef0 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -112,9 +112,7 @@ function Expensify() { const isAuthenticated = useIsAuthenticated(); const autoAuthState = useMemo(() => session?.autoAuthState ?? '', [session]); - const shouldInit = CONFIG.IS_HYBRID_APP - ? !hybridApp?.loggedOutFromOldDot && isNavigationReady && hasAttemptedToOpenPublicRoom - : isNavigationReady && hasAttemptedToOpenPublicRoom; + const shouldInit = CONFIG.IS_HYBRID_APP ? !hybridApp?.loggedOutFromOldDot && isNavigationReady && hasAttemptedToOpenPublicRoom : isNavigationReady && hasAttemptedToOpenPublicRoom; const shouldHideSplash = shouldInit && (CONFIG.IS_HYBRID_APP diff --git a/src/components/CustomStatusBarAndBackground/index.tsx b/src/components/CustomStatusBarAndBackground/index.tsx index 2e92019d2f61..3fef4fedb3a1 100644 --- a/src/components/CustomStatusBarAndBackground/index.tsx +++ b/src/components/CustomStatusBarAndBackground/index.tsx @@ -23,7 +23,7 @@ function CustomStatusBarAndBackground({isNested = false}: CustomStatusBarAndBack const [statusBarStyle, setStatusBarStyle] = useState(); const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); - const isDisabled = (!hybridApp?.isRootStatusBarEnabled ?? false) || (!isNested && !isRootStatusBarEnabled); + const isDisabled = !isNested && !isRootStatusBarEnabled; // Disable the root status bar when a nested status bar is rendered useEffect(() => { diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index d71f780bf73d..de37e1859ba4 100644 --- a/src/components/InitialURLContextProvider.tsx +++ b/src/components/InitialURLContextProvider.tsx @@ -1,10 +1,11 @@ import React, {createContext, useEffect, useMemo, useRef, useState} from 'react'; import type {ReactNode} from 'react'; import {Linking} from 'react-native'; -import type {AppProps} from '@src/App'; import {useOnyx} from 'react-native-onyx'; import {setupNewDotAfterTransitionFromOldDot} from '@libs/actions/Session'; +import type {AppProps} from '@src/App'; import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; import {useSplashScreenStateContext} from '@src/SplashScreenStateContext'; import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; diff --git a/src/components/ScreenWrapper.tsx b/src/components/ScreenWrapper.tsx index 6b40fa0304d7..18e93906c38b 100644 --- a/src/components/ScreenWrapper.tsx +++ b/src/components/ScreenWrapper.tsx @@ -7,6 +7,7 @@ import {Keyboard, PanResponder, View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import {PickerAvoidingView} from 'react-native-picker-select'; import type {EdgeInsets} from 'react-native-safe-area-context'; +import CustomStatusBarAndBackgroundContext from './CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import useBottomSafeSafeAreaPaddingStyle from '@hooks/useBottomSafeSafeAreaPaddingStyle'; import useEnvironment from '@hooks/useEnvironment'; import useInitialDimensions from '@hooks/useInitialWindowDimensions'; @@ -181,7 +182,7 @@ function ScreenWrapper( const {setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext); const {initialURL} = useContext(InitialURLContext); - const [isSingleNewDotEntry] = useOnyx(ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); const includeSafeAreaPaddingBottom = enableEdgeToEdgeBottomSafeAreaPadding ? false : includeSafeAreaPaddingBottomProp; @@ -197,7 +198,7 @@ function ScreenWrapper( const {isBlurred, setIsBlurred} = useInputBlurContext(); - UNSTABLE_usePreventRemove((isSingleNewDotEntry ?? false) && initialURL === Navigation.getActiveRouteWithoutParams(), () => { + UNSTABLE_usePreventRemove((hybridApp?.isSingleNewDotEntry ?? false) && initialURL === Navigation.getActiveRouteWithoutParams(), () => { if (!CONFIG.IS_HYBRID_APP) { return; } diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 177762ba34b8..e6df6292b2e9 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -1,11 +1,11 @@ -import {NativeModules} from 'react-native'; +import HybridAppModule from '@expensify/react-native-hybrid-app'; import Onyx from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; +import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Credentials, HybridApp, Session, TryNewDot} from '@src/types/onyx'; import * as HybridAppActions from './actions/HybridApp'; -import {setIsRootStatusBarEnabled} from './actions/HybridApp'; import Log from './Log'; import {getCurrentUserEmail} from './Network/NetworkStore'; @@ -59,7 +59,7 @@ function shouldUseOldApp(tryNewDot?: TryNewDot) { } function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry, credentials: OnyxEntry) { - if (!NativeModules.HybridAppModule) { + if (!CONFIG.IS_HYBRID_APP) { return; } @@ -71,7 +71,7 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryN if (hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && tryNewDot !== undefined && !!credentials?.autoGeneratedLogin && !!credentials?.autoGeneratedPassword) { Log.info(`[HybridApp] Performing sign-in${shouldUseOldApp(tryNewDot) ? '' : ' (in background)'} on OldDot side`); - NativeModules.HybridAppModule.signInToOldDot({ + HybridAppModule.signInToOldDot({ autoGeneratedLogin: credentials.autoGeneratedLogin, autoGeneratedPassword: credentials.autoGeneratedPassword, authToken: currentSession?.authToken ?? '', @@ -80,8 +80,7 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryN }); HybridAppActions.setUseNewDotSignInPage(false).then(() => { if (shouldUseOldApp(tryNewDot)) { - NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); - setIsRootStatusBarEnabled(false); + HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); } else { Log.info('[HybridApp] The user should see NewDot. There is no need to block the user on the `SignInPage` until the sign-in process is completed on the OldDot side.'); HybridAppActions.setReadyToShowAuthScreens(true); diff --git a/src/libs/Navigation/AppNavigator/PublicScreens.tsx b/src/libs/Navigation/AppNavigator/PublicScreens.tsx index 915f5ffe1f9a..45410f5332b3 100644 --- a/src/libs/Navigation/AppNavigator/PublicScreens.tsx +++ b/src/libs/Navigation/AppNavigator/PublicScreens.tsx @@ -9,7 +9,6 @@ import SAMLSignInPage from '@pages/signin/SAMLSignInPage'; import SignInPage from '@pages/signin/SignInPage'; import UnlinkLoginPage from '@pages/UnlinkLoginPage'; import ValidateLoginPage from '@pages/ValidateLoginPage'; -import CONFIG from '@src/CONFIG'; import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; import defaultScreenOptions from './defaultScreenOptions'; diff --git a/src/libs/Notification/PushNotification/subscribePushNotification/index.ts b/src/libs/Notification/PushNotification/subscribePushNotification/index.ts index 2b6110d26548..b8915470d43d 100644 --- a/src/libs/Notification/PushNotification/subscribePushNotification/index.ts +++ b/src/libs/Notification/PushNotification/subscribePushNotification/index.ts @@ -28,12 +28,12 @@ Onyx.connect({ let isSingleNewDotEntry: boolean | undefined; Onyx.connect({ - key: ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY, + key: ONYXKEYS.HYBRID_APP, callback: (value) => { if (!value) { return; } - isSingleNewDotEntry = value; + isSingleNewDotEntry = value?.isSingleNewDotEntry; }, }); diff --git a/src/libs/actions/HybridApp/index.ts b/src/libs/actions/HybridApp/index.ts index 271b91aa99ee..0bcda22b8b2c 100644 --- a/src/libs/actions/HybridApp/index.ts +++ b/src/libs/actions/HybridApp/index.ts @@ -30,10 +30,6 @@ function setUseNewDotSignInPage(useNewDotSignInPage: boolean) { return Onyx.merge(ONYXKEYS.HYBRID_APP, {useNewDotSignInPage}); } -function setIsRootStatusBarEnabled(isRootStatusBarEnabled: boolean) { - return Onyx.merge(ONYXKEYS.HYBRID_APP, {isRootStatusBarEnabled}); -} - /* * Starts HybridApp sign-in flow from the beginning. */ @@ -64,4 +60,4 @@ function prepareHybridAppAfterTransitionToNewDot(hybridApp: HybridApp) { }); } -export {parseHybridAppSettings, setReadyToShowAuthScreens, setNewDotSignInState, resetSignInFlow, prepareHybridAppAfterTransitionToNewDot, setUseNewDotSignInPage, setIsRootStatusBarEnabled}; +export {parseHybridAppSettings, setReadyToShowAuthScreens, setNewDotSignInState, resetSignInFlow, prepareHybridAppAfterTransitionToNewDot, setUseNewDotSignInPage}; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 7e076ee157fd..c35be3408d33 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -529,24 +529,8 @@ function signUpUser() { }); } -type HybridAppSettings = { - email: string; - authToken: string; - accountID: number; - autoGeneratedLogin: string; - autoGeneratedPassword: string; - clearOnyxOnStart: boolean; - completedHybridAppOnboarding: boolean; - isSingleNewDotEntry: boolean; - primaryLogin: string; - encryptedAuthToken: string; - nudgeMigrationTimestamp?: string; - oldDotOriginalAccountEmail?: string; -}; - function setupNewDotAfterTransitionFromOldDot(hybridAppSettings: string, tryNewDot?: TryNewDot) { - const parsedHybridAppSettings = HybridAppActions.parseHybridAppSettings(hybridAppSettings); - const {initialOnyxValues} = parsedHybridAppSettings; + const {initialOnyxValues} = HybridAppActions.parseHybridAppSettings(hybridAppSettings); const {hybridApp, ...newDotOnyxValues} = initialOnyxValues; const clearOnyxBeforeSignIn = () => { diff --git a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx index 805d53700901..79d090debe90 100644 --- a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx +++ b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx @@ -1,7 +1,8 @@ import HybridAppModule from '@expensify/react-native-hybrid-app'; -import React, {useMemo, useState} from 'react'; +import React, {useContext, useMemo, useState} from 'react'; import {useOnyx} from 'react-native-onyx'; import Button from '@components/Button'; +import CustomStatusBarAndBackgroundContext from '@components/CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import FormHelpMessage from '@components/FormHelpMessage'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; @@ -16,7 +17,6 @@ import getPlatform from '@libs/getPlatform'; import Navigation from '@libs/Navigation/Navigation'; import {isPaidGroupPolicy} from '@libs/PolicyUtils'; import {openOldDotLink} from '@userActions/Link'; -import {setIsRootStatusBarEnabled} from '@userActions/HybridApp'; import {createWorkspace, generatePolicyID} from '@userActions/Policy/Policy'; import {completeOnboarding} from '@userActions/Report'; import {setOnboardingAdminsChatReportID, setOnboardingCompanySize, setOnboardingPolicyID, switchToOldDotOnNonMicroCompanySize} from '@userActions/Welcome'; @@ -38,6 +38,7 @@ function BaseOnboardingEmployees({shouldUseNativeStyles, route}: BaseOnboardingE const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID); const [onboardingAdminsChatReportID] = useOnyx(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID); const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); + const {setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext); const paidGroupPolicy = Object.values(allPolicies ?? {}).find(isPaidGroupPolicy); @@ -112,7 +113,7 @@ function BaseOnboardingEmployees({shouldUseNativeStyles, route}: BaseOnboardingE if (CONFIG.IS_HYBRID_APP) { HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); - setIsRootStatusBarEnabled(false); + setRootStatusBarEnabled(false); } else { openOldDotLink(CONST.OLDDOT_URLS.INBOX, true); } diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 161bb6791f29..b771aa7412b0 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -9,6 +9,7 @@ import type {ValueOf} from 'type-fest'; import AccountSwitcher from '@components/AccountSwitcher'; import AccountSwitcherSkeletonView from '@components/AccountSwitcherSkeletonView'; import ConfirmModal from '@components/ConfirmModal'; +import CustomStatusBarAndBackgroundContext from '@components/CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import DelegateNoAccessModal from '@components/DelegateNoAccessModal'; import Icon from '@components/Icon'; import * as Expensicons from '@components/Icon/Expensicons'; @@ -40,7 +41,6 @@ import * as ReportActionContextMenu from '@pages/home/report/ContextMenu/ReportA import variables from '@styles/variables'; import {confirmReadyToOpenApp} from '@userActions/App'; import * as HybridAppActions from '@userActions/HybridApp'; -import {setIsRootStatusBarEnabled} from '@userActions/HybridApp'; import {buildOldDotURL, openExternalLink, openOldDotLink} from '@userActions/Link'; import {hasPaymentMethodError} from '@userActions/PaymentMethods'; import {isSupportAuthToken, signOutAndRedirectToSignIn} from '@userActions/Session'; diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 64b4d83284a6..d305031b20c6 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -1,7 +1,7 @@ import {useIsFocused} from '@react-navigation/native'; import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react'; import type {ForwardedRef} from 'react'; -import {NativeModules, View} from 'react-native'; +import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import Button from '@components/Button'; import SafariFormWrapper from '@components/Form/SafariFormWrapper'; @@ -27,6 +27,7 @@ import Terms from '@pages/signin/Terms'; import * as HybridAppActions from '@userActions/HybridApp'; import * as SessionActions from '@userActions/Session'; import * as User from '@userActions/User'; +import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -154,7 +155,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * Trigger the reset validate code flow and ensure the 2FA input field is reset to avoid it being permanently hidden */ const resendValidateCode = () => { - if (NativeModules.HybridAppModule) { + if (CONFIG.IS_HYBRID_APP) { HybridAppActions.resetSignInFlow(); } @@ -237,7 +238,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * Check that all the form fields are valid, then trigger the submit callback */ const validateAndSubmitForm = useCallback(() => { - if (NativeModules.HybridAppModule && session?.authToken) { + if (CONFIG.IS_HYBRID_APP && session?.authToken) { HybridAppActions.resetSignInFlow(); } diff --git a/src/types/onyx/HybridApp.ts b/src/types/onyx/HybridApp.ts index 816d9227bfaf..825389ec38fb 100644 --- a/src/types/onyx/HybridApp.ts +++ b/src/types/onyx/HybridApp.ts @@ -41,9 +41,6 @@ type HybridApp = { /** */ delegateAccessData?: HybridAppDelegateAccessData; - - /** */ - isRootStatusBarEnabled?: boolean; }; export default HybridApp; From a695ee30805fad4c5af5938eb284b09ff59abdb7 Mon Sep 17 00:00:00 2001 From: war-in Date: Mon, 17 Mar 2025 14:56:01 +0100 Subject: [PATCH 48/95] fix status bar --- modules/hybrid-app/src/index.native.ts | 2 ++ src/components/BookTravelButton.tsx | 1 - .../CustomStatusBarAndBackground/index.tsx | 2 +- src/components/ScreenWrapper.tsx | 3 +-- src/libs/actions/HybridApp/index.ts | 6 +++++- src/libs/actions/Session/index.ts | 12 ++++++++++-- .../OnboardingEmployees/BaseOnboardingEmployees.tsx | 1 - .../home/sidebar/FloatingActionButtonAndPopover.tsx | 1 - src/pages/settings/InitialSettingsPage.tsx | 5 +---- src/types/onyx/HybridApp.ts | 3 +++ 10 files changed, 23 insertions(+), 13 deletions(-) diff --git a/modules/hybrid-app/src/index.native.ts b/modules/hybrid-app/src/index.native.ts index 3ba899af6ad3..7d8b6d3fab0f 100644 --- a/modules/hybrid-app/src/index.native.ts +++ b/modules/hybrid-app/src/index.native.ts @@ -1,3 +1,4 @@ +import {setClosingReactNativeApp} from '@userActions/HybridApp'; import ReactNativeHybridApp from './NativeReactNativeHybridApp'; import type HybridAppModuleType from './types'; @@ -6,6 +7,7 @@ const HybridAppModule: HybridAppModuleType = { return ReactNativeHybridApp.isHybridApp(); }, closeReactNativeApp({shouldSignOut, shouldSetNVP}) { + setClosingReactNativeApp(true); ReactNativeHybridApp.closeReactNativeApp(shouldSignOut, shouldSetNVP); }, completeOnboarding({status}) { diff --git a/src/components/BookTravelButton.tsx b/src/components/BookTravelButton.tsx index 66f8631d3487..7f2be3c904e9 100644 --- a/src/components/BookTravelButton.tsx +++ b/src/components/BookTravelButton.tsx @@ -87,7 +87,6 @@ function BookTravelButton({text}: BookTravelButtonProps) { // Close NewDot if it was opened only for Travel, as its purpose is now fulfilled. Log.info('[HybridApp] Returning to OldDot after opening TravelDot'); HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); - setRootStatusBarEnabled(false); }) ?.catch(() => { setErrorMessage(translate('travel.errorMessage')); diff --git a/src/components/CustomStatusBarAndBackground/index.tsx b/src/components/CustomStatusBarAndBackground/index.tsx index 3fef4fedb3a1..f61516d6ec64 100644 --- a/src/components/CustomStatusBarAndBackground/index.tsx +++ b/src/components/CustomStatusBarAndBackground/index.tsx @@ -23,7 +23,7 @@ function CustomStatusBarAndBackground({isNested = false}: CustomStatusBarAndBack const [statusBarStyle, setStatusBarStyle] = useState(); const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); - const isDisabled = !isNested && !isRootStatusBarEnabled; + const isDisabled = (!isNested && !isRootStatusBarEnabled) || (hybridApp?.closingReactNativeApp ?? false); // Disable the root status bar when a nested status bar is rendered useEffect(() => { diff --git a/src/components/ScreenWrapper.tsx b/src/components/ScreenWrapper.tsx index 18e93906c38b..55735c2b9512 100644 --- a/src/components/ScreenWrapper.tsx +++ b/src/components/ScreenWrapper.tsx @@ -7,7 +7,6 @@ import {Keyboard, PanResponder, View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import {PickerAvoidingView} from 'react-native-picker-select'; import type {EdgeInsets} from 'react-native-safe-area-context'; -import CustomStatusBarAndBackgroundContext from './CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import useBottomSafeSafeAreaPaddingStyle from '@hooks/useBottomSafeSafeAreaPaddingStyle'; import useEnvironment from '@hooks/useEnvironment'; import useInitialDimensions from '@hooks/useInitialWindowDimensions'; @@ -26,6 +25,7 @@ import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import CustomDevMenu from './CustomDevMenu'; +import CustomStatusBarAndBackgroundContext from './CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import FocusTrapForScreens from './FocusTrap/FocusTrapForScreen'; import type FocusTrapForScreenProps from './FocusTrap/FocusTrapForScreen/FocusTrapProps'; import HeaderGap from './HeaderGap'; @@ -203,7 +203,6 @@ function ScreenWrapper( return; } HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); - setRootStatusBarEnabled(false); }); const panResponder = useRef( diff --git a/src/libs/actions/HybridApp/index.ts b/src/libs/actions/HybridApp/index.ts index 0bcda22b8b2c..1dccba1fa573 100644 --- a/src/libs/actions/HybridApp/index.ts +++ b/src/libs/actions/HybridApp/index.ts @@ -30,6 +30,10 @@ function setUseNewDotSignInPage(useNewDotSignInPage: boolean) { return Onyx.merge(ONYXKEYS.HYBRID_APP, {useNewDotSignInPage}); } +function setClosingReactNativeApp(closingReactNativeApp: boolean) { + Onyx.merge(ONYXKEYS.HYBRID_APP, {closingReactNativeApp}); +} + /* * Starts HybridApp sign-in flow from the beginning. */ @@ -60,4 +64,4 @@ function prepareHybridAppAfterTransitionToNewDot(hybridApp: HybridApp) { }); } -export {parseHybridAppSettings, setReadyToShowAuthScreens, setNewDotSignInState, resetSignInFlow, prepareHybridAppAfterTransitionToNewDot, setUseNewDotSignInPage}; +export {parseHybridAppSettings, setReadyToShowAuthScreens, setNewDotSignInState, resetSignInFlow, prepareHybridAppAfterTransitionToNewDot, setUseNewDotSignInPage, setClosingReactNativeApp}; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index c35be3408d33..c71ad2956b63 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -580,13 +580,21 @@ function setupNewDotAfterTransitionFromOldDot(hybridAppSettings: string, tryNewD encryptedAuthToken: decodeURIComponent(hybridApp?.delegateAccessData?.oldDotCurrentEncryptedAuthToken ?? ''), accountID: hybridApp?.delegateAccessData?.oldDotCurrentAccountID, }, - [ONYXKEYS.CREDENTIALS]: {autoGeneratedLogin: credentials?.autoGeneratedLogin, autoGeneratedPassword: credentials?.autoGeneratedPassword}, + [ONYXKEYS.CREDENTIALS]: { + autoGeneratedLogin: credentials?.autoGeneratedLogin, + autoGeneratedPassword: credentials?.autoGeneratedPassword, + }, }) .then(() => Onyx.merge(ONYXKEYS.ACCOUNT, {primaryLogin: hybridApp?.delegateAccessData?.oldDotCurrentUserEmail})) .then(() => openApp()), ); }) - .then(() => HybridAppActions.prepareHybridAppAfterTransitionToNewDot(hybridApp)) + .then(() => + HybridAppActions.prepareHybridAppAfterTransitionToNewDot({ + ...hybridApp, + closingReactNativeApp: false, + }), + ) .then(resetDidUserLoginDuringSessionIfNeeded) .then(() => Onyx.multiSet(newDotOnyxValues)) .catch((error) => { diff --git a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx index 79d090debe90..ecd764e19181 100644 --- a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx +++ b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx @@ -113,7 +113,6 @@ function BaseOnboardingEmployees({shouldUseNativeStyles, route}: BaseOnboardingE if (CONFIG.IS_HYBRID_APP) { HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); - setRootStatusBarEnabled(false); } else { openOldDotLink(CONST.OLDDOT_URLS.INBOX, true); } diff --git a/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx index b574bdd07688..f562bfc9abea 100644 --- a/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx @@ -615,7 +615,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT setModalVisible(false); if (CONFIG.IS_HYBRID_APP) { HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); - setRootStatusBarEnabled(false); return; } openOldDotLink(CONST.OLDDOT_URLS.INBOX); diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index b771aa7412b0..23a392dd8694 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -251,10 +251,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr icon: Expensicons.ExpensifyLogoNew, ...(CONFIG.IS_HYBRID_APP ? { - action: () => { - HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); - setRootStatusBarEnabled(false); - }, + action: () => HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}), } : { action() { diff --git a/src/types/onyx/HybridApp.ts b/src/types/onyx/HybridApp.ts index 825389ec38fb..e464c11cfd65 100644 --- a/src/types/onyx/HybridApp.ts +++ b/src/types/onyx/HybridApp.ts @@ -41,6 +41,9 @@ type HybridApp = { /** */ delegateAccessData?: HybridAppDelegateAccessData; + + /** */ + closingReactNativeApp?: boolean; }; export default HybridApp; From 3b82ff2347a29f31a9a6cbe62bde5855026a26c4 Mon Sep 17 00:00:00 2001 From: war-in Date: Mon, 17 Mar 2025 15:01:59 +0100 Subject: [PATCH 49/95] fix lint --- src/components/BookTravelButton.tsx | 6 ++---- src/components/ScreenWrapper.tsx | 2 -- src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx | 4 +--- src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx | 5 +---- src/pages/settings/InitialSettingsPage.tsx | 4 +--- 5 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/components/BookTravelButton.tsx b/src/components/BookTravelButton.tsx index 7f2be3c904e9..87749ba06b9b 100644 --- a/src/components/BookTravelButton.tsx +++ b/src/components/BookTravelButton.tsx @@ -1,6 +1,6 @@ import HybridAppModule from '@expensify/react-native-hybrid-app'; import {Str} from 'expensify-common'; -import React, {useCallback, useContext, useState} from 'react'; +import React, {useCallback, useState} from 'react'; import {useOnyx} from 'react-native-onyx'; import useLocalize from '@hooks/useLocalize'; import usePermissions from '@hooks/usePermissions'; @@ -20,7 +20,6 @@ import ROUTES from '@src/ROUTES'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import Button from './Button'; import ConfirmModal from './ConfirmModal'; -import CustomStatusBarAndBackgroundContext from './CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import DotIndicatorMessage from './DotIndicatorMessage'; import {RocketDude} from './Icon/Illustrations'; @@ -45,7 +44,6 @@ function BookTravelButton({text}: BookTravelButtonProps) { const [primaryLogin] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => account?.primaryLogin}); const [sessionEmail] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.email}); const primaryContactMethod = primaryLogin ?? sessionEmail ?? ''; - const {setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext); const {isBlockedFromSpotnanaTravel} = usePermissions(); const [isPreventionModalVisible, setPreventionModalVisibility] = useState(false); @@ -113,7 +111,7 @@ function BookTravelButton({text}: BookTravelButtonProps) { Navigation.navigate(ROUTES.TRAVEL_DOMAIN_SELECTOR); } } - }, [policy, hybridApp?.isSingleNewDotEntry, travelSettings, translate, primaryContactMethod, setRootStatusBarEnabled, isBlockedFromSpotnanaTravel]); + }, [policy, hybridApp?.isSingleNewDotEntry, travelSettings, translate, primaryContactMethod, isBlockedFromSpotnanaTravel]); return ( <> diff --git a/src/components/ScreenWrapper.tsx b/src/components/ScreenWrapper.tsx index 55735c2b9512..44ef4a72741f 100644 --- a/src/components/ScreenWrapper.tsx +++ b/src/components/ScreenWrapper.tsx @@ -25,7 +25,6 @@ import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import CustomDevMenu from './CustomDevMenu'; -import CustomStatusBarAndBackgroundContext from './CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import FocusTrapForScreens from './FocusTrap/FocusTrapForScreen'; import type FocusTrapForScreenProps from './FocusTrap/FocusTrapForScreen/FocusTrapProps'; import HeaderGap from './HeaderGap'; @@ -179,7 +178,6 @@ function ScreenWrapper( const {windowHeight} = useWindowDimensions(shouldUseCachedViewportHeight); // since Modals are drawn in separate native view hierarchy we should always add paddings const ignoreInsetsConsumption = !useContext(ModalContext).default; - const {setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext); const {initialURL} = useContext(InitialURLContext); const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); diff --git a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx index ecd764e19181..23c40342c16d 100644 --- a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx +++ b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx @@ -1,8 +1,7 @@ import HybridAppModule from '@expensify/react-native-hybrid-app'; -import React, {useContext, useMemo, useState} from 'react'; +import React, {useMemo, useState} from 'react'; import {useOnyx} from 'react-native-onyx'; import Button from '@components/Button'; -import CustomStatusBarAndBackgroundContext from '@components/CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import FormHelpMessage from '@components/FormHelpMessage'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; @@ -38,7 +37,6 @@ function BaseOnboardingEmployees({shouldUseNativeStyles, route}: BaseOnboardingE const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID); const [onboardingAdminsChatReportID] = useOnyx(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID); const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); - const {setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext); const paidGroupPolicy = Object.values(allPolicies ?? {}).find(isPaidGroupPolicy); diff --git a/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx index f562bfc9abea..5d073d3cc1c6 100644 --- a/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx @@ -2,13 +2,12 @@ import HybridAppModule from '@expensify/react-native-hybrid-app'; import {useIsFocused} from '@react-navigation/native'; import type {ImageContentFit} from 'expo-image'; import type {ForwardedRef} from 'react'; -import React, {forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react'; +import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react'; import {View} from 'react-native'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import {useOnyx} from 'react-native-onyx'; import type {SvgProps} from 'react-native-svg'; import ConfirmModal from '@components/ConfirmModal'; -import CustomStatusBarAndBackgroundContext from '@components/CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import FloatingActionButton from '@components/FloatingActionButton'; import * as Expensicons from '@components/Icon/Expensicons'; import type {PopoverMenuItem} from '@components/PopoverMenu'; @@ -211,8 +210,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT selector: hasSeenTourSelector, }); - const {setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext); - const {renderProductTrainingTooltip, hideProductTrainingTooltip, shouldShowProductTrainingTooltip} = useProductTrainingContext( CONST.PRODUCT_TRAINING_TOOLTIP_NAMES.QUICK_ACTION_BUTTON, isCreateMenuActive && (!shouldUseNarrowLayout || isFocused), diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 23a392dd8694..9e8dd718401a 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -9,7 +9,6 @@ import type {ValueOf} from 'type-fest'; import AccountSwitcher from '@components/AccountSwitcher'; import AccountSwitcherSkeletonView from '@components/AccountSwitcherSkeletonView'; import ConfirmModal from '@components/ConfirmModal'; -import CustomStatusBarAndBackgroundContext from '@components/CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import DelegateNoAccessModal from '@components/DelegateNoAccessModal'; import Icon from '@components/Icon'; import * as Expensicons from '@components/Icon/Expensicons'; @@ -104,7 +103,6 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr const focusedRouteName = useNavigationState((state) => findFocusedRoute(state)?.name); const emojiCode = currentUserPersonalDetails?.status?.emojiCode ?? ''; const [allConnectionSyncProgresses] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}`); - const {setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext); const [privateSubscription] = useOnyx(ONYXKEYS.NVP_PRIVATE_SUBSCRIPTION); const subscriptionPlan = useSubscriptionPlan(); @@ -297,7 +295,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr }, ], }; - }, [styles.pt4, setRootStatusBarEnabled, isActingAsDelegate, shouldOpenBookACall, signOut]); + }, [styles.pt4, isActingAsDelegate, shouldOpenBookACall, signOut]); /** * Retuns JSX.Element with menu items From 8ca7eecbc14de10adbbee8ae1ec708dd348020a2 Mon Sep 17 00:00:00 2001 From: war-in Date: Wed, 19 Mar 2025 13:11:31 +0100 Subject: [PATCH 50/95] fix broken sign in logic --- src/App.tsx | 1 + src/libs/HybridApp.ts | 2 -- src/libs/Navigation/AppNavigator/index.native.tsx | 7 +------ .../signin/ValidateCodeForm/BaseValidateCodeForm.tsx | 12 ++++++------ 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 3e6fc9ac2a27..064cf9c1aecb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -41,6 +41,7 @@ import OnyxUpdateManager from './libs/actions/OnyxUpdateManager'; import {ReportAttachmentsProvider} from './pages/home/report/ReportAttachmentsContext'; import type {Route} from './ROUTES'; import './setup/backgroundTask'; +import './libs/HybridApp'; import {SplashScreenStateContextProvider} from './SplashScreenStateContext'; /** diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index e6df6292b2e9..18151b42a4a1 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -91,5 +91,3 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryN currentHybridApp = hybridApp; currentTryNewDot = tryNewDot; } - -export default {shouldUseOldApp}; diff --git a/src/libs/Navigation/AppNavigator/index.native.tsx b/src/libs/Navigation/AppNavigator/index.native.tsx index ccdc5492eaed..757783675932 100644 --- a/src/libs/Navigation/AppNavigator/index.native.tsx +++ b/src/libs/Navigation/AppNavigator/index.native.tsx @@ -1,7 +1,6 @@ import React, {memo, useContext, useEffect, useMemo} from 'react'; import {useOnyx} from 'react-native-onyx'; import {InitialURLContext} from '@components/InitialURLContextProvider'; -import HybridApp from '@libs/HybridApp'; import Navigation from '@libs/Navigation/Navigation'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -14,19 +13,15 @@ type AppNavigatorProps = { function AppNavigator({authenticated}: AppNavigatorProps) { const {initialURL} = useContext(InitialURLContext); - const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); const shouldShowAuthScreens = useMemo(() => { if (!CONFIG.IS_HYBRID_APP) { return authenticated; } - if (HybridApp.shouldUseOldApp(tryNewDot) && !hybridApp?.isSingleNewDotEntry) { - return false; - } return authenticated && (!hybridApp?.useNewDotSignInPage || hybridApp?.readyToShowAuthScreens); - }, [tryNewDot, hybridApp?.isSingleNewDotEntry, hybridApp?.useNewDotSignInPage, hybridApp?.readyToShowAuthScreens, authenticated]); + }, [hybridApp?.useNewDotSignInPage, hybridApp?.readyToShowAuthScreens, authenticated]); useEffect(() => { if (!CONFIG.IS_HYBRID_APP || !initialURL || !shouldShowAuthScreens) { diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index d305031b20c6..698237a8142d 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -52,6 +52,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const [account] = useOnyx(ONYXKEYS.ACCOUNT); const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); const [session] = useOnyx(ONYXKEYS.SESSION); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); @@ -238,13 +239,12 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * Check that all the form fields are valid, then trigger the submit callback */ const validateAndSubmitForm = useCallback(() => { - if (CONFIG.IS_HYBRID_APP && session?.authToken) { - HybridAppActions.resetSignInFlow(); - } - - if (account?.isLoading) { + if (account?.isLoading || hybridApp?.readyToShowAuthScreens) { return; } + if (CONFIG.IS_HYBRID_APP) { + HybridAppActions.resetSignInFlow(); + } if (account?.errors) { SessionActions.clearAccountMessages(); } @@ -299,7 +299,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco } else { SessionActions.signIn(validateCode, recoveryCodeOr2faCode); } - }, [session?.authToken, account?.isLoading, account?.errors, account?.requiresTwoFactorAuth, isUsingRecoveryCode, recoveryCode, twoFactorAuthCode, credentials?.accountID, validateCode]); + }, [account?.isLoading, account?.errors, account?.requiresTwoFactorAuth, hybridApp?.readyToShowAuthScreens, isUsingRecoveryCode, recoveryCode, twoFactorAuthCode, credentials?.accountID, validateCode]); return ( From 47ac77d0d099db26f12e81ac420cd7ad7cccd2e5 Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 1 Apr 2025 13:05:27 +0200 Subject: [PATCH 51/95] fix backend issue --- src/libs/HybridApp.ts | 8 ++++++++ src/libs/actions/Session/index.ts | 14 ++------------ .../ValidateCodeForm/BaseValidateCodeForm.tsx | 16 ++++++++++++++-- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 18151b42a4a1..1667900e73e4 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -13,6 +13,14 @@ let currentHybridApp: OnyxEntry; let currentTryNewDot: OnyxEntry; let currentCredentials: OnyxEntry; +// this code fixes bug on backend side, remove it once backend is fixed +Onyx.connect({ + key: 'tryNewDot', + callback: (tryNewDot) => { + Onyx.merge(ONYXKEYS.NVP_TRYNEWDOT, tryNewDot); + }, +}); + Onyx.connect({ key: ONYXKEYS.HYBRID_APP, callback: (hybridApp) => { diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index ffff17b0182d..620760e45762 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -526,12 +526,7 @@ function signUpUser() { const params: SignUpUserParams = {email: credentials.login, preferredLocale}; // eslint-disable-next-line rulesdir/no-api-side-effects-method - API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.SIGN_UP_USER, params, {optimisticData, successData, failureData}).then((response) => { - if (!response) { - return; - } - Onyx.merge(ONYXKEYS.NVP_TRYNEWDOT, {classicRedirect: {dismissed: !response.tryNewDot}}); - }); + API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.SIGN_UP_USER, params, {optimisticData, successData, failureData}).then(() => {}); } function setupNewDotAfterTransitionFromOldDot(hybridAppSettings: string, tryNewDot?: TryNewDot) { @@ -710,12 +705,7 @@ function signIn(validateCode: string, twoFactorAuthCode?: string) { optimisticData, successData, failureData, - }).then((response) => { - if (!response) { - return; - } - Onyx.merge(ONYXKEYS.NVP_TRYNEWDOT, {classicRedirect: {dismissed: !response.tryNewDot}}); - }); + }).then(() => {}); }); } diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 698237a8142d..9a658dad80eb 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -239,7 +239,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * Check that all the form fields are valid, then trigger the submit callback */ const validateAndSubmitForm = useCallback(() => { - if (account?.isLoading || hybridApp?.readyToShowAuthScreens) { + if (account?.isLoading || hybridApp?.readyToShowAuthScreens || hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED || session?.authToken) { return; } if (CONFIG.IS_HYBRID_APP) { @@ -299,7 +299,19 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco } else { SessionActions.signIn(validateCode, recoveryCodeOr2faCode); } - }, [account?.isLoading, account?.errors, account?.requiresTwoFactorAuth, hybridApp?.readyToShowAuthScreens, isUsingRecoveryCode, recoveryCode, twoFactorAuthCode, credentials?.accountID, validateCode]); + }, [ + account?.isLoading, + account?.errors, + account?.requiresTwoFactorAuth, + hybridApp?.readyToShowAuthScreens, + hybridApp?.newDotSignInState, + session?.authToken, + isUsingRecoveryCode, + recoveryCode, + twoFactorAuthCode, + credentials?.accountID, + validateCode, + ]); return ( From 5934f1552b4bb584f057c63ff37165703c28d5f7 Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 1 Apr 2025 15:50:24 +0200 Subject: [PATCH 52/95] fix wrong if --- src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 9a658dad80eb..273101530c21 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -239,7 +239,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * Check that all the form fields are valid, then trigger the submit callback */ const validateAndSubmitForm = useCallback(() => { - if (account?.isLoading || hybridApp?.readyToShowAuthScreens || hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED || session?.authToken) { + if (account?.isLoading || hybridApp?.readyToShowAuthScreens || session?.authToken) { return; } if (CONFIG.IS_HYBRID_APP) { From e23956a0c3eb39523a28a7cfc2eaffd709fcbbad Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 1 Apr 2025 18:50:15 +0200 Subject: [PATCH 53/95] use useFocusEffect instead of useEffect and migrate component to useOnyx --- src/pages/signin/ChooseSSOOrMagicCode.tsx | 41 ++++++++++------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/src/pages/signin/ChooseSSOOrMagicCode.tsx b/src/pages/signin/ChooseSSOOrMagicCode.tsx index 2551fe34a21b..91a355bad2ab 100644 --- a/src/pages/signin/ChooseSSOOrMagicCode.tsx +++ b/src/pages/signin/ChooseSSOOrMagicCode.tsx @@ -1,7 +1,7 @@ -import React, {useEffect} from 'react'; +import {useFocusEffect} from '@react-navigation/native'; +import React, {useCallback} from 'react'; import {Keyboard, View} from 'react-native'; -import {withOnyx} from 'react-native-onyx'; -import type {OnyxEntry} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import Button from '@components/Button'; import FormHelpMessage from '@components/FormHelpMessage'; import Text from '@components/Text'; @@ -16,38 +16,34 @@ import * as Session from '@userActions/Session'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {Account, Credentials} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import ChangeExpensifyLoginLink from './ChangeExpensifyLoginLink'; import Terms from './Terms'; -type ChooseSSOOrMagicCodeOnyxProps = { - /** The credentials of the logged in person */ - credentials: OnyxEntry; - - /** The details about the account that the user is signing in with */ - account: OnyxEntry; -}; - -type ChooseSSOOrMagicCodeProps = ChooseSSOOrMagicCodeOnyxProps & { +type ChooseSSOOrMagicCodeProps = { /** Function that returns whether the user is using SAML or magic codes to log in */ setIsUsingMagicCode: (value: boolean) => void; }; -function ChooseSSOOrMagicCode({credentials, account, setIsUsingMagicCode}: ChooseSSOOrMagicCodeProps) { +function ChooseSSOOrMagicCode({setIsUsingMagicCode}: ChooseSSOOrMagicCodeProps) { const styles = useThemeStyles(); const {isKeyboardShown} = useKeyboardState(); const {translate} = useLocalize(); const {isOffline} = useNetwork(); const {shouldUseNarrowLayout} = useResponsiveLayout(); + const [account] = useOnyx(ONYXKEYS.ACCOUNT); + const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); + // This view doesn't have a field for user input, so dismiss the device keyboard if shown - useEffect(() => { - if (!isKeyboardShown) { - return; - } - Keyboard.dismiss(); - }, [isKeyboardShown]); + useFocusEffect( + useCallback(() => { + if (!isKeyboardShown) { + return; + } + Keyboard.dismiss(); + }, [isKeyboardShown]), + ); return ( <> @@ -94,7 +90,4 @@ function ChooseSSOOrMagicCode({credentials, account, setIsUsingMagicCode}: Choos ChooseSSOOrMagicCode.displayName = 'ChooseSSOOrMagicCode'; -export default withOnyx({ - credentials: {key: ONYXKEYS.CREDENTIALS}, - account: {key: ONYXKEYS.ACCOUNT}, -})(ChooseSSOOrMagicCode); +export default ChooseSSOOrMagicCode; From b4d244351c226feed030f2ca4a4bf2142875660e Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 8 Apr 2025 14:56:10 +0200 Subject: [PATCH 54/95] remove temporary fix --- src/libs/HybridApp.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 1667900e73e4..18151b42a4a1 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -13,14 +13,6 @@ let currentHybridApp: OnyxEntry; let currentTryNewDot: OnyxEntry; let currentCredentials: OnyxEntry; -// this code fixes bug on backend side, remove it once backend is fixed -Onyx.connect({ - key: 'tryNewDot', - callback: (tryNewDot) => { - Onyx.merge(ONYXKEYS.NVP_TRYNEWDOT, tryNewDot); - }, -}); - Onyx.connect({ key: ONYXKEYS.HYBRID_APP, callback: (hybridApp) => { From ee3e9048517f1c2415631bb732c48cbae15013e8 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Tue, 22 Apr 2025 15:00:18 +0200 Subject: [PATCH 55/95] fix navigation from OD --- src/components/InitialURLContextProvider.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index b4458ae7f22c..fbbb36fdf7c2 100644 --- a/src/components/InitialURLContextProvider.tsx +++ b/src/components/InitialURLContextProvider.tsx @@ -1,9 +1,9 @@ import React, {createContext, useEffect, useMemo, useRef, useState} from 'react'; import type {ReactNode} from 'react'; import {Linking} from 'react-native'; -import Navigation from '@navigation/Navigation'; import {useOnyx} from 'react-native-onyx'; import {setupNewDotAfterTransitionFromOldDot} from '@libs/actions/Session'; +import Navigation from '@navigation/Navigation'; import type {AppProps} from '@src/App'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -49,7 +49,18 @@ function InitialURLContextProvider({children, url, hybridAppSettings, timestamp} } setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); }); + return; } + setInitialURL(url); + Navigation.isNavigationReady().then(() => { + Navigation.navigate(url); + }); + + if (splashScreenState === CONST.BOOT_SPLASH_STATE.HIDDEN) { + return; + } + setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); + return; } Linking.getInitialURL().then((initURL) => { From 8d1d5c77c02f71d872305b6b8ea993de2b2f333a Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Tue, 6 May 2025 09:29:17 +0200 Subject: [PATCH 56/95] post-merge new onyxkeys names fix --- src/components/InitialURLContextProvider.tsx | 2 +- src/libs/HybridApp.ts | 2 +- src/libs/actions/HybridApp/types.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index 6caef263fc11..3f7fb675eb3c 100644 --- a/src/components/InitialURLContextProvider.tsx +++ b/src/components/InitialURLContextProvider.tsx @@ -33,7 +33,7 @@ type InitialURLContextProviderProps = AppProps & { function InitialURLContextProvider({children, url, hybridAppSettings, timestamp}: InitialURLContextProviderProps) { const [initialURL, setInitialURL] = useState(); const {splashScreenState, setSplashScreenState} = useSplashScreenStateContext(); - const [tryNewDot, tryNewDotMetadata] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT); + const [tryNewDot, tryNewDotMetadata] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT); // We use `setupCalled` ref to guarantee that `signInAfterTransitionFromOldDot` is called once. const setupCalled = useRef(false); diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 18151b42a4a1..a6c69b3e3fa6 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -21,7 +21,7 @@ Onyx.connect({ }); Onyx.connect({ - key: ONYXKEYS.NVP_TRYNEWDOT, + key: ONYXKEYS.NVP_TRY_NEW_DOT, callback: (tryNewDot) => { handleChangeInHybridAppSignInFlow(currentHybridApp, tryNewDot, currentCredentials); }, diff --git a/src/libs/actions/HybridApp/types.ts b/src/libs/actions/HybridApp/types.ts index 1b45aca6417c..228c6969d29a 100644 --- a/src/libs/actions/HybridApp/types.ts +++ b/src/libs/actions/HybridApp/types.ts @@ -5,8 +5,8 @@ import type HybridApp from '@src/types/onyx/HybridApp'; type HybridAppSettings = { initialOnyxValues: { [ONYXKEYS.HYBRID_APP]: HybridApp; - [ONYXKEYS.NVP_TRYNEWDOT]?: TryNewDot; - [ONYXKEYS.USER]?: {shouldUseStagingServer: boolean}; + [ONYXKEYS.NVP_TRY_NEW_DOT]?: TryNewDot; + [ONYXKEYS.ACCOUNT]?: {shouldUseStagingServer: boolean}; }; }; From 7d15876ab72bd6737fdf849b298cbd395be2f7b1 Mon Sep 17 00:00:00 2001 From: war-in Date: Wed, 7 May 2025 17:30:32 +0200 Subject: [PATCH 57/95] fix copilot navigation issue --- src/components/InitialURLContextProvider.tsx | 70 ++++++++------------ 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index 3f7fb675eb3c..b673d3f512e0 100644 --- a/src/components/InitialURLContextProvider.tsx +++ b/src/components/InitialURLContextProvider.tsx @@ -36,61 +36,49 @@ function InitialURLContextProvider({children, url, hybridAppSettings, timestamp} const [tryNewDot, tryNewDotMetadata] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT); // We use `setupCalled` ref to guarantee that `signInAfterTransitionFromOldDot` is called once. const setupCalled = useRef(false); + const isLoading = !isLoadingOnyxValue(tryNewDotMetadata); - useEffect(() => { - if (url && hybridAppSettings) { - if (!isLoadingOnyxValue(tryNewDotMetadata) && !setupCalled.current) { - setupCalled.current = true; - setupNewDotAfterTransitionFromOldDot(hybridAppSettings, tryNewDot).then(() => { - setInitialURL(url); + function handleNavigation(initialUrl: Route) { + setInitialURL(initialUrl); - const parsedUrl = Navigation.parseHybridAppUrl(url); - - Navigation.isNavigationReady().then(() => { - if (parsedUrl.startsWith(`/${ROUTES.SHARE_ROOT}`)) { - const focusRoute = findFocusedRoute(navigationRef.getRootState()); - if (focusRoute?.name === SCREENS.SHARE.SHARE_DETAILS || focusRoute?.name === SCREENS.SHARE.SUBMIT_DETAILS) { - Navigation.goBack(ROUTES.SHARE_ROOT); - return; - } - } - Navigation.navigate(parsedUrl); - }); + const parsedUrl = Navigation.parseHybridAppUrl(initialUrl); - if (splashScreenState === CONST.BOOT_SPLASH_STATE.HIDDEN) { - return; - } - setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); - }); - return; + Navigation.isNavigationReady().then(() => { + if (parsedUrl.startsWith(`/${ROUTES.SHARE_ROOT}`)) { + const focusRoute = findFocusedRoute(navigationRef.getRootState()); + if (focusRoute?.name === SCREENS.SHARE.SHARE_DETAILS || focusRoute?.name === SCREENS.SHARE.SUBMIT_DETAILS) { + Navigation.goBack(ROUTES.SHARE_ROOT); + return; + } } - setInitialURL(url); + Navigation.navigate(parsedUrl); + }); - const parsedUrl = Navigation.parseHybridAppUrl(url); + if (splashScreenState === CONST.BOOT_SPLASH_STATE.HIDDEN) { + return; + } + setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); + } - Navigation.isNavigationReady().then(() => { - if (parsedUrl.startsWith(`/${ROUTES.SHARE_ROOT}`)) { - const focusRoute = findFocusedRoute(navigationRef.getRootState()); - if (focusRoute?.name === SCREENS.SHARE.SHARE_DETAILS || focusRoute?.name === SCREENS.SHARE.SUBMIT_DETAILS) { - Navigation.goBack(ROUTES.SHARE_ROOT); - return; - } + useEffect(() => { + if (url && hybridAppSettings) { + if (!isLoading) { + if (!setupCalled.current) { + setupCalled.current = true; + setupNewDotAfterTransitionFromOldDot(hybridAppSettings, tryNewDot).then(() => { + handleNavigation(url); + }); + return; } - Navigation.navigate(parsedUrl); - }); - - if (splashScreenState === CONST.BOOT_SPLASH_STATE.HIDDEN) { - return; } - setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); - + handleNavigation(url); return; } Linking.getInitialURL().then((initURL) => { setInitialURL(initURL as Route); }); // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - }, [url, hybridAppSettings, timestamp, tryNewDot, tryNewDotMetadata]); + }, [url, hybridAppSettings, timestamp, isLoading]); const initialUrlContext = useMemo( () => ({ From 1a3f98844e958223063519388fbec38273284d19 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Fri, 9 May 2025 14:06:39 +0200 Subject: [PATCH 58/95] Fix condition and add useCallback --- src/components/InitialURLContextProvider.tsx | 41 +++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index b673d3f512e0..54ba0dd6f502 100644 --- a/src/components/InitialURLContextProvider.tsx +++ b/src/components/InitialURLContextProvider.tsx @@ -1,5 +1,5 @@ import {findFocusedRoute} from '@react-navigation/native'; -import React, {createContext, useEffect, useMemo, useRef, useState} from 'react'; +import React, {createContext, useCallback, useEffect, useMemo, useRef, useState} from 'react'; import type {ReactNode} from 'react'; import {Linking} from 'react-native'; import {useOnyx} from 'react-native-onyx'; @@ -36,29 +36,32 @@ function InitialURLContextProvider({children, url, hybridAppSettings, timestamp} const [tryNewDot, tryNewDotMetadata] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT); // We use `setupCalled` ref to guarantee that `signInAfterTransitionFromOldDot` is called once. const setupCalled = useRef(false); - const isLoading = !isLoadingOnyxValue(tryNewDotMetadata); + const isLoading = isLoadingOnyxValue(tryNewDotMetadata); - function handleNavigation(initialUrl: Route) { - setInitialURL(initialUrl); + const handleNavigation = useCallback( + (initialUrl: Route) => { + setInitialURL(initialUrl); - const parsedUrl = Navigation.parseHybridAppUrl(initialUrl); + const parsedUrl = Navigation.parseHybridAppUrl(initialUrl); - Navigation.isNavigationReady().then(() => { - if (parsedUrl.startsWith(`/${ROUTES.SHARE_ROOT}`)) { - const focusRoute = findFocusedRoute(navigationRef.getRootState()); - if (focusRoute?.name === SCREENS.SHARE.SHARE_DETAILS || focusRoute?.name === SCREENS.SHARE.SUBMIT_DETAILS) { - Navigation.goBack(ROUTES.SHARE_ROOT); - return; + Navigation.isNavigationReady().then(() => { + if (parsedUrl.startsWith(`/${ROUTES.SHARE_ROOT}`)) { + const focusRoute = findFocusedRoute(navigationRef.getRootState()); + if (focusRoute?.name === SCREENS.SHARE.SHARE_DETAILS || focusRoute?.name === SCREENS.SHARE.SUBMIT_DETAILS) { + Navigation.goBack(ROUTES.SHARE_ROOT); + return; + } } - } - Navigation.navigate(parsedUrl); - }); + Navigation.navigate(parsedUrl); + }); - if (splashScreenState === CONST.BOOT_SPLASH_STATE.HIDDEN) { - return; - } - setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); - } + if (splashScreenState === CONST.BOOT_SPLASH_STATE.HIDDEN) { + return; + } + setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); + }, + [splashScreenState, setSplashScreenState], + ); useEffect(() => { if (url && hybridAppSettings) { From 003d2157c5b1002dad38f1dbeb87aa49df4f9016 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Fri, 9 May 2025 14:27:18 +0200 Subject: [PATCH 59/95] Fix SAML flow --- src/libs/HybridApp.ts | 14 +++++++++++--- src/pages/signin/SAMLSignInPage/index.native.tsx | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index a6c69b3e3fa6..4f836644df9b 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -55,6 +55,11 @@ Onyx.connect({ }); function shouldUseOldApp(tryNewDot?: TryNewDot) { + // TODO: this is a workaround for backend issue with `tryNewDot` being an array + if (!tryNewDot || Array.isArray(tryNewDot)) { + return false; + } + return tryNewDot?.classicRedirect.dismissed === true; } @@ -69,8 +74,11 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryN return; } - if (hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && tryNewDot !== undefined && !!credentials?.autoGeneratedLogin && !!credentials?.autoGeneratedPassword) { - Log.info(`[HybridApp] Performing sign-in${shouldUseOldApp(tryNewDot) ? '' : ' (in background)'} on OldDot side`); + // TODO: add tryNewDot undefined check once the backend issue is fixed + if (hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && !!credentials?.autoGeneratedLogin && !!credentials?.autoGeneratedPassword) { + // It's better to not pass function directly to Log.info to avoid bugs with evaluation + const shouldUseOD = shouldUseOldApp(tryNewDot); + Log.info(`[HybridApp] Performing sign-in${shouldUseOD ? '' : ' (in background)'} on OldDot side`); HybridAppModule.signInToOldDot({ autoGeneratedLogin: credentials.autoGeneratedLogin, autoGeneratedPassword: credentials.autoGeneratedPassword, @@ -79,7 +87,7 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryN policyID: activePolicyID ?? '', }); HybridAppActions.setUseNewDotSignInPage(false).then(() => { - if (shouldUseOldApp(tryNewDot)) { + if (shouldUseOD) { HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); } else { Log.info('[HybridApp] The user should see NewDot. There is no need to block the user on the `SignInPage` until the sign-in process is completed on the OldDot side.'); diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index 2daa8ebce16b..1384fea5dd9a 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -7,6 +7,7 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton'; import SAMLLoadingIndicator from '@components/SAMLLoadingIndicator'; import ScreenWrapper from '@components/ScreenWrapper'; import useLocalize from '@hooks/useLocalize'; +import * as HybridAppActions from '@libs/actions/HybridApp'; import getPlatform from '@libs/getPlatform'; import getUAForWebView from '@libs/getUAForWebView'; import Log from '@libs/Log'; @@ -14,6 +15,7 @@ import {handleSAMLLoginError, postSAMLLogin} from '@libs/LoginUtils'; import Navigation from '@libs/Navigation/Navigation'; import {clearSignInData, setAccountError, signInWithShortLivedAuthToken} from '@userActions/Session'; import CONFIG from '@src/CONFIG'; +import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -69,6 +71,7 @@ function SAMLSignInPage() { if (!account?.isLoading && credentials?.login && !!shortLivedAuthToken) { Log.info('SAMLSignInPage - Successfully received shortLivedAuthToken. Signing in...'); signInWithShortLivedAuthToken(shortLivedAuthToken); + HybridAppActions.setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); } // If the login attempt is unsuccessful, set the error message for the account and redirect to sign in page From ed2866a5612826736235c5766c2b604860abebeb Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Fri, 9 May 2025 18:18:04 +0200 Subject: [PATCH 60/95] Add temporary growl in google sign in flow --- src/components/SignInButtons/GoogleSignIn/index.native.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/SignInButtons/GoogleSignIn/index.native.tsx b/src/components/SignInButtons/GoogleSignIn/index.native.tsx index 4a70a10ef017..72ce70809190 100644 --- a/src/components/SignInButtons/GoogleSignIn/index.native.tsx +++ b/src/components/SignInButtons/GoogleSignIn/index.native.tsx @@ -1,6 +1,7 @@ import {GoogleSignin, statusCodes} from '@react-native-google-signin/google-signin'; import React from 'react'; import IconButton from '@components/SignInButtons/IconButton'; +import Growl from '@libs/Growl'; import Log from '@libs/Log'; import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; @@ -38,8 +39,12 @@ function googleSignInRequest() { */ if (error.code === statusCodes.SIGN_IN_CANCELLED) { Log.info('[Google Sign In] Google Sign In cancelled'); + // TODO: Growl is temporary to allow debugging + Growl.error('[Google Sign In] Google Sign In cancelled'); } else { Log.alert(`[Google Sign In] Error Code: ${error.code}. ${error.message}`, {}, false); + // TODO: Growl is temporary to allow debugging + Growl.error(`[Google Sign In] Error Code: ${error.code}. ${error.message}`); } }); } From fe625b3e74593ec93a66575e1e2045278c499e26 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Mon, 12 May 2025 16:41:11 +0200 Subject: [PATCH 61/95] Fix sending authToken after signOut --- src/libs/actions/Session/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index dd5e8f05a8d3..b09bd3f9dfb7 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -72,6 +72,7 @@ const INVALID_TOKEN = 'pizza'; let session: Session = {}; let authPromiseResolver: ((value: boolean) => void) | null = null; +let isSetUpReady = false; let hasSwitchedAccountInHybridMode = false; @@ -86,7 +87,7 @@ Onyx.connect({ authPromiseResolver(true); authPromiseResolver = null; } - if (CONFIG.IS_HYBRID_APP && session.authToken && session.authToken !== INVALID_TOKEN) { + if (CONFIG.IS_HYBRID_APP && session.authToken && session.authToken !== INVALID_TOKEN && isSetUpReady) { HybridAppModule.sendAuthToken({authToken: session.authToken}); } }, @@ -593,6 +594,10 @@ function setupNewDotAfterTransitionFromOldDot(hybridAppSettings: string, tryNewD ) .then(resetDidUserLoginDuringSessionIfNeeded) .then(() => Onyx.multiSet(newDotOnyxValues)) + .then(() => { + isSetUpReady = true; + return Promise.resolve(); + }) .catch((error) => { Log.hmmm('[HybridApp] Initialization of HybridApp has failed. Forcing transition', {error}); }); From ac89c5e3c18c36a102c885f8c2e827d4d8b6ca66 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Mon, 12 May 2025 17:48:41 +0200 Subject: [PATCH 62/95] fix lint --- src/Expensify.tsx | 2 +- src/components/BookTravelButton.tsx | 2 +- src/components/CustomStatusBarAndBackground/index.tsx | 2 +- src/components/InitialURLContextProvider.tsx | 2 +- src/components/ScreenWrapper.tsx | 2 +- src/libs/HybridApp.ts | 8 ++++---- src/libs/Navigation/AppNavigator/index.native.tsx | 2 +- src/pages/settings/InitialSettingsPage.tsx | 1 - .../signin/ValidateCodeForm/BaseValidateCodeForm.tsx | 2 +- 9 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 1b49fa0333b3..d18ab2a2365b 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -104,7 +104,7 @@ function Expensify() { const [screenShareRequest] = useOnyx(ONYXKEYS.SCREEN_SHARE_REQUEST, {canBeMissing: true}); const [focusModeNotification] = useOnyx(ONYXKEYS.FOCUS_MODE_NOTIFICATION, {initWithStoredValues: false, canBeMissing: false}); const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH, {canBeMissing: false}); - const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP, {canBeMissing: true}); useDebugShortcut(); diff --git a/src/components/BookTravelButton.tsx b/src/components/BookTravelButton.tsx index 94a8b6ccce95..d8fd270dce8f 100644 --- a/src/components/BookTravelButton.tsx +++ b/src/components/BookTravelButton.tsx @@ -67,7 +67,7 @@ function BookTravelButton({text, shouldRenderErrorMessageBelowButton = false}: B const groupPaidPolicies = activePolicies.filter((activePolicy) => activePolicy.type !== CONST.POLICY.TYPE.PERSONAL && isPaidGroupPolicy(activePolicy)); // Flag indicating whether NewDot was launched exclusively for Travel, // e.g., when the user selects "Trips" from the Expensify Classic menu in HybridApp. - const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP, {canBeMissing: true}); const hidePreventionModal = () => setPreventionModalVisibility(false); const hideVerificationModal = () => setVerificationModalVisiblity(false); diff --git a/src/components/CustomStatusBarAndBackground/index.tsx b/src/components/CustomStatusBarAndBackground/index.tsx index 6b7d0eb57c28..27fadd74b12a 100644 --- a/src/components/CustomStatusBarAndBackground/index.tsx +++ b/src/components/CustomStatusBarAndBackground/index.tsx @@ -21,7 +21,7 @@ function CustomStatusBarAndBackground({isNested = false}: CustomStatusBarAndBack const {isRootStatusBarEnabled, setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext); const theme = useTheme(); const [statusBarStyle, setStatusBarStyle] = useState(); - const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP, {canBeMissing: true}); const isDisabled = (!isNested && !isRootStatusBarEnabled) || (hybridApp?.closingReactNativeApp ?? false); diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index 54ba0dd6f502..9e43c670da2b 100644 --- a/src/components/InitialURLContextProvider.tsx +++ b/src/components/InitialURLContextProvider.tsx @@ -33,7 +33,7 @@ type InitialURLContextProviderProps = AppProps & { function InitialURLContextProvider({children, url, hybridAppSettings, timestamp}: InitialURLContextProviderProps) { const [initialURL, setInitialURL] = useState(); const {splashScreenState, setSplashScreenState} = useSplashScreenStateContext(); - const [tryNewDot, tryNewDotMetadata] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT); + const [tryNewDot, tryNewDotMetadata] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT, {canBeMissing: true}); // We use `setupCalled` ref to guarantee that `signInAfterTransitionFromOldDot` is called once. const setupCalled = useRef(false); const isLoading = isLoadingOnyxValue(tryNewDotMetadata); diff --git a/src/components/ScreenWrapper.tsx b/src/components/ScreenWrapper.tsx index aef97c1c97c4..e09e92fc9b96 100644 --- a/src/components/ScreenWrapper.tsx +++ b/src/components/ScreenWrapper.tsx @@ -195,7 +195,7 @@ function ScreenWrapper( const ignoreInsetsConsumption = !useContext(ModalContext).default; const {initialURL} = useContext(InitialURLContext); - const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP, {canBeMissing: true}); // When the `enableEdgeToEdgeBottomSafeAreaPadding` prop is explicitly set, we enable edge-to-edge mode. const isUsingEdgeToEdgeMode = enableEdgeToEdgeBottomSafeAreaPaddingProp !== undefined; diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 4f836644df9b..64dc6f055faa 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -5,7 +5,7 @@ import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Credentials, HybridApp, Session, TryNewDot} from '@src/types/onyx'; -import * as HybridAppActions from './actions/HybridApp'; +import {setNewDotSignInState, setReadyToShowAuthScreens, setUseNewDotSignInPage} from './actions/HybridApp'; import Log from './Log'; import {getCurrentUserEmail} from './Network/NetworkStore'; @@ -40,7 +40,7 @@ Onyx.connect({ key: ONYXKEYS.SESSION, callback: (session: OnyxEntry) => { if (!currentSession?.authToken && session?.authToken && currentHybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED) { - HybridAppActions.setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); } currentSession = session; }, @@ -86,12 +86,12 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryN email: getCurrentUserEmail() ?? '', policyID: activePolicyID ?? '', }); - HybridAppActions.setUseNewDotSignInPage(false).then(() => { + setUseNewDotSignInPage(false).then(() => { if (shouldUseOD) { HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); } else { Log.info('[HybridApp] The user should see NewDot. There is no need to block the user on the `SignInPage` until the sign-in process is completed on the OldDot side.'); - HybridAppActions.setReadyToShowAuthScreens(true); + setReadyToShowAuthScreens(true); } }); } diff --git a/src/libs/Navigation/AppNavigator/index.native.tsx b/src/libs/Navigation/AppNavigator/index.native.tsx index 70c5bf2344bd..db3fcd52d36f 100644 --- a/src/libs/Navigation/AppNavigator/index.native.tsx +++ b/src/libs/Navigation/AppNavigator/index.native.tsx @@ -10,7 +10,7 @@ type AppNavigatorProps = { }; function AppNavigator({authenticated}: AppNavigatorProps) { - const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP, {canBeMissing: true}); const shouldShowAuthScreens = useMemo(() => { if (!CONFIG.IS_HYBRID_APP) { diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index ee328cc87fc9..7192328249a0 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -9,7 +9,6 @@ import type {ValueOf} from 'type-fest'; import AccountSwitcher from '@components/AccountSwitcher'; import AccountSwitcherSkeletonView from '@components/AccountSwitcherSkeletonView'; import ConfirmModal from '@components/ConfirmModal'; -import CustomStatusBarAndBackgroundContext from '@components/CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import Icon from '@components/Icon'; import * as Expensicons from '@components/Icon/Expensicons'; import MenuItem from '@components/MenuItem'; diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 4239c5858f77..d7fea503d518 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -239,6 +239,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco * Check that all the form fields are valid, then trigger the submit callback */ const validateAndSubmitForm = useCallback(() => { + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing if (account?.isLoading || hybridApp?.readyToShowAuthScreens || session?.authToken) { return; } @@ -304,7 +305,6 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco account?.errors, account?.requiresTwoFactorAuth, hybridApp?.readyToShowAuthScreens, - hybridApp?.newDotSignInState, session?.authToken, isUsingRecoveryCode, recoveryCode, From a9d437d3a1baaad7ed748135ab47ebb8a325d125 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Tue, 13 May 2025 10:00:37 +0200 Subject: [PATCH 63/95] fix prettier --- src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.tsx b/src/App.tsx index a2718ed8f282..4caa6e336ff2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -39,10 +39,10 @@ import Expensify from './Expensify'; import {CurrentReportIDContextProvider} from './hooks/useCurrentReportID'; import useDefaultDragAndDrop from './hooks/useDefaultDragAndDrop'; import OnyxUpdateManager from './libs/actions/OnyxUpdateManager'; +import './libs/HybridApp'; import {ReportAttachmentsProvider} from './pages/home/report/ReportAttachmentsContext'; import type {Route} from './ROUTES'; import './setup/backgroundTask'; -import './libs/HybridApp'; import {SplashScreenStateContextProvider} from './SplashScreenStateContext'; /** From cd7ef32a648b0225577b6fe83359d6869f42819d Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Thu, 15 May 2025 18:42:50 +0200 Subject: [PATCH 64/95] Change google sign-in configuration --- src/CONFIG.ts | 1 + .../SignInButtons/AppleSignIn/index.android.tsx | 9 ++++++++- src/components/SignInButtons/AppleSignIn/index.ios.tsx | 6 +++++- .../SignInButtons/GoogleSignIn/index.native.tsx | 8 ++++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/CONFIG.ts b/src/CONFIG.ts index aa6e3a325d49..a78b6775060d 100644 --- a/src/CONFIG.ts +++ b/src/CONFIG.ts @@ -96,6 +96,7 @@ export default { // cspell:disable-next-line WEB_CLIENT_ID: '921154746561-gpsoaqgqfuqrfsjdf8l7vohfkfj7b9up.apps.googleusercontent.com', IOS_CLIENT_ID: '921154746561-s3uqn2oe4m85tufi6mqflbfbuajrm2i3.apps.googleusercontent.com', + HYBRID_APP_WEB_CLIENT_ID: '1008697809946-5e095eqem3o6ugtpc2rjf7v880tcp28p.apps.googleusercontent.com', }, GCP_GEOLOCATION_API_KEY: googleGeolocationAPIKey, FIREBASE_WEB_CONFIG: { diff --git a/src/components/SignInButtons/AppleSignIn/index.android.tsx b/src/components/SignInButtons/AppleSignIn/index.android.tsx index a528fe7c5a10..2c1547e16cae 100644 --- a/src/components/SignInButtons/AppleSignIn/index.android.tsx +++ b/src/components/SignInButtons/AppleSignIn/index.android.tsx @@ -1,6 +1,8 @@ import {appleAuthAndroid} from '@invertase/react-native-apple-authentication'; import React from 'react'; import IconButton from '@components/SignInButtons/IconButton'; +import {setNewDotSignInState} from '@libs/actions/HybridApp'; +import Growl from '@libs/Growl'; import Log from '@libs/Log'; import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; @@ -37,11 +39,16 @@ function appleSignInRequest(): Promise { function AppleSignIn({onPress = () => {}}: AppleSignInProps) { const handleSignIn = () => { appleSignInRequest() - .then((token) => Session.beginAppleSignIn(token)) + .then((token) => { + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); + Session.beginAppleSignIn(token); + }) .catch((error: Record) => { if (error.message === appleAuthAndroid.Error.SIGNIN_CANCELLED) { + Growl.error('[Apple In] Apple Sign In cancelled'); return null; } + Growl.error(`[Apple Sign In] Apple authentication failed`); Log.alert('[Apple Sign In] Apple authentication failed', error); }); }; diff --git a/src/components/SignInButtons/AppleSignIn/index.ios.tsx b/src/components/SignInButtons/AppleSignIn/index.ios.tsx index 57aae97b9c48..22ff0ebce939 100644 --- a/src/components/SignInButtons/AppleSignIn/index.ios.tsx +++ b/src/components/SignInButtons/AppleSignIn/index.ios.tsx @@ -2,6 +2,7 @@ import appleAuth from '@invertase/react-native-apple-authentication'; import type {AppleError} from '@invertase/react-native-apple-authentication'; import React from 'react'; import IconButton from '@components/SignInButtons/IconButton'; +import {setNewDotSignInState} from '@libs/actions/HybridApp'; import Log from '@libs/Log'; import * as Session from '@userActions/Session'; import CONST from '@src/CONST'; @@ -36,7 +37,10 @@ function appleSignInRequest(): Promise { function AppleSignIn({onPress = () => {}}: AppleSignInProps) { const handleSignIn = () => { appleSignInRequest() - .then((token) => Session.beginAppleSignIn(token)) + .then((token) => { + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); + Session.beginAppleSignIn(token); + }) .catch((error: {code: AppleError}) => { if (error.code === appleAuth.Error.CANCELED) { return null; diff --git a/src/components/SignInButtons/GoogleSignIn/index.native.tsx b/src/components/SignInButtons/GoogleSignIn/index.native.tsx index 72ce70809190..c005884d0dc8 100644 --- a/src/components/SignInButtons/GoogleSignIn/index.native.tsx +++ b/src/components/SignInButtons/GoogleSignIn/index.native.tsx @@ -1,6 +1,7 @@ import {GoogleSignin, statusCodes} from '@react-native-google-signin/google-signin'; import React from 'react'; import IconButton from '@components/SignInButtons/IconButton'; +import {setNewDotSignInState} from '@libs/actions/HybridApp'; import Growl from '@libs/Growl'; import Log from '@libs/Log'; import * as Session from '@userActions/Session'; @@ -14,7 +15,7 @@ import type GoogleError from './types'; */ function googleSignInRequest() { GoogleSignin.configure({ - webClientId: CONFIG.GOOGLE_SIGN_IN.WEB_CLIENT_ID, + webClientId: CONFIG.IS_HYBRID_APP ? CONFIG.GOOGLE_SIGN_IN.HYBRID_APP_WEB_CLIENT_ID : CONFIG.GOOGLE_SIGN_IN.WEB_CLIENT_ID, iosClientId: CONFIG.GOOGLE_SIGN_IN.IOS_CLIENT_ID, offlineAccess: false, }); @@ -26,7 +27,10 @@ function googleSignInRequest() { GoogleSignin.signIn() .then((response) => response.idToken) - .then((token) => Session.beginGoogleSignIn(token)) + .then((token) => { + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); + Session.beginGoogleSignIn(token); + }) .catch((error: GoogleError | undefined) => { // Handle unexpected error shape if (error?.code === undefined) { From 0d82833afd3f434a95181a9176d6567ff3fbcc6a Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Fri, 16 May 2025 12:23:51 +0200 Subject: [PATCH 65/95] Fix iOS client ID on HybridApp --- src/CONFIG.ts | 1 + src/components/SignInButtons/GoogleSignIn/index.native.tsx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CONFIG.ts b/src/CONFIG.ts index a78b6775060d..8a02d2673de1 100644 --- a/src/CONFIG.ts +++ b/src/CONFIG.ts @@ -97,6 +97,7 @@ export default { WEB_CLIENT_ID: '921154746561-gpsoaqgqfuqrfsjdf8l7vohfkfj7b9up.apps.googleusercontent.com', IOS_CLIENT_ID: '921154746561-s3uqn2oe4m85tufi6mqflbfbuajrm2i3.apps.googleusercontent.com', HYBRID_APP_WEB_CLIENT_ID: '1008697809946-5e095eqem3o6ugtpc2rjf7v880tcp28p.apps.googleusercontent.com', + HYBRID_APP_IOS_CLIENT_ID: '1008697809946-sh04nqq0hea396s1qdqqbj6ia649odb2.apps.googleusercontent.com', }, GCP_GEOLOCATION_API_KEY: googleGeolocationAPIKey, FIREBASE_WEB_CONFIG: { diff --git a/src/components/SignInButtons/GoogleSignIn/index.native.tsx b/src/components/SignInButtons/GoogleSignIn/index.native.tsx index c005884d0dc8..f093b7d43e8a 100644 --- a/src/components/SignInButtons/GoogleSignIn/index.native.tsx +++ b/src/components/SignInButtons/GoogleSignIn/index.native.tsx @@ -16,7 +16,7 @@ import type GoogleError from './types'; function googleSignInRequest() { GoogleSignin.configure({ webClientId: CONFIG.IS_HYBRID_APP ? CONFIG.GOOGLE_SIGN_IN.HYBRID_APP_WEB_CLIENT_ID : CONFIG.GOOGLE_SIGN_IN.WEB_CLIENT_ID, - iosClientId: CONFIG.GOOGLE_SIGN_IN.IOS_CLIENT_ID, + iosClientId: CONFIG.IS_HYBRID_APP ? CONFIG.GOOGLE_SIGN_IN.HYBRID_APP_IOS_CLIENT_ID : CONFIG.GOOGLE_SIGN_IN.IOS_CLIENT_ID, offlineAccess: false, }); From 8405068edf373ea00aa370dcdf2b3f19409056ea Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Fri, 16 May 2025 12:45:56 +0200 Subject: [PATCH 66/95] add missing sign-in growls --- src/components/SignInButtons/AppleSignIn/index.ios.tsx | 2 ++ src/components/SignInButtons/GoogleSignIn/index.native.tsx | 1 + 2 files changed, 3 insertions(+) diff --git a/src/components/SignInButtons/AppleSignIn/index.ios.tsx b/src/components/SignInButtons/AppleSignIn/index.ios.tsx index 22ff0ebce939..164dde36a8cf 100644 --- a/src/components/SignInButtons/AppleSignIn/index.ios.tsx +++ b/src/components/SignInButtons/AppleSignIn/index.ios.tsx @@ -3,6 +3,7 @@ import type {AppleError} from '@invertase/react-native-apple-authentication'; import React from 'react'; import IconButton from '@components/SignInButtons/IconButton'; import {setNewDotSignInState} from '@libs/actions/HybridApp'; +import Growl from '@libs/Growl'; import Log from '@libs/Log'; import * as Session from '@userActions/Session'; import CONST from '@src/CONST'; @@ -24,6 +25,7 @@ function appleSignInRequest(): Promise { appleAuth.getCredentialStateForUser(response.user).then((credentialState) => { if (credentialState !== appleAuth.State.AUTHORIZED) { Log.alert('[Apple Sign In] Authentication failed. Original response: ', {response}); + Growl.error(`[Apple Sign In] Authentication failed. Original response: ${JSON.stringify(response)}`); throw new Error('Authentication failed'); } return response.identityToken; diff --git a/src/components/SignInButtons/GoogleSignIn/index.native.tsx b/src/components/SignInButtons/GoogleSignIn/index.native.tsx index f093b7d43e8a..999c0e9464d2 100644 --- a/src/components/SignInButtons/GoogleSignIn/index.native.tsx +++ b/src/components/SignInButtons/GoogleSignIn/index.native.tsx @@ -35,6 +35,7 @@ function googleSignInRequest() { // Handle unexpected error shape if (error?.code === undefined) { Log.alert(`[Google Sign In] Google sign in failed: ${JSON.stringify(error)}`); + Growl.error(`[Google Sign In] Google sign in failed: ${JSON.stringify(error)}`); return; } /** The logged code is useful for debugging any new errors that are not specifically handled. To decode, see: From 2d386c6055bf5b4880fc48f0379db7e179c873b7 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Mon, 19 May 2025 17:09:54 +0200 Subject: [PATCH 67/95] Fix comments --- src/libs/actions/Session/index.ts | 9 +-------- src/types/onyx/HybridApp.ts | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 156c5d457c77..52ceadcc3336 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -266,7 +266,7 @@ function signOutAndRedirectToSignIn(shouldResetToHome?: boolean, shouldStashSess return; } - // In the HybridApp, we want the Old Dot to handle the sign out process + // When signing out from the HybridApp, we need to sign out from the oldDot app as well if (CONFIG.IS_HYBRID_APP && shouldSignOutFromOldDot) { HybridAppModule.signOutFromOldDot(); } @@ -527,13 +527,6 @@ function setupNewDotAfterTransitionFromOldDot(hybridAppSettings: string, tryNewD if (!hybridApp.useNewDotSignInPage) { return Promise.resolve(); } - // TODO: Check if it is necessary - // We also need to reset: - // - IS_LOADING_APP after sign in to ensure the condition to show ExplanationModal runs once - // https://github.com/Expensify/App/issues/57575#issuecomment-2780189425 - // return Onyx.clear(KEYS_TO_PRESERVE) - // .then(() => Onyx.merge(ONYXKEYS.ACCOUNT, {delegatedAccess: null})) - // .then(() => Onyx.merge(ONYXKEYS.IS_LOADING_APP, null)); return redirectToSignIn(); }; diff --git a/src/types/onyx/HybridApp.ts b/src/types/onyx/HybridApp.ts index e464c11cfd65..b6fee12920cf 100644 --- a/src/types/onyx/HybridApp.ts +++ b/src/types/onyx/HybridApp.ts @@ -1,48 +1,48 @@ import type {ValueOf} from 'type-fest'; import type CONST from '@src/CONST'; -/** */ +/** Data structure holding user's OldDot access information */ type HybridAppDelegateAccessData = { - /** */ + /** Indicates if OldDot is accessed in a delegate mode */ isDelegateAccess?: boolean; - /** */ + /** Email address through which the user is currently authenticated in OldDot */ oldDotCurrentUserEmail?: string; - /** */ + /** Authentication token used in OldDot */ oldDotCurrentAuthToken?: string; - /** */ + /** Encrypted authentication token used in OldDot */ oldDotCurrentEncryptedAuthToken?: string; - /** */ + /** Account ID for the user in OldDot */ oldDotCurrentAccountID?: number; }; -/** */ +/** State and configuration of a HybridApp */ type HybridApp = { /** Stores the information if HybridApp uses NewDot's sign-in flow */ useNewDotSignInPage?: boolean; - /** Tells if we can show AuthScreens */ + /** Determines if the AuthScreens are ready to be displayed */ readyToShowAuthScreens?: boolean; - /** States whether we transitioned from OldDot to show only certain group of screens */ + /** Specifies if the transition from OldDot was made to display a specific subset of screens in NewDot */ isSingleNewDotEntry?: boolean; - /** Stores information if last log out was performed from OldDot */ + /** Indicates if the last sign out action was performed from OldDot */ loggedOutFromOldDot?: boolean; - /** */ + /** Determines whether to remove delegated access */ shouldRemoveDelegatedAccess?: boolean; - /** Describes current stage of NewDot sign-in */ + /** Describes the current state of NewDot sign-in process */ newDotSignInState?: ValueOf; - /** */ + /** Holds delegate access information */ delegateAccessData?: HybridAppDelegateAccessData; - /** */ + /** Indicates if the NewDot is being closed */ closingReactNativeApp?: boolean; }; From 706730f730e76cbd360913430077ec5306eecbf6 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Wed, 21 May 2025 14:56:35 +0200 Subject: [PATCH 68/95] Fix should show auth screens --- src/libs/HybridApp.ts | 5 ++++- src/libs/Navigation/AppNavigator/index.native.tsx | 4 ++-- src/libs/actions/HybridApp/index.ts | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 64dc6f055faa..c20815e5b629 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -55,8 +55,11 @@ Onyx.connect({ }); function shouldUseOldApp(tryNewDot?: TryNewDot) { + if (!tryNewDot) { + return true; + } // TODO: this is a workaround for backend issue with `tryNewDot` being an array - if (!tryNewDot || Array.isArray(tryNewDot)) { + if (Array.isArray(tryNewDot)) { return false; } diff --git a/src/libs/Navigation/AppNavigator/index.native.tsx b/src/libs/Navigation/AppNavigator/index.native.tsx index db3fcd52d36f..285f6ddc830f 100644 --- a/src/libs/Navigation/AppNavigator/index.native.tsx +++ b/src/libs/Navigation/AppNavigator/index.native.tsx @@ -17,8 +17,8 @@ function AppNavigator({authenticated}: AppNavigatorProps) { return authenticated; } - return authenticated && (!hybridApp?.useNewDotSignInPage || hybridApp?.readyToShowAuthScreens); - }, [hybridApp?.useNewDotSignInPage, hybridApp?.readyToShowAuthScreens, authenticated]); + return authenticated && hybridApp?.readyToShowAuthScreens; + }, [hybridApp?.readyToShowAuthScreens, authenticated]); if (shouldShowAuthScreens) { const AuthScreens = require('./AuthScreens').default; diff --git a/src/libs/actions/HybridApp/index.ts b/src/libs/actions/HybridApp/index.ts index 1dccba1fa573..bf51b8b2a813 100644 --- a/src/libs/actions/HybridApp/index.ts +++ b/src/libs/actions/HybridApp/index.ts @@ -52,7 +52,7 @@ function prepareHybridAppAfterTransitionToNewDot(hybridApp: HybridApp) { if (hybridApp?.useNewDotSignInPage) { return Onyx.merge(ONYXKEYS.HYBRID_APP, { ...hybridApp, - readyToShowAuthScreens: false, + readyToShowAuthScreens: !(hybridApp?.useNewDotSignInPage ?? false), newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED, }); } From f0f321c508b9a7861392e8e29a8268004be49dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Warcho=C5=82?= <61014013+war-in@users.noreply.github.com> Date: Tue, 27 May 2025 12:51:19 +0200 Subject: [PATCH 69/95] Fix blink in OD -> ND transition after sign-out (#226) * delay pop all pages * "fix" iOS part * add initial insets for SafeAreaProvider * Fix signing out from ND after transition from OD --------- Co-authored-by: war-in Co-authored-by: 289Adam289 --- .../ReactNativeHybridApp.kt | 4 + .../hybrid-app/ios/ReactNativeHybridApp.mm | 4 + .../src/NativeReactNativeHybridApp.ts | 1 + modules/hybrid-app/src/index.native.ts | 3 + modules/hybrid-app/src/index.ts | 4 + modules/hybrid-app/src/types.ts | 1 + src/App.tsx | 84 ++++++++++--------- src/pages/signin/SignInPage.tsx | 11 +++ 8 files changed, 73 insertions(+), 39 deletions(-) diff --git a/modules/hybrid-app/android/src/main/java/com/expensify/reactnativehybridapp/ReactNativeHybridApp.kt b/modules/hybrid-app/android/src/main/java/com/expensify/reactnativehybridapp/ReactNativeHybridApp.kt index 0949ffb881dd..46c7968d6cca 100644 --- a/modules/hybrid-app/android/src/main/java/com/expensify/reactnativehybridapp/ReactNativeHybridApp.kt +++ b/modules/hybrid-app/android/src/main/java/com/expensify/reactnativehybridapp/ReactNativeHybridApp.kt @@ -50,4 +50,8 @@ class ReactNativeHybridApp(reactContext: ReactApplicationContext) : override fun signOutFromOldDot() { Log.d(NAME, "`signOutFromOldDot` should never be called in standalone `New Expensify` app") } + + override fun clearOldDotAfterSignOut() { + Log.d(NAME, "`clearOldDotAfterSignOut` should never be called in standalone `New Expensify` app") + } } diff --git a/modules/hybrid-app/ios/ReactNativeHybridApp.mm b/modules/hybrid-app/ios/ReactNativeHybridApp.mm index 1e52a0b58394..f94bccf5d560 100644 --- a/modules/hybrid-app/ios/ReactNativeHybridApp.mm +++ b/modules/hybrid-app/ios/ReactNativeHybridApp.mm @@ -35,6 +35,10 @@ - (void)signOutFromOldDot { NSLog(@"[ReactNativeHybridApp] `signOutFromOldDot` should never be called in standalone `New Expensify` app"); } +- (void)clearOldDotAfterSignOut { + NSLog(@"[ReactNativeHybridApp] `clearOldDotAfterSignOut` should never be called in standalone `New Expensify` app"); +} + - (std::shared_ptr)getTurboModule: (const facebook::react::ObjCTurboModule::InitParams &)params { diff --git a/modules/hybrid-app/src/NativeReactNativeHybridApp.ts b/modules/hybrid-app/src/NativeReactNativeHybridApp.ts index f0fe2307e1c9..4001adacff49 100644 --- a/modules/hybrid-app/src/NativeReactNativeHybridApp.ts +++ b/modules/hybrid-app/src/NativeReactNativeHybridApp.ts @@ -11,6 +11,7 @@ export interface Spec extends TurboModule { sendAuthToken: (authToken: string) => void; signInToOldDot: (autoGeneratedLogin: string, autoGeneratedPassword: string, authToken: string, email: string, policyID: string) => void; signOutFromOldDot: () => void; + clearOldDotAfterSignOut: () => void; } export default TurboModuleRegistry.getEnforcing('ReactNativeHybridApp'); diff --git a/modules/hybrid-app/src/index.native.ts b/modules/hybrid-app/src/index.native.ts index 2bd0965bf37d..f217573906d7 100644 --- a/modules/hybrid-app/src/index.native.ts +++ b/modules/hybrid-app/src/index.native.ts @@ -28,6 +28,9 @@ const HybridAppModule: HybridAppModuleType = { signOutFromOldDot() { ReactNativeHybridApp.signOutFromOldDot(); }, + clearOldDotAfterSignOut() { + ReactNativeHybridApp.clearOldDotAfterSignOut(); + } }; export default HybridAppModule; diff --git a/modules/hybrid-app/src/index.ts b/modules/hybrid-app/src/index.ts index ff2dd9a22011..4075cc4f9540 100644 --- a/modules/hybrid-app/src/index.ts +++ b/modules/hybrid-app/src/index.ts @@ -32,6 +32,10 @@ const HybridAppModule: HybridAppModuleType = { // eslint-disable-next-line no-console console.warn('HybridAppModule: `signOutFromOldDot` should never be called on web'); }, + clearOldDotAfterSignOut() { + // eslint-disable-next-line no-console + console.warn('HybridAppModule: `clearOldDotAfterSignOut` should never be called on web'); + } }; export default HybridAppModule; diff --git a/modules/hybrid-app/src/types.ts b/modules/hybrid-app/src/types.ts index bf912dbc6990..7d33f31446f0 100644 --- a/modules/hybrid-app/src/types.ts +++ b/modules/hybrid-app/src/types.ts @@ -7,6 +7,7 @@ type HybridAppModuleType = { sendAuthToken: (args: {authToken: string}) => void; signInToOldDot: (args: {autoGeneratedLogin: string; autoGeneratedPassword: string; authToken: string; email: string; policyID: string}) => void; signOutFromOldDot: () => void; + clearOldDotAfterSignOut: () => void; }; export default HybridAppModuleType; diff --git a/src/App.tsx b/src/App.tsx index 4caa6e336ff2..70ae4457f819 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -84,46 +84,52 @@ function App({url, hybridAppSettings, timestamp}: AppProps) { timestamp={timestamp} > - - - - - - - - - + + + + + + + + + + diff --git a/src/pages/signin/SignInPage.tsx b/src/pages/signin/SignInPage.tsx index 1cd6b2c04ef6..8ad0b93fc44e 100644 --- a/src/pages/signin/SignInPage.tsx +++ b/src/pages/signin/SignInPage.tsx @@ -1,3 +1,4 @@ +import HybridAppModule from '@expensify/react-native-hybrid-app'; import {Str} from 'expensify-common'; import React, {forwardRef, useEffect, useImperativeHandle, useRef, useState} from 'react'; import type {ForwardedRef} from 'react'; @@ -21,6 +22,7 @@ import Performance from '@libs/Performance'; import Visibility from '@libs/Visibility'; import {setLocale} from '@userActions/App'; import {clearSignInData} from '@userActions/Session'; +import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -182,6 +184,7 @@ function SignInPage({shouldEnableMaxHeight = true}: SignInPageInnerProps, ref: F // We need to show "Another login page is opened" message if the page isn't active and visible // eslint-disable-next-line rulesdir/no-negated-variables const shouldShowAnotherLoginPageOpenedMessage = Visibility.isVisible() && !isClientTheLeader; + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP, {canBeMissing: true}); useEffect(() => Performance.measureTTI(), []); useEffect(() => { @@ -299,6 +302,14 @@ function SignInPage({shouldEnableMaxHeight = true}: SignInPageInnerProps, ref: F useImperativeHandle(ref, () => ({ navigateBack, })); + + useEffect(() => { + if (!CONFIG.IS_HYBRID_APP || !hybridApp?.loggedOutFromOldDot) { + return; + } + HybridAppModule.clearOldDotAfterSignOut(); + }, [hybridApp?.loggedOutFromOldDot]); + return ( // Bottom SafeAreaView is removed so that login screen svg displays correctly on mobile. // The SVG should flow under the Home Indicator on iOS. From 697708686725931c7b9c7244af4693ea04114075 Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 27 May 2025 13:13:52 +0200 Subject: [PATCH 70/95] fix few review comments --- modules/hybrid-app/src/index.native.ts | 2 +- modules/hybrid-app/src/index.ts | 2 +- src/CONST.ts | 3 --- src/libs/API/types.ts | 8 ++++---- src/libs/actions/Session/index.ts | 8 +++----- src/types/onyx/Response.ts | 3 --- 6 files changed, 9 insertions(+), 17 deletions(-) diff --git a/modules/hybrid-app/src/index.native.ts b/modules/hybrid-app/src/index.native.ts index f217573906d7..07e331bd5593 100644 --- a/modules/hybrid-app/src/index.native.ts +++ b/modules/hybrid-app/src/index.native.ts @@ -30,7 +30,7 @@ const HybridAppModule: HybridAppModuleType = { }, clearOldDotAfterSignOut() { ReactNativeHybridApp.clearOldDotAfterSignOut(); - } + }, }; export default HybridAppModule; diff --git a/modules/hybrid-app/src/index.ts b/modules/hybrid-app/src/index.ts index 4075cc4f9540..f9c8bb22ec7d 100644 --- a/modules/hybrid-app/src/index.ts +++ b/modules/hybrid-app/src/index.ts @@ -35,7 +35,7 @@ const HybridAppModule: HybridAppModuleType = { clearOldDotAfterSignOut() { // eslint-disable-next-line no-console console.warn('HybridAppModule: `clearOldDotAfterSignOut` should never be called on web'); - } + }, }; export default HybridAppModule; diff --git a/src/CONST.ts b/src/CONST.ts index 6c413ad7d7d6..383a89d5f73d 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -5201,9 +5201,6 @@ const CONST = { }, EVENTS: { SCROLLING: 'scrolling', - HYBRID_APP: { - ON_SIGN_IN_FINISHED: 'onSignInFinished', - }, }, SELECTION_LIST_WITH_MODAL_TEST_ID: 'selectionListWithModalMenuItem', diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 1246dc091edf..ad381480b5ac 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -90,6 +90,7 @@ const WRITE_COMMANDS = { REQUEST_NEW_VALIDATE_CODE: 'RequestNewValidateCode', SIGN_IN_WITH_APPLE: 'SignInWithApple', SIGN_IN_WITH_GOOGLE: 'SignInWithGoogle', + SIGN_IN_USER: 'SigninUser', SIGN_IN_USER_WITH_LINK: 'SigninUserWithLink', SEARCH: 'Search', REQUEST_UNLINK_VALIDATION_LINK: 'RequestUnlinkValidationLink', @@ -319,6 +320,7 @@ const WRITE_COMMANDS = { MERGE_DUPLICATES: 'MergeDuplicates', RESOLVE_DUPLICATES: 'ResolveDuplicates', UPDATE_SUBSCRIPTION_TYPE: 'UpdateSubscriptionType', + SIGN_UP_USER: 'SignUpUser', UPDATE_SUBSCRIPTION_AUTO_RENEW: 'UpdateSubscriptionAutoRenew', UPDATE_SUBSCRIPTION_ADD_NEW_USERS_AUTOMATICALLY: 'UpdateSubscriptionAddNewUsersAutomatically', UPDATE_SUBSCRIPTION_SIZE: 'UpdateSubscriptionSize', @@ -555,6 +557,7 @@ type WriteCommandParameters = { [WRITE_COMMANDS.REQUEST_NEW_VALIDATE_CODE]: Parameters.RequestNewValidateCodeParams; [WRITE_COMMANDS.SIGN_IN_WITH_APPLE]: Parameters.BeginAppleSignInParams; [WRITE_COMMANDS.SIGN_IN_WITH_GOOGLE]: Parameters.BeginGoogleSignInParams; + [WRITE_COMMANDS.SIGN_IN_USER]: SignInUserParams; [WRITE_COMMANDS.SIGN_IN_USER_WITH_LINK]: Parameters.SignInUserWithLinkParams; [WRITE_COMMANDS.REQUEST_UNLINK_VALIDATION_LINK]: Parameters.RequestUnlinkValidationLinkParams; [WRITE_COMMANDS.UNLINK_LOGIN]: Parameters.UnlinkLoginParams; @@ -806,6 +809,7 @@ type WriteCommandParameters = { [WRITE_COMMANDS.MERGE_DUPLICATES]: Parameters.MergeDuplicatesParams; [WRITE_COMMANDS.RESOLVE_DUPLICATES]: Parameters.ResolveDuplicatesParams; [WRITE_COMMANDS.UPDATE_SUBSCRIPTION_TYPE]: Parameters.UpdateSubscriptionTypeParams; + [WRITE_COMMANDS.SIGN_UP_USER]: Parameters.SignUpUserParams; [WRITE_COMMANDS.UPDATE_SUBSCRIPTION_AUTO_RENEW]: Parameters.UpdateSubscriptionAutoRenewParams; [WRITE_COMMANDS.UPDATE_SUBSCRIPTION_ADD_NEW_USERS_AUTOMATICALLY]: Parameters.UpdateSubscriptionAddNewUsersAutomaticallyParams; [WRITE_COMMANDS.UPDATE_SUBSCRIPTION_SIZE]: Parameters.UpdateSubscriptionSizeParams; @@ -1135,8 +1139,6 @@ const SIDE_EFFECT_REQUEST_COMMANDS = { BANK_ACCOUNT_CREATE_CORPAY: 'BankAccount_CreateCorpay', MERGE_INTO_ACCOUNT_AND_LOGIN: 'MergeIntoAccountAndLogIn', GET_EMPHEMERAL_TOKEN: 'GetEmphemeralToken', - SIGN_IN_USER: 'SigninUser', - SIGN_UP_USER: 'SignUpUser', // PayMoneyRequestOnSearch only works online (pattern C) and we need to play the success sound only when the request is successful PAY_MONEY_REQUEST_ON_SEARCH: 'PayMoneyRequestOnSearch', @@ -1160,8 +1162,6 @@ type SideEffectRequestCommandParameters = { [SIDE_EFFECT_REQUEST_COMMANDS.COMPLETE_HYBRID_APP_ONBOARDING]: EmptyObject; [SIDE_EFFECT_REQUEST_COMMANDS.CONNECT_POLICY_TO_QUICKBOOKS_DESKTOP]: Parameters.ConnectPolicyToQuickBooksDesktopParams; [SIDE_EFFECT_REQUEST_COMMANDS.BANK_ACCOUNT_CREATE_CORPAY]: Parameters.BankAccountCreateCorpayParams; - [SIDE_EFFECT_REQUEST_COMMANDS.SIGN_IN_USER]: SignInUserParams; - [SIDE_EFFECT_REQUEST_COMMANDS.SIGN_UP_USER]: Parameters.SignUpUserParams; [SIDE_EFFECT_REQUEST_COMMANDS.PAY_MONEY_REQUEST_ON_SEARCH]: Parameters.PayMoneyRequestOnSearchParams; [SIDE_EFFECT_REQUEST_COMMANDS.MERGE_INTO_ACCOUNT_AND_LOGIN]: Parameters.MergeIntoAccountAndLogInParams; [SIDE_EFFECT_REQUEST_COMMANDS.LOG_OUT]: Parameters.LogOutParams; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 52ceadcc3336..ee434e4388a7 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -515,8 +515,7 @@ function signUpUser() { const params: SignUpUserParams = {email: credentials.login, preferredLocale}; - // eslint-disable-next-line rulesdir/no-api-side-effects-method - API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.SIGN_UP_USER, params, {optimisticData, successData, failureData}).then(() => {}); + API.write(WRITE_COMMANDS.SIGN_UP_USER, params, {optimisticData, successData, failureData}); } function setupNewDotAfterTransitionFromOldDot(hybridAppSettings: string, tryNewDot?: TryNewDot) { @@ -694,12 +693,11 @@ function signIn(validateCode: string, twoFactorAuthCode?: string) { params.validateCode = validateCode || credentials.validateCode; } - // eslint-disable-next-line rulesdir/no-api-side-effects-method - API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.SIGN_IN_USER, params, { + API.write(WRITE_COMMANDS.SIGN_IN_USER, params, { optimisticData, successData, failureData, - }).then(() => {}); + }); }); } diff --git a/src/types/onyx/Response.ts b/src/types/onyx/Response.ts index df360f9e9cac..f518c3b70e1c 100644 --- a/src/types/onyx/Response.ts +++ b/src/types/onyx/Response.ts @@ -112,9 +112,6 @@ type Response = { /** Whether the account already exists */ accountExists?: boolean; - - /** [HybridApp] Determines which app should be opened, NewDot or OldDot */ - tryNewDot?: boolean; }; export default Response; From f643be46e0b5142d1e2224c952650523c70fc093 Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 27 May 2025 13:22:26 +0200 Subject: [PATCH 71/95] simplify hybridAppSettings --- src/libs/actions/HybridApp/types.ts | 8 +++----- src/libs/actions/Session/index.ts | 3 +-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/HybridApp/types.ts b/src/libs/actions/HybridApp/types.ts index 228c6969d29a..5d4ab1431cbc 100644 --- a/src/libs/actions/HybridApp/types.ts +++ b/src/libs/actions/HybridApp/types.ts @@ -3,11 +3,9 @@ import type {TryNewDot} from '@src/types/onyx'; import type HybridApp from '@src/types/onyx/HybridApp'; type HybridAppSettings = { - initialOnyxValues: { - [ONYXKEYS.HYBRID_APP]: HybridApp; - [ONYXKEYS.NVP_TRY_NEW_DOT]?: TryNewDot; - [ONYXKEYS.ACCOUNT]?: {shouldUseStagingServer: boolean}; - }; + [ONYXKEYS.HYBRID_APP]: HybridApp; + [ONYXKEYS.NVP_TRY_NEW_DOT]?: TryNewDot; + [ONYXKEYS.ACCOUNT]?: {shouldUseStagingServer: boolean}; }; export default HybridAppSettings; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index ee434e4388a7..5d2e08a69c15 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -519,8 +519,7 @@ function signUpUser() { } function setupNewDotAfterTransitionFromOldDot(hybridAppSettings: string, tryNewDot?: TryNewDot) { - const {initialOnyxValues} = HybridAppActions.parseHybridAppSettings(hybridAppSettings); - const {hybridApp, ...newDotOnyxValues} = initialOnyxValues; + const {hybridApp, ...newDotOnyxValues} = HybridAppActions.parseHybridAppSettings(hybridAppSettings); const clearOnyxBeforeSignIn = () => { if (!hybridApp.useNewDotSignInPage) { From 63cadff7988ab7a8083be4efe7dae9a67c1e067b Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 27 May 2025 15:17:59 +0200 Subject: [PATCH 72/95] fix broken copilot --- src/libs/actions/Delegate.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/Delegate.ts b/src/libs/actions/Delegate.ts index bf1f9469703d..4b1437f923de 100644 --- a/src/libs/actions/Delegate.ts +++ b/src/libs/actions/Delegate.ts @@ -69,6 +69,7 @@ const KEYS_TO_PRESERVE_DELEGATE_ACCESS = [ ONYXKEYS.IS_LOADING_APP, ONYXKEYS.HAS_LOADED_APP, ONYXKEYS.STASHED_CREDENTIALS, + ONYXKEYS.HYBRID_APP, // 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. From a8bf4a52508965e5b3be907eed2c37dc94348bba Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Tue, 27 May 2025 18:16:45 +0200 Subject: [PATCH 73/95] Fix Sign in page assets loading --- src/components/InitialURLContextProvider.tsx | 12 ++++++++---- src/libs/actions/Session/index.ts | 5 +++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index 9e43c670da2b..e1ae363fc770 100644 --- a/src/components/InitialURLContextProvider.tsx +++ b/src/components/InitialURLContextProvider.tsx @@ -5,6 +5,7 @@ import {Linking} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import {setupNewDotAfterTransitionFromOldDot} from '@libs/actions/Session'; import Navigation, {navigationRef} from '@navigation/Navigation'; +import * as HybridAppActions from '@userActions/HybridApp'; import type {AppProps} from '@src/App'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -55,10 +56,9 @@ function InitialURLContextProvider({children, url, hybridAppSettings, timestamp} Navigation.navigate(parsedUrl); }); - if (splashScreenState === CONST.BOOT_SPLASH_STATE.HIDDEN) { - return; + if (splashScreenState === CONST.BOOT_SPLASH_STATE.VISIBLE) { + setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); } - setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); }, [splashScreenState, setSplashScreenState], ); @@ -68,8 +68,12 @@ function InitialURLContextProvider({children, url, hybridAppSettings, timestamp} if (!isLoading) { if (!setupCalled.current) { setupCalled.current = true; - setupNewDotAfterTransitionFromOldDot(hybridAppSettings, tryNewDot).then(() => { + const parsedHybridAppSettings = HybridAppActions.parseHybridAppSettings(hybridAppSettings); + setupNewDotAfterTransitionFromOldDot(parsedHybridAppSettings, tryNewDot).then(() => { handleNavigation(url); + if (parsedHybridAppSettings.hybridApp?.loggedOutFromOldDot) { + setSplashScreenState(CONST.BOOT_SPLASH_STATE.HIDDEN); + } }); return; } diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 5d2e08a69c15..c1a00f639541 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -50,6 +50,7 @@ import {KEYS_TO_PRESERVE, openApp} from '@userActions/App'; import {KEYS_TO_PRESERVE_DELEGATE_ACCESS} from '@userActions/Delegate'; import * as Device from '@userActions/Device'; import * as HybridAppActions from '@userActions/HybridApp'; +import type HybridAppSettings from '@userActions/HybridApp/types'; import * as PriorityMode from '@userActions/PriorityMode'; import redirectToSignIn from '@userActions/SignInRedirect'; import Timing from '@userActions/Timing'; @@ -518,8 +519,8 @@ function signUpUser() { API.write(WRITE_COMMANDS.SIGN_UP_USER, params, {optimisticData, successData, failureData}); } -function setupNewDotAfterTransitionFromOldDot(hybridAppSettings: string, tryNewDot?: TryNewDot) { - const {hybridApp, ...newDotOnyxValues} = HybridAppActions.parseHybridAppSettings(hybridAppSettings); +function setupNewDotAfterTransitionFromOldDot(hybridAppSettings: HybridAppSettings, tryNewDot?: TryNewDot) { + const {hybridApp, ...newDotOnyxValues} = hybridAppSettings; const clearOnyxBeforeSignIn = () => { if (!hybridApp.useNewDotSignInPage) { From 379a27a0dd17c03a0c297165f65c5719788fec03 Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Thu, 29 May 2025 14:27:22 +0200 Subject: [PATCH 74/95] Fix notification permission prompt on iOS --- .../PushNotification/index.native.ts | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/libs/Notification/PushNotification/index.native.ts b/src/libs/Notification/PushNotification/index.native.ts index a38e9d98a8e4..854aeba8074f 100644 --- a/src/libs/Notification/PushNotification/index.native.ts +++ b/src/libs/Notification/PushNotification/index.native.ts @@ -1,7 +1,8 @@ import type {PushPayload} from '@ua/react-native-airship'; -import Airship, {EventType} from '@ua/react-native-airship'; +import Airship, {EventType, PermissionStatus} from '@ua/react-native-airship'; import Log from '@libs/Log'; import ShortcutManager from '@libs/ShortcutManager'; +import CONFIG from '@src/CONFIG'; import ForegroundNotifications from './ForegroundNotifications'; import type {NotificationDataMap, NotificationTypes} from './NotificationType'; import NotificationType from './NotificationType'; @@ -79,18 +80,28 @@ const register: Register = (notificationID) => { Airship.contact .getNamedUserId() .then((userID) => { - if (userID === notificationID.toString()) { + // In the HybridApp, the contact identity is set on the YAPL side after sign-in. + // Since the Airship instance is shared between NewDot and OldDot, + // NewDot users won't see the push notification permission prompt as we return early in this case. + // Therefore, we cannot handle the HybridApp scenario here. + if (!CONFIG.IS_HYBRID_APP && userID === notificationID.toString()) { // No need to register again for this notificationID. return; } - // Get permissions to display push notifications (prompts user on iOS, but not Android) - Airship.push.enableUserNotifications().then((isEnabled) => { - if (isEnabled) { + // Get permissions to display push notifications if not determined (prompts user on iOS, but not Android) + Airship.push.getNotificationStatus().then(({notificationPermissionStatus}) => { + if (notificationPermissionStatus !== PermissionStatus.NotDetermined) { return; } - Log.info('[PushNotification] User has disabled visible push notifications for this app.'); + Airship.push.enableUserNotifications().then((isEnabled) => { + if (isEnabled) { + return; + } + + Log.info('[PushNotification] User has disabled visible push notifications for this app.'); + }); }); // Register this device as a named user in AirshipAPI. From 7fc6eb16259a7dbd498de2d7b1fdec071e28baf2 Mon Sep 17 00:00:00 2001 From: war-in Date: Thu, 29 May 2025 14:19:46 +0200 Subject: [PATCH 75/95] fix blinking validate code screen --- src/libs/actions/SignInRedirect.ts | 6 +++++- src/pages/settings/InitialSettingsPage.tsx | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index e90f7ac4d2c4..6baa000c56fa 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -3,7 +3,9 @@ import {getMicroSecondOnyxErrorWithMessage} from '@libs/ErrorUtils'; import {clearSessionStorage} from '@libs/Navigation/helpers/lastVisitedTabPathUtils'; import type {OnyxKey} from '@src/ONYXKEYS'; import ONYXKEYS from '@src/ONYXKEYS'; +import CONFIG from '@src/CONFIG'; import {clearAllPolicies} from './Policy/Policy'; +import {resetSignInFlow} from './HybridApp'; let currentIsOffline: boolean | undefined; let currentShouldForceOffline: boolean | undefined; @@ -24,7 +26,6 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { keysToPreserve.push(ONYXKEYS.PREFERRED_THEME); keysToPreserve.push(ONYXKEYS.ACTIVE_CLIENTS); keysToPreserve.push(ONYXKEYS.DEVICE_ID); - keysToPreserve.push(ONYXKEYS.HYBRID_APP); // 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. @@ -33,6 +34,9 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { } return Onyx.clear(keysToPreserve).then(() => { + if (CONFIG.IS_HYBRID_APP) { + resetSignInFlow(); + } clearAllPolicies(); if (!errorMessage) { return; diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 4e027e96b988..39251bf457e3 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -241,7 +241,6 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr icon: Expensicons.Exit, action: () => { signOut(false); - HybridAppActions.resetSignInFlow(); }, }, ], From 4b3be5349d86c5d148b398942cbf365023048484 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Thu, 29 May 2025 17:41:03 +0200 Subject: [PATCH 76/95] Remove unnecessary workaround --- src/libs/HybridApp.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index c20815e5b629..07154ab2ca04 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -58,10 +58,6 @@ function shouldUseOldApp(tryNewDot?: TryNewDot) { if (!tryNewDot) { return true; } - // TODO: this is a workaround for backend issue with `tryNewDot` being an array - if (Array.isArray(tryNewDot)) { - return false; - } return tryNewDot?.classicRedirect.dismissed === true; } @@ -77,7 +73,6 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryN return; } - // TODO: add tryNewDot undefined check once the backend issue is fixed if (hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && !!credentials?.autoGeneratedLogin && !!credentials?.autoGeneratedPassword) { // It's better to not pass function directly to Log.info to avoid bugs with evaluation const shouldUseOD = shouldUseOldApp(tryNewDot); From dbe184c215bcb892081ce9034c944321fffa32f3 Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Fri, 30 May 2025 12:03:27 +0200 Subject: [PATCH 77/95] Sign out from OldDot when account is closed on NewDot --- src/libs/actions/User.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libs/actions/User.ts b/src/libs/actions/User.ts index 8aa1904599eb..b62fa0d793f4 100644 --- a/src/libs/actions/User.ts +++ b/src/libs/actions/User.ts @@ -115,6 +115,11 @@ function closeAccount(reason: string) { optimisticData, failureData, }); + + // On HybridApp, we need to sign out from the oldDot app as well to keep state of both apps in sync + if (CONFIG.IS_HYBRID_APP) { + HybridAppModule.signOutFromOldDot(); + } } /** From 0e54b4b5f002c386e9c04f15c2115e8cb315adf6 Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Fri, 30 May 2025 14:07:08 +0200 Subject: [PATCH 78/95] Add PermissionStatus mock --- __mocks__/@ua/react-native-airship.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/__mocks__/@ua/react-native-airship.ts b/__mocks__/@ua/react-native-airship.ts index a60053df475e..08ec1b781fc2 100644 --- a/__mocks__/@ua/react-native-airship.ts +++ b/__mocks__/@ua/react-native-airship.ts @@ -6,6 +6,13 @@ enum EventType { PushReceived = 'com.airship.push_received', } +// eslint-disable-next-line no-restricted-syntax +enum PermissionStatus { + Granted = 'granted', + Denied = 'denied', + NotDetermined = 'not_determined', +} + // eslint-disable-next-line @typescript-eslint/no-namespace namespace iOS { /** @@ -71,4 +78,4 @@ const Airship: Partial = { export default Airship; -export {EventType, iOS}; +export {EventType, iOS, PermissionStatus}; From 33ca95aea75d35d36f785d4b4a6a7c922c7182e7 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Fri, 30 May 2025 14:42:03 +0200 Subject: [PATCH 79/95] Fix OD sign in for new accounts --- src/libs/HybridApp.ts | 8 +++++++- src/libs/actions/Session/index.ts | 2 +- src/types/onyx/TryNewDot.ts | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 07154ab2ca04..5391d6e66ea3 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -55,7 +55,7 @@ Onyx.connect({ }); function shouldUseOldApp(tryNewDot?: TryNewDot) { - if (!tryNewDot) { + if (!tryNewDot?.classicRedirect) { return true; } @@ -73,6 +73,12 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryN return; } + if (!!tryNewDot && !tryNewDot.classicRedirect) { + currentHybridApp = hybridApp; + currentTryNewDot = tryNewDot; + return; + } + if (hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && !!credentials?.autoGeneratedLogin && !!credentials?.autoGeneratedPassword) { // It's better to not pass function directly to Log.info to avoid bugs with evaluation const shouldUseOD = shouldUseOldApp(tryNewDot); diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index c1a00f639541..d4cb8ff3b366 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -531,7 +531,7 @@ function setupNewDotAfterTransitionFromOldDot(hybridAppSettings: HybridAppSettin }; const resetDidUserLoginDuringSessionIfNeeded = () => { - if (newDotOnyxValues.nvp_tryNewDot === undefined || tryNewDot?.classicRedirect.dismissed !== true) { + if (newDotOnyxValues.nvp_tryNewDot === undefined || tryNewDot?.classicRedirect?.dismissed !== true) { return Promise.resolve(); } diff --git a/src/types/onyx/TryNewDot.ts b/src/types/onyx/TryNewDot.ts index e63b9d6e3195..4d79b0f36c49 100644 --- a/src/types/onyx/TryNewDot.ts +++ b/src/types/onyx/TryNewDot.ts @@ -5,7 +5,7 @@ type TryNewDot = { /** * This key is mostly used on OldDot. In NewDot, we only use `completedHybridAppOnboarding`. */ - classicRedirect: { + classicRedirect?: { /** * Indicates if transition from OldDot to NewDot should happen in HybridApp. */ @@ -23,7 +23,7 @@ type TryNewDot = { /** * This key is added when user is migrated from OldDot to NewDot with nudge migration as part of a cohort. */ - nudgeMigration: { + nudgeMigration?: { /** Indicates timestamp of an action. */ timestamp: Date; }; From 6281f71e547290077323b79e79a4f9dbaf8dce49 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Tue, 3 Jun 2025 10:41:21 +0200 Subject: [PATCH 80/95] Fix lint and prettier --- src/components/BookTravelButton.tsx | 2 +- src/components/InitialURLContextProvider.tsx | 4 ++-- .../SignInButtons/AppleSignIn/index.android.tsx | 4 ++-- .../SignInButtons/AppleSignIn/index.ios.tsx | 4 ++-- .../SignInButtons/GoogleSignIn/index.native.tsx | 4 ++-- src/libs/HybridApp.ts | 1 + src/libs/actions/SignInRedirect.ts | 4 ++-- src/pages/settings/InitialSettingsPage.tsx | 1 - src/pages/signin/ChooseSSOOrMagicCode.tsx | 14 +++++++------- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/components/BookTravelButton.tsx b/src/components/BookTravelButton.tsx index 362a27afda56..6cbf1d592895 100644 --- a/src/components/BookTravelButton.tsx +++ b/src/components/BookTravelButton.tsx @@ -67,7 +67,7 @@ function BookTravelButton({text, shouldRenderErrorMessageBelowButton = false}: B const groupPaidPolicies = activePolicies.filter((activePolicy) => activePolicy.type !== CONST.POLICY.TYPE.PERSONAL && isPaidGroupPolicy(activePolicy)); // Flag indicating whether NewDot was launched exclusively for Travel, // e.g., when the user selects "Trips" from the Expensify Classic menu in HybridApp. - const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP, {canBeMissing: true}); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP, {canBeMissing: false}); const hidePreventionModal = () => setPreventionModalVisibility(false); const hideVerificationModal = () => setVerificationModalVisibility(false); diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index e1ae363fc770..501b6e8055da 100644 --- a/src/components/InitialURLContextProvider.tsx +++ b/src/components/InitialURLContextProvider.tsx @@ -5,7 +5,7 @@ import {Linking} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import {setupNewDotAfterTransitionFromOldDot} from '@libs/actions/Session'; import Navigation, {navigationRef} from '@navigation/Navigation'; -import * as HybridAppActions from '@userActions/HybridApp'; +import {parseHybridAppSettings} from '@userActions/HybridApp'; import type {AppProps} from '@src/App'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -68,7 +68,7 @@ function InitialURLContextProvider({children, url, hybridAppSettings, timestamp} if (!isLoading) { if (!setupCalled.current) { setupCalled.current = true; - const parsedHybridAppSettings = HybridAppActions.parseHybridAppSettings(hybridAppSettings); + const parsedHybridAppSettings = parseHybridAppSettings(hybridAppSettings); setupNewDotAfterTransitionFromOldDot(parsedHybridAppSettings, tryNewDot).then(() => { handleNavigation(url); if (parsedHybridAppSettings.hybridApp?.loggedOutFromOldDot) { diff --git a/src/components/SignInButtons/AppleSignIn/index.android.tsx b/src/components/SignInButtons/AppleSignIn/index.android.tsx index 2c1547e16cae..643412d901ca 100644 --- a/src/components/SignInButtons/AppleSignIn/index.android.tsx +++ b/src/components/SignInButtons/AppleSignIn/index.android.tsx @@ -4,7 +4,7 @@ import IconButton from '@components/SignInButtons/IconButton'; import {setNewDotSignInState} from '@libs/actions/HybridApp'; import Growl from '@libs/Growl'; import Log from '@libs/Log'; -import * as Session from '@userActions/Session'; +import {beginAppleSignIn} from '@userActions/Session'; import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import type {AppleSignInProps} from '.'; @@ -41,7 +41,7 @@ function AppleSignIn({onPress = () => {}}: AppleSignInProps) { appleSignInRequest() .then((token) => { setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); - Session.beginAppleSignIn(token); + beginAppleSignIn(token); }) .catch((error: Record) => { if (error.message === appleAuthAndroid.Error.SIGNIN_CANCELLED) { diff --git a/src/components/SignInButtons/AppleSignIn/index.ios.tsx b/src/components/SignInButtons/AppleSignIn/index.ios.tsx index 164dde36a8cf..6232e922eaec 100644 --- a/src/components/SignInButtons/AppleSignIn/index.ios.tsx +++ b/src/components/SignInButtons/AppleSignIn/index.ios.tsx @@ -5,7 +5,7 @@ import IconButton from '@components/SignInButtons/IconButton'; import {setNewDotSignInState} from '@libs/actions/HybridApp'; import Growl from '@libs/Growl'; import Log from '@libs/Log'; -import * as Session from '@userActions/Session'; +import {beginAppleSignIn} from '@userActions/Session'; import CONST from '@src/CONST'; import type {AppleSignInProps} from '.'; @@ -41,7 +41,7 @@ function AppleSignIn({onPress = () => {}}: AppleSignInProps) { appleSignInRequest() .then((token) => { setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); - Session.beginAppleSignIn(token); + beginAppleSignIn(token); }) .catch((error: {code: AppleError}) => { if (error.code === appleAuth.Error.CANCELED) { diff --git a/src/components/SignInButtons/GoogleSignIn/index.native.tsx b/src/components/SignInButtons/GoogleSignIn/index.native.tsx index 999c0e9464d2..26e35964c795 100644 --- a/src/components/SignInButtons/GoogleSignIn/index.native.tsx +++ b/src/components/SignInButtons/GoogleSignIn/index.native.tsx @@ -4,7 +4,7 @@ import IconButton from '@components/SignInButtons/IconButton'; import {setNewDotSignInState} from '@libs/actions/HybridApp'; import Growl from '@libs/Growl'; import Log from '@libs/Log'; -import * as Session from '@userActions/Session'; +import {beginGoogleSignIn} from '@userActions/Session'; import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import type {GoogleSignInProps} from '.'; @@ -29,7 +29,7 @@ function googleSignInRequest() { .then((response) => response.idToken) .then((token) => { setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); - Session.beginGoogleSignIn(token); + beginGoogleSignIn(token); }) .catch((error: GoogleError | undefined) => { // Handle unexpected error shape diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 5391d6e66ea3..f9aec5a6dd9e 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -88,6 +88,7 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryN autoGeneratedPassword: credentials.autoGeneratedPassword, authToken: currentSession?.authToken ?? '', email: getCurrentUserEmail() ?? '', + // eslint-disable-next-line rulesdir/no-default-id-values policyID: activePolicyID ?? '', }); setUseNewDotSignInPage(false).then(() => { diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index 6baa000c56fa..b00948d79add 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -1,11 +1,11 @@ import Onyx from 'react-native-onyx'; import {getMicroSecondOnyxErrorWithMessage} from '@libs/ErrorUtils'; import {clearSessionStorage} from '@libs/Navigation/helpers/lastVisitedTabPathUtils'; +import CONFIG from '@src/CONFIG'; import type {OnyxKey} from '@src/ONYXKEYS'; import ONYXKEYS from '@src/ONYXKEYS'; -import CONFIG from '@src/CONFIG'; -import {clearAllPolicies} from './Policy/Policy'; import {resetSignInFlow} from './HybridApp'; +import {clearAllPolicies} from './Policy/Policy'; let currentIsOffline: boolean | undefined; let currentShouldForceOffline: boolean | undefined; diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 1df59d332400..06e6c6e3c731 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -40,7 +40,6 @@ import type SETTINGS_TO_RHP from '@navigation/linkingConfig/RELATIONS/SETTINGS_T import {showContextMenu} from '@pages/home/report/ContextMenu/ReportActionContextMenu'; import variables from '@styles/variables'; import {confirmReadyToOpenApp} from '@userActions/App'; -import * as HybridAppActions from '@userActions/HybridApp'; import {openExternalLink} from '@userActions/Link'; import {hasPaymentMethodError} from '@userActions/PaymentMethods'; import {isSupportAuthToken, signOutAndRedirectToSignIn} from '@userActions/Session'; diff --git a/src/pages/signin/ChooseSSOOrMagicCode.tsx b/src/pages/signin/ChooseSSOOrMagicCode.tsx index 91a355bad2ab..fab3cd258008 100644 --- a/src/pages/signin/ChooseSSOOrMagicCode.tsx +++ b/src/pages/signin/ChooseSSOOrMagicCode.tsx @@ -10,9 +10,9 @@ import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as ErrorUtils from '@libs/ErrorUtils'; +import {getLatestErrorMessage} from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; -import * as Session from '@userActions/Session'; +import {clearSignInData, resendValidateCode} from '@userActions/Session'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -32,8 +32,8 @@ function ChooseSSOOrMagicCode({setIsUsingMagicCode}: ChooseSSOOrMagicCodeProps) const {isOffline} = useNetwork(); const {shouldUseNarrowLayout} = useResponsiveLayout(); - const [account] = useOnyx(ONYXKEYS.ACCOUNT); - const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); + const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false}); + const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS, {canBeMissing: true}); // This view doesn't have a field for user input, so dismiss the device keyboard if shown useFocusEffect( @@ -74,12 +74,12 @@ function ChooseSSOOrMagicCode({setIsUsingMagicCode}: ChooseSSOOrMagicCodeProps) text={translate('samlSignIn.useMagicCode')} isLoading={account?.isLoading && account?.loadingForm === (account?.requiresTwoFactorAuth ? CONST.FORMS.VALIDATE_TFA_CODE_FORM : CONST.FORMS.VALIDATE_CODE_FORM)} onPress={() => { - Session.resendValidateCode(credentials?.login); + resendValidateCode(credentials?.login); setIsUsingMagicCode(true); }} /> - {!!account && !isEmptyObject(account.errors) && } - Session.clearSignInData()} /> + {!!account && !isEmptyObject(account.errors) && } + clearSignInData()} /> From 140438d0ba99dccf56fd82a75549c6e41fafcf48 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Tue, 3 Jun 2025 11:17:11 +0200 Subject: [PATCH 81/95] Fix changed files lint --- src/pages/signin/SAMLSignInPage/index.native.tsx | 8 ++++---- src/pages/signin/SignUpWelcomeForm.tsx | 12 ++++++------ .../signin/ValidateCodeForm/BaseValidateCodeForm.tsx | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index 1384fea5dd9a..3d37272549af 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -7,7 +7,7 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton'; import SAMLLoadingIndicator from '@components/SAMLLoadingIndicator'; import ScreenWrapper from '@components/ScreenWrapper'; import useLocalize from '@hooks/useLocalize'; -import * as HybridAppActions from '@libs/actions/HybridApp'; +import {setNewDotSignInState} from '@libs/actions/HybridApp'; import getPlatform from '@libs/getPlatform'; import getUAForWebView from '@libs/getUAForWebView'; import Log from '@libs/Log'; @@ -20,8 +20,8 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; function SAMLSignInPage() { - const [account] = useOnyx(ONYXKEYS.ACCOUNT); - const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); + const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false}); + const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS, {canBeMissing: true}); const [showNavigation, shouldShowNavigation] = useState(true); const [SAMLUrl, setSAMLUrl] = useState(''); const webViewRef = useRef(null); @@ -71,7 +71,7 @@ function SAMLSignInPage() { if (!account?.isLoading && credentials?.login && !!shortLivedAuthToken) { Log.info('SAMLSignInPage - Successfully received shortLivedAuthToken. Signing in...'); signInWithShortLivedAuthToken(shortLivedAuthToken); - HybridAppActions.setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); } // If the login attempt is unsuccessful, set the error message for the account and redirect to sign in page diff --git a/src/pages/signin/SignUpWelcomeForm.tsx b/src/pages/signin/SignUpWelcomeForm.tsx index 4552b8e05105..a52efa042e8d 100644 --- a/src/pages/signin/SignUpWelcomeForm.tsx +++ b/src/pages/signin/SignUpWelcomeForm.tsx @@ -6,9 +6,9 @@ import FormHelpMessage from '@components/FormHelpMessage'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as ErrorUtils from '@libs/ErrorUtils'; +import {getLatestErrorMessage} from '@libs/ErrorUtils'; import {setNewDotSignInState, setReadyToShowAuthScreens} from '@userActions/HybridApp'; -import * as Session from '@userActions/Session'; +import {clearSignInData, signUpUser} from '@userActions/Session'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ChangeExpensifyLoginLink from './ChangeExpensifyLoginLink'; @@ -18,8 +18,8 @@ function SignUpWelcomeForm() { const network = useNetwork(); const styles = useThemeStyles(); const {translate} = useLocalize(); - const [account] = useOnyx(ONYXKEYS.ACCOUNT); - const serverErrorText = useMemo(() => (account ? ErrorUtils.getLatestErrorMessage(account) : ''), [account]); + const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false}); + const serverErrorText = useMemo(() => (account ? getLatestErrorMessage(account) : ''), [account]); return ( <> @@ -32,7 +32,7 @@ function SignUpWelcomeForm() { isLoading={account?.isLoading} onPress={() => { setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); - Session.signUpUser(); + signUpUser(); setReadyToShowAuthScreens(true); }} pressOnEnter @@ -44,7 +44,7 @@ function SignUpWelcomeForm() { message={serverErrorText} /> )} - Session.clearSignInData()} /> + clearSignInData()} /> diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx index 656591db8ffe..3783b5b180e3 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -24,7 +24,7 @@ import {getLatestErrorMessage} from '@libs/ErrorUtils'; import {isValidRecoveryCode, isValidTwoFactorCode, isValidValidateCode} from '@libs/ValidationUtils'; import ChangeExpensifyLoginLink from '@pages/signin/ChangeExpensifyLoginLink'; import Terms from '@pages/signin/Terms'; -import * as HybridAppActions from '@userActions/HybridApp'; +import {resetSignInFlow, setNewDotSignInState} from '@userActions/HybridApp'; import {clearAccountMessages, clearSignInData as sessionActionsClearSignInData, signIn, signInWithValidateCode} from '@userActions/Session'; import {resendValidateCode as userActionsResendValidateCode} from '@userActions/User'; import CONFIG from '@src/CONFIG'; @@ -52,7 +52,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true}); const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS, {canBeMissing: true}); const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false}); - const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP, {canBeMissing: false}); const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); @@ -157,7 +157,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco */ const resendValidateCode = () => { if (CONFIG.IS_HYBRID_APP) { - HybridAppActions.resetSignInFlow(); + resetSignInFlow(); } userActionsResendValidateCode(credentials?.login ?? ''); @@ -244,7 +244,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco return; } if (CONFIG.IS_HYBRID_APP) { - HybridAppActions.resetSignInFlow(); + resetSignInFlow(); } if (account?.errors) { clearAccountMessages(); @@ -293,7 +293,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco const recoveryCodeOr2faCode = isUsingRecoveryCode ? recoveryCode : twoFactorAuthCode; - HybridAppActions.setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); + setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); const accountID = credentials?.accountID; if (accountID) { signInWithValidateCode(accountID, validateCode, recoveryCodeOr2faCode); From 85af8ef93c4a27fc0503144fe60e29ca5c5302b5 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Thu, 5 Jun 2025 17:13:52 +0200 Subject: [PATCH 82/95] fix google sign-in redirect --- src/libs/HybridApp.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index f9aec5a6dd9e..c3768e33a2b4 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -55,11 +55,10 @@ Onyx.connect({ }); function shouldUseOldApp(tryNewDot?: TryNewDot) { - if (!tryNewDot?.classicRedirect) { + if (!!tryNewDot && !tryNewDot.classicRedirect) { return true; } - - return tryNewDot?.classicRedirect.dismissed === true; + return tryNewDot?.classicRedirect?.dismissed === true; } function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry, credentials: OnyxEntry) { @@ -73,13 +72,7 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryN return; } - if (!!tryNewDot && !tryNewDot.classicRedirect) { - currentHybridApp = hybridApp; - currentTryNewDot = tryNewDot; - return; - } - - if (hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && !!credentials?.autoGeneratedLogin && !!credentials?.autoGeneratedPassword) { + if (hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && tryNewDot !== undefined && !!credentials?.autoGeneratedLogin && !!credentials?.autoGeneratedPassword) { // It's better to not pass function directly to Log.info to avoid bugs with evaluation const shouldUseOD = shouldUseOldApp(tryNewDot); Log.info(`[HybridApp] Performing sign-in${shouldUseOD ? '' : ' (in background)'} on OldDot side`); From 24b4c7bc9d6dc3f54330fd1ea8cf3be2df829b75 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Mon, 9 Jun 2025 12:58:15 +0200 Subject: [PATCH 83/95] Fix tryNewDot onyx updates --- src/libs/actions/QueuedOnyxUpdates.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/QueuedOnyxUpdates.ts b/src/libs/actions/QueuedOnyxUpdates.ts index 67c58bb1f7f9..c8072d86cd39 100644 --- a/src/libs/actions/QueuedOnyxUpdates.ts +++ b/src/libs/actions/QueuedOnyxUpdates.ts @@ -32,6 +32,7 @@ function flushQueue(): Promise { if (!currentAccountID && !CONFIG.IS_TEST_ENV && !CONFIG.E2E_TESTING) { const preservedKeys: OnyxKey[] = [ + ONYXKEYS.NVP_TRY_NEW_DOT, ONYXKEYS.NVP_TRY_FOCUS_MODE, ONYXKEYS.PREFERRED_THEME, ONYXKEYS.NVP_PREFERRED_LOCALE, From 0822cc2d6974ea47460fc89c89db7310f2ef13ee Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Mon, 9 Jun 2025 15:41:50 +0200 Subject: [PATCH 84/95] Disable spell check on ids --- src/CONFIG.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/CONFIG.ts b/src/CONFIG.ts index 8a02d2673de1..569995f679c9 100644 --- a/src/CONFIG.ts +++ b/src/CONFIG.ts @@ -95,8 +95,11 @@ export default { GOOGLE_SIGN_IN: { // cspell:disable-next-line WEB_CLIENT_ID: '921154746561-gpsoaqgqfuqrfsjdf8l7vohfkfj7b9up.apps.googleusercontent.com', + // cspell:disable-next-line IOS_CLIENT_ID: '921154746561-s3uqn2oe4m85tufi6mqflbfbuajrm2i3.apps.googleusercontent.com', + // cspell:disable-next-line HYBRID_APP_WEB_CLIENT_ID: '1008697809946-5e095eqem3o6ugtpc2rjf7v880tcp28p.apps.googleusercontent.com', + // cspell:disable-next-line HYBRID_APP_IOS_CLIENT_ID: '1008697809946-sh04nqq0hea396s1qdqqbj6ia649odb2.apps.googleusercontent.com', }, GCP_GEOLOCATION_API_KEY: googleGeolocationAPIKey, From 18b2056c080b116373d9697c190e7af325f00946 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Tue, 10 Jun 2025 11:24:59 +0200 Subject: [PATCH 85/95] Remmove Google and Apple growls --- src/components/SignInButtons/AppleSignIn/index.android.tsx | 3 --- src/components/SignInButtons/AppleSignIn/index.ios.tsx | 2 -- src/components/SignInButtons/GoogleSignIn/index.native.tsx | 6 ------ 3 files changed, 11 deletions(-) diff --git a/src/components/SignInButtons/AppleSignIn/index.android.tsx b/src/components/SignInButtons/AppleSignIn/index.android.tsx index 643412d901ca..46cf0e0ab46d 100644 --- a/src/components/SignInButtons/AppleSignIn/index.android.tsx +++ b/src/components/SignInButtons/AppleSignIn/index.android.tsx @@ -2,7 +2,6 @@ import {appleAuthAndroid} from '@invertase/react-native-apple-authentication'; import React from 'react'; import IconButton from '@components/SignInButtons/IconButton'; import {setNewDotSignInState} from '@libs/actions/HybridApp'; -import Growl from '@libs/Growl'; import Log from '@libs/Log'; import {beginAppleSignIn} from '@userActions/Session'; import CONFIG from '@src/CONFIG'; @@ -45,10 +44,8 @@ function AppleSignIn({onPress = () => {}}: AppleSignInProps) { }) .catch((error: Record) => { if (error.message === appleAuthAndroid.Error.SIGNIN_CANCELLED) { - Growl.error('[Apple In] Apple Sign In cancelled'); return null; } - Growl.error(`[Apple Sign In] Apple authentication failed`); Log.alert('[Apple Sign In] Apple authentication failed', error); }); }; diff --git a/src/components/SignInButtons/AppleSignIn/index.ios.tsx b/src/components/SignInButtons/AppleSignIn/index.ios.tsx index 6232e922eaec..de808ecd49cb 100644 --- a/src/components/SignInButtons/AppleSignIn/index.ios.tsx +++ b/src/components/SignInButtons/AppleSignIn/index.ios.tsx @@ -3,7 +3,6 @@ import type {AppleError} from '@invertase/react-native-apple-authentication'; import React from 'react'; import IconButton from '@components/SignInButtons/IconButton'; import {setNewDotSignInState} from '@libs/actions/HybridApp'; -import Growl from '@libs/Growl'; import Log from '@libs/Log'; import {beginAppleSignIn} from '@userActions/Session'; import CONST from '@src/CONST'; @@ -25,7 +24,6 @@ function appleSignInRequest(): Promise { appleAuth.getCredentialStateForUser(response.user).then((credentialState) => { if (credentialState !== appleAuth.State.AUTHORIZED) { Log.alert('[Apple Sign In] Authentication failed. Original response: ', {response}); - Growl.error(`[Apple Sign In] Authentication failed. Original response: ${JSON.stringify(response)}`); throw new Error('Authentication failed'); } return response.identityToken; diff --git a/src/components/SignInButtons/GoogleSignIn/index.native.tsx b/src/components/SignInButtons/GoogleSignIn/index.native.tsx index 26e35964c795..afdc9edb0bd3 100644 --- a/src/components/SignInButtons/GoogleSignIn/index.native.tsx +++ b/src/components/SignInButtons/GoogleSignIn/index.native.tsx @@ -2,7 +2,6 @@ import {GoogleSignin, statusCodes} from '@react-native-google-signin/google-sign import React from 'react'; import IconButton from '@components/SignInButtons/IconButton'; import {setNewDotSignInState} from '@libs/actions/HybridApp'; -import Growl from '@libs/Growl'; import Log from '@libs/Log'; import {beginGoogleSignIn} from '@userActions/Session'; import CONFIG from '@src/CONFIG'; @@ -35,7 +34,6 @@ function googleSignInRequest() { // Handle unexpected error shape if (error?.code === undefined) { Log.alert(`[Google Sign In] Google sign in failed: ${JSON.stringify(error)}`); - Growl.error(`[Google Sign In] Google sign in failed: ${JSON.stringify(error)}`); return; } /** The logged code is useful for debugging any new errors that are not specifically handled. To decode, see: @@ -44,12 +42,8 @@ function googleSignInRequest() { */ if (error.code === statusCodes.SIGN_IN_CANCELLED) { Log.info('[Google Sign In] Google Sign In cancelled'); - // TODO: Growl is temporary to allow debugging - Growl.error('[Google Sign In] Google Sign In cancelled'); } else { Log.alert(`[Google Sign In] Error Code: ${error.code}. ${error.message}`, {}, false); - // TODO: Growl is temporary to allow debugging - Growl.error(`[Google Sign In] Error Code: ${error.code}. ${error.message}`); } }); } From 1708d627529f25dad74fdfb1256d1a6c602da6f3 Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 10 Jun 2025 12:01:21 +0200 Subject: [PATCH 86/95] post-merge fixes --- src/HybridAppHandler.tsx | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/HybridAppHandler.tsx b/src/HybridAppHandler.tsx index 59ec56bc1bcf..7893921971f7 100644 --- a/src/HybridAppHandler.tsx +++ b/src/HybridAppHandler.tsx @@ -1,20 +1,33 @@ -import {useContext, useState} from 'react'; -import type {AppProps} from './App'; +import { useContext, useState } from 'react'; +import { useOnyx } from 'react-native-onyx'; +import ONYXKEYS from './ONYXKEYS'; +import isLoadingOnyxValue from './types/utils/isLoadingOnyxValue'; +import {parseHybridAppSettings} from './libs/actions/HybridApp'; +import type { AppProps } from './App'; import CONFIG from './CONFIG'; import CONST from './CONST'; -import {signInAfterTransitionFromOldDot} from './libs/actions/Session'; +import { setupNewDotAfterTransitionFromOldDot } from './libs/actions/Session'; import SplashScreenStateContext from './SplashScreenStateContext'; + function HybridAppHandler({hybridAppSettings}: AppProps) { const [signInHandled, setSignInHandled] = useState(false); - const {setSplashScreenState} = useContext(SplashScreenStateContext); + const {splashScreenState, setSplashScreenState} = useContext(SplashScreenStateContext); + const [tryNewDot, tryNewDotMetadata] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT, {canBeMissing: true}); + + const isLoading = isLoadingOnyxValue(tryNewDotMetadata); - if (!CONFIG.IS_HYBRID_APP || !hybridAppSettings || signInHandled) { + if (!CONFIG.IS_HYBRID_APP || !hybridAppSettings || signInHandled || isLoading) { return null; } - signInAfterTransitionFromOldDot(hybridAppSettings).then(() => { - setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); + const parsedHybridAppSettings = parseHybridAppSettings(hybridAppSettings); + setupNewDotAfterTransitionFromOldDot(parsedHybridAppSettings, tryNewDot).then(() => { + if (parsedHybridAppSettings.hybridApp?.loggedOutFromOldDot) { + setSplashScreenState(CONST.BOOT_SPLASH_STATE.HIDDEN); + } else if (splashScreenState === CONST.BOOT_SPLASH_STATE.VISIBLE) { + setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); + } setSignInHandled(true); }); From 7a74fe97edfe86199decf79e9c593b8a224834e3 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Tue, 10 Jun 2025 13:18:22 +0200 Subject: [PATCH 87/95] Fix prettier --- src/HybridAppHandler.tsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/HybridAppHandler.tsx b/src/HybridAppHandler.tsx index 7893921971f7..011e8998a43c 100644 --- a/src/HybridAppHandler.tsx +++ b/src/HybridAppHandler.tsx @@ -1,14 +1,13 @@ -import { useContext, useState } from 'react'; -import { useOnyx } from 'react-native-onyx'; -import ONYXKEYS from './ONYXKEYS'; -import isLoadingOnyxValue from './types/utils/isLoadingOnyxValue'; -import {parseHybridAppSettings} from './libs/actions/HybridApp'; -import type { AppProps } from './App'; +import {useContext, useState} from 'react'; +import {useOnyx} from 'react-native-onyx'; +import type {AppProps} from './App'; import CONFIG from './CONFIG'; import CONST from './CONST'; -import { setupNewDotAfterTransitionFromOldDot } from './libs/actions/Session'; +import {parseHybridAppSettings} from './libs/actions/HybridApp'; +import {setupNewDotAfterTransitionFromOldDot} from './libs/actions/Session'; +import ONYXKEYS from './ONYXKEYS'; import SplashScreenStateContext from './SplashScreenStateContext'; - +import isLoadingOnyxValue from './types/utils/isLoadingOnyxValue'; function HybridAppHandler({hybridAppSettings}: AppProps) { const [signInHandled, setSignInHandled] = useState(false); From 31cd24f69f062414d3a78ac91fa2592611d2256d Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Fri, 13 Jun 2025 13:52:29 +0200 Subject: [PATCH 88/95] Fix account switcher disappearing --- src/libs/actions/Session/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 5df94164d3ec..3096061b7fe7 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -3,7 +3,7 @@ import throttle from 'lodash/throttle'; import type {ChannelAuthorizationData} from 'pusher-js/types/src/core/auth/options'; import type {ChannelAuthorizationCallback} from 'pusher-js/with-encryption'; import {InteractionManager, Linking} from 'react-native'; -import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx'; +import type {OnyxEntry, OnyxKey, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import * as PersistedRequests from '@libs/actions/PersistedRequests'; @@ -584,7 +584,7 @@ function setupNewDotAfterTransitionFromOldDot(hybridAppSettings: HybridAppSettin }), ) .then(resetDidUserLoginDuringSessionIfNeeded) - .then(() => Onyx.multiSet(newDotOnyxValues)) + .then(() => Promise.all(Object.entries(newDotOnyxValues).map(([key, value]) => Onyx.merge(key as OnyxKey, value ?? {})))) .then(() => { isSetUpReady = true; return Promise.resolve(); From a13958630c0edabffa914ff3b6262eff5877cfc4 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Fri, 13 Jun 2025 14:35:23 +0200 Subject: [PATCH 89/95] Fix copilot not working on first try --- src/pages/settings/InitialSettingsPage.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 30c82053cc17..084167e60ef3 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -29,6 +29,7 @@ import useSingleExecution from '@hooks/useSingleExecution'; import useSubscriptionPlan from '@hooks/useSubscriptionPlan'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; +import '@libs/actions/Delegate'; import {resetExitSurveyForm} from '@libs/actions/ExitSurvey'; import {checkIfFeedConnectionIsBroken} from '@libs/CardUtils'; import {convertToDisplayString} from '@libs/CurrencyUtils'; From 28bd4ced0bf14e1a8ca6d194bfdbaeab82c8e51f Mon Sep 17 00:00:00 2001 From: war-in Date: Fri, 13 Jun 2025 14:45:32 +0200 Subject: [PATCH 90/95] add HYBRID_APP to preserved keys --- src/libs/actions/App.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index 8426468d9e84..99a25b0ac815 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -137,6 +137,7 @@ const KEYS_TO_PRESERVE: OnyxKey[] = [ ONYXKEYS.NVP_PREFERRED_LOCALE, ONYXKEYS.CREDENTIALS, ONYXKEYS.PRESERVED_USER_SESSION, + ONYXKEYS.HYBRID_APP, ]; Onyx.connect({ From a268585ec107d6fde45d25391e0fcd269abbcb3d Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Mon, 16 Jun 2025 12:51:22 +0200 Subject: [PATCH 91/95] Simplify shouldInit --- src/Expensify.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 9352b9509996..5c5fbde9c2ee 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -115,7 +115,7 @@ function Expensify() { const isAuthenticated = useIsAuthenticated(); const autoAuthState = useMemo(() => session?.autoAuthState ?? '', [session]); - const shouldInit = CONFIG.IS_HYBRID_APP ? !hybridApp?.loggedOutFromOldDot && isNavigationReady && hasAttemptedToOpenPublicRoom : isNavigationReady && hasAttemptedToOpenPublicRoom; + const shouldInit = isNavigationReady && hasAttemptedToOpenPublicRoom && ( CONFIG.IS_HYBRID_APP ? !hybridApp?.loggedOutFromOldDot : true) const shouldHideSplash = shouldInit && (CONFIG.IS_HYBRID_APP From df50cd47da380b8e767f49a4ce2ac3d1b7f72a80 Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Mon, 16 Jun 2025 12:53:58 +0200 Subject: [PATCH 92/95] Remove setRootStatusBarEnabled --- .../OnboardingAccounting/BaseOnboardingAccounting.tsx | 7 ++----- .../settings/Security/MergeAccounts/MergeResultPage.tsx | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index 57b648e733af..e1d05b5e1d57 100644 --- a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx +++ b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx @@ -1,10 +1,9 @@ import HybridAppModule from '@expensify/react-native-hybrid-app'; -import React, {useCallback, useContext, useEffect, useMemo, useState} from 'react'; +import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {InteractionManager, View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import type {SvgProps} from 'react-native-svg'; import Button from '@components/Button'; -import CustomStatusBarAndBackgroundContext from '@components/CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import FixedFooter from '@components/FixedFooter'; import FormHelpMessage from '@components/FormHelpMessage'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; @@ -99,7 +98,6 @@ function BaseOnboardingAccounting({shouldUseNativeStyles}: BaseOnboardingAccount const theme = useTheme(); const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); - const {setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext); // We need to use isSmallScreenWidth, see navigateAfterOnboarding function comment // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth @@ -137,13 +135,12 @@ function BaseOnboardingAccounting({shouldUseNativeStyles}: BaseOnboardingAccount if (CONFIG.IS_HYBRID_APP) { HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); - setRootStatusBarEnabled(false); return; } waitForIdle().then(() => { openOldDotLink(CONST.OLDDOT_URLS.INBOX, true); }); - }, [isLoading, prevIsLoading, setRootStatusBarEnabled]); + }, [isLoading, prevIsLoading]); const accountingOptions: OnboardingListItem[] = useMemo(() => { const createAccountingOption = (integration: Integration): OnboardingListItem => ({ diff --git a/src/pages/settings/Security/MergeAccounts/MergeResultPage.tsx b/src/pages/settings/Security/MergeAccounts/MergeResultPage.tsx index 3435b54c5729..09a238939951 100644 --- a/src/pages/settings/Security/MergeAccounts/MergeResultPage.tsx +++ b/src/pages/settings/Security/MergeAccounts/MergeResultPage.tsx @@ -1,12 +1,11 @@ import HybridAppModule from '@expensify/react-native-hybrid-app'; import {useRoute} from '@react-navigation/native'; -import React, {useContext, useEffect, useMemo} from 'react'; +import React, {useEffect, useMemo} from 'react'; import {InteractionManager} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import ConfirmationPage from '@components/ConfirmationPage'; import type {ConfirmationPageProps} from '@components/ConfirmationPage'; -import CustomStatusBarAndBackgroundContext from '@components/CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import * as Illustrations from '@components/Icon/Illustrations'; import LottieAnimations from '@components/LottieAnimations'; @@ -29,7 +28,6 @@ import SCREENS from '@src/SCREENS'; function MergeResultPage() { const styles = useThemeStyles(); const {translate} = useLocalize(); - const {setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext); const [userEmailOrPhone] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.email, canBeMissing: true}); const {params} = useRoute>(); const {result, login} = params; @@ -154,7 +152,6 @@ function MergeResultPage() { onSecondaryButtonPress: () => { if (CONFIG.IS_HYBRID_APP) { HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); - setRootStatusBarEnabled(false); return; } openOldDotLink(CONST.OLDDOT_URLS.INBOX, false); @@ -234,7 +231,7 @@ function MergeResultPage() { illustration: Illustrations.LockClosedOrange, }, }; - }, [setRootStatusBarEnabled, login, translate, userEmailOrPhone, styles]); + }, [login, translate, userEmailOrPhone, styles]); useEffect(() => { /** From 9ef3a9178830183cbf416ca68e6ae4eeca4d8c1a Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Mon, 16 Jun 2025 13:14:33 +0200 Subject: [PATCH 93/95] Fix prettier --- src/Expensify.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 5c5fbde9c2ee..9d4baf2255b3 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -115,7 +115,7 @@ function Expensify() { const isAuthenticated = useIsAuthenticated(); const autoAuthState = useMemo(() => session?.autoAuthState ?? '', [session]); - const shouldInit = isNavigationReady && hasAttemptedToOpenPublicRoom && ( CONFIG.IS_HYBRID_APP ? !hybridApp?.loggedOutFromOldDot : true) + const shouldInit = isNavigationReady && hasAttemptedToOpenPublicRoom && (CONFIG.IS_HYBRID_APP ? !hybridApp?.loggedOutFromOldDot : true); const shouldHideSplash = shouldInit && (CONFIG.IS_HYBRID_APP From a747b041db4a5c15516273ea22eaee95714c01e6 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Mon, 16 Jun 2025 14:29:40 +0200 Subject: [PATCH 94/95] Protect hybridApp functions on standalone --- src/components/BookTravelButton.tsx | 2 +- src/libs/actions/HybridApp/index.ts | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/components/BookTravelButton.tsx b/src/components/BookTravelButton.tsx index 33fc7fb6e123..68fab675638a 100644 --- a/src/components/BookTravelButton.tsx +++ b/src/components/BookTravelButton.tsx @@ -70,7 +70,7 @@ function BookTravelButton({text, shouldRenderErrorMessageBelowButton = false, se const groupPaidPolicies = activePolicies.filter((activePolicy) => activePolicy.type !== CONST.POLICY.TYPE.PERSONAL && isPaidGroupPolicy(activePolicy)); // Flag indicating whether NewDot was launched exclusively for Travel, // e.g., when the user selects "Trips" from the Expensify Classic menu in HybridApp. - const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP, {canBeMissing: false}); + const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP, {canBeMissing: true}); const hidePreventionModal = () => setPreventionModalVisibility(false); const hideVerificationModal = () => setVerificationModalVisibility(false); diff --git a/src/libs/actions/HybridApp/index.ts b/src/libs/actions/HybridApp/index.ts index bf51b8b2a813..6f655b83a4bb 100644 --- a/src/libs/actions/HybridApp/index.ts +++ b/src/libs/actions/HybridApp/index.ts @@ -1,5 +1,6 @@ import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; +import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {HybridApp} from '@src/types/onyx'; @@ -16,6 +17,10 @@ function parseHybridAppSettings(hybridAppSettings: string): HybridAppSettings { * Changes value of `readyToShowAuthScreens` */ function setReadyToShowAuthScreens(readyToShowAuthScreens: boolean) { + // This value is only relevant for HybridApp, so we can skip it in other environments. + if (!CONFIG.IS_HYBRID_APP) { + return; + } Onyx.merge(ONYXKEYS.HYBRID_APP, {readyToShowAuthScreens}); } @@ -23,14 +28,26 @@ function setReadyToShowAuthScreens(readyToShowAuthScreens: boolean) { * Changes NewDot sign-in state */ function setNewDotSignInState(newDotSignInState: ValueOf) { + // This value is only relevant for HybridApp, so we can skip it in other environments. + if (!CONFIG.IS_HYBRID_APP) { + return; + } Onyx.merge(ONYXKEYS.HYBRID_APP, {newDotSignInState}); } function setUseNewDotSignInPage(useNewDotSignInPage: boolean) { + // This value is only relevant for HybridApp, so we can skip it in other environments. + if (!CONFIG.IS_HYBRID_APP) { + return Promise.resolve(); + } return Onyx.merge(ONYXKEYS.HYBRID_APP, {useNewDotSignInPage}); } function setClosingReactNativeApp(closingReactNativeApp: boolean) { + // This value is only relevant for HybridApp, so we can skip it in other environments. + if (!CONFIG.IS_HYBRID_APP) { + return; + } Onyx.merge(ONYXKEYS.HYBRID_APP, {closingReactNativeApp}); } @@ -38,6 +55,11 @@ function setClosingReactNativeApp(closingReactNativeApp: boolean) { * Starts HybridApp sign-in flow from the beginning. */ function resetSignInFlow() { + // This value is only relevant for HybridApp, so we can skip it in other environments. + if (!CONFIG.IS_HYBRID_APP) { + return; + } + Onyx.merge(ONYXKEYS.HYBRID_APP, { readyToShowAuthScreens: false, newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED, From cc53169f79c037abd42bdca47fca01ffabd3f5ee Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Mon, 16 Jun 2025 16:45:35 +0200 Subject: [PATCH 95/95] Move setClosingReactNative to a wrapper --- modules/hybrid-app/src/index.native.ts | 2 -- src/components/BookTravelButton.tsx | 4 ++-- src/components/ScreenWrapper/index.tsx | 4 ++-- src/libs/HybridApp.ts | 3 ++- src/libs/actions/Session/index.ts | 9 +++++++++ src/pages/ErrorPage/SessionExpiredPage.tsx | 4 ++-- .../OnboardingAccounting/BaseOnboardingAccounting.tsx | 4 ++-- .../home/sidebar/FloatingActionButtonAndPopover.tsx | 5 ++--- src/pages/settings/InitialSettingsPage.tsx | 4 ++-- .../settings/Security/MergeAccounts/MergeResultPage.tsx | 4 ++-- 10 files changed, 25 insertions(+), 18 deletions(-) diff --git a/modules/hybrid-app/src/index.native.ts b/modules/hybrid-app/src/index.native.ts index 07e331bd5593..83d342cf922f 100644 --- a/modules/hybrid-app/src/index.native.ts +++ b/modules/hybrid-app/src/index.native.ts @@ -1,4 +1,3 @@ -import {setClosingReactNativeApp} from '@userActions/HybridApp'; import ReactNativeHybridApp from './NativeReactNativeHybridApp'; import type HybridAppModuleType from './types'; @@ -10,7 +9,6 @@ const HybridAppModule: HybridAppModuleType = { ReactNativeHybridApp.shouldUseStaging(isStaging); }, closeReactNativeApp({shouldSignOut, shouldSetNVP}) { - setClosingReactNativeApp(true); ReactNativeHybridApp.closeReactNativeApp(shouldSignOut, shouldSetNVP); }, completeOnboarding({status}) { diff --git a/src/components/BookTravelButton.tsx b/src/components/BookTravelButton.tsx index 68fab675638a..34cedb85eec0 100644 --- a/src/components/BookTravelButton.tsx +++ b/src/components/BookTravelButton.tsx @@ -1,4 +1,3 @@ -import HybridAppModule from '@expensify/react-native-hybrid-app'; import {Str} from 'expensify-common'; import type {ReactElement} from 'react'; import React, {useCallback, useEffect, useState} from 'react'; @@ -10,6 +9,7 @@ import usePolicy from '@hooks/usePolicy'; import useStyleUtils from '@hooks/useStyleUtils'; import useThemeStyles from '@hooks/useThemeStyles'; import {openTravelDotLink} from '@libs/actions/Link'; +import {closeReactNativeApp} from '@libs/actions/Session'; import {cleanupTravelProvisioningSession} from '@libs/actions/Travel'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; @@ -135,7 +135,7 @@ function BookTravelButton({text, shouldRenderErrorMessageBelowButton = false, se // Close NewDot if it was opened only for Travel, as its purpose is now fulfilled. Log.info('[HybridApp] Returning to OldDot after opening TravelDot'); - HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); + closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); }) ?.catch(() => { setErrorMessage(translate('travel.errorMessage')); diff --git a/src/components/ScreenWrapper/index.tsx b/src/components/ScreenWrapper/index.tsx index 7432501af290..8c92ce98ca45 100644 --- a/src/components/ScreenWrapper/index.tsx +++ b/src/components/ScreenWrapper/index.tsx @@ -1,4 +1,3 @@ -import HybridAppModule from '@expensify/react-native-hybrid-app'; import {UNSTABLE_usePreventRemove, useIsFocused, useNavigation} from '@react-navigation/native'; import type {ForwardedRef, ReactNode} from 'react'; import React, {createContext, forwardRef, useContext, useEffect, useMemo, useRef, useState} from 'react'; @@ -28,6 +27,7 @@ import useStyleUtils from '@hooks/useStyleUtils'; import useTackInputFocus from '@hooks/useTackInputFocus'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; +import {closeReactNativeApp} from '@libs/actions/Session'; import {isMobile, isMobileWebKit, isSafari} from '@libs/Browser'; import NarrowPaneContext from '@libs/Navigation/AppNavigator/Navigators/NarrowPaneContext'; import Navigation from '@libs/Navigation/Navigation'; @@ -231,7 +231,7 @@ function ScreenWrapper( if (!CONFIG.IS_HYBRID_APP) { return; } - HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); + closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); }); const panResponder = useRef( diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index c3768e33a2b4..d37d919ccb6b 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -6,6 +6,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Credentials, HybridApp, Session, TryNewDot} from '@src/types/onyx'; import {setNewDotSignInState, setReadyToShowAuthScreens, setUseNewDotSignInPage} from './actions/HybridApp'; +import {closeReactNativeApp} from './actions/Session'; import Log from './Log'; import {getCurrentUserEmail} from './Network/NetworkStore'; @@ -86,7 +87,7 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryN }); setUseNewDotSignInPage(false).then(() => { if (shouldUseOD) { - HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); + closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); } else { Log.info('[HybridApp] The user should see NewDot. There is no need to block the user on the `SignInPage` until the sign-in process is completed on the OldDot side.'); setReadyToShowAuthScreens(true); diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 3096061b7fe7..af2f8ec0d7ab 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -50,6 +50,7 @@ import {KEYS_TO_PRESERVE, openApp} from '@userActions/App'; import {KEYS_TO_PRESERVE_DELEGATE_ACCESS} from '@userActions/Delegate'; import * as Device from '@userActions/Device'; import * as HybridAppActions from '@userActions/HybridApp'; +import {setClosingReactNativeApp} from '@userActions/HybridApp'; import type HybridAppSettings from '@userActions/HybridApp/types'; import redirectToSignIn from '@userActions/SignInRedirect'; import Timing from '@userActions/Timing'; @@ -594,6 +595,13 @@ function setupNewDotAfterTransitionFromOldDot(hybridAppSettings: HybridAppSettin }); } +function closeReactNativeApp({shouldSignOut, shouldSetNVP}: {shouldSignOut: boolean; shouldSetNVP: boolean}) { + if (CONFIG.IS_HYBRID_APP) { + setClosingReactNativeApp(true); + } + HybridAppModule.closeReactNativeApp({shouldSignOut, shouldSetNVP}); +} + /** * Given an idToken from Sign in with Apple, checks the API to see if an account * exists for that email address and signs the user in if so. @@ -1432,4 +1440,5 @@ export { MergeIntoAccountAndLogin, resetSMSDeliveryFailureStatus, clearDisableTwoFactorAuthErrors, + closeReactNativeApp, }; diff --git a/src/pages/ErrorPage/SessionExpiredPage.tsx b/src/pages/ErrorPage/SessionExpiredPage.tsx index 85dd6724a3bd..b2a6200e2c70 100644 --- a/src/pages/ErrorPage/SessionExpiredPage.tsx +++ b/src/pages/ErrorPage/SessionExpiredPage.tsx @@ -1,4 +1,3 @@ -import HybridAppModule from '@expensify/react-native-hybrid-app'; import React from 'react'; import {View} from 'react-native'; import Icon from '@components/Icon'; @@ -9,6 +8,7 @@ import TextLink from '@components/TextLink'; import useLocalize from '@hooks/useLocalize'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; +import {closeReactNativeApp} from '@libs/actions/Session'; import Navigation from '@libs/Navigation/Navigation'; import {clearSignInData} from '@userActions/Session'; import CONFIG from '@src/CONFIG'; @@ -39,7 +39,7 @@ function SessionExpiredPage() { Navigation.goBack(); return; } - HybridAppModule.closeReactNativeApp({shouldSignOut: true, shouldSetNVP: false}); + closeReactNativeApp({shouldSignOut: true, shouldSetNVP: false}); }} > {translate('deeplinkWrapper.signIn')} diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index e1d05b5e1d57..399510855bd9 100644 --- a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx +++ b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx @@ -1,4 +1,3 @@ -import HybridAppModule from '@expensify/react-native-hybrid-app'; import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {InteractionManager, View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; @@ -26,6 +25,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import {openOldDotLink} from '@libs/actions/Link'; import {createWorkspace, generatePolicyID} from '@libs/actions/Policy/Policy'; import {completeOnboarding} from '@libs/actions/Report'; +import {closeReactNativeApp} from '@libs/actions/Session'; import {setOnboardingAdminsChatReportID, setOnboardingPolicyID} from '@libs/actions/Welcome'; import navigateAfterOnboarding from '@libs/navigateAfterOnboarding'; import Navigation from '@libs/Navigation/Navigation'; @@ -134,7 +134,7 @@ function BaseOnboardingAccounting({shouldUseNativeStyles}: BaseOnboardingAccount } if (CONFIG.IS_HYBRID_APP) { - HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); + closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); return; } waitForIdle().then(() => { diff --git a/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx index 6fe059d9b061..0409841ea097 100644 --- a/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx @@ -1,4 +1,3 @@ -import HybridAppModule from '@expensify/react-native-hybrid-app'; import {useIsFocused} from '@react-navigation/native'; import {Str} from 'expensify-common'; import type {ImageContentFit} from 'expo-image'; @@ -25,7 +24,7 @@ import {startMoneyRequest} from '@libs/actions/IOU'; import {openOldDotLink} from '@libs/actions/Link'; import {navigateToQuickAction} from '@libs/actions/QuickActionNavigation'; import {createNewReport, startNewChat} from '@libs/actions/Report'; -import {isAnonymousUser} from '@libs/actions/Session'; +import {closeReactNativeApp, isAnonymousUser} from '@libs/actions/Session'; import {completeTestDriveTask} from '@libs/actions/Task'; import getIconForAction from '@libs/getIconForAction'; import interceptAnonymousUser from '@libs/interceptAnonymousUser'; @@ -548,7 +547,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT onConfirm={() => { setModalVisible(false); if (CONFIG.IS_HYBRID_APP) { - HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); + closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); return; } openOldDotLink(CONST.OLDDOT_URLS.INBOX); diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 084167e60ef3..e26a273f682f 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -1,4 +1,3 @@ -import HybridAppModule from '@expensify/react-native-hybrid-app/src'; import {findFocusedRoute, useNavigationState, useRoute} from '@react-navigation/native'; import React, {useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState} from 'react'; // eslint-disable-next-line no-restricted-imports @@ -31,6 +30,7 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import '@libs/actions/Delegate'; import {resetExitSurveyForm} from '@libs/actions/ExitSurvey'; +import {closeReactNativeApp} from '@libs/actions/Session'; import {checkIfFeedConnectionIsBroken} from '@libs/CardUtils'; import {convertToDisplayString} from '@libs/CurrencyUtils'; import useIsSidebarRouteActive from '@libs/Navigation/helpers/useIsSidebarRouteActive'; @@ -237,7 +237,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr icon: Expensicons.ExpensifyLogoNew, ...(CONFIG.IS_HYBRID_APP ? { - action: () => HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}), + action: () => closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}), } : { action() { diff --git a/src/pages/settings/Security/MergeAccounts/MergeResultPage.tsx b/src/pages/settings/Security/MergeAccounts/MergeResultPage.tsx index 09a238939951..e5e2533e47de 100644 --- a/src/pages/settings/Security/MergeAccounts/MergeResultPage.tsx +++ b/src/pages/settings/Security/MergeAccounts/MergeResultPage.tsx @@ -1,4 +1,3 @@ -import HybridAppModule from '@expensify/react-native-hybrid-app'; import {useRoute} from '@react-navigation/native'; import React, {useEffect, useMemo} from 'react'; import {InteractionManager} from 'react-native'; @@ -14,6 +13,7 @@ import Text from '@components/Text'; import TextLink from '@components/TextLink'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; +import {closeReactNativeApp} from '@libs/actions/Session'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; @@ -151,7 +151,7 @@ function MergeResultPage() { secondaryButtonText: translate('mergeAccountsPage.mergePendingSAML.goToExpensifyClassic'), onSecondaryButtonPress: () => { if (CONFIG.IS_HYBRID_APP) { - HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); + closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); return; } openOldDotLink(CONST.OLDDOT_URLS.INBOX, false);