Skip to content

revert: fix encode #24

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

Merged
merged 2 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 1 addition & 4 deletions ui/components/vault/VaultCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -104,9 +103,7 @@ export const VaultCard: IComponent<TVault> = ({
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 (
<tr
Expand Down
15 changes: 4 additions & 11 deletions ui/components/vault/form/CreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,23 +323,16 @@ export const CreateVaultForm: IComponent = () => {

// 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);

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, value }], [value]);
thresholds.push(encodedValue);
});

if (isError) {
Expand Down
17 changes: 7 additions & 10 deletions ui/utils/vaults/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,29 +114,26 @@ export const RuleSchema: Record<TRuleType, any> = {
.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][] => {
Expand Down
Loading