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

Remove deprecated methods from transaction utils that sideload data from Onyx #38258

Merged
merged 2 commits into from
Mar 15, 2024
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
33 changes: 29 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,31 @@ function hasMissingSmartscanFields(iouReportID: string): boolean {
return TransactionUtils.getAllReportTransactions(iouReportID).some((transaction) => TransactionUtils.hasMissingSmartscanFields(transaction));
}

/**
* Get the transactions related to a report preview with receipts
* Get the details linked to the IOU reportAction
*
* NOTE: This method is only meant to be used inside this action file. Do not export and use it elsewhere. Use withOnyx or Onyx.connect() instead.
*/
function getLinkedTransaction(reportAction: OnyxEntry<ReportAction | OptimisticIOUReportAction>): Transaction | EmptyObject {
let transactionID = '';

if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) {
transactionID = (reportAction?.originalMessage as IOUMessage)?.IOUTransactionID ?? '';
}

return allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? {};
}

/**
* Retrieve the particular transaction object given its ID.
*
* NOTE: This method is only meant to be used inside this action file. Do not export and use it elsewhere. Use withOnyx or Onyx.connect() instead.
*/
function getTransaction(transactionID: string): OnyxEntry<Transaction> | EmptyObject {
return allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? {};
}

/**
* Given a parent IOU report action get report name for the LHN.
*/
Expand All @@ -2357,7 +2382,7 @@ function getTransactionReportName(reportAction: OnyxEntry<ReportAction | Optimis
return Localize.translateLocal('parentReportAction.deletedRequest');
}

const transaction = TransactionUtils.getLinkedTransaction(reportAction);
const transaction = getLinkedTransaction(reportAction);
if (isEmptyObject(transaction)) {
// Transaction data might be empty on app's first load, if so we fallback to Request
return Localize.translateLocal('iou.request');
Expand Down Expand Up @@ -2406,7 +2431,7 @@ function getReportPreviewMessage(

if (!isEmptyObject(reportAction) && !isIOUReport(report) && reportAction && ReportActionsUtils.isSplitBillAction(reportAction)) {
// This covers group chats where the last action is a split bill action
const linkedTransaction = TransactionUtils.getLinkedTransaction(reportAction);
const linkedTransaction = getLinkedTransaction(reportAction);
if (isEmptyObject(linkedTransaction)) {
return reportActionMessage;
}
Expand Down Expand Up @@ -2442,7 +2467,7 @@ function getReportPreviewMessage(

let linkedTransaction;
if (!isEmptyObject(reportAction) && shouldConsiderScanningReceiptOrPendingRoute && reportAction && ReportActionsUtils.isMoneyRequestAction(reportAction)) {
linkedTransaction = TransactionUtils.getLinkedTransaction(reportAction);
linkedTransaction = getLinkedTransaction(reportAction);
}

if (!isEmptyObject(linkedTransaction) && TransactionUtils.hasReceipt(linkedTransaction) && TransactionUtils.isReceiptBeingScanned(linkedTransaction)) {
Expand Down Expand Up @@ -4954,7 +4979,7 @@ function getIOUReportActionDisplayMessage(reportAction: OnyxEntry<ReportAction>)
return Localize.translateLocal(translationKey, {amount: formattedAmount, payer: ''});
}

const transaction = TransactionUtils.getTransaction(originalMessage.IOUTransactionID ?? '');
const transaction = getTransaction(originalMessage.IOUTransactionID ?? '');
const transactionDetails = getTransactionDetails(!isEmptyObject(transaction) ? transaction : null);
const formattedAmount = CurrencyUtils.convertToDisplayString(transactionDetails?.amount ?? 0, transactionDetails?.currency);
const isRequestSettled = isSettled(originalMessage.IOUReportID);
Expand Down
32 changes: 1 addition & 31 deletions src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import Onyx from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {RecentWaypoint, Report, ReportAction, TaxRate, TaxRates, Transaction, TransactionViolation} from '@src/types/onyx';
import type {IOUMessage} from '@src/types/onyx/OriginalMessage';
import type {RecentWaypoint, Report, TaxRate, TaxRates, Transaction, TransactionViolation} from '@src/types/onyx';
import type {Comment, Receipt, TransactionChanges, TransactionPendingFieldsKey, Waypoint, WaypointCollection} from '@src/types/onyx/Transaction';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {isCorporateCard, isExpensifyCard} from './CardUtils';
import DateUtils from './DateUtils';
import * as NumberUtils from './NumberUtils';
import {getCleanedTagName} from './PolicyUtils';
import type {OptimisticIOUReportAction} from './ReportUtils';

let allTransactions: OnyxCollection<Transaction> = {};

Expand Down Expand Up @@ -248,15 +245,6 @@ function getUpdatedTransaction(transaction: Transaction, transactionChanges: Tra
return updatedTransaction;
}

/**
* Retrieve the particular transaction object given its ID.
*
* @deprecated Use withOnyx() or Onyx.connect() instead
*/
function getTransaction(transactionID: string): OnyxEntry<Transaction> | EmptyObject {
return allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? {};
}

/**
* Return the comment field (referred to as description in the App) from the transaction.
* The comment does not have its modifiedComment counterpart.
Expand Down Expand Up @@ -493,22 +481,6 @@ function hasRoute(transaction: OnyxEntry<Transaction>): boolean {
return !!transaction?.routes?.route0?.geometry?.coordinates;
}

/**
* Get the transactions related to a report preview with receipts
* Get the details linked to the IOU reportAction
*
* @deprecated Use Onyx.connect() or withOnyx() instead
*/
function getLinkedTransaction(reportAction: OnyxEntry<ReportAction | OptimisticIOUReportAction>): Transaction | EmptyObject {
let transactionID = '';

if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) {
transactionID = (reportAction?.originalMessage as IOUMessage)?.IOUTransactionID ?? '';
}

return allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? {};
}

function getAllReportTransactions(reportID?: string): Transaction[] {
// `reportID` from the `/CreateDistanceRequest` endpoint return's number instead of string for created `transaction`.
// For reference, https://github.com/Expensify/App/pull/26536#issuecomment-1703573277.
Expand Down Expand Up @@ -617,7 +589,6 @@ export {
calculateTaxAmount,
getEnabledTaxRateCount,
getUpdatedTransaction,
getTransaction,
getDescription,
getHeaderTitleTranslationKey,
getRequestType,
Expand All @@ -638,7 +609,6 @@ export {
getTagArrayFromName,
getTagForDisplay,
getTransactionViolations,
getLinkedTransaction,
getAllReportTransactions,
hasReceipt,
hasEReceipt,
Expand Down
Loading