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

[$250] QAB - Negative amount briefly displayed when Pay someone #44914

Closed
1 of 6 tasks
lanitochka17 opened this issue Jul 5, 2024 · 38 comments
Closed
1 of 6 tasks

[$250] QAB - Negative amount briefly displayed when Pay someone #44914

lanitochka17 opened this issue Jul 5, 2024 · 38 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors

Comments

@lanitochka17
Copy link

lanitochka17 commented Jul 5, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 9.0.4-0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/cases/view/2990372
Issue reported by: Applause - Internal Team

Action Performed:

Precondition: user did 'Pay someone' to individual chat

  1. Click FAB
  2. Click QAB > Pay someone
  3. Input amount
  4. Click Pay elsewhere

Expected Result:

User navigated to chat with person he payed. Expense preview displays amount

Actual Result:

User navigated to chat with person he payed. Expense preview briefly displays negative amount (occasionally negative amount may stay)

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6533418_1720122986864.pay_someone.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01ee0d66d57ed7a8d9
  • Upwork Job ID: 1810894586733112761
  • Last Price Increase: 2024-08-21
Issue OwnerCurrent Issue Owner: @brunovjk
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jul 5, 2024
Copy link

melvin-bot bot commented Jul 5, 2024

Triggered auto assignment to @JmillsExpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@bernhardoj
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

Negative amount is shown on the report preview when pay someone.

What is the root cause of that problem?

The pay amount logic is, if there is a total amount from the IOU report object, then we use that amount, otherwise, we take the amount from the report preview message.

const getDisplayAmount = (): string => {
if (totalDisplaySpend) {
return CurrencyUtils.convertToDisplayString(totalDisplaySpend, iouReport?.currency);
}
if (isScanning) {
return translate('iou.receiptScanning');
}
if (hasOnlyTransactionsWithPendingRoutes) {
return translate('iou.fieldPending');
}
// If iouReport is not available, get amount from the action message (Ex: "Domain20821's Workspace owes $33.00" or "paid ₫60" or "paid -₫60 elsewhere")
let displayAmount = '';
const actionMessage = ReportActionsUtils.getReportActionText(action);
const splits = actionMessage.split(' ');
splits.forEach((split) => {
if (!/\d/.test(split)) {
return;
}
displayAmount = split;
});
return displayAmount;
};

In the OP video, we can see the amount changes from
UAH xx -> ₴ xx -> -UAH xx

The reason it shows a negative amount is that the IOU report total is 0, so it takes the amount from the report preview message which is negative. If we see some logic related to the money request amount, we take the abs amount if it's an IOU report, which we don't do here.

App/src/libs/ReportUtils.ts

Lines 2408 to 2412 in c5eafd3

// There is a possibility that if the Expense report has a negative total.
// This is because there are instances where you can get a credit back on your card,
// or you enter a negative expense to “offset” future expenses
nonReimbursableSpend = isExpenseReport(moneyRequestReport) ? nonReimbursableSpend * -1 : Math.abs(nonReimbursableSpend);
totalSpend = isExpenseReport(moneyRequestReport) ? totalSpend * -1 : Math.abs(totalSpend);

But, if we look into the onyx storage, the IOU report actually has a non-zero total, but the data isn't reflected in the report preview component. So, the report preview component holds the old data. It's the withOnyx bug where it doesn't give the most up-to-date data when there are multiple merges happening within a short span of time. It's similar to this issue where the policy data is undefined because activeWorkspaceID is initially undefined but then is updated when the nav state changes, but the policy data stays undefined.

What changes do you think we should make in order to solve the problem?

As withOnyx is officially deprecated, we can just replace it with useOnyx for the ReportPreview component which doesn't have the bug. This will make the component always stay up-to-date.

However, we still have one problem, that is the amount changing. After we replace it with useOnyx, the amount will change from
UAH xx -> ₴ xx -> -UAH xx -> UAH xx

The first amount is the optimistic amount. Then, after the send money request is completed, the send money API response returns multiple Onyx merge requests. The first request merges the IOU report data which has a total data of 0. This overwrites the optimistic total.
image

Also, notice that the statusNum is 1 which is SUBMITTED instead of 4 (REIMBURSED). This makes the isSettled state becomes false.

Because the total is 0, it will get the amount from the report preview message, but the message from the BE response uses the currency symbol (₴) instead of the currency code (UAH). (the 2nd amount shown)

image

The last few merge requests from the API response contain the correct data. (the 3rd (the correct message) and then 4th (the correct iou report total) amount is shown)

This needs a BE fix.

Additionally, we can make sure the amount is never be in negative by making it absolute for IOU report,

let displayAmount = '';
const actionMessage = ReportActionsUtils.getReportActionText(action);
const splits = actionMessage.split(' ');
splits.forEach((split) => {
if (!/\d/.test(split)) {
return;
}
displayAmount = split;
});
return displayAmount;

just like we did here.

totalSpend = isExpenseReport(moneyRequestReport) ? totalSpend * -1 : Math.abs(totalSpend);

@melvin-bot melvin-bot bot added the Overdue label Jul 8, 2024
Copy link

melvin-bot bot commented Jul 8, 2024

@JmillsExpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@JmillsExpensify JmillsExpensify added the External Added to denote the issue can be worked on by a contributor label Jul 10, 2024
Copy link

melvin-bot bot commented Jul 10, 2024

Job added to Upwork: https://www.upwork.com/jobs/~01ee0d66d57ed7a8d9

@melvin-bot melvin-bot bot changed the title QAB - Negative amount briefly displayed when Pay someone [$250] QAB - Negative amount briefly displayed when Pay someone Jul 10, 2024
@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Jul 10, 2024
Copy link

melvin-bot bot commented Jul 10, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @brunovjk (External)

@melvin-bot melvin-bot bot removed the Overdue label Jul 10, 2024
@JmillsExpensify
Copy link

I'll add the external label. If the solution is straightforward we can fix it.

@brunovjk
Copy link
Contributor

@bernhardoj Thanks for the proposal. Your RCA is not clear to me yet. I replace withOnyx with useOnyx in ReportPreview and I continue with exactly the same behavior as before, which by the way is a bit different, I go from $xx to -$xx and I'll stay there. Could you please give me a more detail or share a test branch? Thank you very much.

@bernhardoj
Copy link
Contributor

Hmm, you're right. Maybe there is something happened when I tested it. I just rechecked that the problem is in Onyx.connect which doesn't give us the latest value and I haven't found a solution for that yet..

Copy link

melvin-bot bot commented Jul 16, 2024

@JmillsExpensify, @brunovjk Eep! 4 days overdue now. Issues have feelings too...

@melvin-bot melvin-bot bot added the Overdue label Jul 16, 2024
@brunovjk
Copy link
Contributor

Still waiting for proposals

@melvin-bot melvin-bot bot removed the Overdue label Jul 16, 2024
@brunovjk
Copy link
Contributor

the problem is in Onyx.connect which doesn't give us the latest value and I haven't found a solution for that yet..

Any new finds @bernhardoj ? Thank you :D

@bernhardoj
Copy link
Contributor

Not yet

Copy link

melvin-bot bot commented Jul 17, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

Copy link

melvin-bot bot commented Jul 19, 2024

@JmillsExpensify @brunovjk this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

@melvin-bot melvin-bot bot added the Overdue label Jul 19, 2024
@brunovjk
Copy link
Contributor

Not overdue, still looking for proposals

@melvin-bot melvin-bot bot removed the Overdue label Jul 19, 2024
@brunovjk
Copy link
Contributor

Copy link

melvin-bot bot commented Jul 31, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@brunovjk
Copy link
Contributor

Bumped on Slack for proposals

Copy link

melvin-bot bot commented Aug 2, 2024

@JmillsExpensify @brunovjk this issue is now 4 weeks old, please consider:

  • Finding a contributor to fix the bug
  • Closing the issue if BZ has been unable to add the issue to a VIP or Wave project
  • If you have any questions, don't hesitate to start a discussion in #expensify-open-source

Thanks!

@melvin-bot melvin-bot bot added the Overdue label Aug 2, 2024
@mvtglobally
Copy link

Issue not reproducible during KI retests. (First week)

@melvin-bot melvin-bot bot removed the Overdue label Aug 4, 2024
Copy link

melvin-bot bot commented Aug 7, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@melvin-bot melvin-bot bot added the Overdue label Aug 7, 2024
Copy link

melvin-bot bot commented Aug 7, 2024

@JmillsExpensify, @brunovjk Whoops! This issue is 2 days overdue. Let's get this updated quick!

@brunovjk
Copy link
Contributor

brunovjk commented Aug 7, 2024

@JmillsExpensify can you reproduce? Thanks

@melvin-bot melvin-bot bot removed the Overdue label Aug 7, 2024
@mvtglobally
Copy link

Issue not reproducible during KI retests. (Second week)

Copy link

melvin-bot bot commented Aug 13, 2024

@JmillsExpensify, @brunovjk Huh... This is 4 days overdue. Who can take care of this?

@melvin-bot melvin-bot bot added the Overdue label Aug 13, 2024
@brunovjk
Copy link
Contributor

@JmillsExpensify should we wait for mvtglobally to complete its weeks, or can we close the issue? We reopen if necessary.

@melvin-bot melvin-bot bot removed the Overdue label Aug 13, 2024
Copy link

melvin-bot bot commented Aug 14, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

Copy link

melvin-bot bot commented Aug 19, 2024

@JmillsExpensify, @brunovjk Eep! 4 days overdue now. Issues have feelings too...

@melvin-bot melvin-bot bot added the Overdue label Aug 19, 2024
@brunovjk

This comment was marked as outdated.

@melvin-bot melvin-bot bot removed the Overdue label Aug 20, 2024
Copy link

melvin-bot bot commented Aug 21, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@mvtglobally
Copy link

Issue not reproducible during KI retests. (Third week)

@melvin-bot melvin-bot bot added the Overdue label Aug 23, 2024
Copy link

melvin-bot bot commented Aug 23, 2024

@JmillsExpensify, @brunovjk Whoops! This issue is 2 days overdue. Let's get this updated quick!

@brunovjk
Copy link
Contributor

brunovjk commented Aug 24, 2024

I was unable to reproduce (v9.0.24-1). I believe this issue was being caused by some conflict in the server response, which is why there were times when we were able to reproduce it and others not. I didn't find anything strange about it in FE.

cc: @JmillsExpensify

@melvin-bot melvin-bot bot removed the Overdue label Aug 24, 2024
@brunovjk
Copy link
Contributor

@JmillsExpensify Do you think we can get someone else to reproduce and confirm that the issue still exists? Thank you.

@JmillsExpensify
Copy link

Let's just close. It's not reproducible for several QA runs. Thanks for reaching out via Slack!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors
Projects
None yet
Development

No branches or pull requests

5 participants