Skip to content
Merged
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
2 changes: 0 additions & 2 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1658,8 +1658,6 @@ const CONST = {
APPLY_AIRSHIP_UPDATES: 'apply_airship_updates',
APPLY_PUSHER_UPDATES: 'apply_pusher_updates',
APPLY_HTTPS_UPDATES: 'apply_https_updates',
COMPUTE_REPORT_NAME: 'compute_report_name',
COMPUTE_REPORT_NAME_FOR_NEW_REPORT: 'compute_report_name_for_new_report',
COLD: 'cold',
WARM: 'warm',
REPORT_ACTION_ITEM_LAYOUT_DEBOUNCE_TIME: 1500,
Expand Down
36 changes: 4 additions & 32 deletions src/libs/API/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {handleDeletedAccount, HandleUnusedOptimisticID, Logging, Pagination, Rea
import FraudMonitoring from '@libs/Middleware/FraudMonitoring';
import {isOffline} from '@libs/Network/NetworkStore';
import {push as pushToSequentialQueue, waitForIdle as waitForSequentialQueueIdle} from '@libs/Network/SequentialQueue';
import * as OptimisticReportNames from '@libs/OptimisticReportNames';
import {getUpdateContext, initialize as initializeOptimisticReportNamesContext} from '@libs/OptimisticReportNamesConnectionManager';
import Pusher from '@libs/Pusher';
import {addMiddleware, processWithMiddleware} from '@libs/Request';
import {getAll, getLength as getPersistedRequestsLength} from '@userActions/PersistedRequests';
Expand All @@ -18,7 +16,7 @@ import type OnyxRequest from '@src/types/onyx/Request';
import type {PaginatedRequest, PaginationConfig, RequestConflictResolver} from '@src/types/onyx/Request';
import type Response from '@src/types/onyx/Response';
import type {ApiCommand, ApiRequestCommandParameters, ApiRequestType, CommandOfType, ReadCommand, SideEffectRequestCommand, WriteCommand} from './types';
import {READ_COMMANDS, WRITE_COMMANDS} from './types';
import {READ_COMMANDS} from './types';

// Setup API middlewares. Each request made will pass through a series of middleware functions that will get called in sequence (each one passing the result of the previous to the next).
// Note: The ordering here is intentional as we want to Log, Recheck Connection, Reauthenticate, and Save the Response in Onyx. Errors thrown in one middleware will bubble to the next.
Expand Down Expand Up @@ -51,11 +49,6 @@ addMiddleware(SaveResponseInOnyx);
// FraudMonitoring - Tags the request with the appropriate Fraud Protection event.
addMiddleware(FraudMonitoring);

// Initialize OptimisticReportNames context on module load
initializeOptimisticReportNamesContext().catch(() => {
Log.warn('Failed to initialize OptimisticReportNames context');
});

let requestIndex = 0;

type OnyxData = {
Expand Down Expand Up @@ -87,30 +80,9 @@ function prepareRequest<TCommand extends ApiCommand>(

const {optimisticData, successData, failureData, ...onyxDataWithoutOptimisticData} = onyxData;

let processedSuccessData = successData;
let processedFailureData = failureData;

if (optimisticData && shouldApplyOptimisticData) {
Log.info('[API] Applying optimistic data', false, {command, type});

// Process optimistic data through report name middleware
// Skip for OpenReport command to avoid unnecessary processing
if (command === WRITE_COMMANDS.OPEN_REPORT) {
Onyx.update(optimisticData);
} else {
try {
const context = getUpdateContext();
const processedData = OptimisticReportNames.updateOptimisticReportNamesFromUpdates(optimisticData, context, successData, failureData);

Onyx.update(processedData.optimisticData);
processedSuccessData = processedData.successData;
processedFailureData = processedData.failureData;
} catch (error) {
Log.hmmm('[API] Failed to process optimistic report names', {error});
// Fallback to original optimistic data if processing fails
Onyx.update(optimisticData);
}
}
Onyx.update(optimisticData);
}

const isWriteRequest = type === CONST.API_REQUEST_TYPE.WRITE;
Expand All @@ -137,8 +109,8 @@ function prepareRequest<TCommand extends ApiCommand>(
initiatedOffline: isOffline(),
requestID: requestIndex++,
...onyxDataWithoutOptimisticData,
successData: processedSuccessData,
failureData: processedFailureData,
successData,
failureData,
...conflictResolver,
};

Expand Down
38 changes: 2 additions & 36 deletions src/libs/Formula.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,40 +198,6 @@ function parsePart(definition: string): FormulaPart {
return part;
}

/**
* Check if a formula requires backend computation (e.g., currency conversion with exchange rates)
* This is used by OptimisticReportNames to skip optimistic updates when online and backend is needed
*/
function requiresBackendComputation(parts: FormulaPart[], context?: FormulaContext): boolean {
if (!context) {
return false;
}

const {report} = context;

for (const part of parts) {
if (part.type === FORMULA_PART_TYPES.REPORT) {
const [field, ...additionalPath] = part.fieldPath;
// Reconstruct format string by joining additional path elements with ':'
// This handles format strings with colons like 'HH:mm:ss'
const format = additionalPath.length > 0 ? additionalPath.join(':') : undefined;
const fieldName = field?.toLowerCase();

if (fieldName === 'total' || fieldName === 'reimbursable') {
// Use formatAmount to check whether a currency conversion is needed.
// A null return means the backend must handle the conversion.
// We rely on report.total because zero values can be computed optimistically.
const result = formatAmount(report.total, report.currency, format);
if (result === null) {
return true;
}
}
}
}

return false;
}

/**
* Check if the report field formula value is containing circular references, e.g example: A -> A, A->B->A, A->B->C->A, etc
*/
Expand Down Expand Up @@ -942,6 +908,6 @@ function computePersonalDetailsField(path: string[], personalDetails: PersonalDe
}
}

export {FORMULA_PART_TYPES, compute, extract, getAutoReportingDates, parse, hasCircularReferences, requiresBackendComputation};
export {FORMULA_PART_TYPES, compute, parse, hasCircularReferences};

export type {FormulaContext, FormulaPart, FieldList};
export type {FormulaContext, FieldList};
Loading
Loading