import React, { useEffect, useMemo, useContext } from "react"; import { useParams, NavLink } from "react-router-dom"; import { BigNumber } from "@ethersproject/bignumber"; import { commify } from "@ethersproject/units"; import { toUtf8String } from "@ethersproject/strings"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faBurn } from "@fortawesome/free-solid-svg-icons/faBurn"; import StandardFrame from "./StandardFrame"; import StandardSubtitle from "./StandardSubtitle"; import NavBlock from "./block/NavBlock"; import ContentFrame from "./ContentFrame"; import BlockNotFound from "./components/BlockNotFound"; import InfoRow from "./components/InfoRow"; import Timestamp from "./components/Timestamp"; import GasValue from "./components/GasValue"; import PercentageBar from "./components/PercentageBar"; import BlockLink from "./components/BlockLink"; import DecoratedAddressLink from "./components/DecoratedAddressLink"; import TransactionValue from "./components/TransactionValue"; import FormattedBalance from "./components/FormattedBalance"; import ETH2USDValue from "./components/ETH2USDValue"; import USDValue from "./components/USDValue"; import HexValue from "./components/HexValue"; import { RuntimeContext } from "./useRuntime"; import { useLatestBlockNumber } from "./useLatestBlock"; import { blockTxsURL } from "./url"; import { useBlockData } from "./useErigonHooks"; import { useETHUSDOracle } from "./usePriceOracle"; import { useChainInfo } from "./useChainInfo"; const Block: React.FC = () => { const { provider } = useContext(RuntimeContext); const { blockNumberOrHash } = useParams(); if (blockNumberOrHash === undefined) { throw new Error("blockNumberOrHash couldn't be undefined here"); } const { nativeCurrency: { name, symbol }, } = useChainInfo(); const block = useBlockData(provider, blockNumberOrHash); useEffect(() => { if (block !== undefined) { document.title = `Block #${blockNumberOrHash} | Otterscan`; } }, [blockNumberOrHash, block]); const extraStr = useMemo(() => { try { return block && toUtf8String(block.extraData); } catch (err) { console.info("Error while converting block extra data to string"); console.info(err); } }, [block]); const burntFees = block?.baseFeePerGas && block.baseFeePerGas.mul(block.gasUsed); const netFeeReward = block?.feeReward ?? BigNumber.from(0); const gasUsedPerc = block && block.gasUsed.mul(10000).div(block.gasLimit).toNumber() / 100; const latestBlockNumber = useLatestBlockNumber(provider); const blockETHUSDPrice = useETHUSDOracle(provider, block?.number); return (
Block #{blockNumberOrHash} {block && ( )}
{block === null && ( )} {block && ( {commify(block.number)} {block.transactionCount} transactions {" "} in this block {!netFeeReward.isZero() && ( <> {" "} ( +{" "} ) )} {blockETHUSDPrice && ( <> {" "} )} {commify(block.size)} bytes {block.baseFeePerGas && ( {" "} Gwei ( {" "} wei) )} {burntFees && (
{" "} {symbol}
)}
/{" "}
{extraStr} (Hex:{" "} {block.extraData}) {commify(block._difficulty.toString())} {commify(block.totalDifficulty.toString())} {block.nonce}
)}
); }; export default Block;