Skip to content

Commit

Permalink
fix: check if waypoint is not null
Browse files Browse the repository at this point in the history
  • Loading branch information
kubabutkiewicz committed Sep 12, 2023
1 parent 85a12fa commit 6a86285
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ function saveWaypoint(transactionID: string, index: string, waypoint: RecentWayp
if (!lodashHas(waypoint, 'lat') || !lodashHas(waypoint, 'lng')) {
return;
}

const recentWaypointAlreadyExists = recentWaypoints.find((recentWaypoint) => recentWaypoint?.address === waypoint?.address);
if (!recentWaypointAlreadyExists) {
if (!recentWaypointAlreadyExists && waypoint !== null) {
const clonedWaypoints = lodashClone(recentWaypoints);
clonedWaypoints.unshift(waypoint);
Onyx.merge(ONYXKEYS.NVP_RECENT_WAYPOINTS, clonedWaypoints.slice(0, 5));
Expand All @@ -108,7 +107,6 @@ function removeWaypoint(transactionID: string, currentIndex: string) {
const transaction = allTransactions?.[transactionID] ?? {};
const existingWaypoints = transaction?.comment?.waypoints ?? {};
const totalWaypoints = Object.keys(existingWaypoints).length;

// Prevents removing the starting or ending waypoint but clear the stored address only if there are only two waypoints
if (totalWaypoints === 2 && (index === 0 || index === totalWaypoints - 1)) {
saveWaypoint(transactionID, index.toString(), null);
Expand Down

0 comments on commit 6a86285

Please sign in to comment.