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}; 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 8c836ec97c42..45f251826566 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 @@ -17,7 +17,7 @@ class ReactNativeHybridApp(reactContext: ReactApplicationContext) : Log.d(NAME, "`shouldUseStaging` should never be called in standalone `New Expensify` app") } - override fun closeReactNativeApp(shouldSignOut: Boolean, shouldSetNVP: Boolean) { + override fun closeReactNativeApp(shouldSetNVP: Boolean) { Log.d(NAME, "`closeReactNativeApp` should never be called in standalone `New Expensify` app") } @@ -51,4 +51,22 @@ class ReactNativeHybridApp(reactContext: ReactApplicationContext) : override fun onURLListenerAdded() { Log.d(NAME, "`onURLListenerAdded` 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") + } + + 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 3935f40eb9a7..91bbeaac7599 100644 --- a/modules/hybrid-app/ios/ReactNativeHybridApp.mm +++ b/modules/hybrid-app/ios/ReactNativeHybridApp.mm @@ -11,7 +11,7 @@ - (void)shouldUseStaging:(BOOL)isStaging { NSLog(@"[ReactNativeHybridApp] `shouldUseStaging` should never be called in standalone `New Expensify` app"); } -- (void)closeReactNativeApp:(BOOL)shouldSignOut shouldSetNVP:(BOOL)shouldSetNVP { +- (void)closeReactNativeApp:(BOOL)shouldSetNVP { NSLog(@"[ReactNativeHybridApp] `closeReactNativeApp` should never be called in standalone `New Expensify` app"); } @@ -43,6 +43,18 @@ - (void)onURLListenerAdded { NSLog(@"[ReactNativeHybridApp] `onURLListenerAdded` 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"); +} + +- (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 87bd482faf28..74e337fec494 100644 --- a/modules/hybrid-app/src/NativeReactNativeHybridApp.ts +++ b/modules/hybrid-app/src/NativeReactNativeHybridApp.ts @@ -5,13 +5,16 @@ import {TurboModuleRegistry} from 'react-native'; export interface Spec extends TurboModule { isHybridApp: () => boolean; shouldUseStaging: (isStaging: boolean) => void; - closeReactNativeApp: (shouldSignOut: boolean, shouldSetNVP: boolean) => void; + closeReactNativeApp: (shouldSetNVP: boolean) => void; completeOnboarding: (status: boolean) => void; switchAccount: (newDotCurrentAccountEmail: string, authToken: string, policyID: string, accountID: string) => void; sendAuthToken: (authToken: string) => void; getHybridAppSettings: () => Promise; getInitialURL(): Promise; onURLListenerAdded: () => 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 2fa0c8463c54..d7154f179195 100644 --- a/modules/hybrid-app/src/index.native.ts +++ b/modules/hybrid-app/src/index.native.ts @@ -8,8 +8,8 @@ const HybridAppModule: HybridAppModuleType = { shouldUseStaging(isStaging) { ReactNativeHybridApp.shouldUseStaging(isStaging); }, - closeReactNativeApp({shouldSignOut, shouldSetNVP}) { - ReactNativeHybridApp.closeReactNativeApp(shouldSignOut, shouldSetNVP); + closeReactNativeApp({shouldSetNVP}) { + ReactNativeHybridApp.closeReactNativeApp(shouldSetNVP); }, completeOnboarding({status}) { ReactNativeHybridApp.completeOnboarding(status); @@ -29,6 +29,15 @@ const HybridAppModule: HybridAppModuleType = { onURLListenerAdded() { ReactNativeHybridApp.onURLListenerAdded(); }, + signInToOldDot({autoGeneratedLogin, autoGeneratedPassword, authToken, email, policyID}) { + ReactNativeHybridApp.signInToOldDot(autoGeneratedLogin, autoGeneratedPassword, authToken, email, policyID); + }, + 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 813fe7af880f..6e0534d37d4b 100644 --- a/modules/hybrid-app/src/index.ts +++ b/modules/hybrid-app/src/index.ts @@ -38,6 +38,18 @@ const HybridAppModule: HybridAppModuleType = { // eslint-disable-next-line no-console console.warn('HybridAppModule: `onURLListenerAdded` 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'); + }, + 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 ed227123a9b9..bffa00ce8055 100644 --- a/modules/hybrid-app/src/types.ts +++ b/modules/hybrid-app/src/types.ts @@ -1,13 +1,16 @@ type HybridAppModuleType = { isHybridApp: () => boolean; shouldUseStaging: (isStaging: boolean) => void; - closeReactNativeApp: (args: {shouldSignOut: boolean; shouldSetNVP: boolean}) => void; + closeReactNativeApp: (args: {shouldSetNVP: boolean}) => void; completeOnboarding: (args: {status: boolean}) => void; switchAccount: (args: {newDotCurrentAccountEmail: string; authToken: string; policyID: string; accountID: string}) => void; sendAuthToken: (args: {authToken: string}) => void; getHybridAppSettings: () => Promise; getInitialURL(): Promise; onURLListenerAdded: () => 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 22be657f3e84..283db2d1f58c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -42,6 +42,7 @@ import {CurrentReportIDContextProvider} from './hooks/useCurrentReportID'; import useDefaultDragAndDrop from './hooks/useDefaultDragAndDrop'; import HybridAppHandler from './HybridAppHandler'; import OnyxUpdateManager from './libs/actions/OnyxUpdateManager'; +import './libs/HybridApp'; import {AttachmentModalContextProvider} from './pages/media/AttachmentModalScreen/AttachmentModalContext'; import './setup/backgroundTask'; import './setup/hybridApp'; @@ -67,54 +68,65 @@ function App() { - - - + {/* Initialize metrics early to ensure the UI renders even when NewDot is hidden. + This is necessary for iOS HybridApp's SignInPage to appear correctly without the bootsplash. + See: https://github.com/Expensify/App/pull/65178#issuecomment-3139026551 + */} + + - - - - - - - - - - + + + + + + + + + + + + diff --git a/src/CONFIG.ts b/src/CONFIG.ts index aa6e3a325d49..f73e4c27897d 100644 --- a/src/CONFIG.ts +++ b/src/CONFIG.ts @@ -10,6 +10,26 @@ import * as Url from './libs/Url'; // add a trim() call to prevent headaches const get = (config: NativeConfig, key: string, defaultValue: string): string => (config?.[key] ?? defaultValue).trim(); +const getDefaultLegacyPartnerConfig = () => { + // eslint-disable-next-line no-restricted-properties + if (!HybridAppModule.isHybridApp()) { + return {name: '', password: ''}; + } + + if (Platform.OS === 'ios') { + return { + name: 'iphone', + password: 'e88ed31140a66c73b36a', + }; + } + + // Android partner config + return { + name: 'android', + password: 'c3a9ac418ea3f152aae2', + }; +}; + // Set default values to contributor friendly values to make development work out of the box without an .env file const ENVIRONMENT = get(Config, 'ENVIRONMENT', CONST.ENVIRONMENT.DEV); const newExpensifyURL = Url.addTrailingForwardSlash(get(Config, 'NEW_EXPENSIFY_URL', 'https://new.expensify.com/')); @@ -61,6 +81,8 @@ export default { DEFAULT_SECURE_API_ROOT: secureURLRoot, STAGING_API_ROOT: stagingExpensifyURL, STAGING_SECURE_API_ROOT: stagingSecureExpensifyUrl, + LEGACY_PARTNER_NAME: get(Config, 'LEGACY_EXPENSIFY_PARTNER_NAME', getDefaultLegacyPartnerConfig().name), + LEGACY_PARTNER_PASSWORD: get(Config, 'LEGACY_EXPENSIFY_PARTNER_PASSWORD', getDefaultLegacyPartnerConfig().password), PARTNER_NAME: get(Config, 'EXPENSIFY_PARTNER_NAME', 'chat-expensify-com'), PARTNER_PASSWORD: get(Config, 'EXPENSIFY_PARTNER_PASSWORD', 'e21965746fd75f82bb66'), EXPENSIFY_CASH_REFERER: 'ecash', @@ -95,7 +117,18 @@ 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', + HYBRID_APP: { + // cspell:disable-next-line + IOS_CLIENT_ID: '1008697809946-sh04nqq0hea396s1qdqqbj6ia649odb2.apps.googleusercontent.com', + WEB_CLIENT_ID: { + // cspell:disable-next-line + IOS: '1008697809946-5e095eqem3o6ugtpc2rjf7v880tcp28p.apps.googleusercontent.com', + // cspell:disable-next-line + ANDROID: '240677659774-86pov3adub93cv4b8uj13g7varolmk2l.apps.googleusercontent.com', + }, + }, }, GCP_GEOLOCATION_API_KEY: googleGeolocationAPIKey, FIREBASE_WEB_CONFIG: { diff --git a/src/Expensify.tsx b/src/Expensify.tsx index de21defd5a2b..feb0bb2880bd 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -122,10 +122,21 @@ function Expensify() { const isAuthenticated = useIsAuthenticated(); const autoAuthState = useMemo(() => session?.autoAuthState ?? '', [session]); - const shouldInit = isNavigationReady && hasAttemptedToOpenPublicRoom && !!preferredLocale; + const isSplashReadyToBeHidden = splashScreenState === CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN; const isSplashVisible = splashScreenState === CONST.BOOT_SPLASH_STATE.VISIBLE; - const isHybridAppReady = splashScreenState === CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN && isAuthenticated; - const shouldHideSplash = shouldInit && (CONFIG.IS_HYBRID_APP ? isHybridAppReady : isSplashVisible); + + const shouldInit = isNavigationReady && hasAttemptedToOpenPublicRoom && !!preferredLocale; + const shouldHideSplash = shouldInit && (CONFIG.IS_HYBRID_APP ? isSplashReadyToBeHidden : isSplashVisible); + + useEffect(() => { + if (!shouldInit || splashScreenState !== CONST.BOOT_SPLASH_STATE.HIDDEN) { + return; + } + + // Clears OldDot UI after sign-out, if there's no OldDot UI left it has no effect. + HybridAppModule.clearOldDotAfterSignOut(); + }, [shouldInit, splashScreenState]); + const initializeClient = () => { if (!Visibility.isVisible()) { return; diff --git a/src/HybridAppHandler.tsx b/src/HybridAppHandler.tsx index 2b425b34072d..7de67eaf64d7 100644 --- a/src/HybridAppHandler.tsx +++ b/src/HybridAppHandler.tsx @@ -1,31 +1,49 @@ -import HybridAppModule from '@expensify/react-native-hybrid-app'; -import {useContext, useEffect} from 'react'; +import {useCallback, useContext, useEffect} from 'react'; import CONFIG from './CONFIG'; import CONST from './CONST'; -import {signInAfterTransitionFromOldDot} from './libs/actions/Session'; +import useOnyx from './hooks/useOnyx'; +import {getHybridAppSettings} from './libs/actions/HybridApp'; +import type HybridAppSettings from './libs/actions/HybridApp/types'; +import {setupNewDotAfterTransitionFromOldDot} from './libs/actions/Session'; import Log from './libs/Log'; +import ONYXKEYS from './ONYXKEYS'; import SplashScreenStateContext from './SplashScreenStateContext'; +import isLoadingOnyxValue from './types/utils/isLoadingOnyxValue'; function HybridAppHandler() { - const {setSplashScreenState} = useContext(SplashScreenStateContext); + const {splashScreenState, setSplashScreenState} = useContext(SplashScreenStateContext); + const [tryNewDot, tryNewDotMetadata] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT, {canBeMissing: true}); + const isLoadingTryNewDot = isLoadingOnyxValue(tryNewDotMetadata); + + const finalizeTransitionFromOldDot = useCallback( + (hybridAppSettings: HybridAppSettings) => { + const loggedOutFromOldDot = !!hybridAppSettings.hybridApp.loggedOutFromOldDot; + + setupNewDotAfterTransitionFromOldDot(hybridAppSettings, tryNewDot).then(() => { + if (splashScreenState !== CONST.BOOT_SPLASH_STATE.VISIBLE) { + return; + } + + setSplashScreenState(loggedOutFromOldDot ? CONST.BOOT_SPLASH_STATE.HIDDEN : CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); + }); + }, + [setSplashScreenState, splashScreenState, tryNewDot], + ); useEffect(() => { - if (!CONFIG.IS_HYBRID_APP) { + if (!CONFIG.IS_HYBRID_APP || isLoadingTryNewDot) { return; } - HybridAppModule.getHybridAppSettings().then((hybridAppSettings: string | null) => { + getHybridAppSettings().then((hybridAppSettings: HybridAppSettings | null) => { if (!hybridAppSettings) { // Native method can send non-null value only once per NewDot lifecycle. It prevents issues with multiple initializations during reloads on debug builds. Log.info('[HybridApp] `getHybridAppSettings` called more than once during single NewDot lifecycle. Skipping initialization.'); return; } - - signInAfterTransitionFromOldDot(hybridAppSettings).then(() => { - setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); - }); + finalizeTransitionFromOldDot(hybridAppSettings); }); - }, [setSplashScreenState]); + }, [finalizeTransitionFromOldDot, isLoadingTryNewDot]); return null; } diff --git a/src/components/ScreenWrapper/index.tsx b/src/components/ScreenWrapper/index.tsx index 56779aea01fd..1e7f6a67b929 100644 --- a/src/components/ScreenWrapper/index.tsx +++ b/src/components/ScreenWrapper/index.tsx @@ -20,7 +20,7 @@ import NarrowPaneContext from '@libs/Navigation/AppNavigator/Navigators/NarrowPa import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackNavigationProp} from '@libs/Navigation/PlatformStackNavigation/types'; import type {ReportsSplitNavigatorParamList, RootNavigatorParamList} from '@libs/Navigation/types'; -import closeReactNativeApp from '@userActions/HybridApp'; +import {closeReactNativeApp} from '@userActions/HybridApp'; import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -173,7 +173,7 @@ function ScreenWrapper({ if (!CONFIG.IS_HYBRID_APP) { return; } - closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); + closeReactNativeApp({shouldSetNVP: false}); }); useEffect(() => { diff --git a/src/components/SignInButtons/GoogleSignIn/index.native.tsx b/src/components/SignInButtons/GoogleSignIn/index.native.tsx index 4a70a10ef017..70144444d282 100644 --- a/src/components/SignInButtons/GoogleSignIn/index.native.tsx +++ b/src/components/SignInButtons/GoogleSignIn/index.native.tsx @@ -1,20 +1,32 @@ import {GoogleSignin, statusCodes} from '@react-native-google-signin/google-signin'; import React from 'react'; import IconButton from '@components/SignInButtons/IconButton'; +import getPlatform from '@libs/getPlatform'; 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 '.'; import type GoogleError from './types'; +/** + * Helper function returning webClientId based on a platform used + */ +function getWebClientId() { + if (!CONFIG.IS_HYBRID_APP) { + return CONFIG.GOOGLE_SIGN_IN.WEB_CLIENT_ID; + } + + return getPlatform() === CONST.PLATFORM.ANDROID ? CONFIG.GOOGLE_SIGN_IN.HYBRID_APP.WEB_CLIENT_ID.ANDROID : CONFIG.GOOGLE_SIGN_IN.HYBRID_APP.WEB_CLIENT_ID.IOS; +} + /** * Google Sign In method for iOS and android that returns identityToken. */ function googleSignInRequest() { GoogleSignin.configure({ - webClientId: CONFIG.GOOGLE_SIGN_IN.WEB_CLIENT_ID, - iosClientId: CONFIG.GOOGLE_SIGN_IN.IOS_CLIENT_ID, + webClientId: getWebClientId(), + iosClientId: CONFIG.IS_HYBRID_APP ? CONFIG.GOOGLE_SIGN_IN.HYBRID_APP.IOS_CLIENT_ID : CONFIG.GOOGLE_SIGN_IN.IOS_CLIENT_ID, offlineAccess: false, }); @@ -25,7 +37,7 @@ function googleSignInRequest() { GoogleSignin.signIn() .then((response) => response.idToken) - .then((token) => Session.beginGoogleSignIn(token)) + .then((token) => beginGoogleSignIn(token)) .catch((error: GoogleError | undefined) => { // Handle unexpected error shape if (error?.code === undefined) { diff --git a/src/libs/Authentication.ts b/src/libs/Authentication.ts index 383b91632641..cf83bb8ac43c 100644 --- a/src/libs/Authentication.ts +++ b/src/libs/Authentication.ts @@ -9,7 +9,14 @@ import redirectToSignIn from './actions/SignInRedirect'; import {getAuthenticateErrorMessage} from './ErrorUtils'; import Log from './Log'; import {post} from './Network'; -import {getCredentials, hasReadRequiredDataFromStorage, setAuthToken, setIsAuthenticating} from './Network/NetworkStore'; +import { + getCredentials, + getShouldUseNewPartnerName, + hasReadRequiredDataFromStorage, + hasReadShouldUseNewPartnerNameFromStorage, + setAuthToken, + setIsAuthenticating, +} from './Network/NetworkStore'; import requireParameters from './requireParameters'; type Parameters = { @@ -97,72 +104,80 @@ function reauthenticate(command = ''): Promise { command, }); - return hasReadRequiredDataFromStorage().then(() => { - const credentials = getCredentials(); + return hasReadRequiredDataFromStorage() + .then(hasReadShouldUseNewPartnerNameFromStorage) + .then(() => { + const credentials = getCredentials(); + const shouldUseNewPartnerName = getShouldUseNewPartnerName(); - Log.hmmm('Reauthenticate - Starting authentication process', { - command, - }); + const partnerName = shouldUseNewPartnerName ? CONFIG.EXPENSIFY.PARTNER_NAME : CONFIG.EXPENSIFY.LEGACY_PARTNER_NAME; + const partnerPassword = shouldUseNewPartnerName ? CONFIG.EXPENSIFY.PARTNER_PASSWORD : CONFIG.EXPENSIFY.LEGACY_PARTNER_PASSWORD; - return Authenticate({ - useExpensifyLogin: false, - partnerName: CONFIG.EXPENSIFY.PARTNER_NAME, - partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD, - partnerUserID: credentials?.autoGeneratedLogin, - partnerUserSecret: credentials?.autoGeneratedPassword, - }).then((response) => { - if (!response) { - return false; - } - - Log.hmmm('Reauthenticate - Processing authentication result', { + Log.info(`Reauthenticate - re-authenticating with ${shouldUseNewPartnerName ? 'new' : 'old'} partner name`); + + Log.hmmm('Reauthenticate - Starting authentication process', { command, }); - if (response.jsonCode === CONST.JSON_CODE.UNABLE_TO_RETRY) { - // When a fetch() fails due to a network issue and an error is thrown we won't log the user out. Most likely they - // have a spotty connection and will need to retry reauthenticate when they come back online. Error so it can be handled by the retry mechanism. - throw new Error('Unable to retry Authenticate request'); - } - - // If authentication fails and we are online then log the user out - if (response.jsonCode !== 200) { - const errorMessage = getAuthenticateErrorMessage(response); - setIsAuthenticating(false); - Log.hmmm('Redirecting to Sign In because we failed to reauthenticate', { + return Authenticate({ + useExpensifyLogin: false, + partnerName, + partnerPassword, + partnerUserID: credentials?.autoGeneratedLogin, + partnerUserSecret: credentials?.autoGeneratedPassword, + }).then((response) => { + if (!response) { + return false; + } + + Log.hmmm('Reauthenticate - Processing authentication result', { command, - error: errorMessage, }); - redirectToSignIn(errorMessage); - return false; - } - - // If we reauthenticate due to an expired delegate token, restore the delegate's original account. - // This is because the credentials used to reauthenticate were for the delegate's original account, and not for the account they were connected as. - if (isConnectedAsDelegate()) { - Log.info('Reauthenticate while connected as a delegate. Restoring original account.'); - restoreDelegateSession(response); - return true; - } - - // Update authToken in Onyx and in our local variables so that API requests will use the new authToken - updateSessionAuthTokens(response.authToken, response.encryptedAuthToken); - // Note: It is important to manually set the authToken that is in the store here since any requests that are hooked into - // reauthenticate .then() will immediate post and use the local authToken. Onyx updates subscribers lately so it is not - // enough to do the updateSessionAuthTokens() call above. - setAuthToken(response.authToken ?? null); + if (response.jsonCode === CONST.JSON_CODE.UNABLE_TO_RETRY) { + // When a fetch() fails due to a network issue and an error is thrown we won't log the user out. Most likely they + // have a spotty connection and will need to retry reauthenticate when they come back online. Error so it can be handled by the retry mechanism. + throw new Error('Unable to retry Authenticate request'); + } + + // If authentication fails and we are online then log the user out + if (response.jsonCode !== 200) { + const errorMessage = getAuthenticateErrorMessage(response); + setIsAuthenticating(false); + Log.hmmm('Redirecting to Sign In because we failed to reauthenticate', { + command, + error: errorMessage, + }); + redirectToSignIn(errorMessage); + return false; + } + + // If we reauthenticate due to an expired delegate token, restore the delegate's original account. + // This is because the credentials used to reauthenticate were for the delegate's original account, and not for the account they were connected as. + if (isConnectedAsDelegate()) { + Log.info('Reauthenticate while connected as a delegate. Restoring original account.'); + restoreDelegateSession(response); + return true; + } + + // Update authToken in Onyx and in our local variables so that API requests will use the new authToken + updateSessionAuthTokens(response.authToken, response.encryptedAuthToken); + + // Note: It is important to manually set the authToken that is in the store here since any requests that are hooked into + // reauthenticate .then() will immediate post and use the local authToken. Onyx updates subscribers lately so it is not + // enough to do the updateSessionAuthTokens() call above. + setAuthToken(response.authToken ?? null); + + // The authentication process is finished so the network can be unpaused to continue processing requests + setIsAuthenticating(false); - // The authentication process is finished so the network can be unpaused to continue processing requests - setIsAuthenticating(false); + Log.hmmm('Reauthenticate - Re-authentication successful', { + command, + }); - Log.hmmm('Reauthenticate - Re-authentication successful', { - command, + return true; }); - - return true; }); - }); } export {reauthenticate, Authenticate}; diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts new file mode 100644 index 000000000000..b65eb541b7e4 --- /dev/null +++ b/src/libs/HybridApp.ts @@ -0,0 +1,110 @@ +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 {isEmptyObject} from '@src/types/utils/EmptyObject'; +import {closeReactNativeApp, setReadyToShowAuthScreens, setUseNewDotSignInPage} from './actions/HybridApp'; +import Log from './Log'; +import {getCurrentUserEmail} from './Network/NetworkStore'; + +function isAnonymousUser(sessionParam: OnyxEntry): boolean { + return sessionParam?.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS; +} + +let currentHybridApp: OnyxEntry; +let currentTryNewDot: OnyxEntry; +let currentCredentials: OnyxEntry; +let currentSession: OnyxEntry; + +Onyx.connectWithoutView({ + key: ONYXKEYS.HYBRID_APP, + callback: (hybridApp) => { + currentHybridApp = hybridApp; + signInToOldDotAndChooseExperience(hybridApp, currentTryNewDot, currentCredentials, currentSession); + }, +}); + +Onyx.connectWithoutView({ + key: ONYXKEYS.NVP_TRY_NEW_DOT, + callback: (tryNewDot) => { + currentTryNewDot = tryNewDot; + signInToOldDotAndChooseExperience(currentHybridApp, tryNewDot, currentCredentials, currentSession); + }, +}); + +Onyx.connectWithoutView({ + key: ONYXKEYS.CREDENTIALS, + callback: (credentials) => { + currentCredentials = credentials; + signInToOldDotAndChooseExperience(currentHybridApp, currentTryNewDot, credentials, currentSession); + }, +}); + +Onyx.connectWithoutView({ + key: ONYXKEYS.SESSION, + callback: (session: OnyxEntry) => { + currentSession = session; + signInToOldDotAndChooseExperience(currentHybridApp, currentTryNewDot, currentCredentials, session); + }, +}); + +let activePolicyID: OnyxEntry; +Onyx.connectWithoutView({ + key: ONYXKEYS.NVP_ACTIVE_POLICY_ID, + callback: (newActivePolicyID) => { + activePolicyID = newActivePolicyID; + }, +}); + +function shouldUseOldApp(tryNewDot: TryNewDot) { + if (isEmptyObject(tryNewDot) || isEmptyObject(tryNewDot.classicRedirect)) { + return true; + } + return tryNewDot.classicRedirect.dismissed; +} + +/** + * Signs the user into OldDot when session and credentials are available, + * then decides whether to stay in NewDot or switch to OldDot based on `nvp_tryNewDot`. + */ +function signInToOldDotAndChooseExperience(hybridApp: OnyxEntry, tryNewDot: OnyxEntry, credentials: OnyxEntry, session: OnyxEntry) { + if (!CONFIG.IS_HYBRID_APP) { + return; + } + + if (!session?.authToken || !hybridApp?.useNewDotSignInPage) { + return; + } + + if (isAnonymousUser(session)) { + setReadyToShowAuthScreens(true); + return; + } + + if (!credentials?.autoGeneratedLogin || !credentials?.autoGeneratedPassword) { + return; + } + + Log.info(`[HybridApp] Performing sign-in on OldDot side`); + HybridAppModule.signInToOldDot({ + autoGeneratedLogin: credentials.autoGeneratedLogin, + autoGeneratedPassword: credentials.autoGeneratedPassword, + authToken: session.authToken, + email: getCurrentUserEmail() ?? '', + // eslint-disable-next-line rulesdir/no-default-id-values + policyID: activePolicyID ?? '', + }); + + if (tryNewDot !== undefined) { + setUseNewDotSignInPage(false).then(() => { + if (shouldUseOldApp(tryNewDot)) { + closeReactNativeApp({shouldSetNVP: false}); + } else { + setReadyToShowAuthScreens(true); + } + }); + } +} diff --git a/src/libs/Middleware/HandleDeletedAccount.ts b/src/libs/Middleware/HandleDeletedAccount.ts index 0a7be16a1b90..ec5532baa230 100644 --- a/src/libs/Middleware/HandleDeletedAccount.ts +++ b/src/libs/Middleware/HandleDeletedAccount.ts @@ -12,7 +12,7 @@ const handleDeletedAccount: Middleware = (requestResponse) => if (response?.jsonCode !== 408 || !response?.message?.includes('The account you are trying to use is deleted.')) { return response; } - signOutAndRedirectToSignIn(true, false, false, true); + signOutAndRedirectToSignIn(true, false, true, true); }); export default handleDeletedAccount; diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index c569a24939bc..ed14c906152a 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -296,32 +296,29 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie init(); } - // In Hybrid App we decide to call one of those method when booting ND and we don't want to duplicate calls - if (!CONFIG.IS_HYBRID_APP) { - // 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() and connect() for delegator from OldDot. - if (SessionUtils.didUserLogInDuringSession() || delegatorEmail) { - if (delegatorEmail) { - connect(delegatorEmail, true) - ?.then((success) => { - App.setAppLoading(!!success); - }) - .finally(() => { - setIsDelegatorFromOldDotIsReady(true); - }); - } else { - const reportID = getReportIDFromLink(initialURL ?? null); - if (reportID && !isAuthenticatedAtStartup) { - Report.openReport(reportID); - // Don't want to call `openReport` again when logging out and then logging in - setIsAuthenticatedAtStartup(true); - } - App.openApp(); - } + // 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() and connect() for delegator from OldDot. + if (SessionUtils.didUserLogInDuringSession() || delegatorEmail) { + if (delegatorEmail) { + connect(delegatorEmail, true) + ?.then((success) => { + App.setAppLoading(!!success); + }) + .finally(() => { + setIsDelegatorFromOldDotIsReady(true); + }); } else { - Log.info('[AuthScreens] Sending ReconnectApp'); - App.reconnectApp(initialLastUpdateIDAppliedToClient); + const reportID = getReportIDFromLink(initialURL ?? null); + if (reportID && !isAuthenticatedAtStartup) { + Report.openReport(reportID); + // Don't want to call `openReport` again when logging out and then logging in + setIsAuthenticatedAtStartup(true); + } + App.openApp(); } + } else { + Log.info('[AuthScreens] Sending ReconnectApp'); + App.reconnectApp(initialLastUpdateIDAppliedToClient); } App.setUpPoliciesAndNavigate(session); diff --git a/src/libs/Navigation/AppNavigator/PublicScreens.tsx b/src/libs/Navigation/AppNavigator/PublicScreens.tsx index 993117174ba6..e5ea03e14387 100644 --- a/src/libs/Navigation/AppNavigator/PublicScreens.tsx +++ b/src/libs/Navigation/AppNavigator/PublicScreens.tsx @@ -5,7 +5,6 @@ import createPlatformStackNavigator from '@libs/Navigation/PlatformStackNavigati import {InternalPlatformAnimations} from '@libs/Navigation/PlatformStackNavigation/navigationOptions/animation'; 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'; @@ -13,7 +12,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'; @@ -33,7 +31,7 @@ function PublicScreens() { { + if (!CONFIG.IS_HYBRID_APP) { + return authenticated; + } + + return authenticated && hybridApp?.readyToShowAuthScreens; + }, [hybridApp?.readyToShowAuthScreens, 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/Network/NetworkStore.ts b/src/libs/Network/NetworkStore.ts index ef6e879f0dac..4086f6cc226b 100644 --- a/src/libs/Network/NetworkStore.ts +++ b/src/libs/Network/NetworkStore.ts @@ -1,6 +1,8 @@ import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; +import Log from '@libs/Log'; +import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type Credentials from '@src/types/onyx/Credentials'; @@ -11,6 +13,7 @@ let authTokenType: ValueOf | null; let currentUserEmail: string | null = null; let offline = false; let authenticating = false; +let shouldUseNewPartnerName: boolean | undefined; // Allow code that is outside of the network listen for when a reconnection happens so that it can execute any side-effects (like flushing the sequential network queue) let reconnectCallback: () => void; @@ -30,6 +33,15 @@ let isReadyPromise = new Promise((resolve) => { resolveIsReadyPromise = resolve; }); +let resolveShouldUseNewPartnerNamePromise: (args?: unknown[]) => void; +const shouldUseNewPartnerNamePromise = new Promise((resolve) => { + resolveShouldUseNewPartnerNamePromise = resolve; + // On non-hybrid app variants we can resolve immediately. + if (!CONFIG.IS_HYBRID_APP) { + resolveShouldUseNewPartnerNamePromise(); + } +}); + /** * This is a hack to workaround the fact that Onyx may not yet have read these values from storage by the time Network starts processing requests. * If the values are undefined we haven't read them yet. If they are null or have a value then we have and the network is "ready". @@ -69,6 +81,18 @@ Onyx.connectWithoutView({ }, }); +if (CONFIG.IS_HYBRID_APP) { + Onyx.connectWithoutView({ + key: ONYXKEYS.HYBRID_APP, + callback: (val) => { + // If this value is not set, we can assume that we are using old partner name. + shouldUseNewPartnerName = val?.shouldUseNewPartnerName ?? false; + Log.info(`[HybridApp] User requests should use ${val?.shouldUseNewPartnerName ? 'new' : 'old'} partner name`); + resolveShouldUseNewPartnerNamePromise(); + }, + }); +} + // We subscribe to the online/offline status of the network to determine when we should fire off API calls // vs queueing them for later. // Use connectWithoutView since this doesn't affect to any UI @@ -155,12 +179,26 @@ function setIsAuthenticating(val: boolean) { authenticating = val; } +function getShouldUseNewPartnerName(): boolean | undefined { + if (!CONFIG.IS_HYBRID_APP) { + return true; + } + + return shouldUseNewPartnerName; +} + +function hasReadShouldUseNewPartnerNameFromStorage(): Promise { + return shouldUseNewPartnerNamePromise; +} + export { + getShouldUseNewPartnerName, getAuthToken, setAuthToken, getCurrentUserEmail, hasReadRequiredDataFromStorage, resetHasReadRequiredDataFromStorage, + hasReadShouldUseNewPartnerNameFromStorage, isOffline, onReconnection, isAuthenticating, 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. diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index 838c4b1a7e0d..a1d1058869fd 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -113,6 +113,7 @@ const KEYS_TO_PRESERVE: OnyxKey[] = [ ONYXKEYS.NVP_PREFERRED_LOCALE, ONYXKEYS.CREDENTIALS, ONYXKEYS.PRESERVED_USER_SESSION, + ONYXKEYS.HYBRID_APP, ]; Onyx.connect({ diff --git a/src/libs/actions/Delegate.ts b/src/libs/actions/Delegate.ts index 7177ceb26de1..dde956df777a 100644 --- a/src/libs/actions/Delegate.ts +++ b/src/libs/actions/Delegate.ts @@ -69,6 +69,7 @@ const KEYS_TO_PRESERVE_DELEGATE_ACCESS = [ ONYXKEYS.STASHED_SESSION, 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. diff --git a/src/libs/actions/HybridApp/index.ts b/src/libs/actions/HybridApp/index.ts index 941d91ada965..0a14529d6871 100644 --- a/src/libs/actions/HybridApp/index.ts +++ b/src/libs/actions/HybridApp/index.ts @@ -1,14 +1,114 @@ import HybridAppModule from '@expensify/react-native-hybrid-app'; import Onyx from 'react-native-onyx'; +import Log from '@libs/Log'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {HybridApp} from '@src/types/onyx'; +import type HybridAppSettings from './types'; -function closeReactNativeApp({shouldSignOut, shouldSetNVP}: {shouldSignOut: boolean; shouldSetNVP: boolean}) { +/* + * Parses initial settings passed from OldDot app + */ +function parseHybridAppSettings(hybridAppSettings: string | null): HybridAppSettings | null { + if (!hybridAppSettings) { + return null; + } + + return JSON.parse(hybridAppSettings) as HybridAppSettings; +} + +function getHybridAppSettings(): Promise { + return HybridAppModule.getHybridAppSettings().then((hybridAppSettings) => { + return parseHybridAppSettings(hybridAppSettings); + }); +} + +function closeReactNativeApp({shouldSetNVP}: {shouldSetNVP: boolean}) { if (CONFIG.IS_HYBRID_APP) { Onyx.merge(ONYXKEYS.HYBRID_APP, {closingReactNativeApp: true}); } // eslint-disable-next-line no-restricted-properties - HybridAppModule.closeReactNativeApp({shouldSignOut, shouldSetNVP}); + HybridAppModule.closeReactNativeApp({shouldSetNVP}); +} + +/* + * 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}); +} + +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}); +} + +/* + * 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 Promise.resolve(); + } + + return Onyx.merge(ONYXKEYS.HYBRID_APP, { + readyToShowAuthScreens: false, + useNewDotSignInPage: true, + }); +} + +/* + * 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, { + ...hybridApp, + readyToShowAuthScreens: !(hybridApp?.useNewDotSignInPage ?? false), + }); + } + + // 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, + }); +} + +function migrateHybridAppToNewPartnerName() { + if (!CONFIG.IS_HYBRID_APP) { + return; + } + + Log.info('[HybridApp] Migrating to new partner name'); + Onyx.merge(ONYXKEYS.HYBRID_APP, { + shouldUseNewPartnerName: true, + }); } -export default closeReactNativeApp; +export { + getHybridAppSettings, + setReadyToShowAuthScreens, + resetSignInFlow, + prepareHybridAppAfterTransitionToNewDot, + setUseNewDotSignInPage, + setClosingReactNativeApp, + closeReactNativeApp, + migrateHybridAppToNewPartnerName, +}; diff --git a/src/libs/actions/HybridApp/types.ts b/src/libs/actions/HybridApp/types.ts new file mode 100644 index 000000000000..5d4ab1431cbc --- /dev/null +++ b/src/libs/actions/HybridApp/types.ts @@ -0,0 +1,11 @@ +import type ONYXKEYS from '@src/ONYXKEYS'; +import type {TryNewDot} from '@src/types/onyx'; +import type HybridApp from '@src/types/onyx/HybridApp'; + +type HybridAppSettings = { + [ONYXKEYS.HYBRID_APP]: HybridApp; + [ONYXKEYS.NVP_TRY_NEW_DOT]?: TryNewDot; + [ONYXKEYS.ACCOUNT]?: {shouldUseStagingServer: boolean}; +}; + +export default HybridAppSettings; diff --git a/src/libs/actions/QueuedOnyxUpdates.ts b/src/libs/actions/QueuedOnyxUpdates.ts index 3f679bdcbe15..4af625b21305 100644 --- a/src/libs/actions/QueuedOnyxUpdates.ts +++ b/src/libs/actions/QueuedOnyxUpdates.ts @@ -33,6 +33,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, diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 739d708228c6..fb273f43402a 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -3,8 +3,9 @@ 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 {migrateHybridAppToNewPartnerName} from '@libs/actions/HybridApp'; import * as PersistedRequests from '@libs/actions/PersistedRequests'; import * as API from '@libs/API'; import type { @@ -41,13 +42,15 @@ import NetworkConnection from '@libs/NetworkConnection'; import Pusher from '@libs/Pusher'; import {getReportIDFromLink, parseReportRouteParams as parseReportRouteParamsReportUtils} 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'; -import {KEYS_TO_PRESERVE, openApp, reconnectApp} from '@userActions/App'; +import {confirmReadyToOpenApp, KEYS_TO_PRESERVE, openApp} from '@userActions/App'; import {KEYS_TO_PRESERVE_DELEGATE_ACCESS} from '@userActions/Delegate'; import * as Device from '@userActions/Device'; -import closeReactNativeApp from '@userActions/HybridApp'; +import * as HybridAppActions from '@userActions/HybridApp'; +import type HybridAppSettings from '@userActions/HybridApp/types'; import redirectToSignIn from '@userActions/SignInRedirect'; import Timing from '@userActions/Timing'; import * as Welcome from '@userActions/Welcome'; @@ -57,6 +60,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {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 Locale from '@src/types/onyx/Locale'; import type Response from '@src/types/onyx/Response'; @@ -70,12 +74,18 @@ const INVALID_TOKEN = 'pizza'; let session: Session = {}; let authPromiseResolver: ((value: boolean) => void) | null = null; +let isHybridAppSetupFinished = false; let hasSwitchedAccountInHybridMode = false; Onyx.connect({ key: ONYXKEYS.SESSION, callback: (value) => { session = value ?? {}; + + if (!session?.authToken && isHybridAppSetupFinished) { + migrateHybridAppToNewPartnerName(); + } + if (!session.creationDate) { session.creationDate = new Date().getTime(); } @@ -83,7 +93,7 @@ Onyx.connect({ authPromiseResolver(true); authPromiseResolver = null; } - if (CONFIG.IS_HYBRID_APP && session.authToken && session.authToken !== INVALID_TOKEN) { + if (CONFIG.IS_HYBRID_APP && isHybridAppSetupFinished && session.authToken && session.authToken !== INVALID_TOKEN && !isAnonymousUser(value)) { HybridAppModule.sendAuthToken({authToken: session.authToken}); } }, @@ -204,19 +214,23 @@ function signInWithSupportAuthToken(authToken: string) { * Clears the Onyx store and redirects user to the sign in page */ function signOut(): Promise { - Log.info('Flushing logs before signing out', true, {}, true); - const params: LogOutParams = { - // Send current authToken because we will immediately clear it once triggering this command - authToken: NetworkStore.getAuthToken() ?? null, - partnerUserID: credentials?.autoGeneratedLogin ?? '', - partnerName: CONFIG.EXPENSIFY.PARTNER_NAME, - partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD, - shouldRetry: false, - skipReauthentication: true, - }; + return NetworkStore.hasReadShouldUseNewPartnerNameFromStorage().then(() => { + Log.info('Flushing logs before signing out', true, {}, true); + const shouldUseNewPartnerName = NetworkStore.getShouldUseNewPartnerName(); + + const params: LogOutParams = { + // Send current authToken because we will immediately clear it once triggering this command + authToken: NetworkStore.getAuthToken() ?? null, + partnerUserID: credentials?.autoGeneratedLogin ?? '', + partnerName: shouldUseNewPartnerName ? CONFIG.EXPENSIFY.PARTNER_NAME : CONFIG.EXPENSIFY.LEGACY_PARTNER_NAME, + partnerPassword: shouldUseNewPartnerName ? CONFIG.EXPENSIFY.PARTNER_PASSWORD : CONFIG.EXPENSIFY.LEGACY_PARTNER_PASSWORD, + shouldRetry: false, + skipReauthentication: true, + }; - // eslint-disable-next-line rulesdir/no-api-side-effects-method - return API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.LOG_OUT, params, {}); + // eslint-disable-next-line rulesdir/no-api-side-effects-method + return API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.LOG_OUT, params, {}); + }); } /** @@ -245,7 +259,7 @@ function isExpiredSession(sessionCreationDate: number): boolean { return new Date().getTime() - sessionCreationDate >= CONST.SESSION_EXPIRATION_TIME_MS; } -function signOutAndRedirectToSignIn(shouldResetToHome?: boolean, shouldStashSession?: boolean, shouldKillHybridApp = true, shouldForceUseStashedSession?: boolean) { +function signOutAndRedirectToSignIn(shouldResetToHome?: boolean, shouldStashSession?: boolean, shouldSignOutFromOldDot = true, shouldForceUseStashedSession?: boolean) { Log.info('Redirecting to Sign In because signOut() was called'); hideContextMenu(false); @@ -265,10 +279,9 @@ function signOutAndRedirectToSignIn(shouldResetToHome?: boolean, shouldStashSess return; } - // In the HybridApp, we want the Old Dot to handle the sign out process - if (CONFIG.IS_HYBRID_APP && shouldKillHybridApp) { - closeReactNativeApp({shouldSignOut: true, shouldSetNVP: false}); - return; + // 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(); } const isSupportal = isSupportAuthToken(); @@ -327,7 +340,7 @@ function signOutAndRedirectToSignIn(shouldResetToHome?: boolean, shouldStashSess } // Wait for signOut (if called), then redirect and update Onyx. - signOutPromise + return signOutPromise .then((response) => { if (response?.hasOldDotAuthCookies) { Log.info('Redirecting to OldDot sign out'); @@ -360,7 +373,9 @@ function signOutAndRedirectToSignIn(shouldResetToHome?: boolean, shouldStashSess // eslint-disable-next-line @typescript-eslint/no-explicit-any function callFunctionIfActionIsAllowed any) | void>(callback: TCallback, isAnonymousAction = false): TCallback | (() => void) { if (isAnonymousUser() && !isAnonymousAction) { - return () => signOutAndRedirectToSignIn(); + return () => { + signOutAndRedirectToSignIn(); + }; } return callback; } @@ -518,127 +533,87 @@ 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), - }); - }); -} - -type HybridAppSettings = { - email: string; - authToken: string; - accountID: number; - autoGeneratedLogin: string; - autoGeneratedPassword: string; - clearOnyxOnStart: boolean; - completedHybridAppOnboarding: boolean; - isSingleNewDotEntry: boolean; - isStaging: boolean; - primaryLogin: string; - encryptedAuthToken: string; - nudgeMigrationTimestamp?: string; - oldDotOriginalAccountEmail?: string; - stashedAuthToken?: string; - stashedAccountID?: string; - requiresTwoFactorAuth: boolean; - needsTwoFactorAuthSetup: boolean; -}; +function setupNewDotAfterTransitionFromOldDot(hybridAppSettings: HybridAppSettings, tryNewDot?: TryNewDot) { + const {hybridApp, ...newDotOnyxValues} = hybridAppSettings; -function signInAfterTransitionFromOldDot(hybridAppSettings: string) { - const { - email, - authToken, - encryptedAuthToken, - accountID, - autoGeneratedLogin, - autoGeneratedPassword, - clearOnyxOnStart, - completedHybridAppOnboarding, - nudgeMigrationTimestamp, - isSingleNewDotEntry, - isStaging, - primaryLogin, - oldDotOriginalAccountEmail, - stashedAuthToken, - stashedAccountID, - requiresTwoFactorAuth, - needsTwoFactorAuthSetup, - } = JSON.parse(hybridAppSettings) as HybridAppSettings; - - const clearOnyxForNewAccount = () => { - if (!clearOnyxOnStart) { + const clearOnyxIfSigningIn = () => { + if (!hybridApp.useNewDotSignInPage) { return Promise.resolve(); } - // 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)); + Log.info(`[HybridApp] Clearing onyx after transition from OldDot. useNewDotSignInPage set to ${hybridApp.useNewDotSignInPage}`); + return redirectToSignIn(); }; - // This section controls copilot changes - const currentUserEmail = getCurrentUserEmail(); - - return clearOnyxForNewAccount() - .then(() => { - // If OD is in copilot, stash the original account data - if (oldDotOriginalAccountEmail && oldDotOriginalAccountEmail !== email) { - return Onyx.multiSet({ - [ONYXKEYS.STASHED_SESSION]: {email: oldDotOriginalAccountEmail, authToken: stashedAuthToken, accountID: Number(stashedAccountID)}, - [ONYXKEYS.STASHED_CREDENTIALS]: {autoGeneratedLogin, autoGeneratedPassword}, - }); - } + const resetDidUserLoginDuringSessionIfNeeded = () => { + if (newDotOnyxValues.nvp_tryNewDot === undefined || tryNewDot?.classicRedirect?.dismissed !== true) { + return Promise.resolve(); + } - // If OD and ND account are the same - do nothing - if (email === currentUserEmail) { - return; - } + Log.info("[HybridApp] OpenApp hasn't been called yet. Calling `resetDidUserLogInDuringSession`"); + resetDidUserLogInDuringSession(); + }; - // If account was changed to original one on OD side - clear onyx - if (!oldDotOriginalAccountEmail) { - return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS); - } + return clearOnyxIfSigningIn() + .then(() => { + // This section controls copilot changes + const currentUserEmail = getCurrentUserEmail(); - // If we're already logged in - do nothing, data will be set in next step - if (currentUserEmail) { + // If ND and OD account are the same - do nothing + if (hybridApp?.delegateAccessData?.oldDotCurrentUserEmail === currentUserEmail) { + Log.info('[HybridApp] User did not switch account on OldDot side'); return; } - // If we're not logged in - set stashed data - return Onyx.multiSet({ - [ONYXKEYS.STASHED_CREDENTIALS]: {autoGeneratedLogin, autoGeneratedPassword}, - }); + const stashedData = hybridApp?.delegateAccessData?.isDelegateAccess + ? { + [ONYXKEYS.STASHED_CREDENTIALS]: credentials, + [ONYXKEYS.STASHED_SESSION]: session, + } + : { + [ONYXKEYS.STASHED_CREDENTIALS]: {}, + [ONYXKEYS.STASHED_SESSION]: {}, + }; + + Log.info('[HybridApp] User switched account on OldDot side. Clearing onyx and applying delegate 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, + }, + // When a logged-in user opens NewDot for the first time after migrating to the new SignInPage, there will be no credentials on the NewDot side. + // After migration, NewDot is responsible for creating credentials, but this only happens during sign-in. + // To avoid blocking the transition, we fall back to credentials from OldDot in this scenario. + // The `delegateAccessData` key is misleading in this context because, in the past, this code only handled Copilot. We are reusing the same logic here for this scenario. + [ONYXKEYS.CREDENTIALS]: { + autoGeneratedLogin: credentials?.autoGeneratedLogin ?? hybridApp.delegateAccessData?.oldDotAutoGeneratedLogin, + autoGeneratedPassword: credentials?.autoGeneratedPassword ?? hybridApp.delegateAccessData?.oldDotAutoGeneratedPassword, + }, + }) + .then(() => Onyx.merge(ONYXKEYS.ACCOUNT, {primaryLogin: hybridApp?.delegateAccessData?.oldDotCurrentUserEmail})) + .then(() => { + Log.info('[HybridApp] Calling openApp to get delegate account details'); + confirmReadyToOpenApp(); + return openApp(); + }), + ); }) .then(() => - Onyx.multiSet({ - [ONYXKEYS.SESSION]: {email, authToken, encryptedAuthToken: decodeURIComponent(encryptedAuthToken), accountID: Number(accountID)}, - [ONYXKEYS.CREDENTIALS]: {autoGeneratedLogin, autoGeneratedPassword}, - [ONYXKEYS.NVP_TRY_NEW_DOT]: { - classicRedirect: {completedHybridAppOnboarding}, - nudgeMigration: nudgeMigrationTimestamp ? {timestamp: new Date(nudgeMigrationTimestamp)} : undefined, - }, - }) - .then(() => { - if (email === currentUserEmail) { - return; - } - return Onyx.set(ONYXKEYS.ACCOUNT, {shouldUseStagingServer: isStaging}); - }) - .then(() => Onyx.merge(ONYXKEYS.ACCOUNT, {primaryLogin, requiresTwoFactorAuth, needsTwoFactorAuthSetup})) - .then(() => Onyx.merge(ONYXKEYS.HYBRID_APP, {isSingleNewDotEntry, closingReactNativeApp: false})), + HybridAppActions.prepareHybridAppAfterTransitionToNewDot({ + ...hybridApp, + closingReactNativeApp: false, + }), ) + .then(resetDidUserLoginDuringSessionIfNeeded) + .then(() => Promise.all(Object.entries(newDotOnyxValues).map(([key, value]) => Onyx.merge(key as OnyxKey, value ?? {})))) .then(() => { - if (clearOnyxOnStart) { - return openApp(); - } - return getLastUpdateIDAppliedToClient().then((lastUpdateId) => { - return reconnectApp(lastUpdateId); - }); + Log.info('[HybridApp] Setup after transition from OldDot finished'); + isHybridAppSetupFinished = true; + return Promise.resolve(); }) .catch((error) => { Log.hmmm('[HybridApp] Initialization of HybridApp has failed. Forcing transition', {error}); @@ -1483,7 +1458,7 @@ export { isSupportAuthToken, hasStashedSession, signUpUser, - signInAfterTransitionFromOldDot, + setupNewDotAfterTransitionFromOldDot, AddWorkEmail, MergeIntoAccountAndLogin, resetSMSDeliveryFailureStatus, diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index 8b265a614d4c..c82c1960656e 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -1,8 +1,11 @@ +import HybridAppModule from '@expensify/react-native-hybrid-app'; 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 {resetSignInFlow} from './HybridApp'; import {clearAllPolicies} from './Policy/Policy'; let currentIsOffline: boolean | undefined; @@ -34,6 +37,10 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { } return Onyx.clear(keysToPreserve).then(() => { + if (CONFIG.IS_HYBRID_APP) { + resetSignInFlow(); + HybridAppModule.signOutFromOldDot(); + } clearAllPolicies(); if (!errorMessage) { return; diff --git a/src/libs/actions/User.ts b/src/libs/actions/User.ts index a5e74bde8e09..dc0a68e5d088 100644 --- a/src/libs/actions/User.ts +++ b/src/libs/actions/User.ts @@ -117,6 +117,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(); + } } /** diff --git a/src/pages/ErrorPage/SessionExpiredPage.tsx b/src/pages/ErrorPage/SessionExpiredPage.tsx index 4972b8e6459e..31f6210a0d31 100644 --- a/src/pages/ErrorPage/SessionExpiredPage.tsx +++ b/src/pages/ErrorPage/SessionExpiredPage.tsx @@ -9,9 +9,7 @@ import useLocalize from '@hooks/useLocalize'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; -import closeReactNativeApp from '@userActions/HybridApp'; import {clearSignInData} from '@userActions/Session'; -import CONFIG from '@src/CONFIG'; function SessionExpiredPage() { const styles = useThemeStyles(); @@ -34,12 +32,8 @@ function SessionExpiredPage() { {translate('deeplinkWrapper.expired')}{' '} { - if (!CONFIG.IS_HYBRID_APP) { - clearSignInData(); - Navigation.goBack(); - return; - } - closeReactNativeApp({shouldSignOut: true, shouldSetNVP: false}); + clearSignInData(); + Navigation.goBack(); }} > {translate('deeplinkWrapper.signIn')} diff --git a/src/pages/LogInWithShortLivedAuthTokenPage.tsx b/src/pages/LogInWithShortLivedAuthTokenPage.tsx index 6875b462f839..e3a67a41edd1 100644 --- a/src/pages/LogInWithShortLivedAuthTokenPage.tsx +++ b/src/pages/LogInWithShortLivedAuthTokenPage.tsx @@ -6,7 +6,6 @@ import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {PublicScreensParamList} from '@libs/Navigation/types'; import {setAccountError, signInWithShortLivedAuthToken, signInWithSupportAuthToken} from '@userActions/Session'; -import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; @@ -18,7 +17,7 @@ type LogInWithShortLivedAuthTokenPageProps = PlatformStackScreenProps { // We have to check for both shortLivedAuthToken and shortLivedToken, as the old mobile app uses shortLivedToken, and is not being actively updated. @@ -46,8 +45,7 @@ function LogInWithShortLivedAuthTokenPage({route}: LogInWithShortLivedAuthTokenP setAccountError(error); } - // For HybridApp we have separate logic to handle transitions. - if (!CONFIG.IS_HYBRID_APP && exitTo) { + if (exitTo) { Navigation.isNavigationReady().then(() => { // We must call goBack() to remove the /transition route from history Navigation.goBack(); diff --git a/src/pages/LogOutPreviousUserPage.tsx b/src/pages/LogOutPreviousUserPage.tsx index 16d4082e2201..b9b153da4f64 100644 --- a/src/pages/LogOutPreviousUserPage.tsx +++ b/src/pages/LogOutPreviousUserPage.tsx @@ -35,7 +35,7 @@ function LogOutPreviousUserPage({route}: LogOutPreviousUserPageProps) { if (isLoggingInAsNewUser) { // We don't want to close react-native app in this particular case. - signOutAndRedirectToSignIn(false, isSupportalLogin, false); + signOutAndRedirectToSignIn(false, isSupportalLogin); return; } diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index 89e7f15c772e..9fd7e12d5ded 100644 --- a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx +++ b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx @@ -21,7 +21,6 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; -import closeReactNativeApp from '@libs/actions/HybridApp'; import {openOldDotLink} from '@libs/actions/Link'; import {setOnboardingAdminsChatReportID, setOnboardingPolicyID, setOnboardingUserReportedIntegration} from '@libs/actions/Welcome'; import Navigation from '@libs/Navigation/Navigation'; @@ -29,6 +28,7 @@ import {waitForIdle} from '@libs/Network/SequentialQueue'; import {shouldOnboardingRedirectToOldDot} from '@libs/OnboardingUtils'; import {isPaidGroupPolicy, isPolicyAdmin} from '@libs/PolicyUtils'; import variables from '@styles/variables'; +import {closeReactNativeApp} from '@userActions/HybridApp'; import CONFIG from '@src/CONFIG'; import type {OnboardingAccounting} from '@src/CONST'; import CONST from '@src/CONST'; @@ -134,7 +134,7 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding } if (CONFIG.IS_HYBRID_APP) { - closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); + closeReactNativeApp({shouldSetNVP: true}); return; } waitForIdle().then(() => { diff --git a/src/pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures.tsx b/src/pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures.tsx index 34aa6a3cf467..d8d32cd075c1 100644 --- a/src/pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures.tsx +++ b/src/pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures.tsx @@ -31,7 +31,7 @@ import Navigation from '@libs/Navigation/Navigation'; import {waitForIdle} from '@libs/Network/SequentialQueue'; import {shouldOnboardingRedirectToOldDot} from '@libs/OnboardingUtils'; import {isPaidGroupPolicy, isPolicyAdmin} from '@libs/PolicyUtils'; -import closeReactNativeApp from '@userActions/HybridApp'; +import {closeReactNativeApp} from '@userActions/HybridApp'; import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; @@ -152,7 +152,7 @@ function BaseOnboardingInterestedFeatures({shouldUseNativeStyles}: BaseOnboardin } if (CONFIG.IS_HYBRID_APP) { - closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); + closeReactNativeApp({shouldSetNVP: true}); setRootStatusBarEnabled(false); return; } diff --git a/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx index c89cd96f7c31..043d7cad4674 100644 --- a/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx @@ -47,7 +47,7 @@ import {getQuickActionIcon, getQuickActionTitle, isQuickActionAllowed} from '@li import {generateReportID, getDisplayNameForParticipant, getIcons, getReportName, getWorkspaceChats, isPolicyExpenseChat} from '@libs/ReportUtils'; import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils'; import variables from '@styles/variables'; -import closeReactNativeApp from '@userActions/HybridApp'; +import {closeReactNativeApp} from '@userActions/HybridApp'; import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -583,7 +583,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT onConfirm={() => { setModalVisible(false); if (CONFIG.IS_HYBRID_APP) { - closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); + closeReactNativeApp({shouldSetNVP: true}); return; } openOldDotLink(CONST.OLDDOT_URLS.INBOX); diff --git a/src/pages/home/sidebar/SignInButton.tsx b/src/pages/home/sidebar/SignInButton.tsx index 228bc70fe08d..4ae7d45a9170 100644 --- a/src/pages/home/sidebar/SignInButton.tsx +++ b/src/pages/home/sidebar/SignInButton.tsx @@ -21,7 +21,9 @@ function SignInButton() {