Repository navigation
fix(send): surface real BTC fee errors and validate LNURL receive limits - #680
Merged
Merged
Conversation
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
2 of 3 tasks
- 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
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01G7A41jET8aH7u5WXP7EZoS
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
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
maxSendablecap (ENG-540: IBEX advertises 150k sats instead of 150M), which LNURL-compliant clients reject client-side before ever requesting an invoice.fetchBreezFeereturns a typedBreezFeeError(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 CrashlyticsminSendable/maxSendablebeforeprepareLnurlPay, so the UI shows the actual limit (e.g. "The most this recipient can receive per payment is $97.03 (150,000 sats)")DetailAmountNotevalidates as the user types for BTC-wallet sends (previously only USD/USDT lnurl sends were validated)ConfirmationWalletFee: fixed the deadfee === "null"string comparison and wired typed-error mappinguseSwap: BTC→USD swap fee errors no longer all report as "amount exceeds balance"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:checkcleanyarn 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 mappingnode utils/check-translation-drift.jsgreen;yarn update-translationsregenerated and stablemaxSendable🤖 Generated with Claude Code
https://claude.ai/code/session_01G7A41jET8aH7u5WXP7EZoS