From 7caca60c5dc977a94d8272a871a84d0324a10b39 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Wed, 2 Oct 2024 09:29:04 -0700 Subject: [PATCH] ensure that round trips do not display the duplicate waypoint error incorrectly --- src/libs/TransactionUtils/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index 9fbed928423f..0db771eaa96b 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -646,7 +646,10 @@ function getValidWaypoints(waypoints: WaypointCollection | undefined, reArrangeI let waypointIndex = -1; return waypointValues.reduce((acc, currentWaypoint, index) => { - const previousWaypoint = waypointValues.at(lastWaypointIndex); + // Array.at(-1) returns the last element of the array + // If a user does a round trip, the last waypoint will be the same as the first waypoint + // We want to avoid comparing them as this will result in an incorrect duplicate waypoint error. + const previousWaypoint = lastWaypointIndex !== -1 ? waypointValues.at(lastWaypointIndex) : undefined; // Check if the waypoint has a valid address if (!waypointHasValidAddress(currentWaypoint)) {