diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index f2768c194532..64c41b2a448a 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -6,6 +6,8 @@ import lodashSet from 'lodash/set'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; +import type {Coordinate} from '@components/MapView/MapViewTypes'; +import utils from '@components/MapView/utils'; import type {UnreportedExpenseListItemType} from '@components/SelectionListWithSections/types'; import {getPolicyTagsData} from '@libs/actions/Policy/Tag'; import type {MergeDuplicatesParams} from '@libs/API/parameters'; @@ -1308,8 +1310,10 @@ function getValidWaypoints(waypoints: WaypointCollection | undefined, reArrangeI return acc; } - // Check for adjacent waypoints with the same address - if (previousWaypoint && currentWaypoint?.address === previousWaypoint.address) { + // Check for adjacent waypoints with the same address or coordinate + const previousCoordinate: Coordinate = [previousWaypoint?.lng ?? 0, previousWaypoint?.lat ?? 0]; + const currentCoordinate: Coordinate = [currentWaypoint.lng ?? 0, currentWaypoint.lat ?? 0]; + if (previousWaypoint && (currentWaypoint?.address === previousWaypoint.address || utils.areSameCoordinate(previousCoordinate, currentCoordinate))) { return acc; }