From 91dd933aa2bf9518e3454843a9d51058439f872c Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Wed, 28 Jul 2021 04:24:48 -0300 Subject: [PATCH] Squash block gas used/limit info; add percentage bar --- src/Block.tsx | 37 +++++++++++++++++++++---------------- src/components/InfoRow.tsx | 2 +- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/Block.tsx b/src/Block.tsx index 9e061e7..91951ec 100644 --- a/src/Block.tsx +++ b/src/Block.tsx @@ -5,6 +5,7 @@ import StandardFrame from "./StandardFrame"; import StandardSubtitle from "./StandardSubtitle"; import NavBlock from "./block/NavBlock"; import ContentFrame from "./ContentFrame"; +import InfoRow from "./components/InfoRow"; import Timestamp from "./components/Timestamp"; import GasValue from "./components/GasValue"; import BlockLink from "./components/BlockLink"; @@ -43,6 +44,8 @@ const Block: React.FC = () => { const burnedFees = block?.baseFeePerGas && block.baseFeePerGas.mul(block.gasUsed); const netFeeReward = block && block.feeReward.sub(burnedFees ?? 0); + const gasUsedPerc = + block && block.gasUsed.mul(10000).div(block.gasLimit).toNumber() / 100; const latestBlockNumber = useLatestBlockNumber(provider); @@ -130,11 +133,24 @@ const Block: React.FC = () => { Ether )} - - - - - + +
+
+ /{" "} + +
+
+
+
+
+ {gasUsedPerc}% +
+
+
+
{extraStr} (Hex:{" "} @@ -162,15 +178,4 @@ const Block: React.FC = () => { ); }; -type InfoRowProps = { - title: string; -}; - -const InfoRow: React.FC = ({ title, children }) => ( -
-
{title}:
-
{children}
-
-); - export default React.memo(Block); diff --git a/src/components/InfoRow.tsx b/src/components/InfoRow.tsx index d3758b3..eb40eb6 100644 --- a/src/components/InfoRow.tsx +++ b/src/components/InfoRow.tsx @@ -5,7 +5,7 @@ type InfoRowProps = React.PropsWithChildren<{ }>; const InfoRow: React.FC = ({ title, children }) => ( -
+
{title}:
{children}