Skip to content

Commit

Permalink
simplify blocking logic
Browse files Browse the repository at this point in the history
  • Loading branch information
war-in committed Dec 6, 2024
1 parent 6f5d0c7 commit 84a8445
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 30 deletions.
24 changes: 8 additions & 16 deletions src/libs/HybridApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,7 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry<HybridApp>, tryN
return;
}

if (
hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED &&
!hybridApp?.signedInOnOldDot &&
tryNewDot !== undefined &&
!!credentials?.autoGeneratedLogin &&
!!credentials?.autoGeneratedPassword
) {
if (hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && tryNewDot !== undefined && !!credentials?.autoGeneratedLogin && !!credentials?.autoGeneratedPassword) {
Log.info(`[HybridApp] Performing sign-in${shouldUseOldApp(tryNewDot) ? '' : ' (in background)'} on OldDot side`);
NativeModules.HybridAppModule.signInToOldDot(
credentials.autoGeneratedLogin,
Expand All @@ -84,16 +78,14 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry<HybridApp>, tryN
getCurrentUserEmail() ?? '',
activePolicyID ?? '',
);
HybridAppActions.setSignedInOnOldDot(true);

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

currentHybridApp = hybridApp;
Expand Down
8 changes: 1 addition & 7 deletions src/libs/actions/HybridApp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,13 @@ function setUseNewDotSignInPage(useNewDotSignInPage: boolean) {
return Onyx.merge(ONYXKEYS.HYBRID_APP, {useNewDotSignInPage});
}

function setSignedInOnOldDot(signedInOnOldDot: boolean) {
Onyx.merge(ONYXKEYS.HYBRID_APP, {signedInOnOldDot});
}

/*
* Starts HybridApp sign-in flow from the beginning.
*/
function resetSignInFlow() {
Onyx.merge(ONYXKEYS.HYBRID_APP, {
readyToShowAuthScreens: false,
newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED,
signedInOnOldDot: false,
});
}

Expand All @@ -54,7 +49,6 @@ function prepareHybridAppAfterTransitionToNewDot(hybridApp: HybridApp) {
...hybridApp,
readyToShowAuthScreens: false,
newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED,
signedInOnOldDot: false,
});
}

Expand All @@ -65,4 +59,4 @@ function prepareHybridAppAfterTransitionToNewDot(hybridApp: HybridApp) {
});
}

export {parseHybridAppSettings, setReadyToShowAuthScreens, setNewDotSignInState, resetSignInFlow, prepareHybridAppAfterTransitionToNewDot, setUseNewDotSignInPage, setSignedInOnOldDot};
export {parseHybridAppSettings, setReadyToShowAuthScreens, setNewDotSignInState, resetSignInFlow, prepareHybridAppAfterTransitionToNewDot, setUseNewDotSignInPage};
6 changes: 2 additions & 4 deletions src/pages/settings/InitialSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,8 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
...(NativeModules.HybridAppModule
? {
action: () => {
HybridAppActions.setUseNewDotSignInPage(false).then(() => {
NativeModules.HybridAppModule.closeReactNativeApp(false, true);
setInitialURL(undefined);
});
NativeModules.HybridAppModule.closeReactNativeApp(false, true);
setInitialURL(undefined);
},
}
: {
Expand Down
3 changes: 0 additions & 3 deletions src/types/onyx/HybridApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ type HybridApp = {

/** Describes current stage of NewDot sign-in */
newDotSignInState?: ValueOf<typeof CONST.HYBRID_APP_SIGN_IN_STATE>;

/** Tells if OldDot sign-in was performed */
signedInOnOldDot?: boolean;
};

export default HybridApp;

0 comments on commit 84a8445

Please sign in to comment.