Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP Staging] Revert "Fix pay someone flow for unvalidated accounts" #52469

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libs/Network/SequentialQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ function flush() {
return;
}

if (PersistedRequests.getAll().length === 0 && QueuedOnyxUpdates.isEmpty()) {
Log.info('[SequentialQueue] Unable to flush. No requests or queued Onyx updates to process.');
if (PersistedRequests.getAll().length === 0) {
Log.info('[SequentialQueue] Unable to flush. No requests to process.');
return;
}

Expand Down
33 changes: 2 additions & 31 deletions src/libs/actions/OnyxUpdateManager/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import * as ActiveClientManager from '@libs/ActiveClientManager';
import Log from '@libs/Log';
import * as NetworkStore from '@libs/Network/NetworkStore';
import * as SequentialQueue from '@libs/Network/SequentialQueue';
import * as App from '@userActions/App';
import updateSessionAuthTokens from '@userActions/Session/updateSessionAuthTokens';
import ONYXKEYS from '@src/ONYXKEYS';
import type {OnyxUpdatesFromServer, Session} from '@src/types/onyx';
import type {OnyxUpdatesFromServer} from '@src/types/onyx';
import {isValidOnyxUpdateFromServer} from '@src/types/onyx/OnyxUpdatesFromServer';
import * as OnyxUpdateManagerUtils from './utils';
import * as DeferredOnyxUpdates from './utils/DeferredOnyxUpdates';
Expand Down Expand Up @@ -92,10 +90,6 @@ function handleOnyxUpdateGap(onyxUpdatesFromServer: OnyxEntry<OnyxUpdatesFromSer
return;
}

// Check if one of these onyx updates is for the authToken. If it is, let's update our authToken now because our
// current authToken is probably invalid.
updateAuthTokenIfNecessary(onyxUpdatesFromServer);

const updateParams = onyxUpdatesFromServer;
const lastUpdateIDFromServer = onyxUpdatesFromServer.lastUpdateID;
const previousUpdateIDFromServer = onyxUpdatesFromServer.previousUpdateID;
Expand Down Expand Up @@ -150,29 +144,6 @@ function handleOnyxUpdateGap(onyxUpdatesFromServer: OnyxEntry<OnyxUpdatesFromSer
DeferredOnyxUpdates.getMissingOnyxUpdatesQueryPromise()?.finally(finalizeUpdatesAndResumeQueue);
}

function updateAuthTokenIfNecessary(onyxUpdatesFromServer: OnyxEntry<OnyxUpdatesFromServer>): void {
// Consolidate all of the given Onyx updates
const onyxUpdates: OnyxUpdate[] = [];
onyxUpdatesFromServer?.updates?.forEach((updateEvent) => onyxUpdates.push(...updateEvent.data));
onyxUpdates.push(...(onyxUpdatesFromServer?.response?.onyxData ?? []));

// Find any session updates
const sessionUpdates = onyxUpdates?.filter((onyxUpdate) => onyxUpdate.key === ONYXKEYS.SESSION);

// If any of the updates changes the authToken, let's update it now
sessionUpdates?.forEach((sessionUpdate) => {
const session = (sessionUpdate.value ?? {}) as Session;
const newAuthToken = session.authToken ?? '';
if (!newAuthToken) {
return;
}

Log.info('[OnyxUpdateManager] Found an authToken update while handling an Onyx update gap. Updating the authToken.');
updateSessionAuthTokens(newAuthToken);
NetworkStore.setAuthToken(newAuthToken);
});
}

export default () => {
console.debug('[OnyxUpdateManager] Listening for updates from the server');
Onyx.connect({
Expand Down
6 changes: 1 addition & 5 deletions src/libs/actions/QueuedOnyxUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,4 @@ function flushQueue(): Promise<void> {
});
}

function isEmpty() {
return queuedOnyxUpdates.length === 0;
}

export {queueOnyxUpdates, flushQueue, isEmpty};
export {queueOnyxUpdates, flushQueue};
12 changes: 1 addition & 11 deletions src/libs/actions/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,16 +555,6 @@ function validateLogin(accountID: number, validateCode: string) {
Onyx.merge(ONYXKEYS.ACCOUNT, {...CONST.DEFAULT_ACCOUNT_DATA, isLoading: true});

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.ACCOUNT,
value: {
isLoading: true,
},
},
];

const finallyData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.ACCOUNT,
Expand All @@ -576,7 +566,7 @@ function validateLogin(accountID: number, validateCode: string) {

const parameters: ValidateLoginParams = {accountID, validateCode};

API.write(WRITE_COMMANDS.VALIDATE_LOGIN, parameters, {optimisticData, finallyData});
API.write(WRITE_COMMANDS.VALIDATE_LOGIN, parameters, {optimisticData});
Navigation.navigate(ROUTES.HOME);
}

Expand Down
8 changes: 3 additions & 5 deletions src/pages/settings/Wallet/VerifyAccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ function VerifyAccountPage({route}: VerifyAccountPageProps) {
const loginData = loginList?.[contactMethod];
const validateLoginError = ErrorUtils.getEarliestErrorField(loginData, 'validateLogin');
const [isUserValidated] = useOnyx(ONYXKEYS.USER, {selector: (user) => !!user?.validated});
const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.accountID ?? 0});

const [isValidateCodeActionModalVisible, setIsValidateCodeActionModalVisible] = useState(true);

const navigateBackTo = route?.params?.backTo;

useEffect(() => () => User.clearUnvalidatedNewContactMethodAction(), []);

const handleSubmitForm = useCallback(
(validateCode: string) => {
User.validateLogin(accountID ?? 0, validateCode);
(submitCode: string) => {
User.validateSecondaryLogin(loginList, contactMethod ?? '', submitCode);
},
[accountID],
[loginList, contactMethod],
);

const clearError = useCallback(() => {
Expand Down
Loading