From 851a791375662667ddd28e39528c44ce4dd080f5 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Fri, 23 Jul 2021 15:36:31 -0300 Subject: [PATCH] Add more compilation info --- src/address/Contract.tsx | 46 +++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/src/address/Contract.tsx b/src/address/Contract.tsx index d7f9de6..ae019a4 100644 --- a/src/address/Contract.tsx +++ b/src/address/Contract.tsx @@ -1,6 +1,8 @@ import React, { useState, useEffect } from "react"; +import { ethers } from "ethers"; import ContentFrame from "../ContentFrame"; import Highlight from "react-highlight"; +import InfoRow from "../components/InfoRow"; import "highlight.js/styles/stackoverflow-light.css"; import hljs from "highlight.js"; @@ -13,9 +15,7 @@ type ContractProps = { }; const Contract: React.FC = ({ checksummedAddress }) => { - const [sources, setSources] = useState< - { [fileName: string]: any } | undefined | null - >(undefined); + const [rawMetadata, setRawMetadata] = useState(); useEffect(() => { if (!checksummedAddress) { return; @@ -29,14 +29,14 @@ const Contract: React.FC = ({ checksummedAddress }) => { if (result.ok) { const json = await result.json(); console.log(json); - setSources(json.sources); + setRawMetadata(json); setSelected(Object.keys(json.sources)[0]); } else { - setSources(null); + setRawMetadata(null); } } catch (err) { console.error(err); - setSources(null); + setRawMetadata(null); } }; fetchMetadata(); @@ -44,15 +44,37 @@ const Contract: React.FC = ({ checksummedAddress }) => { const [selected, setSelected] = useState(); + const optimizer = rawMetadata?.settings?.optimizer; + return ( + {rawMetadata && ( + <> + + {rawMetadata.compiler?.version} + + + {optimizer?.enabled ? ( + + Yes with{" "} + + {ethers.utils.commify(optimizer?.runs)} + {" "} + runs + + ) : ( + No + )} + + + )}
- {sources === null && ( + {rawMetadata === null && ( Couldn't find contract metadata in Sourcify repository. )} - {sources !== undefined && sources !== null && ( - <> - {Object.entries(sources).map(([k]) => ( + {rawMetadata !== undefined && rawMetadata !== null && ( +
+ {Object.entries(rawMetadata.sources).map(([k]) => (
)}