From e6a2b034096384bf7ccdc4906a28ca794962ee8d Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Mon, 25 Nov 2024 13:50:22 +0100 Subject: [PATCH 1/5] Simplify HybridApp.ts --- src/libs/HybridApp.ts | 24 ++++++++---------------- src/libs/actions/HybridApp/index.ts | 16 +++++++++++++++- src/types/onyx/HybridApp.ts | 18 +++++++++--------- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 45f464c25afd..d672e7f1fda8 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -5,14 +5,13 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Credentials, HybridApp, Session, TryNewDot} from '@src/types/onyx'; import { + resetSigningInLogic, setIsSigningIn, setNewDotSignInState, setOldDotSignInError, setOldDotSignInState, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, - setShouldResetSigningInLogic, - setUseNewDotSignInPage, } from './actions/HybridApp'; import type {Init} from './ActiveClientManager/types'; import Log from './Log'; @@ -53,29 +52,21 @@ function handleSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry< // 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); + Log.info('[HybridApp] Resetting sign-in state'); + resetSigningInLogic(); 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('Unable to open OldDot. Sign-in has failed'); setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FAILED_AGAIN); } else { - console.debug('Closing, but why', {currentHybridApp, hybridApp}); + Log.info('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 +74,10 @@ function handleSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry< shouldUseOldApp(tryNewDot) ) { if (hybridApp?.oldDotSignInError) { + Log.info('Unable to open OldDot. Sign-in has failed'); return; } - console.log('closing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); + Log.info('Closing NewDot as sign-in to OldDot succeeded'); NativeModules.HybridAppModule.closeReactNativeApp(false, false); } @@ -102,7 +94,7 @@ function handleSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry< setReadyToShowAuthScreens(true); } - console.log('[HybridApp] signInToOldDot'); + Log.info('[HybridApp] Performing sign-in on OldDot side'); setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); NativeModules.HybridAppModule.signInToOldDot(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword); } diff --git a/src/libs/actions/HybridApp/index.ts b/src/libs/actions/HybridApp/index.ts index 486b7a0e79d7..cde6ef816b57 100644 --- a/src/libs/actions/HybridApp/index.ts +++ b/src/libs/actions/HybridApp/index.ts @@ -1,6 +1,6 @@ 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 HybridAppSettings from './types'; @@ -44,6 +44,19 @@ function setOldDotSignInState(oldDotSignInState: ValueOf; - /** */ + /** Describes current stage of OldDot sign-in */ oldDotSignInState?: ValueOf; }; From cac942fbe6769a1ffb5ece77284fc4d27c6f63fc Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Mon, 25 Nov 2024 13:54:46 +0100 Subject: [PATCH 2/5] Use early returns --- src/libs/HybridApp.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index d672e7f1fda8..b56ddd9fc498 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -61,10 +61,11 @@ function handleSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry< if (hybridApp?.oldDotSignInError) { Log.info('Unable to open OldDot. Sign-in has failed'); setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FAILED_AGAIN); - } else { - Log.info('Closing NewDot as retrying sign-in to OldDot succeeded'); - NativeModules.HybridAppModule.closeReactNativeApp(false, true); + return; } + + Log.info('Closing NewDot as retrying sign-in to OldDot succeeded'); + NativeModules.HybridAppModule.closeReactNativeApp(false, true); } if ( From e1a615462ea10bb72d443e4bedf8d8fd797353be Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Mon, 25 Nov 2024 13:57:45 +0100 Subject: [PATCH 3/5] Rearrange HybridApp module --- src/libs/HybridApp.ts | 70 ++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index b56ddd9fc498..4e8745b2a928 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -16,18 +16,6 @@ import { 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; @@ -45,6 +33,29 @@ Onyx.connect({ }, }); +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; + }, +}); + +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; @@ -104,16 +115,18 @@ function handleSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry< 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) { + Log.info(`[HybridApp] onSignInFinished event received with data: ${data}`, true); + const eventData = JSON.parse(data) as {errorMessage: string}; + + setIsSigningIn(false); + setOldDotSignInError(eventData.errorMessage); + setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); + + if (eventData.errorMessage === null) { + setReadyToSwitchToClassicExperience(true); + } +} const init: Init = () => { if (!NativeModules.HybridAppModule) { @@ -121,18 +134,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}; From 277f0046954b554e086b3be9da2096b5f850d87b Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Tue, 26 Nov 2024 15:12:03 +0100 Subject: [PATCH 4/5] Remove redundant keys --- src/components/InitialURLContextProvider.tsx | 11 ++- src/libs/HybridApp.ts | 55 +++++---------- src/libs/actions/HybridApp/index.ts | 69 +++++++++++++------ src/libs/actions/Session/index.ts | 23 ++----- src/pages/settings/InitialSettingsPage.tsx | 16 ++--- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 29 ++++---- src/types/onyx/HybridApp.ts | 9 --- 7 files changed, 100 insertions(+), 112 deletions(-) diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index cf5094e0fcc8..cd0fc338392f 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 {signInAfterTransitionFromOldDot} from '@libs/actions/Session'; @@ -30,12 +30,15 @@ function InitialURLContextProvider({children, url, hybridAppSettings}: InitialUR const [initialURL, setInitialURL] = useState(url); const {setSplashScreenState} = useSplashScreenStateContext(); + const firstRenderRef = useRef(true); + useEffect(() => { - if (url && hybridAppSettings) { + if (url && hybridAppSettings && firstRenderRef.current) { signInAfterTransitionFromOldDot(url, hybridAppSettings).then((route) => { setInitialURL(route); setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); }); + firstRenderRef.current = false; return; } Linking.getInitialURL().then((initURL) => { @@ -43,6 +46,10 @@ function InitialURLContextProvider({children, url, hybridAppSettings}: InitialUR }); }, [hybridAppSettings, setSplashScreenState, url]); + useEffect(() => { + console.debug('VALUE OF firstRenderRef', {firstRenderRef: firstRenderRef.current}); + }); + const initialUrlContext = useMemo( () => ({ initialURL, diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 4e8745b2a928..4a5dea653714 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -4,15 +4,7 @@ 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 { - resetSigningInLogic, - setIsSigningIn, - setNewDotSignInState, - setOldDotSignInError, - setOldDotSignInState, - setReadyToShowAuthScreens, - setReadyToSwitchToClassicExperience, -} from './actions/HybridApp'; +import * as HybridAppActions from './actions/HybridApp'; import type {Init} from './ActiveClientManager/types'; import Log from './Log'; @@ -22,6 +14,7 @@ let currentTryNewDot: OnyxEntry; Onyx.connect({ key: ONYXKEYS.HYBRID_APP, callback: (hybridApp) => { + console.debug('Last hybridApp value', {hybridApp}); handleSignInFlow(hybridApp, currentTryNewDot); }, }); @@ -29,6 +22,7 @@ Onyx.connect({ Onyx.connect({ key: ONYXKEYS.NVP_TRYNEWDOT, callback: (tryNewDot) => { + console.debug('Last tryNewDot value', {tryNewDot}); handleSignInFlow(currentHybridApp, tryNewDot); }, }); @@ -38,7 +32,7 @@ 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); + HybridAppActions.setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); } currentSession = session; }, @@ -61,21 +55,14 @@ function handleSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry< return; } - // reset sign in logic - if (hybridApp?.shouldResetSigningInLogic) { - Log.info('[HybridApp] Resetting sign-in state'); - resetSigningInLogic(); - 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('Unable to open OldDot. Sign-in has failed'); - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FAILED_AGAIN); + 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('Closing NewDot as retrying sign-in to OldDot succeeded'); + Log.info('[HybridApp] Closing NewDot as retrying sign-in to OldDot succeeded'); NativeModules.HybridAppModule.closeReactNativeApp(false, true); } @@ -86,10 +73,11 @@ function handleSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry< shouldUseOldApp(tryNewDot) ) { if (hybridApp?.oldDotSignInError) { - Log.info('Unable to open OldDot. Sign-in has failed'); + Log.info('[HybridApp] Unable to open OldDot. Sign-in has failed'); return; } - Log.info('Closing NewDot as sign-in to OldDot succeeded'); + + Log.info('[HybridApp] Closing NewDot as sign-in to OldDot succeeded'); NativeModules.HybridAppModule.closeReactNativeApp(false, false); } @@ -100,15 +88,13 @@ 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); } - Log.info('[HybridApp] Performing sign-in on OldDot side'); - 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; @@ -116,16 +102,9 @@ function handleSignInFlow(hybridApp: OnyxEntry, tryNewDot: OnyxEntry< } function onOldDotSignInFinished(data: string) { - Log.info(`[HybridApp] onSignInFinished event received with data: ${data}`, true); const eventData = JSON.parse(data) as {errorMessage: string}; - - setIsSigningIn(false); - setOldDotSignInError(eventData.errorMessage); - setOldDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); - - if (eventData.errorMessage === null) { - setReadyToSwitchToClassicExperience(true); - } + Log.info(`[HybridApp] onSignInFinished event received`, true, {eventData}); + HybridAppActions.finishOldDotSignIn(eventData.errorMessage); } const init: Init = () => { diff --git a/src/libs/actions/HybridApp/index.ts b/src/libs/actions/HybridApp/index.ts index cde6ef816b57..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 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,29 +34,68 @@ function setOldDotSignInState(oldDotSignInState: ValueOf { if (!hybridApp.useNewDotSignInPage) { - setReadyToShowAuthScreens(true); - setReadyToSwitchToClassicExperience(true); return Promise.resolve(); } @@ -506,8 +496,6 @@ 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(); } @@ -516,7 +504,7 @@ function signInAfterTransitionFromOldDot(route: Route, hybridAppSettings: string return new Promise((resolve) => { clearOnyxBeforeSignIn() - .then(() => Onyx.merge(ONYXKEYS.HYBRID_APP, hybridApp)) + .then(() => HybridAppActions.prepareHybridAppAfterTransitionToNewDot(hybridApp)) .then(() => Onyx.multiSet(newDotOnyxValues)) .then(() => { if (!hybridApp.shouldRemoveDelegatedAccess) { @@ -525,9 +513,8 @@ 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) => { 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 934e3e2ee9f0..688ac01d05ed 100644 --- a/src/types/onyx/HybridApp.ts +++ b/src/types/onyx/HybridApp.ts @@ -6,21 +6,12 @@ type HybridApp = { /** Stores the information if HybridApp uses NewDot's sign-in flow */ useNewDotSignInPage?: boolean; - /** Stores information on whether HybridApp is signing in to OldDot */ - 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; - /** Tells if we can switch to OldDot */ - readyToSwitchToClassicExperience?: boolean; - - /** Tells if we should reset signing in logic to initial state */ - shouldResetSigningInLogic?: boolean; - /** States whether we transitioned from OldDot to show only certain group of screens */ isSingleNewDotEntry?: boolean; From 3cf4fa9290212d9d23dfeb8da9663d0ac2a443e7 Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Wed, 27 Nov 2024 13:02:38 +0100 Subject: [PATCH 5/5] Remove unused import --- src/components/InitialURLContextProvider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index 6b1570aa1067..b89a842d1420 100644 --- a/src/components/InitialURLContextProvider.tsx +++ b/src/components/InitialURLContextProvider.tsx @@ -1,4 +1,4 @@ -import React, {createContext, useEffect, useMemo, useRef, useState} from 'react'; +import React, {createContext, useEffect, useMemo, useState} from 'react'; import type {ReactNode} from 'react'; import {Linking} from 'react-native'; import {useOnyx} from 'react-native-onyx';