Fix decimal points shown in Checkout UI based on currency ( always showed btc decimal precision before) (#1529)

* Fix decimal points shown in Checkout UI based on currency ( always showed btc decimal precision before)

* cleanup ShowMoney
This commit is contained in:
Andrew Camilleri 2020-05-02 18:28:35 +02:00 committed by GitHub
parent 5312bb1dee
commit 2bb4dd5d01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -224,6 +224,16 @@ namespace BTCPayServer.Controllers
: (decimal?)null;
var paymentMethodHandler = _paymentMethodHandlerDictionary[paymentMethodId];
var divisibility = _CurrencyNameTable.GetNumberFormatInfo(paymentMethod.GetId().CryptoCode, false)?.CurrencyDecimalDigits;
string ShowMoney(Money money)
{
if (!divisibility.HasValue) return money.ToString();
var format = $"0{(divisibility.Value > 0 ? "." : string.Empty)}".PadRight(divisibility.Value, '0');
return money.ToDecimal(MoneyUnit.BTC).ToString(format, CultureInfo.InvariantCulture);
}
var model = new PaymentModel()
{
CryptoCode = network.CryptoCode,
@ -236,8 +246,8 @@ namespace BTCPayServer.Controllers
HtmlTitle = storeBlob.HtmlTitle ?? "BTCPay Invoice",
CryptoImage = Request.GetRelativePathOrAbsolute(paymentMethodHandler.GetCryptoImage(paymentMethodId)),
BtcAddress = paymentMethodDetails.GetPaymentDestination(),
BtcDue = accounting.Due.ToString(),
OrderAmount = (accounting.TotalDue - accounting.NetworkFee).ToString(),
BtcDue = ShowMoney(accounting.Due),
OrderAmount = ShowMoney(accounting.TotalDue - accounting.NetworkFee),
OrderAmountFiat = OrderAmountFromInvoice(network.CryptoCode, invoice.ProductInformation),
CustomerEmail = invoice.RefundMail,
RequiresRefundEmail = storeBlob.RequiresRefundEmail,
@ -253,7 +263,7 @@ namespace BTCPayServer.Controllers
StoreName = store.StoreName,
PeerInfo = (paymentMethodDetails as LightningLikePaymentMethodDetails)?.NodeInfo,
TxCount = accounting.TxRequired,
BtcPaid = accounting.Paid.ToString(),
BtcPaid = ShowMoney(accounting.Paid),
#pragma warning disable CS0618 // Type or member is obsolete
Status = invoice.StatusString,
#pragma warning restore CS0618 // Type or member is obsolete