Skip to content

feat: add available stake, effectivestake #2098

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 2 commits into
base: dev
Choose a base branch
from

Conversation

kemuru
Copy link
Contributor

@kemuru kemuru commented Aug 20, 2025

PR-Codex overview

This PR focuses on refactoring the Courts component into a new Stakes component, updating the associated UI and data handling for a clearer representation of juror stakes.

Detailed summary

  • Deleted Header.tsx from Courts.
  • Renamed Courts to Stakes in several files.
  • Updated tooltipValue formatting in NumberDisplay.tsx.
  • Added new Header component in Stakes with props for availableStake, lockedStake, and effectiveStake.
  • Adjusted the main Profile component to render Stakes instead of Courts.

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

Summary by CodeRabbit

  • New Features

    • Profile “Stakes” header shows Available, Staked (Effective), and Locked PNK with icons; title adapts to “My Stakes” or “Their Stakes” based on address.
    • Number tooltips now display comma-separated values for easier reading.
  • Refactor

    • Replaced the “Courts” section with “Stakes” across the Profile page.
    • Removed the old Courts header and introduced a new Stakes header component.
    • Updated data wiring to surface available, locked, and effective stake values in the header.

@kemuru kemuru requested a review from a team as a code owner August 20, 2025 19:35
Copy link

netlify bot commented Aug 20, 2025

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

Name Link
🔨 Latest commit da90234
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet-devtools/deploys/68a6238c7637cd0008169e8b
😎 Deploy Preview https://deploy-preview-2098--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

netlify bot commented Aug 20, 2025

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

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

Copy link

netlify bot commented Aug 20, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit da90234
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-neo/deploys/68a6238c8f238c00085d0225
😎 Deploy Preview https://deploy-preview-2098--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 bot commented Aug 20, 2025

Walkthrough

Replaces Courts with Stakes in the Profile page. Introduces a new Stakes Header showing available, staked (effective), and locked PNK. Removes the old Courts Header. Updates Stakes page to compute and pass stake values. Adjusts NumberDisplay tooltip to use commified values for both currency and non-currency.

Changes

Cohort / File(s) Summary
Tooltip number formatting
web/src/components/NumberDisplay.tsx
Tooltip now displays commified values: currency as ${unit} ${commify(value)}, non-currency as ${commify(value)} ${unit}; no signature changes.
Remove Courts header
web/src/pages/Profile/Courts/Header.tsx
Deleted component that rendered Courts header with optional lockedStake and title based on address.
Add Stakes header
web/src/pages/Profile/Stakes/Header.tsx
New Header component accepts optional availableStake, lockedStake, effectiveStake; formats with formatUnits and renders via NumberDisplay; title depends on presence of address.
Stakes page logic updates
web/src/pages/Profile/Stakes/index.tsx
Renamed component to Stakes; computes availableStake, lockedStake, effectiveStake from data and passes to Header; updates exports/types accordingly.
Profile page integration
web/src/pages/Profile/index.tsx
Replaces Courts with Stakes; updates imports and GraphQL typings/usages for disputes and user data; no public API changes.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant ProfilePage as Profile Page
  participant Stakes as Stakes Page
  participant Header as Stakes Header
  participant NumberDisplay

  User->>ProfilePage: Navigate to Profile
  ProfilePage->>Stakes: Render with { addressToQuery }
  Stakes->>Stakes: Compute available, locked, effective from data
  Stakes->>Header: Render with { availableStake?, lockedStake?, effectiveStake? }
  Header->>NumberDisplay: Render PNK values (commified tooltip)
  Note over NumberDisplay: Tooltip uses commify for value display
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

Type: Enhancement :sparkles:, Package: Web

Suggested reviewers

  • alcercu
  • tractorss

Poem

A rabbit hops through Stakes anew,
Three rows of PNK in tidy view.
Available, Staked, and Locked in line,
With comma’d tooltips looking fine.
Courts hop out, new headers in—
Thump-thump! A tidy, shiny win. 🥕✨

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.

✨ 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/add-available-and-staked-amounts-to-profile

🪧 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

Copy link

netlify bot commented Aug 20, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit da90234
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet/deploys/68a6238c33f82f0008ebd51c
😎 Deploy Preview https://deploy-preview-2098--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
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

🧹 Nitpick comments (4)
web/src/components/NumberDisplay.tsx (1)

16-26: Guard against decimals=0 producing invalid "< 0.1" boundaries

"0".repeat(decimals - 1) throws for decimals = 0. Add a safe clamp and only emit the threshold strings when decimals > 0.

Apply this diff:

-const getFormattedValue = (value: number, decimals: number) => {
-  const withFixedDecimals = value % 1 !== 0 ? value.toFixed(decimals) : value.toFixed(0);
-  if (value !== 0) {
-    if (withFixedDecimals === `0.${"0".repeat(decimals)}`) {
-      return `< 0.${"0".repeat(decimals - 1)}1`;
-    } else if (withFixedDecimals === `-0.${"0".repeat(decimals)}`) {
-      return `> -0.${"0".repeat(decimals - 1)}1`;
-    }
-  }
-  return withFixedDecimals;
-};
+const getFormattedValue = (value: number, decimals: number) => {
+  const safeDecimals = Math.max(0, decimals);
+  const withFixedDecimals = value % 1 !== 0 ? value.toFixed(safeDecimals) : value.toFixed(0);
+  if (value !== 0 && safeDecimals > 0) {
+    if (withFixedDecimals === `0.${"0".repeat(safeDecimals)}`) {
+      return `< 0.${"0".repeat(safeDecimals - 1)}1`;
+    } else if (withFixedDecimals === `-0.${"0".repeat(safeDecimals)}`) {
+      return `> -0.${"0".repeat(safeDecimals - 1)}1`;
+    }
+  }
+  return withFixedDecimals;
+};
web/src/pages/Profile/Stakes/index.tsx (1)

65-71: Minor: avoid double filtering

You already computed stakedCourts. Reuse it in the map to avoid repeating the filter.

Apply this diff:

-      {isStaked && !isLoading ? (
-        <CourtCardsContainer>
-          {stakeData?.jurorTokensPerCourts
-            ?.filter(({ staked }) => staked > 0)
-            .map(({ court: { id, name }, staked }) => (
-              <CourtCard key={id} name={name ?? ""} stake={staked} {...{ id }} />
-            ))}
-        </CourtCardsContainer>
-      ) : null}
+      {isStaked && !isLoading ? (
+        <CourtCardsContainer>
+          {stakedCourts!.map(({ court: { id, name }, staked }) => (
+            <CourtCard key={id} name={name ?? ""} stake={staked} {...{ id }} />
+          ))}
+        </CourtCardsContainer>
+      ) : null}
web/src/pages/Profile/Stakes/Header.tsx (2)

97-99: Avoid boolean-or-string intermediates from && chaining

const formattedX = !isUndefined(x) && formatUnits(x, 18) yields string | false. It works at runtime but is noisy for types and easy to regress. Prefer undefined | string.

Apply this diff:

-  const formattedAvailableStake = !isUndefined(availableStake) && formatUnits(availableStake, 18);
-  const formattedLockedStake = !isUndefined(lockedStake) && formatUnits(lockedStake, 18);
-  const formattedEffectiveStake = !isUndefined(effectiveStake) && formatUnits(effectiveStake, 18);
+  const formattedAvailableStake = isUndefined(availableStake) ? undefined : formatUnits(availableStake, 18);
+  const formattedLockedStake = isUndefined(lockedStake) ? undefined : formatUnits(lockedStake, 18);
+  const formattedEffectiveStake = isUndefined(effectiveStake) ? undefined : formatUnits(effectiveStake, 18);

119-133: Label clarity: consider “Staked (effective)”

If the intent is to show effective stake (vs raw staked) it may help to disambiguate the label for users.

Apply this diff:

-            <label> Staked: </label>
+            <label> Staked (effective): </label>
📜 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 9895c7c and da90234.

📒 Files selected for processing (5)
  • web/src/components/NumberDisplay.tsx (1 hunks)
  • web/src/pages/Profile/Courts/Header.tsx (0 hunks)
  • web/src/pages/Profile/Stakes/Header.tsx (1 hunks)
  • web/src/pages/Profile/Stakes/index.tsx (3 hunks)
  • web/src/pages/Profile/index.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • web/src/pages/Profile/Courts/Header.tsx
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
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.
📚 Learning: 2024-06-27T10:11:54.861Z
Learnt from: nikhilverma360
PR: kleros/kleros-v2#1632
File: web/src/components/DisputeView/DisputeInfo/DisputeInfoList.tsx:37-42
Timestamp: 2024-06-27T10:11:54.861Z
Learning: `useMemo` is used in `DisputeInfoList` to optimize the rendering of `FieldItems` based on changes in `fieldItems`, ensuring that the mapping and truncation operation are only performed when necessary.

Applied to files:

  • web/src/pages/Profile/index.tsx
🧬 Code Graph Analysis (2)
web/src/components/NumberDisplay.tsx (1)
web/src/utils/commify.ts (1)
  • commify (1-48)
web/src/pages/Profile/Stakes/Header.tsx (1)
web-devtools/src/styles/responsiveSize.ts (1)
  • responsiveSize (9-12)
⏰ 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). (2)
  • GitHub Check: contracts-testing
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (9)
web/src/pages/Profile/index.tsx (2)

15-17: Style imports reorg looks good

The consolidated landscape/responsive imports keep styling concerns localized and consistent.


24-24: Switch to Stakes component aligns with PR intent

Replacing Courts with Stakes is consistent with the feature objective and downstream components.

web/src/pages/Profile/Stakes/index.tsx (5)

38-40: IStakes typing is precise and helpful

Explicitly using the 0x-prefixed template literal type is great for safety across contract hooks.


42-46: Confirm courtId=1 for juror balance is correct across chains

useReadSortitionModuleGetJurorBalance({ args: [addressToQuery, BigInt(1)] }) hard-codes courtId = 1. If balances are court-specific or network-dependent, this could misstate Available/Locked PNK.

Would you confirm whether 1n is always the intended court (e.g., General court) for global juror balance? If not, we should derive the correct courtId from config or aggregate across relevant courts.


51-52: LGTM: Available/Locked derive cleanly from contract tuple

Indexing the contract return for [available, locked] keeps things straightforward and type-safe.


59-60: Header integration looks correct

Passing { lockedStake, availableStake, effectiveStake } keeps the presentation layer focused and free of contract concerns.


77-77: Rename/export are coherent

Default-exporting Stakes matches the new import sites.

web/src/pages/Profile/Stakes/Header.tsx (2)

96-103: Title and prop wiring LGTM

Header props line up with the new data flow; the title switch based on the query param is straightforward.


107-115: Good conditional rendering and consistent NumberDisplay usage

Guarding each row with isUndefined keeps the UI stable while data loads. Using NumberDisplay with unit "PNK" leverages the improved tooltip formatting.

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