@@ -9,6 +9,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
99
1010import HybridAppModule from '@expensify/react-native-hybrid-app' ;
1111import Onyx from 'react-native-onyx' ;
12+ import OnyxUtils from 'react-native-onyx/dist/OnyxUtils' ;
1213
1314import { resetSignInFlow } from './HybridApp' ;
1415
@@ -18,7 +19,6 @@ let currentSessionAuthToken: string | undefined;
1819let currentSessionEmail : string | undefined ;
1920let currentSessionAccountID : number | undefined ;
2021let currentCredentialsValidateCode : string | undefined ;
21- let hasGpsTripInProgress = false ;
2222
2323Onyx . connectWithoutView ( {
2424 key : ONYXKEYS . NETWORK ,
@@ -43,23 +43,14 @@ Onyx.connectWithoutView({
4343 } ,
4444} ) ;
4545
46- // The list of keys to preserve has to be ready before `Onyx.clear` runs below, and reading the draft
47- // from Onyx at that point would delay the clear, so the value is kept here instead of being read on demand.
48- Onyx . connectWithoutView ( {
49- key : ONYXKEYS . GPS_DRAFT_DETAILS ,
50- callback : ( value ) => {
51- hasGpsTripInProgress = ! ! value ?. isTracking ;
52- } ,
53- } ) ;
54-
5546Onyx . connectWithoutView ( {
5647 key : ONYXKEYS . CREDENTIALS ,
5748 callback : ( credentials ) => {
5849 currentCredentialsValidateCode = credentials ?. validateCode ;
5950 } ,
6051} ) ;
6152
62- function clearStorageAndRedirect ( errorMessage ?: string , isSAMLReauthentication ?: boolean ) : Promise < void > {
53+ async function clearStorageAndRedirect ( errorMessage ?: string , isSAMLReauthentication ?: boolean ) : Promise < void > {
6354 // Under certain conditions, there are key-values we'd like to keep in storage even when a user is logged out.
6455 // We pass these into the clear() method in order to avoid having to reset them on a delayed tick and getting
6556 // flashes of unwanted default state.
@@ -106,7 +97,8 @@ function clearStorageAndRedirect(errorMessage?: string, isSAMLReauthentication?:
10697
10798 // A forced re-auth is involuntary, so an in-progress trip is kept and offered back on return.
10899 // Only keep a trip we can record an owner for, so it is never resumed by whoever signs in next.
109- if ( hasGpsTripInProgress && currentSessionAccountID ) {
100+ const gpsTrip = await OnyxUtils . get ( ONYXKEYS . GPS_DRAFT_DETAILS ) ;
101+ if ( gpsTrip ?. isTracking && currentSessionAccountID ) {
110102 Onyx . merge ( ONYXKEYS . GPS_DRAFT_DETAILS , { accountID : currentSessionAccountID } ) ;
111103 keysToPreserve . push ( ONYXKEYS . GPS_DRAFT_DETAILS ) ;
112104 }
0 commit comments