Skip to content

fix(send): surface real BTC fee errors and validate LNURL receive limits - #680

Merged
islandbitcoin merged 4 commits into
mainfrom
eng-btc-fee-error-handling
Aug 7, 2026
Merged

islandbitcoin merged 4 commits into
mainfrom
eng-btc-fee-error-handling

Conversation

@islandbitcoin

Copy link
Copy Markdown
Contributor

Summary

Sending from the Breez Spark BTC wallet to a Flash address (or any LNURL destination) failed with a misleading "make sure you have enough balance" message whenever fee estimation failed for any reason. The most common real cause is the receiver's advertised LUD-06 maxSendable cap (ENG-540: IBEX advertises 150k sats instead of 150M), which LNURL-compliant clients reject client-side before ever requesting an invoice.

  • fetchBreezFee returns a typed BreezFeeError (amount-above-max / amount-below-min / insufficient-funds / network / sdk) instead of swallowing every failure into one hardcoded balance string; real errors are recorded to Crashlytics
  • amounts are validated against the receiver's minSendable/maxSendable before prepareLnurlPay, so the UI shows the actual limit (e.g. "The most this recipient can receive per payment is $97.03 (150,000 sats)")
  • the send-details screen resolves the receiver's limits once per destination and DetailAmountNote validates as the user types for BTC-wallet sends (previously only USD/USDT lnurl sends were validated)
  • ConfirmationWalletFee: fixed the dead fee === "null" string comparison and wired typed-error mapping
  • useSwap: BTC→USD swap fee errors no longer all report as "amount exceeds balance"
  • 5 new i18n keys in en + all 23 locales (English placeholder convention per feat(mobile): Plaid Link SDK cutover for Bridge external accounts [ENG-524] #668/feat(bank): fall back to manual entry when Plaid Link is blocked #678)

Linear: ENG-540

Test plan

  • yarn tsc:check clean
  • yarn test — 50 suites / 267 tests pass, incl. 2 new suites covering msat→sat limit conversion (with the exact 150k-cap regression case), bounds validation, SDK error classification, and message mapping
  • node utils/check-translation-drift.js green; yarn update-translations regenerated and stable
  • Manual: BTC-wallet send >150k sats to a Flash address shows the receiver-limit message inline; retest after IBEX raises maxSendable

🤖 Generated with Claude Code

https://claude.ai/code/session_01G7A41jET8aH7u5WXP7EZoS

Sending from the Breez Spark BTC wallet to a Flash address (or any LNURL
destination) failed with a misleading 'make sure you have enough balance'
message whenever anything went wrong in fee estimation. The most common
real cause is the receiver's advertised LUD-06 maxSendable cap (ENG-540:
IBEX advertises 150k sats instead of 150M), which the SDK rejects
client-side before requesting an invoice.

- fetchBreezFee now returns a typed BreezFeeError instead of swallowing
  every failure into one hardcoded balance string; real errors are
  recorded to Crashlytics
- amounts are validated against the receiver's minSendable/maxSendable
  before prepareLnurlPay, so the UI can show the actual limit
- send-details screen resolves the receiver's limits per destination and
  DetailAmountNote validates as the user types for BTC-wallet sends
  (previously only USD/USDT lnurl sends were validated)
- ConfirmationWalletFee: fix dead 'fee === "null"' string comparison,
  map typed errors to accurate messages
- useSwap: stop reporting every fee error as 'amount exceeds balance'
- new i18n keys in en + all 23 locales (English placeholder convention)
- unit tests for limit conversion/validation, error classification, and
  message mapping

Linear: ENG-540

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01G7A41jET8aH7u5WXP7EZoS
- extract shared useFormatSats hook, replacing four hand-rolled copies of
  the sats formatting closure (details screen, DetailAmountNote,
  ConfirmationWalletFee, useSwap)
- resolve the receiver's LNURL payRequest once on the details screen and
  pass it through to fetchBreezFee, removing the duplicate network
  round-trip to the receiver's LNURL service on every BTC send
  (fetchLnurlLimits -> fetchLnurlPayRequest)
- add component tests for DetailAmountNote's BTC receiver-limit
  validation branch (over-max regression case, below-min, within-bounds,
  unknown limits, lnurl payment type)

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01G7A41jET8aH7u5WXP7EZoS
@linear

linear Bot commented Aug 6, 2026

Copy link
Copy Markdown

ENG-540

Dread and others added 2 commits August 6, 2026 17:06
The added knownPayRequest parameter pushed the signature to five positional
params, tripping max-params on the changed-lines lint gate. An options
object is the better API anyway — no optional-middle-arg call sites.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01G7A41jET8aH7u5WXP7EZoS
@islandbitcoin
islandbitcoin merged commit 47b8c69 into main Aug 7, 2026
10 checks passed
@islandbitcoin
islandbitcoin deleted the eng-btc-fee-error-handling branch August 7, 2026 21:04
islandbitcoin added a commit that referenced this pull request Aug 15, 2026
* feat(send): max amount button on the amount screen

Adds a MAX chip beside the balance in the amount input screen's header
(issue #512). Outlined green when available, solid green while the
entered amount is the computed max, back to outlined the moment the
user edits, greyed out on a zero balance. Theme colors only.

Max rules, computed in the send flow (the amount screen stays free of
payment knowledge via an optional maxAmountButton prop):
- intraledger / Flash-to-Flash: full wallet balance, no API call; note
  says there is no fee between Flash accounts
- external invoice / LNURL: balance minus the fee estimate (BTC wallet
  via fetchBreezFee, USD wallet via the existing fee probes); note
  states the reserved fee
- LNURL destinations clamp to the receiver's maxSendable (reuses the
  payRequest bounds from #680)
- fee estimate failure or timeout fills the full balance and lets the
  existing pre-validation surface the typed fee error — the tap never
  blocks

The currency toggle keeps the same underlying amount, so the chip
stays solid across toggles.

i18n: new AmountInputScreen keys in en, English placeholders appended
to all 23 locale files for the next translation batch.

Tests: computeMaxSendAmount unit suite (12 cases) and an
AmountInputScreen component suite for the chip states (6 cases).

Fixes #512

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015fAxSGEsL2LsMx1uCjAzHH

* fix(send): review fixes for the MAX amount chip

- BTC-wallet intraledger sends settle via LNURL-pay with a real Breez
  fee: route them through the fee path (effectiveMaxPaymentType) instead
  of filling the full balance with a false no-fee note, which dead-ended
  every BTC-wallet MAX-to-Flash send at confirm time
- exclude onchain from the chip: its fee estimate needs the not-yet-
  selected fee speed and the flow already has its own send-all Max
- guard NaN balances: disable the chip while wallets are still loading
  and treat non-finite balances as zero in computeMaxSendAmount, so the
  number pad can never fill the literal string NaN
- drop stale in-flight max computations: any edit (key press, clear,
  currency toggle) invalidates the pending fee fetch so a slow resolve
  can no longer overwrite the user's typed amount or revert a currency
  toggle; the chip now shows a computing state while the fetch runs
- show no note when the reserved fee is zero (a $0.00 reservation note
  is nonsense)
- extract the decision logic into pure functions (maxChipSupports-
  PaymentType, effectiveMaxPaymentType, resolveRecipientCap,
  noteForResult) and unit-test them, plus component tests for the
  computing state and stale-resolve races

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015fAxSGEsL2LsMx1uCjAzHH

* fix(send): probe MAX fee at the cap-clamped amount, not the raw balance

fetchBreezFee bounds-validates the probe amount against the receiver's
LUD-06 limits before preparing, so probing at the full balance was
guaranteed to fail whenever the recipient cap binds — the fee came back
null and MAX filled the cap-clamped amount with no fee headroom. In the
band where balance - cap < fee, confirm-time validation then dead-ended
with "amount exceeds balance (amount + fee)".

computeMaxSendAmount now derives the probe amount (balance clamped to
the recipient cap) and passes it to fetchFee; the details screen probes
Breez/IBEX at that amount. Both regimes now yield a confirm-safe MAX:
min(balance - fee, cap). Adds unit tests for the probe amount and the
cap-within-fee-distance-of-balance band.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015fAxSGEsL2LsMx1uCjAzHH

* fix(send): floor MAX to whole minor units — fractional-cent balances overdraw

On-device repro (iPhone, USD cash wallet, zero-amount invoice): the API
reports USD balances in FRACTIONAL cents (109.9346 = $1.099346 at
IBEX); MAX offered it un-floored, downstream rounding produced a
$1.10 invoice, and IBEX rejected the send — 'insufficient balance.
Current Balance: 1.099346 ... invoice amount: 1.100000'.

computeMaxSendAmount now floors the spendable balance, the fee-adjusted
result, and the recipient cap to whole minor units (no-op for integer
sat balances), and a sub-cent balance counts as zero. Four regression
tests pin the repro numbers.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015fAxSGEsL2LsMx1uCjAzHH

* fix(send): guard MAX fill against display-currency round-trip overdraw

The pad can hold a different currency than the wallet (JMD display over
a USD wallet). The fill converted the wallet-unit max into the pad
currency and floored there — but the send path converts the pad amount
BACK to wallet units and rounds, so a forward-rounding conversion (or a
rate tick) can still round-trip above the computed max and overdraw.

The fill now steps the pad amount down until its round-trip back to
wallet units stays within the computed max. Component test pins the
class with a coarse rounding converter (109-sat max, 10-sats-per-cent:
naive fill 11 cents → 110 sats overdraw; guarded fill 10 cents).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015fAxSGEsL2LsMx1uCjAzHH

* fix(send): harden MAX chip against stale commits and sub-cent balances

Review fixes for the MAX amount chip (PR #689):

- amount-input-screen: the initialAmount reset effect now clears the
  applied-MAX chip state and bumps the edit generation. A new initial
  amount means the caller committed or replaced the amount (Set Amount
  closed the modal and it reopened), so a late MAX resolve can no longer
  overwrite the committed amount or leave the chip solid with a stale
  fee note asserting the committed amount is the computed max.

- max-amount-button: extract buildMaxAmountButton from the details
  screen into a dependency-injected factory next to max-send-amount.ts,
  and unit-test the previously uncovered glue in plain jest — the Breez
  fetchFee adapter's err-to-null mapping, knownPayRequest reuse, the
  flash-address preference, the USD probe-detail construction via
  setAmount/getIbexFee, and the note-kind to string mapping.

- sub-cent balances: disable the chip when Math.floor(balance) is zero
  (a USD wallet drained by a MAX send holds fractional cents, e.g.
  0.9346, which is unspendable), and have compute() return null on a
  zero-balance result instead of emptying the pad under a solid chip.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015fAxSGEsL2LsMx1uCjAzHH

* fix(send): fill MAX in wallet units when it floors to zero display units

A positive wallet-units max worth under one display minor unit (e.g. a
dust BTC balance under USD display) floored to a zero fill: the pad
emptied under a solid MAX chip and Set Amount stayed ready to commit a
zero amount. When the display fill floors (or steps) to 0 while the
computed max is positive, fill the pad in wallet units instead — the
true max needs no display round-trip since the computation already
floors it to whole wallet minor units.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015fAxSGEsL2LsMx1uCjAzHH

* fix(send): close remaining zero-max and lossy-toggle MAX edges

Round-3 review follow-ups for PR #689:

- The zero-max escape gated on reason === 'zero-balance' only, but a fee
  estimate meeting/exceeding the balance ({amount: 0, reason:
  'fee-reserved'}) and a receiver advertising maxSendable 0 also produce
  zero — and would empty the pad under a solid chip. Gate on the amount
  itself; three unit tests cover the routes.

- After a wallet-units dust fill, toggling display currency rounds the
  amount (0.5 cents → 1 cent = double the 5-sat max, or 0.4 → 0 = empty
  pad) while the chip stayed solid. A lossy toggle now drops the MAX
  claim; faithful toggles keep it. Component test pins it.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015fAxSGEsL2LsMx1uCjAzHH

---------

Co-authored-by: Dread <[email protected]>
Co-authored-by: Claude Fable 5 <[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.

1 participant