Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -1867,7 +1867,7 @@ function buildOptimisticIOUReportAction(
currency,
comment,
participants,
transactionID,
transactionID = '',
paymentType = '',
iouReportID = '',
isSettlingUp = false,
Expand All @@ -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
Expand Down
35 changes: 12 additions & 23 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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 = [
Expand All @@ -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 {
Expand Down