From e64a47ff969c1b09a2ec0c1a6719b7dae4cdd96d Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Tue, 5 Mar 2024 10:39:11 +0900 Subject: [PATCH] Allow reset boltcard on balance --- .../UIBoltcardBalanceController.cs | 17 ++++++++++- .../ViewModels/BalanceViewModel.cs | 1 + .../BoltcardBalance/Views/BalanceView.cshtml | 16 +++++----- .../BoltcardBalance/Views/ScanCard.cshtml | 29 ++++++++++++++----- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/BTCPayServer/Plugins/BoltcardBalance/Controllers/UIBoltcardBalanceController.cs b/BTCPayServer/Plugins/BoltcardBalance/Controllers/UIBoltcardBalanceController.cs index 254fc66fd..49b7954b0 100644 --- a/BTCPayServer/Plugins/BoltcardBalance/Controllers/UIBoltcardBalanceController.cs +++ b/BTCPayServer/Plugins/BoltcardBalance/Controllers/UIBoltcardBalanceController.cs @@ -5,8 +5,10 @@ using System.Threading.Tasks; using AngleSharp.Dom; using BTCPayServer.Client.Models; using BTCPayServer.Controllers; +using BTCPayServer.Controllers.Greenfield; using BTCPayServer.Data; using BTCPayServer.HostedServices; +using BTCPayServer.Models; using BTCPayServer.Plugins.BoltcardBalance.ViewModels; using BTCPayServer.Plugins.BoltcardFactory; using BTCPayServer.Services; @@ -87,7 +89,8 @@ namespace BTCPayServer.Plugins.BoltcardBalance.Controllers Currency = blob.Currency, AmountDue = blob.Limit - totalPaid, LNUrlBech32 = bech32LNUrl.AbsoluteUri, - LNUrlPay = Url.Action(nameof(UIBoltcardController.GetPayRequest), "UIBoltcard", new { p }, "lnurlp") + LNUrlPay = Url.Action(nameof(UIBoltcardController.GetPayRequest), "UIBoltcard", new { p }, "lnurlp"), + BoltcardKeysResetLink = $"boltcard://reset?url={GetBoltcardDeeplinkUrl(pp.Id, OnExistingBehavior.KeepVersion)}" }; foreach (var payout in payouts) { @@ -107,5 +110,17 @@ namespace BTCPayServer.Plugins.BoltcardBalance.Controllers return View($"{BoltcardBalancePlugin.ViewsDirectory}/BalanceView.cshtml", vm); } + + private string GetBoltcardDeeplinkUrl(string ppId, OnExistingBehavior onExisting) + { + var registerUrl = Url.Action(nameof(GreenfieldPullPaymentController.RegisterBoltcard), "GreenfieldPullPayment", + new + { + pullPaymentId = ppId, + onExisting = onExisting.ToString() + }, Request.Scheme, Request.Host.ToString()); + registerUrl = Uri.EscapeDataString(registerUrl); + return registerUrl; + } } } diff --git a/BTCPayServer/Plugins/BoltcardBalance/ViewModels/BalanceViewModel.cs b/BTCPayServer/Plugins/BoltcardBalance/ViewModels/BalanceViewModel.cs index 72be4274b..f8a6adf1e 100644 --- a/BTCPayServer/Plugins/BoltcardBalance/ViewModels/BalanceViewModel.cs +++ b/BTCPayServer/Plugins/BoltcardBalance/ViewModels/BalanceViewModel.cs @@ -17,6 +17,7 @@ namespace BTCPayServer.Plugins.BoltcardBalance.ViewModels public decimal AmountDue { get; set; } public List Transactions { get; set; } = new List(); public string LNUrlBech32 { get; set; } + public string BoltcardKeysResetLink { get; set; } public string LNUrlPay { get; set; } } diff --git a/BTCPayServer/Plugins/BoltcardBalance/Views/BalanceView.cshtml b/BTCPayServer/Plugins/BoltcardBalance/Views/BalanceView.cshtml index 72934706d..ab06831ef 100644 --- a/BTCPayServer/Plugins/BoltcardBalance/Views/BalanceView.cshtml +++ b/BTCPayServer/Plugins/BoltcardBalance/Views/BalanceView.cshtml @@ -16,6 +16,9 @@ + @@ -28,16 +31,13 @@
@DisplayFormatter.Currency(Model.AmountDue, Model.Currency)
-@*
- -
- *@ -
+
- diff --git a/BTCPayServer/Plugins/BoltcardBalance/Views/ScanCard.cshtml b/BTCPayServer/Plugins/BoltcardBalance/Views/ScanCard.cshtml index ec34c1d71..8e2a4bb56 100644 --- a/BTCPayServer/Plugins/BoltcardBalance/Views/ScanCard.cshtml +++ b/BTCPayServer/Plugins/BoltcardBalance/Views/ScanCard.cshtml @@ -63,6 +63,22 @@ document.getElementById("error").classList.add("d-none"); } } + function toggleDetails(className) + { + var el = document.getElementsByClassName("boltcard-details"); + for (var i = 0; i < el.length; i++) { + if (el[i].classList.contains(className)) { + if (el[i].classList.contains("d-none")) + el[i].classList.remove("d-none"); + else + el[i].classList.add("d-none"); + } + else + { + el[i].classList.add("d-none"); + } + } + } function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); @@ -86,14 +102,11 @@ }); 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"); - } + toggleDetails('lnurl-pay'); }); + document.getElementById("reset-button").addEventListener("click", function (e) { + toggleDetails('boltcard-reset'); + }); await uiDelay; setState("ShowBalance"); } @@ -197,7 +210,7 @@ catch (e) { handleError(e); } - //showBalance("lnurl://ewfw?p=test&c=test"); + // showBalance("lnurl://ewfw?p=test&c=test"); }); })();