Files
js/contract-ui/components/solidity-inputs/bytes-input.tsx
T
Nacho Iacovino 157f3cdeb9 Improve publish reliability (#2202)
* Take name out of the object

* All of this makes sense to me
2024-02-12 19:45:56 +00:00

35 lines
871 B
TypeScript

import { SolidityInputWithTypeProps } from ".";
import { validateBytes } from "./helpers";
import { Input } from "@chakra-ui/react";
export const SolidityBytesInput: React.FC<SolidityInputWithTypeProps> = ({
formContext: form,
solidityType,
...inputProps
}) => {
const { name, ...restOfInputProps } = inputProps;
const inputName = name as string;
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { value } = e.target;
form.setValue(inputName, value, { shouldDirty: true });
const inputError = validateBytes(value, solidityType);
if (inputError) {
form.setError(inputName, inputError);
} else {
form.clearErrors(inputName);
}
};
return (
<Input
placeholder={solidityType}
{...restOfInputProps}
value={form.watch(inputName)}
onChange={handleChange}
/>
);
};