Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
war-in committed Dec 6, 2024
1 parent 1c9175e commit 4317251
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 28 deletions.
12 changes: 4 additions & 8 deletions src/libs/HybridApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry<HybridApp>, tryN
}

if (hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && tryNewDot !== undefined) {
if (!shouldUseOldApp(tryNewDot)) {
Log.info('[HybridApp] The user should see NewDot. There is no need to block the user on the `SignInPage` until the sign-in process is completed on the OldDot side.');
HybridAppActions.setReadyToShowAuthScreens(true);
}

Log.info(`[HybridApp] Performing sign-in${shouldUseOldApp(tryNewDot) ? '' : ' (in background)'} on OldDot side`);
NativeModules.HybridAppModule.signInToOldDot(
credentials?.autoGeneratedLogin ?? '',
Expand All @@ -85,11 +80,12 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry<HybridApp>, tryN
);

if (shouldUseOldApp(tryNewDot)) {
Onyx.merge(ONYXKEYS.HYBRID_APP, {
useNewDotSignInPage: false,
}).then(() => {
HybridAppActions.setUseNewDotSignInPage(false).then(() => {
NativeModules.HybridAppModule.closeReactNativeApp(false, false);
});
} else {
Log.info('[HybridApp] The user should see NewDot. There is no need to block the user on the `SignInPage` until the sign-in process is completed on the OldDot side.');
HybridAppActions.setReadyToShowAuthScreens(true);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/libs/Navigation/AppNavigator/PublicScreens.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import {NativeModules} from 'react-native';
import createPlatformStackNavigator from '@libs/Navigation/PlatformStackNavigation/createPlatformStackNavigator';
import type {PublicScreensParamList} from '@navigation/types';
import ConnectionCompletePage from '@pages/ConnectionCompletePage';
Expand Down
18 changes: 5 additions & 13 deletions src/libs/actions/HybridApp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,15 @@ function setNewDotSignInState(newDotSignInState: ValueOf<typeof CONST.HYBRID_APP
Onyx.merge(ONYXKEYS.HYBRID_APP, {newDotSignInState});
}

/*
* Starts HybridApp sign-in flow from the beginning.
* In certain cases, it can perform sign-out if necessary
*/
function resetSignInFlow() {
Onyx.merge(ONYXKEYS.HYBRID_APP, {
readyToShowAuthScreens: false,
newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED,
});
function setUseNewDotSignInPage(useNewDotSignInPage: boolean) {
return Onyx.merge(ONYXKEYS.HYBRID_APP, {useNewDotSignInPage});
}

/*
* Sets proper sign-in state after sign-out on NewDot side
* Starts HybridApp sign-in flow from the beginning.
*/
function resetStateAfterSignOut() {
function resetSignInFlow() {
Onyx.merge(ONYXKEYS.HYBRID_APP, {
useNewDotSignInPage: true,
readyToShowAuthScreens: false,
newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED,
});
Expand All @@ -68,4 +60,4 @@ function prepareHybridAppAfterTransitionToNewDot(hybridApp: HybridApp) {
});
}

export {parseHybridAppSettings, setReadyToShowAuthScreens, setNewDotSignInState, resetSignInFlow, prepareHybridAppAfterTransitionToNewDot, resetStateAfterSignOut};
export {parseHybridAppSettings, setReadyToShowAuthScreens, setNewDotSignInState, resetSignInFlow, prepareHybridAppAfterTransitionToNewDot, setUseNewDotSignInPage};
2 changes: 1 addition & 1 deletion src/libs/actions/SignInRedirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function clearStorageAndRedirect(errorMessage?: string): Promise<void> {
Onyx.merge(ONYXKEYS.SESSION, {errors: ErrorUtils.getMicroSecondOnyxErrorWithMessage(errorMessage)});

if (NativeModules.HybridAppModule) {
HybridAppActions.resetStateAfterSignOut();
HybridAppActions.resetSignInFlow();
}
});
}
Expand Down
6 changes: 2 additions & 4 deletions src/pages/settings/InitialSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
...(NativeModules.HybridAppModule
? {
action: () => {
Onyx.merge(ONYXKEYS.HYBRID_APP, {
useNewDotSignInPage: false,
}).then(() => {
HybridAppActions.setUseNewDotSignInPage(false).then(() => {
NativeModules.HybridAppModule.closeReactNativeApp(false, true);
setInitialURL(undefined);
});
Expand Down Expand Up @@ -279,7 +277,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
icon: Expensicons.Exit,
action: () => {
signOut(false);
HybridAppActions.resetStateAfterSignOut();
HybridAppActions.resetSignInFlow();
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco
const clearSignInData = useCallback(() => {
clearLocalSignInData();
SessionActions.clearSignInData();
}, [clearLocalSignInData, session?.authToken]);
}, [clearLocalSignInData]);

useImperativeHandle(forwardedRef, () => ({
clearSignInData,
Expand Down

0 comments on commit 4317251

Please sign in to comment.