Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/mobility-core/src/Kernel/Types/Price.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ instance ToJSON PriceAPIEntity where
]

roundAmountByCurrency :: Currency -> HighPrecMoney -> HighPrecMoney
roundAmountByCurrency EUR amount = roundHighPrecMoney @HighPrecMoney (getAccuracy EUR) amount
roundAmountByCurrency _ amount = amount -- for backward compatibility
roundAmountByCurrency currency amount = roundHighPrecMoney @HighPrecMoney (getAccuracy currency) amount
Comment on lines 174 to +175
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find all usages of roundAmountByCurrency and PriceAPIEntity to assess blast radius.
rg -nP -C3 '\broundAmountByCurrency\b'
echo '----'
rg -nP -C2 '\bPriceAPIEntity\b' --type=hs
echo '----'
# Look for tests/snapshots that may pin amount formatting for INR/USD.
rg -nP -C2 '"amount"\s*[:=]' --type=hs -g '!**/dist*/**'
echo '----'
# Any explicit references to mkPriceFromAPIEntity (potential lossy round-trip).
rg -nP -C3 '\bmkPriceFromAPIEntity\b'

Repository: nammayatri/shared-kernel

Length of output: 3747


INR amounts will lose sub-unit precision in PriceAPIEntity JSON serialization.

roundAmountByCurrency now rounds all currency amounts using getAccuracy: INR=0 (whole rupees), USD=2, EUR=2. This affects the ToJSON PriceAPIEntity instance at line 170, which serializes every PriceAPIEntity.amount rounded.

For INR, this is a breaking change: any API consumer expecting fractional rupee amounts (paise) will now receive whole rupees, with sub-unit precision silently lost via rounding.

Verify:

  • Is this rounding intentional for the API contract, or should PriceAPIEntity JSON preserve full precision while using getAccuracy only for display formatting elsewhere?
  • Are there snapshot tests or integration tests that validate API response precision for INR/USD?
  • If intentional, add a release note explaining the precision change for INR consumers.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/mobility-core/src/Kernel/Types/Price.hs` around lines 174 - 175, The
ToJSON instance for PriceAPIEntity is currently using roundAmountByCurrency
(which applies getAccuracy and makes INR accuracy 0), causing INR amounts to
lose paise; change the ToJSON PriceAPIEntity implementation to serialize
PriceAPIEntity.amount using the raw HighPrecMoney value (or a new
identity-preserving serializer) instead of calling roundAmountByCurrency, and
move rounding logic into a separate display formatter (e.g., roundForDisplay or
formatAmountForCurrency) used only by UI/display paths; ensure references to
roundAmountByCurrency, getAccuracy, PriceAPIEntity.amount and the ToJSON
PriceAPIEntity instance are updated, add/adjust unit or integration tests to
assert full precision is preserved for INR/USD serialization, and if the
rounding change is intentional, add a release note documenting the precision
break for INR consumers.


mkPriceAPIEntity :: Price -> PriceAPIEntity
mkPriceAPIEntity Price {..} = PriceAPIEntity {..}
Expand Down
Loading