import React, { useState, useEffect, useContext } from "react"; import { commify } from "@ethersproject/units"; import { Menu } from "@headlessui/react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faChevronDown } from "@fortawesome/free-solid-svg-icons/faChevronDown"; import ContentFrame from "../ContentFrame"; import InfoRow from "../components/InfoRow"; import Contract from "./Contract"; import ContractFromRepo from "./ContractFromRepo"; import { RuntimeContext } from "../useRuntime"; import { Match, MatchType } from "../sourcify/useSourcify"; import ExternalLink from "../components/ExternalLink"; import { openInRemixURL } from "../url"; import ContractABI from "./ContractABI"; type ContractsProps = { checksummedAddress: string; match: Match | null | undefined; }; const Contracts: React.FC = ({ checksummedAddress, match }) => { const { provider } = useContext(RuntimeContext); const [selected, setSelected] = useState(); useEffect(() => { if (match) { setSelected(Object.keys(match.metadata.sources)[0]); } }, [match]); const optimizer = match?.metadata.settings?.optimizer; return ( {match && ( <> {match.type === MatchType.FULL_MATCH ? "Full" : "Partial"} {match.metadata.language} {match.metadata.compiler.version} {optimizer?.enabled ? ( Yes with{" "} {commify(optimizer?.runs)} {" "} runs ) : ( No )} )}
{match === undefined && ( Getting data from Sourcify repository... )} {match === null && ( Address is not a contract or couldn't find contract metadata in Sourcify repository. )} {match !== undefined && match !== null && ( <> {match.metadata.output.abi && ( )}
{selected} {provider && (
Open in Remix
)}
{Object.entries(match.metadata.sources).map(([k]) => ( ))}
{selected && ( <> {match.metadata.sources[selected].content ? ( ) : ( )} )}
)}
); }; export default React.memo(Contracts);