Skip to content

Commit

Permalink
Store recent waypoints optimistically
Browse files Browse the repository at this point in the history
  • Loading branch information
tgolen committed Aug 25, 2023
1 parent f58407a commit 2c9ffa5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/libs/actions/Transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import ONYXKEYS from '../../ONYXKEYS';
import * as CollectionUtils from '../CollectionUtils';
import * as API from '../API';

let recentWaypoints = [];
Onyx.connect({
key: ONYXKEYS.NVP_RECENT_WAYPOINTS,
callback: (val) => (recentWaypoints = val || []),
});

const allTransactions = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.TRANSACTION,
Expand Down Expand Up @@ -87,6 +93,11 @@ function saveWaypoint(transactionID, index, waypoint) {
},
},
});
const recentWaypointAlreadyExists = _.find(recentWaypoints, (recentWaypoint) => recentWaypoint.address === waypoint.address);
if (!recentWaypointAlreadyExists) {
recentWaypoints.unshift(waypoint);
Onyx.merge(ONYXKEYS.NVP_RECENT_WAYPOINTS, recentWaypoints.slice(0, 5));
}
}

function removeWaypoint(transactionID, currentIndex) {
Expand Down

0 comments on commit 2c9ffa5

Please sign in to comment.