fix: on-chain BIP21 URI emits amount=NaN when tip is absent - #90
Open
tnarnold wants to merge 1 commit into
Open
Conversation
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.
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.
generate() normalizes
amountandtipinto locals (invoices.ts:53-54) but passes the rawinvoiceobject to bip21(), soinvoice.tipstays undefined when the client omits a tip — andamount + undefinedis NaN, producingbitcoin:<addr>?amount=NaN. Lightning is unaffected because it uses the already-normalized locals.Two symptoms, both reproduced on regtest:
amountis 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 makestipdefensively optional inutils.bip21.Verified on regtest: no tip →
0.00050000; tip 1000 →0.00051000; fiat 2 USD →0.00002579; no amount → bare address.