Skip to content

Allow two decimal places in revenue split inputs#987

Open
akshatmittal wants to merge 2 commits into
masterfrom
codex/fix-decimal-precision-in-revenue-share
Open

Allow two decimal places in revenue split inputs#987
akshatmittal wants to merge 2 commits into
masterfrom
codex/fix-decimal-precision-in-revenue-share

Conversation

@akshatmittal
Copy link
Copy Markdown
Member

@akshatmittal akshatmittal commented Apr 29, 2026

Motivation

  • Users reported "Invalid number" validation errors when entering revenue split values with two decimal places (e.g. 45.23) even though proposal simulation accepted them.
  • The UI limited inputs to a single decimal digit and auto-balancing math assumed 1-decimal precision, causing inconsistent validation and UX.

Description

  • Relaxed the form validation regex in src/components/rtoken-setup/token/RevenueSplit.tsx to allow up to two decimal places (/^[0-9]*[.]?[0-9]{0,2}$/i).
  • Applied the same two-decimal validation to external-address splits in src/components/rtoken-setup/token/ExternalRevenueSplit.tsx.
  • Adjusted the external split auto-balance math to preserve two-decimal precision by switching calculations from ((1000 - x*10)/10) to ((10000 - x*100)/100) so complementary fields match 2dp values.

Testing

  • Ran pnpm -s typecheck, which completed successfully.
  • Attempted pnpm -s eslint src/components/rtoken-setup/token/RevenueSplit.tsx src/components/rtoken-setup/token/ExternalRevenueSplit.tsx, but ESLint could not run in this environment due to the repository not exposing an eslint.config.(js|mjs|cjs) file (ESLint v9 migration requirement), so linting was not executed here.
  • No other automated tests were run as part of this change.

Codex Task

Summary by CodeRabbit

  • Bug Fixes
    • Improved percentage input validation to allow up to two decimal places.
    • Reworked reciprocal percentage auto-calculation to derive the complementary value, format to two decimals, and trim unnecessary trailing ".00", ensuring the two fields remain mathematically consistent.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 29, 2026

Deploying register-app with  Cloudflare Pages  Cloudflare Pages

Latest commit: ca753de
Status: ✅  Deploy successful!
Preview URL: https://cc31d00d.register-app.pages.dev
Branch Preview URL: https://codex-fix-decimal-precision.register-app.pages.dev

View logs

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 29, 2026

📝 Walkthrough

Walkthrough

Updated two revenue-split components: numeric input validation regexes now allow up to two decimal places; ExternalRevenueSplit’s reciprocal calculation was replaced by a helper that computes the complementary percent as 100 - value, formats to two decimals, and trims trailing .00.

Changes

Cohort / File(s) Summary
Revenue Split Components
src/components/rtoken-setup/token/ExternalRevenueSplit.tsx, src/components/rtoken-setup/token/RevenueSplit.tsx
Replaced input validation regex to allow digits with an optional decimal portion of 1–2 digits. In ExternalRevenueSplit.tsx, introduced getComplementarySplit() and updated reciprocal auto-calculation to derive the complementary percent as 100 - value, formatted to two decimals with .00 trimmed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Allow two decimal places in revenue split inputs' accurately summarizes the main change in the changeset, which is updating validation patterns and calculations to support two decimal places in revenue split inputs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-decimal-precision-in-revenue-share

Review rate limit: 2/3 reviews remaining, refill in 20 minutes.

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

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/rtoken-setup/token/ExternalRevenueSplit.tsx`:
- Around line 58-59: Round the reciprocal values to 2 decimal places before
calling setValue to avoid float artifacts; locate the places where
setValue('holders', ((10000 - +stakers * 100) / 100).toString()) and the
analogous setValue call around lines 73-74 are used, compute the reciprocal into
a variable, normalize it via a 2-decimal rounding (e.g., Math.round(value * 100)
/ 100 or Number(value.toFixed(2))), then convert that rounded value to string
and pass it to setValue so the form only receives 2dp values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cb3ec60a-4654-4885-86cb-3b5dfe5ae1e4

📥 Commits

Reviewing files that changed from the base of the PR and between 50f62c5 and 70ed046.

📒 Files selected for processing (2)
  • src/components/rtoken-setup/token/ExternalRevenueSplit.tsx
  • src/components/rtoken-setup/token/RevenueSplit.tsx

Comment thread src/components/rtoken-setup/token/ExternalRevenueSplit.tsx Outdated
Copy link
Copy Markdown
Collaborator

@lcamargof lcamargof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sum should be 100, so the values needs to be rounded if required, 99.999999 is not acceptable and a valid case with the current code.

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/rtoken-setup/token/RevenueSplit.tsx`:
- Line 37: The current validation regex in the RevenueSplit component (pattern:
/^\d+(\.\d{1,2})?$/) is too strict for in-progress user input and rejects values
like "45." while typing; change the pattern to allow 0–2 fractional digits
during input (for example /^\d+(\.\d{0,2})?$/) so intermediate values with a
trailing dot are accepted, while relying on existing required/range checks for
final validity. Update the pattern literal used in RevenueSplit (where pattern:
/^\d+(\.\d{1,2})?$/ is defined) accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 51597493-3426-4d8e-a850-6ed88b8dd155

📥 Commits

Reviewing files that changed from the base of the PR and between 70ed046 and ca753de.

📒 Files selected for processing (2)
  • src/components/rtoken-setup/token/ExternalRevenueSplit.tsx
  • src/components/rtoken-setup/token/RevenueSplit.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/rtoken-setup/token/ExternalRevenueSplit.tsx

const inputValidation = {
required: true,
pattern: /^[0-9]*[.]?[0-9]$/i,
pattern: /^\d+(\.\d{1,2})?$/,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Regex is too strict for in-progress decimal input

At Line 37, /^\d+(\.\d{1,2})?$/ rejects intermediate values like 45. while typing, which can still trigger avoidable validation noise in onChange mode. Consider allowing 0–2 fractional digits during input and relying on required + range checks for final validity.

Suggested adjustment
-  pattern: /^\d+(\.\d{1,2})?$/,
+  pattern: /^\d+(\.\d{0,2})?$/,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/rtoken-setup/token/RevenueSplit.tsx` at line 37, The current
validation regex in the RevenueSplit component (pattern: /^\d+(\.\d{1,2})?$/) is
too strict for in-progress user input and rejects values like "45." while
typing; change the pattern to allow 0–2 fractional digits during input (for
example /^\d+(\.\d{0,2})?$/) so intermediate values with a trailing dot are
accepted, while relying on existing required/range checks for final validity.
Update the pattern literal used in RevenueSplit (where pattern:
/^\d+(\.\d{1,2})?$/ is defined) accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants