import React, { useState, useRef, useCallback, useMemo, useContext, } from "react"; import { Tooltip, OverlayTrigger, Spinner } from "react-bootstrap"; import { QueryPreservingLink } from "src/services/network/networkProvider"; import ViewAllTable from "src/components/ViewAllPages/ViewAllTable/ViewAllTable"; import { NetworkContext } from "src/services/network/networkProvider"; import { TxBlockObjListing } from "src/typings/api"; import { timestampToTimeago, qaToZil, pubKeyToZilAddr } from "src/utils/Utils"; import { TxBlockObj } from "@zilliqa-js/core/src/types"; const TxBlocksPage: React.FC = () => { const networkContext = useContext(NetworkContext); if (!networkContext) { return (
); } const { dataService } = networkContext; const fetchIdRef = useRef(0); const [isLoading, setIsLoading] = useState(false); const [pageCount, setPageCount] = useState(0); const [data, setData] = useState(null); const columns = useMemo( () => [ { id: "height-col", Header: "Height", accessor: "header.BlockNum", Cell: ({ value }: { value: string }) => ( {value} ), }, { id: "mbs-count-col", Header: "MB Count", accessor: "body.MicroBlockInfos", Cell: ({ value }: { value: string }) => (
{value.length > 0 ? value.length : "0"}
), }, { id: "numTxns-col", Header: "Txns", accessor: "header.NumTxns", Cell: ({ value }: { value: string }) => (
{value}
), }, { id: "ds-leader-col", Header: "DS Leader", accessor: "header.MinerPubKey", Cell: ({ value }: { value: string }) => (
{pubKeyToZilAddr(value)}
), }, { id: "bkhash-col", Header: "Block Hash", accessor: "body.BlockHash", Cell: ({ value }: { value: string }) => (
{"0x" + value}
), }, { id: "total-txn-fees-col", Header: "Txn Fees", accessor: "header.TxnFees", Cell: ({ value }: { value: string }) => ( {qaToZil(value)} } >
{qaToZil(value, 5)}
), }, { id: "rewards-col", Header: "Rewards", accessor: "header.Rewards", Cell: ({ value }: { value: string }) => ( {qaToZil(value)} } >
{qaToZil(value, 5)}
), }, { id: "age-col", Header: "Age", accessor: "header.Timestamp", Cell: ({ value }: { value: string }) => (
{timestampToTimeago(value)}
), }, ], [] ); const fetchData = useCallback( ({ pageIndex }: { pageIndex: number }) => { if (!dataService) return; const fetchId = ++fetchIdRef.current; let receivedData: TxBlockObjListing; const getData = async () => { try { setIsLoading(true); receivedData = await dataService.getTxBlocksListing(pageIndex + 1); if (receivedData) { setData(receivedData.data); setPageCount(receivedData.maxPages); } } catch (e) { console.log(e); } finally { setIsLoading(false); } }; if (fetchId === fetchIdRef.current) getData(); }, [dataService] ); return ( <> {

Transaction Blocks

} ); }; export default TxBlocksPage;