diff --git a/README.txt b/README.txt index d5acc5e6..874d2436 100644 --- a/README.txt +++ b/README.txt @@ -32,7 +32,7 @@ notes works -- [ ] boolean validation is bad +- [x] boolean validation is bad http://localhost:3000/abi-playground-sapphire?contractAddress=0xEF15601B599F5C0696E38AB27f100c4075B36150&network=42262&methods=emitEvent1%2CemitEvent2%2CemitUnnamed _booleanValue: 2 or truee @@ -43,11 +43,15 @@ notes _str: test `The contract function "emitEvent1" reverted.` `invalid argument 0: json: cannot unmarshal invalid hex string into Go struct field TransactionArgs.data of type hexutil.Bytes` -[ ] it doesn't show an error anymore after workaround to avoid simulating contract write +[ignore] it doesn't show an error anymore after workaround to avoid simulating contract write updated viem validates it https://github.com/wevm/viem/commit/4d52c74d318daf4eebb0dae43f581aa20ef62118 could make checkbox https://github.com/scaffold-eth/scaffold-eth-2/blob/18dd946e961ac7bdf2a47cea4c5b21872750c223/packages/nextjs/app/debug/_components/contract/ContractInput.tsx#L37 + upstream: + https://abi.ninja/0x0635513f179D50A207757E05759CbD106d7dFcE8/11155111?methods=setController + https://abi.ninja/0xfed6a969aaa60e4961fcd3ebf1a2e8913ac65b72/11155111?methods=makeCommitment%2Cregister + - [ ] crashes if you type "0." into deposit, but not into withdrawal https://lukaw3d.github.io/abi-playground-sapphire?contractAddress=0xB759a0fbc1dA517aF257D5Cf039aB4D86dFB3b94&network=23295&methods=balanceOf%2Cwithdraw%2Cdeposit diff --git a/packages/nextjs/components/scaffold-eth/Contract/ContractInput.tsx b/packages/nextjs/components/scaffold-eth/Contract/ContractInput.tsx index 95f77768..aaa0af5b 100644 --- a/packages/nextjs/components/scaffold-eth/Contract/ContractInput.tsx +++ b/packages/nextjs/components/scaffold-eth/Contract/ContractInput.tsx @@ -1,4 +1,5 @@ import { Dispatch, SetStateAction } from "react"; +import { BooleanInput } from "../Input/BooleanInput"; import { Tuple } from "./Tuple"; import { TupleArray } from "./TupleArray"; import { AbiParameter } from "abitype"; @@ -36,6 +37,8 @@ export const ContractInput = ({ setForm, form, stateObjectKey, paramType }: Cont switch (paramType.type) { case "address": return ; + case "bool": + return ; case "bytes32": return ; case "bytes": diff --git a/packages/nextjs/components/scaffold-eth/Input/BooleanInput.tsx b/packages/nextjs/components/scaffold-eth/Input/BooleanInput.tsx new file mode 100644 index 00000000..2412b52b --- /dev/null +++ b/packages/nextjs/components/scaffold-eth/Input/BooleanInput.tsx @@ -0,0 +1,41 @@ +import { ChangeEvent, useCallback } from "react"; +import { CommonInputProps } from "~~/components/scaffold-eth"; + +type BooleanInputProps = CommonInputProps & { + error?: boolean; +}; + +export const BooleanInput = ({ name, value, onChange, placeholder, error, disabled }: BooleanInputProps) => { + let modifier = ""; + if (error) { + modifier = "border border-error"; + } else if (disabled) { + modifier = "border border-disabled bg-base-300"; + } + + const handleChange = useCallback( + (e: ChangeEvent) => { + onChange(e.target.checked); + }, + [onChange], + ); + + return ( +
+
+ +
+
+ ); +};