diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 9abe98106d38..e0c2fb339f52 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1,5 +1,6 @@ import {format} from 'date-fns'; import {fastMerge, Str} from 'expensify-common'; +import {InteractionManager} from 'react-native'; import type {NullishDeep, OnyxCollection, OnyxEntry, OnyxInputValue, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {PartialDeep, SetRequired, ValueOf} from 'type-fest'; @@ -74,6 +75,7 @@ import * as Policy from './Policy/Policy'; import * as Tag from './Policy/Tag'; import * as Report from './Report'; import {getRecentWaypoints, sanitizeRecentWaypoints} from './Transaction'; +import * as TransactionEdit from './TransactionEdit'; type IOURequestType = ValueOf; @@ -624,12 +626,6 @@ function buildOnyxDataForMoneyRequest( pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}, }, }, - // Remove the temporary transaction used during the creation flow - { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`, - value: null, - }, ); if (!isEmptyObject(transactionThreadCreatedReportAction)) { @@ -1004,12 +1000,6 @@ function buildOnyxDataForInvoice( [transactionThreadCreatedReportAction?.reportActionID ?? '-1']: transactionThreadCreatedReportAction, }, }, - // Remove the temporary transaction used during the creation flow - { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`, - value: null, - }, ]; const successData: OnyxUpdate[] = []; @@ -1451,12 +1441,6 @@ function buildOnyxDataForTrackExpense( pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}, }, }, - // Remove the temporary transaction used during the creation flow - { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`, - value: null, - }, ); if (!isEmptyObject(transactionThreadCreatedReportAction)) { @@ -3680,6 +3664,7 @@ function requestMoney( } } + InteractionManager.runAfterInteractions(() => TransactionEdit.removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID)); Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : activeReportID); if (activeReportID) { Report.notifyNewAction(activeReportID, payeeAccountID); @@ -3736,6 +3721,7 @@ function sendInvoice( }; API.write(WRITE_COMMANDS.SEND_INVOICE, parameters, onyxData); + InteractionManager.runAfterInteractions(() => TransactionEdit.removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID)); if (isSearchTopmostCentralPane()) { Navigation.dismissModal(); @@ -3931,6 +3917,7 @@ function trackExpense( API.write(WRITE_COMMANDS.TRACK_EXPENSE, parameters, onyxData); } } + InteractionManager.runAfterInteractions(() => TransactionEdit.removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID)); Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : activeReportID); if (action === CONST.IOU.ACTION.SHARE) { @@ -4118,11 +4105,6 @@ function createSplitsAndOnyxData( key: `${ONYXKEYS.COLLECTION.TRANSACTION}${splitTransaction.transactionID}`, value: splitTransaction, }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`, - value: null, - }, ]; const successData: OnyxUpdate[] = [ { @@ -4501,6 +4483,7 @@ function splitBill({ }; API.write(WRITE_COMMANDS.SPLIT_BILL, parameters, onyxData); + InteractionManager.runAfterInteractions(() => TransactionEdit.removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID)); Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : existingSplitChatReportID); Report.notifyNewAction(splitData.chatReportID, currentUserAccountID); @@ -4568,6 +4551,7 @@ function splitBillAndOpenReport({ }; API.write(WRITE_COMMANDS.SPLIT_BILL_AND_OPEN_REPORT, parameters, onyxData); + InteractionManager.runAfterInteractions(() => TransactionEdit.removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID)); Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : splitData.chatReportID); Report.notifyNewAction(splitData.chatReportID, currentUserAccountID); @@ -5138,6 +5122,7 @@ function completeSplitBill(chatReportID: string, reportAction: OnyxTypes.ReportA }; API.write(WRITE_COMMANDS.COMPLETE_SPLIT_BILL, parameters, {optimisticData, successData, failureData}); + InteractionManager.runAfterInteractions(() => TransactionEdit.removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID)); Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : chatReportID); Report.notifyNewAction(chatReportID, sessionAccountID); } @@ -5315,6 +5300,7 @@ function createDistanceRequest( }); API.write(WRITE_COMMANDS.CREATE_DISTANCE_REQUEST, parameters, onyxData); + InteractionManager.runAfterInteractions(() => TransactionEdit.removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID)); const activeReportID = isMoneyRequestReport ? report?.reportID ?? '-1' : parameters.chatReportID; Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : activeReportID); Report.notifyNewAction(activeReportID, userAccountID);