diff --git a/src/address/Contract.tsx b/src/address/Contract.tsx index e946391..1a30583 100644 --- a/src/address/Contract.tsx +++ b/src/address/Contract.tsx @@ -1,11 +1,10 @@ -import React, { useState, useEffect } from "react"; +import React from "react"; import { Light as SyntaxHighlighter } from "react-syntax-highlighter"; import hljs from "highlight.js"; import docco from "react-syntax-highlighter/dist/esm/styles/hljs/docco"; -import { sourcifySourceFile } from "../url"; - import hljsDefineSolidity from "highlightjs-solidity"; +import { useContract } from "../useSourcify"; hljsDefineSolidity(hljs); type ContractProps = { @@ -21,27 +20,7 @@ const Contract: React.FC = ({ filename, source, }) => { - const [content, setContent] = useState(source.content); - useEffect(() => { - if (source.content) { - return; - } - - const readContent = async () => { - const normalizedFilename = filename.replaceAll("@", "_"); - const url = sourcifySourceFile( - checksummedAddress, - networkId, - normalizedFilename - ); - const res = await fetch(url); - if (res.ok) { - const _content = await res.text(); - setContent(_content); - } - }; - readContent(); - }, [checksummedAddress, networkId, filename, source.content]); + const content = useContract(checksummedAddress, networkId, filename, source); return ( { + const [content, setContent] = useState(source.content); + + useEffect(() => { + if (source.content) { + return; + } + + const readContent = async () => { + const normalizedFilename = filename.replaceAll("@", "_"); + const url = sourcifySourceFile( + checksummedAddress, + networkId, + normalizedFilename + ); + const res = await fetch(url); + if (res.ok) { + const _content = await res.text(); + setContent(_content); + } + }; + readContent(); + }, [checksummedAddress, networkId, filename, source.content]); + + return content; +};