import React, { useEffect, useCallback, useContext } from "react"; import { Routes, Route, useNavigate, useParams, useSearchParams, } from "react-router-dom"; import { Tab } from "@headlessui/react"; import Blockies from "react-blockies"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faCircleNotch } from "@fortawesome/free-solid-svg-icons/faCircleNotch"; import { faQuestionCircle } from "@fortawesome/free-regular-svg-icons/faQuestionCircle"; import StandardFrame from "./StandardFrame"; import StandardSubtitle from "./StandardSubtitle"; import AddressOrENSNameNotFound from "./components/AddressOrENSNameNotFound"; import Copy from "./components/Copy"; import Faucet from "./components/Faucet"; import NavTab from "./components/NavTab"; import SourcifyLogo from "./sourcify/SourcifyLogo"; import AddressTransactionResults from "./address/AddressTransactionResults"; import Contracts from "./address/Contracts"; import { RuntimeContext } from "./useRuntime"; import { useHasCode } from "./useErigonHooks"; import { useChainInfo } from "./useChainInfo"; import { useAddressOrENS } from "./useResolvedAddresses"; import { useSourcifyMetadata } from "./sourcify/useSourcify"; import { ChecksummedAddress } from "./types"; type AddressMainPageProps = {}; const AddressMainPage: React.FC = ({}) => { const { addressOrName, direction } = useParams(); if (addressOrName === undefined) { throw new Error("addressOrName couldn't be undefined here"); } const navigate = useNavigate(); const [searchParams] = useSearchParams(); const urlFixer = useCallback( (address: ChecksummedAddress) => { navigate( `/address/${address}${ direction ? "/" + direction : "" }?${searchParams.toString()}`, { replace: true } ); }, [navigate, direction, searchParams] ); const [checksummedAddress, isENS, error] = useAddressOrENS( addressOrName, urlFixer ); const { provider } = useContext(RuntimeContext); const hasCode = useHasCode(provider, checksummedAddress, "latest"); const addressMetadata = useSourcifyMetadata( hasCode ? checksummedAddress : undefined, provider?.network.chainId ); const { network, faucets } = useChainInfo(); useEffect(() => { if (isENS || checksummedAddress === undefined) { document.title = `Address ${addressOrName} | Otterscan`; } else { document.title = `Address ${checksummedAddress} | Otterscan`; } }, [addressOrName, checksummedAddress, isENS]); return ( {error ? ( ) : ( checksummedAddress && ( <>
Address {checksummedAddress} {/* Only display faucets for testnets who actually have any */} {network === "testnet" && faucets && faucets.length > 0 && ( )} {isENS && ( ENS: {addressOrName} )}
Overview {hasCode && ( Contract {addressMetadata === undefined ? ( ) : addressMetadata === null ? ( ) : ( )} )} } /> } /> } /> ) )}
); }; export default AddressMainPage;