Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.56k stars 2.9k forks source link

[HOLD #48400][$250] Expense - RBR doesn't disappear Instantly after paying held expense #48397

Closed IuliiaHerets closed 3 weeks ago

IuliiaHerets commented 2 months ago

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: 9.0.27-0 Reproducible in staging?: Y Reproducible in production?: Y Email or phone of affected tester (no customers): biruknew45+518@gmail.com Issue reported by: Applause Internal Team

Action Performed:

  1. Go to https://staging.new.expensify.com/
  2. As User A, go to the chat with User B.
  3. As User A, submit an expense.
  4. As User A, right-click on the expense and click "Hold."
  5. The RBR appears in the expense preview for both User A and User B. If not, go to the expense details and then return to the chat.
  6. As User B, click "Pay Elsewhere" and confirm the payment.
  7. Click on the expense preview and then return to the chat (repeat this for both User A and User B).

Expected Result:

After paying the held expense in step 6, the RBR in the preview should disappear instantly.

Actual Result:

After paying the held expense in step 6, the RBR in the preview persists. The red dot only disappears after clicking on the preview and returning to the chat.

Workaround:

Unknown

Platforms:

Screenshots/Videos

Bug6589914_1725218970132!1 (1)

https://github.com/user-attachments/assets/00f5ba3a-6044-4ed1-af7b-bfb4f30bbb2d

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021831729851068678041
  • Upwork Job ID: 1831729851068678041
  • Last Price Increase: 2024-09-19
  • Automatic offers:
    • ikevin127 | Reviewer | 104042668
    • nkdengineer | Contributor | 104042669
Issue OwnerCurrent Issue Owner: @twisterdotcom
melvin-bot[bot] commented 2 months ago

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

IuliiaHerets commented 2 months ago

We think that this bug might be related to #vip-bills

IuliiaHerets commented 2 months ago

@twisterdotcom FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

Nodebrute commented 2 months ago

Edited by proposal-police: This proposal was edited at 2024-09-02 13:47:25 UTC.

Proposal

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

RBR doesn't disappear Instantly after paying held expense

What is the root cause of that problem?

In getPayMoneyRequestParams, we unhold transactions when we process a payment, but we don't clear transaction violation("hold"). This is why we're still seeing RBR. https://github.com/Expensify/App/blob/9aca655e04608e32ae84aeb99b8ec1e006f201e8/src/libs/actions/IOU.ts#L6725-L6734

Screenshot 2024-09-02 at 6 31 18β€―PM

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

We should also clear the transaction violation "hold" here. We can do something like this

            const transactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`]
optimisticData.push({
                onyxMethod: Onyx.METHOD.SET,
                key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`,
                value: transactionViolations?.filter((violation) => violation.name !== CONST.VIOLATIONS.HOLD) ?? []
            })

We also need to include failure data here.

What alternative solutions did you explore? (Optional)

twisterdotcom commented 2 months ago

Yes, I recreated this.

https://github.com/user-attachments/assets/346c33cd-e9a0-44b8-87a4-765656829786

melvin-bot[bot] commented 2 months ago

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

melvin-bot[bot] commented 2 months ago

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

nkdengineer commented 2 months ago

Proposal

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

After paying the held expense in step 6, the RBR in the preview persists. The red dot only disappears after clicking on the preview and returning to the chat.

What is the root cause of that problem?

When we pay money request, we unhold all transactions. But we don't clear the hold violation in optimistic data and after the API is complete, BE also doesn't clear the hold violation of the transaction then RBR still displays.

https://github.com/Expensify/App/blob/65c0f4103f178bf18f81a8b4e71ace5203c912cf/src/libs/actions/IOU.ts#L6725-L6734

This bug also happens when we approve money request but it only happens in offline, after the API is complete, BE returns violation of transaction that cleared the hold violation

https://github.com/Expensify/App/blob/65c0f4103f178bf18f81a8b4e71ace5203c912cf/src/libs/actions/IOU.ts#L7018-L7023

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

We should clear the hold violation when we pay/approve all requests. To prevent duplicate code, we can create a util to get the optimistic data for this case

function buildOnyxDataForUnHoldTransaction(expenseReport: OnyxEntry<OnyxTypes.Report>) {
    const optimisticData: OnyxUpdate[] = [];
    const failureData: OnyxUpdate[] = [];

    const heldTransactions = ReportUtils.getAllHeldTransactions(expenseReport?.reportID);
    heldTransactions.forEach((heldTransaction) => {
        optimisticData.push({
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.TRANSACTION}${heldTransaction.transactionID}`,
            value: {
                comment: {
                    hold: '',
                },
            },
        });
        failureData.push({
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.TRANSACTION}${heldTransaction.transactionID}`,
            value: {
                comment: {
                    hold: heldTransaction.comment?.hold,
                },
            },
        });
        const transactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${heldTransaction.transactionID}`] ?? []
        optimisticData.push({
            onyxMethod: Onyx.METHOD.SET,
            key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${heldTransaction.transactionID}`,
            value: transactionViolations.filter((violation) => violation.name !== CONST.VIOLATIONS.HOLD)
        });
        failureData.push({
            onyxMethod: Onyx.METHOD.SET,
            key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${heldTransaction.transactionID}`,
            value: transactionViolations,
        });
    });

    return {optimisticData, failureData};
}

Then we can use this in both places here

if (full) {
    const unholdTransactionOnyxData = buildOnyxDataForUnHoldTransaction(iouReport);
    optimisticData.push(...unholdTransactionOnyxData.optimisticData);
    failureData.push(...unholdTransactionOnyxData.failureData);
}

https://github.com/Expensify/App/blob/65c0f4103f178bf18f81a8b4e71ace5203c912cf/src/libs/actions/IOU.ts#L6725-L6734

if (full && hasHeldExpenses) {
    const unholdTransactionOnyxData = buildOnyxDataForUnHoldTransaction(expenseReport);
    optimisticData.push(...unholdTransactionOnyxData.optimisticData);
    failureData.push(...unholdTransactionOnyxData.failureData);
}

https://github.com/Expensify/App/blob/65c0f4103f178bf18f81a8b4e71ace5203c912cf/src/libs/actions/IOU.ts#L7018-L7023

OPTIONAL: BE should also clear the hold violation when returning the data in PayMoneyRequest API

What alternative solutions did you explore? (Optional)

melvin-bot[bot] commented 2 months ago

@twisterdotcom, @abdulrahuman5196 Huh... This is 4 days overdue. Who can take care of this?

twisterdotcom commented 2 months ago

@abdulrahuman5196 how are we doing on the reviews here?

melvin-bot[bot] commented 2 months ago

πŸ“£ It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? πŸ’Έ

abdulrahuman5196 commented 2 months ago

Hi @twisterdotcom, I am having multiple items on my plate. Kindly assign it to a different C+. Unassigning myself.

melvin-bot[bot] commented 2 months ago

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

melvin-bot[bot] commented 2 months ago

@twisterdotcom @ikevin127 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!

twisterdotcom commented 2 months ago

@ikevin127 could you review the proposal here from @nkdengineer and @Nodebrute?

ikevin127 commented 2 months ago

@twisterdotcom Sure, will review today.

ikevin127 commented 1 month ago

@nkdengineer's proposal looks good to me.

TLDR: Fixing this issue 100% does require BE changes as well.

[!important] The RCA is correct and the proposed solution solves our issue (partially) in the sense that the RBR does disappear on User B's side when the held expense is paid because the onyx data is only changed locally (in the browser), hence why it's not removed from User A because that would require BE to send a pusher event with the required data to remove the RBR after User B pays the held expense.

πŸŽ€πŸ‘€πŸŽ€Β C+ reviewed

ikevin127 commented 1 month ago

@Nodebrute Thanks for the proposal. Unfortunately the proposed solution does not work as transaction is undefined which besides not fixing our issue, it blocks the payment when trying to confirm Pay elsewhere, because of the undefined variable mentioned above.

error

The solution is not complete enough to facilitate reviewing / testing.

melvin-bot[bot] commented 1 month ago

Triggered auto assignment to @thienlnam, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

melvin-bot[bot] commented 1 month ago

πŸ“£ It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? πŸ’Έ

thienlnam commented 1 month ago

cc @cead22 on the held violation here. It looks like on an paid request, the violations on the transaction do not clear. Is this something we should take care of in Web-E or wait until the new violations roll out?

melvin-bot[bot] commented 1 month ago

πŸ“£ @ikevin127 πŸŽ‰ 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

melvin-bot[bot] commented 1 month ago

πŸ“£ @nkdengineer πŸŽ‰ 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 πŸ“–

cead22 commented 1 month ago

@thienlnam this might be a duplicate of https://github.com/Expensify/App/issues/48400. I think we should fix it now, and if it's a dupe we can handle it in that other issue

thienlnam commented 1 month ago

Ah yeah, actually this does look like a dupe and the other issue already has an assignee

nkdengineer commented 1 month ago

@cead22 I think we should clear the hold violation in optimistic data if we paid full instead of adding !isSettled condition.

ikevin127 commented 1 month ago

There's a 3rd dupe of this issue that might be fixed in similar fashion, only difference being it's a split instead of hold:

Please confirm if this would be fixed by selected proposal from https://github.com/Expensify/App/issues/48400 so we know whether to close it.

melvin-bot[bot] commented 1 month ago

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

thienlnam commented 1 month ago

@ikevin127 That looks like it would also be solved by https://github.com/Expensify/App/issues/48400

The steps don't look reproducible because it's probably because the expense needs to have a violation

melvin-bot[bot] commented 1 month ago

This issue has not been updated in over 15 days. @twisterdotcom, @thienlnam, @ikevin127 eroding to Monthly issue.

P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

twisterdotcom commented 3 weeks ago

48400 is closed now so I'll try to retest this.

ikevin127 commented 3 weeks ago

Retesting.

twisterdotcom commented 3 weeks ago

Yeah, fixed.

https://github.com/user-attachments/assets/74d125c0-3147-4d91-9c3f-5eed0104daff