utils/enh/roundAmountByCurrency#1240
Conversation
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/mobility-core/src/Kernel/Types/Price.hs`:
- Around line 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.
🪄 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: 0aef8d13-85f5-40fe-bed8-7b83ed1ffc9a
📒 Files selected for processing (1)
lib/mobility-core/src/Kernel/Types/Price.hs
| 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 |
There was a problem hiding this comment.
🧩 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
PriceAPIEntityJSON preserve full precision while usinggetAccuracyonly 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.
Summary by CodeRabbit