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.Data;
using BTCPayServer.HostedServices;
using BTCPayServer.NTag424;
using BTCPayServer.Plugins.BoltcardBalance.ViewModels;
using BTCPayServer.Plugins.BoltcardFactory;
using BTCPayServer.Services;
@ -57,10 +58,14 @@ namespace BTCPayServer.Plugins.BoltcardBalance.Controllers
var registration = await _dbContextFactory.GetBoltcardRegistration(issuerKey, boltData, true);
if (registration is null)
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]
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();
var pp = await ctx.PullPayments.FindAsync(ppId);
@ -105,6 +110,7 @@ namespace BTCPayServer.Plugins.BoltcardBalance.Controllers
Status = PayoutState.Completed
});
vm.Keys = keys;
return View($"{BoltcardBalancePlugin.ViewsDirectory}/BalanceView.cshtml", vm);
}
}

View file

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

View file

@ -1,5 +1,8 @@
@using BTCPayServer.Plugins.BoltcardBalance.ViewModels
@using BTCPayServer.Services
@using Newtonsoft.Json.Linq
@using BTCPayServer.Components.QRCode
@using NBitcoin.DataEncoders
@inject DisplayFormatter DisplayFormatter
@model BalanceViewModel
@ -71,3 +74,33 @@
</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>
}
<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">
<h2 class="mb-0">@ViewData["Title"]</h2>
<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.SaveChangesAsync();
_boltcardBalanceController.ViewData["NoCancelWizard"] = true;
return await _boltcardBalanceController.GetBalanceView(registration.PullPaymentId, p);
return await _boltcardBalanceController.GetBalanceView(registration.PullPaymentId, p, null);
}
}
}