From 7d499891a8879be4ef81b86f02493c8332a6daa1 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 11 Apr 2024 11:41:30 +0200 Subject: [PATCH 1/7] remove unneeded condition --- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 897af48f0573..4273e7387457 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -236,7 +236,7 @@ function IOURequestStepConfirmation({ const createDistanceRequest = useCallback( (selectedParticipants: Participant[], trimmedComment: string) => { - if (!report || !transaction) { + if (!transaction) { return; } IOU.createDistanceRequest( @@ -433,7 +433,7 @@ function IOURequestStepConfirmation({ const participant = participants?.[0]; - if (!participant || !report || !transaction?.amount || !currency) { + if (!participant || !transaction?.amount || !currency) { return; } From 70c5d28035244839c617e7bf7e0f6c9ceb7bdb34 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 11 Apr 2024 11:51:26 +0200 Subject: [PATCH 2/7] fix types --- src/libs/actions/IOU.ts | 6 +++--- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index c2d462bbc4a8..4bf09ec6e6b2 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1491,7 +1491,7 @@ function getTrackExpenseInformation( /** Requests money based on a distance (e.g. mileage from a map) */ function createDistanceRequest( - report: OnyxTypes.Report, + report: OnyxTypes.Report | EmptyObject, participant: Participant, comment: string, created: string, @@ -4768,7 +4768,7 @@ function getPayMoneyRequestParams( * @param managerID - Account ID of the person sending the money * @param recipient - The user receiving the money */ -function sendMoneyElsewhere(report: OnyxTypes.Report, amount: number, currency: string, comment: string, managerID: number, recipient: Participant) { +function sendMoneyElsewhere(report: OnyxTypes.Report | EmptyObject, amount: number, currency: string, comment: string, managerID: number, recipient: Participant) { const {params, optimisticData, successData, failureData} = getSendMoneyParams(report, amount, currency, comment, CONST.IOU.PAYMENT_TYPE.ELSEWHERE, managerID, recipient); API.write(WRITE_COMMANDS.SEND_MONEY_ELSEWHERE, params, {optimisticData, successData, failureData}); @@ -4782,7 +4782,7 @@ function sendMoneyElsewhere(report: OnyxTypes.Report, amount: number, currency: * @param managerID - Account ID of the person sending the money * @param recipient - The user receiving the money */ -function sendMoneyWithWallet(report: OnyxTypes.Report, amount: number, currency: string, comment: string, managerID: number, recipient: Participant | ReportUtils.OptionData) { +function sendMoneyWithWallet(report: OnyxTypes.Report | EmptyObject, amount: number, currency: string, comment: string, managerID: number, recipient: Participant | ReportUtils.OptionData) { const {params, optimisticData, successData, failureData} = getSendMoneyParams(report, amount, currency, comment, CONST.IOU.PAYMENT_TYPE.EXPENSIFY, managerID, recipient); API.write(WRITE_COMMANDS.SEND_MONEY_WITH_WALLET, params, {optimisticData, successData, failureData}); diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 4273e7387457..20a76d878ffe 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -240,7 +240,7 @@ function IOURequestStepConfirmation({ return; } IOU.createDistanceRequest( - report, + report ?? {}, selectedParticipants[0], trimmedComment, transaction.created, @@ -438,12 +438,12 @@ function IOURequestStepConfirmation({ } if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) { - IOU.sendMoneyElsewhere(report, transaction.amount, currency, trimmedComment, currentUserPersonalDetails.accountID, participant); + IOU.sendMoneyElsewhere(report ?? {}, transaction.amount, currency, trimmedComment, currentUserPersonalDetails.accountID, participant); return; } if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) { - IOU.sendMoneyWithWallet(report, transaction.amount, currency, trimmedComment, currentUserPersonalDetails.accountID, participant); + IOU.sendMoneyWithWallet(report ?? {}, transaction.amount, currency, trimmedComment, currentUserPersonalDetails.accountID, participant); } }, [transaction?.amount, transaction?.comment, transaction?.currency, participants, currentUserPersonalDetails.accountID, report], From e23539afe217b1901f1b3f11e600d66fdd860bfe Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 11 Apr 2024 12:00:15 +0200 Subject: [PATCH 3/7] typescript --- src/libs/actions/IOU.ts | 6 +++--- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 4bf09ec6e6b2..63d1e25ff159 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1491,7 +1491,7 @@ function getTrackExpenseInformation( /** Requests money based on a distance (e.g. mileage from a map) */ function createDistanceRequest( - report: OnyxTypes.Report | EmptyObject, + report: OnyxEntry, participant: Participant, comment: string, created: string, @@ -4768,7 +4768,7 @@ function getPayMoneyRequestParams( * @param managerID - Account ID of the person sending the money * @param recipient - The user receiving the money */ -function sendMoneyElsewhere(report: OnyxTypes.Report | EmptyObject, amount: number, currency: string, comment: string, managerID: number, recipient: Participant) { +function sendMoneyElsewhere(report: OnyxEntry, amount: number, currency: string, comment: string, managerID: number, recipient: Participant) { const {params, optimisticData, successData, failureData} = getSendMoneyParams(report, amount, currency, comment, CONST.IOU.PAYMENT_TYPE.ELSEWHERE, managerID, recipient); API.write(WRITE_COMMANDS.SEND_MONEY_ELSEWHERE, params, {optimisticData, successData, failureData}); @@ -4782,7 +4782,7 @@ function sendMoneyElsewhere(report: OnyxTypes.Report | EmptyObject, amount: numb * @param managerID - Account ID of the person sending the money * @param recipient - The user receiving the money */ -function sendMoneyWithWallet(report: OnyxTypes.Report | EmptyObject, amount: number, currency: string, comment: string, managerID: number, recipient: Participant | ReportUtils.OptionData) { +function sendMoneyWithWallet(report: OnyxEntry, amount: number, currency: string, comment: string, managerID: number, recipient: Participant | ReportUtils.OptionData) { const {params, optimisticData, successData, failureData} = getSendMoneyParams(report, amount, currency, comment, CONST.IOU.PAYMENT_TYPE.EXPENSIFY, managerID, recipient); API.write(WRITE_COMMANDS.SEND_MONEY_WITH_WALLET, params, {optimisticData, successData, failureData}); diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 20a76d878ffe..4273e7387457 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -240,7 +240,7 @@ function IOURequestStepConfirmation({ return; } IOU.createDistanceRequest( - report ?? {}, + report, selectedParticipants[0], trimmedComment, transaction.created, @@ -438,12 +438,12 @@ function IOURequestStepConfirmation({ } if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) { - IOU.sendMoneyElsewhere(report ?? {}, transaction.amount, currency, trimmedComment, currentUserPersonalDetails.accountID, participant); + IOU.sendMoneyElsewhere(report, transaction.amount, currency, trimmedComment, currentUserPersonalDetails.accountID, participant); return; } if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) { - IOU.sendMoneyWithWallet(report ?? {}, transaction.amount, currency, trimmedComment, currentUserPersonalDetails.accountID, participant); + IOU.sendMoneyWithWallet(report, transaction.amount, currency, trimmedComment, currentUserPersonalDetails.accountID, participant); } }, [transaction?.amount, transaction?.comment, transaction?.currency, participants, currentUserPersonalDetails.accountID, report], From b03bf8f3830d57e60c7ba937505b9b262e1c7c6d Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 11 Apr 2024 12:18:04 +0200 Subject: [PATCH 4/7] more tyopescript --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 63d1e25ff159..c1c9bbfba106 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4313,7 +4313,7 @@ function deleteTrackExpense(chatReportID: string, transactionID: string, reportA * @param recipient - The user receiving the money */ function getSendMoneyParams( - report: OnyxTypes.Report, + report: OnyxEntry | EmptyObject, amount: number, currency: string, comment: string, From 3494d3a64356773a14f052fd6d5b0f75bf919340 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 11 Apr 2024 12:30:02 +0200 Subject: [PATCH 5/7] more typescript --- src/libs/actions/IOU.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index c1c9bbfba106..46fafb7a4405 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1508,8 +1508,8 @@ function createDistanceRequest( ) { // If the report is an iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); - const currentChatReport = isMoneyRequestReport ? ReportUtils.getReport(report.chatReportID) : report; - const moneyRequestReportID = isMoneyRequestReport ? report.reportID : ''; + const currentChatReport = isMoneyRequestReport ? ReportUtils.getReport(report?.chatReportID) : report; + const moneyRequestReportID = isMoneyRequestReport ? report?.reportID : ''; const currentCreated = DateUtils.enrichMoneyRequestTimestamp(created); const optimisticReceipt: Receipt = { @@ -1569,7 +1569,7 @@ function createDistanceRequest( }; API.write(WRITE_COMMANDS.CREATE_DISTANCE_REQUEST, parameters, onyxData); - Navigation.dismissModal(isMoneyRequestReport ? report.reportID : chatReport.reportID); + Navigation.dismissModal(isMoneyRequestReport ? report?.reportID : chatReport.reportID); Report.notifyNewAction(chatReport.reportID, userAccountID); } @@ -4332,11 +4332,8 @@ function getSendMoneyParams( idempotencyKey: Str.guid(), }); - let chatReport = report.reportID ? report : null; + let chatReport = report?.reportID ? report : ReportUtils.getChatByParticipants([recipientAccountID]);; let isNewChat = false; - if (!chatReport) { - chatReport = ReportUtils.getChatByParticipants([recipientAccountID]); - } if (!chatReport) { chatReport = ReportUtils.buildOptimisticChatReport([recipientAccountID]); isNewChat = true; From cc077605195c38de45b922f5d56fb0d5e9c4fcd8 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 11 Apr 2024 12:37:18 +0200 Subject: [PATCH 6/7] I hate typescript --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 46fafb7a4405..ee0eb0ecb618 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4332,7 +4332,7 @@ function getSendMoneyParams( idempotencyKey: Str.guid(), }); - let chatReport = report?.reportID ? report : ReportUtils.getChatByParticipants([recipientAccountID]);; + let chatReport = !isEmptyObject(report) && report?.reportID ? report : ReportUtils.getChatByParticipants([recipientAccountID]);; let isNewChat = false; if (!chatReport) { chatReport = ReportUtils.buildOptimisticChatReport([recipientAccountID]); From 36c6c5b64ac91d5de2432fa720e8c0bacbbddf8f Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 11 Apr 2024 12:50:14 +0200 Subject: [PATCH 7/7] prettier --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index ee0eb0ecb618..93736adf183c 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4332,7 +4332,7 @@ function getSendMoneyParams( idempotencyKey: Str.guid(), }); - let chatReport = !isEmptyObject(report) && report?.reportID ? report : ReportUtils.getChatByParticipants([recipientAccountID]);; + let chatReport = !isEmptyObject(report) && report?.reportID ? report : ReportUtils.getChatByParticipants([recipientAccountID]); let isNewChat = false; if (!chatReport) { chatReport = ReportUtils.buildOptimisticChatReport([recipientAccountID]);