import { Dispatch, SetStateAction, useEffect, useState } from "react"; import { ContractInput } from "./ContractInput"; import { getFunctionInputKey, getInitialTupleFormState } from "./utilsContract"; import { replacer } from "~~/utils/scaffold-eth/common"; import { AbiParameterTuple } from "~~/utils/scaffold-eth/contract"; type TupleProps = { abiTupleParameter: AbiParameterTuple; setParentForm: Dispatch>>; parentStateObjectKey: string; parentForm: Record | undefined; }; export const Tuple = ({ abiTupleParameter, setParentForm, parentStateObjectKey }: TupleProps) => { const [form, setForm] = useState>(() => getInitialTupleFormState(abiTupleParameter)); useEffect(() => { const values = Object.values(form); const argsStruct: Record = {}; abiTupleParameter.components.forEach((component, componentIndex) => { argsStruct[component.name || `input_${componentIndex}_`] = values[componentIndex]; }); setParentForm(parentForm => ({ ...parentForm, [parentStateObjectKey]: JSON.stringify(argsStruct, replacer) })); // eslint-disable-next-line react-hooks/exhaustive-deps }, [JSON.stringify(form, replacer)]); return (

{abiTupleParameter.internalType}

{abiTupleParameter?.components?.map((param, index) => { const key = getFunctionInputKey(abiTupleParameter.name || "tuple", param, index); return ; })}
); };