Skip to content

Commit

Permalink
only display pending message for foreign currency transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
dukenv0307 committed Jan 15, 2024
1 parent 3b548b4 commit 43c38ba
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function MoneyRequestAction({
const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(action);
const isReversedTransaction = ReportActionsUtils.isReversedTransaction(action);
if (!_.isEmpty(iouReport) && !_.isEmpty(reportActions) && chatReport.iouReportID && action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD && network.isOffline) {
shouldShowPendingConversionMessage = IOUUtils.isIOUReportPendingCurrencyConversion(iouReport);
shouldShowPendingConversionMessage = IOUUtils.isTransactionPendingCurrencyConversion(iouReport, (action && action.originalMessage && action.originalMessage.IOUTransactionID) || 0);
}

return isDeletedParentAction || isReversedTransaction ? (
Expand Down
10 changes: 6 additions & 4 deletions src/libs/IOUUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ function updateIOUOwnerAndTotal(iouReport: OnyxEntry<Report>, actorAccountID: nu
}

/**
* Returns whether or not an IOU report contains money requests in a different currency
* Returns whether or not a transaction of IOU report contains money requests in a different currency
* that are either created or cancelled offline, and thus haven't been converted to the report's currency yet
*/
function isIOUReportPendingCurrencyConversion(iouReport: Report): boolean {
function isTransactionPendingCurrencyConversion(iouReport: Report, transactionID: string): boolean {
const reportTransactions: Transaction[] = TransactionUtils.getAllReportTransactions(iouReport.reportID);
const pendingRequestsInDifferentCurrency = reportTransactions.filter((transaction) => transaction.pendingAction && TransactionUtils.getCurrency(transaction) !== iouReport.currency);
const pendingRequestsInDifferentCurrency = reportTransactions.filter(
(transaction) => transaction.pendingAction && transaction.transactionID === transactionID && TransactionUtils.getCurrency(transaction) !== iouReport.currency,
);
return pendingRequestsInDifferentCurrency.length > 0;
}

Expand All @@ -127,4 +129,4 @@ function isValidMoneyRequestType(iouType: string): boolean {
return moneyRequestType.includes(iouType);
}

export {calculateAmount, updateIOUOwnerAndTotal, isIOUReportPendingCurrencyConversion, isValidMoneyRequestType, navigateToStartMoneyRequestStep, navigateToStartStepIfScanFileCannotBeRead};
export {calculateAmount, updateIOUOwnerAndTotal, isTransactionPendingCurrencyConversion, isValidMoneyRequestType, navigateToStartMoneyRequestStep, navigateToStartStepIfScanFileCannotBeRead};
6 changes: 3 additions & 3 deletions tests/unit/IOUUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function initCurrencyList() {
}

describe('IOUUtils', () => {
describe('isIOUReportPendingCurrencyConversion', () => {
describe('isTransactionPendingCurrencyConversion', () => {
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
Expand All @@ -34,7 +34,7 @@ describe('IOUUtils', () => {
[`${ONYXKEYS.COLLECTION.TRANSACTION}${aedPendingTransaction.transactionID}`]: aedPendingTransaction,
}).then(() => {
// We requested money offline in a different currency, we don't know the total of the iouReport until we're back online
expect(IOUUtils.isIOUReportPendingCurrencyConversion(iouReport)).toBe(true);
expect(IOUUtils.isTransactionPendingCurrencyConversion(iouReport, aedPendingTransaction.transactionID)).toBe(true);
});
});

Expand All @@ -54,7 +54,7 @@ describe('IOUUtils', () => {
},
}).then(() => {
// We requested money online in a different currency, we know the iouReport total and there's no need to show the pending conversion message
expect(IOUUtils.isIOUReportPendingCurrencyConversion(iouReport)).toBe(false);
expect(IOUUtils.isTransactionPendingCurrencyConversion(iouReport, aedPendingTransaction.transactionID)).toBe(false);
});
});
});
Expand Down

0 comments on commit 43c38ba

Please sign in to comment.