From a10cc6383f3cd5bc8e7a1ffd211400bf7616d9f1 Mon Sep 17 00:00:00 2001
From: bearpong <178402093+bearpong@users.noreply.github.com>
Date: Mon, 23 Dec 2024 14:28:38 +0100
Subject: [PATCH] fix(governance): handles boolean inputs and fixes validation
---
.../components/UpdateVaultWhitelistStatus.tsx | 6 +-
.../[genre]/create/components/abi-input.tsx | 53 ++++-
.../create/components/custom-action.tsx | 48 ++--
.../create/components/erc20-transfer.tsx | 14 +-
apps/hub/src/app/governance/types.ts | 2 +-
apps/hub/src/hooks/useCreateProposal.ts | 213 ++++++++++--------
6 files changed, 206 insertions(+), 130 deletions(-)
diff --git a/apps/hub/src/app/governance/[genre]/create/components/UpdateVaultWhitelistStatus.tsx b/apps/hub/src/app/governance/[genre]/create/components/UpdateVaultWhitelistStatus.tsx
index d236d0c5e..51e609b04 100644
--- a/apps/hub/src/app/governance/[genre]/create/components/UpdateVaultWhitelistStatus.tsx
+++ b/apps/hub/src/app/governance/[genre]/create/components/UpdateVaultWhitelistStatus.tsx
@@ -52,11 +52,11 @@ export const UpdateVaultWhitelistStatus = ({
label="Reward Vault Address"
value={gauge?.vault}
error={
- errors.vault === ProposalErrorCodes.REQUIRED
+ errors?.vault === ProposalErrorCodes.REQUIRED
? "A Vault Must Be Chosen"
- : errors.vault === ProposalErrorCodes.INVALID_ADDRESS
+ : errors?.vault === ProposalErrorCodes.INVALID_ADDRESS
? "Invalid Vault address."
- : errors.vault
+ : errors?.vault
}
onChange={async (e) => {
setAction({
diff --git a/apps/hub/src/app/governance/[genre]/create/components/abi-input.tsx b/apps/hub/src/app/governance/[genre]/create/components/abi-input.tsx
index 09c8dfa0d..9c59443ca 100644
--- a/apps/hub/src/app/governance/[genre]/create/components/abi-input.tsx
+++ b/apps/hub/src/app/governance/[genre]/create/components/abi-input.tsx
@@ -2,6 +2,10 @@ import { AbiParameter } from "viem";
import { InputWithLabel } from "@bera/ui/input";
import { useEffect, useState } from "react";
import { Button } from "@bera/ui/button";
+import { Label } from "@bera/ui/label";
+import { Switch } from "@bera/ui/switch";
+import { FormError } from "@bera/ui/form-error";
+import { ProposalErrorCodes } from "~/app/governance/types";
export function AbiInput({
input,
@@ -22,6 +26,9 @@ export function AbiInput({
if ("components" in input && typeof value !== "object") {
onChange({ [input.name!]: {} });
}
+ if (input.type === "string" && typeof value !== "string") {
+ onChange("");
+ }
}, [value, input]);
if ("components" in input) {
@@ -46,6 +53,7 @@ export function AbiInput({
}
/>
))}
+