Skip to content

Conversation

kemuru
Copy link
Contributor

@kemuru kemuru commented Aug 22, 2025

PR-Codex overview

This PR focuses on enhancing the InputDisplay component by calculating the maximum withdrawable amount for jurors and updating related error messages and displayed values accordingly.

Detailed summary

  • Introduced maxWithdrawAmount calculation based on jurorBalance.
  • Replaced parsedStake with parsedMaxWithdrawAmount in labels and logic.
  • Updated error message for insufficient withdrawal amounts.
  • Added maxWithdrawAmount to the dependency array in useEffect.

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

Summary by CodeRabbit

  • Bug Fixes
    • Corrects the maximum withdrawable amount to prevent withdrawing more than available.
    • “Withdraw all” now respects the actual available amount.
    • Validation re-runs when availability changes and shows a clearer message: “Insufficient available amount to withdraw this amount.”
    • Display of available amount and quick-fill actions now accurately reflect the current maximum withdrawable balance.

Copy link

netlify bot commented Aug 22, 2025

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

Name Link
🔨 Latest commit 378c2b0
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-university/deploys/68a8a1475220f000086e6c22

Copy link

netlify bot commented Aug 22, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 378c2b0
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet/deploys/68a8a147957c0000081ac735
😎 Deploy Preview https://deploy-preview-2105--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 22, 2025

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

Name Link
🔨 Latest commit 378c2b0
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet-devtools/deploys/68a8a147bf1b1e000806ee41
😎 Deploy Preview https://deploy-preview-2105--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 bot commented Aug 22, 2025

Walkthrough

Computes a new maxWithdrawAmount from jurorBalance (min(pending, total-locked)), exposes a formatted parsedMaxWithdrawAmount, replaces parsedStake usages with it, updates withdrawal validation and error messaging, and adds the new value to effect dependencies.

Changes

Cohort / File(s) Summary
Stake/Withdraw validation update
web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx
Added maxWithdrawAmount = min(jurorBalance[2], jurorBalance[0] - jurorBalance[1]) (defaults to 0n); introduced parsedMaxWithdrawAmount for display; replaced parsedStake usages with parsedMaxWithdrawAmount; updated validation to compare against maxWithdrawAmount and changed error text to "Insufficient available amount to withdraw this amount."; added maxWithdrawAmount to useEffect deps; updated "Withdraw all" quick-fill and available-amount display to reflect new cap.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as InputDisplay
  participant State as jurorBalance
  participant Validator

  User->>UI: Enter amount or click "Withdraw all"
  UI->>State: Read jurorBalance [total, locked, pending] (or absent)
  State-->>UI: jurorBalance values / undefined
  UI->>UI: Compute maxWithdrawAmount = min(pending, total - locked) || 0
  UI->>Validator: Validate requested amount ≤ maxWithdrawAmount
  alt amount ≤ maxWithdrawAmount
    Validator-->>UI: Valid
    UI-->>User: Enable withdraw action
  else amount > maxWithdrawAmount
    Validator-->>UI: Invalid (error text shown)
    UI-->>User: Show "Insufficient available amount to withdraw this amount."
  end
  note right of UI: "Withdraw all" fills parsedMaxWithdrawAmount
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

Package: Web

Suggested reviewers

  • alcercu

Poem

I nibble at numbers, a rabbit so spry,
Max withdraw found where the balances lie.
Quick-fill now honest, no overlong chase,
Carrots for logic, and hops full of grace. 🥕🐇

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 97c7d3d and 378c2b0.

📒 Files selected for processing (1)
  • web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.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). (15)
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: SonarCloud
  • GitHub Check: contracts-testing
  • GitHub Check: Analyze (javascript)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix(web)/withdraw-amounts-fix

🪧 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.
    • 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.
  • 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 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/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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 Aug 22, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit 378c2b0
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-neo/deploys/68a8a147a10a320008603da0
😎 Deploy Preview https://deploy-preview-2105--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
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: 1

🧹 Nitpick comments (2)
web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx (2)

95-97: Message reads a bit awkward; tighten phrasing.

The validation is correct. Consider a clearer copy:

-      setErrorMsg("Insufficient available amount to withdraw this amount");
+      setErrorMsg("Insufficient withdrawable amount.");

113-117: UI swap to max-withdrawable looks right; avoid shadowing prop name.

The display/update behavior is correct. Minor readability nit: the local const amount = … shadows the amount prop.

-        <StyledLabel
-          onClick={() => {
-            const amount = isStaking ? parsedBalance : parsedMaxWithdrawAmount;
-            setAmount(amount);
-          }}
-        >
+        <StyledLabel
+          onClick={() => {
+            const allAmount = isStaking ? parsedBalance : parsedMaxWithdrawAmount;
+            setAmount(allAmount);
+          }}
+        >
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f02d718 and 97c7d3d.

📒 Files selected for processing (1)
  • web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2024-12-09T12:36:59.441Z
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1775
File: web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawButton.tsx:0-0
Timestamp: 2024-12-09T12:36:59.441Z
Learning: In the `StakeWithdrawButton` component, the transaction flow logic is tightly linked to component updates, so extracting it into a custom hook does not provide significant benefits.

Applied to files:

  • web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx
📚 Learning: 2024-11-19T16:31:08.965Z
Learnt from: jaybuidl
PR: kleros/kleros-v2#1746
File: contracts/config/courts.v2.mainnet-neo.json:167-170
Timestamp: 2024-11-19T16:31:08.965Z
Learning: In `contracts/config/courts.v2.mainnet-neo.json`, the `minStake` parameter is denominated in PNK, not ETH.

Applied to files:

  • web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.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-testnet-devtools
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - 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 (1)
web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx (1)

108-108: Good call adding the new cap to dependencies.

Including maxWithdrawAmount ensures validation updates when the cap changes. Looks correct given other direct uses of jurorBalance in the effect.

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 22, 2025
Copy link

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.

1 participant