Skip to content

feat(web): validation of the token address for ERC20/721/1155 types #2052

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

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

jaybuidl
Copy link
Member

@jaybuidl jaybuidl commented Jul 22, 2025

PR-Codex overview

This PR focuses on enhancing token gate validation in the NewDisputeContext and related components. It introduces new hooks for validating ERC20, ERC721, and ERC1155 token addresses, and updates the Court component to handle validation states.

Detailed summary

  • Added isTokenGateValid property to NewDisputeContext.
  • Updated NextButton to check token gate validity.
  • Introduced hooks: useERC20ERC721Validation and useERC1155Validation.
  • Enhanced Court component to validate token addresses and manage validation states.
  • Added visual feedback for token validation results in the UI.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Added real-time validation for Ethereum token contract addresses (ERC-20, ERC-721, ERC-1155) when configuring gated dispute kits.
    • Visual feedback is now provided for token address validation, including loading, valid, and invalid states.
    • The "Next" button is now disabled if the token address for a gated dispute kit is invalid.
    • Introduced a tri-state validation status for token gating: not validated, valid, and invalid.
  • Bug Fixes

    • Validation state is reset appropriately when the token address or type changes.

@jaybuidl jaybuidl requested a review from a team as a code owner July 22, 2025 23:56
Copy link
Contributor

coderabbitai bot commented Jul 22, 2025

Walkthrough

The changes introduce robust validation for Ethereum token contract addresses in the context of "gated" dispute kits within a web application. This includes new hooks for ERC-20, ERC-721, and ERC-1155 address validation, UI feedback for validation status, state synchronization for validation results, and integration of validation into navigation logic.

Changes

Cohort / File(s) Change Summary
Token Validation Hooks
web/src/hooks/useTokenAddressValidation.ts
Introduces new hooks for validating ERC-20/ERC-721 and ERC-1155 token contract addresses, including error handling, debouncing, and caching. Exports useERC20ERC721Validation and useERC1155Validation.
Gated Dispute Data Interface
web/src/context/NewDisputeContext.tsx
Adds optional `isTokenGateValid?: boolean
Court Page Validation Integration
web/src/pages/Resolver/Parameters/Court.tsx
Integrates token address validation into the court parameters page for gated dispute kits. Adds UI feedback for validation status, synchronizes validation state, and updates handlers for input changes.
Navigation Button Validation
web/src/pages/Resolver/NavigationButtons/NextButton.tsx
Updates the Next button to include gated token validation in its enable/disable logic when on the court selection route.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CourtPage
    participant ValidationHook
    participant EthereumClient

    User->>CourtPage: Enter token address / toggle ERC-1155
    CourtPage->>ValidationHook: Call validation hook with address & type
    ValidationHook->>EthereumClient: Query balanceOf/address check
    EthereumClient-->>ValidationHook: Return result (valid/invalid/error)
    ValidationHook-->>CourtPage: Provide validation status
    CourtPage-->>User: Display UI feedback (spinner, check, cross, message)
    CourtPage->>Context: Update isTokenGateValid state
    CourtPage-->>NextButton: Pass validation state
    NextButton-->>User: Enable/disable navigation
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

Type: Enhancement :sparkles:

Suggested reviewers

  • alcercu
  • jaybuidl

Poem

A rabbit hopped through fields of code,
Where token gates and checks abode.
With hooks and icons, swift and neat,
Validation now feels quite complete!
No more guessing—green or red,
The UI tells you what's ahead.
🐇✨ Happy hopping through secure gates!

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 7c74b70 and d78e212.

📒 Files selected for processing (1)
  • web/src/pages/Resolver/Parameters/Court.tsx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/pages/Resolver/Parameters/Court.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: contracts-testing
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-testnet
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/gated-dk-address-validation

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
  • 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 explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @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 or @coderabbitai title 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.

@jaybuidl jaybuidl requested review from tractorss and kemuru and removed request for a team July 22, 2025 23:56
@jaybuidl jaybuidl force-pushed the feat/gated-dk-address-validation branch from 8a3862f to f1fe7c9 Compare July 23, 2025 13:58
Base automatically changed from web/dk-support-improvement to dev July 28, 2025 15:54
Copy link

netlify bot commented Aug 5, 2025

Deploy Preview for kleros-v2-university failed. Why did it fail? →

Name Link
🔨 Latest commit d78e212
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-university/deploys/689306d30b8663000883943d

Copy link

netlify bot commented Aug 5, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit d78e212
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet/deploys/689306d39da5910008432bbf
😎 Deploy Preview https://deploy-preview-2052--kleros-v2-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

netlify bot commented Aug 5, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit d78e212
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-neo/deploys/689306d364243d0008b1d8ee
😎 Deploy Preview https://deploy-preview-2052--kleros-v2-neo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

netlify bot commented Aug 5, 2025

Deploy Preview for kleros-v2-testnet-devtools ready!

Name Link
🔨 Latest commit d78e212
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet-devtools/deploys/689306d3c0861c0008c6f078
😎 Deploy Preview https://deploy-preview-2052--kleros-v2-testnet-devtools.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

@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: 2

🧹 Nitpick comments (3)
web/src/pages/Resolver/NavigationButtons/NextButton.tsx (1)

24-25: Consider using optional chaining for cleaner code.

-    const gatedData = disputeData.disputeKitData as IGatedDisputeData;
-    if (!gatedData?.tokenGate?.trim()) return true; // No token address provided, so valid
+    const gatedData = disputeData.disputeKitData as IGatedDisputeData;
+    if (!gatedData.tokenGate?.trim()) return true; // No token address provided, so valid
web/src/hooks/useTokenAddressValidation.ts (2)

169-171: Consider preserving error details for debugging.

The catch block discards the original error which might contain useful information for debugging contract-specific issues.

-      } catch {
-        throw new Error(`Address does not implement ${tokenType} interface`);
+      } catch (error) {
+        console.debug(`Token validation failed for ${debouncedAddress}:`, error);
+        throw new Error(`Address does not implement ${tokenType} interface`);
       }

202-210: Error message handling could be more robust.

The error message parsing relies on string matching which might be fragile if error messages change.

Consider using error codes or more structured error handling if the contract interaction library supports it.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e3ed3c9 and 92852da.

📒 Files selected for processing (4)
  • web/src/context/NewDisputeContext.tsx (1 hunks)
  • web/src/hooks/useTokenAddressValidation.ts (1 hunks)
  • web/src/pages/Resolver/NavigationButtons/NextButton.tsx (3 hunks)
  • web/src/pages/Resolver/Parameters/Court.tsx (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Analyze (javascript)
  • GitHub Check: contracts-testing
🔇 Additional comments (7)
web/src/context/NewDisputeContext.tsx (1)

64-64: LGTM! Well-designed validation state property.

The tri-state boolean (null = not validated, false = invalid, true = valid) is an appropriate design choice for tracking asynchronous validation status.

web/src/pages/Resolver/NavigationButtons/NextButton.tsx (1)

20-29: LGTM! Validation logic is well-structured.

The memoized validation check correctly handles all cases: non-gated kits, empty token addresses, and validated addresses.

web/src/pages/Resolver/Parameters/Court.tsx (3)

1-1: Import statement updated correctly.

Added useEffect import which is used for validation state synchronization.


90-168: Excellent UI feedback components for validation.

The styled components provide clear visual feedback with loading spinner, success checkmark, and error cross. The color scheme follows standard UX patterns (green for success, red for error).


327-336: Well-implemented validation feedback UI.

The conditional rendering of validation status with appropriate messages for each state (validating, error, success) provides excellent user experience.

web/src/hooks/useTokenAddressValidation.ts (2)

122-129: Good implementation of debouncing.

The 500ms debounce delay is appropriate for reducing unnecessary network calls while maintaining responsive UX.


150-152: Appropriate caching and retry configuration.

The 5-minute cache time and single retry with 1-second delay provide a good balance between performance and user experience.

Copy link
Contributor

@tractorss tractorss left a comment

Choose a reason for hiding this comment

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

looks good, pushed some small refactors

jaybuidl and others added 2 commits August 6, 2025 00:47
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

sonarqubecloud bot commented Aug 6, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants