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 DisplayPerksRanking { get; set; }
public bool Enabled { get; set; } public bool Enabled { get; set; }
public string ResetEvery { get; set; } public string ResetEvery { get; set; }
public Dictionary<string, CurrencyData> CurrencyDataPayments { get; set; }
} }
public class ContributeToCrowdfund public class ContributeToCrowdfund

View File

@@ -153,6 +153,10 @@ namespace BTCPayServer.Services.Apps
Sounds = settings.Sounds, Sounds = settings.Sounds,
AnimationColors = settings.AnimationColors, AnimationColors = settings.AnimationColors,
CurrencyData = _Currencies.GetCurrencyData(settings.TargetCurrency, true), 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() Info = new ViewCrowdfundViewModel.CrowdfundInfo()
{ {
TotalContributors = paidInvoices.Length, TotalContributors = paidInvoices.Length,

View File

@@ -128,7 +128,7 @@
<b-tooltip target="crowdfund-body-raised-amount" v-if="paymentStats && paymentStats.length > 0"> <b-tooltip target="crowdfund-body-raised-amount" v-if="paymentStats && paymentStats.length > 0">
<ul class="p-0 text-uppercase"> <ul class="p-0 text-uppercase">
<li v-for="stat of paymentStats" class="list-unstyled"> <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> </li>
</ul> </ul>
</b-tooltip> </b-tooltip>

View File

@@ -109,11 +109,8 @@ addLoadEvent(function (ev) {
return this.srvModel.targetCurrency.toUpperCase(); return this.srvModel.targetCurrency.toUpperCase();
}, },
paymentStats: function(){ paymentStats: function(){
var result= []; var result= [];
var combinedStats = {}; var combinedStats = {};
var keys = Object.keys(this.srvModel.info.paymentStats); var keys = Object.keys(this.srvModel.info.paymentStats);
for (var i = 0; i < keys.length; i++) { for (var i = 0; i < keys.length; i++) {
@@ -135,20 +132,24 @@ addLoadEvent(function (ev) {
} }
keys = Object.keys(combinedStats); keys = Object.keys(combinedStats);
for (var i = 0; i < keys.length; i++) { 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]]){
result.push(newItem); continue;
}
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;
} }
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);
}
if(result.length === 1 && result[0].label === srvModel.targetCurrency){
return [];
} }
return result; return result;
}, },
perks: function(){ perks: function(){
@@ -255,7 +256,7 @@ addLoadEvent(function (ev) {
} ); } );
}); });
eventAggregator.$on("payment-received", function (amount, cryptoCode, type) { eventAggregator.$on("payment-received", function (amount, cryptoCode, type) {
var onChain = type.toLowerCase() === "btclike"; var onChain = type.toLowerCase() !== "lightninglike";
if(self.sound) { if(self.sound) {
playRandomSound(); playRandomSound();
} }