import React, { useState, useContext } from "react"; import { NavLink, useHistory } from "react-router-dom"; import { ethers } from "ethers"; import Logo from "./Logo"; import Timestamp from "./components/Timestamp"; import { RuntimeContext } from "./useRuntime"; import { useLatestBlock } from "./useLatestBlock"; const Home: React.FC = () => { const { provider } = useContext(RuntimeContext); const [search, setSearch] = useState(); const [canSubmit, setCanSubmit] = useState(false); const history = useHistory(); const handleChange: React.ChangeEventHandler = (e) => { setCanSubmit(e.target.value.trim().length > 0); setSearch(e.target.value.trim()); }; const handleSubmit: React.FormEventHandler = (e) => { e.preventDefault(); if (!canSubmit) { return; } history.push(`/search?q=${search}`); }; const latestBlock = useLatestBlock(provider); document.title = "Home | Otterscan"; return (
{latestBlock && (
Latest block: {ethers.utils.commify(latestBlock.number)}
)}
); }; export default React.memo(Home);