Skip to content

JMD Currency Precision — Full-Stack Fix #282

Open
4 of 4 issues completed
Open

Description

@islandbitcoin

Background

Flash is a Bitcoin banking platform for Jamaica. Users who have set JMD as their display currency are seeing incorrect amounts across three critical surfaces: their wallet balance, the send/receive flows, and their transaction history. These are not cosmetic issues — users are losing money on precision truncation and seeing a transaction history that changes every time the BTC price moves.

The bugs span the full stack. The backend serves stale/wrong data from its transaction adaptor layer, and the mobile app compounds the problem with its own conversion errors. Both must be fixed for JMD amounts to be trustworthy end-to-end.


Scope

This bounty covers all three affected surfaces:

Wallet Balance

The BTC wallet balance query (me.btcWallet.balance) currently returns a serialized class object ({}) instead of a number, because BtcWallet.balance serializes the WalletBalance class instance rather than its numeric value.

File: src/graphql/shared/types/object/btc-wallet.ts (~line 49)
Fix: Return Number(balance.asCents(8)) — the raw satoshi count as a number.

Send & Receive Flows

When a JMD user enters an amount (e.g., JMD$1,000) to create a Lightning invoice or send a payment via the USD wallet, the conversion from JMD to USD cents produces a JavaScript float (e.g., 625.78...). This float is sent directly to the GraphQL API, which expects an integer. The API truncates (e.g., to 625), and the user receives or sends a slightly different amount than intended — consistently losing a small amount to rounding error on every transaction.

Root cause: convertMoneyAmount() in use-price-conversion.ts only calls Math.round() when the target currency is BTC. USD conversions are left as floats.

Files:
app/hooks/use-price-conversion.ts (lines 74–81) — missing Math.round() for USD target
app/screens/receive-bitcoin-screen/payment/payment-request.ts (lines 155–167) — float passed to lnUsdInvoiceCreate
app/screens/send-bitcoin-screen/payment-details/intraledger.ts (lines 58–78) — float passed to intraLedgerUsdPaymentSend

Fix: Apply Math.round() to all currency conversion results, not just BTC. Additionally, add a defensive Math.round() at the API mutation call sites so the fix survives future refactoring.

Backend dependency: The backend price service (src/services/price/index.ts) currently derives the JMD/USD rate by triangulating through BTC rather than using the static ExchangeRates.jmd.sell value from config/yaml.ts. This compounds the mobile rounding error because the exchange rate itself is imprecise. The price service fix (see item 3 below) must land before mobile amounts can be validated as correct.

Transaction History

Transaction history is broken at two layers:

Backend layer (lnflash/flash repo):
The transaction history adaptor (src/app/wallets/get-transactions-for-wallet.ts) has four compounding bugs:
Hardcodes displayCurrency: "USD" regardless of the user's actual display currency
Uses the wrong exponent offset when converting the price, producing amounts off by a large factor
Calls Math.floor() on the price, which truncates sub-dollar JMD prices to 0
Does not apply the JMD/USD conversion — JMD users receive USD amounts from the API

Additionally, the price service derives JMD rate via BTC triangulation (src/services/price/index.ts) — it should use the static ExchangeRates.jmd.sell value from config/yaml.ts directly.

Files:
src/app/wallets/get-transactions-for-wallet.ts — fix displayCurrency, offset, Math.floor, and JMD conversion
src/services/price/index.ts — use ExchangeRates.jmd.sell instead of BTC triangulation

Mobile layer (lnflash/flash-mobile repo):
The TxItem component ignores the settlementDisplayAmount field already returned by the API (which contains the correct historical JMD amount locked in at settlement time) and instead re-computes the JMD amount using the current BTC price. This means every BTC transaction in history shows a different JMD amount each time the price moves. The transaction detail screen already does this correctly (using settlementDisplayAmount) — the list should match it.

Additionally, for USD wallet transactions, TxItem multiplies settlementAmount by 100 (tx.settlementAmount * 100), but settlementAmount is already in cents. This inflates all USD wallet transaction amounts by 100×.

For BTC wallet transactions from the Breez SDK, useBreezPayments.ts hardcodes settlementDisplayCurrency: "USD" and converts to USD, ignoring the user's JMD preference entirely.

Files:
app/components/transaction-item/TxItem.tsx (lines 42–60) — use settlementDisplayAmount / settlementDisplayCurrency instead of live price reconversion
app/components/transaction-item/TxItem.tsx (line 55) — remove * 100 for USD wallet amounts
app/hooks/useBreezPayments.ts (lines 13–18, 46–48) — use DisplayCurrency target and user's currency code, not hardcoded USD


Sub-issues

Sub-issues

4 of 4 Issues completed
Loading 4 sub-issues

Activity

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

    @linear
  3. changed the title [-][Bug] Systemic JMD currency precision failures across price pipeline, transaction history, and balance resolver[/-] [+][Bug] Fix Systemic display currency precision failures[/+] on Feb 23, 2026
  4. islandbitcoin commented on Feb 23, 2026

    @islandbitcoin
    ContributorAuthor

    src/app/wallets/get-transactions-for-wallet.ts, lines ~37-50.

    That's the adaptor that converts Ibex API responses into the domain transaction format. Four separate bugs in one spot:

    • Line ~41: offset: 0n (should be SAT_PRICE_PRECISION_OFFSET of 12 or USD_PRICE_PRECISION_OFFSET of 6)
    • Line ~43: displayCurrency: "USD" hardcoded (ignores user's JMD setting)
    • Line ~39: Math.floor(trx.exchangeRateCurrencySats) truncates per-sat prices like 0.00000007 to 0
    • Lines ~47-48: settlementDisplayAmount and settlementDisplayFee pass through raw Ibex USD strings, never converted to JMD
  5. deleted a comment from islandbitcoin on Feb 23, 2026
  6. deleted a comment from islandbitcoin on Feb 23, 2026
  7. changed the title [-][Bug] Fix Systemic display currency precision failures[/-] [+][Bug] JMD Currency Precision — Backend[/+] on Feb 23, 2026
  8. forge0x commented on Feb 26, 2026

    @forge0x
    Contributor

    ✅ Backend bugs confirmed via production testing + code review

    Cross-referencing flash-mobile#555 evidence:

    Confirmed via production testing:

    • Bug 5 (tx adaptor): displayCurrency: "USD" hardcoded, offset: 0n, Math.floor truncation, raw USD settlementDisplayAmount — all confirmed. JMD users see "Sent USD" labels and $8.01 in tx detail instead of ~J$1,240. Video evidence
    • Bug 6 (JMD/USD via BTC triangulation): Rate difference observed at ~0.08% — within BTC price noise, but the code path through two 32-bit float divisions is confirmed in src/services/price/index.ts lines 58-64.

    Confirmed via code review:

    • Bug 4 (BtcWallet.balance): Returns raw USDAmount object instead of Number(balance.asCents(8)). BTC wallet enabled on test account — shows ₿0, masking the bug. Would fail on any non-zero balance.
    • Bug 8 (protobuf float): price.proto line 5 uses float (32-bit), limiting JMD prices to ~7 significant digits.
    • Bug 9 (toFixed(2)): MoneyAmount.ts truncates Ibex's 8-decimal precision to 2 decimal places.
    • Bug 10 (sendAll): onchain-payment-send-all.ts sends full balance without subtracting miner fee — confirmed in code, not tested (requires on-chain BTC).

    Dropped:

    • Bug 3 (100× inflation): TxItem.tsx * 100 path only runs for non-BTC settlements. Lightning settles in BTC, so this code path is never hit with current wallet types. Removed from scope.
  9. forge0x commented on Feb 26, 2026

    @forge0x
    Contributor

    Bug 4 — BtcWallet.balance returns {} (code trace)

    Severity: Medium — backend only, mobile app uses Breez SDK locally

    Code Trace

    1. src/services/ibex/client.ts:26 — Ibex balance is wrapped in USDAmount domain class:

      balance = r.balance !== undefined ? USDAmount.dollars(r.balance.toString()) : undefined
    2. src/app/wallets/get-balance-for-wallet.ts:19 — Returns the USDAmount object directly:

      return resp.balance  // ← USDAmount class instance, not a number
    3. src/graphql/shared/types/object/btc-wallet.ts:53 — GraphQL resolver returns it as FractionalCentAmount:

      resolve: async (source) => {
        const balanceSats = await Wallets.getBalanceForWallet({ walletId: source.id })
        // balanceSats is a USDAmount object, not a number
        return balanceSats  // ← serializes as {} because USDAmount has no toJSON()
      }

    Fix

    Add numeric extraction: return Number(balanceSats.asCents()) (or equivalent). The USDAmount class needs either a toJSON() method or the resolver must extract the numeric value before returning.

    Mobile Impact

    None — the mobile app uses BreezContext.tsx:83 (walletInfo.balanceSat from Breez SDK) for BTC balance display, bypassing this GraphQL resolver entirely. Only direct API consumers (web apps, third-party integrations) are affected.

  10. 27 remaining items

  11. deleted a comment from on Apr 18, 2026
  12. onchito-walks commented on May 12, 2026

    @onchito-walks

    PR submitted: #350

    This fixes all three precision bugs described in this issue:

    • Float settlement amounts now rounded before casting
    • Display price bias corrected (Math.round replaces Math.floor)
    • JMD rate now sourced directly from ExchangeRates.jmd.sell

    10/10 tests passing. Happy to answer any questions or revise.

    Payout address: 1Ast5dKr9z1bLWFBnyh6WDQSgyL7EHJosp

    Please let me know if anything needs adjustment.

  13. zhaog100 commented on May 20, 2026

    @zhaog100

    🙋 Claiming this bounty. I'll start work within 24-48h.

  14. onchito-walks commented on May 21, 2026

    @onchito-walks

    Lightning address for bounty payment on merge: [email protected]

  15. changed the title [-][Bounty] JMD Currency Precision — Full-Stack Fix[/-] [+]JMD Currency Precision — Full-Stack Fix[/+] on May 22, 2026
  16. islandbitcoin commented on Jun 18, 2026

    @islandbitcoin
    ContributorAuthor

    2026-06-18 — Reframe after the USDT Cash Wallet migration

    The custodial Cash Wallet migrated from IBEX USD → USDT. IBEX now returns Cash Wallet amounts as native integer micro-USDT (USD-pegged), so the Cash Wallet display path no longer routes through BTC price / satoshis. For Cash Wallet rows the precision risk collapses to integer/USD handling + at most one USD→JMD conversion — the BTC price-point mapping, Math.floor sat-truncation, and BTC round-trip drift no longer apply to it.

    The BTC wallet (Breez, self-custodial) stays fiat-displayed (TxItem primary = moneyAmountToDisplayCurrencyString, sats secondary; wallet-overview keeps btcDisplayBalance). Showing BTC amounts in sats-only was considered and deemed too large a change for now, so the BTC↔fiat conversion — and its precision work — stays.

    Net: nothing in this cluster is obsolete. Scope split:

    • Cash Wallet (IBEX adaptor, USD/USDT): ENG-408 (normalize unit → cents), ENG-137 (display-currency + USD→JMD; BTC sub-bugs drop).
    • BTC↔fiat (Breez, app-wide): round-all-conversions + price.proto float→double + RoundingPolicy — still required.
  17. islandbitcoin commented on Oct 10, 2026

    @islandbitcoin
    ContributorAuthor

    Bounty cancelled (2026-10-10). The bounty program is closed and the reward attached to this issue is withdrawn. No bounty will be paid for work on it. The issue itself stays open as a regular work item and has been re-prioritized by the core team. Thanks to everyone who proposed an approach.

  18. islandbitcoin commented on Oct 10, 2026

    @islandbitcoin
    ContributorAuthor

    Priority pass 2026-10-10: rank 8 of 13, kept as the tracker only. After the USDT migration the remaining items are: #284 (adaptor display currency), lnflash/flash-mobile#547 (history converts at today's price), and BTC-wallet balance serialization at btc-wallet.ts:65. Everything else in the body is obsolete.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Mediumcurrency precisioncustomer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions