|
| 1 | +import { useMemo, useContext, FC } from "react"; |
| 2 | +import { useParams } from "react-router-dom"; |
| 3 | +import { commify } from "@ethersproject/units"; |
| 4 | +import StandardFrame from "../components/StandardFrame"; |
| 5 | +import StandardSubtitle from "../components/StandardSubtitle"; |
| 6 | +import NavBlock from "../components/NavBlock"; |
| 7 | +import ContentFrame from "../components/ContentFrame"; |
| 8 | +import BlockNotFound from "../components/BlockNotFound"; |
| 9 | +import InfoRow from "../components/InfoRow"; |
| 10 | +import Timestamp from "../components/Timestamp"; |
| 11 | +import BlockLink from "../components/BlockLink"; |
| 12 | +import DecoratedAddressLink from "./components/DecoratedAddressLink"; |
| 13 | +import { RuntimeContext } from "../useRuntime"; |
| 14 | +import { useLatestBlockChainInfo } from "../useLatestBlock"; |
| 15 | +import { dsBlockURL } from "../url"; |
| 16 | +import { useBlockPageTitle } from "../useTitle"; |
| 17 | +import { useDSBlockData } from "../useZilliqaHooks"; |
| 18 | +import { pubKeyToAddr, zilliqaToOtterscanTimestamp } from "../utils/utils"; |
| 19 | + |
| 20 | +// TODO: Figure out what we want to do with the previous Hash field |
| 21 | +const DSBlock: FC = () => { |
| 22 | + const { zilliqa } = useContext(RuntimeContext); |
| 23 | + const { dsBlockNumberOrHash } = useParams(); |
| 24 | + if (dsBlockNumberOrHash === undefined) { |
| 25 | + throw new Error("dsBlockNumberOrHash couldn't be undefined here"); |
| 26 | + } |
| 27 | + |
| 28 | + const { data: dsBlock, isLoading } = useDSBlockData(zilliqa, dsBlockNumberOrHash); |
| 29 | + useBlockPageTitle(parseInt(dsBlockNumberOrHash)); |
| 30 | + |
| 31 | + const latestBlockChainInfo = useLatestBlockChainInfo(zilliqa); |
| 32 | + const latestDSBlockNum = latestBlockChainInfo?.CurrentDSEpoch; |
| 33 | + |
| 34 | + return ( |
| 35 | + <StandardFrame> |
| 36 | + <StandardSubtitle> |
| 37 | + <div className="flex items-baseline space-x-1"> |
| 38 | + <span>DS Block</span> |
| 39 | + <span className="text-base text-gray-500">#{dsBlockNumberOrHash}</span> |
| 40 | + {dsBlock && ( |
| 41 | + <NavBlock |
| 42 | + entityNum={parseInt(dsBlock.header.BlockNum)} |
| 43 | + latestEntityNum={latestDSBlockNum !== undefined ? parseInt(latestDSBlockNum) : undefined} |
| 44 | + urlBuilder={dsBlockURL} |
| 45 | + /> |
| 46 | + )} |
| 47 | + </div> |
| 48 | + </StandardSubtitle> |
| 49 | + {dsBlock === null && ( |
| 50 | + <BlockNotFound blockNumberOrHash={dsBlockNumberOrHash} /> |
| 51 | + )} |
| 52 | + {dsBlock === undefined && ( |
| 53 | + <ContentFrame> |
| 54 | + <InfoRow title="Block Height">Loading DS Block data...</InfoRow> |
| 55 | + </ContentFrame> |
| 56 | + )} |
| 57 | + {dsBlock && ( |
| 58 | + <ContentFrame isLoading={isLoading}> |
| 59 | + <InfoRow title="Block Height"> |
| 60 | + <span className="font-bold">{commify(dsBlock.header.BlockNum)}</span> |
| 61 | + </InfoRow> |
| 62 | + <InfoRow title="Timestamp"> |
| 63 | + <Timestamp value={zilliqaToOtterscanTimestamp(dsBlock.header.Timestamp)} /> |
| 64 | + </InfoRow> |
| 65 | + <InfoRow title="DS Leader"> |
| 66 | + <DecoratedAddressLink address={pubKeyToAddr(dsBlock.header.LeaderPubKey)} miner /> |
| 67 | + </InfoRow> |
| 68 | + <InfoRow title="Gas Used/Limit"> |
| 69 | + {commify(dsBlock.header.GasPrice)} |
| 70 | + </InfoRow> |
| 71 | + <InfoRow title="Difficulty"> |
| 72 | + {commify(dsBlock.header.Difficulty.toString())} |
| 73 | + </InfoRow> |
| 74 | + <InfoRow title="Total Difficulty"> |
| 75 | + {commify(dsBlock.header.DifficultyDS.toString())} |
| 76 | + </InfoRow> |
| 77 | + <InfoRow title="Previous Hash"> |
| 78 | + <BlockLink blockTag={dsBlock.header.PrevHash} /> |
| 79 | + </InfoRow> |
| 80 | + </ContentFrame> |
| 81 | + )} |
| 82 | + </StandardFrame> |
| 83 | + ); |
| 84 | +}; |
| 85 | + |
| 86 | +export default DSBlock; |
0 commit comments