wipe option on balance page

This commit is contained in:
Kukks 2024-02-29 09:15:24 +00:00
parent 27150bcd4e
commit 2c2b6b8890
No known key found for this signature in database
GPG key ID: 8E5530D9D1C93097
5 changed files with 98 additions and 57 deletions

View file

@ -7,6 +7,7 @@ using BTCPayServer.Client.Models;
using BTCPayServer.Controllers; using BTCPayServer.Controllers;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.HostedServices; using BTCPayServer.HostedServices;
using BTCPayServer.NTag424;
using BTCPayServer.Plugins.BoltcardBalance.ViewModels; using BTCPayServer.Plugins.BoltcardBalance.ViewModels;
using BTCPayServer.Plugins.BoltcardFactory; using BTCPayServer.Plugins.BoltcardFactory;
using BTCPayServer.Services; using BTCPayServer.Services;
@ -57,10 +58,14 @@ namespace BTCPayServer.Plugins.BoltcardBalance.Controllers
var registration = await _dbContextFactory.GetBoltcardRegistration(issuerKey, boltData, true); var registration = await _dbContextFactory.GetBoltcardRegistration(issuerKey, boltData, true);
if (registration is null) if (registration is null)
return NotFound(); return NotFound();
return await GetBalanceView(registration.PullPaymentId, p);
var keys = issuerKey.CreatePullPaymentCardKey(registration.UId, registration.Version, registration.PullPaymentId).DeriveBoltcardKeys(issuerKey);
var result = await GetBalanceView(registration.PullPaymentId, p, keys);
return result;
} }
[NonAction] [NonAction]
public async Task<IActionResult> GetBalanceView(string ppId, string p) public async Task<IActionResult> GetBalanceView(string ppId, string p, BoltcardKeys keys)
{ {
using var ctx = _dbContextFactory.CreateContext(); using var ctx = _dbContextFactory.CreateContext();
var pp = await ctx.PullPayments.FindAsync(ppId); var pp = await ctx.PullPayments.FindAsync(ppId);
@ -105,6 +110,7 @@ namespace BTCPayServer.Plugins.BoltcardBalance.Controllers
Status = PayoutState.Completed Status = PayoutState.Completed
}); });
vm.Keys = keys;
return View($"{BoltcardBalancePlugin.ViewsDirectory}/BalanceView.cshtml", vm); return View($"{BoltcardBalancePlugin.ViewsDirectory}/BalanceView.cshtml", vm);
} }
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
using BTCPayServer.NTag424;
namespace BTCPayServer.Plugins.BoltcardBalance.ViewModels namespace BTCPayServer.Plugins.BoltcardBalance.ViewModels
{ {
@ -19,5 +20,6 @@ namespace BTCPayServer.Plugins.BoltcardBalance.ViewModels
public string LNUrlBech32 { get; set; } public string LNUrlBech32 { get; set; }
public string LNUrlPay { get; set; } public string LNUrlPay { get; set; }
public BoltcardKeys? Keys { get; set; }
} }
} }

View file

@ -1,73 +1,106 @@
@using BTCPayServer.Plugins.BoltcardBalance.ViewModels @using BTCPayServer.Plugins.BoltcardBalance.ViewModels
@using BTCPayServer.Services @using BTCPayServer.Services
@using Newtonsoft.Json.Linq
@using BTCPayServer.Components.QRCode
@using NBitcoin.DataEncoders
@inject DisplayFormatter DisplayFormatter @inject DisplayFormatter DisplayFormatter
@model BalanceViewModel @model BalanceViewModel
@{ @{
Layout = null; Layout = null;
} }
<div class="col col-12 col-lg-12 mb-4"> <div class="col col-12 col-lg-12 mb-4">
<div class="bg-tile h-100 m-0 p-3 p-sm-5 rounded"> <div class="bg-tile h-100 m-0 p-3 p-sm-5 rounded">
<nav id="wizard-navbar"> <nav id="wizard-navbar">
@if (this.ViewData["NoCancelWizard"] is not true) @if (this.ViewData["NoCancelWizard"] is not true)
{ {
<button type="button" class="btn btn-secondary only-for-js mt-4" id="lnurlwithdraw-button"> <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> <span class="fa fa-qrcode fa-2x" title="Deposit"></span>
</button> </button>
<a href="#" id="CancelWizard" class="cancel mt-4"> <a href="#" id="CancelWizard" class="cancel mt-4">
<vc:icon symbol="close" /> <vc:icon symbol="close" />
</a> </a>
} }
</nav> </nav>
<div class="d-flex justify-content-center"> <div class="d-flex justify-content-center">
<div class="d-flex flex-column justify-content-center align-items-center"> <div class="d-flex flex-column justify-content-center align-items-center">
<dl class="mb-0 mt-md-4"> <dl class="mb-0 mt-md-4">
<div class="d-flex d-print-inline-block flex-column mb-4"> <div class="d-flex d-print-inline-block flex-column mb-4">
<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> <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> </div>
</dl> </dl>
@* <div class="lnurl-pay d-none"> @* <div class="lnurl-pay d-none">
<vc:qr-code data="@Model.LNUrlPay" /> <vc:qr-code data="@Model.LNUrlPay" />
</div> </div>
<div class="lnurl-pay d-flex gap-3 mt-3 mt-sm-0 d-none"> <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> <a class="btn btn-primary" target="_blank" href="@Model.LNUrlPay">Deposit from Wallet... (LNURLPay)</a>
</div> *@ </div> *@
<div class="lnurl-pay d-none"> <div class="lnurl-pay d-none">
<vc:qr-code data="@Model.LNUrlBech32" /> <vc:qr-code data="@Model.LNUrlBech32" />
</div> </div>
<div class="lnurl-pay d-flex gap-3 mt-3 mt-sm-0 d-none"> <div class="lnurl-pay 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> <a class="btn btn-primary" target="_blank" href="@Model.LNUrlBech32">Deposit from Wallet...</a>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
@if (Model.Transactions.Any()) @if (Model.Transactions.Any())
{ {
<div class="col col-12 col-lg-12 mb-4"> <div class="col col-12 col-lg-12 mb-4">
<div class="bg-tile h-100 m-0 p-3 p-sm-5 rounded table-responsive"> <div class="bg-tile h-100 m-0 p-3 p-sm-5 rounded table-responsive">
<table class="table table-hover"> <table class="table table-hover">
<thead> <thead>
<tr> <tr>
<th class="date-col">Date</th> <th class="date-col">Date</th>
<th class="amount-col">Amount</th> <th class="amount-col">Amount</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (var tx in Model.Transactions) @foreach (var tx in Model.Transactions)
{ {
<tr> <tr>
<td class="date-col">@tx.Date.ToBrowserDate(ViewsRazor.DateDisplayFormat.Relative)</td> <td class="date-col">@tx.Date.ToBrowserDate(ViewsRazor.DateDisplayFormat.Relative)</td>
<td class="amount-col"> <td class="amount-col">
<span data-sensitive class="text-@(tx.Positive ? "success" : "danger")">@DisplayFormatter.Currency(tx.Balance, Model.Currency, DisplayFormatter.CurrencyFormat.Code)</span> <span data-sensitive class="text-@(tx.Positive ? "success" : "danger")">@DisplayFormatter.Currency(tx.Balance, Model.Currency, DisplayFormatter.CurrencyFormat.Code)</span>
</td> </td>
</tr> </tr>
} }
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
}
@if (Model.Keys is not null && Model.AmountDue <= 0)
{
var wipeContent = JObject.FromObject(new
{
version = 1,
action = "wipe",
K0 = Encoders.Hex.EncodeData(Model.Keys.AppMasterKey.ToBytes()).ToUpperInvariant(),
K1 = Encoders.Hex.EncodeData(Model.Keys.EncryptionKey.ToBytes()).ToUpperInvariant(),
K2 = Encoders.Hex.EncodeData(Model.Keys.AuthenticationKey.ToBytes()).ToUpperInvariant(),
K3 = Encoders.Hex.EncodeData(Model.Keys.K3.ToBytes()).ToUpperInvariant(),
K4 = Encoders.Hex.EncodeData(Model.Keys.K4.ToBytes()).ToUpperInvariant(),
}).ToString();
<h5 class="mb-3 mt-5">Wipe Bolt Card</h5>
<div class="payment-box mx-0">
<div class="qr-container" data-clipboard="@wipeContent">
@await Component.InvokeAsync("QRCode", new {data = wipeContent})
</div>
<div class="input-group mt-3">
<div class="form-floating">
<input id="Bolt-Wipe-Json" class="form-control-plaintext" readonly="readonly" value="@wipeContent">
<label for="Bolt-Wipe-Json">Bolt Card Wipe JSON</label>
</div>
<button type="button" class="btn btn-link" data-clipboard-target="#Bolt-Wipe-Json">
@await Component.InvokeAsync("Icon", new {symbol = "copy"})
</button>
</div>
</div>
} }

View file

@ -16,7 +16,7 @@
<script src="~/vendor/summernote/summernote-bs5.js" asp-append-version="true"></script> <script src="~/vendor/summernote/summernote-bs5.js" asp-append-version="true"></script>
} }
<form method="post" asp-route-appId="@Context.GetRouteValue("appId")" asp-action="UpdateBoltcardFactory"> <form method="post" asp-route-appId="@Context.GetRouteValue("appId")" asp-controller="UIBoltcardFactory" asp-action="UpdateBoltcardFactory">
<div class="sticky-header d-flex align-items-center justify-content-between"> <div class="sticky-header d-flex align-items-center justify-content-between">
<h2 class="mb-0">@ViewData["Title"]</h2> <h2 class="mb-0">@ViewData["Title"]</h2>
<div class="d-flex gap-3 mt-3 mt-sm-0"> <div class="d-flex gap-3 mt-3 mt-sm-0">

View file

@ -201,7 +201,7 @@ namespace BTCPayServer.Plugins.BoltcardTopUp.Controllers
await ctx.Payouts.AddAsync(payout); await ctx.Payouts.AddAsync(payout);
await ctx.SaveChangesAsync(); await ctx.SaveChangesAsync();
_boltcardBalanceController.ViewData["NoCancelWizard"] = true; _boltcardBalanceController.ViewData["NoCancelWizard"] = true;
return await _boltcardBalanceController.GetBalanceView(registration.PullPaymentId, p); return await _boltcardBalanceController.GetBalanceView(registration.PullPaymentId, p, null);
} }
} }
} }