mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Fix UriAttribute bug, and currency formatting crash
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
<Version>1.0.2.19</Version>
|
<Version>1.0.2.20</Version>
|
||||||
<NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn>
|
<NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ namespace BTCPayServer.Controllers
|
|||||||
}
|
}
|
||||||
public static string FormatCurrency(decimal price, string currency, CurrencyNameTable currencies)
|
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 currencyData = currencies.GetCurrencyData(currency);
|
||||||
var divisibility = currencyData.Divisibility;
|
var divisibility = currencyData.Divisibility;
|
||||||
while (true)
|
while (true)
|
||||||
|
|||||||
@@ -40,6 +40,14 @@ namespace BTCPayServer.Services.Rates
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Dictionary<string, IFormatProvider> _CurrencyProviders = new Dictionary<string, IFormatProvider>();
|
static Dictionary<string, IFormatProvider> _CurrencyProviders = new Dictionary<string, IFormatProvider>();
|
||||||
|
|
||||||
|
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)
|
public IFormatProvider GetCurrencyProvider(string currency)
|
||||||
{
|
{
|
||||||
lock (_CurrencyProviders)
|
lock (_CurrencyProviders)
|
||||||
@@ -54,7 +62,11 @@ namespace BTCPayServer.Services.Rates
|
|||||||
}
|
}
|
||||||
catch { }
|
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);
|
return _CurrencyProviders.TryGet(currency);
|
||||||
}
|
}
|
||||||
@@ -106,6 +118,17 @@ namespace BTCPayServer.Services.Rates
|
|||||||
info.Symbol = splitted[3];
|
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();
|
return dico.Values.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ namespace BTCPayServer.Validation
|
|||||||
{
|
{
|
||||||
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
||||||
{
|
{
|
||||||
|
var str = value == null ? null : Convert.ToString(value, CultureInfo.InvariantCulture);
|
||||||
Uri uri;
|
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)
|
if (!valid)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user