From 799fc4dd285f309855e034622d07d616774e135e Mon Sep 17 00:00:00 2001 From: Neven Dyulgerov Date: Fri, 4 Oct 2024 17:37:47 +0300 Subject: [PATCH 01/40] test(apps/web): Pass json_abi specifications to raw input form --- apps/web/src/components/sendTransaction.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/sendTransaction.tsx b/apps/web/src/components/sendTransaction.tsx index 182b98f23..c65b5dfbb 100644 --- a/apps/web/src/components/sendTransaction.tsx +++ b/apps/web/src/components/sendTransaction.tsx @@ -17,6 +17,9 @@ import { useSearchMultiTokens } from "../hooks/useSearchMultiTokens"; import { useSearchTokens } from "../hooks/useSearchTokens"; import getConfiguredChainId from "../lib/getConfiguredChain"; import { BlockExplorerLink } from "./BlockExplorerLink"; +import { useSpecification } from "./specification/hooks/useSpecification"; +import { JSON_ABI } from "./specification/types"; +import { RawInputFormSpecification } from "@cartesi/rollups-explorer-ui/src/RawInputForm"; export type DepositType = | "ether" @@ -34,7 +37,7 @@ interface DepositProps { const DEBOUNCE_TIME = 400 as const; const SendTransaction: FC = ({ - initialDepositType = "ether", + initialDepositType = "input", }) => { const [depositType, setDepositType] = useState(initialDepositType); @@ -63,6 +66,9 @@ const SendTransaction: FC = ({ address: debouncedMultiTokenId, chainId, }); + const { listSpecifications } = useSpecification(); + const specifications = + listSpecifications()?.filter((s) => s.mode === JSON_ABI) ?? []; const onSuccess = useCallback( ({ receipt, type }: TransactionFormSuccessData) => { @@ -120,7 +126,7 @@ const SendTransaction: FC = ({ }, { group: "Other", - items: [{ value: "input", label: "Raw Input" }], + items: [{ value: "input", label: "Generic Input" }], }, ]} value={depositType} @@ -156,6 +162,9 @@ const SendTransaction: FC = ({ ) : depositType === "input" ? ( Date: Fri, 4 Oct 2024 17:38:37 +0300 Subject: [PATCH 02/40] test(apps/web): Add abi option for raw input form --- packages/ui/src/RawInputForm.tsx | 56 +++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/packages/ui/src/RawInputForm.tsx b/packages/ui/src/RawInputForm.tsx index c0b096d8e..c798b6428 100644 --- a/packages/ui/src/RawInputForm.tsx +++ b/packages/ui/src/RawInputForm.tsx @@ -10,6 +10,7 @@ import { Group, Loader, SegmentedControl, + Select, Stack, Textarea, } from "@mantine/core"; @@ -17,6 +18,7 @@ import { useForm } from "@mantine/form"; import { FC, useCallback, useEffect, useState } from "react"; import { TbAlertCircle, TbCheck } from "react-icons/tb"; import { + Abi, BaseError, getAddress, Hex, @@ -30,10 +32,17 @@ import { TransactionProgress } from "./TransactionProgress"; import useUndeployedApplication from "./hooks/useUndeployedApplication"; import { TransactionFormSuccessData } from "./DepositFormTypes"; -type Format = "hex" | "utf"; +type Format = "hex" | "string" | "abi"; + +export interface RawInputFormSpecification { + id: string; + name: string; + abi: Abi; +} export interface RawInputFormProps { applications: string[]; + specifications: RawInputFormSpecification[]; isLoadingApplications: boolean; onSearchApplications: (applicationId: string) => void; onSuccess: (receipt: TransactionFormSuccessData) => void; @@ -42,6 +51,7 @@ export interface RawInputFormProps { export const RawInputForm: FC = (props) => { const { applications, + specifications, isLoadingApplications, onSearchApplications, onSuccess, @@ -52,6 +62,8 @@ export const RawInputForm: FC = (props) => { application: "", rawInput: "0x", stringInput: "", + abiMethod: "existing", + specificationId: "", }, validate: { application: (value) => @@ -63,9 +75,10 @@ export const RawInputForm: FC = (props) => { ? getAddress(values.application) : zeroAddress, rawInput: values.rawInput as Hex, + abiMethod: values.abiMethod, }), }); - const { address, rawInput } = form.getTransformedValues(); + const { address, rawInput, abiMethod } = form.getTransformedValues(); const prepare = useSimulateInputBoxAddInput({ args: [address, rawInput], query: { @@ -81,6 +94,10 @@ export const RawInputForm: FC = (props) => { const canSubmit = form.isValid() && prepare.error === null; const isUndeployedApp = useUndeployedApplication(address, applications); const [format, setFormat] = useState("hex"); + const specificationOptions = specifications.map((s) => ({ + value: s.id, + label: s.name, + })); const onChangeFormat = useCallback((format: string | null) => { setFormat(format as Format); @@ -136,7 +153,8 @@ export const RawInputForm: FC = (props) => { onChange={onChangeFormat} data={[ { label: "Hex", value: "hex" }, - { label: "String to Hex", value: "utf" }, + { label: "String to Hex", value: "string" }, + { label: "ABI to Hex", value: "abi" }, ]} /> @@ -147,7 +165,7 @@ export const RawInputForm: FC = (props) => { withAsterisk {...form.getInputProps("rawInput")} /> - ) : ( + ) : format === "string" ? ( <>