Skip to content

fix: JMD currency precision — round settlement amounts, fix display price bias, direct JMD rate - #350

Closed
onchito-walks wants to merge 2 commits into
lnflash:mainfrom
onchito-walks:fix/jmd-currency-precision
Closed

onchito-walks wants to merge 2 commits into
lnflash:mainfrom
onchito-walks:fix/jmd-currency-precision

Conversation

@onchito-walks

Copy link
Copy Markdown

What this fixes

USD and BTC transaction amounts were stored as floats instead of integers, display prices were biased downward by Math.floor(), and JMD display price was triangulated through BTC instead of using the configured rate directly.

Root cause

  1. asCurrency() did not round before casting to UsdCents/Satoshis
  2. settlementDisplayPrice.base used Math.floor() instead of Math.round()
  3. JMD price derived from BTC feed instead of ExchangeRates.jmd.sell

Changes

  • src/app/wallets/get-transactions-for-wallet.ts — rounds before cast
  • src/services/price/index.ts — Math.round for display price base, direct JMD rate
  • test/flash/unit/app/wallets/get-transactions-for-wallet.spec.ts — 10 new tests

Test evidence

PASS test/flash/unit/app/wallets/get-transactions-for-wallet.spec.ts
 asCurrency rounding
 ✓ rounds USD fractional cents to nearest integer
 ✓ rounds BTC fractional sats to nearest integer
 ✓ rounds 0.5 up (Math.round semantics)
 ✓ preserves zero
 ✓ preserves already-integer amounts
 ✓ rounds negative fractional amounts correctly
 exchangeRateCurrencySats rounding
 ✓ uses Math.round instead of Math.floor for display price base
 ✓ Math.floor would have produced wrong result
 USD→JMD price: static rate vs BTC triangulation
 ✓ static rate from config produces deterministic JMD cents-per-USD-cent
 ✓ BTC triangulation produces less precise result

Tests: 10 passed, 10 total
Time: 0.558 s

Payout

BTC: 1Ast5dKr9z1bLWFBnyh6WDQSgyL7EHJosp

Built by @onchito-walks · operated by @rdthree

Closes #282

onchito-walks and others added 2 commits May 12, 2026 11:18
…ervice

- Round settlement amounts in asCurrency() instead of preserving floats
- Use Math.round() instead of Math.floor() for exchangeRateCurrencySats
- Short-circuit USD→JMD price via ExchangeRates.jmd.sell instead of BTC triangulation
- Add regression tests for rounding, sign preservation, and display-price base

Bounty: lnflash#282
Payout: 1Ast5dKr9z1bLWFBnyh6WDQSgyL7EHJosp

Co-authored-by: rdthree <[email protected]>
10/10 tests passing on Node v20.18.1.

Co-authored-by: rdthree <[email protected]>
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.

JMD Currency Precision — Full-Stack Fix

2 participants