btcpayserver/BTCPayServer/Views/Shared/Lightning/ViewLightningLikePaymentData.cshtml
Nicolas Dorier b4946f4db1
Fix divisibility in invoice details of lightning amounts (#6202)
* Fix divisibility in invoice details of lightning amounts

This PR will show 11 decimal in the invoice details for BTC amount
of lightning payment methods.

It also hacks around the fact that some
lightning clients don't create the requested amount of sats, which
resulted in over or under payments. (Blink not supporting msats, and
strike)

Now, In that case, a payment method fee (which can be negative) called tweak fee
will be added to the prompt.

We are also hiding this tweak fee from the user in the checkout page in
order to not disturb the UI with inconsequential fee of 0.000000001 sats.

* Only show 8 digits in checkout, even if amount is 11 digits
2024-09-12 12:43:08 +09:00

66 lines
2.4 KiB
Text

@using BTCPayServer.Payments
@using BTCPayServer.Payments.Lightning
@using BTCPayServer.Services
@using BTCPayServer.Components.TruncateCenter
@using BTCPayServer.Lightning
@using BTCPayServer.Services.Invoices
@inject DisplayFormatter DisplayFormatter
@inject PaymentMethodHandlerDictionary handlers
@inject PrettyNameProvider prettyName
@model IEnumerable<BTCPayServer.Services.Invoices.PaymentEntity>
@{
var payments = Model
.Select(payment =>
{
if (handlers.TryGet(payment.PaymentMethodId) is not ILightningPaymentHandler handler)
return null;
var offChainPaymentData = handler.ParsePaymentDetails(payment.Details);
return new OffChainPaymentViewModel
{
Type = prettyName.PrettyName(payment.PaymentMethodId),
BOLT11 = offChainPaymentData.BOLT11,
PaymentProof = offChainPaymentData.Preimage?.ToString(),
Amount = DisplayFormatter.Currency(payment.Value, handler.Network.CryptoCode, divisibility: payment.Divisibility)
};
})
.Where(model => model != null)
.ToList();
}
@if (payments.Any())
{
<section>
<h5>Off-Chain Payments</h5>
<div class="invoice-payments table-responsive mt-0">
<table class="table table-hover mb-0">
<thead>
<tr>
<th class="w-75px">Type</th>
<th class="w-175px">Destination</th>
<th class="text-nowrap">Payment Proof</th>
<th class="w-150px text-end">Paid</th>
</tr>
</thead>
<tbody>
@foreach (var payment in payments)
{
<tr>
<td>@payment.Type</td>
<td>
<vc:truncate-center text="@payment.BOLT11" classes="truncate-center-id" />
</td>
<td>
<vc:truncate-center text="@payment.PaymentProof" classes="truncate-center-id" />
</td>
<td class="payment-value text-end text-nowrap">
<span data-sensitive class="text-success">@payment.Amount</span>
</td>
</tr>
}
</tbody>
</table>
</div>
</section>
}