import React, { useState, useEffect, useContext } from "react"; import { ethers } from "ethers"; import { Transition } from "@headlessui/react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faBurn, faCoins, faCube, faGasPump, } from "@fortawesome/free-solid-svg-icons"; import BlockRecord from "./BlockRecord"; import { ExtendedBlock, readBlock } from "../useErigonHooks"; import { RuntimeContext } from "../useRuntime"; const MAX_BLOCK_HISTORY = 20; type BlocksProps = { latestBlock: ethers.providers.Block; }; const Blocks: React.FC = ({ latestBlock }) => { const { provider } = useContext(RuntimeContext); const [blocks, setBlock] = useState([]); const [now, setNow] = useState(Date.now()); useEffect(() => { if (!provider) { return; } const _readBlock = async () => { const extBlock = await readBlock(provider, latestBlock.number.toString()); setNow(Date.now()); setBlock((_blocks) => { if (_blocks.length > 0 && latestBlock.number === _blocks[0].number) { return _blocks; } return [extBlock, ..._blocks].slice(0, MAX_BLOCK_HISTORY + 1); }); }; _readBlock(); }, [provider, latestBlock]); return (
Block
Gas used
Gas target
Base fee
Rewards
Burnt fees
Age
{blocks.map((b, i) => ( ))}
); }; export default React.memo(Blocks);