diff --git a/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/interact/FunctionField.tsx b/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/interact/FunctionField.tsx index 0556bcad6d..ae9a281c88 100644 --- a/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/interact/FunctionField.tsx +++ b/packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/interact/FunctionField.tsx @@ -4,7 +4,7 @@ import { Coins, ExternalLinkIcon, Eye, LoaderIcon, Send } from "lucide-react"; import Link from "next/link"; import { useParams } from "next/navigation"; import { toast } from "sonner"; -import { Abi, AbiFunction, Address, Hex, decodeEventLog, stringify } from "viem"; +import { Abi, AbiFunction, AbiParameter, Address, Hex, decodeEventLog, stringify } from "viem"; import { useAccount, useConfig } from "wagmi"; import { readContract, waitForTransactionReceipt, writeContract } from "wagmi/actions"; import { z } from "zod"; @@ -40,6 +40,20 @@ const formSchema = z.object({ value: z.string().optional(), }); +const getInputLabel = (input: AbiParameter): string => { + if (!("components" in input)) { + return input.type; + } + + const componentsString = input.components.map(getInputLabel).join(", "); + if (input.type === "tuple") { + return `[${componentsString}]`; + } else if (input.type === "tuple[]") { + return `[${componentsString}][]`; + } + return input.type; +}; + export function FunctionField({ worldAbi, functionAbi }: Props) { const operationType: FunctionType = functionAbi.stateMutability === "view" || functionAbi.stateMutability === "pure" @@ -55,15 +69,7 @@ export function FunctionField({ worldAbi, functionAbi }: Props) { const [events, setEvents] = useState(); const [txHash, setTxHash] = useState(); const txUrl = blockExplorerTransactionUrl({ hash: txHash, chainId }); - - const inputLabels = functionAbi.inputs.map((input) => { - if (input.type === "tuple" && "components" in input) { - return `[${input.components.map((c) => c.type).join(", ")}]`; - } else if (input.type === "tuple[]" && "components" in input) { - return `[${input.components.map((c) => c.type).join(", ")}][]`; - } - return input.type; - }); + const inputLabels = functionAbi.inputs.map(getInputLabel); const form = useForm>({ resolver: zodResolver(formSchema), @@ -128,7 +134,7 @@ export function FunctionField({ worldAbi, functionAbi }: Props) {

{functionAbi.name} - ({inputLabels.join(", ")}) + ({inputLabels.join(", ")}) {functionAbi.stateMutability === "payable" && } {(functionAbi.stateMutability === "view" || functionAbi.stateMutability === "pure") && (