From 971554fe82b9facabdbf31792043df730cd15cd9 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Wed, 31 Aug 2022 17:20:02 -0300 Subject: [PATCH 1/2] Add support for partial match on Sourcify --- src/AddressMainPage.tsx | 10 ++-- src/address/ContractFromRepo.tsx | 7 ++- src/address/Contracts.tsx | 45 +++++++++-------- src/components/DecoratedAddressLink.tsx | 4 +- src/sourcify/useSourcify.ts | 64 +++++++++++++++++++++---- src/transaction/Details.tsx | 3 +- src/transaction/LogEntry.tsx | 10 ++-- src/url.ts | 19 ++++---- 8 files changed, 110 insertions(+), 52 deletions(-) diff --git a/src/AddressMainPage.tsx b/src/AddressMainPage.tsx index 77a3e80..a00263a 100644 --- a/src/AddressMainPage.tsx +++ b/src/AddressMainPage.tsx @@ -55,7 +55,7 @@ const AddressMainPage: React.FC = ({}) => { const { provider } = useContext(RuntimeContext); const hasCode = useHasCode(provider, checksummedAddress, "latest"); - const addressMetadata = useSourcifyMetadata( + const match = useSourcifyMetadata( hasCode ? checksummedAddress : undefined, provider?.network.chainId ); @@ -110,18 +110,18 @@ const AddressMainPage: React.FC = ({}) => { Contract - {addressMetadata === undefined ? ( + {match === undefined ? ( - ) : addressMetadata === null ? ( + ) : match === null ? ( @@ -153,7 +153,7 @@ const AddressMainPage: React.FC = ({}) => { element={ } /> diff --git a/src/address/ContractFromRepo.tsx b/src/address/ContractFromRepo.tsx index 568babf..12e0899 100644 --- a/src/address/ContractFromRepo.tsx +++ b/src/address/ContractFromRepo.tsx @@ -1,25 +1,28 @@ import React from "react"; import { SyntaxHighlighter, docco } from "../highlight-init"; -import { useContract } from "../sourcify/useSourcify"; +import { MatchType, useContract } from "../sourcify/useSourcify"; import { useAppConfigContext } from "../useAppConfig"; type ContractFromRepoProps = { checksummedAddress: string; networkId: number; filename: string; + type: MatchType; }; const ContractFromRepo: React.FC = ({ checksummedAddress, networkId, filename, + type, }) => { const { sourcifySource } = useAppConfigContext(); const content = useContract( checksummedAddress, networkId, filename, - sourcifySource + sourcifySource, + type ); return ( diff --git a/src/address/Contracts.tsx b/src/address/Contracts.tsx index d3e4179..e5ba03d 100644 --- a/src/address/Contracts.tsx +++ b/src/address/Contracts.tsx @@ -8,39 +8,39 @@ import InfoRow from "../components/InfoRow"; import Contract from "./Contract"; import ContractFromRepo from "./ContractFromRepo"; import { RuntimeContext } from "../useRuntime"; -import { Metadata } from "../sourcify/useSourcify"; +import { Match, MatchType } from "../sourcify/useSourcify"; import ExternalLink from "../components/ExternalLink"; import { openInRemixURL } from "../url"; import ContractABI from "./ContractABI"; type ContractsProps = { checksummedAddress: string; - rawMetadata: Metadata | null | undefined; + match: Match | null | undefined; }; -const Contracts: React.FC = ({ - checksummedAddress, - rawMetadata, -}) => { +const Contracts: React.FC = ({ checksummedAddress, match }) => { const { provider } = useContext(RuntimeContext); const [selected, setSelected] = useState(); useEffect(() => { - if (rawMetadata) { - setSelected(Object.keys(rawMetadata.sources)[0]); + if (match) { + setSelected(Object.keys(match.metadata.sources)[0]); } - }, [rawMetadata]); - const optimizer = rawMetadata?.settings?.optimizer; + }, [match]); + const optimizer = match?.metadata.settings?.optimizer; return ( - {rawMetadata && ( + {match && ( <> + + {match.type === MatchType.FULL_MATCH ? "Full" : "Partial"} + - {rawMetadata.language} + {match.metadata.language} - {rawMetadata.compiler.version} + {match.metadata.compiler.version} {optimizer?.enabled ? ( @@ -58,19 +58,19 @@ const Contracts: React.FC = ({ )}
- {rawMetadata === undefined && ( + {match === undefined && ( Getting data from Sourcify repository... )} - {rawMetadata === null && ( + {match === null && ( Address is not a contract or couldn't find contract metadata in Sourcify repository. )} - {rawMetadata !== undefined && rawMetadata !== null && ( + {match !== undefined && match !== null && ( <> - {rawMetadata.output.abi && ( - + {match.metadata.output.abi && ( + )}
@@ -96,7 +96,7 @@ const Contracts: React.FC = ({
- {Object.entries(rawMetadata.sources).map(([k]) => ( + {Object.entries(match.metadata.sources).map(([k]) => (