From 12c5306ac0f0c39a3e3f59eb235c09ff38fe1f47 Mon Sep 17 00:00:00 2001 From: finned-palmer Date: Thu, 1 Jul 2021 11:38:18 -0500 Subject: [PATCH] Fix newTx handler --- pkg/btc-wallet/src/js/hooks/useSettings.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/btc-wallet/src/js/hooks/useSettings.js b/pkg/btc-wallet/src/js/hooks/useSettings.js index 02393afcb2..55e7038e48 100644 --- a/pkg/btc-wallet/src/js/hooks/useSettings.js +++ b/pkg/btc-wallet/src/js/hooks/useSettings.js @@ -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); } };