@@ -728,13 +728,17 @@ function getUpdatedTransaction({
728728 }
729729 shouldStopSmartscan = true ;
730730
731- if ( ! transactionChanges . routes ?. route0 ?. geometry ?. coordinates ) {
731+ // A manual-distance edit re-sends unchanged waypoints; when they truly didn't change, leave
732+ // `amount`/`modifiedAmount` to the sibling `distance` branch instead of zeroing them here.
733+ const waypointsActuallyChanged = ! deepEqual ( transactionChanges . waypoints , transaction ?. comment ?. waypoints ) ;
734+
735+ if ( waypointsActuallyChanged && ! transactionChanges . routes ?. route0 ?. geometry ?. coordinates ) {
732736 // The waypoints were changed, but there is no route – it is pending from the BE and we should mark the fields as pending
733737 updatedTransaction . amount = CONST . IOU . DEFAULT_AMOUNT ;
734738 updatedTransaction . modifiedAmount = CONST . IOU . DEFAULT_AMOUNT ;
735739 // eslint-disable-next-line @typescript-eslint/no-deprecated
736740 updatedTransaction . modifiedMerchant = translateLocal ( 'iou.fieldPending' ) ;
737- } else {
741+ } else if ( transactionChanges . routes ?. route0 ?. geometry ?. coordinates ) {
738742 const mileageRate = DistanceRequestUtils . getRate ( { transaction : updatedTransaction , policy} ) ;
739743 const { unit, rate} = mileageRate ;
740744
@@ -881,6 +885,8 @@ function getUpdatedTransaction({
881885
882886 if ( Object . hasOwn ( transactionChanges , 'distance' ) && typeof transactionChanges . distance === 'number' ) {
883887 const distance = roundToTwoDecimalPlaces ( transactionChanges . distance ?? 0 ) ;
888+ // Capture before mutating quantity below; needed by the fallback amount computation.
889+ const previousDistanceInMeters = getDistanceInMeters ( transaction , transaction ?. comment ?. customUnit ?. distanceUnit ) ;
884890
885891 lodashSet ( updatedTransaction , 'comment.customUnit.quantity' , distance ) ;
886892 lodashSet ( updatedTransaction , 'routes.route0.distance' , null ) ;
@@ -906,9 +912,20 @@ function getUpdatedTransaction({
906912 isManualDistanceRequest ( transaction ) ,
907913 ) ;
908914
909- updatedTransaction . modifiedAmount = amount ;
910- updatedTransaction . modifiedMerchant = updatedMerchant ;
911- updatedTransaction . modifiedCurrency = updatedCurrency ;
915+ // No locally resolvable rate (e.g. track expense without policy loaded) → scale the previous
916+ // amount by the distance ratio so the optimistic value isn't 0. `modifiedAmount` is `""` for
917+ // unedited transactions, so coerce via Number() and fall through to `amount`.
918+ const previousAmount = Number ( transaction ?. modifiedAmount ) || transaction ?. amount || 0 ;
919+ const useFallback = ! rate && ! ! previousDistanceInMeters && ! ! previousAmount && ! ! distanceInMeters ;
920+ if ( useFallback ) {
921+ updatedTransaction . modifiedAmount = Math . round ( previousAmount * ( distanceInMeters / previousDistanceInMeters ) ) ;
922+ updatedTransaction . modifiedMerchant = updatedMerchant ;
923+ // Leave currency alone — without a resolvable rate we don't know the target currency.
924+ } else {
925+ updatedTransaction . modifiedAmount = amount ;
926+ updatedTransaction . modifiedMerchant = updatedMerchant ;
927+ updatedTransaction . modifiedCurrency = updatedCurrency ;
928+ }
912929 }
913930
914931 if ( Object . hasOwn ( transactionChanges , 'odometerStart' ) && typeof transactionChanges . odometerStart === 'number' ) {
0 commit comments