From 24e994866e7914f66f8d4ca1fa49e5b75354846c Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Tue, 15 Nov 2022 17:36:30 +0100 Subject: [PATCH 01/42] Add SendMoneyElsewhere request --- src/libs/actions/IOU.js | 87 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index d9ac2d1519a1..a0ebcdb317a6 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -720,6 +720,93 @@ function payIOUReport({ return promiseWithHandlers; } +/** + * @param {Object} report + * @param {Number} amount + * @param {String} currency + * @param {String} comment + * @param {String} ownerEmail - Email of the person generating the IOU. + * @param {String} userEmail - Email of the other person participating in the IOU. + */ +function sendMoneyElsewhere(report, amount, currency, comment, ownerEmail, userEmail) { + const participants = [ + {login: ownerEmail}, + {login: userEmail}, + ]; + const chatReport = lodashGet(report, 'reportID', null) + ? report + : ReportUtils.buildOptimisticChatReport(participants); + + const chatReportID = chatReport.reportID; + const optimisticIOUReport = ReportUtils.buildOptimisticIOUReport(ownerEmail, userEmail); + + const optimisticAddReportIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( + Report.getMaxSequenceNumber(chatReport.reportID) + 1, + CONST.IOU.REPORT_ACTION_TYPE.CREATE, + amount, + currency, + comment, + participants, + optimisticIOUReport.reportID, + ); + + const optimisticReimbursedReportAction = ReportUtils.buildOptimisticIOUReportAction( + Report.getMaxSequenceNumber(chatReport.reportID) + 2, + CONST.IOU.REPORT_ACTION_TYPE.PAY, + amount, + currency, + comment, + participants, + optimisticIOUReport.reportID, + ); + + const newIOUReportDetails = { + requestorEmail: ownerEmail, + amount, + currency, + comment, + }; + const paymentMethodType = CONST.IOU.PAYMENT_TYPE.ELSEWHERE; + + const optimisticData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: ONYXKEYS.IOU, + value: { + errors: {}, + }, + }, + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`, + value: { + [optimisticReimbursedReportAction.reportID]: optimisticReimbursedReportAction, + }, + }, + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`, + value: chatReport, + }, + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_IOUS}${optimisticIOUReport.reportID}`, + value: optimisticIOUReport, + }, + ]; + + API.write('SendMoney', { + iouReportID: optimisticIOUReport.reportID, + chatReportID, + optimisticReimbursedReportAction, + optimisticAddReportIOUReportAction, + paymentMethodType, + transactionID: optimisticReimbursedReportAction.originalMessage.IOUTransactionID, + clientID: optimisticReimbursedReportAction.sequenceNumber, + newIOUReportDetails, + }, {optimisticData}); +} + export { cancelMoneyRequest, splitBill, From 913ffbc1ff0b829e343e9fc9eb0eab290bd5a3cd Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Wed, 16 Nov 2022 01:51:22 +0100 Subject: [PATCH 02/42] Update logic in sendMoneyElsewhere --- src/libs/actions/IOU.js | 111 +++++++++++-------- src/pages/home/report/ReportActionCompose.js | 3 +- src/pages/iou/IOUModal.js | 3 +- 3 files changed, 68 insertions(+), 49 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index a0ebcdb317a6..25ae37cf6bb5 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1,6 +1,7 @@ import Onyx from 'react-native-onyx'; import _ from 'underscore'; import lodashGet from 'lodash/get'; +import Str from 'expensify-common/lib/str'; import CONST from '../../CONST'; import ONYXKEYS from '../../ONYXKEYS'; import ROUTES from '../../ROUTES'; @@ -725,69 +726,66 @@ function payIOUReport({ * @param {Number} amount * @param {String} currency * @param {String} comment - * @param {String} ownerEmail - Email of the person generating the IOU. - * @param {String} userEmail - Email of the other person participating in the IOU. + * @param {String} managerEmail - Email of the person sending the money + * @param {String} recipient - The user receiving the money */ -function sendMoneyElsewhere(report, amount, currency, comment, ownerEmail, userEmail) { - const participants = [ - {login: ownerEmail}, - {login: userEmail}, - ]; - const chatReport = lodashGet(report, 'reportID', null) - ? report - : ReportUtils.buildOptimisticChatReport(participants); - - const chatReportID = chatReport.reportID; - const optimisticIOUReport = ReportUtils.buildOptimisticIOUReport(ownerEmail, userEmail); - - const optimisticAddReportIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( - Report.getMaxSequenceNumber(chatReport.reportID) + 1, - CONST.IOU.REPORT_ACTION_TYPE.CREATE, +function sendMoneyElsewhere(report, amount, currency, comment, managerEmail, recipient) { + const newIOUReportDetails = JSON.stringify({ amount, currency, + requestorEmail: recipient.login, comment, - participants, - optimisticIOUReport.reportID, - ); + idempotencyKey: Str.guid(), + }); - const optimisticReimbursedReportAction = ReportUtils.buildOptimisticIOUReportAction( - Report.getMaxSequenceNumber(chatReport.reportID) + 2, + const recipientEmail = OptionsListUtils.addSMSDomainIfPhoneNumber(recipient.login); + let chatReport = lodashGet(report, 'reportID', null) ? report : null; + let isNewChat = false; + if (!chatReport) { + chatReport = ReportUtils.getChatByParticipants([recipientEmail]); + } + if (!chatReport) { + chatReport = ReportUtils.buildOptimisticChatReport([recipientEmail]); + isNewChat = true; + } + const optimisticIOUReport = ReportUtils.buildOptimisticIOUReport(recipientEmail, managerEmail, amount, chatReport.reportID, currency, preferredLocale); + const newSequenceNumber = Report.getMaxSequenceNumber(chatReport.reportID) + 1; + + const optimisticPaidReportAction = ReportUtils.buildOptimisticIOUReportAction( + newSequenceNumber, CONST.IOU.REPORT_ACTION_TYPE.PAY, amount, currency, comment, - participants, + [recipient], + CONST.IOU.PAYMENT_TYPE.ELSEWHERE, + '', optimisticIOUReport.reportID, ); - const newIOUReportDetails = { - requestorEmail: ownerEmail, - amount, - currency, - comment, - }; - const paymentMethodType = CONST.IOU.PAYMENT_TYPE.ELSEWHERE; - + // First, add data that will be used in all cases const optimisticData = [ { onyxMethod: CONST.ONYX.METHOD.MERGE, - key: ONYXKEYS.IOU, + key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, value: { - errors: {}, + ...chatReport, + lastVisitedTimestamp: Date.now(), + lastReadSequenceNumber: newSequenceNumber, + maxSequenceNumber: newSequenceNumber, + lastMessageText: optimisticPaidReportAction.message[0].text, + lastMessageHtml: optimisticPaidReportAction.message[0].html, + hasOutstandingIOU: optimisticIOUReport.total !== 0, + iouReportID: optimisticIOUReport.reportID, }, }, { onyxMethod: CONST.ONYX.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimisticReimbursedReportAction.reportID]: optimisticReimbursedReportAction, + [optimisticPaidReportAction.sequenceNumber]: optimisticPaidReportAction, }, }, - { - onyxMethod: CONST.ONYX.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`, - value: chatReport, - }, { onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_IOUS}${optimisticIOUReport.reportID}`, @@ -795,16 +793,36 @@ function sendMoneyElsewhere(report, amount, currency, comment, ownerEmail, userE }, ]; + // Now, let's add the data we need just when we are creating a new chat report + if (isNewChat) { + const optimisticCreateAction = ReportUtils.buildOptimisticCreatedReportAction(recipientEmail); + + // Change the method to set for new reports because it doesn't exist yet, is faster, + // and we need the data to be available when we navigate to the chat page + optimisticData[0].onyxMethod = CONST.ONYX.METHOD.SET; + optimisticData[0].value = { + ...optimisticData[0].value, + pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}, + }; + optimisticData[1].onyxMethod = CONST.ONYX.METHOD.SET; + optimisticData[1].value = { + ...optimisticCreateAction, + ...optimisticData[1].value, + }; + optimisticData[2].onyxMethod = CONST.ONYX.METHOD.SET; + } + API.write('SendMoney', { iouReportID: optimisticIOUReport.reportID, - chatReportID, - optimisticReimbursedReportAction, - optimisticAddReportIOUReportAction, - paymentMethodType, - transactionID: optimisticReimbursedReportAction.originalMessage.IOUTransactionID, - clientID: optimisticReimbursedReportAction.sequenceNumber, + chatReportID: chatReport.reportID, + paidReportActionID: optimisticPaidReportAction.reportActionID, + paymentMethodType: CONST.IOU.PAYMENT_TYPE.ELSEWHERE, + transactionID: Report.openPaymentDetailsPage.originalMessage.IOUTransactionID, + clientID: optimisticPaidReportAction.sequenceNumber, newIOUReportDetails, }, {optimisticData}); + + Navigation.navigate(ROUTES.getReportRoute(chatReport.reportID)); } export { @@ -814,4 +832,5 @@ export { requestMoney, payIOUReport, setIOUSelectedCurrency, + sendMoneyElsewhere, }; diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index ab5aa6fba104..26d52dfec8d0 100644 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -436,7 +436,8 @@ class ReportActionCompose extends React.Component { if (reportActionKey !== -1 && this.props.reportActions[reportActionKey]) { const {reportActionID, message} = this.props.reportActions[reportActionKey]; - Report.saveReportActionDraft(this.props.reportID, reportActionID, _.last(message).html); + + // Report.saveReportActionDraft(this.props.reportID, reportActionID, _.last(message).html); } } } diff --git a/src/pages/iou/IOUModal.js b/src/pages/iou/IOUModal.js index cb6905b3bc1f..2c0cc436722c 100755 --- a/src/pages/iou/IOUModal.js +++ b/src/pages/iou/IOUModal.js @@ -295,13 +295,12 @@ class IOUModal extends Component { idempotencyKey: Str.guid(), }); - IOU.payIOUReport({ + IOU.sendMoneyElsewhere({ chatReportID: lodashGet(this.props, 'route.params.reportID', ''), reportID: '0', paymentMethodType, amount, currency, - requestorPayPalMeAddress: this.state.participants[0].payPalMeAddress, comment, newIOUReportDetails, }) From 2ad8370ce6e1a4c7c8abff19ff65c4f1580753a1 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Wed, 16 Nov 2022 16:27:30 +0100 Subject: [PATCH 03/42] Cleanup --- src/pages/home/report/ReportActionCompose.js | 3 +-- src/pages/iou/IOUModal.js | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index 26d52dfec8d0..ab5aa6fba104 100644 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -436,8 +436,7 @@ class ReportActionCompose extends React.Component { if (reportActionKey !== -1 && this.props.reportActions[reportActionKey]) { const {reportActionID, message} = this.props.reportActions[reportActionKey]; - - // Report.saveReportActionDraft(this.props.reportID, reportActionID, _.last(message).html); + Report.saveReportActionDraft(this.props.reportID, reportActionID, _.last(message).html); } } } diff --git a/src/pages/iou/IOUModal.js b/src/pages/iou/IOUModal.js index 2c0cc436722c..cb6905b3bc1f 100755 --- a/src/pages/iou/IOUModal.js +++ b/src/pages/iou/IOUModal.js @@ -295,12 +295,13 @@ class IOUModal extends Component { idempotencyKey: Str.guid(), }); - IOU.sendMoneyElsewhere({ + IOU.payIOUReport({ chatReportID: lodashGet(this.props, 'route.params.reportID', ''), reportID: '0', paymentMethodType, amount, currency, + requestorPayPalMeAddress: this.state.participants[0].payPalMeAddress, comment, newIOUReportDetails, }) From d3311f4c03c6eabde9fba2a28871155a02685d7b Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Wed, 16 Nov 2022 16:46:09 +0100 Subject: [PATCH 04/42] Use the new SendMoneyElseWhere command from IOUModal --- src/libs/actions/IOU.js | 2 +- src/pages/iou/IOUModal.js | 34 ++++++++++++---------------------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 25ae37cf6bb5..71cf1d946dd9 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -817,7 +817,7 @@ function sendMoneyElsewhere(report, amount, currency, comment, managerEmail, rec chatReportID: chatReport.reportID, paidReportActionID: optimisticPaidReportAction.reportActionID, paymentMethodType: CONST.IOU.PAYMENT_TYPE.ELSEWHERE, - transactionID: Report.openPaymentDetailsPage.originalMessage.IOUTransactionID, + transactionID: optimisticPaidReportAction.originalMessage.IOUTransactionID, clientID: optimisticPaidReportAction.sequenceNumber, newIOUReportDetails, }, {optimisticData}); diff --git a/src/pages/iou/IOUModal.js b/src/pages/iou/IOUModal.js index cb6905b3bc1f..471aa2d55c0a 100755 --- a/src/pages/iou/IOUModal.js +++ b/src/pages/iou/IOUModal.js @@ -286,28 +286,18 @@ class IOUModal extends Component { const amount = Math.round(this.state.amount * 100); const currency = this.props.iou.selectedCurrencyCode; const comment = this.state.comment; - - const newIOUReportDetails = JSON.stringify({ - amount, - currency, - requestorEmail: this.state.participants[0].login, - comment, - idempotencyKey: Str.guid(), - }); - - IOU.payIOUReport({ - chatReportID: lodashGet(this.props, 'route.params.reportID', ''), - reportID: '0', - paymentMethodType, - amount, - currency, - requestorPayPalMeAddress: this.state.participants[0].payPalMeAddress, - comment, - newIOUReportDetails, - }) - .finally(() => { - Navigation.navigate(ROUTES.REPORT); - }); + const participant = this.state.participants[0]; + + if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) { + IOU.sendMoneyElsewhere( + this.props.report, + amount, + currency, + comment, + this.props.currentUserPersonalDetails.login, + participant, + ); + } } /** From 2b31e3f915cac30bdf3e7f2b8301fd02660da6b8 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Wed, 16 Nov 2022 16:54:46 +0100 Subject: [PATCH 05/42] Fix param type --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 71cf1d946dd9..419f7cd41fbe 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -727,7 +727,7 @@ function payIOUReport({ * @param {String} currency * @param {String} comment * @param {String} managerEmail - Email of the person sending the money - * @param {String} recipient - The user receiving the money + * @param {Object} recipient - The user receiving the money */ function sendMoneyElsewhere(report, amount, currency, comment, managerEmail, recipient) { const newIOUReportDetails = JSON.stringify({ From 5374b911aafbe1ce166e6432c4eaa105cf646810 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Thu, 17 Nov 2022 20:26:29 +0100 Subject: [PATCH 06/42] Allow sending money while offline --- src/components/SettlementButton.js | 2 +- src/libs/ReportUtils.js | 7 +++--- src/libs/actions/IOU.js | 36 ++++++++++++++++++++++++++---- src/pages/iou/IOUModal.js | 1 - 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/components/SettlementButton.js b/src/components/SettlementButton.js index 12e38b6294be..5fdfb437802f 100644 --- a/src/components/SettlementButton.js +++ b/src/components/SettlementButton.js @@ -84,7 +84,7 @@ class SettlementButton extends React.Component { > {triggerKYCFlow => ( { if (iouPaymentType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) { diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 9252911b4535..68adf102d297 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -669,10 +669,11 @@ function buildOptimisticReportAction(sequenceNumber, text, file) { * @param {String} chatReportID - Report ID of the chat where the IOU is. * @param {String} currency - IOU currency. * @param {String} locale - Locale where the IOU is created + * @param {Boolean} isSendingMoney - Whether we're requesting or sending money * * @returns {Object} */ -function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, currency, locale) { +function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, currency, locale, isSendingMoney = false) { const formattedTotal = NumberFormatUtils.format(locale, total, { style: 'currency', @@ -682,12 +683,12 @@ function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, cu cachedTotal: formattedTotal, chatReportID, currency, - hasOutstandingIOU: true, + hasOutstandingIOU: !isSendingMoney, managerEmail: userEmail, ownerEmail, reportID: generateReportID(), state: CONST.REPORT.STATE.SUBMITTED, - stateNum: 1, + stateNum: isSendingMoney ? 2 : 1, total, }; } diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 419f7cd41fbe..cdc8cb75b8e0 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -748,7 +748,7 @@ function sendMoneyElsewhere(report, amount, currency, comment, managerEmail, rec chatReport = ReportUtils.buildOptimisticChatReport([recipientEmail]); isNewChat = true; } - const optimisticIOUReport = ReportUtils.buildOptimisticIOUReport(recipientEmail, managerEmail, amount, chatReport.reportID, currency, preferredLocale); + const optimisticIOUReport = ReportUtils.buildOptimisticIOUReport(recipientEmail, managerEmail, amount, chatReport.reportID, currency, preferredLocale, true); const newSequenceNumber = Report.getMaxSequenceNumber(chatReport.reportID) + 1; const optimisticPaidReportAction = ReportUtils.buildOptimisticIOUReportAction( @@ -775,7 +775,7 @@ function sendMoneyElsewhere(report, amount, currency, comment, managerEmail, rec maxSequenceNumber: newSequenceNumber, lastMessageText: optimisticPaidReportAction.message[0].text, lastMessageHtml: optimisticPaidReportAction.message[0].html, - hasOutstandingIOU: optimisticIOUReport.total !== 0, + hasOutstandingIOU: false, iouReportID: optimisticIOUReport.reportID, }, }, @@ -783,7 +783,10 @@ function sendMoneyElsewhere(report, amount, currency, comment, managerEmail, rec onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimisticPaidReportAction.sequenceNumber]: optimisticPaidReportAction, + [optimisticPaidReportAction.sequenceNumber]: { + ...optimisticPaidReportAction, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }, }, }, { @@ -793,6 +796,31 @@ function sendMoneyElsewhere(report, amount, currency, comment, managerEmail, rec }, ]; + const successData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticPaidReportAction.sequenceNumber]: { + pendingAction: null, + }, + }, + }, + ]; + + const failureData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticPaidReportAction.sequenceNumber]: { + ...optimisticPaidReportAction, + pendingAction: null, + }, + }, + }, + ]; + // Now, let's add the data we need just when we are creating a new chat report if (isNewChat) { const optimisticCreateAction = ReportUtils.buildOptimisticCreatedReportAction(recipientEmail); @@ -820,7 +848,7 @@ function sendMoneyElsewhere(report, amount, currency, comment, managerEmail, rec transactionID: optimisticPaidReportAction.originalMessage.IOUTransactionID, clientID: optimisticPaidReportAction.sequenceNumber, newIOUReportDetails, - }, {optimisticData}); + }, {optimisticData, successData, failureData}); Navigation.navigate(ROUTES.getReportRoute(chatReport.reportID)); } diff --git a/src/pages/iou/IOUModal.js b/src/pages/iou/IOUModal.js index 471aa2d55c0a..096597341ac3 100755 --- a/src/pages/iou/IOUModal.js +++ b/src/pages/iou/IOUModal.js @@ -25,7 +25,6 @@ import Tooltip from '../../components/Tooltip'; import CONST from '../../CONST'; import * as PersonalDetails from '../../libs/actions/PersonalDetails'; import withCurrentUserPersonalDetails from '../../components/withCurrentUserPersonalDetails'; -import ROUTES from '../../ROUTES'; import networkPropTypes from '../../components/networkPropTypes'; import {withNetwork} from '../../components/OnyxProvider'; import reportPropTypes from '../reportPropTypes'; From 3f4a97301fc4648b7d588a82461f8f0b61df40c2 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Fri, 18 Nov 2022 01:20:56 +0100 Subject: [PATCH 07/42] Wrap IOUAction in OfflineWithFeedback --- src/components/ReportActionItem/IOUAction.js | 13 +++++++++++-- src/libs/actions/ReportActions.js | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/components/ReportActionItem/IOUAction.js b/src/components/ReportActionItem/IOUAction.js index 015766612056..671673e52a56 100644 --- a/src/components/ReportActionItem/IOUAction.js +++ b/src/components/ReportActionItem/IOUAction.js @@ -7,6 +7,8 @@ import IOUQuote from './IOUQuote'; import reportActionPropTypes from '../../pages/home/report/reportActionPropTypes'; import IOUPreview from './IOUPreview'; import Navigation from '../../libs/Navigation/Navigation'; +import OfflineWithFeedback from '../OfflineWithFeedback'; +import * as ReportActions from '../../libs/actions/ReportActions'; import ROUTES from '../../ROUTES'; import styles from '../../styles/styles'; @@ -39,7 +41,14 @@ const IOUAction = (props) => { Navigation.navigate(ROUTES.getIouDetailsRoute(props.chatReportID, props.action.originalMessage.IOUReportID)); }; return ( - <> + { + ReportActions.clearSendMoneyErrors(); + }} + errorRowStyles={[styles.mbn1]} + > { containerStyles={[styles.cursorPointer]} /> )} - + ); }; diff --git a/src/libs/actions/ReportActions.js b/src/libs/actions/ReportActions.js index c56bcabaae58..828cdecdda1d 100644 --- a/src/libs/actions/ReportActions.js +++ b/src/libs/actions/ReportActions.js @@ -23,7 +23,21 @@ function clearReportActionErrors(reportID, sequenceNumber) { }); } +/** + * This method clears the errors for a chat where send money action was done + * @param {String} chatReportID + * @param {String} reportActionID + */ +function clearSendMoneyErrors(chatReportID, reportActionID) { + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`, { + [reportActionID]: { + errors: null, + }, + }); +} + export { clearReportActionErrors, deleteOptimisticReportAction, + clearSendMoneyErrors, }; From 2bac5e70787853610dd1a2e4d78742b3e9b5862d Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Mon, 21 Nov 2022 12:44:14 +0100 Subject: [PATCH 08/42] Reverse wrapping IOUAction in OfflineWithFeedback --- src/components/ReportActionItem/IOUAction.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/components/ReportActionItem/IOUAction.js b/src/components/ReportActionItem/IOUAction.js index 671673e52a56..015766612056 100644 --- a/src/components/ReportActionItem/IOUAction.js +++ b/src/components/ReportActionItem/IOUAction.js @@ -7,8 +7,6 @@ import IOUQuote from './IOUQuote'; import reportActionPropTypes from '../../pages/home/report/reportActionPropTypes'; import IOUPreview from './IOUPreview'; import Navigation from '../../libs/Navigation/Navigation'; -import OfflineWithFeedback from '../OfflineWithFeedback'; -import * as ReportActions from '../../libs/actions/ReportActions'; import ROUTES from '../../ROUTES'; import styles from '../../styles/styles'; @@ -41,14 +39,7 @@ const IOUAction = (props) => { Navigation.navigate(ROUTES.getIouDetailsRoute(props.chatReportID, props.action.originalMessage.IOUReportID)); }; return ( - { - ReportActions.clearSendMoneyErrors(); - }} - errorRowStyles={[styles.mbn1]} - > + <> { containerStyles={[styles.cursorPointer]} /> )} - + ); }; From 1928a625301de0a388938e85e4f5d77543dc9340 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Mon, 21 Nov 2022 13:54:12 +0100 Subject: [PATCH 09/42] Add PayPalMe flow for sending money --- src/libs/actions/IOU.js | 10 ++++++++-- src/pages/iou/IOUModal.js | 19 +++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index cdc8cb75b8e0..3d7453b7055f 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -726,10 +726,11 @@ function payIOUReport({ * @param {Number} amount * @param {String} currency * @param {String} comment + * @param {String} paymentMethodType * @param {String} managerEmail - Email of the person sending the money * @param {Object} recipient - The user receiving the money */ -function sendMoneyElsewhere(report, amount, currency, comment, managerEmail, recipient) { +function sendMoneyElsewhere(report, amount, currency, comment, paymentMethodType, managerEmail, recipient) { const newIOUReportDetails = JSON.stringify({ amount, currency, @@ -844,12 +845,17 @@ function sendMoneyElsewhere(report, amount, currency, comment, managerEmail, rec iouReportID: optimisticIOUReport.reportID, chatReportID: chatReport.reportID, paidReportActionID: optimisticPaidReportAction.reportActionID, - paymentMethodType: CONST.IOU.PAYMENT_TYPE.ELSEWHERE, + paymentMethodType, transactionID: optimisticPaidReportAction.originalMessage.IOUTransactionID, clientID: optimisticPaidReportAction.sequenceNumber, newIOUReportDetails, }, {optimisticData, successData, failureData}); + if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.PAYPAL_ME) { + const url = buildPayPalPaymentUrl(amount, recipient.payPalMeAddress, currency); + asyncOpenURL(Promise.resolve(), url); + } + Navigation.navigate(ROUTES.getReportRoute(chatReport.reportID)); } diff --git a/src/pages/iou/IOUModal.js b/src/pages/iou/IOUModal.js index 096597341ac3..6fd1a9271565 100755 --- a/src/pages/iou/IOUModal.js +++ b/src/pages/iou/IOUModal.js @@ -287,16 +287,15 @@ class IOUModal extends Component { const comment = this.state.comment; const participant = this.state.participants[0]; - if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) { - IOU.sendMoneyElsewhere( - this.props.report, - amount, - currency, - comment, - this.props.currentUserPersonalDetails.login, - participant, - ); - } + IOU.sendMoneyElsewhere( + this.props.report, + amount, + currency, + comment, + paymentMethodType, + this.props.currentUserPersonalDetails.login, + participant, + ); } /** From a3ffc0dd0635cc2b4d44394d1798ebe8bacabf71 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Mon, 21 Nov 2022 14:22:45 +0100 Subject: [PATCH 10/42] Create separate method for PayPal flow --- src/libs/actions/IOU.js | 35 +++++++++++++++++++++++++++++------ src/pages/iou/IOUModal.js | 31 ++++++++++++++++++++++--------- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 3d7453b7055f..12e86390502e 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -730,7 +730,7 @@ function payIOUReport({ * @param {String} managerEmail - Email of the person sending the money * @param {Object} recipient - The user receiving the money */ -function sendMoneyElsewhere(report, amount, currency, comment, paymentMethodType, managerEmail, recipient) { +function sendMoney(report, amount, currency, comment, paymentMethodType, managerEmail, recipient) { const newIOUReportDetails = JSON.stringify({ amount, currency, @@ -851,14 +851,36 @@ function sendMoneyElsewhere(report, amount, currency, comment, paymentMethodType newIOUReportDetails, }, {optimisticData, successData, failureData}); - if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.PAYPAL_ME) { - const url = buildPayPalPaymentUrl(amount, recipient.payPalMeAddress, currency); - asyncOpenURL(Promise.resolve(), url); - } - Navigation.navigate(ROUTES.getReportRoute(chatReport.reportID)); } +/** + * @param {Object} report + * @param {Number} amount + * @param {String} currency + * @param {String} comment + * @param {String} managerEmail - Email of the person sending the money + * @param {Object} recipient - The user receiving the money + */ +function sendMoneyElsewhere(report, amount, currency, comment, managerEmail, recipient) { + const paymentMethodType = CONST.IOU.PAYMENT_TYPE.ELSEWHERE; + sendMoney(report, amount, currency, comment, paymentMethodType, managerEmail, recipient); +} + +/** + * @param {Object} report + * @param {Number} amount + * @param {String} currency + * @param {String} comment + * @param {String} managerEmail - Email of the person sending the money + * @param {Object} recipient - The user receiving the money + */ +function sendMoneyViaPaypal(report, amount, currency, comment, managerEmail, recipient) { + const paymentMethodType = CONST.IOU.PAYMENT_TYPE.PAYPAL_ME; + sendMoney(report, amount, currency, comment, paymentMethodType, managerEmail, recipient); + asyncOpenURL(Promise.resolve(), buildPayPalPaymentUrl(amount, recipient.payPalMeAddress, currency)); +} + export { cancelMoneyRequest, splitBill, @@ -867,4 +889,5 @@ export { payIOUReport, setIOUSelectedCurrency, sendMoneyElsewhere, + sendMoneyViaPaypal, }; diff --git a/src/pages/iou/IOUModal.js b/src/pages/iou/IOUModal.js index 6fd1a9271565..0296a60c839d 100755 --- a/src/pages/iou/IOUModal.js +++ b/src/pages/iou/IOUModal.js @@ -287,15 +287,28 @@ class IOUModal extends Component { const comment = this.state.comment; const participant = this.state.participants[0]; - IOU.sendMoneyElsewhere( - this.props.report, - amount, - currency, - comment, - paymentMethodType, - this.props.currentUserPersonalDetails.login, - participant, - ); + if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) { + IOU.sendMoneyElsewhere( + this.props.report, + amount, + currency, + comment, + this.props.currentUserPersonalDetails.login, + participant, + ); + return; + } + + if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.PAYPAL_ME) { + IOU.sendMoneyViaPaypal( + this.props.report, + amount, + currency, + comment, + this.props.currentUserPersonalDetails.login, + participant, + ); + } } /** From 2c48c72898410ddbcc2fa4acf7d7be73a4e2dda6 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Tue, 22 Nov 2022 16:16:15 +0100 Subject: [PATCH 11/42] Add PayMoneyRequest command --- src/libs/actions/IOU.js | 96 +++++++++++++++++++++++++++++++- src/pages/iou/IOUDetailsModal.js | 32 ++++++++--- 2 files changed, 119 insertions(+), 9 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 12e86390502e..4ca07339a0a8 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -881,13 +881,107 @@ function sendMoneyViaPaypal(report, amount, currency, comment, managerEmail, rec asyncOpenURL(Promise.resolve(), buildPayPalPaymentUrl(amount, recipient.payPalMeAddress, currency)); } +function payMoneyRequest(chatReport, iouReport, recipient, paymentMethodType) { + const newSequenceNumber = Report.getMaxSequenceNumber(chatReport.reportID) + 1; + + const optimisticPaidReportAction = ReportUtils.buildOptimisticIOUReportAction( + newSequenceNumber, + CONST.IOU.REPORT_ACTION_TYPE.PAY, + iouReport.total, + iouReport.currency, + '', + [recipient], + paymentMethodType, + '', + iouReport.reportID, + ); + + // First, add data that will be used in all cases + const optimisticData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, + value: { + ...chatReport, + lastVisitedTimestamp: Date.now(), + lastReadSequenceNumber: newSequenceNumber, + maxSequenceNumber: newSequenceNumber, + lastMessageText: optimisticPaidReportAction.message[0].text, + lastMessageHtml: optimisticPaidReportAction.message[0].html, + hasOutstandingIOU: false, + iouReportID: iouReport.reportID, + }, + }, + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticPaidReportAction.sequenceNumber]: { + ...optimisticPaidReportAction, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }, + }, + }, + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_IOUS}${iouReport.reportID}`, + value: iouReport, + }, + ]; + + const successData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticPaidReportAction.sequenceNumber]: { + pendingAction: null, + }, + }, + }, + ]; + + const failureData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticPaidReportAction.sequenceNumber]: { + ...optimisticPaidReportAction, + pendingAction: null, + }, + }, + }, + ]; + + API.write('PayMoneyRequest', { + iouReportID: iouReport.reportID, + paidReportActionID: optimisticPaidReportAction.reportActionID, + paymentMethodType, + clientID: optimisticPaidReportAction.sequenceNumber, + }, {optimisticData, successData, failureData}); +} + +function payMoneyRequestElsewhere(chatReport, iouReport, recipient) { + payMoneyRequest(chatReport, iouReport, recipient, CONST.IOU.PAYMENT_TYPE.ELSEWHERE); +} + +function payMoneyRequestViaPaypal(chatReport, iouReport, recipient) { + payMoneyRequest(chatReport, iouReport, recipient, CONST.IOU.PAYMENT_TYPE.PAYPAL_ME); + asyncOpenURL(Promise.resolve(), buildPayPalPaymentUrl( + iouReport.total, recipient.payPalMeAddress, iouReport.currency, + )); +} + export { cancelMoneyRequest, splitBill, splitBillAndOpenReport, requestMoney, payIOUReport, - setIOUSelectedCurrency, sendMoneyElsewhere, sendMoneyViaPaypal, + payMoneyRequestElsewhere, + payMoneyRequestViaPaypal, + setIOUSelectedCurrency, }; diff --git a/src/pages/iou/IOUDetailsModal.js b/src/pages/iou/IOUDetailsModal.js index 17369e94891e..f47f49b2525a 100644 --- a/src/pages/iou/IOUDetailsModal.js +++ b/src/pages/iou/IOUDetailsModal.js @@ -99,14 +99,27 @@ class IOUDetailsModal extends Component { * @param {String} paymentMethodType */ performIOUPayment(paymentMethodType) { - IOU.payIOUReport({ - chatReportID: this.props.route.params.chatReportID, - reportID: this.props.route.params.iouReportID, - paymentMethodType, - amount: this.props.iouReport.total, - currency: this.props.iouReport.currency, - requestorPayPalMeAddress: this.props.iouReport.submitterPayPalMeAddress, - }); + const recipient = { + login: this.props.iouReport.ownerEmail, + payPalMeAddress: this.props.iouReport.submitterPayPalMeAddress, + }; + + if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) { + IOU.payMoneyRequestElsewhere( + this.props.chatReport, + this.props.iouReport, + recipient, + ); + return; + } + + if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.PAYPAL_ME) { + IOU.payMoneyRequestViaPaypal( + this.props.chatReport, + this.props.iouReport, + recipient, + ); + } } render() { @@ -166,6 +179,9 @@ export default compose( iou: { key: ONYXKEYS.IOU, }, + chatReport: { + key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.chatReportID}`, + }, iouReport: { key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_IOUS}${route.params.iouReportID}`, }, From 6e72edcd4674a66b769b8ac3cb50aaa0d938dd6f Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Tue, 22 Nov 2022 17:09:54 +0100 Subject: [PATCH 12/42] Improve comment Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 68adf102d297..659618cb364a 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -669,7 +669,7 @@ function buildOptimisticReportAction(sequenceNumber, text, file) { * @param {String} chatReportID - Report ID of the chat where the IOU is. * @param {String} currency - IOU currency. * @param {String} locale - Locale where the IOU is created - * @param {Boolean} isSendingMoney - Whether we're requesting or sending money + * @param {Boolean} isSendingMoney - If we send money the IOU should be created as settled * * @returns {Object} */ From f6d293ac1fc7fac61feabf6656ee7c81de1d9b0c Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Tue, 22 Nov 2022 17:13:54 +0100 Subject: [PATCH 13/42] Add JSDocs to the new methods --- src/libs/actions/IOU.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 4ca07339a0a8..f709a6ba79a5 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -881,6 +881,12 @@ function sendMoneyViaPaypal(report, amount, currency, comment, managerEmail, rec asyncOpenURL(Promise.resolve(), buildPayPalPaymentUrl(amount, recipient.payPalMeAddress, currency)); } +/** + * @param {Object} chatReport + * @param {Object} iouReport + * @param {Object} recipient + * @param {String} paymentMethodType + */ function payMoneyRequest(chatReport, iouReport, recipient, paymentMethodType) { const newSequenceNumber = Report.getMaxSequenceNumber(chatReport.reportID) + 1; @@ -962,10 +968,20 @@ function payMoneyRequest(chatReport, iouReport, recipient, paymentMethodType) { }, {optimisticData, successData, failureData}); } +/** + * @param {Object} chatReport + * @param {Object} iouReport + * @param {Object} recipient + */ function payMoneyRequestElsewhere(chatReport, iouReport, recipient) { payMoneyRequest(chatReport, iouReport, recipient, CONST.IOU.PAYMENT_TYPE.ELSEWHERE); } +/** + * @param {Object} chatReport + * @param {Object} iouReport + * @param {Object} recipient + */ function payMoneyRequestViaPaypal(chatReport, iouReport, recipient) { payMoneyRequest(chatReport, iouReport, recipient, CONST.IOU.PAYMENT_TYPE.PAYPAL_ME); asyncOpenURL(Promise.resolve(), buildPayPalPaymentUrl( From 2776c3a3725ccc61bc943cde14a3ad468f2fb0f1 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Tue, 22 Nov 2022 17:43:09 +0100 Subject: [PATCH 14/42] Add clarifying comment --- src/libs/ReportUtils.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 659618cb364a..5360a268c0b6 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -679,6 +679,8 @@ function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, cu style: 'currency', currency, }); + + // stateNum 2: report is settled (submitted) return { cachedTotal: formattedTotal, chatReportID, From 4f16c9e967772c746c8372ff0cad86864e3a95be Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Fri, 25 Nov 2022 21:38:42 +0100 Subject: [PATCH 15/42] Use a seperate function for each payment method --- src/libs/actions/IOU.js | 136 +++++++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 51 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 8d17206a871e..60a55cb39ad6 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -731,8 +731,9 @@ function payIOUReport({ * @param {String} paymentMethodType * @param {String} managerEmail - Email of the person sending the money * @param {Object} recipient - The user receiving the money + * @returns {Object} */ -function sendMoney(report, amount, currency, comment, paymentMethodType, managerEmail, recipient) { +function getSendMoneyParams(report, amount, currency, comment, paymentMethodType, managerEmail, recipient) { const newIOUReportDetails = JSON.stringify({ amount, currency, @@ -843,44 +844,20 @@ function sendMoney(report, amount, currency, comment, paymentMethodType, manager optimisticData[2].onyxMethod = CONST.ONYX.METHOD.SET; } - API.write('SendMoney', { - iouReportID: optimisticIOUReport.reportID, - chatReportID: chatReport.reportID, - paidReportActionID: optimisticPaidReportAction.reportActionID, - paymentMethodType, - transactionID: optimisticPaidReportAction.originalMessage.IOUTransactionID, - clientID: optimisticPaidReportAction.sequenceNumber, - newIOUReportDetails, - }, {optimisticData, successData, failureData}); - - Navigation.navigate(ROUTES.getReportRoute(chatReport.reportID)); -} - -/** - * @param {Object} report - * @param {Number} amount - * @param {String} currency - * @param {String} comment - * @param {String} managerEmail - Email of the person sending the money - * @param {Object} recipient - The user receiving the money - */ -function sendMoneyElsewhere(report, amount, currency, comment, managerEmail, recipient) { - const paymentMethodType = CONST.IOU.PAYMENT_TYPE.ELSEWHERE; - sendMoney(report, amount, currency, comment, paymentMethodType, managerEmail, recipient); -} - -/** - * @param {Object} report - * @param {Number} amount - * @param {String} currency - * @param {String} comment - * @param {String} managerEmail - Email of the person sending the money - * @param {Object} recipient - The user receiving the money - */ -function sendMoneyViaPaypal(report, amount, currency, comment, managerEmail, recipient) { - const paymentMethodType = CONST.IOU.PAYMENT_TYPE.PAYPAL_ME; - sendMoney(report, amount, currency, comment, paymentMethodType, managerEmail, recipient); - asyncOpenURL(Promise.resolve(), buildPayPalPaymentUrl(amount, recipient.payPalMeAddress, currency)); + return { + params: { + iouReportID: optimisticIOUReport.reportID, + chatReportID: chatReport.reportID, + paidReportActionID: optimisticPaidReportAction.reportActionID, + paymentMethodType, + transactionID: optimisticPaidReportAction.originalMessage.IOUTransactionID, + clientID: optimisticPaidReportAction.sequenceNumber, + newIOUReportDetails, + }, + optimisticData, + successData, + failureData, + }; } /** @@ -888,8 +865,9 @@ function sendMoneyViaPaypal(report, amount, currency, comment, managerEmail, rec * @param {Object} iouReport * @param {Object} recipient * @param {String} paymentMethodType + * @returns {Object} */ -function payMoneyRequest(chatReport, iouReport, recipient, paymentMethodType) { +function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMethodType) { const newSequenceNumber = Report.getMaxSequenceNumber(chatReport.reportID) + 1; const optimisticPaidReportAction = ReportUtils.buildOptimisticIOUReportAction( @@ -962,12 +940,55 @@ function payMoneyRequest(chatReport, iouReport, recipient, paymentMethodType) { }, ]; - API.write('PayMoneyRequest', { - iouReportID: iouReport.reportID, - paidReportActionID: optimisticPaidReportAction.reportActionID, - paymentMethodType, - clientID: optimisticPaidReportAction.sequenceNumber, - }, {optimisticData, successData, failureData}); + return { + params: { + iouReportID: iouReport.reportID, + paidReportActionID: optimisticPaidReportAction.reportActionID, + paymentMethodType, + clientID: optimisticPaidReportAction.sequenceNumber, + }, + optimisticData, + successData, + failureData, + }; +} + +/** + * @param {Object} report + * @param {Number} amount + * @param {String} currency + * @param {String} comment + * @param {String} managerEmail - Email of the person sending the money + * @param {Object} recipient - The user receiving the money + */ +function sendMoneyElsewhere(report, amount, currency, comment, managerEmail, recipient) { + const { + params, optimisticData, successData, failureData, + } = getSendMoneyParams(report, amount, currency, comment, CONST.IOU.PAYMENT_TYPE.ELSEWHERE, managerEmail, recipient); + + API.write('SendMoneyElsewhere', params, {optimisticData, successData, failureData}); + + Navigation.navigate(ROUTES.getReportRoute(params.chatReportID)); +} + +/** + * @param {Object} report + * @param {Number} amount + * @param {String} currency + * @param {String} comment + * @param {String} managerEmail - Email of the person sending the money + * @param {Object} recipient - The user receiving the money + */ +function sendMoneyViaPaypal(report, amount, currency, comment, managerEmail, recipient) { + const { + params, optimisticData, successData, failureData, + } = getSendMoneyParams(report, amount, currency, comment, CONST.IOU.PAYMENT_TYPE.PAYPAL_ME, managerEmail, recipient); + + API.write('SendMoneyViaPaypal', params, {optimisticData, successData, failureData}); + + Navigation.navigate(ROUTES.getReportRoute(params.chatReportID)); + + asyncOpenURL(Promise.resolve(), buildPayPalPaymentUrl(amount, recipient.payPalMeAddress, currency)); } /** @@ -976,7 +997,15 @@ function payMoneyRequest(chatReport, iouReport, recipient, paymentMethodType) { * @param {Object} recipient */ function payMoneyRequestElsewhere(chatReport, iouReport, recipient) { - payMoneyRequest(chatReport, iouReport, recipient, CONST.IOU.PAYMENT_TYPE.ELSEWHERE); + const { + params, optimisticData, successData, failureData, + } = getPayMoneyRequestParams( + chatReport, iouReport, recipient, CONST.IOU.PAYMENT_TYPE.ELSEWHERE, + ); + + API.write('PayMoneyRequestElsewhere', params, {optimisticData, successData, failureData}); + + Navigation.navigate(ROUTES.getReportRoute(params.chatReportID)); } /** @@ -985,10 +1014,15 @@ function payMoneyRequestElsewhere(chatReport, iouReport, recipient) { * @param {Object} recipient */ function payMoneyRequestViaPaypal(chatReport, iouReport, recipient) { - payMoneyRequest(chatReport, iouReport, recipient, CONST.IOU.PAYMENT_TYPE.PAYPAL_ME); - asyncOpenURL(Promise.resolve(), buildPayPalPaymentUrl( - iouReport.total, recipient.payPalMeAddress, iouReport.currency, - )); + const { + params, optimisticData, successData, failureData, + } = getPayMoneyRequestParams( + chatReport, iouReport, recipient, CONST.IOU.PAYMENT_TYPE.PAYPAL_ME, + ); + + API.write('PayMoneyRequestViaPaypal', params, {optimisticData, successData, failureData}); + + Navigation.navigate(ROUTES.getReportRoute(params.chatReportID)); } export { From 8bbd68c9b50bb594f91f4a13c01bc1eed0bfd98e Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Mon, 28 Nov 2022 14:04:09 +0100 Subject: [PATCH 16/42] Add generic error messaged to failed payIOU request --- src/libs/actions/IOU.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 60a55cb39ad6..3c4dff38e70b 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -820,6 +820,9 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType [optimisticPaidReportAction.sequenceNumber]: { ...optimisticPaidReportAction, pendingAction: null, + errors: { + [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericCreateFailureMessage'), + }, }, }, }, @@ -935,6 +938,9 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho [optimisticPaidReportAction.sequenceNumber]: { ...optimisticPaidReportAction, pendingAction: null, + errors: { + [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericCreateFailureMessage'), + }, }, }, }, From 53bff3fc753489463b836c3b726e875bec0508a2 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Tue, 29 Nov 2022 01:11:08 +0100 Subject: [PATCH 17/42] Allow errored sendMoney report actions to be deleted --- src/libs/actions/IOU.js | 1 - src/pages/home/report/ReportActionItem.js | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 3c4dff38e70b..550c96b3bfdf 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -819,7 +819,6 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType value: { [optimisticPaidReportAction.sequenceNumber]: { ...optimisticPaidReportAction, - pendingAction: null, errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericCreateFailureMessage'), }, diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 5223f50b1637..66dc7bfb079a 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -196,7 +196,12 @@ class ReportActionItem extends Component { { if (this.props.action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { - ReportActions.deleteOptimisticReportAction(this.props.report.reportID, this.props.action.clientID); + const sequenceNumber = this.props.action.actionName + === CONST.REPORT.ACTIONS.TYPE.IOU + ? this.props.action + .sequenceNumber + : this.props.action.clientID; + ReportActions.deleteOptimisticReportAction(this.props.report.reportID, sequenceNumber); } else { ReportActions.clearReportActionErrors(this.props.report.reportID, this.props.action.sequenceNumber); } From ae4a3585eefa95b19c25b09fe4521304328c217d Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Tue, 29 Nov 2022 01:21:44 +0100 Subject: [PATCH 18/42] Fix style Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- src/libs/actions/IOU.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 550c96b3bfdf..73ce6283e66c 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1021,9 +1021,7 @@ function payMoneyRequestElsewhere(chatReport, iouReport, recipient) { function payMoneyRequestViaPaypal(chatReport, iouReport, recipient) { const { params, optimisticData, successData, failureData, - } = getPayMoneyRequestParams( - chatReport, iouReport, recipient, CONST.IOU.PAYMENT_TYPE.PAYPAL_ME, - ); + } = getPayMoneyRequestParams(chatReport, iouReport, recipient, CONST.IOU.PAYMENT_TYPE.PAYPAL_ME); API.write('PayMoneyRequestViaPaypal', params, {optimisticData, successData, failureData}); From 781f8674ca7356704bcf0eab1251ba1ef83ba50b Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Tue, 29 Nov 2022 02:26:02 +0100 Subject: [PATCH 19/42] Update generic error message --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 73ce6283e66c..2224ecca979f 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -938,7 +938,7 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho ...optimisticPaidReportAction, pendingAction: null, errors: { - [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericCreateFailureMessage'), + [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.other'), }, }, }, From b27c956421fc0217a22f6fdb8f6f7d311dd65cc0 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Wed, 30 Nov 2022 02:28:54 +0100 Subject: [PATCH 20/42] Fix navigation to report after settling up --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 2224ecca979f..e974622f0f24 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1010,7 +1010,7 @@ function payMoneyRequestElsewhere(chatReport, iouReport, recipient) { API.write('PayMoneyRequestElsewhere', params, {optimisticData, successData, failureData}); - Navigation.navigate(ROUTES.getReportRoute(params.chatReportID)); + Navigation.navigate(ROUTES.getReportRoute(chatReport.reportID)); } /** From dfcfb07a384916c679212418b3b88666d4d25327 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Wed, 30 Nov 2022 02:35:48 +0100 Subject: [PATCH 21/42] Fix settlment button visible after settling up offline --- src/libs/actions/IOU.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index e974622f0f24..c0b69e3b5648 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -913,7 +913,11 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho { onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_IOUS}${iouReport.reportID}`, - value: iouReport, + value: { + ...iouReport, + hasOutstandingIOU: false, + stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, + }, }, ]; From 36d4382e3608d976103be83c923f1ddbd498fe71 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Wed, 30 Nov 2022 14:17:30 +0100 Subject: [PATCH 22/42] Make code more readable --- src/libs/ReportUtils.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index bb7bc043de79..3372051e5113 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -689,7 +689,7 @@ function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, cu currency, }); - // stateNum 2: report is settled (submitted) + // If we're sending money, hasOutstandingIOU should be false return { cachedTotal: formattedTotal, chatReportID, @@ -699,7 +699,9 @@ function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, cu ownerEmail, reportID: generateReportID(), state: CONST.REPORT.STATE.SUBMITTED, - stateNum: isSendingMoney ? 2 : 1, + stateNum: isSendingMoney + ? CONST.REPORT.STATE_NUM.SUBMITTED + : CONST.REPORT.STATE_NUM.PROCESSING, total, }; } From 0880140f581d04f7b42914d9e427ea89e526b61e Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Wed, 30 Nov 2022 16:11:12 +0100 Subject: [PATCH 23/42] Use correct chatReportID for navigation --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index c0b69e3b5648..4acbf98d455d 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1029,7 +1029,7 @@ function payMoneyRequestViaPaypal(chatReport, iouReport, recipient) { API.write('PayMoneyRequestViaPaypal', params, {optimisticData, successData, failureData}); - Navigation.navigate(ROUTES.getReportRoute(params.chatReportID)); + Navigation.navigate(ROUTES.getReportRoute(chatReport.reportID)); } export { From 6b483c6ced9c3a42592206f44d43c7184e043bda Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Wed, 30 Nov 2022 16:15:41 +0100 Subject: [PATCH 24/42] Add navigation to PayPal.me in PayMoneyRequest --- src/libs/actions/IOU.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 4acbf98d455d..a3e578441d14 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1030,6 +1030,8 @@ function payMoneyRequestViaPaypal(chatReport, iouReport, recipient) { API.write('PayMoneyRequestViaPaypal', params, {optimisticData, successData, failureData}); Navigation.navigate(ROUTES.getReportRoute(chatReport.reportID)); + + asyncOpenURL(Promise.resolve(), buildPayPalPaymentUrl(iouReport.total, recipient.payPalMeAddress, iouReport.currency)); } export { From 6313845532c60e9c668be450364e3d7bc5810ea4 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Thu, 1 Dec 2022 17:29:01 +0100 Subject: [PATCH 25/42] Renaming --- src/libs/actions/IOU.js | 42 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index a3e578441d14..77d9bc27a439 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -755,7 +755,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType const optimisticIOUReport = ReportUtils.buildOptimisticIOUReport(recipientEmail, managerEmail, amount, chatReport.reportID, currency, preferredLocale, true); const newSequenceNumber = Report.getMaxSequenceNumber(chatReport.reportID) + 1; - const optimisticPaidReportAction = ReportUtils.buildOptimisticIOUReportAction( + const optimsticReportActionID = ReportUtils.buildOptimisticIOUReportAction( newSequenceNumber, CONST.IOU.REPORT_ACTION_TYPE.PAY, amount, @@ -777,8 +777,8 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType lastVisitedTimestamp: Date.now(), lastReadSequenceNumber: newSequenceNumber, maxSequenceNumber: newSequenceNumber, - lastMessageText: optimisticPaidReportAction.message[0].text, - lastMessageHtml: optimisticPaidReportAction.message[0].html, + lastMessageText: optimsticReportActionID.message[0].text, + lastMessageHtml: optimsticReportActionID.message[0].html, hasOutstandingIOU: false, iouReportID: optimisticIOUReport.reportID, }, @@ -787,8 +787,8 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimisticPaidReportAction.sequenceNumber]: { - ...optimisticPaidReportAction, + [optimsticReportActionID.sequenceNumber]: { + ...optimsticReportActionID, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, }, }, @@ -805,7 +805,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimisticPaidReportAction.sequenceNumber]: { + [optimsticReportActionID.sequenceNumber]: { pendingAction: null, }, }, @@ -817,8 +817,8 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimisticPaidReportAction.sequenceNumber]: { - ...optimisticPaidReportAction, + [optimsticReportActionID.sequenceNumber]: { + ...optimsticReportActionID, errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericCreateFailureMessage'), }, @@ -850,10 +850,10 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType params: { iouReportID: optimisticIOUReport.reportID, chatReportID: chatReport.reportID, - paidReportActionID: optimisticPaidReportAction.reportActionID, + reportActionID: optimsticReportActionID.reportActionID, paymentMethodType, - transactionID: optimisticPaidReportAction.originalMessage.IOUTransactionID, - clientID: optimisticPaidReportAction.sequenceNumber, + transactionID: optimsticReportActionID.originalMessage.IOUTransactionID, + clientID: optimsticReportActionID.sequenceNumber, newIOUReportDetails, }, optimisticData, @@ -872,7 +872,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMethodType) { const newSequenceNumber = Report.getMaxSequenceNumber(chatReport.reportID) + 1; - const optimisticPaidReportAction = ReportUtils.buildOptimisticIOUReportAction( + const optimsticReportActionID = ReportUtils.buildOptimisticIOUReportAction( newSequenceNumber, CONST.IOU.REPORT_ACTION_TYPE.PAY, iouReport.total, @@ -894,8 +894,8 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho lastVisitedTimestamp: Date.now(), lastReadSequenceNumber: newSequenceNumber, maxSequenceNumber: newSequenceNumber, - lastMessageText: optimisticPaidReportAction.message[0].text, - lastMessageHtml: optimisticPaidReportAction.message[0].html, + lastMessageText: optimsticReportActionID.message[0].text, + lastMessageHtml: optimsticReportActionID.message[0].html, hasOutstandingIOU: false, iouReportID: iouReport.reportID, }, @@ -904,8 +904,8 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimisticPaidReportAction.sequenceNumber]: { - ...optimisticPaidReportAction, + [optimsticReportActionID.sequenceNumber]: { + ...optimsticReportActionID, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, }, }, @@ -926,7 +926,7 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimisticPaidReportAction.sequenceNumber]: { + [optimsticReportActionID.sequenceNumber]: { pendingAction: null, }, }, @@ -938,8 +938,8 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimisticPaidReportAction.sequenceNumber]: { - ...optimisticPaidReportAction, + [optimsticReportActionID.sequenceNumber]: { + ...optimsticReportActionID, pendingAction: null, errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.other'), @@ -952,9 +952,9 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho return { params: { iouReportID: iouReport.reportID, - paidReportActionID: optimisticPaidReportAction.reportActionID, + reportActionID: optimsticReportActionID.reportActionID, paymentMethodType, - clientID: optimisticPaidReportAction.sequenceNumber, + clientID: optimsticReportActionID.sequenceNumber, }, optimisticData, successData, From cc3df115a2cf907c729ddc0f9c4a5f850711628a Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Thu, 1 Dec 2022 20:23:19 +0100 Subject: [PATCH 26/42] Fix typo --- src/libs/actions/IOU.js | 43 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 77d9bc27a439..641eb4e3e1c7 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -755,7 +755,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType const optimisticIOUReport = ReportUtils.buildOptimisticIOUReport(recipientEmail, managerEmail, amount, chatReport.reportID, currency, preferredLocale, true); const newSequenceNumber = Report.getMaxSequenceNumber(chatReport.reportID) + 1; - const optimsticReportActionID = ReportUtils.buildOptimisticIOUReportAction( + const optimsticReportAction = ReportUtils.buildOptimisticIOUReportAction( newSequenceNumber, CONST.IOU.REPORT_ACTION_TYPE.PAY, amount, @@ -777,9 +777,8 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType lastVisitedTimestamp: Date.now(), lastReadSequenceNumber: newSequenceNumber, maxSequenceNumber: newSequenceNumber, - lastMessageText: optimsticReportActionID.message[0].text, - lastMessageHtml: optimsticReportActionID.message[0].html, - hasOutstandingIOU: false, + lastMessageText: optimsticReportAction.message[0].text, + lastMessageHtml: optimsticReportAction.message[0].html, iouReportID: optimisticIOUReport.reportID, }, }, @@ -787,8 +786,8 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticReportActionID.sequenceNumber]: { - ...optimsticReportActionID, + [optimsticReportAction.sequenceNumber]: { + ...optimsticReportAction, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, }, }, @@ -805,7 +804,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticReportActionID.sequenceNumber]: { + [optimsticReportAction.sequenceNumber]: { pendingAction: null, }, }, @@ -817,8 +816,8 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticReportActionID.sequenceNumber]: { - ...optimsticReportActionID, + [optimsticReportAction.sequenceNumber]: { + ...optimsticReportAction, errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericCreateFailureMessage'), }, @@ -850,10 +849,10 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType params: { iouReportID: optimisticIOUReport.reportID, chatReportID: chatReport.reportID, - reportActionID: optimsticReportActionID.reportActionID, + reportActionID: optimsticReportAction.reportActionID, paymentMethodType, - transactionID: optimsticReportActionID.originalMessage.IOUTransactionID, - clientID: optimsticReportActionID.sequenceNumber, + transactionID: optimsticReportAction.originalMessage.IOUTransactionID, + clientID: optimsticReportAction.sequenceNumber, newIOUReportDetails, }, optimisticData, @@ -872,7 +871,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMethodType) { const newSequenceNumber = Report.getMaxSequenceNumber(chatReport.reportID) + 1; - const optimsticReportActionID = ReportUtils.buildOptimisticIOUReportAction( + const optimsticReportAction = ReportUtils.buildOptimisticIOUReportAction( newSequenceNumber, CONST.IOU.REPORT_ACTION_TYPE.PAY, iouReport.total, @@ -894,8 +893,8 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho lastVisitedTimestamp: Date.now(), lastReadSequenceNumber: newSequenceNumber, maxSequenceNumber: newSequenceNumber, - lastMessageText: optimsticReportActionID.message[0].text, - lastMessageHtml: optimsticReportActionID.message[0].html, + lastMessageText: optimsticReportAction.message[0].text, + lastMessageHtml: optimsticReportAction.message[0].html, hasOutstandingIOU: false, iouReportID: iouReport.reportID, }, @@ -904,8 +903,8 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticReportActionID.sequenceNumber]: { - ...optimsticReportActionID, + [optimsticReportAction.sequenceNumber]: { + ...optimsticReportAction, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, }, }, @@ -926,7 +925,7 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticReportActionID.sequenceNumber]: { + [optimsticReportAction.sequenceNumber]: { pendingAction: null, }, }, @@ -938,8 +937,8 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticReportActionID.sequenceNumber]: { - ...optimsticReportActionID, + [optimsticReportAction.sequenceNumber]: { + ...optimsticReportAction, pendingAction: null, errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.other'), @@ -952,9 +951,9 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho return { params: { iouReportID: iouReport.reportID, - reportActionID: optimsticReportActionID.reportActionID, + reportActionID: optimsticReportAction.reportActionID, paymentMethodType, - clientID: optimsticReportActionID.sequenceNumber, + clientID: optimsticReportAction.sequenceNumber, }, optimisticData, successData, From 8e425f1c419c46bdc49915bed4d212c7597d6b13 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Fri, 2 Dec 2022 00:37:43 +0100 Subject: [PATCH 27/42] Delete deprecated methods --- src/libs/actions/IOU.js | 64 -------------------------------- src/libs/deprecatedAPI.js | 27 -------------- src/pages/iou/IOUDetailsModal.js | 4 +- 3 files changed, 2 insertions(+), 93 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 641eb4e3e1c7..5213bafb4735 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -660,69 +660,6 @@ function buildPayPalPaymentUrl(amount, submitterPayPalMeAddress, currency) { return `https://paypal.me/${submitterPayPalMeAddress}/${(amount / 100)}${currency}`; } -/** - * Pays an IOU Report and then retrieves the iou and chat reports to trigger updates to the UI. - * - * @param {Object} params - * @param {Number} params.chatReportID - * @param {String} params.reportID - * @param {String} params.paymentMethodType - one of CONST.IOU.PAYMENT_TYPE - * @param {Number} params.amount - * @param {String} params.currency - * @param {String} [params.requestorPayPalMeAddress] - * @param {String} [params.newIOUReportDetails] - Extra details required only for send money flow - * - * @return {Promise} - */ -function payIOUReport({ - chatReportID, - reportID, - paymentMethodType, - amount, - currency, - requestorPayPalMeAddress, - newIOUReportDetails, -}) { - Onyx.merge(ONYXKEYS.IOU, {loading: true, error: false}); - - const payIOUPromise = paymentMethodType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY - ? DeprecatedAPI.PayWithWallet({reportID, newIOUReportDetails}) - : DeprecatedAPI.PayIOU({reportID, paymentMethodType, newIOUReportDetails}); - - // Build the url for Paypal.me if they have selected it instead of a manual settlement or Expensify Wallet - let url; - if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.PAYPAL_ME) { - url = buildPayPalPaymentUrl(amount, requestorPayPalMeAddress, currency); - } - - const promiseWithHandlers = payIOUPromise - .then((response) => { - if (response.jsonCode !== 200) { - switch (response.message) { - case 'You cannot pay via Expensify Wallet until you have either a verified deposit bank account or debit card.': - Growl.error(Localize.translateLocal('bankAccount.error.noDefaultDepositAccountOrDebitCardAvailable'), 5000); - break; - case 'This report doesn\'t have reimbursable expenses.': - Growl.error(Localize.translateLocal('iou.noReimbursableExpenses'), 5000); - break; - default: - Growl.error(response.message, 5000); - } - Onyx.merge(ONYXKEYS.IOU, {error: true}); - return; - } - - const chatReportStuff = response.reports[chatReportID]; - const iouReportStuff = response.reports[reportID]; - Report.syncChatAndIOUReports(chatReportStuff, iouReportStuff); - }) - .finally(() => { - Onyx.merge(ONYXKEYS.IOU, {loading: false}); - }); - asyncOpenURL(promiseWithHandlers, url); - return promiseWithHandlers; -} - /** * @param {Object} report * @param {Number} amount @@ -1038,7 +975,6 @@ export { splitBill, splitBillAndOpenReport, requestMoney, - payIOUReport, sendMoneyElsewhere, sendMoneyViaPaypal, payMoneyRequestElsewhere, diff --git a/src/libs/deprecatedAPI.js b/src/libs/deprecatedAPI.js index 1dd77c6eb5f0..7433e376ea6e 100644 --- a/src/libs/deprecatedAPI.js +++ b/src/libs/deprecatedAPI.js @@ -125,31 +125,6 @@ function Graphite_Timer(parameters) { return Network.post(commandName, parameters); } -/** - * @param {Object} parameters - * @param {Number} parameters.reportID - * @param {String} parameters.paymentMethodType - * @param {Object} [parameters.newIOUReportDetails] - * @returns {Promise} - */ -function PayIOU(parameters) { - const commandName = 'PayIOU'; - requireParameters(['reportID', 'paymentMethodType'], parameters, commandName); - return Network.post(commandName, parameters); -} - -/** - * @param {Object} parameters - * @param {Number} parameters.reportID - * @param {Object} [parameters.newIOUReportDetails] - * @returns {Promise} - */ -function PayWithWallet(parameters) { - const commandName = 'PayWithWallet'; - requireParameters(['reportID'], parameters, commandName); - return Network.post(commandName, parameters); -} - /** * @param {Object} parameters * @param {String} parameters.emailList @@ -326,8 +301,6 @@ export { GetStatementPDF, GetIOUReport, Graphite_Timer, - PayIOU, - PayWithWallet, PersonalDetails_GetForEmails, PersonalDetails_Update, ResendValidateCode, diff --git a/src/pages/iou/IOUDetailsModal.js b/src/pages/iou/IOUDetailsModal.js index f47f49b2525a..ed6332a450d4 100644 --- a/src/pages/iou/IOUDetailsModal.js +++ b/src/pages/iou/IOUDetailsModal.js @@ -98,7 +98,7 @@ class IOUDetailsModal extends Component { /** * @param {String} paymentMethodType */ - performIOUPayment(paymentMethodType) { + payMoneyRequest(paymentMethodType) { const recipient = { login: this.props.iouReport.ownerEmail, payPalMeAddress: this.props.iouReport.submitterPayPalMeAddress, @@ -152,7 +152,7 @@ class IOUDetailsModal extends Component { this.performIOUPayment(paymentMethodType)} + onPress={paymentMethodType => this.payMoneyRequest(paymentMethodType)} shouldShowPaypal={Boolean(lodashGet(this.props, 'iouReport.submitterPayPalMeAddress'))} currency={lodashGet(this.props, 'iouReport.currency')} enablePaymentsRoute={ROUTES.IOU_DETAILS_ENABLE_PAYMENTS} From ddbe82114435b11a1fc03f5c2f6bb3d7d81a4f08 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Fri, 2 Dec 2022 01:54:13 +0100 Subject: [PATCH 28/42] Use appropriate error message --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 5e1e74849792..5253027e850a 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -758,7 +758,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType [optimsticReportAction.sequenceNumber]: { ...optimsticReportAction, errors: { - [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericCreateFailureMessage'), + [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.other'), }, }, }, From 05bfe3a734d5af60202b3032797299a108ec463c Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Fri, 2 Dec 2022 13:32:02 +0100 Subject: [PATCH 29/42] Cleanup --- src/libs/actions/IOU.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 5253027e850a..f5223666e242 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -5,10 +5,8 @@ import Str from 'expensify-common/lib/str'; import CONST from '../../CONST'; import ONYXKEYS from '../../ONYXKEYS'; import ROUTES from '../../ROUTES'; -import * as DeprecatedAPI from '../deprecatedAPI'; import * as Report from './Report'; import Navigation from '../Navigation/Navigation'; -import Growl from '../Growl'; import * as Localize from '../Localize'; import asyncOpenURL from '../asyncOpenURL'; import * as API from '../API'; From 04af65083d8579530b70aa26ee2cb70dfd0557f1 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Fri, 2 Dec 2022 14:03:04 +0100 Subject: [PATCH 30/42] Apply requested changes --- src/libs/ReportUtils.js | 4 +-- src/libs/actions/IOU.js | 58 +++++++++++++++---------------- src/libs/actions/ReportActions.js | 14 -------- 3 files changed, 31 insertions(+), 45 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 95af3bc2d923..73ce12ef9f58 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -689,12 +689,12 @@ function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, cu currency, }); - // If we're sending money, hasOutstandingIOU should be false return { + // If we're sending money, hasOutstandingIOU should be false + hasOutstandingIOU: !isSendingMoney, cachedTotal: formattedTotal, chatReportID, currency, - hasOutstandingIOU: !isSendingMoney, managerEmail: userEmail, ownerEmail, reportID: generateReportID(), diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index f5223666e242..61a2d7197806 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -156,7 +156,7 @@ function requestMoney(report, amount, currency, recipientEmail, participant, com // Now, let's add the data we need just when we are creating a new chat report if (isNewChat) { - const optimisticCreateAction = ReportUtils.buildOptimisticCreatedReportAction(recipientEmail); + const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(recipientEmail); // Change the method to set for new reports because it doesn't exist yet, is faster, // and we need the data to be available when we navigate to the chat page @@ -167,7 +167,7 @@ function requestMoney(report, amount, currency, recipientEmail, participant, com }; optimisticData[1].onyxMethod = CONST.ONYX.METHOD.SET; optimisticData[1].value = { - ...optimisticCreateAction, + ...optimisticCreatedAction, ...optimisticData[1].value, }; optimisticData[2].onyxMethod = CONST.ONYX.METHOD.SET; @@ -674,13 +674,13 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType const newIOUReportDetails = JSON.stringify({ amount, currency, - requestorEmail: recipient.login, + requestorEmail: OptionsListUtils.addSMSDomainIfPhoneNumber(recipient.login), comment, idempotencyKey: Str.guid(), }); const recipientEmail = OptionsListUtils.addSMSDomainIfPhoneNumber(recipient.login); - let chatReport = lodashGet(report, 'reportID', null) ? report : null; + let chatReport = report.reportID ? report : null; let isNewChat = false; if (!chatReport) { chatReport = ReportUtils.getChatByParticipants([recipientEmail]); @@ -690,9 +690,11 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType isNewChat = true; } const optimisticIOUReport = ReportUtils.buildOptimisticIOUReport(recipientEmail, managerEmail, amount, chatReport.reportID, currency, preferredLocale, true); + + // This will be deprecated soon, in case the migration happens before this PR is merged we'll need to adjust the code here const newSequenceNumber = Report.getMaxSequenceNumber(chatReport.reportID) + 1; - const optimsticReportAction = ReportUtils.buildOptimisticIOUReportAction( + const optimsticIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( newSequenceNumber, CONST.IOU.REPORT_ACTION_TYPE.PAY, amount, @@ -714,8 +716,8 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType lastVisitedTimestamp: Date.now(), lastReadSequenceNumber: newSequenceNumber, maxSequenceNumber: newSequenceNumber, - lastMessageText: optimsticReportAction.message[0].text, - lastMessageHtml: optimsticReportAction.message[0].html, + lastMessageText: optimsticIOUReportAction.message[0].text, + lastMessageHtml: optimsticIOUReportAction.message[0].html, iouReportID: optimisticIOUReport.reportID, }, }, @@ -723,8 +725,8 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticReportAction.sequenceNumber]: { - ...optimsticReportAction, + [optimsticIOUReportAction.sequenceNumber]: { + ...optimsticIOUReportAction, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, }, }, @@ -741,7 +743,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticReportAction.sequenceNumber]: { + [optimsticIOUReportAction.sequenceNumber]: { pendingAction: null, }, }, @@ -753,8 +755,8 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticReportAction.sequenceNumber]: { - ...optimsticReportAction, + [optimsticIOUReportAction.sequenceNumber]: { + ...optimsticIOUReportAction, errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.other'), }, @@ -786,10 +788,10 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType params: { iouReportID: optimisticIOUReport.reportID, chatReportID: chatReport.reportID, - reportActionID: optimsticReportAction.reportActionID, + reportActionID: optimsticIOUReportAction.reportActionID, paymentMethodType, - transactionID: optimsticReportAction.originalMessage.IOUTransactionID, - clientID: optimsticReportAction.sequenceNumber, + transactionID: optimsticIOUReportAction.originalMessage.IOUTransactionID, + clientID: optimsticIOUReportAction.sequenceNumber, newIOUReportDetails, }, optimisticData, @@ -808,7 +810,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMethodType) { const newSequenceNumber = Report.getMaxSequenceNumber(chatReport.reportID) + 1; - const optimsticReportAction = ReportUtils.buildOptimisticIOUReportAction( + const optimsticIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( newSequenceNumber, CONST.IOU.REPORT_ACTION_TYPE.PAY, iouReport.total, @@ -820,7 +822,6 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho iouReport.reportID, ); - // First, add data that will be used in all cases const optimisticData = [ { onyxMethod: CONST.ONYX.METHOD.MERGE, @@ -830,8 +831,8 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho lastVisitedTimestamp: Date.now(), lastReadSequenceNumber: newSequenceNumber, maxSequenceNumber: newSequenceNumber, - lastMessageText: optimsticReportAction.message[0].text, - lastMessageHtml: optimsticReportAction.message[0].html, + lastMessageText: optimsticIOUReportAction.message[0].text, + lastMessageHtml: optimsticIOUReportAction.message[0].html, hasOutstandingIOU: false, iouReportID: iouReport.reportID, }, @@ -840,8 +841,8 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticReportAction.sequenceNumber]: { - ...optimsticReportAction, + [optimsticIOUReportAction.sequenceNumber]: { + ...optimsticIOUReportAction, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, }, }, @@ -862,7 +863,7 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticReportAction.sequenceNumber]: { + [optimsticIOUReportAction.sequenceNumber]: { pendingAction: null, }, }, @@ -874,8 +875,9 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticReportAction.sequenceNumber]: { - ...optimsticReportAction, + [optimsticIOUReportAction.sequenceNumber]: { + hasOutstandingIOU: true, + stateNum: CONST.REPORT.STATE_NUM.PROCESSING, pendingAction: null, errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.other'), @@ -888,9 +890,9 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho return { params: { iouReportID: iouReport.reportID, - reportActionID: optimsticReportAction.reportActionID, + reportActionID: optimsticIOUReportAction.reportActionID, paymentMethodType, - clientID: optimsticReportAction.sequenceNumber, + clientID: optimsticIOUReportAction.sequenceNumber, }, optimisticData, successData, @@ -944,9 +946,7 @@ function sendMoneyViaPaypal(report, amount, currency, comment, managerEmail, rec function payMoneyRequestElsewhere(chatReport, iouReport, recipient) { const { params, optimisticData, successData, failureData, - } = getPayMoneyRequestParams( - chatReport, iouReport, recipient, CONST.IOU.PAYMENT_TYPE.ELSEWHERE, - ); + } = getPayMoneyRequestParams(chatReport, iouReport, recipient, CONST.IOU.PAYMENT_TYPE.ELSEWHERE); API.write('PayMoneyRequestElsewhere', params, {optimisticData, successData, failureData}); diff --git a/src/libs/actions/ReportActions.js b/src/libs/actions/ReportActions.js index 828cdecdda1d..c56bcabaae58 100644 --- a/src/libs/actions/ReportActions.js +++ b/src/libs/actions/ReportActions.js @@ -23,21 +23,7 @@ function clearReportActionErrors(reportID, sequenceNumber) { }); } -/** - * This method clears the errors for a chat where send money action was done - * @param {String} chatReportID - * @param {String} reportActionID - */ -function clearSendMoneyErrors(chatReportID, reportActionID) { - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`, { - [reportActionID]: { - errors: null, - }, - }); -} - export { clearReportActionErrors, deleteOptimisticReportAction, - clearSendMoneyErrors, }; From 8272d1d62a9426a424917058d663709f2eab9b52 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Fri, 2 Dec 2022 14:05:20 +0100 Subject: [PATCH 31/42] Fix typo --- src/libs/actions/IOU.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 61a2d7197806..c1e62a536f77 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -767,7 +767,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType // Now, let's add the data we need just when we are creating a new chat report if (isNewChat) { - const optimisticCreateAction = ReportUtils.buildOptimisticCreatedReportAction(recipientEmail); + const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(recipientEmail); // Change the method to set for new reports because it doesn't exist yet, is faster, // and we need the data to be available when we navigate to the chat page @@ -778,7 +778,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType }; optimisticData[1].onyxMethod = CONST.ONYX.METHOD.SET; optimisticData[1].value = { - ...optimisticCreateAction, + ...optimisticCreatedAction, ...optimisticData[1].value, }; optimisticData[2].onyxMethod = CONST.ONYX.METHOD.SET; From b457ad03282409f7bc1f9d45a98d819048db11c1 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Fri, 2 Dec 2022 14:14:17 +0100 Subject: [PATCH 32/42] Deprecate REPORT_IOUS Onyx key --- src/libs/actions/IOU.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index c1e62a536f77..541294ea2b08 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -733,7 +733,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType }, { onyxMethod: CONST.ONYX.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_IOUS}${optimisticIOUReport.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticIOUReport.reportID}`, value: optimisticIOUReport, }, ]; @@ -849,7 +849,7 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho }, { onyxMethod: CONST.ONYX.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_IOUS}${iouReport.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, value: { ...iouReport, hasOutstandingIOU: false, From 39d28840c759dfca2c5e30d5c6e93ab6f02a38c7 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Fri, 2 Dec 2022 14:29:01 +0100 Subject: [PATCH 33/42] Fix IOUBadge changing when we send money --- src/libs/actions/IOU.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 541294ea2b08..3305df41af09 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -718,7 +718,6 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType maxSequenceNumber: newSequenceNumber, lastMessageText: optimsticIOUReportAction.message[0].text, lastMessageHtml: optimsticIOUReportAction.message[0].html, - iouReportID: optimisticIOUReport.reportID, }, }, { From 2de2def0a3684fd71e458f2c7b0ef649e0bf5089 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Fri, 2 Dec 2022 16:11:19 +0100 Subject: [PATCH 34/42] Keep deprecated payWithWallet as it should be removed in a different PR --- src/libs/actions/IOU.js | 62 ++++++++++++++++++++++++++++++++ src/libs/deprecatedAPI.js | 13 +++++++ src/pages/iou/IOUDetailsModal.js | 12 +++++++ 3 files changed, 87 insertions(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 3305df41af09..31e37bf46d5d 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -5,8 +5,10 @@ import Str from 'expensify-common/lib/str'; import CONST from '../../CONST'; import ONYXKEYS from '../../ONYXKEYS'; import ROUTES from '../../ROUTES'; +import * as DeprecatedAPI from '../deprecatedAPI'; import * as Report from './Report'; import Navigation from '../Navigation/Navigation'; +import Growl from '../Growl'; import * as Localize from '../Localize'; import asyncOpenURL from '../asyncOpenURL'; import * as API from '../API'; @@ -660,6 +662,65 @@ function buildPayPalPaymentUrl(amount, submitterPayPalMeAddress, currency) { return `https://paypal.me/${submitterPayPalMeAddress}/${(amount / 100)}${currency}`; } +/** + * Pays an IOU Report and then retrieves the iou and chat reports to trigger updates to the UI. + * + * @param {Object} params + * @param {Number} params.chatReportID + * @param {String} params.reportID + * @param {String} params.paymentMethodType - one of CONST.IOU.PAYMENT_TYPE + * @param {Number} params.amount + * @param {String} params.currency + * @param {String} [params.requestorPayPalMeAddress] + * @param {String} [params.newIOUReportDetails] - Extra details required only for send money flow + * + * @return {Promise} + */ +function payIOUReport({ + chatReportID, + reportID, + paymentMethodType, + amount, + currency, + requestorPayPalMeAddress, + newIOUReportDetails, +}) { + Onyx.merge(ONYXKEYS.IOU, {loading: true, error: false}); + + // Build the url for Paypal.me if they have selected it instead of a manual settlement or Expensify Wallet + let url; + if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.PAYPAL_ME) { + url = buildPayPalPaymentUrl(amount, requestorPayPalMeAddress, currency); + } + + const promiseWithHandlers = DeprecatedAPI.PayWithWallet({reportID, newIOUReportDetails}) + .then((response) => { + if (response.jsonCode !== 200) { + switch (response.message) { + case 'You cannot pay via Expensify Wallet until you have either a verified deposit bank account or debit card.': + Growl.error(Localize.translateLocal('bankAccount.error.noDefaultDepositAccountOrDebitCardAvailable'), 5000); + break; + case 'This report doesn\'t have reimbursable expenses.': + Growl.error(Localize.translateLocal('iou.noReimbursableExpenses'), 5000); + break; + default: + Growl.error(response.message, 5000); + } + Onyx.merge(ONYXKEYS.IOU, {error: true}); + return; + } + + const chatReportStuff = response.reports[chatReportID]; + const iouReportStuff = response.reports[reportID]; + Report.syncChatAndIOUReports(chatReportStuff, iouReportStuff); + }) + .finally(() => { + Onyx.merge(ONYXKEYS.IOU, {loading: false}); + }); + asyncOpenURL(promiseWithHandlers, url); + return promiseWithHandlers; +} + /** * @param {Object} report * @param {Number} amount @@ -974,6 +1035,7 @@ export { splitBill, splitBillAndOpenReport, requestMoney, + payIOUReport, sendMoneyElsewhere, sendMoneyViaPaypal, payMoneyRequestElsewhere, diff --git a/src/libs/deprecatedAPI.js b/src/libs/deprecatedAPI.js index 5f77d0daa8f2..61731c29208f 100644 --- a/src/libs/deprecatedAPI.js +++ b/src/libs/deprecatedAPI.js @@ -75,6 +75,18 @@ function Get(parameters, shouldUseSecure = false) { return Network.post(commandName, parameters, CONST.NETWORK.METHOD.POST, shouldUseSecure); } +/** + * @param {Object} parameters + * @param {Number} parameters.reportID + * @param {Object} [parameters.newIOUReportDetails] + * @returns {Promise} + */ +function PayWithWallet(parameters) { + const commandName = 'PayWithWallet'; + requireParameters(['reportID'], parameters, commandName); + return Network.post(commandName, parameters); +} + /** * @param {Object} parameters * @param {Object} parameters.details @@ -138,6 +150,7 @@ export { DeleteLogin, Get, GetStatementPDF, + PayWithWallet, PersonalDetails_Update, ResendValidateCode, SetNameValuePair, diff --git a/src/pages/iou/IOUDetailsModal.js b/src/pages/iou/IOUDetailsModal.js index 6a632bfe32df..0d45271ab5b1 100644 --- a/src/pages/iou/IOUDetailsModal.js +++ b/src/pages/iou/IOUDetailsModal.js @@ -119,6 +119,18 @@ class IOUDetailsModal extends Component { this.props.iouReport, recipient, ); + return; + } + + if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) { + IOU.payIOUReport({ + chatReportID: this.props.route.params.chatReportID, + reportID: this.props.route.params.iouReportID, + paymentMethodType, + amount: this.props.iouReport.total, + currency: this.props.iouReport.currency, + requestorPayPalMeAddress: this.props.iouReport.submitterPayPalMeAddress, + }); } } From 281d32bc174de6ea0ec445209d824eb96aaf3138 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Fri, 2 Dec 2022 17:01:44 +0100 Subject: [PATCH 35/42] Update report's lastActionCreated in IOU flows --- src/libs/actions/IOU.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 31e37bf46d5d..6baf452ca300 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -775,6 +775,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType value: { ...chatReport, lastVisitedTimestamp: Date.now(), + lastActionCreated: optimsticIOUReportAction.created, lastReadSequenceNumber: newSequenceNumber, maxSequenceNumber: newSequenceNumber, lastMessageText: optimsticIOUReportAction.message[0].text, @@ -889,6 +890,7 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho value: { ...chatReport, lastVisitedTimestamp: Date.now(), + lastActionCreated: optimsticIOUReportAction.created, lastReadSequenceNumber: newSequenceNumber, maxSequenceNumber: newSequenceNumber, lastMessageText: optimsticIOUReportAction.message[0].text, From 7bba84b6a01d0aa5e2d639a4b0d8014a733d1abe Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Fri, 2 Dec 2022 17:16:34 +0100 Subject: [PATCH 36/42] Fix typo --- src/libs/actions/IOU.js | 44 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 6baf452ca300..fca07e1d2904 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -755,7 +755,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType // This will be deprecated soon, in case the migration happens before this PR is merged we'll need to adjust the code here const newSequenceNumber = Report.getMaxSequenceNumber(chatReport.reportID) + 1; - const optimsticIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( + const optimisticIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( newSequenceNumber, CONST.IOU.REPORT_ACTION_TYPE.PAY, amount, @@ -775,19 +775,19 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType value: { ...chatReport, lastVisitedTimestamp: Date.now(), - lastActionCreated: optimsticIOUReportAction.created, + lastActionCreated: optimisticIOUReportAction.created, lastReadSequenceNumber: newSequenceNumber, maxSequenceNumber: newSequenceNumber, - lastMessageText: optimsticIOUReportAction.message[0].text, - lastMessageHtml: optimsticIOUReportAction.message[0].html, + lastMessageText: optimisticIOUReportAction.message[0].text, + lastMessageHtml: optimisticIOUReportAction.message[0].html, }, }, { onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticIOUReportAction.sequenceNumber]: { - ...optimsticIOUReportAction, + [optimisticIOUReportAction.sequenceNumber]: { + ...optimisticIOUReportAction, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, }, }, @@ -804,7 +804,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticIOUReportAction.sequenceNumber]: { + [optimisticIOUReportAction.sequenceNumber]: { pendingAction: null, }, }, @@ -816,8 +816,8 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticIOUReportAction.sequenceNumber]: { - ...optimsticIOUReportAction, + [optimisticIOUReportAction.sequenceNumber]: { + ...optimisticIOUReportAction, errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.other'), }, @@ -849,10 +849,10 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType params: { iouReportID: optimisticIOUReport.reportID, chatReportID: chatReport.reportID, - reportActionID: optimsticIOUReportAction.reportActionID, + reportActionID: optimisticIOUReportAction.reportActionID, paymentMethodType, - transactionID: optimsticIOUReportAction.originalMessage.IOUTransactionID, - clientID: optimsticIOUReportAction.sequenceNumber, + transactionID: optimisticIOUReportAction.originalMessage.IOUTransactionID, + clientID: optimisticIOUReportAction.sequenceNumber, newIOUReportDetails, }, optimisticData, @@ -871,7 +871,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMethodType) { const newSequenceNumber = Report.getMaxSequenceNumber(chatReport.reportID) + 1; - const optimsticIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( + const optimisticIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( newSequenceNumber, CONST.IOU.REPORT_ACTION_TYPE.PAY, iouReport.total, @@ -890,11 +890,11 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho value: { ...chatReport, lastVisitedTimestamp: Date.now(), - lastActionCreated: optimsticIOUReportAction.created, + lastActionCreated: optimisticIOUReportAction.created, lastReadSequenceNumber: newSequenceNumber, maxSequenceNumber: newSequenceNumber, - lastMessageText: optimsticIOUReportAction.message[0].text, - lastMessageHtml: optimsticIOUReportAction.message[0].html, + lastMessageText: optimisticIOUReportAction.message[0].text, + lastMessageHtml: optimisticIOUReportAction.message[0].html, hasOutstandingIOU: false, iouReportID: iouReport.reportID, }, @@ -903,8 +903,8 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticIOUReportAction.sequenceNumber]: { - ...optimsticIOUReportAction, + [optimisticIOUReportAction.sequenceNumber]: { + ...optimisticIOUReportAction, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, }, }, @@ -925,7 +925,7 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticIOUReportAction.sequenceNumber]: { + [optimisticIOUReportAction.sequenceNumber]: { pendingAction: null, }, }, @@ -937,7 +937,7 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - [optimsticIOUReportAction.sequenceNumber]: { + [optimisticIOUReportAction.sequenceNumber]: { hasOutstandingIOU: true, stateNum: CONST.REPORT.STATE_NUM.PROCESSING, pendingAction: null, @@ -952,9 +952,9 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho return { params: { iouReportID: iouReport.reportID, - reportActionID: optimsticIOUReportAction.reportActionID, + reportActionID: optimisticIOUReportAction.reportActionID, paymentMethodType, - clientID: optimsticIOUReportAction.sequenceNumber, + clientID: optimisticIOUReportAction.sequenceNumber, }, optimisticData, successData, From 4becf7fc48e2705870cd27f14ab1029831881aef Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Sat, 3 Dec 2022 01:33:28 +0100 Subject: [PATCH 37/42] Fix optimistic IOU payment messages --- src/libs/ReportUtils.js | 28 ++++++++++++++++++++++++---- src/libs/actions/IOU.js | 1 + 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 73ce12ef9f58..da0e6fd26a72 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -712,15 +712,32 @@ function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, cu * @param {Array} participants - List of logins for the IOU participants, excluding the current user login * @param {String} comment - IOU comment * @param {String} currency - IOU currency + * @param {String} paymentType - IOU paymentMethodType. Can be oneOf(Elsewhere, Expensify, PayPal.me) + * @param {Boolean} isSettlingUp - Whether we are settling up an IOU * @returns {Array} */ -function getIOUReportActionMessage(type, total, participants, comment, currency) { +function getIOUReportActionMessage(type, total, participants, comment, currency, paymentType = '', isSettlingUp = false) { const amount = NumberFormatUtils.format(preferredLocale, total / 100, {style: 'currency', currency}); const displayNames = _.map(participants, participant => getDisplayNameForParticipant(participant.login, true)); const who = displayNames.length < 3 ? displayNames.join(' and ') : `${displayNames.slice(0, -1).join(', ')}, and ${_.last(displayNames)}`; + let paymentMethodMessage; + switch (paymentType) { + case CONST.IOU.PAYMENT_TYPE.EXPENSIFY: + paymentMethodMessage = 'using wallet'; + break; + case CONST.IOU.PAYMENT_TYPE.ELSEWHERE: + paymentMethodMessage = 'elsewhere'; + break; + case CONST.IOU.PAYMENT_TYPE.PAYPAL_ME: + paymentMethodMessage = 'using PayPal.me'; + break; + default: + break; + } + let iouMessage; switch (type) { case CONST.IOU.REPORT_ACTION_TYPE.CREATE: @@ -736,7 +753,9 @@ function getIOUReportActionMessage(type, total, participants, comment, currency) iouMessage = `Declined the ${amount} request${comment && ` for ${comment}`}`; break; case CONST.IOU.REPORT_ACTION_TYPE.PAY: - iouMessage = `Paid ${amount} to ${who}${comment && ` for ${comment}`}`; + iouMessage = isSettlingUp + ? `Settled up ${paymentMethodMessage}` + : `Sent ${amount}${comment && ` for ${comment}`} ${paymentMethodMessage}`; break; default: break; @@ -762,10 +781,11 @@ function getIOUReportActionMessage(type, total, participants, comment, currency) * @param {String} paymentType - Only required if the IOUReportAction type is 'pay'. Can be oneOf(elsewhere, payPal, Expensify). * @param {String} iouTransactionID - Only required if the IOUReportAction type is oneOf(cancel, decline). Generates a randomID as default. * @param {String} iouReportID - Only required if the IOUReportActions type is oneOf(decline, cancel, pay). Generates a randomID as default. + * @param {String} isSettlingUp - Whether we are settling up an IOU. * * @returns {Object} */ -function buildOptimisticIOUReportAction(sequenceNumber, type, amount, currency, comment, participants, paymentType = '', iouTransactionID = '', iouReportID = '') { +function buildOptimisticIOUReportAction(sequenceNumber, type, amount, currency, comment, participants, paymentType = '', iouTransactionID = '', iouReportID = '', isSettlingUp) { const IOUTransactionID = iouTransactionID || NumberUtils.rand64(); const IOUReportID = iouReportID || generateReportID(); const originalMessage = { @@ -800,7 +820,7 @@ function buildOptimisticIOUReportAction(sequenceNumber, type, amount, currency, clientID: NumberUtils.generateReportActionClientID(), isAttachment: false, originalMessage, - message: getIOUReportActionMessage(type, amount, participants, comment, currency), + message: getIOUReportActionMessage(type, amount, participants, comment, currency, paymentType, isSettlingUp), person: [{ style: 'strong', text: lodashGet(currentUserPersonalDetails, 'displayName', currentUserEmail), diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index fca07e1d2904..40efba0ca643 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -881,6 +881,7 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho paymentMethodType, '', iouReport.reportID, + true, ); const optimisticData = [ From 01aa33dafff4be812deb9195603fadb2e80edd99 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Wed, 7 Dec 2022 17:51:18 +0100 Subject: [PATCH 38/42] Fix method argument --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 40efba0ca643..2c7d2fdcd188 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -762,7 +762,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType currency, comment, [recipient], - CONST.IOU.PAYMENT_TYPE.ELSEWHERE, + paymentMethodType, '', optimisticIOUReport.reportID, ); From 3ec36251b35cb8e088279ff103958e7e53a50efc Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Wed, 7 Dec 2022 17:55:00 +0100 Subject: [PATCH 39/42] Small improvement --- src/libs/actions/IOU.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 2c7d2fdcd188..3bf61d8d0a60 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -732,15 +732,16 @@ function payIOUReport({ * @returns {Object} */ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType, managerEmail, recipient) { + const recipientEmail = OptionsListUtils.addSMSDomainIfPhoneNumber(recipient.login); + const newIOUReportDetails = JSON.stringify({ amount, currency, - requestorEmail: OptionsListUtils.addSMSDomainIfPhoneNumber(recipient.login), + requestorEmail: recipientEmail, comment, idempotencyKey: Str.guid(), }); - const recipientEmail = OptionsListUtils.addSMSDomainIfPhoneNumber(recipient.login); let chatReport = report.reportID ? report : null; let isNewChat = false; if (!chatReport) { From 1b150237ff2e85e813abfd230d33ae1cc24c80b4 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Thu, 8 Dec 2022 00:33:47 +0100 Subject: [PATCH 40/42] Remove unneeded code --- src/libs/actions/IOU.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 3bf61d8d0a60..0a6d0767676d 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -818,7 +818,6 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { [optimisticIOUReportAction.sequenceNumber]: { - ...optimisticIOUReportAction, errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.other'), }, From e7d78baf4b1946a753f8c18d9268f5beb0d8b734 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Thu, 8 Dec 2022 04:03:07 +0100 Subject: [PATCH 41/42] Fix IOU Preview still showing after failed pay request --- src/components/ReportActionItem/IOUAction.js | 40 ++++++++++++-------- src/libs/actions/IOU.js | 4 +- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/components/ReportActionItem/IOUAction.js b/src/components/ReportActionItem/IOUAction.js index 71717dad1faf..affa1035eb64 100644 --- a/src/components/ReportActionItem/IOUAction.js +++ b/src/components/ReportActionItem/IOUAction.js @@ -25,6 +25,9 @@ const propTypes = { chatReport: PropTypes.shape({ /** The participants of this report */ participants: PropTypes.arrayOf(PropTypes.string), + + /** Whether the chat report has an outstanding IOU */ + hasOutstandingIOU: PropTypes.bool.isRequired, }), /** Whether the IOU is hovered so we can modify its style */ @@ -43,6 +46,12 @@ const IOUAction = (props) => { const launchDetailsModal = () => { Navigation.navigate(ROUTES.getIouDetailsRoute(props.chatReportID, props.action.originalMessage.IOUReportID)); }; + + const shouldShowIOUPreview = ( + props.isMostRecentIOUReportAction + && Boolean(props.action.originalMessage.IOUReportID) + && props.chatReport.hasOutstandingIOU) || props.action.originalMessage.type === 'pay'; + return ( <> { shouldAllowViewDetails={Boolean(props.action.originalMessage.IOUReportID)} onViewDetailsPressed={launchDetailsModal} /> - {((props.isMostRecentIOUReportAction && Boolean(props.action.originalMessage.IOUReportID)) - || (props.action.originalMessage.type === 'pay')) && ( - + {shouldShowIOUPreview && ( + )} ); diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 0a6d0767676d..0157dc590eff 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -897,7 +897,7 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho lastMessageText: optimisticIOUReportAction.message[0].text, lastMessageHtml: optimisticIOUReportAction.message[0].html, hasOutstandingIOU: false, - iouReportID: iouReport.reportID, + iouReportID: null, }, }, { @@ -939,8 +939,6 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { [optimisticIOUReportAction.sequenceNumber]: { - hasOutstandingIOU: true, - stateNum: CONST.REPORT.STATE_NUM.PROCESSING, pendingAction: null, errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.other'), From eedccb16acd2540a1ca7e9772881905399a0b826 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Thu, 8 Dec 2022 18:51:28 +0100 Subject: [PATCH 42/42] Use SET in sendMoney to save the iouReport Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 0157dc590eff..dd8194584c9b 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -794,7 +794,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType }, }, { - onyxMethod: CONST.ONYX.METHOD.MERGE, + onyxMethod: CONST.ONYX.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticIOUReport.reportID}`, value: optimisticIOUReport, },