-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from cosmos/formgen-field-theight
Add field timeout height
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
components/forms/CreateTxForm/Fields/FieldTimeoutHeight.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<> | ||
<FormField | ||
control={form.control} | ||
name={`${fieldFormName}.revisionNumber`} | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>{`${prettyLabel} Revision Number`}</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Enter revision number" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name={`${fieldFormName}.revisionHeight`} | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>{`${prettyLabel} Revision Height`}</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Enter revision height" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters