11import { FormFieldSetup } from "@/components/blocks/FormFieldSetup" ;
22import { Checkbox , CheckboxWithLabel } from "@/components/ui/checkbox" ;
3+ import { InlineCode } from "@/components/ui/inline-code" ;
34import { Input } from "@/components/ui/input" ;
45import { Separator } from "@/components/ui/separator" ;
56import { Switch } from "@/components/ui/switch" ;
@@ -11,8 +12,6 @@ import { camelToTitle } from "contract-ui/components/solidity-inputs/helpers";
1112import { getTemplateValuesForType } from "lib/deployment/template-values" ;
1213import { useState } from "react" ;
1314import { useFormContext } from "react-hook-form" ;
14- import { } from "tw-components" ;
15- import { InlineCode } from "../../../@/components/ui/inline-code" ;
1615import { DecodedInputArrayFieldset } from "./decoded-bytes-input/decoded-input-array-fieldset" ;
1716import { RefInputFieldset } from "./ref-contract-input/ref-input-fieldset" ;
1817
@@ -25,15 +24,19 @@ export const ContractParamsFieldset: React.FC<ContractParamsFieldsetProps> = ({
2524 const form = useFormContext ( ) ;
2625 const isMobile = useBreakpointValue ( { base : true , md : false } ) ;
2726
28- const [ isCustomInputEnabled , setIsCustomInputEnabled ] = useState (
27+ const [ isCustomInputEnabledArray , setIsCustomInputEnabledArray ] = useState (
2928 Array ( deployParams . length ) . fill ( false ) ,
3029 ) ;
3130
32- const handleToggleCustomInput = ( index : number ) => {
33- const updated = [ ...isCustomInputEnabled ] ;
34- updated [ index ] = ! updated [ index ] ;
35- // Clear values accordingly when toggling between input types
36- if ( updated [ index ] ) {
31+ const handleCustomInputEnabledArrayChange = (
32+ index : number ,
33+ newValue : boolean ,
34+ ) => {
35+ const newIsCustomInputEnabledArray = [ ...isCustomInputEnabledArray ] ;
36+ newIsCustomInputEnabledArray [ index ] = newValue ;
37+ setIsCustomInputEnabledArray ( newIsCustomInputEnabledArray ) ;
38+
39+ if ( newValue ) {
3740 form . setValue (
3841 `constructorParams.${ deployParams [ index ] ?. name || "*" } .defaultValue` ,
3942 "" ,
@@ -59,8 +62,6 @@ export const ContractParamsFieldset: React.FC<ContractParamsFieldsetProps> = ({
5962 } ,
6063 ) ;
6164 }
62-
63- setIsCustomInputEnabled ( updated ) ;
6465 } ;
6566
6667 return (
@@ -201,15 +202,17 @@ export const ContractParamsFieldset: React.FC<ContractParamsFieldsetProps> = ({
201202 < div className = "flex items-center gap-3 text-sm" >
202203 Advanced Input
203204 < Switch
204- checked = { isCustomInputEnabled [ idx ] }
205- onCheckedChange = { ( ) => handleToggleCustomInput ( idx ) }
205+ checked = { isCustomInputEnabledArray [ idx ] }
206+ onCheckedChange = { ( v ) =>
207+ handleCustomInputEnabledArrayChange ( idx , v )
208+ }
206209 />
207210 </ div >
208211 ) }
209212 </ div >
210213
211214 { /* Inputs */ }
212- { ! isCustomInputEnabled [ idx ] ? (
215+ { ! isCustomInputEnabledArray [ idx ] ? (
213216 < FormControl >
214217 < SolidityInput
215218 className = "!bg-background !text-sm placeholder:!text-sm"
@@ -236,7 +239,7 @@ export const ContractParamsFieldset: React.FC<ContractParamsFieldsetProps> = ({
236239
237240 { /* Checkboxes */ }
238241 { paramTemplateValues . length > 0 &&
239- ! isCustomInputEnabled [ idx ] &&
242+ ! isCustomInputEnabledArray [ idx ] &&
240243 paramTemplateValues [ 0 ] ?. helperText && (
241244 < CheckboxWithLabel className = "text-foreground" >
242245 < Checkbox
0 commit comments