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

Closed

Description

@izarutskaya

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

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Nov 30, 2023
  2. 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[/+] on Nov 30, 2023
  3. melvin-bot commented on Nov 30, 2023

    @melvin-bot
  4. melvin-bot commented on Nov 30, 2023

    @melvin-bot

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

  5. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Nov 30, 2023
  6. melvin-bot commented on Nov 30, 2023

    @melvin-bot

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

    @melvin-bot

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

  8. dukenv0307 commented on Nov 30, 2023

    @dukenv0307
    Contributor

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

  9. paultsimura commented on Nov 30, 2023

    @paultsimura
    Contributor

    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')) {

  10. DylanDylann commented on Dec 1, 2023

    @DylanDylann
    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
    
  11. 53 remaining items

  12. 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[/+] on Mar 2, 2024
  13. greg-schroeder commented on Mar 7, 2024

    @greg-schroeder
    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...

  14. paultsimura commented on Mar 7, 2024

    @paultsimura
    Contributor

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

  15. greg-schroeder commented on Mar 8, 2024

    @greg-schroeder
    Contributor

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

  16. greg-schroeder commented on Mar 9, 2024

    @greg-schroeder
    Contributor

    Doing

  17. greg-schroeder commented on Mar 9, 2024

    @greg-schroeder
    Contributor

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

  18. Ollyws commented on Mar 9, 2024

    @Ollyws
    Contributor

    Accepted, thanks!

  19. greg-schroeder commented on Mar 9, 2024

    @greg-schroeder
    Contributor

    cool, paid

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 contributorReviewingHas a PR in review

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions