-
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.
Add Blockchain Info to Home Page (#14)
* Fixed reward truncation entry * Added a display of blockchain statistics to home page
- Loading branch information
1 parent
be2d76c
commit f497073
Showing
9 changed files
with
232 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { faInfoCircle } from "@fortawesome/free-solid-svg-icons"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { Menu } from "@headlessui/react"; | ||
|
||
type BCInfoToolTipProps = { | ||
child: React.ReactNode, | ||
}; | ||
|
||
const BCInfoToolTip: React.FC<BCInfoToolTipProps> = ({ child }) => { | ||
|
||
return ( | ||
<Menu> | ||
<span> | ||
<Menu.Button className="rounded"> | ||
<FontAwesomeIcon icon={faInfoCircle} size="1x" /> | ||
</Menu.Button> | ||
<Menu.Items className="absolute mt-2 flex min-w-max flex-col rounded-b border bg-white p-1 text-sm"> | ||
<div className="w-60 text-xs"> | ||
{ child } | ||
</div> | ||
</Menu.Items> | ||
</span> | ||
</Menu> | ||
); | ||
}; | ||
|
||
export default BCInfoToolTip; |
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,17 @@ | ||
import { FC, memo } from "react"; | ||
|
||
type RecentNavBarProps = { | ||
isLoading : boolean | ||
}; | ||
|
||
const ChainInfoHeader: FC<RecentNavBarProps> = ({ isLoading }) => ( | ||
<div className="flex items-baseline justify-between py-3"> | ||
<div className="text-sm text-gray-500"> | ||
{isLoading | ||
? "Waiting for blocks..." | ||
: "Chain Info"} | ||
</div> | ||
</div> | ||
); | ||
|
||
export default memo(ChainInfoHeader); |
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,21 @@ | ||
type ChainInfoItemProps = { | ||
title: React.ReactNode, | ||
data: React.ReactNode, | ||
}; | ||
|
||
const ChainInfoItem: React.FC<ChainInfoItemProps> = ({ title, data }) => { | ||
|
||
return ( | ||
<span className=""> | ||
<span className="px-2 py-1 font-bold text-gray-500"> | ||
{title} | ||
</span> | ||
<br/> | ||
<span className="px-2 py-1"> | ||
{data} | ||
</span> | ||
</span> | ||
); | ||
}; | ||
|
||
export default ChainInfoItem; |
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,110 @@ | ||
import { FC, useContext, memo } from "react"; | ||
import ContentFrame from "../components/ContentFrame"; | ||
import { RuntimeContext } from "../useRuntime"; | ||
import ChainInfoItem from "../components/ChainInfoItem"; | ||
import { PendingChainInfoResults } from "../search/PendingResults"; | ||
import ChainInfoHeader from "../components/ChainInfoHeader"; | ||
import { useBCInfoStateInfo, useLatestBlockChainInfo } from "../useLatestBlock"; | ||
import BCInfoToolTip from "../components/BCInfoToolTip"; | ||
import BlockLink from "../components/BlockLink"; | ||
|
||
const ChainInfo: FC = () => { | ||
const { zilliqa } = useContext(RuntimeContext); | ||
|
||
const latestBlockChainInfo = useLatestBlockChainInfo(zilliqa); | ||
|
||
const BCInfo = useBCInfoStateInfo(latestBlockChainInfo); | ||
|
||
// Return a table with rows containing the basic information of the most recent RECENT_SIZE blocks | ||
return ( | ||
<ContentFrame isLoading={latestBlockChainInfo === undefined}> | ||
<div className="pb-3"> | ||
<ChainInfoHeader isLoading={ latestBlockChainInfo === undefined }/> | ||
{latestBlockChainInfo ? | ||
<div className="grid grid-rows-3 grid-cols-4 items-baseline gap-x-1 border-t | ||
border-b border-gray-200 bg-gray-100 text-sm"> | ||
<span> | ||
<ChainInfoItem title="Current Tx Epoch:" data={latestBlockChainInfo.NumTxBlocks} /> | ||
</span> | ||
<span> | ||
<ChainInfoItem title="Number of Transactions:" data={latestBlockChainInfo.NumTransactions} /> | ||
</span> | ||
<span> | ||
<ChainInfoItem title="Peers:" data={latestBlockChainInfo.NumPeers} /> | ||
</span> | ||
<span> | ||
<ChainInfoItem title="Sharding Structure:" data={`[${latestBlockChainInfo.ShardingStructure.NumPeers.toString()}]`} /> | ||
</span> | ||
<span> | ||
<ChainInfoItem title="Current DS Epoch:" data={latestBlockChainInfo.CurrentDSEpoch} /> | ||
</span> | ||
<span> | ||
<ChainInfoItem title="DS Block Rate:" data={latestBlockChainInfo.DSBlockRate.toFixed(5)} /> | ||
</span> | ||
<span> | ||
<ChainInfoItem title="Tx Block Rate:" data={latestBlockChainInfo.TxBlockRate.toFixed(5)} /> | ||
</span> | ||
<span> | ||
<ChainInfoItem title="TPS:" data={latestBlockChainInfo.TransactionRate.toFixed(5)} /> | ||
</span> | ||
<span> | ||
<ChainInfoItem title="Number of Txns in DS Epoch:" data={latestBlockChainInfo.NumTxnsDSEpoch} /> | ||
</span> | ||
<span> | ||
<ChainInfoItem title="Number of Txns in Txn Epoch:" data={latestBlockChainInfo.NumTxnsTxEpoch} /> | ||
</span> | ||
<span> | ||
<ChainInfoItem title={ | ||
<span> | ||
<BCInfoToolTip child={`This statistic is accurate from TxBlock ${BCInfo?.startTxBlock}. Requires user to stay on the Home Page`}/> | ||
{' '} | ||
Recent Max Observed TPS: | ||
</span>} | ||
data={ | ||
<span> | ||
{BCInfo?.maxTPS.toFixed(5)} | ||
{' '} | ||
{BCInfo?.startTxBlock && <span className="text-xs"> | ||
<span className="text-gray-500"> | ||
(on TxBlock | ||
{' '} | ||
<BlockLink blockTag={BCInfo?.startTxBlock} /> | ||
) | ||
</span> | ||
</span>} | ||
</span> | ||
}/> | ||
</span> | ||
<span> | ||
<ChainInfoItem title={ | ||
<span> | ||
<BCInfoToolTip child={`This statistic is accurate from TxBlock ${BCInfo?.startTxBlock}. Requires user to stay on the Home Page`}/> | ||
{' '} | ||
Recent Max Observed Txn Count: | ||
</span>} | ||
data={ | ||
<span> | ||
{BCInfo?.maxTxnCount} | ||
{' '} | ||
{BCInfo?.startTxBlock && <span className="text-xs"> | ||
<span className="text-gray-500"> | ||
(on TxBlock | ||
{' '} | ||
<BlockLink blockTag={BCInfo?.startTxBlock} /> | ||
) | ||
</span> | ||
</span>} | ||
</span> | ||
}/> | ||
</span> | ||
</div> | ||
: | ||
|
||
<PendingChainInfoResults /> | ||
} | ||
</div> | ||
</ContentFrame> | ||
); | ||
}; | ||
|
||
export default memo(ChainInfo); |
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