Skip to content

Commit

Permalink
refactor: improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroferreira1 committed Aug 20, 2024
1 parent 3c5cf6f commit 385b62e
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/components/nano/NanoContractHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

/**
Expand Down

0 comments on commit 385b62e

Please sign in to comment.