Fix newTx handler

This commit is contained in:
finned-palmer 2021-07-01 11:38:18 -05:00
parent 6badb91b6f
commit 12c5306ac0

View File

@ -134,22 +134,28 @@ export const SettingsProvider = ({ channel, children }) => {
} }
}; };
const handleNewTx = ({ txid, recvd }) => { const handleNewTx = (newTx) => {
const { txid, recvd } = newTx;
let old = _.findIndex(history, (h) => { let old = _.findIndex(history, (h) => {
return h.txid.dat === txid.dat && h.txid.wid === txid.wid; return h.txid.dat === txid.dat && h.txid.wid === txid.wid;
}); });
if (old !== -1) { if (old !== -1) {
delete history.splice(old, 1); const newHistory = history.filter((o, i) => i !== old);
setHistory(newHistory);
} }
if (recvd === null) { if (recvd === null && old === -1) {
history.unshift({ txid, recvd }); const newHistory = [...history, newTx];
} else { setHistory(newHistory);
} else if (recvd !== null && old === -1) {
// we expect history to have null recvd values first, and the rest in // we expect history to have null recvd values first, and the rest in
// descending order // descending order
let insertionIndex = _.findIndex(history, (h) => { let insertionIndex = _.findIndex(history, (h) => {
return h.recvd < recvd && h.recvd !== null; return h.recvd < recvd && h.recvd !== null;
}); });
history.splice(insertionIndex, 0, { txid, recvd }); const newHistory = history.map((o, i) =>
i === insertionIndex ? newTx : o
);
setHistory(newHistory);
} }
}; };