Skip to content

Commit 6f91ef1

Browse files
committed
remove newDotSignInState
1 parent b196416 commit 6f91ef1

11 files changed

Lines changed: 24 additions & 77 deletions

File tree

src/CONST/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6609,12 +6609,6 @@ const CONST = {
66096609
HIDDEN: `hidden`,
66106610
},
66116611

6612-
HYBRID_APP_SIGN_IN_STATE: {
6613-
NOT_STARTED: 'notStarted',
6614-
STARTED: 'started',
6615-
FINISHED: 'finished',
6616-
},
6617-
66186612
CSV_IMPORT_COLUMNS: {
66196613
EMAIL: 'email',
66206614
NAME: 'name',

src/components/SignInButtons/AppleSignIn/index.android.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import {appleAuthAndroid} from '@invertase/react-native-apple-authentication';
22
import React from 'react';
33
import IconButton from '@components/SignInButtons/IconButton';
4-
import {setNewDotSignInState} from '@libs/actions/HybridApp';
54
import Log from '@libs/Log';
6-
import {beginAppleSignIn} from '@userActions/Session';
5+
import * as Session from '@userActions/Session';
76
import CONFIG from '@src/CONFIG';
87
import CONST from '@src/CONST';
98
import type {AppleSignInProps} from '.';
@@ -38,10 +37,7 @@ function appleSignInRequest(): Promise<string | undefined> {
3837
function AppleSignIn({onPress = () => {}}: AppleSignInProps) {
3938
const handleSignIn = () => {
4039
appleSignInRequest()
41-
.then((token) => {
42-
setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED);
43-
beginAppleSignIn(token);
44-
})
40+
.then((token) => Session.beginAppleSignIn(token))
4541
.catch((error: Record<string, unknown>) => {
4642
if (error.message === appleAuthAndroid.Error.SIGNIN_CANCELLED) {
4743
return null;

src/components/SignInButtons/AppleSignIn/index.ios.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import appleAuth from '@invertase/react-native-apple-authentication';
22
import type {AppleError} from '@invertase/react-native-apple-authentication';
33
import React from 'react';
44
import IconButton from '@components/SignInButtons/IconButton';
5-
import {setNewDotSignInState} from '@libs/actions/HybridApp';
65
import Log from '@libs/Log';
7-
import {beginAppleSignIn} from '@userActions/Session';
6+
import * as Session from '@userActions/Session';
87
import CONST from '@src/CONST';
98
import type {AppleSignInProps} from '.';
109

@@ -37,10 +36,7 @@ function appleSignInRequest(): Promise<string | null | undefined> {
3736
function AppleSignIn({onPress = () => {}}: AppleSignInProps) {
3837
const handleSignIn = () => {
3938
appleSignInRequest()
40-
.then((token) => {
41-
setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED);
42-
beginAppleSignIn(token);
43-
})
39+
.then((token) => Session.beginAppleSignIn(token))
4440
.catch((error: {code: AppleError}) => {
4541
if (error.code === appleAuth.Error.CANCELED) {
4642
return null;

src/components/SignInButtons/GoogleSignIn/index.native.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {GoogleSignin, statusCodes} from '@react-native-google-signin/google-signin';
22
import React from 'react';
33
import IconButton from '@components/SignInButtons/IconButton';
4-
import {setNewDotSignInState} from '@libs/actions/HybridApp';
54
import Log from '@libs/Log';
65
import {beginGoogleSignIn} from '@userActions/Session';
76
import CONFIG from '@src/CONFIG';
@@ -26,10 +25,7 @@ function googleSignInRequest() {
2625

2726
GoogleSignin.signIn()
2827
.then((response) => response.idToken)
29-
.then((token) => {
30-
setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED);
31-
beginGoogleSignIn(token);
32-
})
28+
.then((token) => beginGoogleSignIn(token))
3329
.catch((error: GoogleError | undefined) => {
3430
// Handle unexpected error shape
3531
if (error?.code === undefined) {

src/libs/HybridApp.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,45 @@ import HybridAppModule from '@expensify/react-native-hybrid-app';
22
import Onyx from 'react-native-onyx';
33
import type {OnyxEntry} from 'react-native-onyx';
44
import CONFIG from '@src/CONFIG';
5-
import CONST from '@src/CONST';
65
import ONYXKEYS from '@src/ONYXKEYS';
76
import type {Credentials, HybridApp, Session, TryNewDot} from '@src/types/onyx';
8-
import {setNewDotSignInState, setReadyToShowAuthScreens, setUseNewDotSignInPage} from './actions/HybridApp';
7+
import {setReadyToShowAuthScreens, setUseNewDotSignInPage} from './actions/HybridApp';
98
import {closeReactNativeApp} from './actions/Session';
109
import Log from './Log';
1110
import {getCurrentUserEmail} from './Network/NetworkStore';
1211

1312
let currentHybridApp: OnyxEntry<HybridApp>;
1413
let currentTryNewDot: OnyxEntry<TryNewDot>;
1514
let currentCredentials: OnyxEntry<Credentials>;
15+
let currentSession: OnyxEntry<Session>;
1616

1717
Onyx.connect({
1818
key: ONYXKEYS.HYBRID_APP,
1919
callback: (hybridApp) => {
20-
handleChangeInHybridAppSignInFlow(hybridApp, currentTryNewDot, currentCredentials);
20+
handleChangeInHybridAppSignInFlow(hybridApp, currentTryNewDot, currentCredentials, currentSession);
2121
},
2222
});
2323

2424
Onyx.connect({
2525
key: ONYXKEYS.NVP_TRY_NEW_DOT,
2626
callback: (tryNewDot) => {
27-
handleChangeInHybridAppSignInFlow(currentHybridApp, tryNewDot, currentCredentials);
27+
handleChangeInHybridAppSignInFlow(currentHybridApp, tryNewDot, currentCredentials, currentSession);
2828
},
2929
});
3030

3131
Onyx.connect({
3232
key: ONYXKEYS.CREDENTIALS,
3333
callback: (credentials) => {
3434
currentCredentials = credentials;
35-
handleChangeInHybridAppSignInFlow(currentHybridApp, currentTryNewDot, credentials);
35+
handleChangeInHybridAppSignInFlow(currentHybridApp, currentTryNewDot, credentials, currentSession);
3636
},
3737
});
3838

39-
let currentSession: OnyxEntry<Session>;
4039
Onyx.connect({
4140
key: ONYXKEYS.SESSION,
4241
callback: (session: OnyxEntry<Session>) => {
43-
if (!currentSession?.authToken && session?.authToken && currentHybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.STARTED) {
44-
setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED);
42+
if (!currentSession?.authToken && session?.authToken) {
43+
handleChangeInHybridAppSignInFlow(currentHybridApp, currentTryNewDot, currentCredentials, session);
4544
}
4645
currentSession = session;
4746
},
@@ -62,7 +61,7 @@ function shouldUseOldApp(tryNewDot?: TryNewDot) {
6261
return tryNewDot?.classicRedirect?.dismissed === true;
6362
}
6463

65-
function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry<HybridApp>, tryNewDot: OnyxEntry<TryNewDot>, credentials: OnyxEntry<Credentials>) {
64+
function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry<HybridApp>, tryNewDot: OnyxEntry<TryNewDot>, credentials: OnyxEntry<Credentials>, session: OnyxEntry<Session>) {
6665
if (!CONFIG.IS_HYBRID_APP) {
6766
return;
6867
}
@@ -73,14 +72,14 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry<HybridApp>, tryN
7372
return;
7473
}
7574

76-
if (hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && tryNewDot !== undefined && !!credentials?.autoGeneratedLogin && !!credentials?.autoGeneratedPassword) {
75+
if (!!session?.authToken && tryNewDot !== undefined && !!credentials?.autoGeneratedLogin && !!credentials?.autoGeneratedPassword) {
7776
// It's better to not pass function directly to Log.info to avoid bugs with evaluation
7877
const shouldUseOD = shouldUseOldApp(tryNewDot);
7978
Log.info(`[HybridApp] Performing sign-in${shouldUseOD ? '' : ' (in background)'} on OldDot side`);
8079
HybridAppModule.signInToOldDot({
8180
autoGeneratedLogin: credentials.autoGeneratedLogin,
8281
autoGeneratedPassword: credentials.autoGeneratedPassword,
83-
authToken: currentSession?.authToken ?? '',
82+
authToken: session.authToken,
8483
email: getCurrentUserEmail() ?? '',
8584
// eslint-disable-next-line rulesdir/no-default-id-values
8685
policyID: activePolicyID ?? '',

src/libs/actions/HybridApp/index.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import Onyx from 'react-native-onyx';
2-
import type {ValueOf} from 'type-fest';
32
import CONFIG from '@src/CONFIG';
4-
import CONST from '@src/CONST';
53
import ONYXKEYS from '@src/ONYXKEYS';
64
import type {HybridApp} from '@src/types/onyx';
75
import type HybridAppSettings from './types';
@@ -24,17 +22,6 @@ function setReadyToShowAuthScreens(readyToShowAuthScreens: boolean) {
2422
Onyx.merge(ONYXKEYS.HYBRID_APP, {readyToShowAuthScreens});
2523
}
2624

27-
/*
28-
* Changes NewDot sign-in state
29-
*/
30-
function setNewDotSignInState(newDotSignInState: ValueOf<typeof CONST.HYBRID_APP_SIGN_IN_STATE>) {
31-
// This value is only relevant for HybridApp, so we can skip it in other environments.
32-
if (!CONFIG.IS_HYBRID_APP) {
33-
return;
34-
}
35-
Onyx.merge(ONYXKEYS.HYBRID_APP, {newDotSignInState});
36-
}
37-
3825
function setUseNewDotSignInPage(useNewDotSignInPage: boolean) {
3926
// This value is only relevant for HybridApp, so we can skip it in other environments.
4027
if (!CONFIG.IS_HYBRID_APP) {
@@ -62,7 +49,6 @@ function resetSignInFlow() {
6249

6350
Onyx.merge(ONYXKEYS.HYBRID_APP, {
6451
readyToShowAuthScreens: false,
65-
newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED,
6652
useNewDotSignInPage: true,
6753
});
6854
}
@@ -75,7 +61,6 @@ function prepareHybridAppAfterTransitionToNewDot(hybridApp: HybridApp) {
7561
return Onyx.merge(ONYXKEYS.HYBRID_APP, {
7662
...hybridApp,
7763
readyToShowAuthScreens: !(hybridApp?.useNewDotSignInPage ?? false),
78-
newDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.NOT_STARTED,
7964
});
8065
}
8166

@@ -86,4 +71,4 @@ function prepareHybridAppAfterTransitionToNewDot(hybridApp: HybridApp) {
8671
});
8772
}
8873

89-
export {parseHybridAppSettings, setReadyToShowAuthScreens, setNewDotSignInState, resetSignInFlow, prepareHybridAppAfterTransitionToNewDot, setUseNewDotSignInPage, setClosingReactNativeApp};
74+
export {parseHybridAppSettings, setReadyToShowAuthScreens, resetSignInFlow, prepareHybridAppAfterTransitionToNewDot, setUseNewDotSignInPage, setClosingReactNativeApp};

src/pages/ValidateLoginPage/index.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import React, {useEffect} from 'react';
22
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
33
import useOnyx from '@hooks/useOnyx';
44
import Navigation from '@libs/Navigation/Navigation';
5-
import {setNewDotSignInState} from '@userActions/HybridApp';
6-
import {handleExitToNavigation, signInWithValidateCodeAndNavigate} from '@userActions/Session';
7-
import CONFIG from '@src/CONFIG';
5+
import * as Session from '@userActions/Session';
86
import CONST from '@src/CONST';
97
import ONYXKEYS from '@src/ONYXKEYS';
108
import type ValidateLoginPageProps from './types';
@@ -14,7 +12,7 @@ function ValidateLoginPage({
1412
params: {accountID, validateCode, exitTo},
1513
},
1614
}: ValidateLoginPageProps) {
17-
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true});
15+
const [session] = useOnyx(ONYXKEYS.SESSION);
1816

1917
useEffect(() => {
2018
// Wait till navigation becomes available
@@ -23,17 +21,12 @@ function ValidateLoginPage({
2321
// If already signed in, do not show the validate code if not on web,
2422
// because we don't want to block the user with the interstitial page.
2523
if (exitTo) {
26-
handleExitToNavigation(exitTo);
24+
Session.handleExitToNavigation(exitTo);
2725
return;
2826
}
2927
Navigation.goBack();
3028
} else {
31-
// On HybridApp we need to orchestrate the sign-in flow of both apps so we need to set the state to STARTED here
32-
if (CONFIG.IS_HYBRID_APP) {
33-
setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED);
34-
}
35-
36-
signInWithValidateCodeAndNavigate(Number(accountID), validateCode, '', exitTo);
29+
Session.signInWithValidateCodeAndNavigate(Number(accountID), validateCode, '', exitTo);
3730
}
3831
});
3932
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps

src/pages/signin/SAMLSignInPage/index.native.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,19 @@ import SAMLLoadingIndicator from '@components/SAMLLoadingIndicator';
77
import ScreenWrapper from '@components/ScreenWrapper';
88
import useLocalize from '@hooks/useLocalize';
99
import useOnyx from '@hooks/useOnyx';
10-
import {setNewDotSignInState} from '@libs/actions/HybridApp';
1110
import getPlatform from '@libs/getPlatform';
1211
import getUAForWebView from '@libs/getUAForWebView';
1312
import Log from '@libs/Log';
1413
import {handleSAMLLoginError, postSAMLLogin} from '@libs/LoginUtils';
1514
import Navigation from '@libs/Navigation/Navigation';
1615
import {clearSignInData, setAccountError, signInWithShortLivedAuthToken} from '@userActions/Session';
1716
import CONFIG from '@src/CONFIG';
18-
import CONST from '@src/CONST';
1917
import ONYXKEYS from '@src/ONYXKEYS';
2018
import ROUTES from '@src/ROUTES';
2119

2220
function SAMLSignInPage() {
23-
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false});
24-
const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS, {canBeMissing: true});
21+
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
22+
const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS);
2523
const [showNavigation, shouldShowNavigation] = useState(true);
2624
const [SAMLUrl, setSAMLUrl] = useState('');
2725
const webViewRef = useRef<WebView>(null);
@@ -71,7 +69,6 @@ function SAMLSignInPage() {
7169
if (!account?.isLoading && credentials?.login && !!shortLivedAuthToken) {
7270
Log.info('SAMLSignInPage - Successfully received shortLivedAuthToken. Signing in...');
7371
signInWithShortLivedAuthToken(shortLivedAuthToken);
74-
setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED);
7572
}
7673

7774
// If the login attempt is unsuccessful, set the error message for the account and redirect to sign in page

src/pages/signin/SignUpWelcomeForm.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import useNetwork from '@hooks/useNetwork';
77
import useOnyx from '@hooks/useOnyx';
88
import useThemeStyles from '@hooks/useThemeStyles';
99
import {getLatestErrorMessage} from '@libs/ErrorUtils';
10-
import {setNewDotSignInState, setReadyToShowAuthScreens} from '@userActions/HybridApp';
10+
import {setReadyToShowAuthScreens} from '@userActions/HybridApp';
1111
import {clearSignInData, signUpUser} from '@userActions/Session';
12-
import CONST from '@src/CONST';
1312
import ONYXKEYS from '@src/ONYXKEYS';
1413
import ChangeExpensifyLoginLink from './ChangeExpensifyLoginLink';
1514
import Terms from './Terms';
@@ -31,7 +30,6 @@ function SignUpWelcomeForm() {
3130
text={translate('welcomeSignUpForm.join')}
3231
isLoading={account?.isLoading}
3332
onPress={() => {
34-
setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED);
3533
signUpUser();
3634
setReadyToShowAuthScreens(true);
3735
}}

src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {getLatestErrorMessage} from '@libs/ErrorUtils';
2424
import {isValidRecoveryCode, isValidTwoFactorCode, isValidValidateCode} from '@libs/ValidationUtils';
2525
import ChangeExpensifyLoginLink from '@pages/signin/ChangeExpensifyLoginLink';
2626
import Terms from '@pages/signin/Terms';
27-
import {resetSignInFlow, setNewDotSignInState} from '@userActions/HybridApp';
27+
import {resetSignInFlow} from '@userActions/HybridApp';
2828
import {clearAccountMessages, isAnonymousUser as isAnonymousUserUtil, clearSignInData as sessionActionsClearSignInData, signIn, signInWithValidateCode} from '@userActions/Session';
2929
import {resendValidateCode as userActionsResendValidateCode} from '@userActions/User';
3030
import CONFIG from '@src/CONFIG';
@@ -295,7 +295,6 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco
295295

296296
const recoveryCodeOr2faCode = isUsingRecoveryCode ? recoveryCode : twoFactorAuthCode;
297297

298-
setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED);
299298
const accountID = credentials?.accountID;
300299
if (accountID) {
301300
signInWithValidateCode(accountID, validateCode, recoveryCodeOr2faCode);

0 commit comments

Comments
 (0)