diff --git a/components/forms/CreateTxForm/Fields/FieldTimeoutHeight.tsx b/components/forms/CreateTxForm/Fields/FieldTimeoutHeight.tsx new file mode 100644 index 00000000..ff51d35e --- /dev/null +++ b/components/forms/CreateTxForm/Fields/FieldTimeoutHeight.tsx @@ -0,0 +1,79 @@ +import { FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; +import { Input } from "@/components/ui/input"; +import { prettyFieldName } from "@/lib/form"; +import * as z from "zod"; +import type { FieldProps } from "./types"; + +const isFieldTimeoutHeight = (fieldName: string) => fieldName === "timeoutHeight"; + +export const getFieldTimeoutHeight = (fieldName: string) => + isFieldTimeoutHeight(fieldName) ? FieldTimeoutHeight : null; + +export const getFieldTimeoutHeightSchema = (fieldName: string) => + isFieldTimeoutHeight(fieldName) + ? z.object({ + revisionNumber: z + .any() + .transform((value) => { + try { + return BigInt(value); + } catch (error) { + return value; + } + }) + .pipe( + z + .bigint({ invalid_type_error: "Must be an integer", required_error: "Required" }) + .positive("Must be positive"), + ), + revisionHeight: z + .any() + .transform((value) => { + try { + return BigInt(value); + } catch (error) { + return value; + } + }) + .pipe( + z + .bigint({ invalid_type_error: "Must be an integer", required_error: "Required" }) + .positive("Must be positive"), + ), + }) + : null; + +export default function FieldTimeoutHeight({ form, fieldFormName }: FieldProps) { + const prettyLabel = prettyFieldName(fieldFormName); + + return ( + <> + ( + + {`${prettyLabel} Revision Number`} + + + + + + )} + /> + ( + + {`${prettyLabel} Revision Height`} + + + + + + )} + /> + + ); +} diff --git a/components/forms/CreateTxForm/Fields/index.ts b/components/forms/CreateTxForm/Fields/index.ts index 4417b14e..ab659975 100644 --- a/components/forms/CreateTxForm/Fields/index.ts +++ b/components/forms/CreateTxForm/Fields/index.ts @@ -3,3 +3,4 @@ export * from "./FieldAmount"; export * from "./FieldBoolean"; export * from "./FieldNumber"; export * from "./FieldString"; +export * from "./FieldTimeoutHeight"; diff --git a/lib/form.ts b/lib/form.ts index a4ad2fb5..9a1a8db2 100644 --- a/lib/form.ts +++ b/lib/form.ts @@ -9,6 +9,8 @@ import { getFieldNumberSchema, getFieldString, getFieldStringSchema, + getFieldTimeoutHeight, + getFieldTimeoutHeightSchema, } from "@/components/forms/CreateTxForm/Fields"; import { FieldSchemaInput } from "@/components/forms/CreateTxForm/Fields/types"; import { z } from "zod"; @@ -27,6 +29,7 @@ export const getField = (fieldName: string) => getFieldString(fieldName) || getFieldNumber(fieldName) || getFieldBoolean(fieldName) || + getFieldTimeoutHeight(fieldName) || null; const getFieldSchema = (fieldName: string, schemaInput: FieldSchemaInput) => @@ -35,6 +38,7 @@ const getFieldSchema = (fieldName: string, schemaInput: FieldSchemaInput) => getFieldStringSchema(fieldName) || getFieldNumberSchema(fieldName) || getFieldBooleanSchema(fieldName) || + getFieldTimeoutHeightSchema(fieldName) || null; export const getMsgSchema = (fieldNames: readonly string[], schemaInput: FieldSchemaInput) => {