Skip to content

Commit 2c9ffa5

Browse files
committed
Store recent waypoints optimistically
1 parent f58407a commit 2c9ffa5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/libs/actions/Transaction.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import ONYXKEYS from '../../ONYXKEYS';
55
import * as CollectionUtils from '../CollectionUtils';
66
import * as API from '../API';
77

8+
let recentWaypoints = [];
9+
Onyx.connect({
10+
key: ONYXKEYS.NVP_RECENT_WAYPOINTS,
11+
callback: (val) => (recentWaypoints = val || []),
12+
});
13+
814
const allTransactions = {};
915
Onyx.connect({
1016
key: ONYXKEYS.COLLECTION.TRANSACTION,
@@ -87,6 +93,11 @@ function saveWaypoint(transactionID, index, waypoint) {
8793
},
8894
},
8995
});
96+
const recentWaypointAlreadyExists = _.find(recentWaypoints, (recentWaypoint) => recentWaypoint.address === waypoint.address);
97+
if (!recentWaypointAlreadyExists) {
98+
recentWaypoints.unshift(waypoint);
99+
Onyx.merge(ONYXKEYS.NVP_RECENT_WAYPOINTS, recentWaypoints.slice(0, 5));
100+
}
90101
}
91102

92103
function removeWaypoint(transactionID, currentIndex) {

0 commit comments

Comments
 (0)