Skip to content

[HOLD for payment 2024-03-06] [$500] [MEDIUM] Distance - Map doesn't load and TBD remains when creating request and editing amount offline #32263

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

Closed
6 tasks done
izarutskaya opened this issue Nov 30, 2023 · 47 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 Reviewing Has a PR in review

Comments

@izarutskaya
Copy link

izarutskaya commented Nov 30, 2023

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: v1.4.5-7
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: Applause-Internal Tean
Slack conversation: @

Action Performed:

  1. Navigate to staging.new.expensify.com
  2. Go offline.
  3. Go to workspace chat > + > Request money.
  4. Create a distance request.
  5. Open distance request details page > Amount.
  6. Enter amount and save it.
  7. Go online.

Expected Result:

The map will load and the fields with TBD will load data when the network connection is regained.

Actual Result:

The map never loads and all the details remain TBD.

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

Bug6295871_1701345082560.bandicam_2023-11-30_09-31-22-433.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01a40cd0507a4b7824
  • Upwork Job ID: 1730201171282763776
  • Last Price Increase: 2024-02-16
  • Automatic offers:
    • Ollyws | Reviewer | 0
    • paultsimura | Contributor | 0
@izarutskaya izarutskaya 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 Nov 30, 2023
@melvin-bot melvin-bot bot changed the title Distance - Map doesn't load and TBD remains when creating request and editing amount offline [$500] Distance - Map doesn't load and TBD remains when creating request and editing amount offline Nov 30, 2023
Copy link

melvin-bot bot commented Nov 30, 2023

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

Copy link

melvin-bot bot commented Nov 30, 2023

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

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

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

Copy link

melvin-bot bot commented Nov 30, 2023

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

@dukenv0307
Copy link
Contributor

@izarutskaya Can you please update the video of this issue.

@paultsimura
Copy link
Contributor

paultsimura commented Nov 30, 2023

Proposal

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

When creating & modifying a Distance request offline, the TBD state is stuck.

What is the root cause of that problem?

There is a race condition of onSuccess update of the transaction's pendingFields.

When creating the request, the successData contains the following update for the transaction:

"pendingFields": null

pendingFields: null,

And when modifying the amount:

"pendingFields": {
    "amount": null,
    "currency": null
},

pendingFields: clearedPendingFields,

As a result, when coming back online, both operations execute, and the "pendingFields": null is ignored (I believe, this is an in-Onyx bug, probably because the operations with null get stacked incorrectly), and the optimistically added "waypoints": "add" is not removed on successful response.

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

We should reset the pendingFields while creating a money request not fully: pendingFields: null, but only the pending fields which were set optimistically, similar to the editing scenario – in our case, it would look like this:

"pendingFields": {
    "waypoints": null
},

To do this, make the following changes:

        {
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`,
            value: {
                pendingAction: null,
                pendingFields: _.mapObject(transaction.pendingFields, () => null),
            },
        },

App/src/libs/actions/IOU.js

Lines 254 to 261 in a56c5cb

{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`,
value: {
pendingAction: null,
pendingFields: null,
},
},

What alternative solutions did you explore? (Optional)

We set the transaction.isLoading when modifying the waypoints of the distance request here:

App/src/libs/actions/IOU.js

Lines 757 to 766 in cd9cd57

optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
value: {
...updatedTransaction,
pendingFields,
isLoading: _.has(transactionChanges, 'waypoints'),
errorFields: null,
},
});

And we handle this state in other places, like here:

const isLoading = lodashGet(transaction, 'isLoading', false);

We should set this isLoading state not only while editing, but when creating the Distance request as well.

We shouldn't rely on the hasPendingWaypoints, but rather the transaction.isLoading as well in MoneyRequestView to display TBD:

const isLoading = lodashGet(transaction, 'isLoading', false);

const hasPendingWaypoints = lodashGet(transaction, 'pendingFields.waypoints', null);

We should also use if (!transaction.isLoading) instead of if (!Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints')) here, otherwise the map will be replaced with the pending receipt while the waypoints are being added.

if (!Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints')) {

@DylanDylann
Copy link
Contributor

Proposal

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

Map doesn't load and TBD remains when creating request and editing amount offline

This is bug video

bug.mp4

I see we have 2 bugs:

  1. When creating distance request offline the amount field will be TBD. If we click the amount field and edit another number, the amount field will be TBD (can't edit amount field when offline and there is pending waypoint)
  2. After editing amount field and go online, the map doesn't load and the amount field still be TBD

What is the root cause of that problem?

For the bug 1

if (isDistanceRequest && (!formattedTransactionAmount || hasPendingWaypoints)) {
formattedTransactionAmount = translate('common.tbd');
}

We are setting amount field to TBD if pendingFields.waypoints is valuable

For the bug 2, when creating distance request in successData we set pendingFields: null to reset pendingFields.waypoints. When editing distance request in success data we set

pendingFields {
   amount:  null
   currency: null

But after 2 APIs success, the pending field of creating distance request isn't merged to ONYX so pendingFields.waypoints still be valuable. It seems It is ONYX problem.

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

For bug 1, I suggest 2 solution:

  1. Because we always display TBD if there is any pending waypoint, we also need to disable amount field and don't allow user editing this field if there is any pending waypoint
  2. We still allow user edit amount and display modifiedAmount if !formattedTransactionAmount || hasPendingWaypoints. If modifiedAmount is empty we still display TBD as old logic

For the bug 2, I suggest 2 solution:

  1. When creating new distance request we only need set pendingAction and shouldn't set pendingField.waypoints It is redundant

pendingFields: {
comment: isEditingWaypoint ? CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE : CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},

I am not sure why we add pendingField in saveWaypoint function (this function only merge data to ONYX, not send API). Noe Note that, pendingField only be added in optimisticaData (apply before sending API) and It is re-set in successData and FailureData

  1. In successData of create distance request we should reset pending field like
pendingFields {
   waypoints:  null

@melvin-bot melvin-bot bot added the Overdue label Dec 4, 2023
@Ollyws
Copy link
Contributor

Ollyws commented Dec 4, 2023

Will get to this one asap.

Copy link

melvin-bot bot commented Dec 7, 2023

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

@greg-schroeder
Copy link
Contributor

Friendly bump @Ollyws :)

@melvin-bot melvin-bot bot removed the Overdue label Dec 7, 2023
@kbecciv
Copy link

kbecciv commented Dec 8, 2023

@dukenv0307 Uploaded a video

@melvin-bot melvin-bot bot added the Overdue label Dec 11, 2023
@greg-schroeder
Copy link
Contributor

Let's get to this one ASAP this week!

@melvin-bot melvin-bot bot removed the Overdue label Dec 11, 2023
@Ollyws
Copy link
Contributor

Ollyws commented Dec 11, 2023

I can no longer reproduce this one.

@melvin-bot melvin-bot bot added the Overdue label Dec 14, 2023
Copy link

melvin-bot bot commented Dec 14, 2023

@Ollyws @greg-schroeder 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 removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Feb 20, 2024
@tgolen
Copy link
Contributor

tgolen commented Feb 20, 2024

LGTM!

Copy link

melvin-bot bot commented Feb 20, 2024

📣 @Ollyws 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

Copy link

melvin-bot bot commented Feb 20, 2024

📣 @paultsimura 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@kmbcook
Copy link
Contributor

kmbcook commented Feb 21, 2024

The root cause is that the optimistic data is incorrect. If that root cause is eliminated, there is no concern with success data. As soon as the user confirms the distance request waypoints:add can be removed from pendingFields of the optimistic transaction. There is no need to wait for the API call to return successfully.

@paultsimura
Copy link
Contributor

The root cause is that the optimistic data is incorrect. If that root cause is eliminated, there is no concern with success data. As soon as the user confirms the distance request waypoints:add can be removed from pendingFields of the optimistic transaction. There is no need to wait for the API call to return successfully.

This is incorrect. The waypoints are marked as pending intentionally, and they should remain pending until the CreateDistanceRequest API response comes from the server.

@kmbcook
Copy link
Contributor

kmbcook commented Feb 21, 2024

The root cause is that the optimistic data is incorrect. If that root cause is eliminated, there is no concern with success data. As soon as the user confirms the distance request waypoints:add can be removed from pendingFields of the optimistic transaction. There is no need to wait for the API call to return successfully.

This is incorrect. The waypoints are marked as pending intentionally, and they should remain pending until the CreateDistanceRequest API response comes from the server.

Actually, I believe that as soon as the user confirms the choice of waypoints, they are no longer "pending" in the user's mind. Pending waypoints are useful up until the time that the user confirms them to be correct and complete, which happens prior to the CreateDistanceRequest API call.

@paultsimura
Copy link
Contributor

@kmbcook if you're interested - here's a quite informative thread explaining, in particular, why it was chosen to set the pending waypoints when creating a Distance request offline.

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Feb 21, 2024
@paultsimura
Copy link
Contributor

Thanks. The PR is ready for review: #37009

@greg-schroeder
Copy link
Contributor

greg-schroeder commented Mar 2, 2024

This was deployed to prod 2/28, so payment date will be 3/6

@greg-schroeder greg-schroeder added the Awaiting Payment Auto-added when associated PR is deployed to production label Mar 2, 2024
@greg-schroeder greg-schroeder changed the title [$500] [MEDIUM] Distance - Map doesn't load and TBD remains when creating request and editing amount offline [HOLD for payment 2024-03-06] [$500] [MEDIUM] Distance - Map doesn't load and TBD remains when creating request and editing amount offline Mar 2, 2024
@greg-schroeder
Copy link
Contributor

Hmm. The upwork job was closed for some reason, even though there was recent activity. I don't know. I'll probably have to create a new one...

@paultsimura
Copy link
Contributor

@greg-schroeder it's weird because the offer is still active for me on Upwork 🤔

@greg-schroeder
Copy link
Contributor

Apologies, I was out yesterday, but I'll generate a new job today and get this done

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Mar 8, 2024
@greg-schroeder
Copy link
Contributor

Doing

@greg-schroeder
Copy link
Contributor

@paultsimura paid! @Ollyws can you accept the offer we sent you? I'll pay you as soon as you accept

@Ollyws
Copy link
Contributor

Ollyws commented Mar 9, 2024

Accepted, thanks!

@greg-schroeder
Copy link
Contributor

cool, paid

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 Reviewing Has a PR in review
Projects
No open projects
Development

No branches or pull requests

9 participants