mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-18 21:32:27 +01:00
Fix: Incorrect percentage accounting of raised money in crowdfunding (#6347)
This commit is contained in:
parent
e3ec07da76
commit
4687bb95cb
@ -228,8 +228,7 @@ namespace BTCPayServer.Plugins.Crowdfund
|
||||
ProgressPercentage = (currentPayments.TotalCurrency / settings.TargetAmount) * 100,
|
||||
PendingProgressPercentage = (pendingPayments.TotalCurrency / settings.TargetAmount) * 100,
|
||||
LastUpdated = DateTime.UtcNow,
|
||||
PaymentStats = GetPaymentStats(currentPayments),
|
||||
PendingPaymentStats = GetPaymentStats(pendingPayments),
|
||||
PaymentStats = GetPaymentStats(currentPayments, pendingPayments),
|
||||
LastResetDate = lastResetDate,
|
||||
NextResetDate = nextResetDate,
|
||||
CurrentPendingAmount = pendingPayments.TotalCurrency,
|
||||
@ -244,17 +243,21 @@ namespace BTCPayServer.Plugins.Crowdfund
|
||||
return vm;
|
||||
}
|
||||
|
||||
private Dictionary<string, PaymentStat> GetPaymentStats(InvoiceStatistics stats)
|
||||
private Dictionary<string, PaymentStat> GetPaymentStats(InvoiceStatistics stats, InvoiceStatistics pendingSats)
|
||||
{
|
||||
var r = new Dictionary<string, PaymentStat>();
|
||||
var total = stats.Select(s => s.Value.CurrencyValue).Sum();
|
||||
foreach (var kv in stats)
|
||||
var allStats = stats.Concat(pendingSats);
|
||||
var total = allStats
|
||||
.Select(s => s.Value.CurrencyValue).Sum();
|
||||
foreach (var kv in allStats
|
||||
.GroupBy(k => k.Key, k => k.Value)
|
||||
.Select(g => (g.Key, CurrencyValue: g.Sum(s => s.CurrencyValue))))
|
||||
{
|
||||
var pmi = PaymentMethodId.Parse(kv.Key);
|
||||
r.TryAdd(kv.Key, new PaymentStat()
|
||||
{
|
||||
Label = _prettyNameProvider.PrettyName(pmi),
|
||||
Percent = (kv.Value.CurrencyValue / total) * 100.0m,
|
||||
Percent = (kv.CurrencyValue / total) * 100.0m,
|
||||
// Note that the LNURL will have the same LN
|
||||
IsLightning = pmi == PaymentTypes.LN.GetPaymentMethodId(kv.Key)
|
||||
});
|
||||
|
@ -56,7 +56,6 @@ namespace BTCPayServer.Plugins.Crowdfund.Models
|
||||
public decimal? PendingProgressPercentage { get; set; }
|
||||
public DateTime LastUpdated { get; set; }
|
||||
public Dictionary<string, PaymentStat> PaymentStats { get; set; }
|
||||
public Dictionary<string, PaymentStat> PendingPaymentStats { get; set; }
|
||||
public DateTime? LastResetDate { get; set; }
|
||||
public DateTime? NextResetDate { get; set; }
|
||||
}
|
||||
|
@ -111,29 +111,12 @@ app = new Vue({
|
||||
return this.srvModel.targetCurrency.toUpperCase();
|
||||
},
|
||||
paymentStats: function(){
|
||||
var result= [];
|
||||
var combinedStats = {};
|
||||
var keys = Object.keys(this.srvModel.info.paymentStats);
|
||||
|
||||
var result = [];
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
combinedStats[keys[i]] = this.srvModel.info.paymentStats[keys[i]];
|
||||
}
|
||||
|
||||
keys = Object.keys(this.srvModel.info.pendingPaymentStats);
|
||||
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
if(combinedStats[keys[i]])
|
||||
combinedStats[keys[i]].percent += this.srvModel.info.pendingPaymentStats[keys[i]].percent;
|
||||
else
|
||||
combinedStats[keys[i]] = this.srvModel.info.pendingPaymentStats[keys[i]];
|
||||
}
|
||||
|
||||
keys = Object.keys(combinedStats);
|
||||
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var value = combinedStats[keys[i]].percent.toFixed(2) + '%';
|
||||
var newItem = {key:keys[i], value: value, label: combinedStats[keys[i]].label};
|
||||
newItem.lightning = combinedStats[keys[i]].isLightning;
|
||||
var value = this.srvModel.info.paymentStats[keys[i]].percent.toFixed(2) + '%';
|
||||
var newItem = { key: keys[i], value: value, label: this.srvModel.info.paymentStats[keys[i]].label};
|
||||
newItem.lightning = this.srvModel.info.paymentStats[keys[i]].isLightning;
|
||||
result.push(newItem);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user