Skip to content

[Bug] JMD currency precision loss — users lose up to J$1.10 per transaction due to float truncation in convertMoneyAmount() #555

Closed

Description

@islandbitcoin

Unified tracking issue for JMD currency precision failures (Mobile)

GitHub Issue: #555

14 distinct bugs across backend + mobile. This issue tracks the mobile fixes.

Supersedes: ENG-81, ENG-87

Depends on: ENG-132 (backend fixes must land first for Wave 1)

PR Review: Nick must approve before merge. Dread (islandbitcoin) final sign-off.

Activity

  1. added
    bug
    on Feb 22, 2026
  2. linear commented on Feb 22, 2026

    @linear
  3. islandbitcoin commented on Feb 22, 2026

    @islandbitcoin
    ContributorAuthor

    Companion backend issue: lnflash/flash#282

  4. forge0x commented on Feb 26, 2026

    @forge0x
    Contributor

    🐛 Bug 1 Reproduced: convertMoneyAmount() Float Precision Loss

    📹 Video Evidence

    Side-by-side production recording (iOS sender + Android receiver)

    Setup

    • Sender: forgetest1 (iOS sim, JMD wallet)
    • Receiver: forgetest2 (Android emu, JMD display)
    • Tested on: Test env + Production

    Results

    Test Sender Receiver Lost
    Test 1 (test env, J$7) -J$7.00 / -₿67 J$6.99 / ₿67 J$0.01
    Test 2 (prod, J$1,234.56) -J$1,234.56 / -₿11,811 J$1,233.85 / ₿11,805 J$0.71 + 6 sats
    Test 3 (prod, J$1,234.56) -J$1,234.56 / -₿11,812 J$1,233.46 / ₿11,797 J$1.10 + 15 sats

    Root Cause

    convertMoneyAmount() in app/hooks/use-price-conversion.ts (lines 74-81) only applies Math.round() for BTC amounts, not for USD/DisplayCurrency. When sats are reconverted to JMD, fractional results get truncated instead of rounded.

    Additional Findings

    • Balance proof: After multiple J$7 sends, receiver balance was J$24.99 instead of expected J$25.00
    • Bug 2 also confirmed: Transaction list reconverts amounts at current price, masking historical discrepancies — only the balance reveals the precision leak
    • Worst case observed: J$1.10 lost on a single J$1,234.56 transaction (0.09%)
    • The bug is rate-timing dependent — manifests whenever sats↔JMD conversion produces a fractional result

    Fix

    Add Math.round() to the fiat conversion path in convertMoneyAmount(), matching the existing BTC path.

  5. changed the title [-][Bug] Systemic JMD currency precision failures — float amounts, wrong tx history, 100× inflation, hardcoded USD[/-] [+][Bug] JMD currency precision loss — users lose up to J$1.10 per transaction due to float truncation in convertMoneyAmount()[/+] on Feb 26, 2026
  6. forge0x commented on Feb 26, 2026

    @forge0x
    Contributor

    🐛 Bug 2 Reproduced: Transaction detail screen ignores display currency

    📹 Video Evidence

    Transaction list → detail discrepancy (Android, JMD user)

    The Bug

    A JMD user sees two completely different amounts for the same transaction:

    View Amount Currency
    Transaction list J$1,240.08 JMD (user display currency)
    Transaction detail $8.01 USD (raw settlement amount)

    The user taps a J$1,240 transaction and sees $8.01 — no explanation, no JMD equivalent shown.

    Root Cause

    Two issues in app/components/transaction-item/TxItem.tsx (lines 54-65):

    1. List view reconverts at current BTC price via moneyAmountToDisplayCurrencyString() instead of using tx.settlementDisplayAmount (the historical display amount set at settlement time)
    2. Detail screen (transaction-detail-screen.tsx) shows raw settlementAmount in USD without converting to the user's display currency

    Impact

    • JMD users see inconsistent amounts between list and detail views
    • List amounts drift over time as BTC price changes — a J$1,234 transaction today might show as J$1,250 tomorrow
    • Detail screen shows USD with no JMD context, confusing for Jamaican users

    Fix

    • TxItem.tsx: Use tx.settlementDisplayAmount + tx.settlementDisplayCurrency for the primary amount instead of reconverting via current price
    • transaction-detail-screen.tsx: Convert header amount to user's display currency
  7. forge0x commented on Feb 26, 2026

    @forge0x
    Contributor

    🐛 Bug 5 Reproduced: Transaction labels say "USD" + detail screen shows raw USD for JMD users

    📹 Video Evidence

    Side-by-side iOS + Android recording

    The Bug (3 issues in one)

    5a. Wrong transaction labels: All transactions labeled "Sent USD" / "Received USD" even though the user's display currency is JMD. Should say "Sent" or "Sent JMD".

    5b. Detail screen shows raw USD: Tapping a transaction that shows J$1,237 in the list opens a detail view showing $8.01 USD — the raw Ibex settlement amount with zero JMD context. Completely confusing for Jamaican users.

    5c. List amounts reconvert at current BTC price: The tx list shows J$1,237.09 now, but the original send was J$1,234.56. The amount drifts as BTC/JMD price changes because TxItem.tsx reconverts sats → JMD at the current rate instead of using the historical settlementDisplayAmount.

    Root Cause

    Backend (get-transactions-for-wallet.ts lines ~37-50):

    • displayCurrency: "USD" hardcoded — backend stamps every tx as USD regardless of user setting
    • offset: 0n — price scaling completely broken (should be SAT_PRICE_PRECISION_OFFSET = 12)
    • Math.floor(trx.exchangeRateCurrencySats) — truncates fractional sat prices to 0
    • settlementDisplayAmount: \${trx.amount}`` — raw Ibex USD amount, never converted to JMD

    Mobile (TxItem.tsx lines 54-65):

    • Reconverts at current BTC price via moneyAmountToDisplayCurrencyString() instead of using tx.settlementDisplayAmount

    Mobile (transaction-detail-screen.tsx):

    • Shows raw settlementAmount in USD without converting to user's display currency

    Fix

    • Backend: Pass account displayCurrency into the adaptor, use correct offset, use Math.round not Math.floor, convert settlementDisplayAmount to user's currency
    • Mobile TxItem: Use tx.settlementDisplayAmount + tx.settlementDisplayCurrency for primary amount
    • Mobile detail screen: Convert header amount to user's display currency
  8. forge0x commented on Feb 26, 2026

    @forge0x
    Contributor

    🔍 Bug 4 & Bug 7: Confirmed via code review (not visually reproducible with test setup)

    Bug 4: BtcWallet.balance returns object instead of number

    File: src/graphql/shared/types/object/btc-wallet.ts line 53

    // BtcWallet — BROKEN: returns USDAmount class instance
    return balanceSats  // ← raw object, serializes as {} in GraphQL
    
    // UsdWallet — CORRECT: extracts numeric value
    return Number(balance.asCents(8))

    BTC wallet enabled on forgetest1 (iOS) — shows ₿0, which masks the bug since {} and 0 both display as zero. Would need a funded BTC wallet to demonstrate. The FractionalCentAmount scalar has no serialize method, so a non-zero USDAmount object would serialize as {} or throw.

    Bug 7: Breez SDK hardcodes USD display currency

    File: app/hooks/useBreezPayments.ts line 48

    settlementDisplayCurrency: "USD",  // ← hardcoded, ignores user display currency

    All Breez-settled transactions (non-custodial Lightning via BTC wallet) will show USD regardless of user's JMD setting. Cannot reproduce without funding the BTC wallet and making a Breez payment.

    Status

    Both bugs are confirmed in code but require funded BTC wallets / Breez transactions to demonstrate visually. The fix for both is straightforward:

    • Bug 4: return Number(balanceSats.asCents(8)) (match UsdWallet pattern)
    • Bug 7: Use displayCurrency from user's account settings instead of hardcoded "USD"
  9. forge0x commented on Feb 26, 2026

    @forge0x
    Contributor

    Bug 7 — Breez SDK transactions show USD instead of JMD (video evidence)

    Video: bug7-ios.mp4

    What the video shows

    1. Home screen: JMD user (forgetest1), Bitcoin balance ₿4,766 sats, recent swap tx shows ~J$501 JMD ✅
    2. Tap swap transaction → detail screen shows $3.21 USD ❌
    3. The same transaction displays as JMD on the home screen but USD in the detail view

    Root cause

    useBreezPayments.ts line 48 hardcodes:

    settlementDisplayCurrency: "USD"

    Should use the user's display currency preference instead.

    Expected behavior

    Transaction detail should show ~J$500 JMD (matching the home screen display), not $3.21 USD.

  10. self-assigned this
    on Mar 2, 2026
  11. added theissue type on Mar 2, 2026
  12. forge0x commented on Apr 17, 2026

    @forge0x
    Contributor

    closing as a duplicate/overlap of #547. consolidating jmd precision and currency-conversion work into the parent tracker there so the bug is tracked in one place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BlockedHighWaiting on backendbug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions