mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-21 14:04:12 +01:00
remove decimals for Colombian (COP) and Argentina's Peso (ARS) (#5710)
* remove decimals for Colombian (COP) and Argentina's Peso (ARS) * remove js currency hardcoding * Fixes removal of columbia and argentina's peso * Refactor --------- Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
This commit is contained in:
parent
6437967e60
commit
6621859567
5 changed files with 26 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"name":"Afghan Afghani",
|
"name":"Afghan Afghani",
|
||||||
"code":"AFN",
|
"code":"AFN",
|
||||||
|
@ -58,7 +58,7 @@
|
||||||
{
|
{
|
||||||
"name":"Argentine Peso",
|
"name":"Argentine Peso",
|
||||||
"code":"ARS",
|
"code":"ARS",
|
||||||
"divisibility":2,
|
"divisibility":0,
|
||||||
"symbol":null,
|
"symbol":null,
|
||||||
"crypto":false
|
"crypto":false
|
||||||
},
|
},
|
||||||
|
@ -289,7 +289,7 @@
|
||||||
{
|
{
|
||||||
"name":"Colombian Peso",
|
"name":"Colombian Peso",
|
||||||
"code":"COP",
|
"code":"COP",
|
||||||
"divisibility":2,
|
"divisibility":0,
|
||||||
"symbol":null,
|
"symbol":null,
|
||||||
"crypto":false
|
"crypto":false
|
||||||
},
|
},
|
||||||
|
|
|
@ -77,7 +77,15 @@ namespace BTCPayServer.Services.Rates
|
||||||
continue;
|
continue;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_CurrencyProviders.TryAdd(new RegionInfo(culture.LCID).ISOCurrencySymbol, culture);
|
var symbol = new RegionInfo(culture.LCID).ISOCurrencySymbol;
|
||||||
|
var c = symbol switch
|
||||||
|
{
|
||||||
|
// ARS and COP are officially 2 digits, but due to depreciation,
|
||||||
|
// nobody really use those anymore. (See https://github.com/btcpayserver/btcpayserver/issues/5708)
|
||||||
|
"ARS" or "COP" => ModifyCurrencyDecimalDigit(culture, 0),
|
||||||
|
_ => culture
|
||||||
|
};
|
||||||
|
_CurrencyProviders.TryAdd(symbol, c);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
@ -91,6 +99,15 @@ namespace BTCPayServer.Services.Rates
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CultureInfo ModifyCurrencyDecimalDigit(CultureInfo culture, int decimals)
|
||||||
|
{
|
||||||
|
var modifiedCulture = new CultureInfo(culture.Name);
|
||||||
|
NumberFormatInfo modifiedNumberFormat = (NumberFormatInfo)modifiedCulture.NumberFormat.Clone();
|
||||||
|
modifiedNumberFormat.CurrencyDecimalDigits = decimals;
|
||||||
|
modifiedCulture.NumberFormat = modifiedNumberFormat;
|
||||||
|
return modifiedCulture;
|
||||||
|
}
|
||||||
|
|
||||||
private void AddCurrency(Dictionary<string, IFormatProvider> currencyProviders, string code, int divisibility, string symbol)
|
private void AddCurrency(Dictionary<string, IFormatProvider> currencyProviders, string code, int divisibility, string symbol)
|
||||||
{
|
{
|
||||||
var culture = new CultureInfo("en-US");
|
var culture = new CultureInfo("en-US");
|
||||||
|
|
|
@ -790,13 +790,15 @@ namespace BTCPayServer.Tests
|
||||||
(0.0005m, "0.0005 USD", "USD"), (0.001m, "0.001 USD", "USD"), (0.01m, "0.01 USD", "USD"),
|
(0.0005m, "0.0005 USD", "USD"), (0.001m, "0.001 USD", "USD"), (0.01m, "0.01 USD", "USD"),
|
||||||
(0.1m, "0.10 USD", "USD"), (0.1m, "0,10 EUR", "EUR"), (1000m, "1,000 JPY", "JPY"),
|
(0.1m, "0.10 USD", "USD"), (0.1m, "0,10 EUR", "EUR"), (1000m, "1,000 JPY", "JPY"),
|
||||||
(1000.0001m, "1,000.00 INR", "INR"),
|
(1000.0001m, "1,000.00 INR", "INR"),
|
||||||
(0.0m, "0.00 USD", "USD")
|
(0.0m, "0.00 USD", "USD"), (1m, "1 COP", "COP"), (1m, "1 ARS", "ARS")
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
var actual = displayFormatter.Currency(test.Item1, test.Item3);
|
var actual = displayFormatter.Currency(test.Item1, test.Item3);
|
||||||
actual = actual.Replace("¥", "¥"); // Hack so JPY test pass on linux as well
|
actual = actual.Replace("¥", "¥"); // Hack so JPY test pass on linux as well
|
||||||
Assert.Equal(test.Item2, actual);
|
Assert.Equal(test.Item2, actual);
|
||||||
}
|
}
|
||||||
|
Assert.Equal(0, CurrencyNameTable.Instance.GetNumberFormatInfo("ARS").CurrencyDecimalDigits);
|
||||||
|
Assert.Equal(0, CurrencyNameTable.Instance.GetNumberFormatInfo("COP").CurrencyDecimalDigits);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
@ -92,6 +92,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
|
||||||
EmbeddedCSS = settings.EmbeddedCSS,
|
EmbeddedCSS = settings.EmbeddedCSS,
|
||||||
CustomCSSLink = settings.CustomCSSLink
|
CustomCSSLink = settings.CustomCSSLink
|
||||||
};
|
};
|
||||||
|
// Check if the currency is COP or ARS (exclude decimal places)
|
||||||
|
|
||||||
return View($"PointOfSale/Public/{viewType}", new ViewPointOfSaleViewModel
|
return View($"PointOfSale/Public/{viewType}", new ViewPointOfSaleViewModel
|
||||||
{
|
{
|
||||||
|
|
|
@ -93,7 +93,7 @@ const posCommon = {
|
||||||
formatCurrency (value, withSymbol) {
|
formatCurrency (value, withSymbol) {
|
||||||
const currency = this.currencyCode
|
const currency = this.currencyCode
|
||||||
if (currency === 'BTC' || currency === 'SATS') return this.formatCrypto(value, withSymbol)
|
if (currency === 'BTC' || currency === 'SATS') return this.formatCrypto(value, withSymbol)
|
||||||
const { divisibility } = this.currencyInfo
|
const { divisibility } = this.currencyInfo;
|
||||||
const locale = this.getLocale(currency);
|
const locale = this.getLocale(currency);
|
||||||
const style = withSymbol ? 'currency' : 'decimal'
|
const style = withSymbol ? 'currency' : 'decimal'
|
||||||
const opts = { currency, style, maximumFractionDigits: divisibility, minimumFractionDigits: divisibility }
|
const opts = { currency, style, maximumFractionDigits: divisibility, minimumFractionDigits: divisibility }
|
||||||
|
|
Loading…
Add table
Reference in a new issue