feat: add cents support to money widget#1756
Conversation
Adds opt-in `cents: true` widget_param so the money widget can render and edit values stored as Stripe-style integer minor units. Zero-decimal currencies (JPY, KRW, VND, ...) bypass division per Stripe convention. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
There was a problem hiding this comment.
Pull request overview
Adds opt-in cents: true handling for money widgets so they can display and edit integer minor-unit values, extending the existing money widget flow across table display, record view, and record edit components.
Changes:
- Added shared helpers for zero-decimal currencies and minor-unit conversion in
currencies.ts. - Updated money display/view components to format minor-unit values when
widget_params.centsis enabled. - Updated the money edit component and tests to load/save minor units and documented the new widget param.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
frontend/src/app/consts/currencies.ts |
Adds zero-decimal currency metadata and conversion helpers used by money widgets. |
frontend/src/app/components/ui-components/table-display-fields/money/money.component.ts |
Applies minor-unit formatting in table money display. |
frontend/src/app/components/ui-components/table-display-fields/money/money.component.spec.ts |
Adds table-display tests for cents and zero-decimal behavior. |
frontend/src/app/components/ui-components/record-view-fields/money/money.component.ts |
Applies minor-unit formatting in record-view money display. |
frontend/src/app/components/ui-components/record-view-fields/money/money.component.spec.ts |
Adds record-view tests for cents behavior. |
frontend/src/app/components/ui-components/record-edit-fields/money/money.component.ts |
Adds minor-unit load/save logic and currency-aware decimal handling in the editor. |
frontend/src/app/components/ui-components/record-edit-fields/money/money.component.spec.ts |
Adds editor tests for loading, saving, rounding, and currency switching with cents. |
frontend/src/app/components/dashboard/db-table-view/db-table-widgets/db-table-widgets.component.ts |
Documents the new cents widget parameter in widget configuration help text. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (this.amount !== '' && this.amount !== null && this.amount !== undefined) { | ||
| const numericAmount = typeof this.amount === 'string' ? parseFloat(this.amount) : this.amount; | ||
| if (!Number.isNaN(numericAmount)) { | ||
| const rounded = parseFloat(numericAmount.toFixed(this.decimalPlaces)); | ||
| this.amount = rounded; | ||
| this.displayAmount = this.formatAmount(rounded); | ||
| } | ||
| } |
| const cleanNumber = numberMatch[1].replace(/,/g, ''); | ||
| this.amount = parseFloat(cleanNumber) || ''; | ||
| const parsed = parseFloat(cleanNumber); | ||
| this.amount = Number.isNaN(parsed) ? '' : this._fromMinorUnits(parsed); |
| export function isZeroDecimalCurrency(code: string): boolean { | ||
| return ZERO_DECIMAL_CURRENCIES.has(code); | ||
| } | ||
|
|
||
| export function getCurrencyDecimalPlaces(code: string): number { | ||
| return isZeroDecimalCurrency(code) ? 0 : 2; | ||
| } | ||
|
|
||
| export function getCurrencyMinorUnitFactor(code: string): number { | ||
| return isZeroDecimalCurrency(code) ? 1 : 100; |
Adds opt-in
cents: truewidget_param so the money widget can render and edit values stored as Stripe-style integer minor units. Zero-decimal currencies (JPY, KRW, VND, ...) bypass division per Stripe convention.