Skip to content

Commit 0eb6d02

Browse files
authored
Merge pull request #35818 from koko57/refactor/34411-lhn-previews-followup-iou-amount
fix: display iou amount and currency from the last transaction
2 parents ff23077 + 935685c commit 0eb6d02

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/libs/ReportUtils.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,15 @@ function getReportPreviewMessage(
22572257
});
22582258
}
22592259

2260+
let linkedTransaction;
22602261
if (!isEmptyObject(reportAction) && shouldConsiderReceiptBeingScanned && reportAction && ReportActionsUtils.isMoneyRequestAction(reportAction)) {
2261-
const linkedTransaction = TransactionUtils.getLinkedTransaction(reportAction);
2262+
linkedTransaction = TransactionUtils.getLinkedTransaction(reportAction);
2263+
}
22622264

2263-
if (!isEmptyObject(linkedTransaction) && TransactionUtils.hasReceipt(linkedTransaction) && TransactionUtils.isReceiptBeingScanned(linkedTransaction)) {
2264-
return Localize.translateLocal('iou.receiptScanning');
2265-
}
2265+
if (!isEmptyObject(linkedTransaction) && TransactionUtils.hasReceipt(linkedTransaction) && TransactionUtils.isReceiptBeingScanned(linkedTransaction)) {
2266+
return Localize.translateLocal('iou.receiptScanning');
22662267
}
2268+
22672269
const originalMessage = reportAction?.originalMessage as IOUMessage | undefined;
22682270

22692271
// Show Paid preview message if it's settled or if the amount is paid & stuck at receivers end for only chat reports.
@@ -2290,21 +2292,26 @@ function getReportPreviewMessage(
22902292
return Localize.translateLocal('iou.waitingOnBankAccount', {submitterDisplayName});
22912293
}
22922294

2293-
const containsNonReimbursable = hasNonReimbursableTransactions(report.reportID);
2294-
22952295
const lastActorID = reportAction?.actorAccountID;
2296+
let amount = originalMessage?.amount;
2297+
let currency = originalMessage?.currency ? originalMessage?.currency : report.currency;
2298+
2299+
if (!isEmptyObject(linkedTransaction)) {
2300+
amount = TransactionUtils.getAmount(linkedTransaction, isExpenseReport(report));
2301+
currency = TransactionUtils.getCurrency(linkedTransaction);
2302+
}
22962303

22972304
// if we have the amount in the originalMessage and lastActorID, we can use that to display the preview message for the latest request
2298-
if (originalMessage?.amount !== undefined && lastActorID && !isPreviewMessageForParentChatReport) {
2299-
const amount = originalMessage?.amount;
2300-
const currency = originalMessage?.currency ?? report.currency ?? '';
2305+
if (amount !== undefined && lastActorID && !isPreviewMessageForParentChatReport) {
23012306
const amountToDisplay = CurrencyUtils.convertToDisplayString(Math.abs(amount), currency);
23022307

23032308
// We only want to show the actor name in the preview if it's not the current user who took the action
23042309
const requestorName = lastActorID && lastActorID !== currentUserAccountID ? getDisplayNameForParticipant(lastActorID, !isPreviewMessageForParentChatReport) : '';
23052310
return `${requestorName ? `${requestorName}: ` : ''}${Localize.translateLocal('iou.requestedAmount', {formattedAmount: amountToDisplay})}`;
23062311
}
23072312

2313+
const containsNonReimbursable = hasNonReimbursableTransactions(report.reportID);
2314+
23082315
return Localize.translateLocal(containsNonReimbursable ? 'iou.payerSpentAmount' : 'iou.payerOwesAmount', {payer: payerName ?? '', amount: formattedAmount});
23092316
}
23102317

@@ -4582,6 +4589,7 @@ function canEditReportDescription(report: OnyxEntry<Report>, policy: OnyxEntry<P
45824589
(getVisibleMemberIDs(report).includes(currentUserAccountID ?? 0) || getParticipantsIDs(report).includes(currentUserAccountID ?? 0))
45834590
);
45844591
}
4592+
45854593
/**
45864594
* Checks if report action has error when smart scanning
45874595
*/

0 commit comments

Comments
 (0)