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

Feat(components): add deployed bytecode #1204

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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

- [#1204](https://github.com/alleslabs/celatone-frontend/pull/1204) Add EVM contract details deployed bytecode
- [#1202](https://github.com/alleslabs/celatone-frontend/pull/1202) Add EVM contract interaction form
- [#1201](https://github.com/alleslabs/celatone-frontend/pull/1201) Add EVM contract verification with upload files
- [#1200](https://github.com/alleslabs/celatone-frontend/pull/1200) Add EVM contract verification with contract code
Expand Down
79 changes: 79 additions & 0 deletions src/lib/components/TypeSwitch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Flex } from "@chakra-ui/react";
import { useCallback } from "react";

import { MotionBox } from "lib/components/MotionBox";

interface TypeSwitchProps<T extends string> {
tabs: T[];
currentTab: T;
disabled?: boolean;
onTabChange: (newType: T) => void;
}

export const TypeSwitch = <T extends string>({
tabs,
currentTab,
disabled = false,
onTabChange: onTabChangeProps,
}: TypeSwitchProps<T>) => {
const activeIndex = currentTab ? tabs.indexOf(currentTab) : 0;

const onTabChange = useCallback(
(tab: T) => {
onTabChangeProps(tab);
},
[onTabChangeProps]
);

return (
<Flex
border="1px solid var(--chakra-colors-gray-700)"
borderRadius="4px"
p={1}
direction="row"
align="center"
position="relative"
sx={{ ...(disabled ? { pointerEvents: "none", opacity: 0.3 } : {}) }}
>
{tabs.map((tab) => (
<MotionBox
key={tab}
cursor="pointer"
p="2px 10px"
w="96px"
fontSize="12px"
fontWeight={700}
variants={{
active: { color: "var(--chakra-colors-text-main)" },
inactive: {
color: "var(--chakra-colors-primary-light)",
},
}}
initial="inactive"
animate={currentTab === tab ? "active" : "inactive"}
onClick={() => onTabChange(tab as T)}
zIndex={1}
textAlign="center"
textTransform="capitalize"
>
{tab}
</MotionBox>
))}
<MotionBox
w="96px"
h="22px"
position="absolute"
borderRadius="2px"
backgroundColor="primary.darker"
animate={{
left: `${activeIndex * 96 + 4}px`,
}}
transition={{
type: "spring",
stiffness: "250",
damping: "30",
}}
/>
</Flex>
);
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Heading, Stack } from "@chakra-ui/react";
import { TextReadOnly } from "lib/components/json/TextReadOnly";
import { Option } from "lib/types";

export interface ContractByteCodeProps {
code: Option<string>;
deployedCode: string;
}

export const ContractByteCode = ({
code = "",
deployedCode,
}: ContractByteCodeProps) => (
<Stack gap={8}>
<Stack gap={4}>
<Heading as="h6" variant="h7">
ByteCode
</Heading>
<TextReadOnly text={code} canCopy />
</Stack>
<Stack gap={4}>
<Heading as="h6" variant="h7">
Deployed ByteCode
</Heading>
<TextReadOnly text={deployedCode} canCopy />
</Stack>
</Stack>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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 { TypeSwitch } from "lib/components/TypeSwitch";
import { ContractByteCode, ContractByteCodeProps } from "./ContractByteCode";

interface EvmContractDetailsContractProps extends ContractByteCodeProps {
contractAddress: HexAddr20;
}

export const EvmContractDetailsContract = ({
contractAddress,
code,
deployedCode,
}: EvmContractDetailsContractProps) => {
const [currentTab, setCurrentTab] = useState(
EvmContractDetailsContractTabs.ByteCode
);

return (
<Stack gap={8}>
{/* // TODO: Support all status */}
<NotVerifiedDetails contractAddress={contractAddress} />
<Flex>
<TypeSwitch
tabs={Object.values(EvmContractDetailsContractTabs)}
onTabChange={setCurrentTab}
currentTab={currentTab}
/>
</Flex>
{currentTab === EvmContractDetailsContractTabs.ByteCode && (
<ContractByteCode code={code} deployedCode={deployedCode} />
)}
</Stack>
);
};
7 changes: 4 additions & 3 deletions src/lib/pages/evm-contract-details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useEvmTxHashByCosmosTxHash } from "lib/services/tx";
import type { HexAddr20 } from "lib/types";
import { isHexWalletAddress, truncate } from "lib/utils";

import { EvmContractDetailsBytecode } from "./components/EvmContractDetailsBytecode";
import { EvmContractDetailsContract } from "./components/EvmContractDetailsContarct";
import { EvmContractDetailsOverview } from "./components/EvmContractDetailsOverview";
import { EvmContractDetailsTop } from "./components/EvmContractDetailsTop";
import { EvmContractDetailsTxs } from "./components/EvmContractDetailsTxs";
Expand Down Expand Up @@ -140,8 +140,9 @@ const EvmContractDetailsBody = ({
/>
</TabPanel>
<TabPanel p={0} pt={8}>
<EvmContractDetailsBytecode
code={evmCodesByAddressData.code}
<EvmContractDetailsContract
deployedCode={evmCodesByAddressData.code}
code={evmContractInfoData?.code}
contractAddress={contractAddress}
/>
</TabPanel>
Expand Down
7 changes: 7 additions & 0 deletions src/lib/pages/evm-contract-details/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ export enum TabIndex {
Transactions = "transactions",
}

export enum EvmContractDetailsContractTabs {
Code = "code",
Compiler = "compiler",
Abi = "abi",
ByteCode = "byteCode",
}

export const zEvmContractDetailsQueryParams = z.object({
contractAddress: zHexAddr20,
tab: z.union([
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion src/lib/pages/interact-contract/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./execute-area";
export * from "./query-area";
export * from "./InteractionTypeSwitch";
export * from "./InteractionWrapper";
11 changes: 4 additions & 7 deletions src/lib/pages/interact-contract/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ import type { BechAddr32, Coin } from "lib/types";
import { ContractInteractionTabs } from "lib/types";
import { jsonPrettify, jsonValidate, libDecode } from "lib/utils";

import {
ExecuteArea,
InteractionTypeSwitch,
InteractionWrapper,
QueryArea,
} from "./components";
import { ExecuteArea, InteractionWrapper, QueryArea } from "./components";
import type { InteractContractQueryParams } from "./types";
import { zInteractContractQueryParams } from "./types";
import { TypeSwitch } from "lib/components/TypeSwitch";

const INTERACT_CONTRACT_PATH_NAME = "/interact-contract";

Expand Down Expand Up @@ -154,7 +150,8 @@ const InteractContractBody = ({
{capitalize(selectedType)} Message
</Heading>
{!isMobile && (
<InteractionTypeSwitch
<TypeSwitch
tabs={Object.values(ContractInteractionTabs)}
currentTab={selectedType}
onTabChange={handleSetSelectedType}
/>
Expand Down
5 changes: 5 additions & 0 deletions src/lib/services/evm/lcd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ export const getEvmContractInfoSequencer = async (
const tx = txs.items[0];
const sender = convertAccountPubkeyToAccountAddress(tx.signerPubkey, prefix);

const createEvent = tx.events?.find((event) => event.type === "create");
const code =
createEvent?.attributes?.find((attr) => attr.key === "ret")?.value ?? "";

return {
hash: tx.hash,
sender,
created: tx.created,
code,
};
};
Loading