-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Changed Runtime Context to contain Zilliqa object * Reformatted code so that all Pending components are together * Added basic components for DS Blocks * Implemented polling for most recent DS Block * Added function to convert to Otterscan timestamp format * Added detailed DS Block page * Added ability to search for DS Blocks using search bar * Added DS Block List page
- Loading branch information
1 parent
c81d20e
commit be2d76c
Showing
32 changed files
with
665 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { FC, memo } from "react"; | ||
import { NavLink } from "react-router-dom"; | ||
import { BlockTag } from "@ethersproject/abstract-provider"; | ||
import { commify } from "@ethersproject/units"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { faCube } from "@fortawesome/free-solid-svg-icons"; | ||
import { dsBlockURL } from "../url"; | ||
|
||
type DSBlockLinkProps = { | ||
blockTag: BlockTag; | ||
}; | ||
|
||
const DSBlockLink: FC<DSBlockLinkProps> = ({ blockTag }) => { | ||
const isNum = typeof blockTag === "number"; | ||
let text = blockTag; | ||
if (isNum) { | ||
text = commify(blockTag); | ||
} | ||
|
||
return ( | ||
<NavLink | ||
className={`flex-inline items-baseline space-x-1 text-link-blue hover:text-link-blue-hover ${ | ||
isNum ? "font-blocknum" : "font-hash" | ||
}`} | ||
to={dsBlockURL(blockTag)} | ||
> | ||
<span className="text-orange-500"> | ||
<FontAwesomeIcon className="self-center" icon={faCube} size="1x" /> | ||
</span> | ||
<span>{text}</span> | ||
</NavLink> | ||
); | ||
}; | ||
|
||
export default memo(DSBlockLink); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from "react"; | ||
import ContentFrame from "./ContentFrame"; | ||
|
||
type DSBlockNotFoundProps = { | ||
blockNumberOrHash: string; | ||
}; | ||
|
||
const DSBlockNotFound: React.FC<DSBlockNotFoundProps> = ({ blockNumberOrHash }) => ( | ||
<ContentFrame> | ||
<div className="py-4 text-sm">DS Block "{blockNumberOrHash}" not found.</div> | ||
</ContentFrame> | ||
); | ||
|
||
export default React.memo(DSBlockNotFound); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { useMemo, useContext, FC } from "react"; | ||
import { useParams } from "react-router-dom"; | ||
import { commify } from "@ethersproject/units"; | ||
import StandardFrame from "../components/StandardFrame"; | ||
import StandardSubtitle from "../components/StandardSubtitle"; | ||
import NavBlock from "../components/NavBlock"; | ||
import ContentFrame from "../components/ContentFrame"; | ||
import BlockNotFound from "../components/BlockNotFound"; | ||
import InfoRow from "../components/InfoRow"; | ||
import Timestamp from "../components/Timestamp"; | ||
import BlockLink from "../components/BlockLink"; | ||
import DecoratedAddressLink from "./components/DecoratedAddressLink"; | ||
import { RuntimeContext } from "../useRuntime"; | ||
import { useLatestBlockChainInfo } from "../useLatestBlock"; | ||
import { dsBlockURL } from "../url"; | ||
import { useBlockPageTitle } from "../useTitle"; | ||
import { useDSBlockData } from "../useZilliqaHooks"; | ||
import { pubKeyToAddr, zilliqaToOtterscanTimestamp } from "../utils/utils"; | ||
|
||
// TODO: Figure out what we want to do with the previous Hash field | ||
const DSBlock: FC = () => { | ||
const { zilliqa } = useContext(RuntimeContext); | ||
const { dsBlockNumberOrHash } = useParams(); | ||
if (dsBlockNumberOrHash === undefined) { | ||
throw new Error("dsBlockNumberOrHash couldn't be undefined here"); | ||
} | ||
|
||
const { data: dsBlock, isLoading } = useDSBlockData(zilliqa, dsBlockNumberOrHash); | ||
useBlockPageTitle(parseInt(dsBlockNumberOrHash)); | ||
|
||
const latestBlockChainInfo = useLatestBlockChainInfo(zilliqa); | ||
const latestDSBlockNum = latestBlockChainInfo?.CurrentDSEpoch; | ||
|
||
return ( | ||
<StandardFrame> | ||
<StandardSubtitle> | ||
<div className="flex items-baseline space-x-1"> | ||
<span>DS Block</span> | ||
<span className="text-base text-gray-500">#{dsBlockNumberOrHash}</span> | ||
{dsBlock && ( | ||
<NavBlock | ||
entityNum={parseInt(dsBlock.header.BlockNum)} | ||
latestEntityNum={latestDSBlockNum !== undefined ? parseInt(latestDSBlockNum) : undefined} | ||
urlBuilder={dsBlockURL} | ||
/> | ||
)} | ||
</div> | ||
</StandardSubtitle> | ||
{dsBlock === null && ( | ||
<BlockNotFound blockNumberOrHash={dsBlockNumberOrHash} /> | ||
)} | ||
{dsBlock === undefined && ( | ||
<ContentFrame> | ||
<InfoRow title="Block Height">Loading DS Block data...</InfoRow> | ||
</ContentFrame> | ||
)} | ||
{dsBlock && ( | ||
<ContentFrame isLoading={isLoading}> | ||
<InfoRow title="Block Height"> | ||
<span className="font-bold">{commify(dsBlock.header.BlockNum)}</span> | ||
</InfoRow> | ||
<InfoRow title="Timestamp"> | ||
<Timestamp value={zilliqaToOtterscanTimestamp(dsBlock.header.Timestamp)} /> | ||
</InfoRow> | ||
<InfoRow title="DS Leader"> | ||
<DecoratedAddressLink address={pubKeyToAddr(dsBlock.header.LeaderPubKey)} miner /> | ||
</InfoRow> | ||
<InfoRow title="Gas Used/Limit"> | ||
{commify(dsBlock.header.GasPrice)} | ||
</InfoRow> | ||
<InfoRow title="Difficulty"> | ||
{commify(dsBlock.header.Difficulty.toString())} | ||
</InfoRow> | ||
<InfoRow title="Total Difficulty"> | ||
{commify(dsBlock.header.DifficultyDS.toString())} | ||
</InfoRow> | ||
<InfoRow title="Previous Hash"> | ||
<BlockLink blockTag={dsBlock.header.PrevHash} /> | ||
</InfoRow> | ||
</ContentFrame> | ||
)} | ||
</StandardFrame> | ||
); | ||
}; | ||
|
||
export default DSBlock; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React, { useContext } from "react"; | ||
import { useSearchParams } from "react-router-dom"; | ||
import StandardFrame from "../components/StandardFrame"; | ||
import { PAGE_SIZE } from "../params"; | ||
import { RuntimeContext } from "../useRuntime"; | ||
import StandardSubtitle from "../components/StandardSubtitle"; | ||
import { useLatestBlockChainInfo } from "../useLatestBlock"; | ||
import { PendingRecentDSBlockResults } from "../search/PendingResults"; | ||
import StandardSelectionBoundary from "../selection/StandardSelectionBoundary"; | ||
import ContentFrame from "../components/ContentFrame"; | ||
import { totalBlocksFormatter } from "../search/messages"; | ||
import SearchResultNavBar from "../search/SearchResultNavBar"; | ||
import { useDSBlocksData } from "../useZilliqaHooks"; | ||
import RecentDSBlockItem from "../search/RecentDSBlockItem"; | ||
import DSBlockResultHeader from "../search/DSBlockResultHeader"; | ||
import DSBlockItem from "../search/DSBlockItem"; | ||
|
||
const DSBlockList: React.FC = () => { | ||
const { zilliqa } = useContext(RuntimeContext); | ||
|
||
const latestBlockChainInfo = useLatestBlockChainInfo(zilliqa); | ||
const latestBlockNum = latestBlockChainInfo?.CurrentDSEpoch; | ||
const latestBlockNumInt = latestBlockNum !== undefined ? parseInt(latestBlockNum, 10) : undefined; | ||
|
||
const [searchParams] = useSearchParams(); | ||
let pageNumber = 1; | ||
const p = searchParams.get("p"); | ||
if (p) { | ||
try { | ||
pageNumber = parseInt(p); | ||
} catch (err) {} | ||
} | ||
|
||
const { data, isLoading } = useDSBlocksData( | ||
zilliqa, | ||
latestBlockNumInt, | ||
pageNumber - 1, | ||
PAGE_SIZE | ||
); | ||
|
||
return ( | ||
<StandardFrame> | ||
<StandardSubtitle> | ||
<div className="flex items-baseline space-x-1">DS Block List</div> | ||
</StandardSubtitle> | ||
<ContentFrame isLoading={isLoading}> | ||
<SearchResultNavBar | ||
pageNumber={pageNumber} | ||
pageSize={PAGE_SIZE} | ||
total={latestBlockNumInt} | ||
totalFormatter={totalBlocksFormatter} | ||
/> | ||
<DSBlockResultHeader/> | ||
{data ? ( | ||
<StandardSelectionBoundary> | ||
{data.map((block) => ( | ||
block ? <DSBlockItem key={block.header.BlockNum} block={block} /> : <></> | ||
))} | ||
</StandardSelectionBoundary> | ||
) : ( | ||
<PendingRecentDSBlockResults /> | ||
)} | ||
</ContentFrame> | ||
</StandardFrame> | ||
); | ||
}; | ||
|
||
export default DSBlockList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.