From 0dbf2d4c1c58069bcb9d1555e21e537e7d10ed1d Mon Sep 17 00:00:00 2001 From: vinhtrand8 Date: Mon, 1 Jul 2024 01:26:55 +0700 Subject: [PATCH 1/2] Revert "hotfix: fix bool value" This reverts commit f14ed1a1a7fbb9693f8529bb34049a6068c26eac. --- ui/components/vault/form/CreateForm.tsx | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/ui/components/vault/form/CreateForm.tsx b/ui/components/vault/form/CreateForm.tsx index 7bf4304..5f2401a 100644 --- a/ui/components/vault/form/CreateForm.tsx +++ b/ui/components/vault/form/CreateForm.tsx @@ -331,15 +331,8 @@ export const CreateVaultForm: IComponent = () => { } ops.push(op); - - if (rule.type === 'bool') { - const boolValue = value === 'true'; - thresholds.push(encodeAbiParameters([{ type: 'bool', value: boolValue }], [boolValue])); - return; - } else { - const encodedValue = encodeAbiParameters([{ type: rule.type, value: value }], [value]); - thresholds.push(encodedValue); - } + const encodedValue = encodeAbiParameters([{ type: rule.type, parsedValue }], [parsedValue]); + thresholds.push(encodedValue); }); if (isError) { From ada2121b28cc4bf70b235164c98b355bd3cc4450 Mon Sep 17 00:00:00 2001 From: vinhtrand8 Date: Mon, 1 Jul 2024 01:27:13 +0700 Subject: [PATCH 2/2] Revert "fix: fix encode boolean value" This reverts commit 10258661564dc2da713ce7c2fc9ac5acef2f67b1. --- ui/components/vault/VaultCard.tsx | 5 +---- ui/components/vault/form/CreateForm.tsx | 8 ++++---- ui/utils/vaults/schema.ts | 17 +++++++---------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/ui/components/vault/VaultCard.tsx b/ui/components/vault/VaultCard.tsx index 7be2475..a3adbe4 100644 --- a/ui/components/vault/VaultCard.tsx +++ b/ui/components/vault/VaultCard.tsx @@ -13,7 +13,6 @@ import { getForrmattedFullDate, isValidAddress } from '@/utils/tools'; import { ClaimType } from '@/utils/vaults/claim'; import { RuleOperators, getShortOperator } from '@/utils/vaults/operators'; import { splitValidationSchema } from '@/utils/vaults/schema'; -import { isNumericType } from '@/utils/vaults/types'; import { wagmiConfig } from '@/utils/wagmi'; import { ArrowRightIcon } from 'lucide-react'; import Link from 'next/link'; @@ -104,9 +103,7 @@ export const VaultCard: IComponent = ({ const value = decodeAbiParameters(abi, thresholds[index])[0] as string; thresholdValue = isValidAddress(value) ? value.slice(0, 4) + '...' + value.slice(-4) - : isNumericType(type as TRuleType) - ? Number(value).toLocaleString() - : value; + : value; } return ( { // eslint-disable-next-line @typescript-eslint/no-explicit-any const value = (values as any)[ruleName]; - const [valid, parsedValue, msg] = validateField(rule.type, value); - if (!valid || !parsedValue) { + const [valid, msg] = validateField(rule.type, value); + if (!valid) { form.setError(ruleName, { message: msg }); isError = true; return; } - ops.push(op); - const encodedValue = encodeAbiParameters([{ type: rule.type, parsedValue }], [parsedValue]); + + const encodedValue = encodeAbiParameters([{ type: rule.type, value }], [value]); thresholds.push(encodedValue); }); diff --git a/ui/utils/vaults/schema.ts b/ui/utils/vaults/schema.ts index 7204b4e..928a712 100644 --- a/ui/utils/vaults/schema.ts +++ b/ui/utils/vaults/schema.ts @@ -114,29 +114,26 @@ export const RuleSchema: Record = { .optional(), } as const; -export const validateField = ( - type: TRuleType, - value: string -): [boolean, number | string | boolean | bigint | undefined, string] => { +export const validateField = (type: TRuleType, value: string): [boolean, string] => { if (isNumericType(type)) { const num = parseInt(value, 10); if (isNaN(num)) { - return [false, undefined, 'Must be a valid number']; + return [false, 'Must be a valid number']; } const min = getMinValue(type); const max = getMaxValue(type); const result = num >= min && num <= max; - return [result, num, result ? '' : `Must be a number between ${min} and ${max}`]; + return [result, result ? '' : `Must be a number between ${min} and ${max}`]; } else if (isBytesType(type)) { - return [isNBytesValue(type, value), value, 'Must be a valid bytes string']; + return [isNBytesValue(type, value), 'Must be a valid bytes string']; } else if (type === 'address') { - return [isValidAddress(value), value, 'Must be a valid address']; + return [isValidAddress(value), 'Must be a valid address']; } else if (type === 'bool') { - return [value === 'true' || value === 'false', value === 'true', 'Must be a valid boolean']; + return [value === 'true' || value === 'false', 'Must be a valid boolean']; } else { // string is always valid } - return [true, undefined, '']; + return [true, '']; }; export const splitValidationSchema = (schema: string): [string, string][] => {