Skip to content

fix(send): compare LNURL bounds in the wallet's own units, and name them - #706

Merged
islandbitcoin merged 5 commits into
mainfrom
fix/lnurl-bounds-units
Aug 21, 2026
Merged

islandbitcoin merged 5 commits into
mainfrom
fix/lnurl-bounds-units

Conversation

@bobodread876

@bobodread876 bobodread876 commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes ENG-556. Confirmed in production on v0.6.6.

The report

Sending to [email protected] from a USD wallet, nothing under $1.00 could be sent, and the error read:

The amount on the invoice is less than minimum amount NaN

Why $1.00, exactly

Strike advertises minSendable: 100000 msat = 100 sats. app/components/send-flow/DetailAmountNote.tsx compared:

paymentDetail.settlementAmount.amount < paymentDetail?.lnurlParams.min

LUD-06 bounds are in sats; a cash wallet's settlementAmount is in cents. So 100 sats was read as 100 cents and the app demanded a dollar — for a receiver whose real floor is worth single-digit cents. Over 10× overstated, and the threshold moves with the BTC price.

The maximum had the identical fault in the opposite direction: against Strike's 16,000,000-sat ceiling it could only fire above $160,000, so it never protected anyone. Silent rather than loud, which is why nobody reported it.

Both bounds are now converted into the sending wallet's units before comparing.

Converted is not enough — the bound has to be typeable

A converted bound is usually fractional, and the number pad only accepts whole minor units. Left fractional, the app can name a minimum it then refuses: at BTC $64,000 Strike's floor converts to 6.4¢, the message rounds that to "$0.06", the user types 6¢ — and is refused again. A dead end at roughly half of all price levels.

So the bound is quantized outward before it is either enforced or named: the minimum rounds up, the maximum rounds down, so the quantized bound is always one the receiver accepts, and the amount printed in the message is exactly the smallest (largest) entry that will be accepted. Float noise is stripped first — 100 sats at exactly BTC $70,000 computes to 7.000000000000001 cents, and a naive ceil would name 8¢ as the floor of a bound that is really 7¢.

That rule now lives in one place, lnurlBoundInWalletUnits in app/screens/send-bitcoin-screen/max-send-amount.ts, next to resolveRecipientCap, and both the MAX chip and this check call it. The sat→wallet conversion goes through paymentDetail.convertMoneyAmount — the same function settlementAmount itself was derived from, matching the sibling call in send-bitcoin-details-screen.tsx — so both sides of the comparison come from one source.

Why "NaN"

The i18n placeholder was typed as a number:

minAmountInvoiceError: "...minimum amount {amount: number}"

formatDisplayAndWalletAmount returns a formatted string, so the call site satisfied the type with Number("$0.07") — which is NaN. The placeholder is now {amount: string} and the formatted value passes through intact. That also makes the mistake uncompilable rather than merely fixed.

The message names the bound as money in the wallet's own units ("$0.07"), not as sats — formatDisplayAndWalletAmount drops the suffix for a cash wallet under a USD display currency.

Retyping surfaced a second call site in redeem-flow/InforError.tsx passing a bare 1 for "one cent"; it now formats the amount so the message names a unit ("$0.01").

The same two keys were still declared {amount: number} in all 23 translated locale files. Harmless at runtime — typesafe-i18n strips the annotation when interpolating — but the corpus contradicted its own source of truth and check:translation-drift only compares key presence, so nothing would ever have caught it. Retyped in the same pass that seeds allowanceExhausted, anchored on the key so each locale's own phrasing is preserved.

Scope

Tests

detail-amount-note.spec.tsx runs every cash-wallet case against both USD and USDT (DetailAmountNote routes them through one branch):

  • The production case: 50¢ to a 100-sat floor is allowed, 5¢ is still refused, and the ceiling fires. Verified they fail against the old comparison — reinjecting it turns the Strike case and the ceiling case red.
  • The bounds themselves: ceil(bound) - 1 refused, ceil(bound) allowed, floor(maxBound) allowed, floor(maxBound) + 1 refused.
  • Two awkward rates — a genuinely fractional bound (BTC $64,000 → 6.4¢) and a float-noise bound (BTC $70,000 → 7.000000000000001¢) — each asserting that the amount named in the error is itself accepted when re-entered. That pair is the regression test for the dead end; both fail if the quantization is removed.
  • Assertions on the formatter's arguments, not on a string the mock fabricates.

lnurlBoundInWalletUnits has its own unit tests in max-send-amount.spec.ts, including both float-noise directions and NaN passthrough.

New: __tests__/components/redeem-flow-infor-error.spec.tsx — the redeem flow's one-cent threshold had no coverage anywhere. It asserts the message says $0.01 (not 1, not $1.00), that the formatter is handed a one-cent MoneyAmount, and that no error renders once the entry clears a cent.

731 tests pass; tsc:check, check:translations, check:translation-drift, check:codegen and graphql-check clean; no new lint on changed lines.

One unrelated inclusion, deliberately

TopupDetails.allowanceExhausted is seeded into the 23 locale files. #700 added it to en/index.ts without regenerating the raw source, so running update-translations here surfaced the gap and check-translation-drift would otherwise fail on this branch. Mechanical, and required for CI to pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_016MsAGwtS4sNodzWu2VMTKR

Reported in production on v0.6.6: sending to [email protected] from a
USD wallet, nothing under $1.00 could be sent, and the error read "The
amount on the invoice is less than minimum amount NaN".

Two defects in the same branch, both since #689.

LUD-06 bounds arrive in SATS; a cash wallet's settlementAmount is in
CENTS. The check compared them directly, so Strike's minSendable of
100_000 msat — 100 sats, worth single-digit cents — was read as 100
cents and the app demanded a dollar. That is over 10x the receiver's
real floor, and the threshold drifts with the BTC price. The maximum had
the same fault in the opposite direction: against a 16M-sat ceiling it
could only fire above $160,000, so it never protected anyone. Both
bounds are now converted into the sending wallet's units first.

The "NaN" came from the i18n placeholder being typed {amount: number}.
formatDisplayAndWalletAmount returns a formatted string, so the call site
satisfied the type with Number("$0.07 (100 sats)"). The placeholder is
now {amount: string} and the formatted value passes through intact —
which also makes the mistake uncompilable rather than merely fixed.

That retyping surfaced a second call site in redeem-flow, which was
passing a bare 1 for "one cent"; it now formats the amount so the
message names a unit.

Also seeds TopupDetails.allowanceExhausted into the 23 locale files.
#700 added it to en/index.ts without regenerating the raw source, so
running update-translations here surfaced the gap and check-translation-
drift would otherwise fail on this branch.

Tests reproduce the production case: 50c to a 100-sat floor is allowed,
5c is still refused, the message names "100 sats" rather than NaN, and
the ceiling fires. Verified they fail against the old comparison.

699 tests pass.

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

linear Bot commented Aug 20, 2026

Copy link
Copy Markdown

ENG-556

Dread and others added 4 commits August 20, 2026 14:37
…rule

Review fixes for #706.

- The bounds were converted but left fractional, while the number pad only
  accepts whole minor units, and the message rendered a *rounded* version of
  that fractional bound — so the app could name a minimum it then refused.
  Strike's 100-sat floor at $64,000/BTC is 6.4c: the validator rejected 6c,
  the message read "minimum amount $0.06", the user typed 6c, refused again.
  Quantize outward (ceil the minimum, floor the maximum) and name the
  quantized value, so the amount in the message is exactly the smallest
  (largest) entry that is accepted. Float noise is stripped before
  quantizing: 100 sats at $70,000/BTC computes to 7.000000000000001c, and a
  naive ceil would name 8c as the floor of a bound that is really 7c.

- Lift lnurlBoundInWalletUnits next to resolveRecipientCap in
  max-send-amount.ts and call it from both the MAX chip and this check,
  replacing a local satBound/inWalletUnits pair that re-implemented
  toBtcMoneyAmount with a divergent currencyCode ("SAT" vs "BTC").

- Convert through paymentDetail.convertMoneyAmount — the same function
  settlementAmount was derived from, matching the sibling call in
  send-bitcoin-details-screen.tsx — so both sides of the comparison come
  from one source.

- Tests now probe the bounds themselves (ceil-1 / ceil / floor / floor+1),
  add non-integral and float-noise rate cases asserting the amount named in
  the error is itself accepted when re-entered, run every case for USDT as
  well as USD, and assert on the formatter's arguments instead of a string
  the mock fabricates — production renders a BTC wallet amount as "₿100",
  never "100 sats".

- Add __tests__/components/redeem-flow-infor-error.spec.tsx: the redeem
  flow's one-cent threshold message had no coverage anywhere.

- Retype minAmountInvoiceError/maxAmountInvoiceError to {amount: string} in
  the 23 translated locale files, so the corpus matches en.json.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_016MsAGwtS4sNodzWu2VMTKR
Review fixes for the LNURL bounds check.

Enforce on the sat axis. The receiver enforces sats and the request is
built in sats (send-bitcoin-details-screen converts unitOfAccountAmount
to BTC and asks for exactly that many), but the check converted the sat
bound into whole wallet cents and compared it against settlementAmount.
That amount is FRACTIONAL whenever the number pad is denominated in
display currency -- the default, since the pad is seeded with
zeroDisplayAmount and use-price-conversion only rounds when the target
is BTC. JMD display, BTC $65,000, J$158.5/USD, 100-sat floor: J$11.00 is
107 sats, comfortably over the floor, yet 6.94c < 7c refused it. Same
dead end as before, one dimension out. Comparing sats also removes the
crossed-bound case where a band narrower than one cent made 6c "below
the minimum" and 7c "above the maximum".

Quote in the pad's units. lnurlBoundInWalletUnits now backs the MESSAGE
only, pointed at unitOfAccountAmount.currency, so the amount named is
the smallest (largest) entry the pad can actually produce that the
receiver accepts.

Name a cash bound once. A USDT wallet amount renders as USD, but
getSecondaryAmountIfCurrencyIsDifferent compares walletAmount.currency
("USDT") with displayAmount.currencyCode ("USD"), so under a USD display
currency the message printed the same figure twice: "minimum amount
$0.07 ($0.07 USD)". Skip the secondary when both sides render as one
currency.

Tests:
- Display-currency pad cases with a real cross rate (JMD, 158.5 minor
  per cent) for both cash wallets: J$11.00 is allowed, the floor and
  ceiling the message names are accepted when re-entered, and the
  settlement amount is asserted fractional so the case cannot silently
  drift back onto the whole-cent axis.
- makeConvert is now a true three-way converter that rounds only BTC
  targets, mirroring use-price-conversion; settlementAmount is derived
  through it rather than hand-written.
- The format mocks reimplement use-display-currency's rules (USD suffix
  on USDT, secondary-amount selection) instead of reading displayAmount
  alone, so the duplication is observable; a test asserts the bound is
  named exactly once.
- resolveRecipientCap gains a fractional-rate case (100 sats at 0.065
  cents/sat -> 6), which fails without the floor wiring.

Verified each fix by reverting it and watching the new tests fail.
The amount toggle flips the pad into the wallet's own minor units while
the display currency stays JMD. That is the one reachable combination
where describeBound hands formatDisplayAndWalletAmount a wallet-currency
primaryAmount and takes the other formatting branch — untested until now,
and routine for a JMD-display user.

Covers both halves: the refusal names a bound with no NaN or undefined in
it, and the amount it names is itself accepted when re-entered. The
round-trip is the part that matters — a message quoting a figure the
validator then rejects is the dead end this PR already fixed once.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016MsAGwtS4sNodzWu2VMTKR
The spell check flags the FILENAME. typos.toml already allowlists the
identifier InforError, with a comment saying the component rename is a
deferred cross-file refactor — but a kebab-case filename splits it into
the bare word 'infor', which that entry does not cover.

Naming the file after what it asserts avoids propagating the misspelling
into a second place while the component keeps its name. The import inside
the file still refers to the real identifier, which the allowlist covers.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NEoz7nBtdtsHyuYG5wNPQV
@islandbitcoin
islandbitcoin merged commit d1e0263 into main Aug 21, 2026
10 checks passed
islandbitcoin added a commit that referenced this pull request Aug 24, 2026
…708)

* fix(send): disclose when the network fee is deducted from the amount

Fixes the actionable half of #694.

On external sends from cash wallets, IBEX's pre-send estimate for some
routes is 0 while settlement deducts the real routing fee FROM THE
AMOUNT: the repro was a $1.10 send that displayed "$0.00" fee, debited
$1.10, and delivered $1.07. The app cannot conjure the true fee pre-send
— IBEX does not provide it on those routes — so an unqualified $0.00 is
a claim the settlement then breaks, and the customer discovers the fee on
the recipient's side.

The confirmation screen now renders, under exactly that case, the note:
"The network fee is deducted from the amount — the recipient may receive
slightly less."

The predicate (fee-from-amount.logic.ts) discloses only on a PROBED zero
from a cash wallet on an external send, and each exclusion is a decision:
- intraledger stays silent because free is TRUE there, and crying wolf
  teaches users to ignore the caveat exactly where it matters
- BTC-wallet sends stay silent because their probes price the actual
  route — a zero there is a genuinely free path
- loading/error/unset stay silent because those states already carry
  their own caveats
A rare genuinely-free external route reads the soft copy — a mild false
positive, priced against the current false NEGATIVE.

i18n: key added at the source (app/i18n/en/index.ts), types and raw
exports regenerated via yarn update-translations, all 23 locales filled
(Spanish translated, others English fallback, matching #706's
convention). Drift check green.

Deliberately NOT in this PR: making the probe honest server-side (IBEX
does not expose the fee on these routes) and showing the actual settled
fee in the transaction detail — tracked in the issue as follow-ups.

88 suites / 867 tests green; tsc and eslint clean.

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

* fix(send): review fixes — verify Flash-to-Flash probes 0, suppress by payee node, type paymentType, render tests

Applies the three review findings on #708:

1. Render-level disclosure tests. The predicate was fully unit-tested but
   nothing asserted the component actually renders the caveat, so a wiring
   regression (e.g. passing fee.amount, the object, instead of
   fee.amount?.amount) would silently kill the feature with every test
   green. ConfirmationWalletFee.test.tsx now pins a probed-zero render
   showing the disclosure, a priced-fee render omitting it, and the
   Flash-node suppression end to end (mutation-tested: breaking the
   feeAmount wiring fails the probed-zero case).

2. paymentType is now the PaymentType union BasePaymentDetail uses,
   compared against PaymentType.Intraledger, so the predicate's most
   safety-critical exclusion is compiler-checked instead of stringly typed.

3. The "rare genuinely-free external route" framing was unverified — and
   turned out wrong. Verified live on the Test instance (2026-08-24):
   minting a Flash-internal USD invoice and probing it via
   lnUsdInvoiceFeeProbe returns a SET fee of 0 (the backend probe is a
   blind pass-through to IBEX estimate-fee, no internal-invoice
   special-casing — flash ln-usd-invoice-fee-probe.ts). Without a guard the
   caveat would fire on every Flash-to-Flash invoice payment, teaching
   users to ignore it exactly where it matters. The predicate now
   suppresses when the held bolt11's payee node pubkey is one of the
   instance's own lnNodePubkeys (new galoy-instances field; globals.nodesIds
   is empty on prod and test, verified live, so the ids ship as config).
   Test's node id is pinned and verified (IBEX_SB); Main's list is
   deliberately empty until someone with a prod account decodes a prod
   receive invoice — recipe in galoy-instances.ts. Suppression fails open:
   no invoice, undecodable invoice, or an empty list all still disclose.

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

* fix(send): pin the verified prod node for Flash-to-Flash suppression, memoize invoice decode

Round-2 review fixes for #708:

- Main's lnNodePubkeys was empty, leaving the Flash-to-Flash caveat
  suppression inert on prod — the disclosure fired on every prod
  Flash-to-Flash invoice payment despite full-amount delivery. Pinned
  03501a74…ac106 (IBEX_Ops1), verified 2026-08-24 by minting five live
  prod invoices via the LNURL-pay callback across two accounts and four
  amounts (1 to 50,000 sats); all decode to this single payee. Tests now
  decode a real prod invoice and fail if the pin regresses or drifts.

- payeeNodePubkey ran eagerly on every render, re-doing sync ECDSA
  pubkey recovery on each fee/quote state transition. Memoized on
  paymentRequest; a render test counts decode calls and fails on the
  eager version (verified: 2 calls un-memoized, 1 memoized).

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

* fix(i18n): keep the locale diff to the one key this PR introduces

The earlier locale fill rewrote the 23 translation JSONs through a JSON
parser, which silently DEDUPED a literal duplicate 'allowanceExhausted'
line that main carries — runtime-neutral (parsers collapse duplicates
anyway) but 23 files of unrelated diff bundled into a send-flow PR.

Restored main's exact bytes and re-inserted feeDeductedFromAmount as a
text edit. The translations diff vs main is now pure additions: one line
per file. Verified: zero deletion lines, all 23 files parse, drift check
green, 880 tests green.

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

---------

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.

2 participants