From a6b1551756aa306a5fabbdecb0c8abab537821df Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Tue, 3 Aug 2021 00:45:07 -0300 Subject: [PATCH] Use total info from node --- src/BlockTransactions.tsx | 9 ++++++--- src/useErigonHooks.ts | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/BlockTransactions.tsx b/src/BlockTransactions.tsx index 02352d7..f8a3bf9 100644 --- a/src/BlockTransactions.tsx +++ b/src/BlockTransactions.tsx @@ -34,7 +34,10 @@ const BlockTransactions: React.FC = () => { [params.blockNumber] ); - const txs = useBlockTransactions(provider, blockNumber.toNumber()); + const [totalTxs, txs] = useBlockTransactions( + provider, + blockNumber.toNumber() + ); const page = useMemo(() => { if (!txs) { @@ -43,7 +46,7 @@ const BlockTransactions: React.FC = () => { const pageStart = (pageNumber - 1) * PAGE_SIZE; return txs.slice(pageStart, pageStart + PAGE_SIZE); }, [txs, pageNumber]); - const total = useMemo(() => txs?.length ?? 0, [txs]); + const total = totalTxs; document.title = `Block #${blockNumber} Txns | Otterscan`; @@ -52,7 +55,7 @@ const BlockTransactions: React.FC = () => { diff --git a/src/useErigonHooks.ts b/src/useErigonHooks.ts index 8fe170e..56677af 100644 --- a/src/useErigonHooks.ts +++ b/src/useErigonHooks.ts @@ -67,7 +67,8 @@ export const readBlock = async ( export const useBlockTransactions = ( provider: ethers.providers.JsonRpcProvider | undefined, blockNumber: number -) => { +): [number | undefined, ProcessedTransaction[] | undefined] => { + const [totalTxs, setTotalTxs] = useState(); const [txs, setTxs] = useState(); useEffect(() => { @@ -114,6 +115,7 @@ export const useBlockTransactions = ( ) .reverse(); setTxs(rawTxs); + setTotalTxs(result.fullblock.transactionCount); const checkTouchMinerAddr = await Promise.all( rawTxs.map(async (res) => { @@ -139,7 +141,7 @@ export const useBlockTransactions = ( readBlock(); }, [provider, blockNumber]); - return txs; + return [totalTxs, txs]; }; export const useBlockData = (