forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'make-new-dot-signin-default-for-hybridapp' into war-in/…
…add-named-params-to-HybridAppModule-methods # Conflicts: # src/libs/actions/Session/index.ts # src/types/modules/react-native.d.ts
- Loading branch information
Showing
24 changed files
with
364 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import {NativeModules} from 'react-native'; | ||
import Onyx from 'react-native-onyx'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {Credentials, HybridApp, Session, TryNewDot} from '@src/types/onyx'; | ||
import * as HybridAppActions from './actions/HybridApp'; | ||
import Log from './Log'; | ||
import {getCurrentUserEmail} from './Network/NetworkStore'; | ||
|
||
let currentHybridApp: OnyxEntry<HybridApp>; | ||
let currentTryNewDot: OnyxEntry<TryNewDot>; | ||
let currentCredentials: OnyxEntry<Credentials>; | ||
|
||
Onyx.connect({ | ||
key: ONYXKEYS.HYBRID_APP, | ||
callback: (hybridApp) => { | ||
handleChangeInHybridAppSignInFlow(hybridApp, currentTryNewDot, currentCredentials); | ||
}, | ||
}); | ||
|
||
Onyx.connect({ | ||
key: ONYXKEYS.NVP_TRYNEWDOT, | ||
callback: (tryNewDot) => { | ||
handleChangeInHybridAppSignInFlow(currentHybridApp, tryNewDot, currentCredentials); | ||
}, | ||
}); | ||
|
||
Onyx.connect({ | ||
key: ONYXKEYS.CREDENTIALS, | ||
callback: (credentials) => { | ||
currentCredentials = credentials; | ||
handleChangeInHybridAppSignInFlow(currentHybridApp, currentTryNewDot, credentials); | ||
}, | ||
}); | ||
|
||
let currentSession: OnyxEntry<Session>; | ||
Onyx.connect({ | ||
key: ONYXKEYS.SESSION, | ||
callback: (session: OnyxEntry<Session>) => { | ||
if (!currentSession?.authToken && session?.authToken && currentHybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED) { | ||
HybridAppActions.setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED); | ||
} | ||
currentSession = session; | ||
}, | ||
}); | ||
|
||
let activePolicyID: OnyxEntry<string>; | ||
Onyx.connect({ | ||
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID, | ||
callback: (newActivePolicyID) => { | ||
activePolicyID = newActivePolicyID; | ||
}, | ||
}); | ||
|
||
function shouldUseOldApp(tryNewDot?: TryNewDot) { | ||
return tryNewDot?.classicRedirect.dismissed === true; | ||
} | ||
|
||
function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry<HybridApp>, tryNewDot: OnyxEntry<TryNewDot>, credentials: OnyxEntry<Credentials>) { | ||
if (!NativeModules.HybridAppModule) { | ||
return; | ||
} | ||
|
||
if (!hybridApp?.useNewDotSignInPage) { | ||
currentHybridApp = hybridApp; | ||
currentTryNewDot = tryNewDot; | ||
return; | ||
} | ||
|
||
if (hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && tryNewDot !== undefined && !!credentials?.autoGeneratedLogin && !!credentials?.autoGeneratedPassword) { | ||
Log.info(`[HybridApp] Performing sign-in${shouldUseOldApp(tryNewDot) ? '' : ' (in background)'} on OldDot side`); | ||
NativeModules.HybridAppModule.signInToOldDot( | ||
credentials.autoGeneratedLogin, | ||
credentials.autoGeneratedPassword, | ||
currentSession?.authToken ?? '', | ||
getCurrentUserEmail() ?? '', | ||
activePolicyID ?? '', | ||
); | ||
HybridAppActions.setUseNewDotSignInPage(false).then(() => { | ||
if (shouldUseOldApp(tryNewDot)) { | ||
NativeModules.HybridAppModule.closeReactNativeApp(false, false); | ||
} else { | ||
Log.info('[HybridApp] The user should see NewDot. There is no need to block the user on the `SignInPage` until the sign-in process is completed on the OldDot side.'); | ||
HybridAppActions.setReadyToShowAuthScreens(true); | ||
} | ||
}); | ||
} | ||
|
||
currentHybridApp = hybridApp; | ||
currentTryNewDot = tryNewDot; | ||
} | ||
|
||
export default {shouldUseOldApp}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.