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

Fix IOU badge disappearing after sending money to same user #8816

Merged
merged 8 commits into from
Apr 29, 2022
18 changes: 10 additions & 8 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,10 @@ function fetchIOUReportByID(iouReportID, chatReportID, shouldRedirectIfEmpty = f
* fetching the iouReport and therefore should only be called if we are certain that the fetched iouReport is currently
* open - else we would overwrite the existing open iouReportID with a closed iouReportID.
*
* Examples of usage include 'receieving a push notification', or 'paying an IOU', because both of these cases can only
* occur for an iouReport that is currently open (notifications are not sent for closed iouReports, and you cannot pay a
* closed IOU).
* Examples of correct usage include 'receieving a push notification', or 'paying an IOU', because both of these cases can only
* occur for an iouReport that is currently open (notifications are not sent for closed iouReports, and you cannot pay a closed
* IOU). Send Money is an incorrect use case, because these IOUReports are never associated with the chatReport and this would
* prevent outstanding IOUs from showing.
Comment on lines -522 to +525
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly this logic is super confusing and should be done on the backend without F.E needing to do this. I'm not going to do that though, as we're about to refactor our APIs for offline -- and because this will probably need to change anyway as part of Manual Requests.

I'll do this at some point

*
* @param {Number} iouReportID - ID of the report we are fetching
* @param {Number} chatReportID - associated chatReportID, used to sync the reports
Expand Down Expand Up @@ -647,11 +648,12 @@ function updateReportWithNewAction(
if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && reportAction.originalMessage.IOUReportID) {
const iouReportID = reportAction.originalMessage.IOUReportID;

// We know this iouReport is open because reportActions of type CONST.REPORT.ACTIONS.TYPE.IOU can only be
// triggered for an open iouReport (an open iouReport has an IOU, but is not yet paid). After fetching the
// iouReport we must update the chatReport with the correct iouReportID. If we don't, then new IOUs would not
// be displayed and paid IOUs would show as unpaid.
fetchIOUReportByIDAndUpdateChatReport(iouReportID, reportID);
// If the IOUDetails object exists we are in the Send Money flow, and we should not fetch and update the chatReport
// as this would overwrite any existing IOUs. For all other cases we must update the chatReport with the iouReportID as
// if we don't, new IOUs would not be displayed and paid IOUs would still show as unpaid.
if (reportAction.originalMessage.IOUDetails === undefined) {
fetchIOUReportByIDAndUpdateChatReport(iouReportID, reportID);
}
}

if (!ActiveClientManager.isClientTheLeader()) {
Expand Down