Skip to content

feat: add BRL (R$) currency support - #49

Open
smllb wants to merge 1 commit into
clucraft:mainfrom
smllb:feat/brl-currency-support
Open

feat: add BRL (R$) currency support#49
smllb wants to merge 1 commit into
clucraft:mainfrom
smllb:feat/brl-currency-support

Conversation

@smllb

@smllb smllb commented Sep 10, 2026

Copy link
Copy Markdown

feat: add Brazilian Real (R$) currency support

Summary

Adds detection, storage, and display of Brazilian Real (R$) prices. Previously
any non-mapped currency symbol fell through to the generic $ pattern and was
recorded as USD, which was wrong for stores like amazon.com.br.

What changed

Backend

  • backend/src/utils/priceParser.ts

    • Add R$ / BRL to currencyMap and a dedicated regex pattern placed
      before the generic $ one (so R$ isn't swallowed by the dollar match).
    • The new pattern handles the Brazilian numeric format 1.234,56 (dot
      thousands separator, comma decimal) as well as the short form 284,90.
    • Include R$ in extractPricesFromText so it's considered when scanning
      raw HTML.
  • backend/src/routes/products.ts

    • The confirm-price path previously hardcoded 'USD' when recording the
      initial price history entry. It now records the currency of the candidate
      the user actually selected (selectedCurrency), falling back to the
      detected price currency and finally 'USD'.

Frontend

  • frontend/src/utils/formatPrice.ts (new)

    • Shared formatPrice() helper using Intl.NumberFormat, so any currency
      (including BRL) formats correctly and is locale-aware.
  • PriceChart.tsx, ProductCard.tsx, PriceSelectionModal.tsx,
    ProductDetail.tsx

    • Replaced the hardcoded € / £ / CHF / $ symbol map with the shared
      formatter. BRL now renders as R$ 284,90 instead of $284.90.
  • PriceSelectionModal.tsx, Dashboard.tsx, api/client.ts

    • Thread the selected candidate's currency through to the backend so the
      recorded currency matches what the user picked.

Why

The existing parser mapped a fixed set of symbols and fell back to $/USD
for everything else. That made tracked BRL prices display and store as USD.
This change is additive: all previously supported currencies behave exactly as
before, and BRL (plus any other Intl.NumberFormat-supported currency) now
works correctly.

Testing

  • Verified parsePrice against R$284,90, R$5.256,36, R$1.299,00,
    R$499,90, and $29.99 (BRL cases parse to correct values + BRL,
    USD unaffected).
  • tsc typecheck and production builds pass for both backend and
    frontend.
  • End-to-end: adding an amazon.com.br product records history as BRL and
    the UI shows R$ formatting in the modal, cards, and price chart.

Detect and display Brazilian Real prices:
- priceParser: recognize R$/BRL incl. the 1.234,56 format
- products: record the selected candidate's currency instead of
  hardcoded USD, falling back to the detected price currency
- frontend: shared Intl.NumberFormat price formatter replacing the
  hardcoded EUR/GBP/CHF/$ symbol map
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