From f08608f76649391176bd5904d7b8589336962d7e Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 21 Feb 2024 17:45:15 +0900 Subject: [PATCH] Add lnurlpay to balance --- .../UIBoltcardBalanceController.cs | 7 +++--- .../ViewModels/BalanceViewModel.cs | 2 +- .../BoltcardBalance/Views/BalanceView.cshtml | 23 +++++++++++++------ .../BoltcardBalance/Views/ScanCard.cshtml | 13 ++++++++++- .../Controllers/UIBoltcardTopUpController.cs | 2 +- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/BTCPayServer/Plugins/BoltcardBalance/Controllers/UIBoltcardBalanceController.cs b/BTCPayServer/Plugins/BoltcardBalance/Controllers/UIBoltcardBalanceController.cs index 5abcfbdff..083e17e2b 100644 --- a/BTCPayServer/Plugins/BoltcardBalance/Controllers/UIBoltcardBalanceController.cs +++ b/BTCPayServer/Plugins/BoltcardBalance/Controllers/UIBoltcardBalanceController.cs @@ -57,10 +57,10 @@ namespace BTCPayServer.Plugins.BoltcardBalance.Controllers var registration = await _dbContextFactory.GetBoltcardRegistration(issuerKey, boltData, true); if (registration is null) return NotFound(); - return await GetBalanceView(registration.PullPaymentId); + return await GetBalanceView(registration.PullPaymentId, p); } [NonAction] - public async Task GetBalanceView(string ppId) + public async Task GetBalanceView(string ppId, string p) { using var ctx = _dbContextFactory.CreateContext(); var pp = await ctx.PullPayments.FindAsync(ppId); @@ -84,7 +84,8 @@ namespace BTCPayServer.Plugins.BoltcardBalance.Controllers var vm = new BalanceViewModel() { Currency = blob.Currency, - AmountDue = blob.Limit - totalPaid + AmountDue = blob.Limit - totalPaid, + LNUrlPay = Url.Action(nameof(UIBoltcardController.GetPayRequest), "UIBoltcard", new { p }, "lnurlp") }; foreach (var payout in payouts) { diff --git a/BTCPayServer/Plugins/BoltcardBalance/ViewModels/BalanceViewModel.cs b/BTCPayServer/Plugins/BoltcardBalance/ViewModels/BalanceViewModel.cs index 4ed2235f9..2c9995f54 100644 --- a/BTCPayServer/Plugins/BoltcardBalance/ViewModels/BalanceViewModel.cs +++ b/BTCPayServer/Plugins/BoltcardBalance/ViewModels/BalanceViewModel.cs @@ -16,7 +16,7 @@ namespace BTCPayServer.Plugins.BoltcardBalance.ViewModels public string Currency { get; set; } public decimal AmountDue { get; set; } public List Transactions { get; set; } = new List(); + public string LNUrlPay { get; set; } - } } diff --git a/BTCPayServer/Plugins/BoltcardBalance/Views/BalanceView.cshtml b/BTCPayServer/Plugins/BoltcardBalance/Views/BalanceView.cshtml index f82ae55ac..9cf4fdfab 100644 --- a/BTCPayServer/Plugins/BoltcardBalance/Views/BalanceView.cshtml +++ b/BTCPayServer/Plugins/BoltcardBalance/Views/BalanceView.cshtml @@ -11,20 +11,29 @@
-
+
@DisplayFormatter.Currency(Model.AmountDue, Model.Currency)
+
+ +
+
diff --git a/BTCPayServer/Plugins/BoltcardBalance/Views/ScanCard.cshtml b/BTCPayServer/Plugins/BoltcardBalance/Views/ScanCard.cshtml index 9b8ec7bb2..8d3cfbc19 100644 --- a/BTCPayServer/Plugins/BoltcardBalance/Views/ScanCard.cshtml +++ b/BTCPayServer/Plugins/BoltcardBalance/Views/ScanCard.cshtml @@ -67,6 +67,17 @@ setState("WaitingForCard"); document.getElementById("balance-table").innerHTML = ""; }); + + document.getElementById("lnurlwithdraw-button").addEventListener("click", function (e) { + var el = document.getElementsByClassName("lnurl-pay"); + for (var i = 0; i < el.length; i++) { + if (el[i].classList.contains("d-none")) + el[i].classList.remove("d-none"); + else + el[i].classList.add("d-none"); + } + }); + setState("ShowBalance"); } else { @@ -142,7 +153,7 @@ } } delegate('click', "#start-scan-btn", startScan); - // showBalance("lnurl://ewfw?p=test&c=test"); + //showBalance("lnurl://ewfw?p=test&c=test"); }); })(); diff --git a/BTCPayServer/Plugins/BoltcardTopUp/Controllers/UIBoltcardTopUpController.cs b/BTCPayServer/Plugins/BoltcardTopUp/Controllers/UIBoltcardTopUpController.cs index 5b6cbad83..d8b8e3611 100644 --- a/BTCPayServer/Plugins/BoltcardTopUp/Controllers/UIBoltcardTopUpController.cs +++ b/BTCPayServer/Plugins/BoltcardTopUp/Controllers/UIBoltcardTopUpController.cs @@ -201,7 +201,7 @@ namespace BTCPayServer.Plugins.BoltcardTopUp.Controllers await ctx.Payouts.AddAsync(payout); await ctx.SaveChangesAsync(); _boltcardBalanceController.ViewData["NoCancelWizard"] = true; - return await _boltcardBalanceController.GetBalanceView(registration.PullPaymentId); + return await _boltcardBalanceController.GetBalanceView(registration.PullPaymentId, p); } } }