diff --git a/src/CONST.ts b/src/CONST.ts index edfea995ed9b..e479597a107d 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1171,6 +1171,7 @@ const CONST = { EXPENSIFY: 'Expensify', VBBA: 'ACH', }, + DEFAULT_AMOUNT: 0, TYPE: { SEND: 'send', SPLIT: 'split', diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index e835418c3f5a..259483b1a133 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -178,6 +178,14 @@ function setMoneyRequestAmount_temporaryForRefactor(transactionID, amount, curre Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {amount, currency}); } +/** + * Reset the money request amount, discarding the user-provided value. In the case of distance requests, this will effectively re-enable the default behavior of automatic amount calculation. + * @param {String} transactionID + */ +function resetMoneyRequestAmount_temporaryForRefactor(transactionID) { + Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {amount: CONST.IOU.DEFAULT_AMOUNT}); +} + /** * @param {String} transactionID * @param {String} created @@ -3434,4 +3442,5 @@ export { detachReceipt, getIOUReportID, editMoneyRequest, + resetMoneyRequestAmount_temporaryForRefactor, }; diff --git a/src/libs/actions/Transaction.ts b/src/libs/actions/Transaction.ts index 2132ae1bdc61..951851d72eb3 100644 --- a/src/libs/actions/Transaction.ts +++ b/src/libs/actions/Transaction.ts @@ -10,6 +10,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import {RecentWaypoint, Transaction} from '@src/types/onyx'; import {OnyxData} from '@src/types/onyx/Request'; import {WaypointCollection} from '@src/types/onyx/Transaction'; +import * as IOU from './IOU'; let recentWaypoints: RecentWaypoint[] = []; Onyx.connect({ @@ -58,6 +59,7 @@ function addStop(transactionID: string) { } function saveWaypoint(transactionID: string, index: string, waypoint: RecentWaypoint | null, isDraft = false) { + IOU.resetMoneyRequestAmount_temporaryForRefactor(transactionID); Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION : ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, { comment: { waypoints: { @@ -100,6 +102,7 @@ function saveWaypoint(transactionID: string, index: string, waypoint: RecentWayp } function removeWaypoint(transaction: Transaction, currentIndex: string, isDraft: boolean) { + IOU.resetMoneyRequestAmount_temporaryForRefactor(transaction.transactionID); // Index comes from the route params and is a string const index = Number(currentIndex); const existingWaypoints = transaction?.comment?.waypoints ?? {}; @@ -240,6 +243,7 @@ function getRouteForDraft(transactionID: string, waypoints: WaypointCollection) * which will replace the existing ones. */ function updateWaypoints(transactionID: string, waypoints: WaypointCollection, isDraft = false): Promise { + IOU.resetMoneyRequestAmount_temporaryForRefactor(transactionID); return Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, { comment: { waypoints,