import React, { useEffect, useState } from "react"; import { JsonRpcProvider, Block } from "@ethersproject/providers"; import { commify } from "@ethersproject/units"; type CountdownProps = { provider: JsonRpcProvider; currentBlock: Block; targetBlock: number; }; const Countdown: React.FC = ({ provider, currentBlock, targetBlock, }) => { const [targetTimestamp, setTargetTimestamp] = useState(); useEffect(() => { const calcTime = async () => { const diff = targetBlock - currentBlock.number; const _prevBlock = await provider.getBlock(currentBlock.number - diff); const _targetTimestamp = currentBlock.timestamp + (currentBlock.timestamp - _prevBlock.timestamp); setTargetTimestamp(_targetTimestamp); }; calcTime(); }, [provider, currentBlock, targetBlock]); return (

London Network Upgrade

{commify(targetBlock - currentBlock.number)}

Blocks remaining

Current block: {commify(currentBlock.number)}
Target block: {commify(targetBlock)}

{targetTimestamp && (
{new Date(targetTimestamp * 1000).toLocaleDateString()} @{" "} {new Date(targetTimestamp * 1000).toLocaleTimeString()} (Estimative)
)}
); }; export default React.memo(Countdown);