import React, { useState, useRef, useCallback, useMemo, useContext, } from "react"; import { 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 { DsBlockObjWithHashListing } from "src/typings/api"; import { timestampToTimeago, pubKeyToZilAddr } from "src/utils/Utils"; import { DsBlockObj } from "@zilliqa-js/core/src/types"; const DSBlocksPage: 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: "difficulty-col", Header: "Difficulty", accessor: "header.Difficulty", }, { id: "ds-difficulty-col", Header: "DS Difficulty", accessor: "header.DifficultyDS", }, { id: "ds-leader-col", Header: "DS Leader", accessor: "header.LeaderPubKey", Cell: ({ value }: { value: string }) => (
{pubKeyToZilAddr(value)}
), }, { id: "bkhash-col", Header: "Block Hash", accessor: "Hash", Cell: ({ value }: { value: string }) => (
{"0x" + value}
), }, { 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: DsBlockObjWithHashListing; const getData = async () => { try { setIsLoading(true); receivedData = await dataService.getDSBlocksListing(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 ( <> {

DS Blocks

} ); }; export default DSBlocksPage;