Skip to content

[Bug] Transaction history adaptor shows wrong settlement display price for JMD users #284

Open

Description

@islandbitcoin

Summary

The transaction history adaptor (src/app/wallets/get-transactions-for-wallet.ts) serves incorrect display amounts for JMD users. Since Ibex IS the ledger and Flash has no server-side ledger for Ibex-settled transactions, this adaptor is the only place to fix display amounts — if it's wrong, every historical transaction displays wrong, retroactively.

The Bugs

1. Hardcoded USD instead of user display currency

The adaptor returns USD as the display currency and does not convert the settlement amount to the user's configured currency (JMD). This means both the currency label and the numeric value are wrong — JMD users see raw USD amounts labeled as their display currency. One fix: pass the user's display currency into the adaptor and apply the conversion.

2. Wrong offset in pagination/conversion

An offset error causes transactions to map to incorrect price points, shifting which rate gets applied to which transaction.

3. Math.floor truncates fractional amounts

Math.floor on converted amounts silently drops fractional JMD cents. For small BTC transactions, this can truncate the display amount to 0.

Why This Matters

  • Flash has no server-side ledger for Ibex-settled transactions — Ibex is the ledger
  • Transaction history is fetched live from the Ibex API every time
  • This adaptor is the single point of truth for display amounts
  • Every JMD user sees wrong amounts on every historical transaction, retroactively

File

src/app/wallets/get-transactions-for-wallet.ts

Fix Approach

  1. Pass the user's configured display currency into the adaptor; use it for both the label and the USD→JMD conversion
  2. Fix the offset logic for correct price mapping
  3. Replace Math.floor with proper rounding (Math.round)

Priority

Urgent — this affects every JMD user's transaction history on every page load.

Related

Activity

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

    @linear
  3. chengyixu commented on Mar 21, 2026

    @chengyixu

    Proposal — Transaction History Adaptor Fix

    I'd like to work on this issue as part of the JMD currency precision bundle (#282).

    Approach for src/app/wallets/get-transactions-for-wallet.ts:

    1. Hardcoded USD fix: Pull the authenticated user's displayCurrency setting from the user resolver and thread it into the adaptor call. In the adaptor, replace the hardcoded 'USD' string with the user's actual currency code. If displayCurrency === 'JMD', apply the JMD/USD exchange rate from config/yaml.ts.

    2. Offset fix: Apply the correct precision offset constant (SAT_PRICE_PRECISION_OFFSET = 12 for BTC→USD, USD_PRICE_PRECISION_OFFSET = 6 for USD→JMD) when computing settlementDisplayAmount. The current offset: 0n skips this scaling entirely.

    3. Math.floor → Math.round: Replace truncation with rounding so small BTC transactions don't silently round to 0 JMD.

    ETA: 1–2 days for the backend fix with tests. I'll coordinate with the mobile companion fix (#555 on flash-mobile) so both land together.

    Lightning address: [email protected]

    Please confirm and I'll open a draft PR.

  4. chengyixu commented on Mar 21, 2026

    @chengyixu

    Proposing to fix the transaction history adaptor for JMD users.

    Root Cause (confirmed from analysis):
    The adaptor in src/app/wallets/get-transactions-for-wallet.ts has multiple compounding bugs for JMD users. This is a subset of the full-stack fix in #282, but isolated to the backend adaptor layer.

    Specific fixes needed:

    1. Hardcoded USD display currency:

    // Current (wrong):
    displayCurrency: 'USD'
    // Fix: 
    displayCurrency: user.displayCurrency || 'USD'

    2. Wrong exponent offset in price conversion:
    The price conversion uses an incorrect power-of-10 offset. JMD/USD rates are ~140, so the exponent shift produces values off by orders of magnitude.
    Fix: verify the correct satoshi → JMD conversion: (satsAmount / 1e8) * btcPriceUSD * jmdRate

    3. Math.floor() truncating sub-dollar JMD values to 0:
    Replace Math.floor(price) with Math.round(price * 100) / 100 (preserve 2 decimal places for JMD)

    4. Missing JMD conversion:
    After computing the USD amount, apply: usdAmount * ExchangeRates.jmd.sell for JMD users

    5. Price service (src/services/price/index.ts):
    Use config.ExchangeRates.jmd.sell directly instead of BTC triangulation to avoid compounding precision errors.

    Timeline: Backend fix + tests within 48 hours. This is well-scoped to the adaptor layer. Ready to start immediately.

  5. xyaz1313 commented on Apr 15, 2026

    @xyaz1313

    I've analyzed the source code in src/app/wallets/get-transactions-for-wallet.ts and identified the root causes. Here's my fix proposal:

    Root Cause Analysis

    Bug 1 — Hardcoded displayCurrency: "USD"
    toWalletTransactions() hardcodes displayCurrency: "USD" as DisplayCurrency in the settlementDisplayPrice object. JMD users see "USD" labels.

    Bug 2 — offset: 0n breaks exchange rate representation
    The offset: 0n combined with BigInt(Math.floor(trx.exchangeRateCurrencySats)) means small exchange rates (< 1 sat per unit) floor to 0n, making the price zero. For JMD, exchangeRateCurrencySats ≈ 0.00065, so BigInt(Math.floor(0.00065)) = 0n.

    Bug 3 — Math.floor truncates to zero
    For any exchangeRateCurrencySats < 1, BigInt(Math.floor(...)) yields 0n. The codebase already handles this correctly in priceAmountFromNumber() (src/domain/fiat/display-currency.ts) using 10 ** offset scaling.

    Fix

    The fix follows the existing pattern in display-currency.ts:priceAmountFromNumber():

    // Add import
    import { SAT_PRICE_PRECISION_OFFSET } from "@domain/fiat"
    
    // getTransactionsForWallets: pass displayCurrency through
    export const getTransactionsForWallets = async ({
      wallets,
      paginationArgs,
      displayCurrency = "USD" as DisplayCurrency,
    }: {
      wallets: Wallet[]
      paginationArgs?: PaginationArgs
      displayCurrency?: DisplayCurrency
    }): Promise<PartialResult<PaginatedArray<IbexTransaction>>> => {
      // ... existing ibexCalls logic unchanged ...
    
      const transactions = ibexCalls.flatMap(resp => {
        if (resp instanceof IbexError) return []
        else return toWalletTransactions(resp, displayCurrency)  // pass displayCurrency
      })
      // ... rest unchanged
    }
    
    // toWalletTransactions: accept displayCurrency, fix price calculation
    export const toWalletTransactions = (
      ibexResp: GResponse200,
      displayCurrency: DisplayCurrency = "USD" as DisplayCurrency
    ): IbexTransaction[] => {
      return ibexResp.map(trx => {
        const currency = (trx.currencyId === 3 ? "USD" : "BTC") as WalletCurrency
    
        // Fix: scale exchangeRate properly (matches priceAmountFromNumber pattern)
        const exchangeRate = trx.exchangeRateCurrencySats ?? 0
        const offset = SAT_PRICE_PRECISION_OFFSET  // 12
        const scaledBase = Math.round(exchangeRate * Math.pow(10, offset))
    
        const settlementDisplayPrice: WalletMinorUnitDisplayPrice<WalletCurrency, DisplayCurrency> = {
          base: BigInt(scaledBase),
          offset: BigInt(offset),
          displayCurrency: displayCurrency,  // ← was hardcoded "USD"
          walletCurrency: currency
        }
    
        // ... rest of baseTrx and switch unchanged
      })
    }

    Changes summary:

    1. Added displayCurrency param (default: "USD") to both functions
    2. Replaced BigInt(Math.floor(...)) with Math.round(exchangeRate * 10^12) — preserves precision
    3. Set offset: BigInt(SAT_PRICE_PRECISION_OFFSET) instead of 0n — follows priceAmountFromNumber() pattern
    4. Uses user's displayCurrency instead of hardcoded "USD"

    Happy to submit a PR if this approach looks right.

  6. added a commit that references this issue on Apr 15, 2026
    3527e08
  7. added a commit that references this issue on Apr 17, 2026
    55f76a8
  8. added
    currency precision
    and removed
    bug
    on Apr 17, 2026
  9. islandbitcoin commented on Jun 18, 2026

    @islandbitcoin
    ContributorAuthor

    2026-06-18 — Reframe (USDT migration): this shrinks. The IBEX adaptor (src/app/wallets/get-transactions-for-wallet.ts) handles only USD/USDT accounts, and with the Cash Wallet now USDT it no longer routes display through BTC price. So bug #2 (price-point offset) and #3 (Math.floor truncation) are now obsolete for this adaptor. What remains is #1: use the user's display currency for the primary amount + a single USD→JMD conversion on Cash/IBEX rows. The BTC wallet's JMD display is a separate path (Breez) and is unchanged.

  10. 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. (This issue was part of the #282 bundle.)

  11. added
    bug
    and removed on Oct 10, 2026
  12. islandbitcoin commented on Oct 10, 2026

    @islandbitcoin
    ContributorAuthor

    Priority pass 2026-10-10: rank 3 of 13. Remaining scope after the Jun 18 reframe is bug 1 only: get-transactions-for-wallet.ts:69 hardcodes displayCurrency USD and does no USD to JMD conversion. Pairs with lnflash/flash-mobile#547 on the client side. Most visible correctness bug left for JMD users.

  13. nul-quill commented on Oct 11, 2026

    @nul-quill

    Handle: nul-quill. Payout wallets: Solana USDC BdznDjc4xwt5Y6WJT5UnrFQzDptka8YnC9oqmmkKpwkd, TRC20 TNEHCVwR2aPMrj5AKfWCQ2rFL3bEDQmsg7.

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

    Urgentbugcurrency precisioncustomer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions