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

feat: validate evm verify form options #1225

Merged
merged 3 commits into from
Feb 11, 2025

Conversation

songwongtp
Copy link
Collaborator

@songwongtp songwongtp commented Feb 10, 2025

Summary by CodeRabbit

  • New Features

    • Added validation for EVM verification form options, ensuring required inputs are captured accurately.
    • Introduced a new ContractLibrary component for improved user input handling regarding contract libraries.
  • Refactor

    • Streamlined state management and rendering logic for contract libraries, enhancing form interaction and error handling.
    • Updated validation logic for optimizer configuration to provide clearer feedback on required fields.

Copy link

vercel bot commented Feb 10, 2025

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

Name Status Preview Comments Updated (UTC)
celatone-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 11, 2025 4:08am
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
celatone-frontend-main ⬜️ Ignored (Inspect) Visit Preview Feb 11, 2025 4:08am
initia-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 11, 2025 4:08am
neutron-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 11, 2025 4:08am
osmosis-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 11, 2025 4:08am
sei-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 11, 2025 4:08am
terra-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 11, 2025 4:08am

Copy link

coderabbitai bot commented Feb 10, 2025

Walkthrough

This PR introduces multiple enhancements to the contract verification workflow. A new changelog entry for EVM verification form option validation is added. The contract library components are refactored by simplifying state management and introducing a new dedicated component, while related components in contract details are renamed. Additionally, the optimizer configuration and overall EVM verification form have their validation logic improved with additional state and Zod schema refinements. Several schema definitions are enhanced to enforce stricter validation rules.

Changes

File(s) Change Summary
CHANGELOG.md Added a new feature entry for validating EVM verification form options.
src/lib/pages/evm-contract-verify/components/ContractLibraries.tsx and src/lib/pages/evm-contract-verify/components/ContractLibrary.tsx Refactored contract libraries management: removed unused hooks, simplified state handling, and introduced a new component for individual library entries.
src/lib/pages/evm-contract-verify/components/OptimizerConfiguration.tsx and src/lib/pages/evm-contract-verify/index.tsx Updated form validation logic: added state checks (e.g., for optimizer runs) and enhanced submission handling via Zod schema integration.
src/lib/services/types/verification/evm.ts Enhanced Zod schema validations with additional .refine() methods and introduced a new zFile schema for file validations.
src/lib/pages/evm-contract-details/components/evm-contract-details-contract-info/ContractCode.tsx and src/lib/pages/evm-contract-details/components/evm-contract-details-contract-info/ContractLibraryList.tsx Renamed and updated contract library display: replaced ContractLibrary with ContractLibraryList and updated the corresponding interface.

Possibly related PRs

  • Feat(components): EVM constructor arguments #1214: The changes in the main PR are related to the modifications in the ContractCode component, specifically regarding the handling of constructor arguments and the introduction of the findAndDecodeEvmConstructorArgs function.
  • feat: add evm library contract on details page #1218: The changes in the main PR are related to the introduction of the ContractLibrary component, which is also present in the retrieved PR, indicating a direct connection in terms of component functionality and usage.

Suggested reviewers

  • evilpeach

Poem

I'm a rabbit with code so bright,
Hopping through forms in the day and night,
Fixing libraries and validations with grace,
Each commit brings a smile to my face,
🥕 Code crunching in a whimsical pace!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0cde4e and 0b585e9.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/lib/pages/evm-contract-verify/index.tsx (2)

131-185: Consider consolidating partial schema validation logic.

In isFormDisabled, multiple Zod schemas are selectively parsed depending on the chosen verification option, which can lead to verbose and repetitive checks. It might be more maintainable to build a consolidated schema (or a more composable approach) that accounts for each option’s conditional fields. This way, validation remains consistent and easier to update as the number of verification options grows.


194-195: Provide user feedback or logging for missing parameters.

When option, language, or licenseType is missing, the function simply returns without any warning or error message. Consider displaying a user-facing toast or inline error to clarify why submission is aborted, as this helps users correct mistakes more efficiently.

src/lib/pages/evm-contract-verify/components/ContractLibrary.tsx (1)

16-56: Use form error states instead of manual string checks.

Currently, the error prop is derived from field.value.name !== "" ? "" : "Required". This can conflict with the form library’s validation flow and lead to discrepancies. For better maintainability and consistency, rely on built-in errors[fieldName]?.message (from your Zod schema or rules) rather than manually checking for an empty string.

src/lib/pages/evm-contract-verify/components/OptimizerConfiguration.tsx (1)

25-64: Align inline checks with global form validation.

You’re conditionally setting the status to error when enabled is true but runs is an empty string. While this is effective, consider consolidating it with your Zod schema validation so the UI and form states stay in sync. Doing so would also simplify the code by using a single source of truth for validations.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 119683f and dc1dc50.

📒 Files selected for processing (7)
  • CHANGELOG.md (1 hunks)
  • src/lib/pages/evm-contract-verify/components/ContractLibraries.tsx (4 hunks)
  • src/lib/pages/evm-contract-verify/components/ContractLibrary.tsx (1 hunks)
  • src/lib/pages/evm-contract-verify/components/OptimizerConfiguration.tsx (2 hunks)
  • src/lib/pages/evm-contract-verify/components/solidity/EvmContractVerifySolidityContractCode.tsx (1 hunks)
  • src/lib/pages/evm-contract-verify/index.tsx (2 hunks)
  • src/lib/services/types/verification/evm.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (11)
src/lib/pages/evm-contract-verify/components/solidity/EvmContractVerifySolidityContractCode.tsx (1)

58-58: LGTM! The name prop update improves form state management.

The change to use a more specific path verifyForm.solidityContractCode.contractLibraries better reflects the form's data structure and aligns with the contract libraries state management refactoring.

src/lib/pages/evm-contract-verify/components/ContractLibraries.tsx (3)

7-7: LGTM! Improved type safety and component organization.

The addition of FieldArrayPath import and new ContractLibrary component improves type safety and modularizes the library field logic.

Also applies to: 13-13


26-26: LGTM! Simplified state management.

The changes improve state management by:

  1. Using a more specific path for enabled state
  2. Using proper field array typing
  3. Directly using field.value for checkbox state
  4. Simplifying display logic

Also applies to: 31-31, 47-48, 58-58


60-65: LGTM! Improved component composition.

The refactoring to use the dedicated ContractLibrary component simplifies the code and improves maintainability by encapsulating library field logic.

src/lib/services/types/verification/evm.ts (6)

40-45: LGTM! Added validation for optimizer configuration.

The refinement ensures that if optimizer is enabled, the runs field must not be empty, preventing invalid configurations.


48-53: LGTM! Added validation for constructor arguments.

The refinement ensures that if constructor arguments are enabled, the value field must not be empty, preventing invalid configurations.


55-55: LGTM! Added validation for EVM target version.

The refinement ensures that the target version is not empty, preventing invalid configurations.


62-71: LGTM! Added comprehensive validation for contract libraries.

The refinement ensures that if libraries are enabled:

  1. Library names are not empty
  2. Addresses are valid hex addresses
    This prevents invalid library configurations.

73-82: LGTM! Added file validation schema.

The new zFile schema with custom validation ensures that files are provided when required, improving form validation.


85-97: LGTM! Improved schema organization and reusability.

The changes to export schemas improve code organization and allow reuse across the codebase. The schemas now properly validate:

  1. File uploads
  2. Contract code
  3. JSON input
  4. Contract names

Also applies to: 99-105, 107-110, 113-117, 119-124, 126-129

CHANGELOG.md (1)

42-42: LGTM! Clear and well-formatted changelog entry.

The changelog entry accurately describes the EVM Verification form options validation feature and follows the proper format.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/lib/pages/evm-contract-verify/components/ContractLibrary.tsx (2)

34-34: Improve type safety for nested field paths.

String concatenation for field paths could lead to type safety issues. Consider using a type-safe approach.

Use a utility type to ensure type safety:

type NestedFieldPath<T, K extends string> = `${FieldPath<T>}.${K}`;

// Usage
name={name as NestedFieldPath<T, 'name'>}
name={name as NestedFieldPath<T, 'address'>}

Also applies to: 46-46


37-37: Consider making the label background color configurable.

The hardcoded labelBgColor="gray.900" might not work well with different themes.

Make it configurable through props:

-        labelBgColor="gray.900"
+        labelBgColor={props.labelBgColor ?? "gray.900"}

Update the interface:

interface ContractLibraryProps<T extends FieldValues> {
  control: Control<T>;
  name: FieldPath<T>;
+ labelBgColor?: string;
}

Also applies to: 49-49

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dc1dc50 and f0cde4e.

📒 Files selected for processing (3)
  • src/lib/pages/evm-contract-details/components/evm-contract-details-contract-info/ContractCode.tsx (2 hunks)
  • src/lib/pages/evm-contract-details/components/evm-contract-details-contract-info/ContractLibraryList.tsx (1 hunks)
  • src/lib/pages/evm-contract-verify/components/ContractLibrary.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
src/lib/pages/evm-contract-details/components/evm-contract-details-contract-info/ContractLibraryList.tsx (1)

7-9: LGTM! The renaming improves clarity.

The renaming of the interface and component to ContractLibraryListProps and ContractLibraryList respectively better reflects the component's purpose of displaying a list of contract libraries.

Also applies to: 13-15

src/lib/pages/evm-contract-details/components/evm-contract-details-contract-info/ContractCode.tsx (1)

17-17: LGTM! The changes are consistent.

The import statement and component usage have been correctly updated to use the renamed ContractLibraryList component.

Also applies to: 77-77

src/lib/pages/evm-contract-verify/components/ContractLibrary.tsx (1)

1-14: LGTM! Clean imports and well-typed interface.

The imports are well-organized and the generic interface is properly typed for form handling.

@songwongtp songwongtp merged commit 66f62e8 into develop Feb 11, 2025
13 checks passed
@songwongtp songwongtp deleted the feat/validate-evm-verify-forms branch February 11, 2025 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants