Skip to content

Commit

Permalink
Remove deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tgolen committed Mar 13, 2024
1 parent 34930fe commit 723b050
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 36 deletions.
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1917,4 +1917,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: a431c146e1501391834a2f299a74093bac53b530

COCOAPODS: 1.13.0
COCOAPODS: 1.12.1
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

0 comments on commit 723b050

Please sign in to comment.