Allow reset boltcard on balance

This commit is contained in:
nicolas.dorier 2024-03-05 10:39:11 +09:00
parent 413b88faf1
commit e64a47ff96
No known key found for this signature in database
GPG key ID: 6618763EF09186FE
4 changed files with 46 additions and 17 deletions

View file

@ -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;
}
}
}

View file

@ -17,6 +17,7 @@ namespace BTCPayServer.Plugins.BoltcardBalance.ViewModels
public decimal AmountDue { get; set; }
public List<Transaction> Transactions { get; set; } = new List<Transaction>();
public string LNUrlBech32 { get; set; }
public string BoltcardKeysResetLink { get; set; }
public string LNUrlPay { get; set; }
}

View file

@ -16,6 +16,9 @@
<button type="button" class="btn btn-secondary only-for-js mt-4" id="lnurlwithdraw-button">
<span class="fa fa-qrcode fa-2x" title="Deposit"></span>
</button>
<button type="button" class="btn btn-outline-danger only-for-js mt-4" id="reset-button">
<span>Reset Boltcard</span>
</button>
<a href="#" id="CancelWizard" class="cancel mt-4">
<vc:icon symbol="close" />
</a>
@ -28,16 +31,13 @@
<dt class="h4 fw-semibold text-nowrap text-primary text-print-default order-2 order-sm-1 mb-1">@DisplayFormatter.Currency(Model.AmountDue, Model.Currency)</dt>
</div>
</dl>
@* <div class="lnurl-pay d-none">
<vc:qr-code data="@Model.LNUrlPay" />
</div>
<div class="lnurl-pay d-flex gap-3 mt-3 mt-sm-0 d-none">
<a class="btn btn-primary" target="_blank" href="@Model.LNUrlPay">Deposit from Wallet... (LNURLPay)</a>
</div> *@
<div class="lnurl-pay d-none">
<div class="lnurl-pay boltcard-details d-none">
<vc:qr-code data="@Model.LNUrlBech32" />
</div>
<div class="lnurl-pay d-flex gap-3 mt-3 mt-sm-0 d-none">
<div class="boltcard-reset boltcard-details d-flex gap-3 mt-3 mt-sm-0 d-none">
<a class="btn btn-outline-danger" target="_blank" href="@Model.BoltcardKeysResetLink">Reset Boltcard from app</a>
</div>
<div class="lnurl-pay boltcard-details d-flex gap-3 mt-3 mt-sm-0 d-none">
<a class="btn btn-primary" target="_blank" href="@Model.LNUrlBech32">Deposit from Wallet...</a>
</div>
</div>

View file

@ -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");
});
})();
</script>