Use proper divisibility for payments in crowdfund and do not show tooltip if identical data

fixes #1037 and fixes #1003
This commit is contained in:
Kukks
2020-02-28 12:51:15 +01:00
parent 18aaa1a0c4
commit c607696230
4 changed files with 23 additions and 17 deletions

View File

@@ -75,6 +75,7 @@ namespace BTCPayServer.Models.AppViewModels
public bool DisplayPerksRanking { get; set; }
public bool Enabled { get; set; }
public string ResetEvery { get; set; }
public Dictionary<string, CurrencyData> CurrencyDataPayments { get; set; }
}
public class ContributeToCrowdfund

View File

@@ -153,6 +153,10 @@ namespace BTCPayServer.Services.Apps
Sounds = settings.Sounds,
AnimationColors = settings.AnimationColors,
CurrencyData = _Currencies.GetCurrencyData(settings.TargetCurrency, true),
CurrencyDataPayments = currentPayments.Select(pair => pair.Key)
.Concat(pendingPayments.Select(pair => pair.Key)).Distinct()
.Select(id => _Currencies.GetCurrencyData(id.CryptoCode, true))
.ToDictionary(data => data.Code, data => data),
Info = new ViewCrowdfundViewModel.CrowdfundInfo()
{
TotalContributors = paidInvoices.Length,

View File

@@ -128,7 +128,7 @@
<b-tooltip target="crowdfund-body-raised-amount" v-if="paymentStats && paymentStats.length > 0">
<ul class="p-0 text-uppercase">
<li v-for="stat of paymentStats" class="list-unstyled">
{{stat.label}} <span v-if="stat.lightning" class="fa fa-bolt"></span> {{stat.value.toFixed(srvModel.currencyData.divisibility)}}
{{stat.label}} <span v-if="stat.lightning" class="fa fa-bolt"></span> {{stat.value}}
</li>
</ul>
</b-tooltip>

View File

@@ -110,10 +110,7 @@ addLoadEvent(function (ev) {
},
paymentStats: function(){
var result= [];
var combinedStats = {};
var keys = Object.keys(this.srvModel.info.paymentStats);
for (var i = 0; i < keys.length; i++) {
@@ -137,18 +134,22 @@ addLoadEvent(function (ev) {
keys = Object.keys(combinedStats);
for (var i = 0; i < keys.length; i++) {
var newItem = {key:keys[i], value: combinedStats[keys[i]], label: keys[i].replace("_","")};
if(!combinedStats[keys[i]]){
continue;
}
var paymentMethodId = keys[i].split("_");
var value = combinedStats[keys[i]].toFixed(this.srvModel.currencyDataPayments[paymentMethodId[0]].divisibility);
var newItem = {key:keys[i], value: value, label: paymentMethodId[0]};
if(paymentMethodId.length > 1 && paymentMethodId[1].endsWith("LightningLike")){
newItem.lightning = true;
}
result.push(newItem);
}
for (var i = 0; i < result.length; i++) {
var current = result[i];
if(current.label.endsWith("LightningLike")){
current.label = current.label.substr(0,current.label.indexOf("LightningLike"));
current.lightning = true;
}
}
if(result.length === 1 && result[0].label === srvModel.targetCurrency){
return [];
}
return result;
},
perks: function(){
@@ -255,7 +256,7 @@ addLoadEvent(function (ev) {
} );
});
eventAggregator.$on("payment-received", function (amount, cryptoCode, type) {
var onChain = type.toLowerCase() === "btclike";
var onChain = type.toLowerCase() !== "lightninglike";
if(self.sound) {
playRandomSound();
}