Skip to content

Conversation

@Klakurka
Copy link
Member

@Klakurka Klakurka commented Nov 27, 2025

Related to #582

Test plan

Create a widget/button w/ editable=true, then try to enter 9999999999999999999999999999 and see that it stops you.

Greptile Overview

Greptile Summary

Implemented maximum amount limits for the editable amount field to prevent users from entering unrealistic cryptocurrency values. The limits are set to 999,999.99999999 BCH and 999,999,999,999.99 XEC, aligned with the related issue requirements.

Key Changes:

  • Added MAX_AMOUNT constant in constants.ts defining currency-specific maximum values
  • Modified TextField component to use type="number" with max, min, and step attributes for better UX
  • Implemented runtime validation in handleAmountChange to clamp values exceeding the maximum
  • Set appropriate step values: 0.00000001 for BCH (8 decimals) and 0.01 for XEC (2 decimals)

The implementation provides both browser-level validation hints (via HTML5 attributes) and JavaScript-level enforcement (via the onChange handler) to ensure amounts stay within acceptable ranges.

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk - it adds input validation without breaking existing functionality
  • The implementation correctly enforces max amount limits through both HTML5 attributes and runtime validation. The constants are properly defined and the logic is straightforward. Score reduced by 1 point because the change from text to number input type removes the previous maxLength constraint, which could allow users to briefly type very long numbers before they're clamped by validation.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
react/lib/util/constants.ts 5/5 Added MAX_AMOUNT constant defining maximum allowed amounts for BCH (999,999.99999999) and XEC (999,999,999,999.99)
react/lib/components/Widget/Widget.tsx 4/5 Added max amount enforcement in handleAmountChange handler and TextField inputProps, changed input type to number with min/max/step attributes

Sequence Diagram

sequenceDiagram
    participant User
    participant TextField
    participant handleAmountChange
    participant MAX_AMOUNT
    participant State
    
    User->>TextField: Types amount in editable field
    TextField->>TextField: Validates with max/min/step attributes
    TextField->>handleAmountChange: onChange event with value
    handleAmountChange->>handleAmountChange: Check if empty, set to "0"
    handleAmountChange->>MAX_AMOUNT: Get max for thisAddressType
    handleAmountChange->>handleAmountChange: Compare +amount > maxAmount
    alt Amount exceeds max
        handleAmountChange->>handleAmountChange: Clamp to maxAmount.toString()
    end
    handleAmountChange->>State: setUserEditedAmount(getCurrencyObject)
    handleAmountChange->>State: updateAmount(clamped value)
    State->>TextField: Re-render with clamped value
Loading

Summary by CodeRabbit

  • Bug Fixes

    • Amount input now enforces numeric entry, per-currency upper bounds and decimal precision to prevent invalid or too-large values.
  • Improvements

    • Edit amount field applies currency-appropriate increments and real-time validation; accepts blank/cleared input states gracefully.
    • Minor UI spacing and alignment tweaks around confirm/draft controls.
  • Chores

    • Added a convenience script to streamline clean-and-watch development workflow.

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

@Klakurka Klakurka added this to the Phase 3 milestone Nov 27, 2025
@Klakurka Klakurka requested a review from chedieck November 27, 2025 08:45
@Klakurka Klakurka self-assigned this Nov 27, 2025
@Klakurka Klakurka added the enhancement (UI/UX/feature) New feature or request label Nov 27, 2025
@Klakurka Klakurka linked an issue Nov 27, 2025 that may be closed by this pull request
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 27, 2025

Walkthrough

Adds a currency-specific max amount constant and uses it in the Widget numeric input to restrict value and decimal precision; updates NumericFormat isAllowed guard and clamps edited amounts; and adds a clean:watch npm script.

Changes

Cohort / File(s) Summary
Constants
react/lib/util/constants.ts
Added exported MAX_AMOUNT ({ BCH: 999999.99999999, XEC: 999999999999.99 }) alongside existing constants.
Widget amount input & validation
react/lib/components/Widget/Widget.tsx
Imported MAX_AMOUNT; NumericFormat now uses an isAllowed guard enforcing 0 ≤ floatValue ≤ `MAX_AMOUNT[thisAddressType]
Package scripts
package.json
Added clean:watch script: yarn clean:build && yarn watch.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review isAllowed logic for NaN/undefined handling and edge float values.
  • Verify decimal-count enforcement matches DECIMALS[thisAddressType] and interacts correctly with STEP_AMOUNT/NumericFormat rounding.
  • Confirm fallback behavior when thisAddressType is missing or unrecognized and that clamping preserves expected formatting.

Possibly related PRs

Suggested labels

enhancement (behind the scenes)

Poem

🐰 I hopped to guard the digits and the sum,

Set fences high so numbers don't run,
Tiny hops for decimals, steady and neat,
Clamped the bounds so values stay sweet,
A clean watch script — my work is done.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Introduced max editable amounts' directly and clearly summarizes the main change: adding maximum amount limits to the editable amount field.
Description check ✅ Passed The PR description includes the related issue (#582), a clear test plan, and detailed implementation notes via Greptile. However, it lacks the 'Description' section from the template to explain the change in non-technical terms.
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 feat/max-editable-amount

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd4c9ad and d53a145.

📒 Files selected for processing (2)
  • react/lib/components/Widget/Widget.tsx (3 hunks)
  • react/lib/util/constants.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • react/lib/util/constants.ts
  • react/lib/components/Widget/Widget.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). (1)
  • GitHub Check: Run build

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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 (2)
react/lib/util/constants.ts (1)

11-14: MAX_AMOUNT values are consistent with existing currency config

The per-currency caps line up with current decimal precision (8 for BCH, 2 for XEC) and give sensible upper bounds against pathological inputs. If you later expand the currency set, you might consider tightening the typing to something like Record<CryptoCurrency, number> so missing entries are caught at compile time, but what you have is fine for now.

react/lib/components/Widget/Widget.tsx (1)

27-27: Max-amount clamping and numeric input props look correct; consider centralizing clamp logic

  • Importing MAX_AMOUNT and clamping in handleAmountChange ensures user-edited amounts can’t exceed the per-currency caps, which directly addresses the “huge editable amount” issue.
  • Using type="number" with min: 0, max: MAX_AMOUNT[thisAddressType] || MAX_AMOUNT.XEC, and BCH‑specific step (1e‑8 vs 0.01) is consistent with your existing decimal configuration and helps keep the UI in a sane range.
  • Note that only this input path applies the clamp; other paths that set thisAmount (e.g., via props.amount or via updateAmount from child components) can still provide values above MAX_AMOUNT. If you want a stronger invariant, consider extracting a small helper (e.g., clampToMaxAmount(thisAddressType, rawAmount)) and reusing it wherever thisAmount is set, but that’s an optional hardening step rather than a blocker.

Also applies to: 865-878, 1051-1058

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a6661b and c523744.

📒 Files selected for processing (2)
  • react/lib/components/Widget/Widget.tsx (3 hunks)
  • react/lib/util/constants.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
react/lib/components/Widget/Widget.tsx (2)
react/lib/util/constants.ts (1)
  • MAX_AMOUNT (11-14)
react/lib/util/format.ts (1)
  • amount (5-12)

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 (3)
package.json (1)

27-28: clean:watch composition is sound; be aware it's a heavy operation

Chaining clean:build then watch is correct and predictable, and the script looks good. Just keep in mind it will nuke node_modules/dist and do a full reinstall+build before starting dev, so it’s best reserved for “start from scratch” scenarios rather than routine watch usage.

react/lib/util/constants.ts (2)

11-14: STEP_AMOUNT values align with DECIMALS; optional DRY-up opportunity

The BCH/XEC step values correctly match their declared decimal precision (10^-8 and 10^-2), so this is consistent with existing DECIMALS and suitable for numeric inputs.

If you want to reduce duplication in the future, you could derive step at use‑site from DECIMALS (e.g., 10 ** -DECIMALS[symbol]) instead of maintaining a separate map, but that’s purely a convenience refactor.


16-19: MAX_AMOUNT bounds look reasonable; consider centralizing per‑currency config later

The BCH and XEC max amounts are within a safe numeric range for JS and match the intent of preventing unrealistic values, so they’re fine as standalone constants.

Longer term, you might want to group per‑currency settings (decimals, step, min/max, etc.) into a single typed config object per currency to avoid spreading several parallel maps across this file.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c523744 and a84e78b.

📒 Files selected for processing (3)
  • package.json (1 hunks)
  • react/lib/components/Widget/Widget.tsx (4 hunks)
  • react/lib/util/constants.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • react/lib/components/Widget/Widget.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). (1)
  • GitHub Check: Run build

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)
react/lib/components/Widget/Widget.tsx (2)

1203-1214: Well-implemented max amount validation.

The isAllowed validation correctly constrains user input to the currency-specific maximum. The fallback to MAX_AMOUNT.XEC is reasonable.

Consider adding defensive handling if thisAddressType could be undefined or an unexpected value:

  isAllowed={
    (values) => {
      const { floatValue } = values
+     const maxForType = MAX_AMOUNT[thisAddressType ?? 'XEC'] ?? MAX_AMOUNT.XEC
      return (
        floatValue === undefined ||
        (
-         floatValue <= (MAX_AMOUNT[thisAddressType] ?? MAX_AMOUNT.XEC) &&
+         floatValue <= maxForType &&
          floatValue >= 0
        )
      )
    }
  }

1217-1219: Minor: Additional attributes unrelated to PR objective.

The name, placeholder, and id attributes are standard form field improvements but weren't mentioned in the PR objectives. While these are acceptable additions, the placeholder text "Enter Amount" duplicates the label.

Consider removing the redundant placeholder or making it more specific:

  name="Amount"
- placeholder="Enter Amount"
+ placeholder={`0.00${STEP_AMOUNT[thisAddressType] === STEP_AMOUNT.BCH ? '000001' : ''}`}
  id="userEditedAmount"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a84e78b and cd4c9ad.

📒 Files selected for processing (1)
  • react/lib/components/Widget/Widget.tsx (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
react/lib/components/Widget/Widget.tsx (1)
react/lib/util/constants.ts (2)
  • MAX_AMOUNT (16-19)
  • STEP_AMOUNT (11-14)
⏰ 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). (1)
  • GitHub Check: Run build
🔇 Additional comments (2)
react/lib/components/Widget/Widget.tsx (2)

19-19: LGTM!

The imports for STEP_AMOUNT and MAX_AMOUNT are correctly added to support the maximum editable amount feature.

Also applies to: 28-28


1228-1239: LGTM! Button styling improvements.

The Confirm button styling has been refactored to use inline sx prop with theme values, improving maintainability. The visibility logic and functionality remain unchanged.

@chedieck chedieck merged commit 3ea46c6 into master Nov 28, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement (UI/UX/feature) New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restrict 'Edit Amount' input

3 participants