Skip to content

Conversation

@jaybuidl
Copy link
Member

@jaybuidl jaybuidl commented Apr 30, 2025

PR-Codex overview

This PR focuses on updating the Kleros escrow application with various improvements, including new hooks, style adjustments, and dependency updates.

Detailed summary

  • Deleted useArbitrationCostFromKlerosCore.ts hook.
  • Added useScrollTop hook for scrolling to the top.
  • Modified global styles for Toastify component.
  • Updated subgraph/package.json version to 2.1.0.
  • Changed network in subgraph.yaml from arbitrum-one to arbitrum-sepolia.
  • Updated contract paths in deployment scripts.
  • Updated TransactionDetails to use new arbitration cost hook.
  • Enhanced AttachmentDisplay with new styles and ScrollTop component.
  • Updated various dependencies in package.json files across multiple directories.

The following files were skipped due to too many changes: yarn.lock

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

Summary by CodeRabbit

  • New Features

    • Added a ScrollTop component to improve navigation by scrolling to specific sections or the top of the page.
    • Introduced a useScrollTop hook for smooth or instant scrolling to the top within overlays.
  • Enhancements

    • Improved styling and layout of the AttachmentDisplay page, including better external link handling and responsive design.
    • Updated subgraph configuration to target the arbitrum-sepolia network for more relevant data indexing.
  • Dependency Updates

    • Upgraded multiple dependencies and devDependencies across contracts, subgraph, and web projects for improved compatibility and security.
    • Added @kleros/kleros-v2-contracts as a dependency in the web project.
  • Bug Fixes

    • Refined external link security in AttachmentDisplay by updating the rel attribute.
  • Refactor

    • Streamlined contract retrieval logic for arbitrator contracts, improving maintainability and network support.
    • Replaced the arbitration cost hook with a new implementation for more robust contract reads.
    • Updated configuration and artifact reading logic to support new contract deployment structures.
  • Chores

    • Removed obsolete arbitration cost hook and unused dependencies.
    • Cleaned up Hardhat configuration by removing external deployment paths.
  • Style

    • Added global styles for toast notifications to improve UI consistency.

@jaybuidl jaybuidl requested review from a team as code owners April 30, 2025 10:10
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 30, 2025

Walkthrough

This set of changes refactors how arbitrator contracts are retrieved and managed across deployment scripts, utilities, and configuration files. It introduces a new centralized function for fetching arbitrator contracts, updates deployment and script logic to use this function, and removes legacy chain-based logic. Dependency versions are updated in multiple package.json files, with some dependencies added or removed. The subgraph configuration is updated to target a new network and contract address. In the web application, new hooks and components are introduced for scroll management, a legacy arbitration cost hook is removed, and related components are updated to use the new contract read hook. Styling and layout improvements are also made.

Changes

File(s) Change Summary
contracts/deploy/00-escrow.ts Updated import and usage from getContracts to getArbitratorContracts for contract retrieval.
contracts/deploy/utils/getContracts.ts Refactored contract retrieval logic: added getArbitratorContracts, simplified getContracts, delegated arbitrator contract fetching to a centralized function.
contracts/hardhat.config.ts Removed the external property, eliminating external deployment artifact imports.
contracts/package.json
subgraph/package.json
web/package.json
Updated dependency versions, added/removed specific packages (e.g., added @kleros/kleros-v2-contracts, removed ethers from web).
contracts/scripts/setDisputeTemplate.ts Added frontendUrl parameter to network config and dispute template function, updated template logic to use it.
subgraph/subgraph.yaml Changed target network, contract address, starting block, and ABI path for the subgraph.
web/src/components/ScrollTop.tsx Introduced a new ScrollTop React component for scroll management based on URL parameters.
web/src/hooks/queries/useArbitrationCostFromKlerosCore.ts Removed the legacy arbitration cost React hook.
web/src/hooks/useScrollTop.ts Added a new useScrollTop React hook for scrolling to the top via overlay scroll context.
web/src/pages/AttachmentDisplay/index.tsx Enhanced layout and styling, refactored external link handling, added ScrollTop component.
web/src/pages/MyTransactions/TransactionDetails/index.tsx Switched arbitration cost retrieval to a new generated hook, updated prop passing accordingly.
web/src/styles/global-style.ts Added CSS rule to adjust toast notification container padding and positioning.
web/wagmi.config.ts Refactored to import arbitrator contracts, updated artifact reading logic, introduced new types and helper functions.

Sequence Diagram(s)

sequenceDiagram
    participant DeploymentScript
    participant getArbitratorContracts
    participant getContractsEthers

    DeploymentScript->>getArbitratorContracts: Request arbitrator contracts (hre)
    getArbitratorContracts->>getContractsEthers: Fetch contracts for network
    getContractsEthers-->>getArbitratorContracts: Return contract instances
    getArbitratorContracts-->>DeploymentScript: Return {klerosCore, disputeTemplateRegistry}
Loading
sequenceDiagram
    participant ReactComponent
    participant useScrollTop
    participant OverlayScrollContext

    ReactComponent->>useScrollTop: Call hook
    useScrollTop->>OverlayScrollContext: Access scroll instance
    ReactComponent->>useScrollTop: Call scrollTop()
    useScrollTop->>OverlayScrollContext: Scroll to top
Loading

Possibly related PRs

  • Arbitrator contracts update and subgraph redeploy #110: The main PR and the retrieved PR both modify the same files (contracts/deploy/00-escrow.ts and contracts/deploy/utils/getContracts.ts) with the same core change of replacing getContracts with getArbitratorContracts for fetching arbitrator contracts, indicating they are directly related.

Suggested labels

Type: Maintenance :construction:, Package: Contracts, Package: Web, Package: Subgraph

Suggested reviewers

  • kemuru

Poem

A rabbit hops through code so neat,
Refactoring paths with nimble feet.
Contracts fetched with central grace,
Scrolls to top, leaves not a trace.
Dependencies fresh, the subgraph anew,
With every hop, the project grew!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in 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.

@netlify
Copy link

netlify bot commented Apr 30, 2025

Deploy Preview for kleros-escrow-v2 ready!

Name Link
🔨 Latest commit a7f4b01
🔍 Latest deploy log https://app.netlify.com/sites/kleros-escrow-v2/deploys/6811f72f83e072000885aeb7
😎 Deploy Preview https://deploy-preview-114--kleros-escrow-v2.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 site 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 (6)
web/src/styles/global-style.ts (1)

125-128: Consider avoiding !important in CSS rules

While this positioning fix for toast containers works, using !important is generally considered a last resort in CSS as it breaks the natural cascade and can make future style changes more difficult to maintain.

Consider investigating if this can be achieved with more specific selectors or by adjusting the toast library configuration instead.

 [class*="Toastify__toast-container"] {
   top: unset;
-  padding-top: 20px !important;
+  padding-top: 20px;
 }

If the !important is truly necessary due to the toast library's styles having higher specificity, please add a comment explaining this requirement.

web/src/components/ScrollTop.tsx (1)

12-28: Consider adding cleanup for hasScrolled ref

The component uses a ref to track if scrolling has occurred, but doesn't reset it when the component unmounts or when dependencies change.

Consider adding a cleanup function to the useEffect:

  useEffect(() => {
    if (hasScrolled.current) return;
    const params = new URLSearchParams(search);
    const section = params.get("section");

    if (section) {
      const targetElement = document.getElementById(section);
      if (targetElement) {
        targetElement.scrollIntoView({ behavior: "smooth" });
        hasScrolled.current = true;
        navigate(pathname, { replace: true });
        return;
      }
    }

    scrollTop();
+   
+   return () => {
+     hasScrolled.current = false;
+   };
  }, [navigate, pathname, scrollTop]);

This ensures the component will work correctly if it's unmounted and remounted.

contracts/deploy/utils/getContracts.ts (1)

11-20: Good implementation of centralized arbitrator contract retrieval

The new helper function effectively centralizes the retrieval of arbitrator contracts with proper error handling for unsupported networks.

Consider adding a fallback deployment name for local development environments:

 const NETWORK_TO_DEPLOYMENT: Record<string, DeploymentName> = {
   arbitrumSepoliaDevnet: "devnet",
   arbitrumSepolia: "testnet",
   arbitrum: "mainnetNeo",
+  hardhat: "devnet", // Fallback for local development
 } as const;

This would make local development and testing more straightforward.

web/wagmi.config.ts (3)

15-24: Consider using more specific typing for ABI.

The ArbitratorContracts type definition is well-structured, but uses any[] for the ABI type. Consider using a more specific type for better type safety.

- abi: any[];
+ abi: readonly unknown[];

77-80: New logic to include KlerosCore contract.

The code now extracts the KlerosCore contract from arbitrator contracts and adds it to the results. This approach centralizes contract management and avoids hardcoding addresses.

Consider adding error handling in case KlerosCore is undefined in the imported contracts.

- const { KlerosCore } = arbitratorContracts.default.contracts;
+ const { KlerosCore } = arbitratorContracts.default.contracts;
+ if (!KlerosCore) {
+   throw new Error('KlerosCore contract not found in arbitrator contracts');
+ }

78-78: Consider making the contract list more flexible.

The arbitrator contract name is hardcoded. For better maintainability and future-proofing, consider defining contract names as constants or making this approach more flexible.

- const arbitratorContractConfigs = [{ name: "KlerosCore", contract: KlerosCore }];
+ const ARBITRATOR_CONTRACTS = ["KlerosCore"];
+ const arbitratorContractConfigs = ARBITRATOR_CONTRACTS.map(name => ({ 
+   name, 
+   contract: arbitratorContracts.default.contracts[name] 
+ }));
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 64ecc14 and a7f4b01.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (15)
  • contracts/deploy/00-escrow.ts (2 hunks)
  • contracts/deploy/utils/getContracts.ts (1 hunks)
  • contracts/hardhat.config.ts (0 hunks)
  • contracts/package.json (2 hunks)
  • contracts/scripts/setDisputeTemplate.ts (3 hunks)
  • subgraph/package.json (2 hunks)
  • subgraph/subgraph.yaml (2 hunks)
  • web/package.json (3 hunks)
  • web/src/components/ScrollTop.tsx (1 hunks)
  • web/src/hooks/queries/useArbitrationCostFromKlerosCore.ts (0 hunks)
  • web/src/hooks/useScrollTop.ts (1 hunks)
  • web/src/pages/AttachmentDisplay/index.tsx (3 hunks)
  • web/src/pages/MyTransactions/TransactionDetails/index.tsx (3 hunks)
  • web/src/styles/global-style.ts (1 hunks)
  • web/wagmi.config.ts (3 hunks)
💤 Files with no reviewable changes (2)
  • contracts/hardhat.config.ts
  • web/src/hooks/queries/useArbitrationCostFromKlerosCore.ts
🧰 Additional context used
🧬 Code Graph Analysis (4)
web/src/hooks/useScrollTop.ts (1)
web/src/context/OverlayScrollContext.tsx (1)
  • OverlayScrollContext (3-3)
contracts/deploy/00-escrow.ts (1)
contracts/deploy/utils/getContracts.ts (1)
  • getArbitratorContracts (11-20)
web/src/pages/AttachmentDisplay/index.tsx (3)
web/src/styles/landscapeStyle.ts (2)
  • MAX_WIDTH_LANDSCAPE (3-3)
  • landscapeStyle (7-11)
web/src/styles/responsiveSize.ts (1)
  • responsiveSize (9-12)
web/src/components/ExternalLink.tsx (1)
  • ExternalLink (5-9)
web/wagmi.config.ts (1)
contracts/scripts/wagmiHelpers.ts (1)
  • readArtifacts (15-42)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Redirect rules - kleros-escrow-v2
  • GitHub Check: Redirect rules - kleros-escrow-v2
  • GitHub Check: Header rules - kleros-escrow-v2
  • GitHub Check: Header rules - kleros-escrow-v2
  • GitHub Check: Pages changed - kleros-escrow-v2
  • GitHub Check: Pages changed - kleros-escrow-v2
🔇 Additional comments (31)
web/src/hooks/useScrollTop.ts (1)

1-15: Well-structured hook for scroll management

This new hook provides a clean, reusable way to scroll to the top of the page. The implementation is well thought out with:

  • Good use of optional chaining to safely handle possible undefined values
  • Clean API with the optional smooth scrolling parameter
  • Proper context usage to access the scroll instance

The hook follows React best practices and provides a focused, single-responsibility utility.

subgraph/package.json (2)

3-3: Version bump follows semantic versioning

Appropriate minor version increase from 2.0.8 to 2.1.0, indicating non-breaking changes with new functionality, which aligns with the contract management refactoring in this PR.


33-33: Dependency update to latest version

The gluegun dependency update from ^5.1.2 to ^5.2.0 is a minor version bump, which should maintain compatibility while providing new features or fixes.

contracts/deploy/00-escrow.ts (2)

5-5: Import update aligns with centralized contract retrieval

The import change from getContracts to getArbitratorContracts follows the refactoring pattern described in the PR objectives.


31-31: Implementation successfully updated to use centralized function

The code now uses getArbitratorContracts(hre) to retrieve the arbitrator contracts, which is consistent with the refactoring to centralize contract retrieval logic. This change improves maintainability by removing duplicated network detection logic across deployment scripts.

subgraph/subgraph.yaml (3)

7-7: Network change to arbitrum-sepolia implemented correctly.

The network change from arbitrum-one to arbitrum-sepolia aligns with the broader changes in contract deployment strategy. This properly targets the testnet environment.


9-11: Contract address and starting block updated appropriately.

The contract address and starting block have been updated to match the arbitrum-sepolia deployment. This ensures the subgraph will index events from the correct contract and starting point.


25-25: ABI file path correctly updated.

The ABI file path now correctly points to the arbitrumSepoliaDevnet deployment directory, which aligns with the network change.

contracts/package.json (2)

63-77: Dev dependency updates look good.

The dev dependencies have been updated to newer versions, which should provide bug fixes and new features. The most significant update is hardhat from 2.22.18 to 2.23.0, which includes improvements and bug fixes.


86-87: Key dependency updates align with contract retrieval changes.

The upgrade of @kleros/kleros-v2-contracts from ^0.7.0 to ^0.9.3 is particularly important as it supports the centralized contract retrieval refactoring described in the PR. The OpenZeppelin contracts update to 5.3.0 brings in the latest security improvements.

web/package.json (2)

48-48: Correctly added kleros-v2-contracts dependency.

Adding @kleros/kleros-v2-contracts as a dev dependency is essential for the centralized contract retrieval pattern being implemented in this PR.


70-70: Frontend dependency updates align with architectural changes.

The updates to @kleros/kleros-app, subgraph-status, viem, and wagmi support the shift from ethers.js to viem/wagmi for contract interactions. This is a positive architectural improvement that brings more type safety and better performance.

Also applies to: 101-103

contracts/scripts/setDisputeTemplate.ts (3)

9-9: Frontend URLs correctly configured for devnet and mainnet.

The frontend URLs for arbitrumSepoliaDevnet and arbitrum are properly configured with the appropriate placeholder for external dispute IDs.

Also applies to: 18-18


22-22: Dispute template function correctly updated to use dynamic frontend URL.

The function signature now includes the frontendUrl parameter, and the template correctly uses this dynamic value instead of a hardcoded URL. This improves flexibility and maintainability.

Also applies to: 49-49


101-101: Implementation correctly uses the new frontendUrl parameter.

The code properly extracts the frontendUrl alongside the subgraphEndpoint and passes it to the disputeTemplateFn. This ensures the dispute template is correctly configured for each network.

Also applies to: 108-108

web/src/pages/MyTransactions/TransactionDetails/index.tsx (3)

13-13: Implementation of generated contract hook

The import change from useArbitrationCost to useReadKlerosCoreArbitrationCost aligns with the broader refactoring to use generated contract hooks instead of custom ones.


35-37: Improved arbitration cost retrieval implementation

The code now uses the generated hook with proper argument structure, passing escrow parameters' arbitrator extra data as an argument array.


93-93: Updated prop passing to match new data structure

The arbitration cost is now properly passed as arbitrationCost?.data to account for the new hook's return structure.

web/src/pages/AttachmentDisplay/index.tsx (4)

18-32: Improved container styling with responsive design

The updated container styles now include background color, proper padding, and responsive adjustments for landscape orientation. This enhances the visual consistency and user experience.


40-46: Refined link styling with proper component usage

The switch from a styled <a> tag to using the ExternalLink component improves code consistency and maintainability.


63-65: Security improvement in external link

The rel attribute now includes both "noopener" and "noreferrer", which enhances security when opening links in new tabs by preventing the new page from accessing the window.opener property.


77-77: ScrollTop component integration

The addition of the ScrollTop component enables scrolling to top functionality, improving user experience.

contracts/deploy/utils/getContracts.ts (3)

2-2: Improved contract import with proper naming

Importing the arbitrator contracts from the Kleros V2 package and renaming the function for clarity enhances code readability.


5-9: Well-structured network to deployment mapping

The constant mapping of network names to deployment names provides a clear and maintainable way to handle different environments.


22-28: Simplified contract retrieval with improved maintainability

The refactored getContracts function now uses the centralized helper, making the code more maintainable and reducing duplication.

web/wagmi.config.ts (6)

7-11: Import structure is well organized.

The imports from @kleros/kleros-v2-contracts are clearly labeled to match their respective environments (devnet, testnet, mainnet), making the code more maintainable and easier to understand.


26-44: Good abstraction of contract addition logic.

Creating a separate helper function for adding arbitrator contracts improves code organization and reusability. The function signature is also well typed.


46-50: Function signature updated to support arbitrator contracts.

The updated parameter list properly supports the new requirements, making the function's purpose clearer.


88-88: Environment-specific contract selection is clear.

The code correctly selects the appropriate arbitrator contracts based on the deployment environment, improving the configuration process.

Also applies to: 93-93, 98-98, 103-103


109-109: Updated function call with new parameter.

The readArtifacts function call is correctly updated to include the arbitratorContracts parameter.


57-57:

❓ Verification inconclusive

Path construction has changed.

The directory path now uses a relative path ../contracts/deployments/${hardhatChainName} instead of the previous ./deployments/${hardhatChainName ?? viemChainName}.

This change assumes a specific directory structure and removes the fallback to viemChainName. Ensure this works correctly in all environments.


🏁 Script executed:

#!/bin/bash
# Check if the directory structure exists as expected
ls -la ../contracts/deployments/ 2>/dev/null || echo "Directory does not exist as expected"

Length of output: 117


🏁 Script executed:

#!/bin/bash
# List directories named 'contracts' or 'deployments'
find . -type d | grep -E "contracts|deployments" || echo "No matching directories found"

# Search for references to 'deployments' in code files
rg -l "deployments" || echo "No references to 'deployments' found"

Length of output: 1141


🏁 Script executed:

#!/bin/bash
# Display the lines around directoryPath in web/wagmi.config.ts to confirm fallback logic
rg -n 'directoryPath' -A3 -B3 web/wagmi.config.ts

Length of output: 596


🏁 Script executed:

#!/bin/bash
# Show imports and chain name mappings in web/wagmi.config.ts
head -n 50 web/wagmi.config.ts
rg -n "hardhatChainName" web/wagmi.config.ts
rg -n "viemChainName" web/wagmi.config.ts

Length of output: 1473


🏁 Script executed:

#!/bin/bash
# Find where readArtifacts is invoked to inspect the passed chain names and fallback logic
rg -n 'readArtifacts' -A5 -B5 web/wagmi.config.ts || echo "No invocations found"

Length of output: 673


Ensure deployments path and chain‐name fallback are correct

The snippet at web/wagmi.config.ts:57 now reads:

const directoryPath = `../contracts/deployments/${hardhatChainName}`;

This removes the previous …/${hardhatChainName ?? viemChainName} fallback and relies on a relative lookup from wherever the CLI is invoked. Please verify:

  • That the wagmi CLI always runs with CWD set to web/, so ../contracts/deployments/... points at the repo’s contracts/deployments folder.
  • Every value of hardhatChainName you pass (e.g. arbitrum, arbitrumSepoliaDevnet) matches an existing subfolder under contracts/deployments.
  • If you need a fallback to the viem chain name or more robust resolution, consider either re-adding ?? viemChainName or using an absolute path helper:
    const directoryPath = join(__dirname, "../contracts/deployments", hardhatChainName);

@jaybuidl jaybuidl merged commit 66b6cf4 into master Apr 30, 2025
7 of 9 checks passed
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.

4 participants