@@ -43,7 +43,7 @@ import Navigation from '@libs/Navigation/Navigation';
4343import OnyxTabNavigator , { TabScreenWithFocusTrapWrapper , TopTab } from '@libs/Navigation/OnyxTabNavigator' ;
4444import { roundToTwoDecimalPlaces } from '@libs/NumberUtils' ;
4545import { isPolicyExpenseChat as isPolicyExpenseChatUtil } from '@libs/ReportUtils' ;
46- import { getDistanceInMeters , getRateID , getRequestType , hasRoute , isCustomUnitRateIDForP2P , isWaypointNullIsland } from '@libs/TransactionUtils' ;
46+ import { getDistanceInMeters , getRateID , getRequestType , hasRoute , haveWaypointAddressesChanged , isCustomUnitRateIDForP2P , isWaypointNullIsland } from '@libs/TransactionUtils' ;
4747import CONST from '@src/CONST' ;
4848import type { IOUType } from '@src/CONST' ;
4949import ONYXKEYS from '@src/ONYXKEYS' ;
@@ -509,11 +509,8 @@ function IOURequestStepDistance({
509509
510510 // If nothing was changed, simply go to transaction thread
511511 // We compare only addresses because numbers are rounded while backup
512- const oldWaypoints = transactionBackup ?. comment ?. waypoints ?? { } ;
513- const oldAddresses = Object . fromEntries ( Object . entries ( oldWaypoints ) . map ( ( [ key , waypoint ] ) => [ key , 'address' in waypoint ? waypoint . address : { } ] ) ) ;
514- const addresses = Object . fromEntries ( Object . entries ( waypoints ) . map ( ( [ key , waypoint ] ) => [ key , 'address' in waypoint ? waypoint . address : { } ] ) ) ;
515512 const hasRouteChanged = ! deepEqual ( transactionBackup ?. routes , transaction ?. routes ) ;
516- if ( deepEqual ( oldAddresses , addresses ) ) {
513+ if ( ! haveWaypointAddressesChanged ( transactionBackup ?. comment ?. waypoints , waypoints ) ) {
517514 transactionWasSaved . current = true ;
518515 navigateBackAfterSave ( ) ;
519516 return ;
@@ -601,10 +598,7 @@ function IOURequestStepDistance({
601598
602599 // Check if waypoints were edited on the map tab before the user switched to manual.
603600 // If so, we must still send the update even if the distance value itself didn't change.
604- const oldWaypoints = transactionBackup ?. comment ?. waypoints ?? { } ;
605- const oldAddresses = Object . fromEntries ( Object . entries ( oldWaypoints ) . map ( ( [ key , waypoint ] ) => [ key , 'address' in waypoint ? waypoint . address : { } ] ) ) ;
606- const currentAddresses = Object . fromEntries ( Object . entries ( waypoints ) . map ( ( [ key , waypoint ] ) => [ key , 'address' in waypoint ? waypoint . address : { } ] ) ) ;
607- const haveWaypointsChanged = ! deepEqual ( oldAddresses , currentAddresses ) ;
601+ const haveWaypointsChanged = haveWaypointAddressesChanged ( transactionBackup ?. comment ?. waypoints , waypoints ) ;
608602
609603 if ( ! isDistanceChanged && ! isDistanceUnitChanged && ! haveWaypointsChanged ) {
610604 transactionWasSaved . current = true ;
0 commit comments