Skip to content

Commit

Permalink
fix: display iou amount and currency from the last transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
koko57 committed Feb 5, 2024
1 parent 89fe932 commit 935685c
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2269,13 +2269,15 @@ function getReportPreviewMessage(
});
}

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

if (!isEmptyObject(linkedTransaction) && TransactionUtils.hasReceipt(linkedTransaction) && TransactionUtils.isReceiptBeingScanned(linkedTransaction)) {
return Localize.translateLocal('iou.receiptScanning');
}
if (!isEmptyObject(linkedTransaction) && TransactionUtils.hasReceipt(linkedTransaction) && TransactionUtils.isReceiptBeingScanned(linkedTransaction)) {
return Localize.translateLocal('iou.receiptScanning');
}

const originalMessage = reportAction?.originalMessage as IOUMessage | undefined;

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

const containsNonReimbursable = hasNonReimbursableTransactions(report.reportID);

const lastActorID = reportAction?.actorAccountID;
let amount = originalMessage?.amount;
let currency = originalMessage?.currency ? originalMessage?.currency : report.currency;

if (!isEmptyObject(linkedTransaction)) {
amount = TransactionUtils.getAmount(linkedTransaction, isExpenseReport(report));
currency = TransactionUtils.getCurrency(linkedTransaction);
}

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

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

const containsNonReimbursable = hasNonReimbursableTransactions(report.reportID);

return Localize.translateLocal(containsNonReimbursable ? 'iou.payerSpentAmount' : 'iou.payerOwesAmount', {payer: payerName ?? '', amount: formattedAmount});
}

Expand Down Expand Up @@ -4590,6 +4597,7 @@ function getRoom(type: ValueOf<typeof CONST.REPORT.CHAT_TYPE>, policyID: string)
function shouldDisableWelcomeMessage(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boolean {
return isMoneyRequestReport(report) || isArchivedRoom(report) || !isChatRoom(report) || isChatThread(report) || !PolicyUtils.isPolicyAdmin(policy);
}

/**
* Checks if report action has error when smart scanning
*/
Expand Down

0 comments on commit 935685c

Please sign in to comment.