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

#297 Validate abi params entry when adding it #312

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nevendyulgerov
Copy link
Contributor

I tweaked slightly the logic for adding abi params from the specs form. Now, when clicking on the Add button next to the abi params input, we'll first parse the params to ensure they're valid. Only if they are, we'll add them to the entries array.

I kept the validation for entries, this line:

const error = isNotNilOrEmpty(entries) ? checkError(entries) : null;

so that users can still see an error for the entries if they previously saved a spec with invalid params.

@nevendyulgerov nevendyulgerov added Type: Bug Something isn't working apps: web labels Jan 22, 2025
Copy link

vercel bot commented Jan 22, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rollups-explorer-arbitrum-mainnet ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 4, 2025 9:00am
rollups-explorer-arbitrum-sepolia ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 4, 2025 9:00am
rollups-explorer-base-mainnet ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 4, 2025 9:00am
rollups-explorer-base-sepolia ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 4, 2025 9:00am
rollups-explorer-mainnet ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 4, 2025 9:00am
rollups-explorer-optimism-mainnet ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 4, 2025 9:00am
rollups-explorer-optimism-sepolia ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 4, 2025 9:00am
rollups-explorer-sepolia ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 4, 2025 9:00am
rollups-explorer-workshop ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 4, 2025 9:00am

Copy link
Collaborator

@brunomenezes brunomenezes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nevendyulgerov, I think the issue would be more around not allowing to save if it is in a state of error rather than not allowing declarations to be added. As an example, is that with that change I am not allowed to either declare a Struct (a.k.a tuple) first or declare an abi parameter signature that uses a tuple ahead of time (i.e. before I declare the tuple) I am limited to inline declarations. My suggestion is to rollback that one and focus on not allowing the save to go through when in an error state, as it does when the name is empty.

New changes, I am not able to define a struct.

2025-01-28 16 28 57

Current production deployed. After using a Struct ahead of time, then declaring it.

2025-01-28 16 25 20

@@ -86,7 +89,7 @@ export const HumanReadableABIParameter: FC<HumanReadableABIParameter> = (
Add
</Button>
}
error={props.error || form.errors.abiParamEntry}
error={isNilOrEmpty(entries) ? props.error : null}
Copy link
Collaborator

@brunomenezes brunomenezes Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nevendyulgerov, this here is doing two different things. The original code was saying that if the caller of that component is setting an error, it has higher precedence than an internal error. However, the change only displays the external set error (if any) if the entries are nil/empty.

Copy link
Contributor Author

@nevendyulgerov nevendyulgerov Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @brunomenezes , looking at the code there's no validation for abiParamEntry so the second part of the expression will always evaluate to null, so in any case only the external error (coming from props.error) can be displayed here.

The reason for this change was that without it, there will be 2 errors for the abi params displayed when users attempt to save an ABI Params spec with invalid params.

Here's a video demonstrating this, using error={props.error || form.errors.abiParamEntry}:
https://github.com/user-attachments/assets/01a949d7-1ed8-49fc-be37-cf7c47d202bf

Another video, using error={isNilOrEmpty(entries) ? props.error : null}:
https://github.com/user-attachments/assets/79549060-f210-440d-bee5-48a51981bbac

So my idea here is to display the external error only when no entries were added, because specAbiParamValidation verifies that as well. specAbiParamValidation produces validation errors only in this case when no entries were added. In the case when there are entries and some are invalid (when validating with parseAbiParameters), the error doesn't need to be displayed underneath the abi params input, as there will be already another error displayed under the added entry card, below the input.

I hope this makes sense :) Please let me know if this approach is ok.

Copy link
Collaborator

@brunomenezes brunomenezes Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about edit mode? I think it is relevant in that context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apps: web Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ABI Parameters spec can be created/updated with invalid parameters
2 participants