fix(pricing): make price and currency formatting more robust#374
Conversation
|
@Atharvsinh-codez is attempting to deploy a commit to the Dodo Payments Team on Vercel. A member of the Team first needs to authorize it. |
|
@tsahil01 Can you please merge it, After reviewing, thanks. |
|
@dodo-squirrels review |
Code ReviewThe overall direction of this PR is good — centralizing price parsing and formatting logic into a shared module eliminates copy-paste bugs and makes "Custom" price handling consistent. Here are the issues I found that need to be addressed before merging: Bug: Double currency symbol in
|
016870f to
12f50d5
Compare
A bunch of components were doing their own ad-hoc parsing for prices (which are strings to allow 'Custom' etc). Some had basic guards, proration had nicer regex stripping after a previous review, but it wasn't shared. This adds a small shared utils/price-utils.ts (modeled after the existing card-validation one) with: - safe parsePrice that handles junk input - isCustomPrice - formatPrice that prefers proper Intl when you give it a real currency code like 'USD' - calculateDiscount that reuses the above - a couple helpers for the 'show prefix or raw' cases Then wired it into the main pricing tables, the update plan stuff, proration preview, and usage table (which was always hardcoding $ before). Also registered the util so it comes along when people install the components via the CLI or shadcn. Should make weird plan data from APIs or configs less likely to blow up the UI, and currency display more correct for non-USD stuff. Tested typecheck and lint clean (build has a pre-existing tailwind issue in global.css unrelated to this).
12f50d5 to
101bc00
Compare
|
Thanks for the review. I pushed an update that addresses the points you called out:
Local checks: |
Code ReviewThe refactor to centralize price formatting in The previous review's blockers have been addressed:
One typographic regression to fix before merging: Em dash replaced with double hyphen in
|
Summary
src/utils/price-utils.ts, then registered that helper in the affected registry entries so installed components get the same code.pricing-table-onerendering the currency twice after switching to shared formatting.proration-previewto format full amounts directly instead of extracting a currency symbol from a dummy formatted value.$0.00.usage-tableformat costs with either a symbol or an ISO currency code.Review updates
getParsedPriceandshouldShowCurrencyPrefixexports.currency-codesimport from the shared price helper; ISO currency codes now useIntl.NumberFormatdirectly.public/r/*.jsonfiles and registry manifests.Test plan
npm run typechecknpm run lint(passes with the existing.source/dynamic.tsunused variable warning)npm run build:shadcn