mirror of
https://github.com/luxfhe/example-poker.git
synced 2026-10-30 18:13:22 +00:00
31 lines
852 B
TypeScript
31 lines
852 B
TypeScript
import { useCallback } from "react";
|
|
import { hexToString, isHex, stringToHex } from "viem";
|
|
import { CommonInputProps, InputBase } from "~~/components/scaffold-eth";
|
|
|
|
export const Bytes32Input = ({ value, onChange, name, placeholder, disabled }: CommonInputProps) => {
|
|
const convertStringToBytes32 = useCallback(() => {
|
|
if (!value) {
|
|
return;
|
|
}
|
|
onChange(isHex(value) ? hexToString(value, { size: 32 }) : stringToHex(value, { size: 32 }));
|
|
}, [onChange, value]);
|
|
|
|
return (
|
|
<InputBase
|
|
name={name}
|
|
value={value}
|
|
placeholder={placeholder}
|
|
onChange={onChange}
|
|
disabled={disabled}
|
|
suffix={
|
|
<div
|
|
className="self-center cursor-pointer text-xl font-semibold px-4 text-accent"
|
|
onClick={convertStringToBytes32}
|
|
>
|
|
#
|
|
</div>
|
|
}
|
|
/>
|
|
);
|
|
};
|