mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-19 05:33:31 +01:00
Reporting fixes (#5410)
This commit is contained in:
parent
c8ee6ead0b
commit
8dadfa2111
@ -66,6 +66,10 @@ public partial class UIReportsController
|
||||
decimal randomValue = ((decimal)rand.NextDouble() * range) + from;
|
||||
return decimal.Round(randomValue, precision);
|
||||
}
|
||||
|
||||
var fiatCurrency = rand.NextSingle() > 0.2 ? "USD" : TakeOne("JPY", "EUR", "CHF");
|
||||
var cryptoCurrency = rand.NextSingle() > 0.2 ? "BTC" : TakeOne("LTC", "DOGE", "DASH");
|
||||
|
||||
if (f.Type == "invoice_id")
|
||||
return Encoders.Base58.EncodeData(GenerateBytes(20));
|
||||
if (f.Type == "boolean")
|
||||
@ -80,9 +84,9 @@ public partial class UIReportsController
|
||||
if (f.Name == "Address")
|
||||
return Encoders.Bech32("bc1").Encode(0, GenerateBytes(20));
|
||||
if (f.Name == "Crypto")
|
||||
return rand.NextSingle() > 0.2 ? "BTC" : TakeOne("LTC", "DOGE", "DASH");
|
||||
return cryptoCurrency;
|
||||
if (f.Name == "CryptoAmount")
|
||||
return GenerateDecimal(0.1m, 5m, 8);
|
||||
return DisplayFormatter.ToFormattedAmount(GenerateDecimal(0.1m, 5m, 8), cryptoCurrency);
|
||||
if (f.Name == "LightningAddress")
|
||||
return TakeOne("satoshi", "satosan", "satoichi") + "@bitcoin.org";
|
||||
if (f.Name == "BalanceChange")
|
||||
@ -98,24 +102,30 @@ public partial class UIReportsController
|
||||
if (f.Name == "Quantity")
|
||||
return TakeOne(1, 2, 3, 4, 5);
|
||||
if (f.Name == "Currency")
|
||||
return rand.NextSingle() > 0.2 ? "USD" : TakeOne("JPY", "EUR", "CHF");
|
||||
return fiatCurrency;
|
||||
if (f.Name == "CurrencyAmount")
|
||||
return row[fi - 1] switch
|
||||
{
|
||||
var curr = row[fi - 1]?.ToString();
|
||||
var value = curr switch
|
||||
{
|
||||
"USD" or "EUR" or "CHF" => GenerateDecimal(100.0m, 10_000m, 2),
|
||||
"JPY" => GenerateDecimal(10_000m, 1000_0000, 0),
|
||||
_ => GenerateDecimal(100.0m, 10_000m, 2)
|
||||
};
|
||||
return DisplayFormatter.ToFormattedAmount(value, curr);
|
||||
}
|
||||
if (f.Type == "tx_id")
|
||||
return Encoders.Hex.EncodeData(GenerateBytes(32));
|
||||
if (f.Name == "Rate")
|
||||
{
|
||||
return row[fi - 1] switch
|
||||
var curr = row[fi - 1]?.ToString();
|
||||
var value = curr switch
|
||||
{
|
||||
"USD" or "EUR" or "CHF" => GenerateDecimal(30_000m, 60_000, 2),
|
||||
"JPY" => GenerateDecimal(400_0000m, 1000_0000m, 0),
|
||||
_ => GenerateDecimal(30_000m, 60_000, 2)
|
||||
};
|
||||
return DisplayFormatter.ToFormattedAmount(value, curr);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public partial class UIReportsController : Controller
|
||||
ApplicationDbContextFactory dbContextFactory,
|
||||
GreenfieldReportsController api,
|
||||
ReportService reportService,
|
||||
DisplayFormatter displayFormatter,
|
||||
BTCPayServerEnvironment env)
|
||||
{
|
||||
Api = api;
|
||||
@ -32,8 +33,10 @@ public partial class UIReportsController : Controller
|
||||
Env = env;
|
||||
DBContextFactory = dbContextFactory;
|
||||
NetworkProvider = networkProvider;
|
||||
DisplayFormatter = displayFormatter;
|
||||
}
|
||||
private BTCPayNetworkProvider NetworkProvider { get; }
|
||||
private DisplayFormatter DisplayFormatter { get; }
|
||||
public GreenfieldReportsController Api { get; }
|
||||
public ReportService ReportService { get; }
|
||||
public BTCPayServerEnvironment Env { get; }
|
||||
|
@ -3,14 +3,9 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Data;
|
||||
using BTCPayServer.Services.Stores;
|
||||
using BTCPayServer.Services.Wallets;
|
||||
using Dapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NBitcoin;
|
||||
using NBXplorer.DerivationStrategy;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
|
||||
|
||||
namespace BTCPayServer.Services.Reporting;
|
||||
|
||||
@ -19,7 +14,6 @@ public class OnChainWalletReportProvider : ReportProvider
|
||||
public OnChainWalletReportProvider(
|
||||
NBXplorerConnectionFactory NbxplorerConnectionFactory,
|
||||
StoreRepository storeRepository,
|
||||
DisplayFormatter displayFormatter,
|
||||
BTCPayNetworkProvider networkProvider,
|
||||
WalletRepository walletRepository)
|
||||
{
|
||||
@ -27,10 +21,8 @@ public class OnChainWalletReportProvider : ReportProvider
|
||||
StoreRepository = storeRepository;
|
||||
NetworkProvider = networkProvider;
|
||||
WalletRepository = walletRepository;
|
||||
_displayFormatter = displayFormatter;
|
||||
}
|
||||
|
||||
private readonly DisplayFormatter _displayFormatter;
|
||||
private NBXplorerConnectionFactory NbxplorerConnectionFactory { get; }
|
||||
private StoreRepository StoreRepository { get; }
|
||||
private BTCPayNetworkProvider NetworkProvider { get; }
|
||||
|
@ -3,15 +3,9 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Client.Models;
|
||||
using BTCPayServer.Data;
|
||||
using BTCPayServer.Lightning;
|
||||
using BTCPayServer.Payments;
|
||||
using BTCPayServer.Rating;
|
||||
using BTCPayServer.Services.Invoices;
|
||||
using BTCPayServer.Services.Rates;
|
||||
using Dapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NBitcoin;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace BTCPayServer.Services.Reporting;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BTCPayServer.Services.Reporting
|
||||
|
@ -1,9 +1,6 @@
|
||||
#nullable enable
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using BTCPayServer.Data;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace BTCPayServer.Services.Reporting
|
||||
{
|
||||
|
@ -11,6 +11,6 @@ namespace BTCPayServer.Services.Reporting
|
||||
set;
|
||||
} = new List<StoreReportResponse.Field>();
|
||||
|
||||
public List<ChartDefinition> Charts { get; set; } = new List<ChartDefinition>();
|
||||
public List<ChartDefinition> Charts { get; set; } = new ();
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,7 @@
|
||||
<table class="table table-hover w-auto">
|
||||
<thead class="sticky-top bg-body">
|
||||
<tr>
|
||||
<th v-for="field in srv.result.fields">
|
||||
<th v-for="field in srv.result.fields" :class="{ 'text-end': ['integer', 'decimal', 'amount'].includes(field.type) }">
|
||||
<a class="text-nowrap sort-column"
|
||||
href="#"
|
||||
:data-field="field.name"
|
||||
|
@ -135,14 +135,16 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
const result = str.replace(/([A-Z])/g, " $1");
|
||||
return result.charAt(0).toUpperCase() + result.slice(1);
|
||||
},
|
||||
displayValue(val) {
|
||||
return val && typeof (val) === "object" && val.d ? new Decimal(val.v).toFixed(val.d) : val;
|
||||
}
|
||||
displayValue
|
||||
}
|
||||
});
|
||||
fetchStoreReports();
|
||||
});
|
||||
|
||||
function displayValue(val) {
|
||||
return val && typeof val === "object" && typeof val.d === "number" ? new Decimal(val.v).toFixed(val.d) : val;
|
||||
}
|
||||
|
||||
function updateUIDateRange() {
|
||||
document.getElementById("toDate")._flatpickr.setDate(moment.unix(srv.request.timePeriod.to).toDate());
|
||||
document.getElementById("fromDate")._flatpickr.setDate(moment.unix(srv.request.timePeriod.from).toDate());
|
||||
@ -167,6 +169,7 @@ function downloadCSV() {
|
||||
const data = clone(origData);
|
||||
|
||||
// Convert ISO8601 dates to YYYY-MM-DD HH:mm:ss so the CSV easily integrate with Excel
|
||||
modifyFields(srv.result.fields, data, 'amount', displayValue)
|
||||
modifyFields(srv.result.fields, data, 'datetime', v => moment(v).format('YYYY-MM-DD hh:mm:ss'));
|
||||
const csv = Papa.unparse({ fields: srv.result.fields.map(f => f.name), data });
|
||||
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
||||
|
Loading…
Reference in New Issue
Block a user