Skip to content

Commit

Permalink
feat: form read
Browse files Browse the repository at this point in the history
  • Loading branch information
songwongtp committed Jan 20, 2025
1 parent 6229431 commit ce136c2
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/lib/components/evm-abi/EvmAbiForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ interface EvmAbiFormProps {
isPayable: boolean;
initialData?: JsonDataType[];
propsOnChange?: (data: JsonDataType[]) => void;
isDisabled?: boolean;
}

export const EvmAbiForm = ({
types,
isPayable,
initialData,
propsOnChange,
isDisabled,
}: EvmAbiFormProps) => {
const defaultValues = useMemo(
() => initialData ?? getComponentsDefaultValues(types),
Expand Down Expand Up @@ -45,6 +47,11 @@ export const EvmAbiForm = ({
}, [JSON.stringify(inputs), propsOnChange]);

return (
<FormFields control={control} components={types} isPayable={isPayable} />
<FormFields
control={control}
components={types}
isPayable={isPayable}
isDisabled={isDisabled}
/>
);
};
3 changes: 2 additions & 1 deletion src/lib/components/evm-abi/fields/BaseField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const BaseField = <T extends FieldValues>({
control,
name,
type,
isDisabled,
isRequired = false,
}: BaseFieldProps<T>) => {
const {
Expand All @@ -24,7 +25,7 @@ export const BaseField = <T extends FieldValues>({
const isError = (isTouched || isDirty) && !!error;

return (
<FormControl isInvalid={isError} {...fieldProps}>
<FormControl isInvalid={isError} isDisabled={isDisabled} {...fieldProps}>
<Input value={value} onBlur={onBlur} onChange={onChange} />
{isError && <FormErrorMessage>{error.message}</FormErrorMessage>}
</FormControl>
Expand Down
2 changes: 2 additions & 0 deletions src/lib/components/evm-abi/fields/BoolField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const BOOL_FIELD_OPTIONS: SelectInputOption<string>[] = [
export const BoolField = <T extends FieldValues>({
control,
name,
isDisabled,
}: FieldProps<T>) => {
const {
field: { value, onChange },
Expand All @@ -34,6 +35,7 @@ export const BoolField = <T extends FieldValues>({
onChange(newValue.value);
}}
size="md"
isDisabled={isDisabled}
/>
);
};
2 changes: 2 additions & 0 deletions src/lib/components/evm-abi/fields/TupleField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const TupleField = <T extends FieldValues>({
name,
control,
components,
isDisabled,
withoutBorder,
}: TupleFieldProps<T>) => {
const values = useWatch<T>({
Expand Down Expand Up @@ -53,6 +54,7 @@ export const TupleField = <T extends FieldValues>({
type={subfieldType}
label={subfieldLabel}
dimensions={getTypeDimensions(subfieldType)}
isDisabled={isDisabled}
{...rest}
/>
</TypeLabel>
Expand Down
3 changes: 3 additions & 0 deletions src/lib/components/evm-abi/fields/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ interface FormFieldsProps<T extends FieldValues> {
control: Control<T>;
components: ReadonlyArray<JsonFragmentType>;
isPayable: boolean;
isDisabled?: boolean;
}

export const FormFields = <T extends FieldValues>({
control,
components,
isPayable,
isDisabled,
}: FormFieldsProps<T>) => {
const { data: evmParamsData } = useEvmParams();
const { data: assetInfos } = useAssetInfos({
Expand All @@ -34,6 +36,7 @@ export const FormFields = <T extends FieldValues>({
control={control}
name={"inputs" as Path<T>}
components={components}
isDisabled={isDisabled}
withoutBorder
/>
{isPayable && (
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/evm-abi/fields/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export interface FieldProps<T extends FieldValues>
control: Control<T>;
name: FieldPath<T>;
label?: string;
isDisabled?: boolean;
}
127 changes: 127 additions & 0 deletions src/lib/pages/evm-contract-details/dummy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// TODO: REMOVE

import { JsonFragment } from "ethers";

export const EVM_ABI: Record<string, JsonFragment> = {
payable: {
inputs: [],
name: "fnPayable",
outputs: [],
stateMutability: "payable",
type: "function",
},
int8: {
inputs: [
{
internalType: "int8",
name: "i8",
type: "int8",
},
],
name: "fnInt8",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
bytes4: {
inputs: [
{
internalType: "bytes4",
name: "b4",
type: "bytes4",
},
],
name: "fnBytes4",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
bytes: {
inputs: [
{
internalType: "bytes",
name: "b",
type: "bytes",
},
],
name: "fnBytes",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
bool: {
inputs: [
{
internalType: "bool",
name: "b",
type: "bool",
},
],
name: "fnBool",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
array: {
inputs: [
{
internalType: "uint8[2][][2]",
name: "u8f20",
type: "uint8[2][][2]",
},
],
name: "fnUint8fixed20",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
struct: {
inputs: [
{
components: [
{
components: [
{
internalType: "uint256",
name: "key",
type: "uint256",
},
{
internalType: "bool",
name: "value",
type: "bool",
},
],
internalType: "struct Types.Struct1",
name: "s1",
type: "tuple",
},
{
components: [
{
internalType: "bool",
name: "value",
type: "bool",
},
{
internalType: "uint256",
name: "key",
type: "uint256",
},
],
internalType: "struct Types.Struct2",
name: "s2",
type: "tuple",
},
],
internalType: "struct Types.Struct3",
name: "s3",
type: "tuple",
},
],
name: "fnStruct3",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
};

0 comments on commit ce136c2

Please sign in to comment.