"use client"; import { Dispatch, SetStateAction } from "react"; import { Tuple } from "./Tuple"; import { TupleArray } from "./TupleArray"; import { AbiParameter } from "abitype"; import { AddressInput, Bytes32Input, BytesInput, InputBase, IntegerInput, IntegerVariant, } from "~~/components/scaffold-eth"; import { AbiParameterTuple } from "~~/utils/scaffold-eth/contract"; type ContractInputProps = { setForm: Dispatch>>; form: Record | undefined; stateObjectKey: string; paramType: AbiParameter; }; /** * Generic Input component to handle input's based on their function param type */ export const ContractInput = ({ setForm, form, stateObjectKey, paramType }: ContractInputProps) => { const inputProps = { name: stateObjectKey, value: form?.[stateObjectKey], placeholder: paramType.name ? `${paramType.type} ${paramType.name}` : paramType.type, onChange: (value: any) => { setForm(form => ({ ...form, [stateObjectKey]: value })); }, }; const renderInput = () => { switch (paramType.type) { case "address": return ; case "bytes32": return ; case "bytes": return ; case "string": return ; case "tuple": return ( ); default: // Handling 'int' types and 'tuple[]' types if (paramType.type.includes("int") && !paramType.type.includes("[")) { return ; } else if (paramType.type.startsWith("tuple[")) { return ( ); } else { return ; } } }; return (
{paramType.name && {paramType.name}} {paramType.type}
{renderInput()}
); };