btcpayserver/BTCPayServer/Views/Shared/Bitcoin/ViewBitcoinLikePaymentData.cshtml
2024-04-04 16:31:04 +09:00

113 lines
5 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 IEnumerable<BTCPayServer.Services.Invoices.PaymentEntity>
@{
PayjoinInformation payjoinInformation = null;
var payments = Model
.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.Crypto = network.CryptoCode;
m.DepositAddress = BitcoinAddress.Create(payment.Destination, network.NBitcoinNetwork);
var confirmationCount = onChainPaymentData.ConfirmationCount;
if (confirmationCount >= network.MaxTrackedConfirmation)
{
m.Confirmations = "At least " + (network.MaxTrackedConfirmation);
}
else
{
m.Confirmations = confirmationCount.ToString(CultureInfo.InvariantCulture);
}
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(network.CryptoCode, onChainPaymentData.Outpoint.ToString());
m.Replaced = !payment.Accounted;
m.CryptoPaymentData = onChainPaymentData;
m.Value = payment.Value;
m.NetworkFee = payment.PaymentMethodFee;
m.PaymentProof = onChainPaymentData.Outpoint.ToString();
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">Crypto</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.Crypto</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.Crypto)</span>
@if (!string.IsNullOrEmpty(payment.AdditionalInformation))
{
<div>(@payment.AdditionalInformation)</div>
}
</td>
</tr>
}
</tbody>
</table>
</div>
</section>
}