import React, { useEffect, useState } from "react"; import { ethers } from "ethers"; type CountdownProps = { provider: ethers.providers.JsonRpcProvider; currentBlock: ethers.providers.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

{ethers.utils.commify(targetBlock - currentBlock.number)}

Block remaining

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

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