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

[HOLD for payment 2024-01-17] [HOLD for payment 2024-01-11] [$500] Android- IOU-When user changes Stop address, the Request money amount is not updated #26946

Closed
1 of 6 tasks
izarutskaya opened this issue Sep 7, 2023 · 82 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@izarutskaya
Copy link

izarutskaya commented Sep 7, 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. Launch app
  2. Tap profile icon
  3. Tap Workspaces
  4. Tap any Workspace
  5. Tap Reimbursements
  6. Tap Track distance
  7. Enter Rate and Unit
  8. Tap Save
  9. Navigate back to LHN
  10. Tap Fab
  11. Tap request money
  12. Tap distance
  13. Tap Start and select an address
  14. Tap Finish and select an address
  15. Tap Add stop
  16. Tap Finish and select an address
  17. Tap next
  18. Select a workspace
  19. Note the distance details and request money amount is correct (15.39*2=₹30.78) i. e shown as ₹30.77
  20. Tap back to distance money request page
  21. Tap Stop
  22. Replace the entered address with a new one
  23. Tap next
  24. Select a Workspace
  25. Note the distance field and request money amount (9.68*2=₹19.36)

Expected Result:

When user changes Stop address, the Request money amount should be updated based on new distance.

Actual Result:

When user changes Stop address, the Request money amount is not updated. The distance amount(15.39*2=₹30.78) before changing address is shown even after changing the address.

For new distance when address changed (9.68*2=₹19.36) , but still old amount ₹30.77 is displayed.

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.65-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:

Email or phone of affected tester (no customers):

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos: Any additional supporting documentation

Bug6191115_km.mp4

Expensify/Expensify Issue URL:

Issue reported by: Applause-Internal Team / @ashimsharma10

Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1693984012665899

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01f82f14ed7e096782
  • Upwork Job ID: 1700194911206653952
  • Last Price Increase: 2023-09-15
  • Automatic offers:
    • cubuspl42 | Reviewer | 28066262
    • DylanDylann | Contributor | 28066263
Issue OwnerCurrent Issue Owner: @CortneyOfstad
@izarutskaya izarutskaya added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Sep 7, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 7, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Sep 7, 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

@dukenv0307
Copy link
Contributor

Proposal

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

distance - Amount isn't recalculated on changing waypoints

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

@CortneyOfstad CortneyOfstad added the External Added to denote the issue can be worked on by a contributor label Sep 8, 2023
@melvin-bot melvin-bot bot changed the title Android- IOU-When user changes Stop address, the Request money amount is not updated [$500] Android- IOU-When user changes Stop address, the Request money amount is not updated Sep 8, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 8, 2023

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

@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

Current assignee @CortneyOfstad is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented Sep 8, 2023

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

@ashimsharma10
Copy link

@jeet-dhandha
Copy link
Contributor

Proposal

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

  • Amount is not recalculated when the distance is changed.

What is the root cause of that problem?

  • The shouldCalculateDistanceAmount flag is not set to true when the distance is changed. due to the props.iouAmount === 0 condition.

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

  • We can simply remove the shouldCalculateDistanceAmount flag and replace it with props.isDistanceRequest.

  • Keeping the shouldCalculateDistanceAmount flag doesn't make sense anymore since we are always calculating the amount when its a distance request.

  • This will solve two problems:

    • The amount will be recalculated when the distance is changed.
    • The amount will be recalculated when the rate is changed.

What alternative solutions did you explore? (Optional)

  • N/A

@ahmedGaber93
Copy link
Contributor

Proposal

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

distance - Amount isn't recalulated on changing waypoints

What is the root cause of that problem?

In the code below, the shouldCalculateDistanceAmount is true only when props.iouAmount === 0
this is good when we calculate the amount for the first time in const formattedAmount =
But when we re-calculate the amount in the useEffect we stop re-calculate by it, because shouldCalculateDistanceAmount is true only on the first time.

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]);

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

  1. keep props.iouAmount === 0 in shouldCalculateDistanceAmount condition, I think it intended because it is good to only calculate amount once here, then use props.iouAmount which calculated by the useEffect (will fix in step 2).

const formattedAmount = CurrencyUtils.convertToDisplayString(
shouldCalculateDistanceAmount ? DistanceRequestUtils.getDistanceRequestAmount(distance, unit, rate) : props.iouAmount,
props.isDistanceRequest ? currency : props.iouCurrencyCode,
);

  1. replace the condition and deps in the useEffect to re-calculate the amount when any of its deps change, and the updated amount will pass to formattedAmount in props.iouAmount
useEffect(() => {
    // if (!shouldCalculateDistanceAmount) {
    if (!props.isDistanceRequest) {
         return;
    }

    const amount = DistanceRequestUtils.getDistanceRequestAmount(distance, unit, rate);
    IOU.setMoneyRequestAmount(amount);
}, [props.isDistanceRequest, distance, rate, unit]);

What alternative solutions did you explore? (Optional)

N/A

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

melvin-bot bot commented Sep 11, 2023

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

1 similar comment
@melvin-bot
Copy link

melvin-bot bot commented Sep 11, 2023

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

@cubuspl42
Copy link
Contributor

@dukenv0307 @jeet-dhandha @ahmedGaber93

Did you explore an alternative involving using useMemo (to calculate the amount) in tandem with useEffect (to call setMoneyRequestAmount), re-solving this problem cleanly? Is there some catch with that?

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

@cubuspl42 I think we should use a useEffect here because we only need to update amount if this is a distance request.

@cubuspl42
Copy link
Contributor

@ahmedGaber93

keep props.iouAmount === 0 in shouldCalculateDistanceAmount condition, I think it intended

This is a good point, I asked here

@dukenv0307
Copy link
Contributor

@cubuspl42 If we keep props.iouAmount === 0 in shouldCalculateDistanceAmount, the formattedAmount that is used to display in the UI will not be updated when the distance is changed.

const formattedAmount = CurrencyUtils.convertToDisplayString(
shouldCalculateDistanceAmount ? DistanceRequestUtils.getDistanceRequestAmount(distance, unit, rate) : props.iouAmount,
props.isDistanceRequest ? currency : props.iouCurrencyCode,

@ahmedGaber93
Copy link
Contributor

If we keep props.iouAmount === 0 in shouldCalculateDistanceAmount, the formattedAmount that is used to display in the UI will not be updated when the distance is changed.

No, it will work fine after update useEffect to

useEffect(() => {
    // if (!shouldCalculateDistanceAmount) {
    if (!props.isDistanceRequest) {
         return;
    }

    const amount = DistanceRequestUtils.getDistanceRequestAmount(distance, unit, rate);
    IOU.setMoneyRequestAmount(amount);
}, [props.isDistanceRequest, distance, rate, unit]);

The useEffect will call IOU.setMoneyRequestAmount(amount) which change the props.iouAmount that will update the formattedAmount without recalculating it because shouldCalculateDistanceAmount now is false and will use props.iouAmount that updated by use effect

shouldCalculateDistanceAmount ? DistanceRequestUtils.getDistanceRequestAmount(distance, unit, rate) : props.iouAmount,

This is a good point, I asked here

I remember I read before the amount can be editable manually by user in MoneyRequestConfirmationList.js, but we temporarily disable this feature.
So I think shouldCalculateDistanceAmount with props.iouAmount === 0 maybe added for that, to prevent reset the amount by recalculating it after manually edit it and use props.iouAmount.

Let us wait the answer here.

@DylanDylann

This comment was marked as outdated.

@cubuspl42
Copy link
Contributor

cubuspl42 commented Sep 12, 2023

Hey everyone, we've got a response from the original author of the PR. It seems that @ahmedGaber93 had good intuition here.

I marked with 👎 proposals which seem not to match the expectations here.

@ahmedGaber93
Copy link
Contributor

ahmedGaber93 commented Sep 13, 2023

@cubuspl42 what do you think of using Onyx store to save this value? are this option available?

// IOU.js > add new function to set the value.
function setIsDistanceAmountOverridden(isDistanceAmountOverridden) {
    Onyx.merge(ONYXKEYS.IOU, {isDistanceAmountOverridden});
}

// IOU.js > edit this function and add isDistanceAmountOverridden rest value.
function resetMoneyRequestInfo(id = '') {
    const created = currentDate || moment().format('YYYY-MM-DD');
    Onyx.merge(ONYXKEYS.IOU, {
        ...
        isDistanceAmountOverridden: false,
    });
}


// in NewRequestAmountPage.js > navigateToNextPage
if(isDistanceRequestTab) {
    IOU.setIsDistanceAmountOverridden(true);
}

// in MoneyRequestConfirmPage.js
<MoneyRequestConfirmationList
    ...
    isDistanceAmountOverridden={props.iou.isDistanceAmountOverridden}


// in MoneyRequestConfirmationList.js > shouldCalculateDistanceAmount
const shouldCalculateDistanceAmount = props.isDistanceRequest && !props.isDistanceAmountOverridden;
result
Screen.Recording.2023-09-13.at.8.29.47.PM.mov

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Weekly KSv2 labels Jan 8, 2024
@melvin-bot melvin-bot bot changed the title [HOLD for payment 2024-01-11] [$500] Android- IOU-When user changes Stop address, the Request money amount is not updated [HOLD for payment 2024-01-17] [HOLD for payment 2024-01-11] [$500] Android- IOU-When user changes Stop address, the Request money amount is not updated Jan 10, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Jan 10, 2024
Copy link

melvin-bot bot commented Jan 10, 2024

Reviewing label has been removed, please complete the "BugZero Checklist".

Copy link

melvin-bot bot commented Jan 10, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.23-4 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-01-17. 🎊

  • @cubuspl42 paid $250 as C+ (-50% due to regression) in Upwork
  • @DylanDylann paid $250 as Contributor (-50% due to regression) in Upwork

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Jan 10, 2024

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@cubuspl42] The PR that introduced the bug has been identified. Link to the PR:
  • [@cubuspl42] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@cubuspl42] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [@cubuspl42] Determine if we should create a regression test for this bug.
  • [@cubuspl42] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@CortneyOfstad] – https://github.com/Expensify/Expensify/issues/363208

@melvin-bot melvin-bot bot added Daily KSv2 Overdue and removed Weekly KSv2 labels Jan 11, 2024
@CortneyOfstad
Copy link
Contributor

Payment is not set until the 17th 👍

@melvin-bot melvin-bot bot removed the Overdue label Jan 15, 2024
@CortneyOfstad
Copy link
Contributor

Payments have been completed!

Payment Summary

@cubuspl42 paid $250 as C+ (-50% due to regression) in Upwork
@DylanDylann paid $250 as Contributor (-50% due to regression) in Upwork

@CortneyOfstad
Copy link
Contributor

@cubuspl42 any update on the checklist above? Thanks!

@ashimsharma10
Copy link

@CortneyOfstad Waiting for payment.
I'm the issue reporter.
Thanks.

@CortneyOfstad
Copy link
Contributor

Thanks @ashimsharma10 — sorry about that!

I had to create a new job post since the old one expired. I've sent you an offer here — https://www.upwork.com/jobs/~01d9cdd3e5a961ef64.

Please let me know once you accept and I can get that paid ASAP. Thanks!

@cubuspl42
Copy link
Contributor

  • The PR that introduced the bug has been identified. Link to the PR:
  • The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
    • No need for additional discussion
  • Determine if we should create a regression test for this bug.
    • Up to the QA team
  • If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
    • Create new distance request
    • Fill start point and end point
    • Go to confirmation page and observe the amount field
    • Click back to the distance page and edit waypoint
    • Go to confirmation page and verify that the amount is updated

@CortneyOfstad
Copy link
Contributor

Thanks @cubuspl42!

@ashimsharma10 any update on the proposal so I can get the payment processed? Thanks!

@ashimsharma10
Copy link

@CortneyOfstad I'm not able to apply.
my upwork is this : https://www.upwork.com/freelancers/~018a92cf13e1e88eed

@melvin-bot melvin-bot bot added the Overdue label Jan 22, 2024
@CortneyOfstad
Copy link
Contributor

@ashimsharma10 that Upwork profile is where I sent the proposal. I just sent it again 👍

@Expensify Expensify deleted a comment from ashimsharma10 Jan 24, 2024
@CortneyOfstad
Copy link
Contributor

@ashimsharma10 sorry for the delay here — finalized the payment this morning so you're all set!

Regression test has been created here, so this is all set to be closed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests