diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index 215743aef..ad2987d1f 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -2,7 +2,7 @@ Exe netcoreapp2.1 - 1.0.2.19 + 1.0.2.20 NU1701,CA1816,CA1308,CA1810,CA2208 diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 546bf9b68..dfd71768e 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -295,7 +295,7 @@ namespace BTCPayServer.Controllers } public static string FormatCurrency(decimal price, string currency, CurrencyNameTable currencies) { - var provider = ((CultureInfo)currencies.GetCurrencyProvider(currency)).NumberFormat; + var provider = currencies.GetNumberFormatInfo(currency); var currencyData = currencies.GetCurrencyData(currency); var divisibility = currencyData.Divisibility; while (true) diff --git a/BTCPayServer/Services/Rates/CurrencyNameTable.cs b/BTCPayServer/Services/Rates/CurrencyNameTable.cs index 01c6b57fa..97e748722 100644 --- a/BTCPayServer/Services/Rates/CurrencyNameTable.cs +++ b/BTCPayServer/Services/Rates/CurrencyNameTable.cs @@ -40,6 +40,14 @@ namespace BTCPayServer.Services.Rates } static Dictionary _CurrencyProviders = new Dictionary(); + + public NumberFormatInfo GetNumberFormatInfo(string currency) + { + var data = GetCurrencyProvider(currency); + if (data is NumberFormatInfo nfi) + return nfi; + return ((CultureInfo)data).NumberFormat; + } public IFormatProvider GetCurrencyProvider(string currency) { lock (_CurrencyProviders) @@ -54,7 +62,11 @@ namespace BTCPayServer.Services.Rates } catch { } } - AddCurrency(_CurrencyProviders, "BTC", 8, "BTC"); + + foreach (var network in new BTCPayNetworkProvider(NetworkType.Mainnet).GetAll()) + { + AddCurrency(_CurrencyProviders, network.CryptoCode, 8, network.CryptoCode); + } } return _CurrencyProviders.TryGet(currency); } @@ -106,6 +118,17 @@ namespace BTCPayServer.Services.Rates info.Symbol = splitted[3]; } } + + foreach (var network in new BTCPayNetworkProvider(NetworkType.Mainnet).GetAll()) + { + dico.TryAdd(network.CryptoCode, new CurrencyData() + { + Code = network.CryptoCode, + Divisibility = 8, + Name = network.CryptoCode + }); + } + return dico.Values.ToArray(); } diff --git a/BTCPayServer/Validation/UriAttribute.cs b/BTCPayServer/Validation/UriAttribute.cs index e6bb01608..0e9c75e08 100644 --- a/BTCPayServer/Validation/UriAttribute.cs +++ b/BTCPayServer/Validation/UriAttribute.cs @@ -9,8 +9,9 @@ namespace BTCPayServer.Validation { protected override ValidationResult IsValid(object value, ValidationContext validationContext) { + var str = value == null ? null : Convert.ToString(value, CultureInfo.InvariantCulture); Uri uri; - bool valid = Uri.TryCreate(Convert.ToString(value, CultureInfo.InvariantCulture), UriKind.Absolute, out uri); + bool valid = string.IsNullOrWhiteSpace(str) || Uri.TryCreate(str, UriKind.Absolute, out uri); if (!valid) {