mirror of
https://github.com/urbit/shrub.git
synced 2024-12-19 08:32:39 +03:00
Fix newTx handler
This commit is contained in:
parent
76743129fb
commit
72fbbb11e5
@ -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) => {
|
||||
return h.txid.dat === txid.dat && h.txid.wid === txid.wid;
|
||||
});
|
||||
if (old !== -1) {
|
||||
delete history.splice(old, 1);
|
||||
const newHistory = history.filter((o, i) => i !== old);
|
||||
setHistory(newHistory);
|
||||
}
|
||||
if (recvd === null) {
|
||||
history.unshift({ txid, recvd });
|
||||
} else {
|
||||
if (recvd === null && old === -1) {
|
||||
const newHistory = [...history, newTx];
|
||||
setHistory(newHistory);
|
||||
} else if (recvd !== null && old === -1) {
|
||||
// we expect history to have null recvd values first, and the rest in
|
||||
// descending order
|
||||
let insertionIndex = _.findIndex(history, (h) => {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user