Skip to content

[HOLD for payment 2024-06-06] [$250] Distance is not optimistically updated #41817

Description

@m-natarajan

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 1.4.71-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
Expensify/Expensify Issue URL:
Issue reported by: @neil-marcellini
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1713898800427079

Action Performed:

  1. Go to an existing distance request
  2. Click the distance field
  3. Edit the waypoints and click save

Expected Result:

The distance optimistically updates to the correct new value.

Actual Result:

The distance does not optimistically update to the correct new value while online. It updates to a big value, then showing "pending" and then updates.

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

Recording.9.mp4
Screen.Recording.2024-04-23.at.11.56.01.AM.mov

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01e08c348144daf8d9
  • Upwork Job ID: 1788075386637766656
  • Last Price Increase: 2024-05-15
  • Automatic offers:
    • nkdengineer | Contributor | 0

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on May 7, 2024
  2. melvin-bot commented on May 7, 2024

    @melvin-bot

    Triggered auto assignment to @Christinadobrzyn (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.

  3. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on May 8, 2024
  4. changed the title [-] Distance is not optimistically updated[/-] [+][$250] Distance is not optimistically updated[/+] on May 8, 2024
  5. melvin-bot commented on May 8, 2024

    @melvin-bot
  6. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on May 8, 2024
  7. melvin-bot commented on May 8, 2024

    @melvin-bot

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

  8. Christinadobrzyn commented on May 8, 2024

    @Christinadobrzyn
    Contributor
  9. nkdengineer commented on May 8, 2024

    @nkdengineer
    Contributor

    Proposal

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

    The distance does not optimistically update to the correct new value while online. It updates to a big value, then showing "pending" and then updates.

    What is the root cause of that problem?

    We always set amount to default amount in optimistic data if the waypoints is changed.

    App/src/libs/actions/IOU.ts

    Lines 2322 to 2323 in 55c56bf

    amount: CONST.IOU.DEFAULT_AMOUNT,
    modifiedAmount: CONST.IOU.DEFAULT_AMOUNT,

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

    We should check if the route is also updated, we will calculate the amount and update it in optimistic data. The way to calculate the same as we do in MoneyRequestConfirmationList here

    1. Accept routes params in updateMoneyRequestDistance function and add it to transactionChanges here
    const transactionChanges: TransactionChanges = {
        waypoints,
        routes
    };
    

    App/src/libs/actions/IOU.ts

    Lines 2861 to 2862 in 55c56bf

    const transactionChanges: TransactionChanges = {
    waypoints,

    2. Pass routes and policy into IOU.updateMoneyRequestDistance function here

    const isRouteChanged = !isEqual(transactionBackup?.routes, transaction?.routes)
    if (isEqual(oldAddresses, addresses) && isRouteChanged) {
        Navigation.dismissModal();
        return;
    }
    IOU.updateMoneyRequestDistance({transactionID: transaction?.transactionID ?? '', transactionThreadReportID: report?.reportID ?? '', waypoints, ...(isRouteChanged ? {routes: transaction?.routes} : {}), policy});
    
    

    IOU.updateMoneyRequestDistance({transactionID: transaction?.transactionID ?? '', transactionThreadReportID: report?.reportID ?? '', waypoints});

    1. If the routes exist in transactionChanges, we will calculate the amount otherwise set it as default
    let updateAmount: number = CONST.IOU.DEFAULT_AMOUNT;
    if (transactionChanges?.routes) {
        const customUnitRateID = TransactionUtils.getRateID(transaction) ?? '';
        const mileageRates = DistanceRequestUtils.getMileageRates(policy);
        const mileageRate = mileageRates?.[customUnitRateID];
        const {unit, rate} = mileageRate;
        const distance = TransactionUtils.getDistance(transaction);
        updateAmount = -DistanceRequestUtils.getDistanceRequestAmount(distance, unit, rate ?? 0);
    }
    
    updatedTransaction = {
        ...updatedTransaction,
        amount: updateAmount,
        modifiedAmount: updateAmount,
        modifiedMerchant: Localize.translateLocal('iou.fieldPending'),
    };
    
    

    if (transaction && updatedTransaction && hasPendingWaypoints) {

    Do the same for getUpdateTrackExpenseParams.

    OPTIONAL: We can create a util to update the amount when the waypoint is changed and use it in these functions

    What alternative solutions did you explore? (Optional)

    NA

    Result

    Screen.Recording.2024-05-08.at.12.28.02.mov
  10. 28 remaining items

  11. melvin-bot commented on May 30, 2024

    @melvin-bot

    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:

    • [@akinwale] The PR that introduced the bug has been identified. Link to the PR:
    • [@akinwale] 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:
    • [@akinwale] 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:
    • [@akinwale] Determine if we should create a regression test for this bug.
    • [@akinwale] 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.
    • [@Christinadobrzyn] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
  12. Christinadobrzyn commented on Jun 5, 2024

    @Christinadobrzyn
    Contributor

    @akinwale do we need a regression test for this?

    Payouts due:

    Upwork job is here.

  13. akinwale commented on Jun 5, 2024

    @akinwale
    Contributor

    @akinwale do we need a regression test for this?

    @Christinadobrzyn Yes, we do.

    Also, please note that there was a regression from the PR, so there should be a penalty of 50% of the due payment applied.

  14. added and removed on Jun 6, 2024
  15. Christinadobrzyn commented on Jun 7, 2024

    @Christinadobrzyn
    Contributor

    hi @akinwale can you provide the regression test for this? Thank you!

  16. akinwale commented on Jun 7, 2024

    @akinwale
    Contributor
    • [@akinwale] The PR that introduced the bug has been identified. Link to the PR:
    • [@akinwale] 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:
    • [@akinwale] 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:

    Not a regression.

    • [@akinwale] Determine if we should create a regression test for this bug.
    • [@akinwale] 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.

    Regression Test Steps

    1. Launch the Expensify app
    2. Create a new distance request
    3. Navigate to the newly created distance request
    4. Change the distance by modifying any of the way points to new locations, or by adding additional waypoints
    5. Verify that the amount is updated immediately

    Do we agree 👍 or 👎?

  17. akinwale commented on Jun 7, 2024

    @akinwale
    Contributor
  18. Christinadobrzyn commented on Jun 10, 2024

    @Christinadobrzyn
    Contributor

    Thanks @akinwale - regression test here - https://github.com/Expensify/Expensify/issues/403299

    Paying out based on this payment summary - #41817 (comment)

    Closing this out! let me know if I missed anything!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions