Skip to content

Commit 5d25d69

Browse files
authored
Merge pull request #55363 from Expensify/revert-54296-war-in/enable-hybrid-app-copilot
Revert "[HybridApp] Necessary copilot changes"
2 parents 73a82fe + 87e7f01 commit 5d25d69

File tree

4 files changed

+20
-72
lines changed

4 files changed

+20
-72
lines changed

src/libs/actions/Delegate.ts

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {NativeModules} from 'react-native';
22
import Onyx from 'react-native-onyx';
3-
import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
3+
import type {OnyxUpdate} from 'react-native-onyx';
44
import * as API from '@libs/API';
55
import type {AddDelegateParams, RemoveDelegateParams, UpdateDelegateRoleParams} from '@libs/API/parameters';
66
import {SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
77
import * as ErrorUtils from '@libs/ErrorUtils';
88
import Log from '@libs/Log';
99
import * as NetworkStore from '@libs/Network/NetworkStore';
10+
import {getCurrentUserEmail} from '@libs/Network/NetworkStore';
1011
import * as SequentialQueue from '@libs/Network/SequentialQueue';
1112
import CONST from '@src/CONST';
1213
import ONYXKEYS from '@src/ONYXKEYS';
@@ -15,7 +16,6 @@ import type Credentials from '@src/types/onyx/Credentials';
1516
import type Response from '@src/types/onyx/Response';
1617
import type Session from '@src/types/onyx/Session';
1718
import {confirmReadyToOpenApp, openApp} from './App';
18-
import {getCurrentUserAccountID} from './Report';
1919
import updateSessionAuthTokens from './Session/updateSessionAuthTokens';
2020
import updateSessionUser from './Session/updateSessionUser';
2121

@@ -51,14 +51,6 @@ Onyx.connect({
5151
callback: (value) => (stashedSession = value ?? {}),
5252
});
5353

54-
let activePolicyID: OnyxEntry<string>;
55-
Onyx.connect({
56-
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
57-
callback: (newActivePolicyID) => {
58-
activePolicyID = newActivePolicyID;
59-
},
60-
});
61-
6254
const KEYS_TO_PRESERVE_DELEGATE_ACCESS = [
6355
ONYXKEYS.NVP_TRY_FOCUS_MODE,
6456
ONYXKEYS.PREFERRED_THEME,
@@ -81,8 +73,6 @@ function connect(email: string) {
8173
Onyx.set(ONYXKEYS.STASHED_CREDENTIALS, credentials);
8274
Onyx.set(ONYXKEYS.STASHED_SESSION, session);
8375

84-
const previousAccountID = getCurrentUserAccountID();
85-
8676
const optimisticData: OnyxUpdate[] = [
8777
{
8878
onyxMethod: Onyx.METHOD.MERGE,
@@ -140,14 +130,6 @@ function connect(email: string) {
140130
Onyx.update(failureData);
141131
return;
142132
}
143-
if (!activePolicyID) {
144-
Log.alert('[Delegate] Unable to access activePolicyID');
145-
Onyx.update(failureData);
146-
return;
147-
}
148-
const restrictedToken = response.restrictedToken;
149-
const policyID = activePolicyID;
150-
151133
return SequentialQueue.waitForIdle()
152134
.then(() => Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS))
153135
.then(() => {
@@ -156,7 +138,9 @@ function connect(email: string) {
156138

157139
NetworkStore.setAuthToken(response?.restrictedToken ?? null);
158140
confirmReadyToOpenApp();
159-
openApp().then(() => NativeModules.HybridAppModule.switchAccount(email, restrictedToken, policyID, String(previousAccountID)));
141+
openApp();
142+
143+
NativeModules.HybridAppModule.switchAccount(email);
160144
});
161145
})
162146
.catch((error) => {
@@ -211,34 +195,22 @@ function disconnect() {
211195
return;
212196
}
213197

214-
if (!response?.requesterID || !response?.requesterEmail) {
215-
Log.alert('[Delegate] No requester data returned while disconnecting as a delegate');
216-
return;
217-
}
218-
219-
const requesterEmail = response.requesterEmail;
220-
const authToken = response.authToken;
221198
return SequentialQueue.waitForIdle()
222199
.then(() => Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS))
223200
.then(() => {
224-
Onyx.set(ONYXKEYS.CREDENTIALS, {
225-
...stashedCredentials,
226-
accountID: response.requesterID,
227-
});
228-
Onyx.set(ONYXKEYS.SESSION, {
229-
...stashedSession,
230-
accountID: response.requesterID,
231-
email: requesterEmail,
232-
authToken,
233-
encryptedAuthToken: response.encryptedAuthToken,
234-
});
235-
Onyx.set(ONYXKEYS.STASHED_CREDENTIALS, {});
236-
Onyx.set(ONYXKEYS.STASHED_SESSION, {});
201+
// Update authToken in Onyx and in our local variables so that API requests will use the new authToken
202+
updateSessionAuthTokens(response?.authToken, response?.encryptedAuthToken);
237203

238204
NetworkStore.setAuthToken(response?.authToken ?? null);
239205

206+
Onyx.set(ONYXKEYS.CREDENTIALS, stashedCredentials);
207+
Onyx.set(ONYXKEYS.SESSION, stashedSession);
208+
Onyx.set(ONYXKEYS.STASHED_CREDENTIALS, {});
209+
Onyx.set(ONYXKEYS.STASHED_SESSION, {});
240210
confirmReadyToOpenApp();
241-
openApp().then(() => NativeModules.HybridAppModule.switchAccount(requesterEmail, authToken, '', ''));
211+
openApp();
212+
213+
NativeModules.HybridAppModule.switchAccount(getCurrentUserEmail() ?? '');
242214
});
243215
})
244216
.catch((error) => {

src/libs/actions/Session/index.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import Navigation from '@libs/Navigation/Navigation';
3333
import navigationRef from '@libs/Navigation/navigationRef';
3434
import * as MainQueue from '@libs/Network/MainQueue';
3535
import * as NetworkStore from '@libs/Network/NetworkStore';
36-
import {getCurrentUserEmail} from '@libs/Network/NetworkStore';
3736
import NetworkConnection from '@libs/NetworkConnection';
3837
import * as Pusher from '@libs/Pusher/pusher';
3938
import {getReportIDFromLink, parseReportRouteParams as parseReportRouteParamsReportUtils} from '@libs/ReportUtils';
@@ -525,7 +524,7 @@ function signInAfterTransitionFromOldDot(transitionURL: string) {
525524
nudgeMigrationTimestamp,
526525
isSingleNewDotEntry,
527526
primaryLogin,
528-
oldDotOriginalAccountEmail,
527+
shouldRemoveDelegatedAccess,
529528
} = Object.fromEntries(
530529
queryParams.split('&').map((param) => {
531530
const [key, value] = param.split('=');
@@ -544,39 +543,22 @@ function signInAfterTransitionFromOldDot(transitionURL: string) {
544543
const setSessionDataAndOpenApp = new Promise<Route>((resolve) => {
545544
clearOnyxForNewAccount()
546545
.then(() => {
547-
// This section controls copilot changes
548-
const currentUserEmail = getCurrentUserEmail();
549-
550-
// If ND and OD account are the same - do nothing
551-
if (email === currentUserEmail) {
552-
return;
553-
}
554-
555-
// If account was changed to original one on OD side - clear onyx
556-
if (!oldDotOriginalAccountEmail) {
557-
return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS);
558-
}
559-
560-
// If we're already logged in - do nothing, data will be set in next step
561-
if (currentUserEmail) {
546+
if (!shouldRemoveDelegatedAccess) {
562547
return;
563548
}
564-
565-
// If we're not logged in - set stashed data
566-
return Onyx.multiSet({
567-
[ONYXKEYS.STASHED_CREDENTIALS]: {autoGeneratedLogin, autoGeneratedPassword},
568-
});
549+
return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS);
569550
})
570551
.then(() =>
571552
Onyx.multiSet({
572553
[ONYXKEYS.SESSION]: {email, authToken, encryptedAuthToken: decodeURIComponent(encryptedAuthToken), accountID: Number(accountID)},
554+
[ONYXKEYS.ACCOUNT]: {primaryLogin},
573555
[ONYXKEYS.CREDENTIALS]: {autoGeneratedLogin, autoGeneratedPassword},
574556
[ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY]: isSingleNewDotEntry === 'true',
575557
[ONYXKEYS.NVP_TRYNEWDOT]: {
576558
classicRedirect: {completedHybridAppOnboarding: completedHybridAppOnboarding === 'true'},
577559
nudgeMigration: nudgeMigrationTimestamp ? {timestamp: new Date(nudgeMigrationTimestamp)} : undefined,
578560
},
579-
}).then(() => Onyx.merge(ONYXKEYS.ACCOUNT, {primaryLogin})),
561+
}),
580562
)
581563
.then(() => {
582564
if (clearOnyxOnStart === 'true') {

src/types/modules/react-native.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type StartupTimer from '@libs/StartupTimer/types';
88
type HybridAppModule = {
99
closeReactNativeApp: (shouldSignOut: boolean, shouldSetNVP: boolean) => void;
1010
completeOnboarding: (status: boolean) => void;
11-
switchAccount: (newDotCurrentAccount: string, authToken: string, policyID: string, accountID: string) => void;
11+
switchAccount: (newDotCurrentAccount: string) => void;
1212
exitApp: () => void;
1313
};
1414

src/types/onyx/Response.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ type Response = {
8383

8484
/** If there is newer data to load for pagination commands */
8585
hasNewerActions?: boolean;
86-
87-
/** The email of the original user (returned when in delegate mode) */
88-
requesterEmail?: string;
89-
90-
/** The ID of the original user (returned when in delegate mode) */
91-
requesterID?: number;
9286
};
9387

9488
export default Response;

0 commit comments

Comments
 (0)