Add language file info

This commit is contained in:
Willian Mitsuda 2021-07-25 05:09:30 -03:00
parent aeae3c3825
commit 5d24789998

View File

@ -6,13 +6,47 @@ import Contract from "./Contract";
import { sourcifyMetadata } from "../url"; import { sourcifyMetadata } from "../url";
import { RuntimeContext } from "../useRuntime"; import { RuntimeContext } from "../useRuntime";
type Metadata = {
version: string;
language: string;
compiler: {
version: string;
keccak256?: string | undefined;
};
sources: {
[filename: string]: {
keccak256: string;
content?: string | undefined;
urls?: string[];
};
};
settings: {
remappings: string[];
optimizer?: {
enabled: boolean;
runs: number;
};
compilationTarget: {
[filename: string]: string;
};
libraries: {
[filename: string]: string;
};
};
output: {
abi: any[];
userdocs: any[];
devdoc: any[];
};
};
type ContractsProps = { type ContractsProps = {
checksummedAddress: string; checksummedAddress: string;
}; };
const Contracts: React.FC<ContractsProps> = ({ checksummedAddress }) => { const Contracts: React.FC<ContractsProps> = ({ checksummedAddress }) => {
const { provider } = useContext(RuntimeContext); const { provider } = useContext(RuntimeContext);
const [rawMetadata, setRawMetadata] = useState<any>(); const [rawMetadata, setRawMetadata] = useState<Metadata | null | undefined>();
useEffect(() => { useEffect(() => {
if (!checksummedAddress) { if (!checksummedAddress) {
return; return;
@ -24,10 +58,9 @@ const Contracts: React.FC<ContractsProps> = ({ checksummedAddress }) => {
sourcifyMetadata(checksummedAddress, provider!.network.chainId) sourcifyMetadata(checksummedAddress, provider!.network.chainId)
); );
if (result.ok) { if (result.ok) {
const json = await result.json(); const _metadata = await result.json();
console.log(json); setRawMetadata(_metadata);
setRawMetadata(json); setSelected(Object.keys(_metadata.sources)[0]);
setSelected(Object.keys(json.sources)[0]);
} else { } else {
setRawMetadata(null); setRawMetadata(null);
} }
@ -47,8 +80,11 @@ const Contracts: React.FC<ContractsProps> = ({ checksummedAddress }) => {
<ContentFrame tabs> <ContentFrame tabs>
{rawMetadata && ( {rawMetadata && (
<> <>
<InfoRow title="Language">
<span>{rawMetadata.language}</span>
</InfoRow>
<InfoRow title="Compiler"> <InfoRow title="Compiler">
<span>{rawMetadata.compiler?.version}</span> <span>{rawMetadata.compiler.version}</span>
</InfoRow> </InfoRow>
<InfoRow title="Optimizer Enabled"> <InfoRow title="Optimizer Enabled">
{optimizer?.enabled ? ( {optimizer?.enabled ? (