mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Async dashboard (#3916)
* Dashboard: Load Lightning balance async, display default currency * Simplify approach, improve views and scripts * Async tiles Async tiles * Add period for app sales * Fix missing keypad view sales * Fix after rebase * Fix awaited call * Fix build Co-authored-by: Nicolas Dorier <nicolas.dorier@gmail.com>
This commit is contained in:
@@ -283,12 +283,7 @@ namespace BTCPayServer.Services.Apps
|
||||
var invoices = await GetInvoicesForApp(app);
|
||||
var paidInvoices = invoices.Where(IsPaid).ToArray();
|
||||
var series = paidInvoices
|
||||
.Where(entity => entity.InvoiceTime > DateTimeOffset.UtcNow - TimeSpan.FromDays(numberOfDays) && (
|
||||
// The POS data is present for the cart view, where multiple items can be bought
|
||||
!string.IsNullOrEmpty(entity.Metadata.PosData) ||
|
||||
// The item code should be present for all types other than the cart and keypad
|
||||
!string.IsNullOrEmpty(entity.Metadata.ItemCode)
|
||||
))
|
||||
.Where(entity => entity.InvoiceTime > DateTimeOffset.UtcNow - TimeSpan.FromDays(numberOfDays))
|
||||
.Aggregate(new List<InvoiceStatsItem>(), AggregateInvoiceEntitiesForStats(items))
|
||||
.GroupBy(entity => entity.Date)
|
||||
.Select(entities => new SalesStatsItem
|
||||
@@ -330,26 +325,7 @@ namespace BTCPayServer.Services.Apps
|
||||
{
|
||||
return (res, e) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(e.Metadata.ItemCode))
|
||||
{
|
||||
var item = items.FirstOrDefault(p => p.Id == e.Metadata.ItemCode);
|
||||
if (item == null) return res;
|
||||
|
||||
var fiatPrice = e.GetPayments(true).Sum(pay =>
|
||||
{
|
||||
var paymentMethodId = pay.GetPaymentMethodId();
|
||||
var value = pay.GetCryptoPaymentData().GetValue() - pay.NetworkFee;
|
||||
var rate = e.GetPaymentMethod(paymentMethodId).Rate;
|
||||
return rate * value;
|
||||
});
|
||||
res.Add(new InvoiceStatsItem
|
||||
{
|
||||
ItemCode = e.Metadata.ItemCode,
|
||||
FiatPrice = fiatPrice,
|
||||
Date = e.InvoiceTime.Date
|
||||
});
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(e.Metadata.PosData))
|
||||
if (!string.IsNullOrEmpty(e.Metadata.PosData))
|
||||
{
|
||||
// flatten single items from POS data
|
||||
var data = JsonConvert.DeserializeObject<PosAppData>(e.Metadata.PosData);
|
||||
@@ -370,6 +346,22 @@ namespace BTCPayServer.Services.Apps
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var fiatPrice = e.GetPayments(true).Sum(pay =>
|
||||
{
|
||||
var paymentMethodId = pay.GetPaymentMethodId();
|
||||
var value = pay.GetCryptoPaymentData().GetValue() - pay.NetworkFee;
|
||||
var rate = e.GetPaymentMethod(paymentMethodId).Rate;
|
||||
return rate * value;
|
||||
});
|
||||
res.Add(new InvoiceStatsItem
|
||||
{
|
||||
ItemCode = e.Metadata.ItemCode,
|
||||
FiatPrice = fiatPrice,
|
||||
Date = e.InvoiceTime.Date
|
||||
});
|
||||
}
|
||||
return res;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user