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(web): dispute-maintenance-buttons #1645

Merged
merged 20 commits into from
Aug 7, 2024
Merged

feat(web): dispute-maintenance-buttons #1645

merged 20 commits into from
Aug 7, 2024

Conversation

Harman-singh-waraich
Copy link
Contributor

@Harman-singh-waraich Harman-singh-waraich commented Jul 4, 2024

  • adds dispute maintenance buttons to manually do operations in case bots fails or in development.
  • The ripple shows when a Period is over or Execution is pending. Not showing it for rewards distribution, since that is not straightforward to determine and want to keep these buttons minimal.

closes #1601

Summary by CodeRabbit

  • New Features

    • Introduced MaintenanceButtons component for managing maintenance actions related to disputes.
    • Added action buttons including DrawButton, ExecuteRulingButton, and PassPeriodButton.
    • Implemented DistributeRewards component for reward distribution management.
    • Added useTransactionBatcher custom hook to facilitate batching of contract transactions.
  • Enhancements

    • Updated the CaseDetails page structure to incorporate the MaintenanceButtons.
    • Added nbVotes field to the disputeDetailsQuery for improved tracking of disputes.
    • Enhanced GraphQL schema with new fields related to fee management and dispute resolution.

PR-Codex overview

This PR introduces various updates related to dispute details, maintenance, and contract batching.

Detailed summary

  • Added new fields jurorsDrawn and jurorRewardsDispersed to rounds
  • Implemented TransactionBatcher contract for batch transactions
  • Updated UI components for maintenance buttons and case details

The following files were skipped due to too many changes: web/src/pages/Cases/CaseDetails/MaintenanceButtons/MenuButton.tsx, web/src/pages/Cases/CaseDetails/MaintenanceButtons/ExecuteRuling.tsx, subgraph/core/src/KlerosCore.ts, web/src/hooks/useTransactionBatcher.tsx, web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx, web/src/pages/Cases/CaseDetails/MaintenanceButtons/PassPeriodButton.tsx, web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewards.tsx, web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx, web/src/pages/Cases/CaseDetails/MaintenanceButtons/WithdrawAppealFees.tsx, contracts/deployments/arbitrum/TransactionBatcher.json, contracts/deployments/arbitrumSepoliaDevnet/TransactionBatcher.json

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

Copy link
Contributor

coderabbitai bot commented Jul 4, 2024

Walkthrough

The updates enhance the user interface by introducing maintenance buttons for managing disputes, allowing users to pass periods, execute rulings, and distribute rewards. These components integrate with Kleros Core contracts and utilize new hooks for improved state management. Additionally, a new field, nbVotes, has been added to the currentRound object in the disputeDetailsQuery GraphQL query to enrich the dispute details.

Changes

Files / Directories Change Summary
web/src/hooks/queries/useDisputeDetailsQuery.ts Added a new field nbVotes to the currentRound object in the disputeDetailsQuery GraphQL query.
web/src/pages/Cases/CaseDetails/index.tsx Added MaintenanceButtons import, created HeaderContainer styled component, and updated structure to include MaintenanceButtons.
web/src/pages/Cases/CaseDetails/MaintenanceButtons/*.tsx Introduced new components for various dispute actions: MaintenanceButtons, DrawButton, ExecuteRulingButton, PassPeriodButton, and WithdrawAppealFees.
web/src/hooks/useTransactionBatcher.tsx Implemented useTransactionBatcher custom hook for facilitating batch transactions in a blockchain context.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI as MaintenanceButtons UI
    participant Contract as Kleros Core Contracts

    User ->> UI: Click Pass Period Button
    UI ->> Contract: passPeriod(dispute.id)
    Contract ->> UI: Confirmation

    User ->> UI: Click Execute Ruling Button
    UI ->> Contract: executeRuling(dispute.id)
    Contract ->> UI: Confirmation

    User ->> UI: Click Distribute Rewards Button
    UI ->> Contract: execute(dispute.id, dispute.currentRoundIndex, 20)
    Contract ->> UI: Confirmation
Loading

Assessment against linked issues

Objective Addressed Explanation
Add maintenance buttons for dispute actions (#1601)
Disable button if prepareCall fails (#1601)
Display error message for failed prepareCall (#1601) Unclear if error messages are implemented in the UI.

Poem

In the realm where disputes arise,
Maintenance buttons now surprise,
With actions swift and seamless flair,
Passing periods, rulings fair.
Rewards now flow, no task too tall,
Contracts heed the maintenance call.
Cheers to progress, big and small! 🌟


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

netlify bot commented Jul 4, 2024

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

Name Link
🔨 Latest commit 097bbaa
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/66b0a2df7dbbb600089d5ee8

Copy link

netlify bot commented Jul 4, 2024

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/66b34bdde38124b2613b9819
😎 Deploy Preview https://deploy-preview-1645--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 site configuration.

Copy link

netlify bot commented Jul 4, 2024

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

Name Link
🔨 Latest commit
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/66b34a97ff0755a5c43e8f68

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: 5

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ad0154c and bd5ecbb.

Files ignored due to path filters (1)
  • web/src/assets/svgs/icons/dotted-menu.svg is excluded by !**/*.svg
Files selected for processing (8)
  • web/src/hooks/queries/useDisputeDetailsQuery.ts (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewads.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/ExecuteRuling.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/MenuButton.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/PassPeriodButton.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/index.tsx (3 hunks)
Files skipped from review due to trivial changes (1)
  • web/src/hooks/queries/useDisputeDetailsQuery.ts
Additional context used
Biome
web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx

[error] 80-83: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)

Additional comments not posted (33)
web/src/pages/Cases/CaseDetails/MaintenanceButtons/ExecuteRuling.tsx (6)

1-3: Imports look good.

The imports are necessary and correctly included.


4-7: Imports look good.

The imports are necessary and correctly included.


8-11: Imports look good.

The imports are necessary and correctly included.


13-17: Styled button component looks good.

The styled button component is defined correctly.


19-21: Type alias and component definition look good.

The type alias is correctly defined, and the component definition starts correctly.


51-53: Component return and export look good.

The button is correctly returned, and the component is correctly exported.

web/src/pages/Cases/CaseDetails/MaintenanceButtons/PassPeriodButton.tsx (6)

1-3: Imports look good.

The imports are necessary and correctly included.


4-7: Imports look good.

The imports are necessary and correctly included.


8-11: Imports look good.

The imports are necessary and correctly included.


13-17: Styled button component looks good.

The styled button component is defined correctly.


19-21: Type alias and component definition look good.

The type alias is correctly defined, and the component definition starts correctly.


51-53: Component return and export look good.

The button is correctly returned, and the component is correctly exported.

web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx (6)

1-3: Imports look good.

The imports are necessary and correctly included.


4-7: Imports look good.

The imports are necessary and correctly included.


8-11: Imports look good.

The imports are necessary and correctly included.


13-17: Styled button component looks good.

The styled button component is defined correctly.


19-21: Interface definition looks good.

The interface is correctly defined.


55-58: Component return and export look good.

The button is correctly returned, and the component is correctly exported.

web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewads.tsx (5)

1-3: Imports look good.

The imports are necessary and correctly included.


4-7: Imports look good.

The imports are necessary and correctly included.


8-11: Imports look good.

The imports are necessary and correctly included.


13-17: Styled button component looks good.

The styled button component is defined correctly.


19-22: Interface definition looks good.

The interface is correctly defined.

web/src/pages/Cases/CaseDetails/MaintenanceButtons/MenuButton.tsx (4)

1-5: LGTM!

The import statements are appropriate for the functionality being implemented.


6-68: LGTM!

The styled components are well-defined and utilize the styled-components library effectively.


70-73: LGTM!

The IMenuButton interface is correctly defined and specifies the required props.


75-83: LGTM!

The MenuButton functional component is well-structured and correctly implements the desired functionality.

web/src/pages/Cases/CaseDetails/index.tsx (3)

Line range hint 1-17:
LGTM!

The import statements are appropriate for the functionality being implemented.


29-40: LGTM!

The styled components are well-defined and utilize the styled-components library effectively.


53-56: LGTM!

The CaseDetails functional component is well-structured and correctly integrates the MaintenanceButtons component.

web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx (3)

1-17: LGTM!

The import statements are appropriate for the functionality being implemented.


19-45: LGTM!

The styled components are well-defined and utilize the styled-components library effectively.


47-50: LGTM!

The IBaseMaintenaceButton interface is correctly defined and specifies the required props.

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bd5ecbb and 7599a23.

Files selected for processing (1)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 4, 2024
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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7599a23 and 4a4b27e.

Files selected for processing (3)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewards.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/MenuButton.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/MenuButton.tsx
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx
Additional comments not posted (4)
web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewards.tsx (4)

1-17: LGTM!

The imports and styled component definitions are appropriate and necessary for the functionality of the component.


19-24: LGTM!

The interface definition and component props are well-defined and necessary for the component's functionality.


25-45: LGTM!

The state, hooks, and memoized values are necessary for managing the component's functionality and performance.


46-56: LGTM!

The button click handler and return statement are well-implemented and necessary for the component's functionality.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 4, 2024
kemuru
kemuru previously approved these changes Jul 4, 2024
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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4a4b27e and 2d2c605.

Files selected for processing (1)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 5, 2024
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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2d2c605 and 037bc7f.

Files selected for processing (2)
  • web/src/hooks/useTransactionBatcher.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewards.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewards.tsx
Additional comments not posted (8)
web/src/hooks/useTransactionBatcher.tsx (8)

1-3: LGTM! Imports are appropriate.

The import statements include necessary modules from viem, wagmi, and other local utilities, which are relevant for the functionality of the file.


9-33: LGTM! ABI and constants are well-defined.

The ABI for the batcher contract and the addresses are correctly defined and seem appropriate for the functionality.


35-43: LGTM! Hooks are correctly defined.

The hooks useBatchSimulate and useBatchWrite are correctly defined using createUseSimulateContract and createUseWriteContract respectively.


45-47: LGTM! Contract address mapping is correctly defined.

The batcherAddress mapping for contract addresses is well-defined.


49-49: LGTM! Type definition is appropriate.

The TransactionBatcherConfig type definition is appropriate and relevant for the hook's functionality.


51-68: Ensure configurations are correctly handled.

The hook initializes with optional configurations and maps them correctly for the useBatchSimulate hook. Ensure that the configurations are correctly passed and handled.


70-73: LGTM! Execution logic is well-defined.

The executeBatch function is well-defined and uses writeContractAsync to execute the batch transaction. Ensure proper error handling in the calling code.


73-74: LGTM! Return statement is appropriate.

The return statement includes all necessary states and functions (executeBatch, batchConfig, isError, and isLoading), which are appropriate for the hook's functionality.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 8, 2024
@kemuru kemuru self-requested a review July 15, 2024 13:56
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: 3

Outside diff range, codebase verification and nitpick comments (1)
contracts/deployments/arbitrumSepoliaDevnet/TransactionBatcher.json (1)

73-82: Consider adding documentation.

The devdoc and userdoc sections are present but empty. Consider adding documentation to provide more context and usage information for the contract.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a9e3732 and c0f0d29.

Files selected for processing (5)
  • contracts/README.md (2 hunks)
  • contracts/deploy/00-transaction-batcher.ts (1 hunks)
  • contracts/deployments/arbitrum/TransactionBatcher.json (1 hunks)
  • contracts/deployments/arbitrumSepoliaDevnet/TransactionBatcher.json (1 hunks)
  • contracts/src/utils/TransactionBatcher.sol (1 hunks)
Files skipped from review due to trivial changes (1)
  • contracts/README.md
Additional comments not posted (8)
contracts/deployments/arbitrum/TransactionBatcher.json (4)

2-49: LGTM!

The address and abi sections are correctly implemented.


51-66: LGTM!

The transactionHash and receipt sections are correctly implemented.


67-71: LGTM!

The args, numDeployments, solcInputHash, and metadata sections are correctly implemented.


72-86: LGTM!

The bytecode, deployedBytecode, devdoc, userdoc, and storageLayout sections are correctly implemented.

contracts/deployments/arbitrumSepoliaDevnet/TransactionBatcher.json (4)

2-2: Contract address is valid.

The address "0x35f93986950804ac1F93519BF68C2a7Dd776db0E" appears to be valid.


3-49: ABI appears correctly defined.

The ABI defines two functions, batchSend and batchSendUnchecked, both of which accept arrays of addresses, values, and data, and are payable.


50-66: Transaction hash and receipt are valid.

The transaction hash "0x3c4a6f233fda3dc940b9aba1e04ee5993b515e4834b73365c4cd613718db46b2" and receipt details are consistent with a successful deployment.


69-72: Metadata is correctly defined.

The metadata includes relevant details about the Solidity compiler version, compilation target, and other settings.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c0f0d29 and 1413980.

Files selected for processing (1)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx (1 hunks)
Additional comments not posted (10)
web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx (10)

1-2: LGTM!

The imports for React, useEffect, useState, and styled-components are correct and necessary.


4-9: LGTM!

The imports for useParams, useDisputeDetailsQuery, Periods, and Period are correct and necessary.


11-13: LGTM!

The imports for EnsureChain and Overlay components are correct and necessary.


14-18: LGTM!

The imports for DistributeRewards, DrawButton, ExecuteRulingButton, MenuButton, and PassPeriodButton are correct and necessary.


20-27: LGTM!

The Container styled component is well-defined and correctly used to style the main container.


29-46: LGTM!

The PopupContainer styled component is well-defined and correctly used to style the popup container.


53-56: LGTM!

The MaintenanceButtons component correctly initializes state and retrieves the dispute ID from the URL parameters.


58-59: LGTM!

The useDisputeDetailsQuery hook is correctly used to fetch dispute details.


98-121: LGTM!

The toggle function and the JSX structure for rendering the buttons and ripple effect are correctly implemented.


125-125: LGTM!

The MaintenanceButtons component is correctly exported as the default export.

@jaybuidl jaybuidl enabled auto-merge July 24, 2024 11:54
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: 6

Outside diff range, codebase verification and nitpick comments (18)
web/src/pages/Cases/CaseDetails/MaintenanceButtons/ExecuteRuling.tsx (6)

1-3: Remove unnecessary blank line.

The blank line between the import statements and the styled-components import is unnecessary.

- import styled from "styled-components";
- 
+ import styled from "styled-components";

4-5: Remove unnecessary blank line.

The blank line between the usePublicClient import and the next import is unnecessary.

- import { usePublicClient } from "wagmi";
- 
+ import { usePublicClient } from "wagmi";

6-7: Remove unnecessary blank line.

The blank line between the Button import and the next import is unnecessary.

- import { Button } from "@kleros/ui-components-library";
- 
+ import { Button } from "@kleros/ui-components-library";

9-10: Remove unnecessary blank line.

The blank line between the wrapWithToast import and the next import is unnecessary.

- import { wrapWithToast } from "utils/wrapWithToast";
- 
+ import { wrapWithToast } from "utils/wrapWithToast";

11-12: Remove unnecessary blank line.

The blank line between the isUndefined import and the next import is unnecessary.

- import { isUndefined } from "src/utils";
- 
+ import { isUndefined } from "src/utils";

13-14: Remove unnecessary blank line.

The blank line between the IBaseMaintenanceButton import and the next line is unnecessary.

- import { IBaseMaintenanceButton } from ".";
- 
+ import { IBaseMaintenanceButton } from ".";
web/src/pages/Cases/CaseDetails/MaintenanceButtons/PassPeriodButton.tsx (6)

1-3: Remove unnecessary blank line.

The blank line between the import statements and the styled-components import is unnecessary.

- import styled from "styled-components";
- 
+ import styled from "styled-components";

4-5: Remove unnecessary blank line.

The blank line between the usePublicClient import and the next import is unnecessary.

- import { usePublicClient } from "wagmi";
- 
+ import { usePublicClient } from "wagmi";

6-7: Remove unnecessary blank line.

The blank line between the Button import and the next import is unnecessary.

- import { Button } from "@kleros/ui-components-library";
- 
+ import { Button } from "@kleros/ui-components-library";

9-10: Remove unnecessary blank line.

The blank line between the wrapWithToast import and the next import is unnecessary.

- import { wrapWithToast } from "utils/wrapWithToast";
- 
+ import { wrapWithToast } from "utils/wrapWithToast";

11-12: Remove unnecessary blank line.

The blank line between the isUndefined import and the next import is unnecessary.

- import { isUndefined } from "src/utils";
- 
+ import { isUndefined } from "src/utils";

13-14: Remove unnecessary blank line.

The blank line between the IBaseMaintenanceButton import and the next line is unnecessary.

- import { IBaseMaintenanceButton } from ".";
- 
+ import { IBaseMaintenanceButton } from ".";
web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx (6)

1-3: Remove unnecessary blank line.

The blank line between the import statements and the styled-components import is unnecessary.

- import styled from "styled-components";
- 
+ import styled from "styled-components";

4-5: Remove unnecessary blank line.

The blank line between the usePublicClient import and the next import is unnecessary.

- import { usePublicClient } from "wagmi";
- 
+ import { usePublicClient } from "wagmi";

6-7: Remove unnecessary blank line.

The blank line between the Button import and the next import is unnecessary.

- import { Button } from "@kleros/ui-components-library";
- 
+ import { Button } from "@kleros/ui-components-library";

9-10: Remove unnecessary blank line.

The blank line between the wrapWithToast import and the next import is unnecessary.

- import { wrapWithToast } from "utils/wrapWithToast";
- 
+ import { wrapWithToast } from "utils/wrapWithToast";

11-12: Remove unnecessary blank line.

The blank line between the isUndefined import and the next import is unnecessary.

- import { isUndefined } from "src/utils";
- 
+ import { isUndefined } from "src/utils";

13-14: Remove unnecessary blank line.

The blank line between the IBaseMaintenanceButton import and the next line is unnecessary.

- import { IBaseMaintenanceButton } from ".";
- 
+ import { IBaseMaintenanceButton } from ".";
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1413980 and fe737d4.

Files selected for processing (5)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewards.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/ExecuteRuling.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/PassPeriodButton.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx
Additional comments not posted (8)
web/src/pages/Cases/CaseDetails/MaintenanceButtons/ExecuteRuling.tsx (1)

45-48: Improve error handling in wrapWithToast.

Include a catch block to handle potential errors in the wrapWithToast function.

- wrapWithToast(async () => await rule(ruleConfig.request), publicClient).finally(() => {
+ wrapWithToast(async () => await rule(ruleConfig.request), publicClient)
+   .catch((error) => {
+     console.error("Error executing ruling:", error);
+   })
+   .finally(() => {
web/src/pages/Cases/CaseDetails/MaintenanceButtons/PassPeriodButton.tsx (1)

45-48: Improve error handling in wrapWithToast.

Include a catch block to handle potential errors in the wrapWithToast function.

- wrapWithToast(async () => await passPeriod(passPeriodConfig.request), publicClient).finally(() => {
+ wrapWithToast(async () => await passPeriod(passPeriodConfig.request), publicClient)
+   .catch((error) => {
+     console.error("Error passing period:", error);
+   })
+   .finally(() => {
web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx (1)

50-53: Improve error handling in wrapWithToast.

Include a catch block to handle potential errors in the wrapWithToast function.

- wrapWithToast(async () => await draw(drawConfig.request), publicClient).finally(() => {
+ wrapWithToast(async () => await draw(drawConfig.request), publicClient)
+   .catch((error) => {
+     console.error("Error executing draw:", error);
+   })
+   .finally(() => {
web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewards.tsx (5)

26-31: Ensure proper error handling for hooks.

The hooks usePublicClient and useAccount should have error handling to manage potential issues during their execution.

Ensure that the hooks handle errors gracefully and do not cause the application to crash.


32-52: Validate state dependencies in useEffect.

The useEffect hook depends on id, roundIndex, numberOfVotes, and chainId. Ensure that these dependencies are correctly managed and updated.

Ensure that the dependencies are correctly managed and updated to avoid potential issues with stale state.


54-62: Check for potential performance issues with useMemo.

The useMemo hook is used to memoize isLoading and isDisabled. Ensure that these computations are not causing performance issues.

Ensure that the useMemo computations are efficient and do not cause performance bottlenecks.


64-72: Handle potential errors in handleClick.

The handleClick function should handle potential errors during the execution of the batch request.

Ensure that the function handles errors gracefully and provides appropriate feedback to the user.


1-15: Ensure all imports are necessary.

Review the imports to ensure that all of them are necessary and used within the file. Unused imports can be removed to keep the code clean.

Verification successful

All imports are necessary and used within the file.

  • The imports React, styled, useAccount, usePublicClient, Button, DEFAULT_CHAIN, klerosCoreAbi, klerosCoreAddress, useTransactionBatcher, wrapWithToast, isUndefined, and IBaseMaintenanceButton are all utilized in the file.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if all imported modules are used in the file.

# Test: Search for the usage of each imported module. Expect: All modules should be used within the file.
rg --type tsx 'React|styled|useAccount|usePublicClient|Button|DEFAULT_CHAIN|klerosCoreAbi|klerosCoreAddress|useTransactionBatcher|wrapWithToast|isUndefined|IBaseMaintenanceButton'

Length of output: 209


Script:

#!/bin/bash
# Description: Verify if all imported modules are used in the file.

# Test: Search for the usage of each imported module. Expect: All modules should be used within the file.
rg 'React|styled|useAccount|usePublicClient|Button|DEFAULT_CHAIN|klerosCoreAbi|klerosCoreAddress|useTransactionBatcher|wrapWithToast|isUndefined|IBaseMaintenanceButton' web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewards.tsx

Length of output: 1601

@Harman-singh-waraich
Copy link
Contributor Author

  • Implementing better button handling
  • hook update
    Merge on hold

@Harman-singh-waraich Harman-singh-waraich marked this pull request as draft July 25, 2024 11:06
coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 25, 2024
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

Outside diff range, codebase verification and nitpick comments (1)
web/src/hooks/useTransactionBatcher.tsx (1)

16-34: Enhance documentation with parameter details.

The function documentation is good but can be enhanced by providing more details about the parameters.

 * @param configs SimulateContractParameters[] - an array of useWriteContract Parameters
 * @param options TransactionBatcherOptions - an object containing options to apply to hook behaviour
 * @description This takes in multiple write calls and batches them into a single transaction
 * @example useTransactionBatcher([
 *                 { address : "contract one address",
 *                   abi : "contract one abi",
 *                   functionName : "...",
 *                   args: [...]
 *                   value: 0
 *                 },
 *                 { address : "contract 2 address",
 *                   abi : "contract 2 abi",
 *                   functionName : "...",
 *                   args: [...]
 *                   value: 0
 *                 },
 *                ])
+ * @returns {Object} - An object containing the executeBatch function, batchConfig, isError, and isLoading states.
 */
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fe737d4 and 1c02948.

Files selected for processing (6)
  • web/src/hooks/useTransactionBatcher.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewards.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/ExecuteRuling.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/PassPeriodButton.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewards.tsx
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/ExecuteRuling.tsx
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/PassPeriodButton.tsx
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx
Additional comments not posted (4)
web/src/hooks/useTransactionBatcher.tsx (4)

1-7: LGTM! Import statements are appropriate.

The import statements are necessary and correctly imported.


9-14: LGTM! Type definitions are appropriate.

The type definitions are necessary and correctly defined.


57-57: LGTM! Return statement is appropriate.

The return statement is necessary and correctly defined.


60-60: LGTM! Default export is appropriate.

The default export is necessary and correctly defined.

Copy link

codeclimate bot commented Aug 5, 2024

Code Climate has analyzed commit 097bbaa and detected 17 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 3
Duplication 6
Style 8

View more on Code Climate.

Copy link

sonarqubecloud bot commented Aug 5, 2024

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: 4

Outside diff range, codebase verification and nitpick comments (7)
web/src/hooks/useTransactionBatcher.tsx (1)

39-39: Improve readability by renaming validatedConfigs.

The variable validatedConfigs can be renamed to configs for better readability.

-  const validatedConfigs = configs ?? [];
+  const configs = configs ?? [];
web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx (1)

68-68: Enhance button accessibility.

Consider adding an aria-label attribute to the button for better accessibility.

-  return <StyledButton text="Draw" small isLoading={isLoading} disabled={isDisabled} onClick={handleClick} />;
+  return <StyledButton text="Draw" small isLoading={isLoading} disabled={isDisabled} onClick={handleClick} aria-label="Draw" />;
web/src/pages/Cases/CaseDetails/MaintenanceButtons/PassPeriodButton.tsx (1)

22-24: Add JSDoc comments for interface properties.

Consider adding JSDoc comments to describe the properties of the IPassPeriodButton interface for better documentation and readability.

interface IPassPeriodButton extends IBaseMaintenanceButton {
+  /**
+   * The period of the dispute.
+   */
  period?: string;
}
subgraph/core/src/entities/ClassicRound.ts (1)

19-20: LGTM! Consider adding comments for new properties.

The new properties appealFeesDispersed and totalFeeDispersed enhance the state representation of the ClassicRound object. Consider adding comments to describe these properties.

classicRound.appealFeesDispersed = false; // Indicates whether appeal fees have been dispersed.
classicRound.totalFeeDispersed = ZERO; // The total amount of fees dispersed.
web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewards.tsx (1)

24-27: Add JSDoc comments for interface properties.

Consider adding JSDoc comments to describe the properties of the IDistributeRewards interface for better documentation and readability.

interface IDistributeRewards extends IBaseMaintenanceButton {
+  /**
+   * The round index of the dispute.
+   */
  roundIndex?: string;
+  /**
+   * The period of the dispute.
+   */
  period?: string;
}
web/src/pages/Cases/CaseDetails/MaintenanceButtons/WithdrawAppealFees.tsx (1)

1-24: Consider Import Optimization

While the imports are correct, consider grouping related imports together for better readability. For example, group all wagmi imports together.

web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx (1)

1-47: Consider Import Optimization

While the imports are correct, consider grouping related imports together for better readability. For example, group all component imports together.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1c02948 and 097bbaa.

Files selected for processing (14)
  • subgraph/core/schema.graphql (2 hunks)
  • subgraph/core/src/DisputeKitClassic.ts (2 hunks)
  • subgraph/core/src/KlerosCore.ts (3 hunks)
  • subgraph/core/src/entities/ClassicRound.ts (1 hunks)
  • subgraph/core/src/entities/Round.ts (1 hunks)
  • web/src/hooks/queries/useClassicAppealQuery.ts (1 hunks)
  • web/src/hooks/queries/useDisputeMaintenanceQuery.ts (1 hunks)
  • web/src/hooks/useTransactionBatcher.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewards.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/PassPeriodButton.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/WithdrawAppealFees.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx (1 hunks)
  • web/src/utils/getLocalRounds.ts (1 hunks)
Additional comments not posted (31)
web/src/utils/getLocalRounds.ts (2)

1-2: LGTM! The use of generics enhances flexibility.

The new interface DisputeKitDispute<T> is well-defined and improves the function's reusability.


5-11: LGTM! Improved readability and flexibility.

The updated getLocalRounds function handles edge cases correctly and uses flatMap for better readability.

web/src/hooks/queries/useDisputeMaintenanceQuery.ts (3)

9-34: LGTM! The GraphQL query is well-defined.

The disputeMaintenance query correctly fetches the necessary dispute details and contributions.


36-50: LGTM! The hook is correctly implemented.

The useDisputeMaintenanceQuery hook uses react-query effectively and handles the query results appropriately.


52-52: LGTM! The default export is correctly defined.

The useDisputeMaintenanceQuery hook is correctly exported as the default export.

web/src/hooks/queries/useClassicAppealQuery.ts (2)

30-31: LGTM! The additional fields enhance the query.

The inclusion of appealFeesDispersed and totalFeeDispersed fields provides more comprehensive data.


Line range hint 33-49:
LGTM! The hook is correctly implemented.

The useClassicAppealQuery hook uses react-query effectively and handles the query results appropriately.

subgraph/core/src/entities/Round.ts (1)

27-28: LGTM! Verify the usage of new properties.

The new properties jurorsDrawn and jurorRewardsDispersed are appropriately initialized to false.

Ensure that the usage of these new properties is correctly handled throughout the codebase.

Verification successful

The new properties jurorsDrawn and jurorRewardsDispersed are correctly handled throughout the codebase.

  • The properties are set based on specific conditions in subgraph/core/src/KlerosCore.ts.
  • They are queried from the GraphQL API in web/src/hooks/queries/useDisputeMaintenanceQuery.ts.
  • They are used to determine the state of UI components in web/src/pages/Cases/CaseDetails/MaintenanceButtons/PassPeriodButton.tsx, DistributeRewards.tsx, and DrawButton.tsx.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new properties `jurorsDrawn` and `jurorRewardsDispersed`.

# Test: Search for the usage of the new properties. Expect: Correct handling throughout the codebase.
rg --type js --type ts 'jurorsDrawn|jurorRewardsDispersed'

Length of output: 1004


Script:

#!/bin/bash
# Extract context around the usage of `jurorsDrawn` and `jurorRewardsDispersed` in the identified files.

# Extract context from subgraph/core/src/KlerosCore.ts
rg --type js --type ts -A 5 -B 5 'jurorsDrawn|jurorRewardsDispersed' subgraph/core/src/KlerosCore.ts

# Extract context from web/src/hooks/queries/useDisputeMaintenanceQuery.ts
rg --type js --type ts -A 5 -B 5 'jurorsDrawn|jurorRewardsDispersed' web/src/hooks/queries/useDisputeMaintenanceQuery.ts

# Extract context from web/src/pages/Cases/CaseDetails/MaintenanceButtons/PassPeriodButton.tsx
rg --type js --type ts -A 5 -B 5 'jurorsDrawn' web/src/pages/Cases/CaseDetails/MaintenanceButtons/PassPeriodButton.tsx

# Extract context from web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewards.tsx
rg --type js --type ts -A 5 -B 5 'jurorRewardsDispersed' web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewards.tsx

# Extract context from web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx
rg --type js --type ts -A 5 -B 5 'jurorsDrawn' web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx

Length of output: 2799

web/src/pages/Cases/CaseDetails/MaintenanceButtons/PassPeriodButton.tsx (5)

1-20: LGTM!

The imports and styled button definition are correct.


26-29: Ensure correct error handling for useSimulateKlerosCorePassPeriod.

Consider adding error handling for the useSimulateKlerosCorePassPeriod hook to manage potential errors during the simulation.

const { 
  data: passPeriodConfig, 
  isLoading: isLoadingConfig, 
  isError, 
  error 
} = useSimulateKlerosCorePassPeriod({ 
  query: { 
    enabled: !isUndefined(id), 
  }, 
  args: [BigInt(id ?? 0)], 
});

if (error) {
  console.error("Error simulating pass period:", error);
}

60-70: Improve error handling in handleClick.

Add a catch block to handle potential errors in the wrapWithToast function.

wrapWithToast(async () => await passPeriod(passPeriodConfig.request), publicClient)
  .catch((error) => {
    console.error("Error passing period:", error);
  })
  .finally(() => {
    setIsSending(false);
    setIsOpen(false);
  });

70-71: Enhance button accessibility.

Consider adding an aria-label attribute to the button for better accessibility.

return <StyledButton text="Pass Period" small isLoading={isLoading} disabled={isDisabled} onClick={handleClick} aria-label="Pass Period" />;

73-73: LGTM!

The export statement is correct.

subgraph/core/src/entities/ClassicRound.ts (2)

Line range hint 23-47:
LGTM!

The updateCountsAndGetCurrentRuling function is well-defined.


Line range hint 49-70:
LGTM!

The updateChoiceFundingFromContributionEvent function is well-defined.

web/src/pages/Cases/CaseDetails/MaintenanceButtons/DistributeRewards.tsx (3)

1-22: LGTM!

The imports and styled button definition are correct.


76-84: Improve error handling in handleClick.

Add a catch block to handle potential errors in the wrapWithToast function.

wrapWithToast(async () => await executeBatch(batchConfig), publicClient)
  .catch((error) => {
    console.error("Error distributing rewards:", error);
  })
  .finally(() => {
    setIsSending(false);
    setIsOpen(false);
  });

85-86: Enhance button accessibility.

Consider adding an aria-label attribute to the button for better accessibility.

return <StyledButton text="Juror Rewards" small isLoading={isLoading} disabled={isDisabled} onClick={handleClick} aria-label="Distribute Juror Rewards" />;
web/src/pages/Cases/CaseDetails/MaintenanceButtons/WithdrawAppealFees.tsx (4)

26-30: Interface Definition Looks Good

The interface IWithdrawAppealFees is correctly defined, extending IBaseMaintenanceButton and adding relevant properties.


32-79: Ensure chainId is defined

The chainId might be undefined, ensure that this case is handled correctly, possibly with a fallback or error handling.


81-88: Ensure Correct Usage of useTransactionBatcher

The enabled condition is complex. Verify that all conditions are correctly checked and that the hook is used as intended.


96-105: Ensure publicClient and batchConfig are Defined

The handleClick function checks for publicClient and batchConfig. Ensure these are always defined when the function is called.

web/src/pages/Cases/CaseDetails/MaintenanceButtons/index.tsx (3)

49-52: Interface Definition Looks Good

The interface IBaseMaintenanceButton is correctly defined with the necessary props.


54-97: Ensure dispute is Defined Before Use

The dispute object is used in multiple places. Ensure that it is always defined before use to avoid runtime errors.


99-132: Ensure dispute Properties are Defined

The dispute properties such as period, currentRound, and ruled are used in the return statement. Ensure these properties are always defined before use.

subgraph/core/src/DisputeKitClassic.ts (2)

111-115: Ensure Correct Retrieval of Appeal Cost

The logic for retrieving the appeal cost has been updated. Verify that the getRoundInfo method correctly retrieves the information for the relevant round.


136-151: Ensure Correct Tracking of Withdrawal

The logic for tracking the withdrawal of appeal fees and updating the localRound state has been updated. Verify that the totalFeeDispersed and appealFeesDispersed properties are correctly updated.

subgraph/core/schema.graphql (2)

195-196: Addition of new fields to Round type.

The fields jurorsDrawn and jurorRewardsDispersed are added to track the status of juror selection and reward distribution.


269-270: Addition of new fields to ClassicRound type.

The fields totalFeeDispersed and appealFeesDispersed are added to track the total fees distributed and the status of appeal fee distribution.

subgraph/core/src/KlerosCore.ts (2)

27-27: Addition of Round entity to import statements.

The Round entity is added to the import statements to support the changes made to the handleDraw and handleTokenAndETHShift functions.


188-198: Enhancements to handleDraw and handleTokenAndETHShift functions.

The handleDraw function now updates the jurorsDrawn field, and the handleTokenAndETHShift function updates the jurorRewardsDispersed field of the Round entity. These changes improve the logic of juror management and reward distribution.

Also applies to: 213-227

@jaybuidl jaybuidl marked this pull request as ready for review August 7, 2024 10:15
@jaybuidl jaybuidl merged commit d1fef37 into dev Aug 7, 2024
9 of 23 checks passed
@jaybuidl jaybuidl deleted the feat/case-dev-buttons branch August 7, 2024 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UI: add buttons for dispute-level maintenance
4 participants