From 8cb3757f5c934dad474476ece5e4c2beae129f04 Mon Sep 17 00:00:00 2001 From: Kukks Date: Thu, 8 Oct 2020 09:19:50 +0200 Subject: [PATCH] Decouple payment type icon from UI We should put an effort to not couple payment methods/types together after spending so much time decoupling things. --- BTCPayServer/Payments/PaymentTypes.Bitcoin.cs | 6 ++---- BTCPayServer/Payments/PaymentTypes.Lightning.cs | 2 ++ BTCPayServer/Payments/PaymentTypes.cs | 1 + BTCPayServer/Views/Invoice/ListInvoices.cshtml | 13 ++----------- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/BTCPayServer/Payments/PaymentTypes.Bitcoin.cs b/BTCPayServer/Payments/PaymentTypes.Bitcoin.cs index ffdbd7b12..0f2580e21 100644 --- a/BTCPayServer/Payments/PaymentTypes.Bitcoin.cs +++ b/BTCPayServer/Payments/PaymentTypes.Bitcoin.cs @@ -19,10 +19,8 @@ namespace BTCPayServer.Payments public override string ToPrettyString() => "On-Chain"; public override string GetId() => "BTCLike"; - public override string ToStringNormalized() - { - return "OnChain"; - } + public override string ToStringNormalized() => "OnChain"; + public override string GetBadge() => "🔗"; public override CryptoPaymentData DeserializePaymentData(BTCPayNetworkBase network, string str) { diff --git a/BTCPayServer/Payments/PaymentTypes.Lightning.cs b/BTCPayServer/Payments/PaymentTypes.Lightning.cs index 999443d2c..d69c4bb38 100644 --- a/BTCPayServer/Payments/PaymentTypes.Lightning.cs +++ b/BTCPayServer/Payments/PaymentTypes.Lightning.cs @@ -17,6 +17,8 @@ namespace BTCPayServer.Payments public override string ToPrettyString() => "Off-Chain"; public override string GetId() => "LightningLike"; + public override string GetBadge() => "⚡"; + public override string ToStringNormalized() { return "LightningNetwork"; diff --git a/BTCPayServer/Payments/PaymentTypes.cs b/BTCPayServer/Payments/PaymentTypes.cs index 5b4e23cb9..52c294428 100644 --- a/BTCPayServer/Payments/PaymentTypes.cs +++ b/BTCPayServer/Payments/PaymentTypes.cs @@ -82,6 +82,7 @@ namespace BTCPayServer.Payments } public abstract string GetId(); + public virtual string GetBadge() => null; public abstract CryptoPaymentData DeserializePaymentData(BTCPayNetworkBase network, string str); public abstract string SerializePaymentData(BTCPayNetworkBase network, CryptoPaymentData paymentData); public abstract IPaymentMethodDetails DeserializePaymentMethodDetails(BTCPayNetworkBase network, string str); diff --git a/BTCPayServer/Views/Invoice/ListInvoices.cshtml b/BTCPayServer/Views/Invoice/ListInvoices.cshtml index 1d88081f5..4b3bce4fb 100644 --- a/BTCPayServer/Views/Invoice/ListInvoices.cshtml +++ b/BTCPayServer/Views/Invoice/ListInvoices.cshtml @@ -291,18 +291,9 @@ @invoice.Status.ToString().ToLower() } - @{ - var grouped = invoice.Details.Payments.GroupBy(payment => payment.GetPaymentMethodId()?.PaymentType).Where(entities => entities.Key!= null); - var paiOnChain = grouped.Where(g => g.Key == BitcoinPaymentType.Instance).Any(); - var paidOffChain = grouped.Where(g => g.Key == LightningPaymentType.Instance).Any(); - } - @if (paiOnChain) + @foreach (var paymentType in invoice.Details.Payments.Select(payment => payment.GetPaymentMethodId()?.PaymentType).Distinct().Where(type => type != null && !string.IsNullOrEmpty(type.GetBadge()))) { - 🔗 - } - @if (paidOffChain) - { - ⚡️ + @paymentType.GetBadge() } @invoice.AmountCurrency