From de24a6e71b3f14272a803f74563ea2b9689c5cec Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Fri, 12 Aug 2022 20:10:44 +0200 Subject: [PATCH] LNURL controller refactoring By moving the `amount is null` check up, this prevents cases in which the `paymentMethodDetails.GeneratedBoltAmount != amount` check fails because of amount being null. --- BTCPayServer/Controllers/UILNURLController.cs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/BTCPayServer/Controllers/UILNURLController.cs b/BTCPayServer/Controllers/UILNURLController.cs index af40d3f17..a3c2c4138 100644 --- a/BTCPayServer/Controllers/UILNURLController.cs +++ b/BTCPayServer/Controllers/UILNURLController.cs @@ -524,8 +524,21 @@ namespace BTCPayServer Url = _linkGenerator.GetUriByAction(HttpContext, "InvoiceReceipt", "UIInvoice", new { invoiceId}) }; } - if (amount.HasValue && string.IsNullOrEmpty(paymentMethodDetails.BOLT11) || - paymentMethodDetails.GeneratedBoltAmount != amount) + + if (amount is null) + { + return Ok(new LNURLPayRequest + { + Tag = "payRequest", + MinSendable = min, + MaxSendable = max, + CommentAllowed = lnurlSupportedPaymentMethod.LUD12Enabled ? 2000 : 0, + Metadata = metadata, + Callback = new Uri(Request.GetCurrentUrl()) + }); + } + + if (string.IsNullOrEmpty(paymentMethodDetails.BOLT11) || paymentMethodDetails.GeneratedBoltAmount != amount) { var client = _lightningLikePaymentHandler.CreateLightningClient( @@ -589,7 +602,7 @@ namespace BTCPayServer }); } - if (amount.HasValue && paymentMethodDetails.GeneratedBoltAmount == amount) + if (paymentMethodDetails.GeneratedBoltAmount == amount) { if (lnurlSupportedPaymentMethod.LUD12Enabled && paymentMethodDetails.ProvidedComment != comment) { @@ -604,19 +617,6 @@ namespace BTCPayServer SuccessAction = successAction }); } - - if (amount is null) - { - return Ok(new LNURLPayRequest - { - Tag = "payRequest", - MinSendable = min, - MaxSendable = max, - CommentAllowed = lnurlSupportedPaymentMethod.LUD12Enabled ? 2000 : 0, - Metadata = metadata, - Callback = new Uri(Request.GetCurrentUrl()) - }); - } } return BadRequest(new LNUrlStatusResponse