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

[$500] [Distance] - Incorrect Amount after updating distance rate #27051

Closed
6 tasks
kbecciv opened this issue Sep 8, 2023 · 22 comments
Closed
6 tasks

[$500] [Distance] - Incorrect Amount after updating distance rate #27051

kbecciv opened this issue Sep 8, 2023 · 22 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

@kbecciv
Copy link

kbecciv commented Sep 8, 2023

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


Action Performed:

  1. Go to Request money
  2. Select distance
  3. Fill start and finish points and click next
  4. In a new tab change the rate of the workspace

Expected Result:

The amount should be recalculated after updating the distance rate

Actual Result:

Incorrect Amount

Workaround:

Unknown

Platforms:

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

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.66.3
Reproducible in staging?: y
Reproducible in production?: y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation

wrong-amount.mp4
Recording.4343.mp4

Expensify/Expensify Issue URL:
Issue reported by: @hichamcc
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1693858446228419

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~013f2b0dfe92fa39b6
  • Upwork Job ID: 1700221326639685632
  • Last Price Increase: 2023-09-22
@kbecciv kbecciv added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Sep 8, 2023
@dukenv0307
Copy link
Contributor

Proposal

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

[Distance] Incorrect Amount after updating distance rate

What is the root cause of that problem?

We only calculate when the amount is 0 and the request is distance. So when we edit the waypoint again, the amount is not recalculated

const shouldCalculateDistanceAmount = props.isDistanceRequest && props.iouAmount === 0;

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

We should always calculate the amount when the distance is changed by changing the check here to

const shouldCalculateDistanceAmount = props.isDistanceRequest; 

const shouldCalculateDistanceAmount = props.isDistanceRequest && props.iouAmount === 0;

What alternative solutions did you explore? (Optional)

Whenever we edit the waypoint we will reset the amount to 0 to make it re-calculate in MoneyRequestConfirmationList

@melvin-bot melvin-bot bot changed the title [Distance] - Incorrect Amount after updating distance rate [$500] [Distance] - Incorrect Amount after updating distance rate Sep 8, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 8, 2023

Triggered auto assignment to @anmurali (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot
Copy link

melvin-bot bot commented Sep 8, 2023

Job added to Upwork: https://www.upwork.com/jobs/~013f2b0dfe92fa39b6

@melvin-bot
Copy link

melvin-bot bot commented Sep 8, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Sep 8, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 8, 2023

Triggered auto assignment to @JmillsExpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

@melvin-bot
Copy link

melvin-bot bot commented Sep 8, 2023

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

@Pujan92
Copy link
Contributor

Pujan92 commented Sep 8, 2023

Proposal

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

Updating distance rate in other tab isn't update the earlier calculated amount

What is the root cause of that problem?

Currently, we are only calculating the amount when the current iou amount is 0 which kind of gets calculated the first time only.

const shouldCalculateDistanceAmount = props.isDistanceRequest && props.iouAmount === 0;

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

We need to consider the recalculation for 2 cases

  1. when the mileage gets updated in other tab (we are rerendering the component on mileage change)
    const shouldCalculateDistanceAmount = props.isDistanceRequest && props.iouAmount === 0;
  2. When we update the waypoint by going back and come to this page again

To recalculate we need to take out the iou amount condition and keep only props.isDistanceRequest.

Note: I actually provided the solution recalculation in one of the other issue here(I am not sure whether it considers or not) regarding the waypoint but posting here again with the explanation of the mileage part too.

@DylanDylann
Copy link
Contributor

Proposal

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

Incorrect Amount after updating distance rate

What is the root cause of that problem?

const shouldCalculateDistanceAmount = props.isDistanceRequest && props.iouAmount === 0;

We only calculate the amount if the props.iouAmount === 0. So when the rate is changed, we don't re-calculate the amount

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

I think props.iouAmount === 0 condition is added to reduce the redundant computation.
In here

const shouldCalculateDistanceAmount = props.isDistanceRequest && props.iouAmount === 0;
const shouldCategoryEditable = !_.isEmpty(props.policyCategories) && !props.isDistanceRequest;
const formattedAmount = CurrencyUtils.convertToDisplayString(
shouldCalculateDistanceAmount ? DistanceRequestUtils.getDistanceRequestAmount(distance, unit, rate) : props.iouAmount,
props.isDistanceRequest ? currency : props.iouCurrencyCode,
);
useEffect(() => {
if (!shouldCalculateDistanceAmount) {
return;
}
const amount = DistanceRequestUtils.getDistanceRequestAmount(distance, unit, rate);
IOU.setMoneyRequestAmount(amount);
}, [shouldCalculateDistanceAmount, distance, rate, unit]);

we should remove the shouldCalculateDistanceAmount variable and to avoid redundant re-calculate we can create a new variable called amount in a useMemo and use it instead of calling getDistanceRequestAmount function

this is demo code change

const amount = useMemo(() => DistanceRequestUtils.getDistanceRequestAmount(distance, unit, rate), [distance, unit, rate]) 
const formattedAmount = CurrencyUtils.convertToDisplayString(
        props.isDistanceRequest ? amount : props.iouAmount,
        props.isDistanceRequest ? currency : props.iouCurrencyCode,
);

useEffect(() => {
        if (!props.isDistanceRequest) {
            return;
        }
        IOU.setMoneyRequestAmount(amount);
}, [props.isDistanceRequest, distance, rate, unit, amount]);

What alternative solutions did you explore? (Optional)

@melvin-bot melvin-bot bot added the Overdue label Sep 11, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 12, 2023

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

@Ollyws
Copy link
Contributor

Ollyws commented Sep 12, 2023

Will review proposals asap.

@melvin-bot melvin-bot bot removed the Overdue label Sep 12, 2023
@dukenv0307
Copy link
Contributor

I think this is dupe of #26946

@melvin-bot
Copy link

melvin-bot bot commented Sep 15, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Sep 18, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Sep 19, 2023

@JmillsExpensify, @Ollyws, @anmurali 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

@melvin-bot
Copy link

melvin-bot bot commented Sep 21, 2023

@JmillsExpensify, @Ollyws, @anmurali Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!

@melvin-bot
Copy link

melvin-bot bot commented Sep 22, 2023

@JmillsExpensify @Ollyws @anmurali 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
Copy link

melvin-bot bot commented Sep 22, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

@JmillsExpensify, @Ollyws, @anmurali 12 days overdue. Walking. Toward. The. Light...

@anmurali
Copy link

Closing this as a dupe of #26946

@melvin-bot melvin-bot bot removed the Overdue label Sep 26, 2023
@hichamcc
Copy link

@anmurali I reported it first

@DylanDylann
Copy link
Contributor

@anmurali @Ollyws Currently, we can'r reproduce #26946 But we still reproduce this bug. It's not a dupe, Let's re-open it

@DylanDylann
Copy link
Contributor

@anmurali Bump on this one

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

8 participants