Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: form faults in bad input on game creation #42

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions frontend/src/components/CreateGameForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StandardMerkleTree } from "@openzeppelin/merkle-tree";
import { zodResolver } from "@hookform/resolvers/zod";
import * as z from "zod";
import { Button } from "./ui/button";
import { BaseError, getAddress } from "viem";
import { BaseError, getAddress, parseEther } from "viem";
import { useAccount, useWaitForTransaction } from "wagmi";
import {
usePrepareTankGameFactoryCreateGame,
Expand All @@ -29,7 +29,7 @@ const formSchema = z.object({
initHearts: z.number(),
initShootRange: z.number(),
epochSeconds: z.number(),
buyInMinimum: z.number(),
buyInMinimum: z.string(),
revealWaitBlocks: z.number(),
autoStart: z.boolean(),
root: z.string(),
Expand All @@ -49,7 +49,7 @@ export default function CreateGameForm({
initHearts: 3,
initShootRange: 3,
epochSeconds: 60,
buyInMinimum: 0,
buyInMinimum: "0",
revealWaitBlocks: 60,
autoStart: "true",
root: "0x0000000000000000000000000000000000000000000000000000000000000000",
Expand All @@ -71,7 +71,7 @@ export default function CreateGameForm({
initHearts: BigInt(formState.initHearts),
initShootRange: BigInt(formState.initShootRange),
epochSeconds: BigInt(formState.epochSeconds),
buyInMinimum: BigInt(formState.buyInMinimum),
buyInMinimum: parseEther(formState.buyInMinimum),
revealWaitBlocks: BigInt(formState.revealWaitBlocks),
autoStart: Boolean(formState.autoStart),
root: formState.root as `0x${string}`,
Expand Down Expand Up @@ -127,8 +127,11 @@ export default function CreateGameForm({
<Input
{...field}
onChange={(e) => {
if (!isNaN(Number(e.target.value))) {
try {
BigInt(e.target.value);
handleInputChange(e);
} catch {
console.error("Value is not convertible to BigInt");
}
}}
value={formState.playerCount}
Expand All @@ -148,15 +151,18 @@ export default function CreateGameForm({
<Input
{...field}
onChange={(e) => {
if (!isNaN(Number(e.target.value))) {
try {
BigInt(e.target.value);
handleInputChange(e);
} catch {
console.error("Value is not convertible to BigInt");
}
}}
value={formState.boardSize}
/>
</FormControl>
<FormDescription>
Enter the size of the board (must be div by 3)
Enter the size of the board (must be div by 3){" "}
</FormDescription>
</div>
)}
Expand All @@ -171,8 +177,11 @@ export default function CreateGameForm({
<Input
{...field}
onChange={(e) => {
if (!isNaN(Number(e.target.value))) {
try {
BigInt(e.target.value);
handleInputChange(e);
} catch {
console.error("Value is not convertible to BigInt");
}
}}
value={formState.initAPs}
Expand All @@ -192,8 +201,11 @@ export default function CreateGameForm({
<Input
{...field}
onChange={(e) => {
if (!isNaN(Number(e.target.value))) {
try {
BigInt(e.target.value);
handleInputChange(e);
} catch {
console.error("Value is not convertible to BigInt");
}
}}
value={formState.initHearts}
Expand Down Expand Up @@ -236,8 +248,11 @@ export default function CreateGameForm({
<Input
{...field}
onChange={(e) => {
if (!isNaN(Number(e.target.value))) {
try {
BigInt(e.target.value);
handleInputChange(e);
} catch {
console.error("Value is not convertible to BigInt");
}
}}
value={formState.epochSeconds}
Expand Down Expand Up @@ -278,8 +293,11 @@ export default function CreateGameForm({
<Input
{...field}
onChange={(e) => {
if (!isNaN(Number(e.target.value))) {
try {
BigInt(e.target.value);
handleInputChange(e);
} catch {
console.error("Value is not convertible to BigInt");
}
}}
value={formState.revealWaitBlocks}
Expand Down
Loading