Skip to content

fix(amount): added bigInt and hideCurrency support in amount component#793

Open
Shreyag02 wants to merge 7 commits intomainfrom
fix/amount/bigInt-support
Open

fix(amount): added bigInt and hideCurrency support in amount component#793
Shreyag02 wants to merge 7 commits intomainfrom
fix/amount/bigInt-support

Conversation

@Shreyag02
Copy link
Copy Markdown
Contributor

@Shreyag02 Shreyag02 commented May 7, 2026

Description

Adds two capabilities to the Amount component:

  1. BigInt support. value now accepts bigint in addition to number | string. BigInt is treated as integer-only and always in major units, so valueInMinorUnits is ignored when value is a BigInt. This restores precision for amounts beyond Number.MAX_SAFE_INTEGER (≈ 9 × 10¹⁵) — the previous workaround was string-only, which is awkward for backends that already produce BigInt. Intl.NumberFormat.prototype.format() accepts BigInt natively, so the integration is direct.
  2. hideCurrency prop. A boolean that renders only the formatted number, with locale-driven separators, grouping, and currency-driven fraction digits intact. Useful for places where the currency is displayed elsewhere (column headers, line-item subtotals, token counters in the SDK tokens view). When hideCurrency is true, currencyDisplay is ignored.

Behavior contract documented in JSDoc on both source and docs props.ts.
Backwards compatible — hideCurrency defaults to false, the BigInt branch is purely additive, and the negative-string path was previously buggy (no test ever passed against it).

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update

How Has This Been Tested?

  • Unit tests: added 11 new cases covering BigInt (6), hideCurrency (4), and the negative-string regression (1). Full suite at 41/41 passing.
    • BigInt: defaults, valueInMinorUnits=false parity, precision beyond MAX_SAFE_INTEGER, negative BigInts, zero-decimal currency (JPY), no MAX_SAFE_INTEGER warning for BigInt.
    • hideCurrency: basic case, BigInt input, override of currencyDisplay, currency-driven decimals still respected.
    • Negative string: value="-1299" → -$12.99.
  • Type checks: zero TS diagnostics across all five files.
  • Manual trace: walked through edge-case combinations not directly tested — all produce correct output.
    <Amount  value="-1" /> (padStart-padded to -$0.01)
    <Amount value={0n} />
    <Amount value={1299n} currency='BHD' /> 
    
  • Docs preview: added hideCurrencyDemo and a BigInt entry in largeNumbersDemo. The console-warning demo value was bumped from 15 digits (which never tripped Math.abs > MAX_SAFE_INTEGER) to 17 digits, so the warning now actually fires when the section is rendered.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (.mdx files)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

Screenshots (if appropriate):

N/A

Related Issues

N/A

@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
apsara Ready Ready Preview, Comment May 8, 2026 8:58am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR extends the Amount component with two complementary features. First, it broadens the value prop to accept bigint in addition to number and string, treating bigint values as already in major units (ignoring valueInMinorUnits). Second, it introduces a hideCurrency prop that renders only the formatted numeric portion while preserving locale-specific grouping and decimal separators. The implementation refactors the value-handling logic into explicit type branches and reworks the NumberFormat options to dynamically choose between decimal and currency styles. Tests validate edge cases including very large bigint values, negative inputs, and interactions with zero-decimal currencies.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AmountComponent
  participant RuntimeProbe
  participant Intl as Intl.NumberFormat
  participant Console
  Client->>AmountComponent: render(value, {currency,...})
  AmountComponent->>RuntimeProbe: check SUPPORTS_INTL_STRING_PRECISION
  RuntimeProbe-->>AmountComponent: boolean
  AmountComponent->>Intl: create formatter & format/formatToParts
  Intl-->>AmountComponent: parts/string
  AmountComponent->>Client: return formatted numeric string (strip currency parts if hideCurrency)
  alt unsupported && large string
    AmountComponent->>Console: warn about precision loss
  end
Loading

Suggested reviewers

  • paanSinghCoder
  • rohilsurana
  • rohanchkrabrty
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: adding BigInt and hideCurrency support to the Amount component, plus the negative-string bug fix mentioned in the description.
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.
Description check ✅ Passed The pull request description clearly explains the two main features (BigInt support and hideCurrency prop), documents the behavior contract, explains backward compatibility, and details testing approach and edge cases covered.

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

Warning

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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
Copy Markdown
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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/raystack/components/amount/__tests__/amount.test.tsx`:
- Around line 251-271: The hideCurrency test suite only covers non-round
amounts; add tests that assert behavior for round amounts (e.g., render <Amount
value={1200} hideCurrency /> and expect "12.00") and for bigint round values
(e.g., value={1200n} hideCurrency expecting "1,200") to ensure fraction digits
are preserved, and duplicate the override and zero-decimal (JPY) cases with
round values (e.g., currencyDisplay='code' and currency='JPY' with value=1200)
so the suite catches the fraction-digit regression in the Amount component.

In `@packages/raystack/components/amount/amount.tsx`:
- Around line 223-234: The current formatOptions object (in Amount component)
leaves minimumFractionDigits/maximumFractionDigits undefined when hideCurrency
is true, causing decimal digits to be stripped for round values; update the
hideCurrency branch inside formatOptions so it sets style: 'decimal' and also
explicitly applies the currency-driven fraction digits (use
minimumFractionDigits and maximumFractionDigits or the computed decimals value
used elsewhere) so decimals are preserved when hideCurrency=true; adjust tests
for bigint expectations and add a new test case asserting round amounts (e.g.,
value=1200) still render the expected trailing zeros.
- Around line 239-240: The code calls Intl.NumberFormat.format(finalBaseValue)
with finalBaseValue as a string to preserve precision, but environments may not
support V3 string-precision; either ensure your supported browsers include V3
(update browserslist/README) or add a runtime feature-detection and fallback:
implement the suggested supportsStringFormat check (new
Intl.NumberFormat('und').format('11111111111111111112').indexOf('2') !== -1)
and, if false, convert finalBaseValue to a safe fallback (e.g.,
Number(finalBaseValue) or a BigInt-to-string grouping formatter) before calling
Intl.NumberFormat.format; update the code around the
Intl.NumberFormat.format(...) call in amount.tsx that uses finalBaseValue
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

Run ID: 9bb66c33-bcb5-4f9f-8b88-800f3a0c6b4e

📥 Commits

Reviewing files that changed from the base of the PR and between 3eba1bb and fe87575.

📒 Files selected for processing (5)
  • apps/www/src/content/docs/components/amount/demo.ts
  • apps/www/src/content/docs/components/amount/index.mdx
  • apps/www/src/content/docs/components/amount/props.ts
  • packages/raystack/components/amount/__tests__/amount.test.tsx
  • packages/raystack/components/amount/amount.tsx

Comment thread packages/raystack/components/amount/__tests__/amount.test.tsx
Comment thread packages/raystack/components/amount/amount.tsx
Comment thread packages/raystack/components/amount/amount.tsx Outdated
Copy link
Copy Markdown
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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/raystack/components/amount/amount.tsx`:
- Around line 252-257: The current computation of resolvedMinFrac and
resolvedMaxFrac in amount.tsx can produce an inverted range (min>max) when
hideCurrency is true and only one of minimumFractionDigits/maximumFractionDigits
is provided; update the logic in the resolvedMinFrac/resolvedMaxFrac assignments
(and the similar block at lines 259–270) to clamp the missing bound against the
provided one: if minimumFractionDigits is undefined but maximumFractionDigits is
defined, set resolvedMinFrac = Math.min(defaultDecimals, resolvedMaxFrac); if
maximumFractionDigits is undefined but minimumFractionDigits is defined, set
resolvedMaxFrac = Math.max(defaultDecimals, resolvedMinFrac); ensure both
resolvedMinFrac and resolvedMaxFrac are numbers and that resolvedMinFrac <=
resolvedMaxFrac before passing to Intl.NumberFormat to avoid RangeError.
🪄 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

Run ID: 1777c7bb-4738-4365-a282-93a7e065ef31

📥 Commits

Reviewing files that changed from the base of the PR and between fe87575 and 4bd4039.

📒 Files selected for processing (2)
  • packages/raystack/components/amount/__tests__/amount.test.tsx
  • packages/raystack/components/amount/amount.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/raystack/components/amount/tests/amount.test.tsx

Comment thread packages/raystack/components/amount/amount.tsx Outdated
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