Skip to content

Conversation

@tractorss
Copy link
Contributor

@tractorss tractorss commented Dec 8, 2025

PR-Codex overview

This PR focuses on improving validation and state management for the NextButton and Jurors components in the resolver pages. It enhances condition checks and handles potential undefined or invalid values for numberOfJurors.

Detailed summary

  • Updated condition in NextButton.tsx to check both arbitrationCost and numberOfJurors.
  • Modified args in Jurors.tsx to ensure numberOfJurors defaults to 0 instead of a string.
  • Enhanced handleJurorsWrite function to set numberOfJurors to 0 if the input value is undefined or NaN.

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

Summary by CodeRabbit

  • Bug Fixes
    • Strengthened validation on the juror configuration step to ensure all required fields are completed before proceeding to subsequent steps.
    • Improved input handling for juror quantity entries to gracefully handle invalid or undefined numeric values.

✏️ Tip: You can customize this high-level summary in your review settings.

@tractorss tractorss requested a review from a team as a code owner December 8, 2025 05:03
@netlify
Copy link

netlify bot commented Dec 8, 2025

Deploy Preview for kleros-v2-testnet ready!

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

@netlify
Copy link

netlify bot commented Dec 8, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit cf44adf
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-neo/deploys/69365c098009e300083a9005
😎 Deploy Preview https://deploy-preview-2201--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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 8, 2025

Walkthrough

The changes tighten validation for the jurors step in the Resolver form by requiring both arbitrationCost and numberOfJurors to be present before enabling the Next button, and harden the numberOfJurors input handler to validate numeric input and use a numeric default.

Changes

Cohort / File(s) Summary
Jurors validation hardening
web/src/pages/Resolver/NavigationButtons/NextButton.tsx
Tightens Next button enablement logic for jurors step to require both arbitrationCost and numberOfJurors to be truthy, preventing navigation until both fields are populated.
Jurors input parsing
web/src/pages/Resolver/Parameters/Jurors.tsx
Updates prepareArbitratorExtradata argument from string "0" to numeric 0 with optional chaining on disputeData.numberOfJurors; hardens input handler to guard against NaN/undefined by defaulting to 0 for invalid parsed values.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify numeric 0 default doesn't conflict with type expectations in prepareArbitratorExtradata
  • Confirm NaN guard logic in input handler covers all edge cases (empty strings, non-numeric input, etc.)
  • Ensure simultaneous validation of both fields doesn't break existing workflows

Suggested labels

Type: Bug :bug:, Package: Web

Suggested reviewers

  • alcercu

Poem

🐰 A rabbit hops through validation trees,
Where numbers now must dance with certainties.
No more shall jurors slip through without care—
Both fields must fill the air!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(web): juror-number-input-crash' clearly identifies the primary change: fixing a crash related to the juror number input field in the web application.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/empty-number-input-crash

Comment @coderabbitai help to get the list of available commands and usage tips.

@netlify
Copy link

netlify bot commented Dec 8, 2025

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

Name Link
🔨 Latest commit cf44adf
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet-devtools/deploys/69365c09d194cf00085dfcc0

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 8, 2025

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

🧹 Nitpick comments (1)
web/src/pages/Resolver/Parameters/Jurors.tsx (1)

69-76: Input hardening prevents crash, with minor refinement opportunities.

The numeric validation and fallback to 0 successfully prevent the crash. Two observations:

  1. isUndefined(value) is redundant—parseInt returns only number or NaN, never undefined.
  2. With this logic, numberOfJurors is always 0 or a valid number. When users clear the field, it displays "0" rather than remaining empty (since line 78's NaN check no longer triggers).

If you prefer an empty field when cleared, consider this alternative:

 const handleJurorsWrite = (event: React.ChangeEvent<HTMLInputElement>) => {
-  const value = parseInt(event.target.value.replace(/\D/g, ""), 10);
-  if (isUndefined(value) || isNaN(value)) {
-    setDisputeData({ ...disputeData, numberOfJurors: 0 });
-  } else {
-    setDisputeData({ ...disputeData, numberOfJurors: value });
-  }
+  const cleaned = event.target.value.replace(/\D/g, "");
+  const value = cleaned === "" ? NaN : parseInt(cleaned, 10);
+  setDisputeData({ ...disputeData, numberOfJurors: value });
 };

This preserves NaN for empty input, allowing line 78 to display an empty field.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 592243f and cf44adf.

📒 Files selected for processing (2)
  • web/src/pages/Resolver/NavigationButtons/NextButton.tsx (1 hunks)
  • web/src/pages/Resolver/Parameters/Jurors.tsx (2 hunks)
🧰 Additional context used
🧠 Learnings (10)
📓 Common learnings
Learnt from: Harman-singh-waraich
Repo: kleros/kleros-v2 PR: 1739
File: web/src/pages/Home/TopJurors/JurorCard/Coherency.tsx:22-26
Timestamp: 2024-11-07T10:48:16.774Z
Learning: In the `Coherency` component (`web/src/pages/Home/TopJurors/JurorCard/Coherency.tsx`), `totalResolvedVotes` is always greater than or equal to `totalCoherentVotes`. When both are zero, `0/0` results in `NaN`, which is acceptable in this context.
📚 Learning: 2024-11-07T10:48:16.774Z
Learnt from: Harman-singh-waraich
Repo: kleros/kleros-v2 PR: 1739
File: web/src/pages/Home/TopJurors/JurorCard/Coherency.tsx:22-26
Timestamp: 2024-11-07T10:48:16.774Z
Learning: In the `Coherency` component (`web/src/pages/Home/TopJurors/JurorCard/Coherency.tsx`), `totalResolvedVotes` is always greater than or equal to `totalCoherentVotes`. When both are zero, `0/0` results in `NaN`, which is acceptable in this context.

Applied to files:

  • web/src/pages/Resolver/NavigationButtons/NextButton.tsx
  • web/src/pages/Resolver/Parameters/Jurors.tsx
📚 Learning: 2024-10-29T10:13:04.524Z
Learnt from: Harman-singh-waraich
Repo: kleros/kleros-v2 PR: 1729
File: web/src/layout/Header/navbar/Menu/Settings/Notifications/FormContactDetails/index.tsx:69-69
Timestamp: 2024-10-29T10:13:04.524Z
Learning: In `web/src/layout/Header/navbar/Menu/Settings/Notifications/FormContactDetails/index.tsx`, when the button is disabled, the associated logic won't be reached, and certain code paths may exist for TypeScript purposes.

Applied to files:

  • web/src/pages/Resolver/NavigationButtons/NextButton.tsx
📚 Learning: 2025-05-15T06:50:40.859Z
Learnt from: tractorss
Repo: kleros/kleros-v2 PR: 1982
File: web/src/pages/Resolver/Landing/index.tsx:62-62
Timestamp: 2025-05-15T06:50:40.859Z
Learning: In the Landing component, it's safe to pass `dispute?.dispute?.arbitrated.id as 0x${string}` to `usePopulatedDisputeData` without additional null checks because the hook internally handles undefined parameters through its `isEnabled` flag and won't execute the query unless all required data is available.

Applied to files:

  • web/src/pages/Resolver/NavigationButtons/NextButton.tsx
  • web/src/pages/Resolver/Parameters/Jurors.tsx
📚 Learning: 2024-10-14T13:58:25.708Z
Learnt from: Harman-singh-waraich
Repo: kleros/kleros-v2 PR: 1703
File: web/src/hooks/queries/usePopulatedDisputeData.ts:58-61
Timestamp: 2024-10-14T13:58:25.708Z
Learning: In `web/src/hooks/queries/usePopulatedDisputeData.ts`, the query and subsequent logic only execute when `disputeData.dispute?.arbitrableChainId` and `disputeData.dispute?.externalDisputeId` are defined, so `initialContext` properties based on these values are safe to use without additional null checks.

Applied to files:

  • web/src/pages/Resolver/NavigationButtons/NextButton.tsx
  • web/src/pages/Resolver/Parameters/Jurors.tsx
📚 Learning: 2024-12-06T13:04:50.495Z
Learnt from: kemuru
Repo: kleros/kleros-v2 PR: 1774
File: web/src/components/CasesDisplay/index.tsx:61-61
Timestamp: 2024-12-06T13:04:50.495Z
Learning: In `web/src/components/CasesDisplay/index.tsx`, the variables `numberDisputes` and `numberClosedDisputes` can sometimes be `NaN`, and should default to `0` using logical OR (`||`) to prevent display issues in the `StatsAndFilters` component.

Applied to files:

  • web/src/pages/Resolver/Parameters/Jurors.tsx
📚 Learning: 2024-10-28T05:55:12.728Z
Learnt from: Harman-singh-waraich
Repo: kleros/kleros-v2 PR: 1716
File: web-devtools/src/app/(main)/dispute-template/CustomContextInputs.tsx:29-42
Timestamp: 2024-10-28T05:55:12.728Z
Learning: In the `CustomContextInputs` component located at `web-devtools/src/app/(main)/dispute-template/CustomContextInputs.tsx`, the `DisputeRequestParams` array is used to exclude certain variables from the custom input since they are already provided in a preceding component. Therefore, converting it to a type is unnecessary.

Applied to files:

  • web/src/pages/Resolver/Parameters/Jurors.tsx
📚 Learning: 2025-09-09T13:33:46.896Z
Learnt from: tractorss
Repo: kleros/kleros-v2 PR: 2117
File: web/src/components/DisputeFeatures/Features/GatedErc1155.tsx:51-66
Timestamp: 2025-09-09T13:33:46.896Z
Learning: The `setDisputeData` function in `NewDisputeContext` at `web/src/context/NewDisputeContext.tsx` has signature `(disputeData: IDisputeData) => void` and only accepts direct state values, not functional updates like standard React state setters. It cannot be used with the pattern `setDisputeData((prev) => ...)`.

Applied to files:

  • web/src/pages/Resolver/Parameters/Jurors.tsx
📚 Learning: 2024-10-21T10:32:16.970Z
Learnt from: Harman-singh-waraich
Repo: kleros/kleros-v2 PR: 1703
File: kleros-sdk/src/utils/getDispute.ts:38-40
Timestamp: 2024-10-21T10:32:16.970Z
Learning: The variables 'arbitrableChainID' and 'externalDisputeID' are required by the context to have uppercase 'ID', so they should remain unchanged even if the corresponding source properties use 'Id'.

Applied to files:

  • web/src/pages/Resolver/Parameters/Jurors.tsx
📚 Learning: 2024-10-09T10:22:41.474Z
Learnt from: jaybuidl
Repo: kleros/kleros-v2 PR: 1582
File: web-devtools/src/app/(main)/ruler/SelectArbitrable.tsx:88-90
Timestamp: 2024-10-09T10:22:41.474Z
Learning: Next.js recommends using the `useEffect` hook to set `isClient` and using `suppressHydrationWarning` as a workaround for handling hydration inconsistencies, especially when dealing with data like `knownArbitrables` that may differ between server-side and client-side rendering. This approach is acceptable in TypeScript/React applications, such as in `web-devtools/src/app/(main)/ruler/SelectArbitrable.tsx`.

Applied to files:

  • web/src/pages/Resolver/Parameters/Jurors.tsx
🧬 Code graph analysis (1)
web/src/pages/Resolver/Parameters/Jurors.tsx (1)
web/src/utils/prepareArbitratorExtradata.ts (1)
  • prepareArbitratorExtradata (48-68)
⏰ 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-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • 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: hardhat-tests
  • GitHub Check: Analyze (javascript)
  • GitHub Check: SonarCloud
  • 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
🔇 Additional comments (2)
web/src/pages/Resolver/Parameters/Jurors.tsx (1)

61-61: LGTM: Type-correct argument for arbitration cost calculation.

The change from string "0" to numeric disputeData?.numberOfJurors ?? 0 correctly matches the number type expected by prepareArbitratorExtradata's noOfVotes parameter.

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

46-46: LGTM: Proper validation for jurors step.

Requiring both arbitrationCost and numberOfJurors to be truthy correctly prevents users from proceeding with invalid input (e.g., 0 jurors). This validation coordinates well with the input hardening in Jurors.tsx.

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.

2 participants