mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
Triggering optional confirmation update only on Invoice details page
This commit is contained in:
committed by
Nicolas Dorier
parent
be844978c1
commit
9a2e1d43ea
@@ -84,6 +84,29 @@ namespace BTCPayServer.Controllers
|
|||||||
Current = !h.UnAssigned.HasValue
|
Current = !h.UnAssigned.HasValue
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
|
|
||||||
|
var updateConfirmationCountIfNeeded = invoice
|
||||||
|
.GetPayments()
|
||||||
|
.Select<PaymentEntity, Task>(async payment =>
|
||||||
|
{
|
||||||
|
var paymentNetwork = _NetworkProvider.GetNetwork(payment.GetCryptoCode());
|
||||||
|
var paymentData = payment.GetCryptoPaymentData();
|
||||||
|
if (paymentData is Payments.Bitcoin.BitcoinLikePaymentData onChainPaymentData)
|
||||||
|
{
|
||||||
|
int confirmationCount = 0;
|
||||||
|
if ((onChainPaymentData.ConfirmationCount < paymentNetwork.MaxTrackedConfirmation && payment.Accounted)
|
||||||
|
&& (onChainPaymentData.Legacy || invoice.MonitoringExpiration < DateTimeOffset.UtcNow))
|
||||||
|
// The confirmation count in the paymentData is not up to date
|
||||||
|
{
|
||||||
|
confirmationCount = (await ((ExplorerClientProvider)_ServiceProvider.GetService(typeof(ExplorerClientProvider))).GetExplorerClient(payment.GetCryptoCode())?.GetTransactionAsync(onChainPaymentData.Outpoint.Hash))?.Confirmations ?? 0;
|
||||||
|
onChainPaymentData.ConfirmationCount = confirmationCount;
|
||||||
|
payment.SetCryptoPaymentData(onChainPaymentData);
|
||||||
|
await _InvoiceRepository.UpdatePayments(new List<PaymentEntity> { payment });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.ToArray();
|
||||||
|
await Task.WhenAll(updateConfirmationCountIfNeeded);
|
||||||
|
|
||||||
var details = await InvoicePopulatePayments(invoice);
|
var details = await InvoicePopulatePayments(invoice);
|
||||||
model.CryptoPayments = details.CryptoPayments;
|
model.CryptoPayments = details.CryptoPayments;
|
||||||
model.OnChainPayments = details.OnChainPayments;
|
model.OnChainPayments = details.OnChainPayments;
|
||||||
@@ -127,19 +150,7 @@ namespace BTCPayServer.Controllers
|
|||||||
m.Crypto = payment.GetPaymentMethodId().CryptoCode;
|
m.Crypto = payment.GetPaymentMethodId().CryptoCode;
|
||||||
m.DepositAddress = onChainPaymentData.GetDestination(paymentNetwork);
|
m.DepositAddress = onChainPaymentData.GetDestination(paymentNetwork);
|
||||||
|
|
||||||
int confirmationCount = 0;
|
int confirmationCount = onChainPaymentData.ConfirmationCount;
|
||||||
if ((onChainPaymentData.ConfirmationCount < paymentNetwork.MaxTrackedConfirmation && payment.Accounted)
|
|
||||||
&& (onChainPaymentData.Legacy || invoice.MonitoringExpiration < DateTimeOffset.UtcNow)) // The confirmation count in the paymentData is not up to date
|
|
||||||
{
|
|
||||||
confirmationCount = (await ((ExplorerClientProvider)_ServiceProvider.GetService(typeof(ExplorerClientProvider))).GetExplorerClient(payment.GetCryptoCode())?.GetTransactionAsync(onChainPaymentData.Outpoint.Hash))?.Confirmations ?? 0;
|
|
||||||
onChainPaymentData.ConfirmationCount = confirmationCount;
|
|
||||||
payment.SetCryptoPaymentData(onChainPaymentData);
|
|
||||||
await _InvoiceRepository.UpdatePayments(new List<PaymentEntity> { payment });
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
confirmationCount = onChainPaymentData.ConfirmationCount;
|
|
||||||
}
|
|
||||||
if (confirmationCount >= paymentNetwork.MaxTrackedConfirmation)
|
if (confirmationCount >= paymentNetwork.MaxTrackedConfirmation)
|
||||||
{
|
{
|
||||||
m.Confirmations = "At least " + (paymentNetwork.MaxTrackedConfirmation);
|
m.Confirmations = "At least " + (paymentNetwork.MaxTrackedConfirmation);
|
||||||
@@ -157,7 +168,7 @@ namespace BTCPayServer.Controllers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var lightningPaymentData = (Payments.Lightning.LightningLikePaymentData)paymentData;
|
var lightningPaymentData = (LightningLikePaymentData)paymentData;
|
||||||
return new InvoiceDetailsModel.OffChainPayment()
|
return new InvoiceDetailsModel.OffChainPayment()
|
||||||
{
|
{
|
||||||
Crypto = paymentNetwork.CryptoCode,
|
Crypto = paymentNetwork.CryptoCode,
|
||||||
@@ -576,11 +587,11 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
new PaymentMethodId(network.CryptoCode, PaymentTypes.BTCLike),
|
new PaymentMethodId(network.CryptoCode, PaymentTypes.BTCLike),
|
||||||
new PaymentMethodId(network.CryptoCode, PaymentTypes.LightningLike)
|
new PaymentMethodId(network.CryptoCode, PaymentTypes.LightningLike)
|
||||||
}).Select(id => new SelectListItem(id.ToString(true), id.ToString(false))),
|
}).Select(id => new SelectListItem(id.ToString(true), id.ToString(false))),
|
||||||
nameof(SelectListItem.Value),
|
nameof(SelectListItem.Value),
|
||||||
nameof(SelectListItem.Text));
|
nameof(SelectListItem.Text));
|
||||||
|
|
||||||
return View(new CreateInvoiceModel() { Stores = stores, AvailablePaymentMethods = paymentMethods});
|
return View(new CreateInvoiceModel() { Stores = stores, AvailablePaymentMethods = paymentMethods });
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
@@ -591,16 +602,16 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
var stores = await _StoreRepository.GetStoresByUserId(GetUserId());
|
var stores = await _StoreRepository.GetStoresByUserId(GetUserId());
|
||||||
model.Stores = new SelectList(stores, nameof(StoreData.Id), nameof(StoreData.StoreName), model.StoreId);
|
model.Stores = new SelectList(stores, nameof(StoreData.Id), nameof(StoreData.StoreName), model.StoreId);
|
||||||
|
|
||||||
var paymentMethods = new SelectList(_NetworkProvider.GetAll().SelectMany(network => new[]
|
var paymentMethods = new SelectList(_NetworkProvider.GetAll().SelectMany(network => new[]
|
||||||
{
|
{
|
||||||
new PaymentMethodId(network.CryptoCode, PaymentTypes.BTCLike),
|
new PaymentMethodId(network.CryptoCode, PaymentTypes.BTCLike),
|
||||||
new PaymentMethodId(network.CryptoCode, PaymentTypes.LightningLike)
|
new PaymentMethodId(network.CryptoCode, PaymentTypes.LightningLike)
|
||||||
}).Select(id => new SelectListItem(id.ToString(true), id.ToString(false))),
|
}).Select(id => new SelectListItem(id.ToString(true), id.ToString(false))),
|
||||||
nameof(SelectListItem.Value),
|
nameof(SelectListItem.Value),
|
||||||
nameof(SelectListItem.Text));
|
nameof(SelectListItem.Text));
|
||||||
model.AvailablePaymentMethods = paymentMethods;
|
model.AvailablePaymentMethods = paymentMethods;
|
||||||
|
|
||||||
var store = stores.FirstOrDefault(s => s.Id == model.StoreId);
|
var store = stores.FirstOrDefault(s => s.Id == model.StoreId);
|
||||||
if (store == null)
|
if (store == null)
|
||||||
{
|
{
|
||||||
@@ -622,7 +633,7 @@ namespace BTCPayServer.Controllers
|
|||||||
ModelState.AddModelError(nameof(model.StoreId), "You need to configure the derivation scheme in order to create an invoice");
|
ModelState.AddModelError(nameof(model.StoreId), "You need to configure the derivation scheme in order to create an invoice");
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (StatusMessage != null)
|
if (StatusMessage != null)
|
||||||
{
|
{
|
||||||
@@ -648,7 +659,7 @@ namespace BTCPayServer.Controllers
|
|||||||
BuyerEmail = model.BuyerEmail,
|
BuyerEmail = model.BuyerEmail,
|
||||||
SupportedTransactionCurrencies = model.SupportedTransactionCurrencies?.ToDictionary(s => s, s => new InvoiceSupportedTransactionCurrency()
|
SupportedTransactionCurrencies = model.SupportedTransactionCurrencies?.ToDictionary(s => s, s => new InvoiceSupportedTransactionCurrency()
|
||||||
{
|
{
|
||||||
Enabled =true
|
Enabled = true
|
||||||
})
|
})
|
||||||
}, store, HttpContext.Request.GetAbsoluteRoot(), cancellationToken: cancellationToken);
|
}, store, HttpContext.Request.GetAbsoluteRoot(), cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user