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

fix: display iou amount and currency from the last transaction #35818

Merged
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
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let currency = originalMessage?.currency ? originalMessage?.currency : report.currency;
let currency = originalMessage?.currency ? originalMessage.currency : report.currency;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we do originalMessage?.currency ?? report.currency? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, because we don't want an empty string

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup we should usually avoid optional chaining for strings. This caused so many regressions in the past


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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@koko57 Maybe it was a bad merge resolution, but I'm getting a compile error on main.

image


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
Loading