2021-07-08 19:02:42 +00:00
|
|
|
import React, { useState, useContext } from "react";
|
2021-07-01 18:21:40 +00:00
|
|
|
import { NavLink, useHistory } from "react-router-dom";
|
2021-08-08 22:49:45 +00:00
|
|
|
import { commify } from "@ethersproject/units";
|
2021-07-30 08:18:28 +00:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2021-08-08 06:51:21 +00:00
|
|
|
import { faBurn } from "@fortawesome/free-solid-svg-icons/faBurn";
|
2021-07-01 18:21:40 +00:00
|
|
|
import Logo from "./Logo";
|
|
|
|
import Timestamp from "./components/Timestamp";
|
2021-07-09 05:07:20 +00:00
|
|
|
import { RuntimeContext } from "./useRuntime";
|
2021-07-04 01:42:06 +00:00
|
|
|
import { useLatestBlock } from "./useLatestBlock";
|
2021-07-23 22:46:21 +00:00
|
|
|
import { blockURL } from "./url";
|
2021-07-01 18:21:40 +00:00
|
|
|
|
|
|
|
const Home: React.FC = () => {
|
2021-07-09 05:07:20 +00:00
|
|
|
const { provider } = useContext(RuntimeContext);
|
2021-07-01 18:21:40 +00:00
|
|
|
const [search, setSearch] = useState<string>();
|
|
|
|
const [canSubmit, setCanSubmit] = useState<boolean>(false);
|
|
|
|
const history = useHistory();
|
|
|
|
|
|
|
|
const handleChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
|
|
|
|
setCanSubmit(e.target.value.trim().length > 0);
|
|
|
|
setSearch(e.target.value.trim());
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleSubmit: React.FormEventHandler<HTMLFormElement> = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
if (!canSubmit) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
history.push(`/search?q=${search}`);
|
|
|
|
};
|
|
|
|
|
2021-07-08 19:02:42 +00:00
|
|
|
const latestBlock = useLatestBlock(provider);
|
2021-07-01 18:21:40 +00:00
|
|
|
|
|
|
|
document.title = "Home | Otterscan";
|
|
|
|
|
|
|
|
return (
|
2021-07-10 06:17:07 +00:00
|
|
|
<div className="m-auto">
|
|
|
|
<Logo />
|
|
|
|
<form
|
|
|
|
className="flex flex-col"
|
|
|
|
onSubmit={handleSubmit}
|
|
|
|
autoComplete="off"
|
|
|
|
spellCheck={false}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
className="w-full border rounded focus:outline-none px-2 py-1 mb-10"
|
|
|
|
type="text"
|
|
|
|
size={50}
|
|
|
|
placeholder="Search by address / txn hash / block number / ENS name"
|
|
|
|
onChange={handleChange}
|
|
|
|
autoFocus
|
|
|
|
></input>
|
|
|
|
<button
|
|
|
|
className="mx-auto px-3 py-1 mb-10 rounded bg-gray-100 hover:bg-gray-200 focus:outline-none"
|
|
|
|
type="submit"
|
2021-07-01 18:21:40 +00:00
|
|
|
>
|
2021-07-10 06:17:07 +00:00
|
|
|
Search
|
|
|
|
</button>
|
2021-07-29 04:24:39 +00:00
|
|
|
<div className="mx-auto mt-5 mb-5 text-lg text-link-blue hover:text-link-blue-hover font-bold">
|
|
|
|
<NavLink to="/special/london">
|
2021-07-30 08:18:28 +00:00
|
|
|
<div className="flex space-x-2 items-baseline text-orange-500 hover:text-orange-700 hover:underline">
|
|
|
|
<span>
|
|
|
|
<FontAwesomeIcon icon={faBurn} />
|
|
|
|
</span>
|
2021-07-30 21:02:11 +00:00
|
|
|
<span>Check out the special dashboard for EIP-1559</span>
|
2021-07-30 08:18:28 +00:00
|
|
|
<span>
|
|
|
|
<FontAwesomeIcon icon={faBurn} />
|
|
|
|
</span>
|
|
|
|
</div>
|
2021-07-29 04:24:39 +00:00
|
|
|
</NavLink>
|
|
|
|
</div>
|
2021-07-10 06:17:07 +00:00
|
|
|
{latestBlock && (
|
|
|
|
<NavLink
|
|
|
|
className="mx-auto flex flex-col items-center space-y-1 mt-5 text-sm text-gray-500 hover:text-link-blue"
|
2021-07-23 22:46:21 +00:00
|
|
|
to={blockURL(latestBlock.number)}
|
2021-07-01 18:21:40 +00:00
|
|
|
>
|
2021-08-08 22:49:45 +00:00
|
|
|
<div>Latest block: {commify(latestBlock.number)}</div>
|
2021-07-10 06:17:07 +00:00
|
|
|
<Timestamp value={latestBlock.timestamp} />
|
|
|
|
</NavLink>
|
|
|
|
)}
|
|
|
|
</form>
|
2021-07-01 18:21:40 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default React.memo(Home);
|