Skip to content

Commit

Permalink
feat(apps/web): Revert setting the abiParamEntry error on adding a ne…
Browse files Browse the repository at this point in the history
…w entry. Display props error only when the entries are empty. Memoize entries error.
  • Loading branch information
nevendyulgerov committed Jan 28, 2025
1 parent a2a0dc3 commit 43ade3c
Showing 1 changed file with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
} from "@mantine/core";
import { createFormActions, useForm } from "@mantine/form";
import { clone } from "ramda";
import { isFunction, isNotNilOrEmpty } from "ramda-adjunct";
import { FC, ReactNode, useEffect, useRef } from "react";
import { isFunction, isNilOrEmpty, isNotNilOrEmpty } from "ramda-adjunct";
import { FC, ReactNode, useEffect, useMemo, useRef } from "react";
import { TbTrash } from "react-icons/tb";
import { parseAbiParameters } from "viem";

Expand Down Expand Up @@ -49,7 +49,10 @@ export const HumanReadableABIParameter: FC<HumanReadableABIParameter> = (

const ref = useRef<HTMLInputElement>(null);
const { entries, abiParamEntry } = form.getTransformedValues();
const error = isNotNilOrEmpty(entries) ? checkError(entries) : null;
const error = useMemo(
() => (isNotNilOrEmpty(entries) ? checkError(entries) : null),
[entries],
);
const onAbiParamsChange = props.onAbiParamsChange;

const addABIParam = () => {
Expand Down Expand Up @@ -81,22 +84,12 @@ export const HumanReadableABIParameter: FC<HumanReadableABIParameter> = (
rightSection={
<Button
data-testid="abi-parameter-add-button"
onClick={() => {
try {
parseAbiParameters(abiParamEntry);
addABIParam();
} catch (error: any) {
form.setFieldError(
"abiParamEntry",
error.message,
);
}
}}
onClick={addABIParam}
>
Add
</Button>
}
error={props.error || form.errors.abiParamEntry}
error={isNilOrEmpty(entries) ? props.error : null}
/>

{entries.length > 0 && (
Expand Down

0 comments on commit 43ade3c

Please sign in to comment.