diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 880cd776c3dc..567234fb8bd7 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1853,7 +1853,7 @@ function getIOUReportActionMessage(type, total, comment, currency, paymentType = * @param {String} currency * @param {String} comment - User comment for the IOU. * @param {Array} participants - An array with participants details. - * @param {String} transactionID + * @param {String} [transactionID] - Not required if the IOUReportAction type is 'pay' * @param {String} [paymentType] - Only required if the IOUReportAction type is 'pay'. Can be oneOf(elsewhere, payPal, Expensify). * @param {String} [iouReportID] - Only required if the IOUReportActions type is oneOf(decline, cancel, pay). Generates a randomID as default. * @param {Boolean} [isSettlingUp] - Whether we are settling up an IOU. @@ -1867,7 +1867,7 @@ function buildOptimisticIOUReportAction( currency, comment, participants, - transactionID, + transactionID = '', paymentType = '', iouReportID = '', isSettlingUp = false, @@ -1885,13 +1885,21 @@ function buildOptimisticIOUReportAction( type, }; - // We store amount, comment, currency in IOUDetails when type = pay - if (type === CONST.IOU.REPORT_ACTION_TYPE.PAY && isSendMoneyFlow) { - _.each(['amount', 'comment', 'currency'], (key) => { - delete originalMessage[key]; - }); - originalMessage.IOUDetails = {amount, comment, currency}; - originalMessage.paymentType = paymentType; + if (type === CONST.IOU.REPORT_ACTION_TYPE.PAY) { + // In send money flow, we store amount, comment, currency in IOUDetails when type = pay + if (isSendMoneyFlow) { + _.each(['amount', 'comment', 'currency'], (key) => { + delete originalMessage[key]; + }); + originalMessage.IOUDetails = {amount, comment, currency}; + originalMessage.paymentType = paymentType; + } else { + // In case of pay money request action, we dont store the comment + // and there is no single transctionID to link the action to. + delete originalMessage.IOUTransactionID; + delete originalMessage.comment; + originalMessage.paymentType = paymentType; + } } // IOUs of type split only exist in group DMs and those don't have an iouReport so we need to delete the IOUReportID key diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index b15a897bb4aa..37870d4feddc 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -364,7 +364,16 @@ function requestMoney(report, amount, currency, payeeEmail, payeeAccountID, part receiptObject.source = receipt.source; receiptObject.state = CONST.IOU.RECEIPT_STATE.SCANREADY; } - const optimisticTransaction = TransactionUtils.buildOptimisticTransaction(amount, currency, iouReport.reportID, comment, '', '', undefined, receiptObject); + const optimisticTransaction = TransactionUtils.buildOptimisticTransaction( + ReportUtils.isExpenseReport(iouReport) ? -amount : amount, + currency, + iouReport.reportID, + comment, + '', + '', + undefined, + receiptObject, + ); // STEP 4: Build optimistic reportActions. We need: // 1. CREATED action for the chatReport @@ -630,7 +639,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco // STEP 3: Build optimistic transaction const oneOnOneTransaction = TransactionUtils.buildOptimisticTransaction( - splitAmount, + ReportUtils.isExpenseReport(oneOnOneIOUReport) ? -splitAmount : splitAmount, currency, oneOnOneIOUReport.reportID, comment, @@ -1323,14 +1332,13 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType * @returns {Object} */ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMethodType) { - const optimisticTransaction = TransactionUtils.buildOptimisticTransaction(iouReport.total, iouReport.currency, iouReport.reportID); const optimisticIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( CONST.IOU.REPORT_ACTION_TYPE.PAY, iouReport.total, iouReport.currency, '', [recipient], - optimisticTransaction.transactionID, + '', paymentMethodType, iouReport.reportID, true, @@ -1380,11 +1388,6 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, }, }, - { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.TRANSACTION}${optimisticTransaction.transactionID}`, - value: optimisticTransaction, - }, { onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.NVP_LAST_PAYMENT_METHOD, @@ -1402,13 +1405,6 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho }, }, }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.TRANSACTION}${optimisticTransaction.transactionID}`, - value: { - pendingAction: null, - }, - }, ]; const failureData = [ @@ -1430,13 +1426,6 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho }, }, }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.TRANSACTION}${optimisticTransaction.transactionID}`, - value: { - errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'), - }, - }, ]; return {