Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/evm contract verified compiler #1207

Merged
merged 4 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- [#1207](https://github.com/alleslabs/celatone-frontend/pull/1207) Add EVM contract details compiler settings
- [#1206](https://github.com/alleslabs/celatone-frontend/pull/1206) Add EVM contract details abi
- [#1204](https://github.com/alleslabs/celatone-frontend/pull/1204) Add EVM contract details deployed bytecode
- [#1203](https://github.com/alleslabs/celatone-frontend/pull/1203) Fetch EVM verify config from API, and wire up to UIs as initial values
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Heading, Stack } from "@chakra-ui/react";
import JsonReadOnly from "lib/components/json/JsonReadOnly";
import { jsonPrettify } from "lib/utils";

interface ContractCompilerProps {
compilerSettings: string;
}

export const ContractCompiler = ({
compilerSettings,
}: ContractCompilerProps) => (
<Stack gap={4}>
<Heading as="h6" variant="h7">
Compiler Setting
</Heading>
<JsonReadOnly text={jsonPrettify(compilerSettings)} />
</Stack>
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { Flex, Stack } from "@chakra-ui/react";
import { NotVerifiedDetails } from "lib/components/evm-verify-section";
import { HexAddr20 } from "lib/types";
import { EvmContractDetailsContractTabs } from "../../types";
import { useState } from "react";
import { useEffect, useState } from "react";
import { TypeSwitch } from "lib/components/TypeSwitch";
import { ContractByteCode, ContractByteCodeProps } from "./ContractByteCode";
import { ContractAbi } from "./ContractAbi";
import { useEvmVerifyInfo } from "lib/services/verification/evm";
import { ErrorFetching } from "lib/components/state";
import { Loading } from "lib/components/Loading";
import { ContractCompiler } from "./ContractCompiler";

interface EvmContractDetailsContractProps extends ContractByteCodeProps {
contractAddress: HexAddr20;
Expand All @@ -18,27 +19,39 @@ export const EvmContractDetailsContract = ({
code,
deployedCode,
}: EvmContractDetailsContractProps) => {
const { data } = useEvmVerifyInfo(contractAddress);
const { data, isLoading } = useEvmVerifyInfo(contractAddress);

const [currentTab, setCurrentTab] = useState(
EvmContractDetailsContractTabs.Abi
EvmContractDetailsContractTabs.Code
);

if (!data) return <ErrorFetching dataName="evm contract information" />;
useEffect(() => {
if (isLoading || data) return;
setCurrentTab(EvmContractDetailsContractTabs.ByteCode);
}, [isLoading, data]);

if (isLoading) return <Loading />;

return (
<Stack gap={8}>
{/* // TODO: Support all status */}
<NotVerifiedDetails contractAddress={contractAddress} />
<Flex>
<TypeSwitch
tabs={Object.values(EvmContractDetailsContractTabs)}
onTabChange={setCurrentTab}
currentTab={currentTab}
/>
</Flex>
{currentTab === EvmContractDetailsContractTabs.Abi && (
<ContractAbi abi={data.abi} />
{data && (
<>
<Flex>
<TypeSwitch
tabs={Object.values(EvmContractDetailsContractTabs)}
onTabChange={setCurrentTab}
currentTab={currentTab}
/>
</Flex>
{currentTab === EvmContractDetailsContractTabs.Compiler && (
<ContractCompiler compilerSettings={data.settings} />
)}
{currentTab === EvmContractDetailsContractTabs.Abi && (
<ContractAbi abi={data.abi} />
)}
</>
)}
{currentTab === EvmContractDetailsContractTabs.ByteCode && (
<ContractByteCode code={code} deployedCode={deployedCode} />
Expand Down