Repository navigation
fix(send): price LNURL sends instead of guessing a fee reserve - #702
Merged
Merged
Conversation
MAX proposed an amount the send flow could never accept. For a USD wallet sending to a lightning address there is no invoice at MAX-press time, so getIbexFee resolves undefined, fetchFee returns null, and computeMaxSendAmount fell back to the *full balance* with zero fee headroom. The backend then adds its own fee on top — payment-flow-builder uses `usdProtocolAndBankFee || LnFees().maxProtocolAndBankFee(amount)` and checkBalanceForSend refuses anything where `balance < amount + fee` — so the send died and the user saw only 'An error occurred. Contact support if error persists.' Reported on TEST: balance $4.42, MAX filled $4.42 and failed; a manual $4.00 to the same destination succeeded. Reserve what the backend reserves instead: 50 basis points with a one-minor-unit floor, mirroring FEECAP_BASIS_POINTS. This is not a guess at the fee — it is the same bound the backend applies when it has no probed fee of its own, so an amount computed against it is one the balance check will accept. Intraledger is untouched: fee is genuinely zero between Flash accounts on the same instance, which is why MAX has always worked there and why this only showed up on cross-instance / external destinations. The no-estimate result now also carries feeReserved, so the amount screen explains the shortfall rather than silently offering less than the balance the user can see. Tests: 662 pass. New coverage includes an exhaustive check that no proposed amount can exceed the balance once the cap is added, and that the amount offered is the largest one that fits. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_016MsAGwtS4sNodzWu2VMTKR
Review found the first version's premise was wrong. It mirrored flash's FEECAP_BASIS_POINTS on the claim that "the backend reserves exactly this much" — but lnNoAmountUsdInvoicePaymentSend, the mutation that actually failed, never reaches that code. Its resolver has the Payments layer commented out and calls Ibex.payInvoice directly, so there is no paymentFlow, no LnFees, and no checkBalanceForSend on this path. The constant bounded nothing real. It was also arithmetically wrong: the client floored where mulBasisPoints uses divRound, which rounds up when the remainder exceeds half, so 2353 of 5000 balances would still have been refused — including the 10_000 case the tests asserted as correct. Nothing in this app knows what IBEX charges: there is no fee bound in the flash config or the IBEX client, and no invoice-free lightning estimate (getLnFeeEstimation needs a bolt11, estimateFeeV2 is onchain). So stop guessing and get a real number. An LNURL payment detail has no getFee until an invoice is attached, which is why the probe returned nothing and MAX had nothing to work from. probeLnurlFee mints a throwaway invoice at the probe amount purely to price it — never paid, and the send flow mints its own on Next, which matters because these expire in 60s. When a destination still cannot be priced, propose nothing rather than invent a number, and say so: "Couldn't estimate the network fee for this destination — enter an amount to continue". MaxAmountButtonResult.amount is now optional so a computation can explain itself without filling the pad, instead of the tap silently doing nothing. This also drops the BTC/Breez concern flagged on the first version: that path no longer gets a fabricated reserve presented to the user as a real estimate. Tests rewritten. The old ones were tautological — they asserted amount + reservedFeeCapFor(amount) <= balance, the client's own function on both sides, which is why the off-by-one passed 662 green tests. They now pin behaviour: the probe is consulted at the cap-clamped amount, the invoice-less IBEX probe is not used for LNURL, an unpriceable destination yields no amount and a note, and a priced one yields balance minus the real fee. 663 pass. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_016MsAGwtS4sNodzWu2VMTKR
Review fixes for #702. - Extract the LNURL price probe out of the screen into a dependency-injected `priceLnurlSend` (lnurl-fee-probe.ts) and unit-test it: the cents-to-whole-sats conversion, the params-taking invoice mint, the invoice-to-getFee link, the timeout and every failure mapping. The probe was the only new production logic in the PR and nothing covered it — both spec files injected a stand-in, so `return null` passed all of them. - Mint the probe invoice with `requestInvoiceWithServiceParams` against the already-resolved `lnurlParams` instead of re-resolving the pay service by address. One round-trip inside the budget, not two. - Memoize completed probes per destination + wallet + probe amount for the life of the screen. Every completed MAX tap minted a real invoice at the receiver; repeated taps orphaned invoices and tripped rate-limited services. Successes only — a transient failure must not brand a destination unpriceable for the session. - Reserve `ceil(fee) + 1` minor unit instead of `floor(balance - fee)`. The estimate was priced against the probe invoice, not the one the send pays: balance 442c with a 0.5c probe fee filled 441c, the final invoice priced at 1.5c, and confirm blocked with "amount exceeds balance (amount + fee)". - Keep the MAX chip outlined when the tap explains itself without filling anything. `appliedMax` now carries `applied` separately from `note`, so an unpriceable destination no longer renders a solid, VoiceOver-selected chip over an unchanged $0 pad. - Make `probeLnurlFee` required on `buildMaxAmountButton`. A caller that forgets to wire it is a compile error now, not a silent degradation of every USD LNURL send to "couldn't estimate". - Reword `maxNoteFeeUnknown` to blame the moment rather than the destination, and seed it (plus the `allowanceExhausted` key en.json picked up from #700) into all 23 translation files so the translation-drift gate goes green. - Fix two stale comments in max-send-amount.ts that still described the deleted full-balance fallback, and drop the unrelated cosmetic edits in send-bitcoin-details-screen.tsx. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_016MsAGwtS4sNodzWu2VMTKR
Second round of review fixes for #702. - Add a `fee-exceeds-balance` outcome. `Math.max(balance - ceil(fee) - 1, 0)` reported a zero max as `fee-reserved`, which max-amount-button mapped to `null`, which amount-input-screen drops on the floor — so a BTC wallet holding 2_000 sats against a 2_500-sat channel-open fee spun the chip, returned it to outlined, and said nothing. This PR's whole thesis is that a tap proposing nothing must say why, and it applied that to exactly one of the three zero routes. The new reason carries a `fee-too-large` note kind and a string ("The network fee is more than this balance can cover"). The slack unit also moved the boundary: balance 2_500 with a 2_499-sat fee filled 1 sat on main and is now explained rather than silent. - Say why on the zero-cap route too, while the note mapping is open. A receiver advertising maxSendable 0 was the other silent zero; it now gets the cap note, which names the limit that bound. Only a wordless zero still resolves null — and zero-balance cannot be tapped, because the chip is disabled for it. - Bound the whole price check with `LNURL_PROBE_TIMEOUT_MS`, as its doc comment always claimed. The race wrapped only the invoice mint; the IBEX route probe that follows ran untimed, so a 6.9s mint plus a 5s probe took 11.9s and only the chip's outer 10s race stopped it. A slow destination burned the full spinner on every tap before showing the same note. - Share the in-flight MINT, not just the finished fee. `Promise.race` abandons the wait at 7s but cannot cancel `requestInvoiceWithServiceParams` — the receiver mints and returns an orphaned invoice anyway, the probe resolves null, and the null is (correctly) not cached, so the retry the note asks for mints another. For any receiver slower than the budget (Tor-hosted, cold serverless, LNbits under load) nothing was ever cached and every tap cost a fresh invoice: the exact orphan/rate-limit failure the memo was added to prevent. A rejected mint is forgotten immediately, and an answered one that could not be priced is forgotten when the probe gives up, so a stale invoice cannot brand a destination dead either. - Extract that glue out of the screen into `makeLnurlFeeProbe` / `makeLnurlProbeCache` and unit-test it. The memo was ten lines of untested production logic: deleting it, inverting its guard, or dropping the probe amount from its key all left 684 tests green. Nine tests now cover the cache hit, the uncached failure, per-amount and per-destination keys, and every mint-sharing rule. Each fix is pinned by a test that fails without it (verified by mutation). 703 pass, up from 684. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_016MsAGwtS4sNodzWu2VMTKR
Two review notes. A typed Breez bounds error was collapsing into the same null as a network failure. That did not matter while a null fee still filled the balance — committing it surfaced "The minimum this recipient can receive is N sats" downstream. Now that an unpriceable destination proposes nothing, the MAX note is the only place that reason can still reach the user, and telling them the fee could not be estimated when the real answer is a receiver minimum sends them nowhere. The typed error is captured and the note reports the minimum when there is one. maxNoteFeeTooLarge claimed "the network fee is more than this balance can cover", but it fires whenever the balance cannot survive the rounded-up fee plus a unit of slack — so a 2-cent balance with a half-cent fee was told the fee exceeded it. Reworded to describe the balance, not the fee. 705 tests pass. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_016MsAGwtS4sNodzWu2VMTKR
…loor
Review fixes on the LNURL MAX price probe.
Age retires a mint, not the outcome of a probe. Deleting a settled entry
whenever the price came back null threw away a perfectly good invoice
whenever the IBEX leg was the slow half: mint answers at 2s, the route
probe hangs, the 7s budget fires, and an invoice good for another 53s is
dropped. The note says "tap MAX again", so the retry mints another at the
receiver — the orphan/rate-limit failure the memo exists to prevent, moved
from the first leg to the second. Settled mints are now kept and entries
older than MINT_REUSE_TTL_MS (45s, inside the 60s invoice lifetime) are
treated as absent, which also closes the other end: the mint key is
destination + sats, so 441c and 442c both land on 221 sats and a fresh fee
key could previously be served an invoice minted minutes ago.
The LNURL branch honoured the receiver's maximum but never its minimum.
lnurl-pay bounds-checks client-side and throws a bare Error("Invalid
amount") below minSendable, which collapsed into the same null as a
network blip and produced "couldn't estimate the fee — tap MAX again" — a
retry loop that can never succeed for a $4.42 balance (221 sats) against a
1_000-sat minimum. buildMaxAmountButton now takes receiverMinSats and
reports the bound through the existing amount-below-min -> recipientMin
mapping instead of asking the receiver for an impossible invoice. The
screen resolves it from lnurlParams on the USD path, where receiverLimits
(BTC-only) cannot supply it.
maxNoteFeeTooLarge was seeded in all 23 locales from a stale draft, so
English users and every other locale saw different sentences. Re-seeded
from source/en.json.
FEE_ESTIMATE_TIMEOUT_MS is now exported so the probe-budget test asserts
against the chip's real constant instead of a hardcoded copy that would
keep passing after the chip's budget dropped below the probe's.
The lnurl-pay adapter moves out of the screen into mintProbeInvoice, the
last untested line of the PR: it pins the params-taking call (one
round-trip, not two) and enforces whole sats before utils.toSats, which is
a bare cast that would otherwise brand 220.5 as Satoshis.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_016MsAGwtS4sNodzWu2VMTKR
Two review fixes on the MAX chip.
The receiver's minSendable guarded the fee probe's INPUT but never the
number the chip put in the pad. The cap is applied to the result; the
floor was applied only to the probe, and the fee is subtracted between
them — so every balance in [min, min + fee + slack) cleared the probe and
still proposed an unsendable amount. A BTC wallet with 3,000 sats against
a 2,500-sat channel-open fee and a 1,000-sat minimum filled 499 sats under
"~2,500 sats reserved for the network fee", with "the minimum this
recipient can receive is 1,000 sats" painted directly beneath it. The USD
LNURL path had no working local check at all, so 2,010c (1,005 sats) filled
1,989c (994 sats) and Next asked the mint for an impossible invoice —
lnurl-pay threw Error("Invalid amount") and the screen blamed the fetch.
ENG-554's own symptom, out of the chip written to prevent it.
Resolve the floor once, in both units, and clamp the result the way the
cap already is: propose nothing, name the bound. The floor stays
inclusive, so an amount landing exactly on it is still offered.
The chip's recipient-minimum note also hardcoded `${minSats} sats` while
the validation banner two rows down renders the same sentence through
formatSats ("$0.65 (1,000 sats)"). On the BTC LNURL path both can be on
screen at once, and two renderings of one number read as two different
limits. Move the note builders into max-amount-button-strings.ts — bound
to the same formatSats, and unit-testable against breezFeeErrorMessage so
the two renderings cannot drift again.
The same ENG-554 narrative was written out three times in one file. Prose does not fail tests: the next person to change the clamp updates one copy and the other two quietly become documentation of behaviour that no longer exists. The full story stays on the `receiverMinSats` type doc, which is what a caller actually reads; the two call sites now state their invariant in a line and point at it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_016MsAGwtS4sNodzWu2VMTKR
This was referenced Aug 20, 2026
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.
What this fixes
Tapping MAX on the send amount screen filled the full wallet balance for
destinations the app could not price. The network fee then landed on top and
the send was refused with a generic error (ENG-554; reproduced on-device at a
$4.42 balance).
The gap is structural, not a rounding bug: an LNURL payment detail has no
getFeeuntil an invoice is attached (payment-details/lightning.tskeepscanGetFeefalse until then), so the ordinary IBEX fee probe had nothing toprice and silently returned nothing. MAX read "no fee" as "no fee to reserve".
What it does instead
Price the destination for real, and propose nothing when that fails.
lnurl-fee-probe.tsprices an LNURL send by minting a throwaway invoice atthe probe amount and running the IBEX fee probe against it. The invoice is
never paid — pressing Next mints a fresh one for the actual send, which
matters because these expire in 60s. It is minted with
requestInvoiceWithServiceParamsagainst the pay-service params the screenalready resolved, so pricing costs one round-trip inside its 7s budget
rather than two.
computeMaxSendAmountreturns{ amount: 0, reason: "fee-unavailable" }.The chip proposes no amount at all and shows
maxNoteFeeUnknown("Couldn't estimate the network fee right now — tap MAX again or enter an
amount"). The chip stays outlined: nothing was applied, so it must not claim
it was, visually or to VoiceOver.
balance − ceil(fee) − 1minor unit. Theslack is deliberate: the estimate was priced against the probe invoice, not
the one the send will pay, and amount-monotonicity says nothing about
invoice-to-invoice route variance. Without it, a 442c balance with a 0.5c
probe fee filled 441c, the final invoice priced at 1.5c, and confirm blocked
with "amount exceeds balance (amount + fee)".
life of the screen, so tap → edit → tap does not orphan a second real invoice
at the receiver or trip a rate-limited LNURL service. Successes only: a
transient failure must not brand a destination unpriceable for the session.
This applies to every non-intraledger path, BTC/Breez included. Only
USD-wallet Flash-to-Flash sends still offer the full balance, because those
genuinely have no fee.
Deliberately not done
An earlier revision of this branch reserved a constant borrowed from galoy's
FEECAP_BASIS_POINTS(50bp with a one-minor-unit floor). That was dropped in670c8b6d: the cap governs galoy's payment layer, andlnNoAmountUsdInvoicePaymentSendbypasses it entirely to callIbex.payInvoice, so the number bounded nothing real. Guessing a reserve isnot more honest than declining to guess — it just fails later.
Tests
__tests__/utils/lnurl-fee-probe.spec.ts(new) — the probe itself: thewhole-sat conversion of the probe amount, the resolved-params mint, that the
fee returned belongs to the invoice it minted, and null on mint rejection,
timeout, missing params, non-LNURL detail, sub-sat amount, and an IBEX probe
that returns nothing or throws.
__tests__/utils/max-send-amount.spec.ts— the reserve arithmetic, includingthe 442c/0.5c band that used to dead-end at confirm.
__tests__/utils/max-amount-button.spec.ts— routing LNURL through the proberather than the invoice-less IBEX probe, and the note mapping.
__tests__/components/amount-input-screen-max-chip.spec.tsx— a note with noamount shows the note, leaves the pad untouched, and leaves the chip
outlined and unselected.
Note on the i18n diff
app/i18n/raw-i18n/source/en.jsonis generated fromapp/i18n/en/index.tsbyyarn update-translations. Regenerating it to addmaxNoteFeeUnknownalsobackfilled
TopupDetails.allowanceExhausted, which #700 added to the source oftruth without re-exporting. Both keys are seeded into all 23 translation files
with the English string — the same convention the existing
maxNote*keysfollow — so the
translation-driftgate passes.