From 28d1bceb584155aa6e9aa230ae50586c12633566 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Thu, 4 Dec 2025 23:51:03 +0530 Subject: [PATCH 1/6] move send Money functions to its on lib --- src/libs/actions/IOU/SendMoney.ts | 511 ++++++++++++++++++ src/libs/actions/{IOU.ts => IOU/index.ts} | 502 +---------------- .../iou/request/step/IOURequestStepAmount.tsx | 3 +- .../step/IOURequestStepConfirmation.tsx | 4 +- 4 files changed, 524 insertions(+), 496 deletions(-) create mode 100644 src/libs/actions/IOU/SendMoney.ts rename src/libs/actions/{IOU.ts => IOU/index.ts} (97%) diff --git a/src/libs/actions/IOU/SendMoney.ts b/src/libs/actions/IOU/SendMoney.ts new file mode 100644 index 000000000000..273f544ff857 --- /dev/null +++ b/src/libs/actions/IOU/SendMoney.ts @@ -0,0 +1,511 @@ +import type { PaymentMethodType } from "@components/KYCWall/types"; +import { isEmptyObject } from "@github/libs/isEmptyObject"; +import { WRITE_COMMANDS } from "@libs/API/types"; +import DateUtils from "@libs/DateUtils"; +import { getMicroSecondOnyxErrorWithTranslationKey } from "@libs/ErrorUtils"; +import { addSMSDomainIfPhoneNumber } from "@libs/PhoneNumber"; +import { getReportActionText, getReportActionHtml } from "@libs/ReportActionsUtils"; +import type { OptionData } from "@libs/ReportUtils"; +import { getParsedComment, getChatByParticipants, buildOptimisticChatReport, buildOptimisticIOUReport, buildOptimisticMoneyRequestEntities, buildOptimisticReportPreview } from "@libs/ReportUtils"; +import { buildOptimisticTransaction } from "@libs/TransactionUtils"; +import ONYXKEYS from "@src/ONYXKEYS"; +import type { Receipt } from "@src/types/onyx/Transaction"; +import type { OnyxEntry, OnyxUpdate } from "react-native-onyx"; +import Onyx from "react-native-onyx"; +import type * as OnyxTypes from '@src/types/onyx'; +import type { + SendMoneyParams, +} from '@libs/API/parameters'; +import CONST from "@src/CONST"; +import { notifyNewAction } from "@userActions/Report"; +import { dismissModalAndOpenReportInInboxTab } from "."; +import { Str } from "expensify-common"; +import type {Participant} from '@src/types/onyx/IOU'; +import * as API from '@libs/API'; +import playSound, {SOUNDS} from '@libs/Sound'; + + +type SendMoneyParamsData = { + params: SendMoneyParams; + optimisticData: OnyxUpdate[]; + successData: OnyxUpdate[]; + failureData: OnyxUpdate[]; +}; + + +/** + * @param managerID - Account ID of the person sending the money + * @param recipient - The user receiving the money + */ +function getSendMoneyParams({ + report, + quickAction, + amount, + currency, + commentParam, + paymentMethodType, + managerID, + recipient, + created, + merchant, + receipt, +}: { + report: OnyxEntry; + quickAction: OnyxEntry; + amount: number; + currency: string; + commentParam: string; + paymentMethodType: PaymentMethodType; + managerID: number; + recipient: Participant; + created?: string; + merchant?: string; + receipt?: Receipt; +}): SendMoneyParamsData { + const recipientEmail = addSMSDomainIfPhoneNumber(recipient.login ?? ''); + const recipientAccountID = Number(recipient.accountID); + const comment = getParsedComment(commentParam); + const newIOUReportDetails = JSON.stringify({ + amount, + currency, + requestorEmail: recipientEmail, + requestorAccountID: recipientAccountID, + comment, + idempotencyKey: Str.guid(), + ...(created && {created}), + ...(merchant && {merchant}), + }); + + let chatReport = !isEmptyObject(report) && report?.reportID ? report : getChatByParticipants([recipientAccountID, managerID]); + let isNewChat = false; + if (!chatReport) { + chatReport = buildOptimisticChatReport({ + participantList: [recipientAccountID, managerID], + }); + isNewChat = true; + } + const optimisticIOUReport = buildOptimisticIOUReport(recipientAccountID, managerID, amount, chatReport.reportID, currency, true); + + const optimisticTransaction = buildOptimisticTransaction({ + transactionParams: { + amount, + currency, + reportID: optimisticIOUReport.reportID, + comment, + created, + merchant, + receipt, + }, + }); + const optimisticTransactionData: OnyxUpdate = { + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.TRANSACTION}${optimisticTransaction.transactionID}`, + value: optimisticTransaction, + }; + + const [optimisticCreatedActionForChat, optimisticCreatedActionForIOUReport, optimisticIOUReportAction, optimisticTransactionThread, optimisticCreatedActionForTransactionThread] = + buildOptimisticMoneyRequestEntities({ + iouReport: optimisticIOUReport, + type: CONST.IOU.REPORT_ACTION_TYPE.PAY, + amount, + currency, + comment, + payeeEmail: recipientEmail, + participants: [recipient], + transactionID: optimisticTransaction.transactionID, + paymentType: paymentMethodType, + isSendMoneyFlow: true, + }); + + const reportPreviewAction = buildOptimisticReportPreview(chatReport, optimisticIOUReport); + + // 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 + const optimisticChatReportData: OnyxUpdate = isNewChat + ? { + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, + value: { + ...chatReport, + // Set and clear pending fields on the chat report + pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}, + lastReadTime: DateUtils.getDBTime(), + lastVisibleActionCreated: reportPreviewAction.created, + }, + } + : { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, + value: { + ...chatReport, + lastReadTime: DateUtils.getDBTime(), + lastVisibleActionCreated: reportPreviewAction.created, + }, + }; + const optimisticQuickActionData: OnyxUpdate = { + onyxMethod: Onyx.METHOD.SET, + key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, + value: { + action: CONST.QUICK_ACTIONS.SEND_MONEY, + chatReportID: chatReport.reportID, + isFirstQuickAction: isEmptyObject(quickAction), + }, + }; + const optimisticIOUReportData: OnyxUpdate = { + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticIOUReport.reportID}`, + value: { + ...optimisticIOUReport, + lastMessageText: getReportActionText(optimisticIOUReportAction), + lastMessageHtml: getReportActionHtml(optimisticIOUReportAction), + pendingFields: { + createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }, + }, + }; + const optimisticTransactionThreadData: OnyxUpdate = { + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticTransactionThread.reportID}`, + value: optimisticTransactionThread, + }; + const optimisticIOUReportActionsData: OnyxUpdate = { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticIOUReport.reportID}`, + value: { + [optimisticCreatedActionForIOUReport.reportActionID]: optimisticCreatedActionForIOUReport, + [optimisticIOUReportAction.reportActionID]: { + ...(optimisticIOUReportAction as OnyxTypes.ReportAction), + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }, + }, + }; + const optimisticChatReportActionsData: OnyxUpdate = { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [reportPreviewAction.reportActionID]: reportPreviewAction, + }, + }; + const optimisticTransactionThreadReportActionsData: OnyxUpdate | undefined = optimisticCreatedActionForTransactionThread + ? { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticTransactionThread.reportID}`, + value: {[optimisticCreatedActionForTransactionThread?.reportActionID]: optimisticCreatedActionForTransactionThread}, + } + : undefined; + + const optimisticMetaData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${chatReport.reportID}`, + value: { + isOptimisticReport: true, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${optimisticTransactionThread.reportID}`, + value: { + isOptimisticReport: true, + }, + }, + ]; + + const successData: OnyxUpdate[] = []; + + // Add optimistic personal details for recipient + let optimisticPersonalDetailListData: OnyxUpdate | null = null; + const optimisticPersonalDetailListAction = isNewChat + ? { + [recipientAccountID]: { + accountID: recipientAccountID, + // Disabling this line since participant.displayName can be an empty string + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + displayName: recipient.displayName || recipient.login, + login: recipient.login, + }, + } + : {}; + + const redundantParticipants: Record = {}; + if (!isEmptyObject(optimisticPersonalDetailListAction)) { + const successPersonalDetailListAction: Record = {}; + + // BE will send different participants. We clear the optimistic ones to avoid duplicated entries + for (const accountIDKey of Object.keys(optimisticPersonalDetailListAction)) { + const accountID = Number(accountIDKey); + successPersonalDetailListAction[accountID] = null; + redundantParticipants[accountID] = null; + } + + optimisticPersonalDetailListData = { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + value: optimisticPersonalDetailListAction, + }; + successData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + value: successPersonalDetailListAction, + }); + } + + successData.push( + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticIOUReport.reportID}`, + value: { + participants: redundantParticipants, + pendingFields: { + createChat: null, + }, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticTransactionThread.reportID}`, + value: { + participants: redundantParticipants, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${optimisticTransactionThread.reportID}`, + value: { + isOptimisticReport: false, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticIOUReport.reportID}`, + value: { + [optimisticCreatedActionForIOUReport.reportActionID]: {pendingAction: null}, + [optimisticIOUReportAction.reportActionID]: { + pendingAction: null, + }, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.TRANSACTION}${optimisticTransaction.transactionID}`, + value: {pendingAction: null}, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${chatReport.reportID}`, + value: { + isOptimisticReport: false, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [reportPreviewAction.reportActionID]: { + isOptimisticAction: null, + pendingAction: null, + childLastActorAccountID: reportPreviewAction.childLastActorAccountID, + }, + }, + }, + ); + + const failureData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.TRANSACTION}${optimisticTransaction.transactionID}`, + value: { + errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.other'), + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticTransactionThread.reportID}`, + value: { + errorFields: { + createChat: getMicroSecondOnyxErrorWithTranslationKey('report.genericCreateReportFailureMessage'), + }, + }, + }, + { + onyxMethod: Onyx.METHOD.SET, + key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, + value: quickAction ?? null, + }, + ]; + + if (optimisticCreatedActionForTransactionThread?.reportActionID) { + successData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticTransactionThread.reportID}`, + value: {[optimisticCreatedActionForTransactionThread?.reportActionID]: {pendingAction: null}}, + }); + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticTransactionThread.reportID}`, + value: {[optimisticCreatedActionForTransactionThread?.reportActionID]: {errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericCreateFailureMessage')}}, + }); + } + + // Now, let's add the data we need just when we are creating a new chat report + if (isNewChat) { + successData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, + value: {pendingFields: null, participants: redundantParticipants}, + }); + failureData.push( + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, + value: { + errorFields: { + createChat: getMicroSecondOnyxErrorWithTranslationKey('report.genericCreateReportFailureMessage'), + }, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticIOUReport.reportID}`, + value: { + [optimisticIOUReportAction.reportActionID]: { + errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericCreateFailureMessage'), + }, + }, + }, + ); + + const optimisticChatReportActionsValue = optimisticChatReportActionsData.value as Record; + + if (optimisticChatReportActionsValue) { + // Add an optimistic created action to the optimistic chat reportActions data + optimisticChatReportActionsValue[optimisticCreatedActionForChat.reportActionID] = optimisticCreatedActionForChat; + } + } else { + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticIOUReport.reportID}`, + value: { + [optimisticIOUReportAction.reportActionID]: { + errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.other'), + }, + }, + }); + } + + // @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830 + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const optimisticData: OnyxUpdate[] = [ + optimisticChatReportData, + optimisticQuickActionData, + optimisticIOUReportData, + optimisticChatReportActionsData, + optimisticIOUReportActionsData, + optimisticTransactionData, + optimisticTransactionThreadData, + ...optimisticMetaData, + ]; + + if (optimisticTransactionThreadReportActionsData) { + optimisticData.push(optimisticTransactionThreadReportActionsData); + } + if (!isEmptyObject(optimisticPersonalDetailListData)) { + optimisticData.push(optimisticPersonalDetailListData); + } + + return { + params: { + iouReportID: optimisticIOUReport.reportID, + chatReportID: chatReport.reportID, + reportActionID: optimisticIOUReportAction.reportActionID, + paymentMethodType, + transactionID: optimisticTransaction.transactionID, + newIOUReportDetails, + createdReportActionID: isNewChat ? optimisticCreatedActionForChat.reportActionID : undefined, + reportPreviewReportActionID: reportPreviewAction.reportActionID, + createdIOUReportActionID: optimisticCreatedActionForIOUReport.reportActionID, + transactionThreadReportID: optimisticTransactionThread.reportID, + createdReportActionIDForThread: optimisticCreatedActionForTransactionThread?.reportActionID, + receipt, + receiptState: receipt?.state, + }, + optimisticData, + successData, + failureData, + }; +} + +/** + * @param managerID - Account ID of the person sending the money + * @param recipient - The user receiving the money + */ +function sendMoneyElsewhere( + report: OnyxEntry, + quickAction: OnyxEntry, + amount: number, + currency: string, + comment: string, + managerID: number, + recipient: Participant, + created?: string, + merchant?: string, + receipt?: Receipt, +) { + const {params, optimisticData, successData, failureData} = getSendMoneyParams({ + report, + quickAction, + amount, + currency, + commentParam: comment, + paymentMethodType: CONST.IOU.PAYMENT_TYPE.ELSEWHERE, + managerID, + recipient, + created, + merchant, + receipt, + }); + playSound(SOUNDS.DONE); + API.write(WRITE_COMMANDS.SEND_MONEY_ELSEWHERE, params, {optimisticData, successData, failureData}); + + dismissModalAndOpenReportInInboxTab(params.chatReportID); + notifyNewAction(params.chatReportID, managerID); +} + +/** + * @param managerID - Account ID of the person sending the money + * @param recipient - The user receiving the money + */ +function sendMoneyWithWallet( + report: OnyxEntry, + quickAction: OnyxEntry, + amount: number, + currency: string, + comment: string, + managerID: number, + recipient: Participant | OptionData, + created?: string, + merchant?: string, + receipt?: Receipt, +) { + const {params, optimisticData, successData, failureData} = getSendMoneyParams({ + report, + quickAction, + amount, + currency, + commentParam: comment, + paymentMethodType: CONST.IOU.PAYMENT_TYPE.EXPENSIFY, + managerID, + recipient, + created, + merchant, + receipt, + }); + playSound(SOUNDS.DONE); + API.write(WRITE_COMMANDS.SEND_MONEY_WITH_WALLET, params, {optimisticData, successData, failureData}); + + dismissModalAndOpenReportInInboxTab(params.chatReportID); + notifyNewAction(params.chatReportID, managerID); +} + + +export {sendMoneyElsewhere, sendMoneyWithWallet}; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU/index.ts similarity index 97% rename from src/libs/actions/IOU.ts rename to src/libs/actions/IOU/index.ts index c40659b64f9f..7b69f433bfc1 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU/index.ts @@ -257,17 +257,17 @@ import type {OnyxData} from '@src/types/onyx/Request'; import type {SearchTransaction} from '@src/types/onyx/SearchResults'; import type {Comment, Receipt, ReceiptSource, Routes, SplitShares, TransactionChanges, TransactionCustomUnit, WaypointCollection} from '@src/types/onyx/Transaction'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; -import {clearByKey as clearPdfByOnyxKey} from './CachedPDFPaths'; -import {buildAddMembersToWorkspaceOnyxData, buildUpdateWorkspaceMembersRoleOnyxData} from './Policy/Member'; +import {clearByKey as clearPdfByOnyxKey} from '../CachedPDFPaths'; +import {buildAddMembersToWorkspaceOnyxData, buildUpdateWorkspaceMembersRoleOnyxData} from '../Policy/Member'; // eslint-disable-next-line @typescript-eslint/no-deprecated -import {buildOptimisticRecentlyUsedCurrencies, buildPolicyData, generatePolicyID} from './Policy/Policy'; -import {buildOptimisticPolicyRecentlyUsedTags, getPolicyTagsData} from './Policy/Tag'; -import type {GuidedSetupData} from './Report'; -import {buildInviteToRoomOnyxData, completeOnboarding, getCurrentUserAccountID, notifyNewAction, optimisticReportLastData} from './Report'; -import {clearAllRelatedReportActionErrors} from './ReportActions'; -import {sanitizeRecentWaypoints} from './Transaction'; -import {removeDraftSplitTransaction, removeDraftTransaction, removeDraftTransactions} from './TransactionEdit'; -import {getOnboardingMessages} from './Welcome/OnboardingFlow'; +import {buildOptimisticRecentlyUsedCurrencies, buildPolicyData, generatePolicyID} from '../Policy/Policy'; +import {buildOptimisticPolicyRecentlyUsedTags, getPolicyTagsData} from '../Policy/Tag'; +import type {GuidedSetupData} from '../Report'; +import {buildInviteToRoomOnyxData, completeOnboarding, getCurrentUserAccountID, notifyNewAction, optimisticReportLastData} from '../Report'; +import {clearAllRelatedReportActionErrors} from '../ReportActions'; +import {sanitizeRecentWaypoints} from '../Transaction'; +import {removeDraftSplitTransaction, removeDraftTransaction, removeDraftTransactions} from '../TransactionEdit'; +import {getOnboardingMessages} from '../Welcome/OnboardingFlow'; type IOURequestType = ValueOf; @@ -421,13 +421,6 @@ type PayMoneyRequestData = { failureData: OnyxUpdate[]; }; -type SendMoneyParamsData = { - params: SendMoneyParams; - optimisticData: OnyxUpdate[]; - successData: OnyxUpdate[]; - failureData: OnyxUpdate[]; -}; - type GPSPoint = { lat: number; long: number; @@ -9438,408 +9431,6 @@ function deleteTrackExpense({ return urlToNavigateBack; } -/** - * @param managerID - Account ID of the person sending the money - * @param recipient - The user receiving the money - */ -function getSendMoneyParams({ - report, - quickAction, - amount, - currency, - commentParam, - paymentMethodType, - managerID, - recipient, - created, - merchant, - receipt, -}: { - report: OnyxEntry; - quickAction: OnyxEntry; - amount: number; - currency: string; - commentParam: string; - paymentMethodType: PaymentMethodType; - managerID: number; - recipient: Participant; - created?: string; - merchant?: string; - receipt?: Receipt; -}): SendMoneyParamsData { - const recipientEmail = addSMSDomainIfPhoneNumber(recipient.login ?? ''); - const recipientAccountID = Number(recipient.accountID); - const comment = getParsedComment(commentParam); - const newIOUReportDetails = JSON.stringify({ - amount, - currency, - requestorEmail: recipientEmail, - requestorAccountID: recipientAccountID, - comment, - idempotencyKey: Str.guid(), - ...(created && {created}), - ...(merchant && {merchant}), - }); - - let chatReport = !isEmptyObject(report) && report?.reportID ? report : getChatByParticipants([recipientAccountID, managerID]); - let isNewChat = false; - if (!chatReport) { - chatReport = buildOptimisticChatReport({ - participantList: [recipientAccountID, managerID], - }); - isNewChat = true; - } - const optimisticIOUReport = buildOptimisticIOUReport(recipientAccountID, managerID, amount, chatReport.reportID, currency, true); - - const optimisticTransaction = buildOptimisticTransaction({ - transactionParams: { - amount, - currency, - reportID: optimisticIOUReport.reportID, - comment, - created, - merchant, - receipt, - }, - }); - const optimisticTransactionData: OnyxUpdate = { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.TRANSACTION}${optimisticTransaction.transactionID}`, - value: optimisticTransaction, - }; - - const [optimisticCreatedActionForChat, optimisticCreatedActionForIOUReport, optimisticIOUReportAction, optimisticTransactionThread, optimisticCreatedActionForTransactionThread] = - buildOptimisticMoneyRequestEntities({ - iouReport: optimisticIOUReport, - type: CONST.IOU.REPORT_ACTION_TYPE.PAY, - amount, - currency, - comment, - payeeEmail: recipientEmail, - participants: [recipient], - transactionID: optimisticTransaction.transactionID, - paymentType: paymentMethodType, - isSendMoneyFlow: true, - }); - - const reportPreviewAction = buildOptimisticReportPreview(chatReport, optimisticIOUReport); - - // 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 - const optimisticChatReportData: OnyxUpdate = isNewChat - ? { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, - value: { - ...chatReport, - // Set and clear pending fields on the chat report - pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}, - lastReadTime: DateUtils.getDBTime(), - lastVisibleActionCreated: reportPreviewAction.created, - }, - } - : { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, - value: { - ...chatReport, - lastReadTime: DateUtils.getDBTime(), - lastVisibleActionCreated: reportPreviewAction.created, - }, - }; - const optimisticQuickActionData: OnyxUpdate = { - onyxMethod: Onyx.METHOD.SET, - key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, - value: { - action: CONST.QUICK_ACTIONS.SEND_MONEY, - chatReportID: chatReport.reportID, - isFirstQuickAction: isEmptyObject(quickAction), - }, - }; - const optimisticIOUReportData: OnyxUpdate = { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticIOUReport.reportID}`, - value: { - ...optimisticIOUReport, - lastMessageText: getReportActionText(optimisticIOUReportAction), - lastMessageHtml: getReportActionHtml(optimisticIOUReportAction), - pendingFields: { - createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - }, - }, - }; - const optimisticTransactionThreadData: OnyxUpdate = { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticTransactionThread.reportID}`, - value: optimisticTransactionThread, - }; - const optimisticIOUReportActionsData: OnyxUpdate = { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticIOUReport.reportID}`, - value: { - [optimisticCreatedActionForIOUReport.reportActionID]: optimisticCreatedActionForIOUReport, - [optimisticIOUReportAction.reportActionID]: { - ...(optimisticIOUReportAction as OnyxTypes.ReportAction), - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - }, - }, - }; - const optimisticChatReportActionsData: OnyxUpdate = { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, - value: { - [reportPreviewAction.reportActionID]: reportPreviewAction, - }, - }; - const optimisticTransactionThreadReportActionsData: OnyxUpdate | undefined = optimisticCreatedActionForTransactionThread - ? { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticTransactionThread.reportID}`, - value: {[optimisticCreatedActionForTransactionThread?.reportActionID]: optimisticCreatedActionForTransactionThread}, - } - : undefined; - - const optimisticMetaData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${chatReport.reportID}`, - value: { - isOptimisticReport: true, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${optimisticTransactionThread.reportID}`, - value: { - isOptimisticReport: true, - }, - }, - ]; - - const successData: OnyxUpdate[] = []; - - // Add optimistic personal details for recipient - let optimisticPersonalDetailListData: OnyxUpdate | null = null; - const optimisticPersonalDetailListAction = isNewChat - ? { - [recipientAccountID]: { - accountID: recipientAccountID, - // Disabling this line since participant.displayName can be an empty string - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - displayName: recipient.displayName || recipient.login, - login: recipient.login, - }, - } - : {}; - - const redundantParticipants: Record = {}; - if (!isEmptyObject(optimisticPersonalDetailListAction)) { - const successPersonalDetailListAction: Record = {}; - - // BE will send different participants. We clear the optimistic ones to avoid duplicated entries - for (const accountIDKey of Object.keys(optimisticPersonalDetailListAction)) { - const accountID = Number(accountIDKey); - successPersonalDetailListAction[accountID] = null; - redundantParticipants[accountID] = null; - } - - optimisticPersonalDetailListData = { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - value: optimisticPersonalDetailListAction, - }; - successData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - value: successPersonalDetailListAction, - }); - } - - successData.push( - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticIOUReport.reportID}`, - value: { - participants: redundantParticipants, - pendingFields: { - createChat: null, - }, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticTransactionThread.reportID}`, - value: { - participants: redundantParticipants, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${optimisticTransactionThread.reportID}`, - value: { - isOptimisticReport: false, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticIOUReport.reportID}`, - value: { - [optimisticCreatedActionForIOUReport.reportActionID]: {pendingAction: null}, - [optimisticIOUReportAction.reportActionID]: { - pendingAction: null, - }, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.TRANSACTION}${optimisticTransaction.transactionID}`, - value: {pendingAction: null}, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${chatReport.reportID}`, - value: { - isOptimisticReport: false, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, - value: { - [reportPreviewAction.reportActionID]: { - isOptimisticAction: null, - pendingAction: null, - childLastActorAccountID: reportPreviewAction.childLastActorAccountID, - }, - }, - }, - ); - - const failureData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.TRANSACTION}${optimisticTransaction.transactionID}`, - value: { - errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.other'), - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticTransactionThread.reportID}`, - value: { - errorFields: { - createChat: getMicroSecondOnyxErrorWithTranslationKey('report.genericCreateReportFailureMessage'), - }, - }, - }, - { - onyxMethod: Onyx.METHOD.SET, - key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, - value: quickAction ?? null, - }, - ]; - - if (optimisticCreatedActionForTransactionThread?.reportActionID) { - successData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticTransactionThread.reportID}`, - value: {[optimisticCreatedActionForTransactionThread?.reportActionID]: {pendingAction: null}}, - }); - failureData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticTransactionThread.reportID}`, - value: {[optimisticCreatedActionForTransactionThread?.reportActionID]: {errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericCreateFailureMessage')}}, - }); - } - - // Now, let's add the data we need just when we are creating a new chat report - if (isNewChat) { - successData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, - value: {pendingFields: null, participants: redundantParticipants}, - }); - failureData.push( - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, - value: { - errorFields: { - createChat: getMicroSecondOnyxErrorWithTranslationKey('report.genericCreateReportFailureMessage'), - }, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticIOUReport.reportID}`, - value: { - [optimisticIOUReportAction.reportActionID]: { - errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericCreateFailureMessage'), - }, - }, - }, - ); - - const optimisticChatReportActionsValue = optimisticChatReportActionsData.value as Record; - - if (optimisticChatReportActionsValue) { - // Add an optimistic created action to the optimistic chat reportActions data - optimisticChatReportActionsValue[optimisticCreatedActionForChat.reportActionID] = optimisticCreatedActionForChat; - } - } else { - failureData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticIOUReport.reportID}`, - value: { - [optimisticIOUReportAction.reportActionID]: { - errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.other'), - }, - }, - }); - } - - // @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830 - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const optimisticData: OnyxUpdate[] = [ - optimisticChatReportData, - optimisticQuickActionData, - optimisticIOUReportData, - optimisticChatReportActionsData, - optimisticIOUReportActionsData, - optimisticTransactionData, - optimisticTransactionThreadData, - ...optimisticMetaData, - ]; - - if (optimisticTransactionThreadReportActionsData) { - optimisticData.push(optimisticTransactionThreadReportActionsData); - } - if (!isEmptyObject(optimisticPersonalDetailListData)) { - optimisticData.push(optimisticPersonalDetailListData); - } - - return { - params: { - iouReportID: optimisticIOUReport.reportID, - chatReportID: chatReport.reportID, - reportActionID: optimisticIOUReportAction.reportActionID, - paymentMethodType, - transactionID: optimisticTransaction.transactionID, - newIOUReportDetails, - createdReportActionID: isNewChat ? optimisticCreatedActionForChat.reportActionID : undefined, - reportPreviewReportActionID: reportPreviewAction.reportActionID, - createdIOUReportActionID: optimisticCreatedActionForIOUReport.reportActionID, - transactionThreadReportID: optimisticTransactionThread.reportID, - createdReportActionIDForThread: optimisticCreatedActionForTransactionThread?.reportActionID, - receipt, - receiptState: receipt?.state, - }, - optimisticData, - successData, - failureData, - }; -} - type OptimisticHoldReportExpenseActionID = { optimisticReportActionID: string; oldReportActionID: string; @@ -10434,77 +10025,6 @@ function getPayMoneyRequestParams({ }; } -/** - * @param managerID - Account ID of the person sending the money - * @param recipient - The user receiving the money - */ -function sendMoneyElsewhere( - report: OnyxEntry, - quickAction: OnyxEntry, - amount: number, - currency: string, - comment: string, - managerID: number, - recipient: Participant, - created?: string, - merchant?: string, - receipt?: Receipt, -) { - const {params, optimisticData, successData, failureData} = getSendMoneyParams({ - report, - quickAction, - amount, - currency, - commentParam: comment, - paymentMethodType: CONST.IOU.PAYMENT_TYPE.ELSEWHERE, - managerID, - recipient, - created, - merchant, - receipt, - }); - playSound(SOUNDS.DONE); - API.write(WRITE_COMMANDS.SEND_MONEY_ELSEWHERE, params, {optimisticData, successData, failureData}); - - dismissModalAndOpenReportInInboxTab(params.chatReportID); - notifyNewAction(params.chatReportID, managerID); -} - -/** - * @param managerID - Account ID of the person sending the money - * @param recipient - The user receiving the money - */ -function sendMoneyWithWallet( - report: OnyxEntry, - quickAction: OnyxEntry, - amount: number, - currency: string, - comment: string, - managerID: number, - recipient: Participant | OptionData, - created?: string, - merchant?: string, - receipt?: Receipt, -) { - const {params, optimisticData, successData, failureData} = getSendMoneyParams({ - report, - quickAction, - amount, - currency, - commentParam: comment, - paymentMethodType: CONST.IOU.PAYMENT_TYPE.EXPENSIFY, - managerID, - recipient, - created, - merchant, - receipt, - }); - playSound(SOUNDS.DONE); - API.write(WRITE_COMMANDS.SEND_MONEY_WITH_WALLET, params, {optimisticData, successData, failureData}); - - dismissModalAndOpenReportInInboxTab(params.chatReportID); - notifyNewAction(params.chatReportID, managerID); -} function canApproveIOU(iouReport: OnyxTypes.OnyxInputOrEntry, policy: OnyxTypes.OnyxInputOrEntry, iouTransactions?: OnyxTypes.Transaction[]) { // Only expense reports can be approved @@ -15111,8 +14631,6 @@ export { resetDraftTransactionsCustomUnit, savePreferredPaymentMethod, sendInvoice, - sendMoneyElsewhere, - sendMoneyWithWallet, setCustomUnitRateID, setCustomUnitID, removeSubrate, diff --git a/src/pages/iou/request/step/IOURequestStepAmount.tsx b/src/pages/iou/request/step/IOURequestStepAmount.tsx index 60600960c0ea..e6d7919dfbee 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.tsx +++ b/src/pages/iou/request/step/IOURequestStepAmount.tsx @@ -26,8 +26,6 @@ import { getMoneyRequestParticipantsFromReport, requestMoney, resetSplitShares, - sendMoneyElsewhere, - sendMoneyWithWallet, setDraftSplitTransaction, setMoneyRequestAmount, setMoneyRequestParticipantsFromReport, @@ -48,6 +46,7 @@ import StepScreenWrapper from './StepScreenWrapper'; import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; import withWritableReportOrNotFound from './withWritableReportOrNotFound'; +import { sendMoneyElsewhere, sendMoneyWithWallet } from '@userActions/IOU/SendMoney'; type AmountParams = { amount: string; diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index f49fb7d21911..c3e3e9dfe096 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -78,8 +78,6 @@ import { getReceiverType, requestMoney as requestMoneyIOUActions, sendInvoice, - sendMoneyElsewhere, - sendMoneyWithWallet, setMoneyRequestBillable, setMoneyRequestCategory, setMoneyRequestReceipt, @@ -111,6 +109,8 @@ import type {WithFullTransactionOrNotFoundProps} from './withFullTransactionOrNo import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; import withWritableReportOrNotFound from './withWritableReportOrNotFound'; +import { sendMoneyElsewhere, sendMoneyWithWallet } from '@userActions/IOU/SendMoney'; + type IOURequestStepConfirmationProps = WithWritableReportOrNotFoundProps & WithFullTransactionOrNotFoundProps; From ad5847d70e8148d3191a2ebab54962c1bab22595 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Mon, 15 Dec 2025 14:57:33 +0530 Subject: [PATCH 2/6] code cleanup --- src/libs/actions/IOU/SendMoney.ts | 54 ++++++++++++++++--------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/libs/actions/IOU/SendMoney.ts b/src/libs/actions/IOU/SendMoney.ts index 273f544ff857..8557897b0fc6 100644 --- a/src/libs/actions/IOU/SendMoney.ts +++ b/src/libs/actions/IOU/SendMoney.ts @@ -1,29 +1,33 @@ -import type { PaymentMethodType } from "@components/KYCWall/types"; -import { isEmptyObject } from "@github/libs/isEmptyObject"; -import { WRITE_COMMANDS } from "@libs/API/types"; -import DateUtils from "@libs/DateUtils"; -import { getMicroSecondOnyxErrorWithTranslationKey } from "@libs/ErrorUtils"; -import { addSMSDomainIfPhoneNumber } from "@libs/PhoneNumber"; -import { getReportActionText, getReportActionHtml } from "@libs/ReportActionsUtils"; -import type { OptionData } from "@libs/ReportUtils"; -import { getParsedComment, getChatByParticipants, buildOptimisticChatReport, buildOptimisticIOUReport, buildOptimisticMoneyRequestEntities, buildOptimisticReportPreview } from "@libs/ReportUtils"; -import { buildOptimisticTransaction } from "@libs/TransactionUtils"; -import ONYXKEYS from "@src/ONYXKEYS"; -import type { Receipt } from "@src/types/onyx/Transaction"; -import type { OnyxEntry, OnyxUpdate } from "react-native-onyx"; -import Onyx from "react-native-onyx"; -import type * as OnyxTypes from '@src/types/onyx'; -import type { - SendMoneyParams, -} from '@libs/API/parameters'; -import CONST from "@src/CONST"; -import { notifyNewAction } from "@userActions/Report"; -import { dismissModalAndOpenReportInInboxTab } from "."; -import { Str } from "expensify-common"; -import type {Participant} from '@src/types/onyx/IOU'; +import {Str} from 'expensify-common'; +import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx'; +import Onyx from 'react-native-onyx'; +import type {PaymentMethodType} from '@components/KYCWall/types'; +import {isEmptyObject} from '@github/libs/isEmptyObject'; import * as API from '@libs/API'; +import type {SendMoneyParams} from '@libs/API/parameters'; +import {WRITE_COMMANDS} from '@libs/API/types'; +import DateUtils from '@libs/DateUtils'; +import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils'; +import {addSMSDomainIfPhoneNumber} from '@libs/PhoneNumber'; +import {getReportActionHtml, getReportActionText} from '@libs/ReportActionsUtils'; +import type {OptionData} from '@libs/ReportUtils'; +import { + buildOptimisticChatReport, + buildOptimisticIOUReport, + buildOptimisticMoneyRequestEntities, + buildOptimisticReportPreview, + getChatByParticipants, + getParsedComment, +} from '@libs/ReportUtils'; import playSound, {SOUNDS} from '@libs/Sound'; - +import {buildOptimisticTransaction} from '@libs/TransactionUtils'; +import {notifyNewAction} from '@userActions/Report'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type * as OnyxTypes from '@src/types/onyx'; +import type {Participant} from '@src/types/onyx/IOU'; +import type {Receipt} from '@src/types/onyx/Transaction'; +import {dismissModalAndOpenReportInInboxTab} from '.'; type SendMoneyParamsData = { params: SendMoneyParams; @@ -32,7 +36,6 @@ type SendMoneyParamsData = { failureData: OnyxUpdate[]; }; - /** * @param managerID - Account ID of the person sending the money * @param recipient - The user receiving the money @@ -507,5 +510,4 @@ function sendMoneyWithWallet( notifyNewAction(params.chatReportID, managerID); } - export {sendMoneyElsewhere, sendMoneyWithWallet}; From 5a3ec97a60a02f415f762ff54588d254f9058be6 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Mon, 15 Dec 2025 15:00:13 +0530 Subject: [PATCH 3/6] Prettier fixes --- src/pages/iou/request/step/IOURequestStepAmount.tsx | 2 +- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepAmount.tsx b/src/pages/iou/request/step/IOURequestStepAmount.tsx index f3326c9c77e5..2d5c133775c5 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.tsx +++ b/src/pages/iou/request/step/IOURequestStepAmount.tsx @@ -36,6 +36,7 @@ import { trackExpense, updateMoneyRequestAmountAndCurrency, } from '@userActions/IOU'; +import {sendMoneyElsewhere, sendMoneyWithWallet} from '@userActions/IOU/SendMoney'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -48,7 +49,6 @@ import StepScreenWrapper from './StepScreenWrapper'; import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; import withWritableReportOrNotFound from './withWritableReportOrNotFound'; -import { sendMoneyElsewhere, sendMoneyWithWallet } from '@userActions/IOU/SendMoney'; type AmountParams = { amount: string; diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index b210525cc2be..6d85317ff495 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -90,6 +90,7 @@ import { trackExpense as trackExpenseIOUActions, updateLastLocationPermissionPrompt, } from '@userActions/IOU'; +import {sendMoneyElsewhere, sendMoneyWithWallet} from '@userActions/IOU/SendMoney'; import {openDraftWorkspaceRequest} from '@userActions/Policy/Policy'; import {removeDraftTransaction, removeDraftTransactions, replaceDefaultDraftTransaction} from '@userActions/TransactionEdit'; import CONST from '@src/CONST'; @@ -109,8 +110,6 @@ import type {WithFullTransactionOrNotFoundProps} from './withFullTransactionOrNo import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; import withWritableReportOrNotFound from './withWritableReportOrNotFound'; -import { sendMoneyElsewhere, sendMoneyWithWallet } from '@userActions/IOU/SendMoney'; - type IOURequestStepConfirmationProps = WithWritableReportOrNotFoundProps & WithFullTransactionOrNotFoundProps; From 37f8a8a4f62ff0d9b877175590ab5fec8a2a5601 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Mon, 15 Dec 2025 15:33:55 +0530 Subject: [PATCH 4/6] Fix lint --- src/libs/actions/IOU/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index c26ab2ff7b4c..f6f7db6f7354 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -1,6 +1,6 @@ /* eslint-disable max-lines */ import {format} from 'date-fns'; -import {fastMerge, Str} from 'expensify-common'; +import {fastMerge} from 'expensify-common'; import cloneDeep from 'lodash/cloneDeep'; // eslint-disable-next-line you-dont-need-lodash-underscore/union-by import lodashUnionBy from 'lodash/unionBy'; @@ -36,7 +36,6 @@ import type { RetractReportParams, RevertSplitTransactionParams, SendInvoiceParams, - SendMoneyParams, SetNameValuePairParams, ShareTrackedExpenseParams, SplitBillParams, @@ -115,7 +114,7 @@ import { isMoneyRequestAction, isReportPreviewAction, } from '@libs/ReportActionsUtils'; -import type {OptimisticChatReport, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptionData, TransactionDetails} from '@libs/ReportUtils'; +import type {OptimisticChatReport, OptimisticCreatedReportAction, OptimisticIOUReportAction, TransactionDetails} from '@libs/ReportUtils'; import { buildOptimisticActionableTrackExpenseWhisper, buildOptimisticAddCommentReportAction, @@ -10101,7 +10100,6 @@ function getPayMoneyRequestParams({ }; } - function canApproveIOU(iouReport: OnyxTypes.OnyxInputOrEntry, policy: OnyxTypes.OnyxInputOrEntry, iouTransactions?: OnyxTypes.Transaction[]) { // Only expense reports can be approved if (!isExpenseReport(iouReport) || !(policy && isPaidGroupPolicy(policy))) { From 069fc39ec8b781528500c394dae860518a34950d Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Mon, 15 Dec 2025 16:27:17 +0530 Subject: [PATCH 5/6] Fix imports --- src/libs/actions/IOU/index.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index f6f7db6f7354..270fe10c139e 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -237,6 +237,17 @@ import { removeTransactionFromDuplicateTransactionViolation, } from '@libs/TransactionUtils'; import ViolationsUtils from '@libs/Violations/ViolationsUtils'; +import {clearByKey as clearPdfByOnyxKey} from '@userActions/CachedPDFPaths'; +import {buildAddMembersToWorkspaceOnyxData, buildUpdateWorkspaceMembersRoleOnyxData} from '@userActions/Policy/Member'; +// eslint-disable-next-line @typescript-eslint/no-deprecated +import {buildOptimisticRecentlyUsedCurrencies, buildPolicyData, generatePolicyID} from '@userActions/Policy/Policy'; +import {buildOptimisticPolicyRecentlyUsedTags, getPolicyTagsData} from '@userActions/Policy/Tag'; +import type {GuidedSetupData} from '@userActions/Report'; +import {buildInviteToRoomOnyxData, completeOnboarding, getCurrentUserAccountID, notifyNewAction, optimisticReportLastData} from '@userActions/Report'; +import {clearAllRelatedReportActionErrors} from '@userActions/ReportActions'; +import {sanitizeRecentWaypoints} from '@userActions/Transaction'; +import {removeDraftSplitTransaction, removeDraftTransaction, removeDraftTransactions} from '@userActions/TransactionEdit'; +import {getOnboardingMessages} from '@userActions/Welcome/OnboardingFlow'; import type {IOUAction, IOUActionParams, IOUType} from '@src/CONST'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; @@ -257,17 +268,6 @@ import type {OnyxData} from '@src/types/onyx/Request'; import type {SearchTransaction} from '@src/types/onyx/SearchResults'; import type {Comment, Receipt, ReceiptSource, Routes, SplitShares, TransactionChanges, TransactionCustomUnit, WaypointCollection} from '@src/types/onyx/Transaction'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; -import {clearByKey as clearPdfByOnyxKey} from '../CachedPDFPaths'; -import {buildAddMembersToWorkspaceOnyxData, buildUpdateWorkspaceMembersRoleOnyxData} from '../Policy/Member'; -// eslint-disable-next-line @typescript-eslint/no-deprecated -import {buildOptimisticRecentlyUsedCurrencies, buildPolicyData, generatePolicyID} from '../Policy/Policy'; -import {buildOptimisticPolicyRecentlyUsedTags, getPolicyTagsData} from '../Policy/Tag'; -import type {GuidedSetupData} from '../Report'; -import {buildInviteToRoomOnyxData, completeOnboarding, getCurrentUserAccountID, notifyNewAction, optimisticReportLastData} from '../Report'; -import {clearAllRelatedReportActionErrors} from '../ReportActions'; -import {sanitizeRecentWaypoints} from '../Transaction'; -import {removeDraftSplitTransaction, removeDraftTransaction, removeDraftTransactions} from '../TransactionEdit'; -import {getOnboardingMessages} from '../Welcome/OnboardingFlow'; type IOURequestType = ValueOf; From 3536de8f1097802e15aabe5e22fadf27376645c7 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Sat, 27 Dec 2025 17:50:23 +0530 Subject: [PATCH 6/6] fix imports --- src/libs/actions/IOU/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index 5cba667e0ebe..991a123bab9d 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -1,6 +1,6 @@ /* eslint-disable max-lines */ import {eachDayOfInterval, format} from 'date-fns'; -import {fastMerge, Str} from 'expensify-common'; +import {fastMerge} from 'expensify-common'; import cloneDeep from 'lodash/cloneDeep'; // eslint-disable-next-line you-dont-need-lodash-underscore/union-by import lodashUnionBy from 'lodash/unionBy';