Skip to content

fix: on-chain BIP21 URI emits amount=NaN when tip is absent - #90

Open
tnarnold wants to merge 1 commit into
coinos:masterfrom
tnarnold:bip21-nan-fix
Open

fix: on-chain BIP21 URI emits amount=NaN when tip is absent#90
tnarnold wants to merge 1 commit into
coinos:masterfrom
tnarnold:bip21-nan-fix

Conversation

@tnarnold

Copy link
Copy Markdown

generate() normalizes amount and tip into locals (invoices.ts:53-54) but passes the raw invoice object to bip21(), so invoice.tip stays undefined when the client omits a tip — and amount + undefined is NaN, producing bitcoin:<addr>?amount=NaN. Lightning is unaffected because it uses the already-normalized locals.

Two symptoms, both reproduced on regtest:

  • bitcoin/liquid without a tip: the QR carries an invalid amount, so wallets drop it and the payer re-types it by hand.
  • fiat invoices: amount is recomputed from fiat/rate only in the local, so the URI ships with no amount at all — the point-of-sale flow.

The fix passes the normalized values to bip21() and makes tip defensively optional in utils.bip21.

Verified on regtest: no tip → 0.00050000; tip 1000 → 0.00051000; fiat 2 USD → 0.00002579; no amount → bare address.

generate() normalizes `amount` and `tip` into locals (invoices.ts:53-54)
but passes the raw `invoice` object to bip21(), so `invoice.tip` stays
undefined when the client omits a tip — and `amount + undefined` is NaN,
producing "bitcoin:<addr>?amount=NaN". Lightning is unaffected because it
uses the already-normalized locals.

Two symptoms, both reproduced on regtest:
- bitcoin/liquid without a tip: the QR carries an invalid amount, so
  wallets drop it and the payer re-types it by hand.
- fiat invoices: `amount` is recomputed from fiat/rate only in the local,
  so the URI ships with no amount at all — the point-of-sale flow.

Pass the normalized values to bip21() and make tip defensively optional.

Verified on regtest: no tip -> 0.00050000; tip 1000 -> 0.00051000;
fiat 2 USD -> 0.00002579; no amount -> bare address.
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