btcpayserver/BTCPayServer/Views/Shared/Bitcoin/ViewBitcoinLikePaymentData.cshtml
2024-10-07 18:37:38 +09:00

109 lines
4.9 KiB
Text

@using System.Globalization
@using BTCPayServer.Payments
@using BTCPayServer.Payments.Bitcoin
@using BTCPayServer.Services
@using BTCPayServer.Services.Invoices
@using NBitcoin
@inject DisplayFormatter DisplayFormatter
@inject TransactionLinkProviders TransactionLinkProviders
@inject PaymentMethodHandlerDictionary handlers
@model InvoiceDetailsModel
@{
PayjoinInformation payjoinInformation = null;
var payments = Model.Payments
.Select(payment =>
{
if (!handlers.TryGetValue(payment.PaymentMethodId, out var h) || h is not BitcoinLikePaymentHandler handler)
return null;
var network = handler.Network;
var m = new OnchainPaymentViewModel();
var onChainPaymentData = handler.ParsePaymentDetails(payment.Details);
m.PaymentMethodId = payment.PaymentMethodId;
m.DepositAddress = BitcoinAddress.Create(payment.Destination, network.NBitcoinNetwork);
var confReq = NBXplorerListener.ConfirmationRequired(payment.InvoiceEntity, onChainPaymentData);
var confCount = onChainPaymentData.ConfirmationCount;
confCount = Math.Min(confReq, confCount);
m.Confirmations = $"{confCount} / {confReq}";
if (onChainPaymentData.PayjoinInformation is PayjoinInformation pj)
{
payjoinInformation = pj;
m.AdditionalInformation = "Original transaction";
}
if (payjoinInformation is PayjoinInformation &&
payjoinInformation.CoinjoinTransactionHash == onChainPaymentData?.Outpoint.Hash)
{
m.AdditionalInformation = "Payjoin transaction";
}
m.TransactionId = onChainPaymentData.Outpoint.Hash.ToString();
m.ReceivedTime = payment.ReceivedTime;
m.TransactionLink = TransactionLinkProviders.GetTransactionLink(payment.PaymentMethodId, onChainPaymentData.Outpoint.ToString());
m.Replaced = !payment.Accounted;
m.CryptoPaymentData = onChainPaymentData;
m.Value = payment.Value;
m.NetworkFee = payment.PaymentMethodFee;
m.PaymentProof = onChainPaymentData.Outpoint.ToString();
m.Currency = payment.Currency;
return m;
})
.Where(model => model != null)
.ToList();
}
@if (payments.Any())
{
var hasNetworkFee = payments.Sum(a => a.NetworkFee) > 0;
<section>
<h5>On-Chain Payments</h5>
<div class="invoice-payments table-responsive mt-0">
<table class="table table-hover mb-0">
<thead>
<tr>
<th class="w-75px">Payment Method</th>
<th class="w-100px">Index</th>
<th class="w-175px">Destination</th>
<th class="text-nowrap">Payment Proof</th>
@if (hasNetworkFee)
{
<th class="text-end">
Network Fee
<a href="https://docs.btcpayserver.org/FAQ/Stores/#allow-anyone-to-create-invoice" target="_blank" rel="noreferrer noopener" title="More information...">
<vc:icon symbol="info" />
</a>
</th>
}
<th class="text-end">Confirmations</th>
<th class="w-150px text-end">Paid</th>
</tr>
</thead>
<tbody>
@foreach (var payment in payments)
{
<tr style="@(payment.Replaced ? "text-decoration: line-through" : "")">
<td>@payment.PaymentMethodId</td>
<td>@(payment.CryptoPaymentData.KeyPath?.ToString()?? "Unknown")</td>
<td>
<vc:truncate-center text="@payment.DepositAddress.ToString()" classes="truncate-center-id" />
</td>
<td>
<vc:truncate-center text="@payment.PaymentProof" link="@payment.TransactionLink" classes="truncate-center-id" />
</td>
@if (hasNetworkFee)
{
<td class="text-end text-nowrap">@payment.NetworkFee</td>
}
<td class="text-end">@payment.Confirmations</td>
<td class="payment-value text-end text-nowrap">
<span data-sensitive class="text-success">@DisplayFormatter.Currency(payment.Value, payment.Currency)</span>
@if (!string.IsNullOrEmpty(payment.AdditionalInformation))
{
<div>(@payment.AdditionalInformation)</div>
}
</td>
</tr>
}
</tbody>
</table>
</div>
</section>
}