From 993898f82bd11ba930d99bf9458493c078fbffc7 Mon Sep 17 00:00:00 2001 From: Pedro Ferreira Date: Mon, 19 Aug 2024 23:08:53 -0300 Subject: [PATCH] refactor: improve code readability --- src/components/nano/NanoContractHistory.js | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/nano/NanoContractHistory.js b/src/components/nano/NanoContractHistory.js index d91af07e..25c03e7c 100644 --- a/src/components/nano/NanoContractHistory.js +++ b/src/components/nano/NanoContractHistory.js @@ -64,18 +64,22 @@ function NanoContractHistory({ ncId }) { */ const updateListWs = useCallback((tx) => { // We only add to the list if it's the first page and it's a new tx from this nano - if (!hasBefore) { - if (tx.version === hathorLib.constants.NANO_CONTRACTS_VERSION && tx.nc_id === ncId) { - let nanoHistory = [...history]; - const willHaveAfter = (hasAfter || nanoHistory.length === NANO_CONTRACT_TX_HISTORY_COUNT) - // This updates the list with the new element at first - nanoHistory = helpers.updateListWs(nanoHistory, tx, NANO_CONTRACT_TX_HISTORY_COUNT); - - // Now update the history - setHistory(nanoHistory); - setHasAfter(willHaveAfter); - } + if (hasBefore) { + return; + } + + if (tx.version !== hathorLib.constants.NANO_CONTRACTS_VERSION || tx.nc_id !== ncId) { + return; } + + let nanoHistory = [...history]; + const willHaveAfter = (hasAfter || nanoHistory.length === NANO_CONTRACT_TX_HISTORY_COUNT) + // This updates the list with the new element at first + nanoHistory = helpers.updateListWs(nanoHistory, tx, NANO_CONTRACT_TX_HISTORY_COUNT); + + // Now update the history + setHistory(nanoHistory); + setHasAfter(willHaveAfter); }, [history, hasAfter, hasBefore, ncId]); /**