mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-19 15:04:19 +01:00
round up rates sent back by the RateProviderFactory
This commit is contained in:
@@ -1454,7 +1454,7 @@ namespace BTCPayServer.Tests
|
|||||||
|
|
||||||
private static BTCPayRateProviderFactory CreateBTCPayRateFactory(BTCPayNetworkProvider provider)
|
private static BTCPayRateProviderFactory CreateBTCPayRateFactory(BTCPayNetworkProvider provider)
|
||||||
{
|
{
|
||||||
return new BTCPayRateProviderFactory(new MemoryCacheOptions() { ExpirationScanFrequency = TimeSpan.FromSeconds(1.0) }, provider, new CoinAverageSettings());
|
return new BTCPayRateProviderFactory(new MemoryCacheOptions() { ExpirationScanFrequency = TimeSpan.FromSeconds(1.0) }, provider, null, new CoinAverageSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -417,10 +417,21 @@ namespace BTCPayServer.Rating
|
|||||||
|
|
||||||
public RateRule(RateRules parent, CurrencyPair currencyPair, SyntaxNode candidate)
|
public RateRule(RateRules parent, CurrencyPair currencyPair, SyntaxNode candidate)
|
||||||
{
|
{
|
||||||
|
_CurrencyPair = currencyPair;
|
||||||
flatten = new FlattenExpressionRewriter(parent, currencyPair);
|
flatten = new FlattenExpressionRewriter(parent, currencyPair);
|
||||||
this.expression = flatten.Visit(candidate);
|
this.expression = flatten.Visit(candidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private readonly CurrencyPair _CurrencyPair;
|
||||||
|
public CurrencyPair CurrencyPair
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _CurrencyPair;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ExchangeRates ExchangeRates
|
public ExchangeRates ExchangeRates
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace BTCPayServer.Services.Rates
|
|||||||
}
|
}
|
||||||
IMemoryCache _Cache;
|
IMemoryCache _Cache;
|
||||||
private IOptions<MemoryCacheOptions> _CacheOptions;
|
private IOptions<MemoryCacheOptions> _CacheOptions;
|
||||||
|
CurrencyNameTable _CurrencyTable;
|
||||||
public IMemoryCache Cache
|
public IMemoryCache Cache
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -46,10 +46,12 @@ namespace BTCPayServer.Services.Rates
|
|||||||
CoinAverageSettings _CoinAverageSettings;
|
CoinAverageSettings _CoinAverageSettings;
|
||||||
public BTCPayRateProviderFactory(IOptions<MemoryCacheOptions> cacheOptions,
|
public BTCPayRateProviderFactory(IOptions<MemoryCacheOptions> cacheOptions,
|
||||||
BTCPayNetworkProvider btcpayNetworkProvider,
|
BTCPayNetworkProvider btcpayNetworkProvider,
|
||||||
|
CurrencyNameTable currencyTable,
|
||||||
CoinAverageSettings coinAverageSettings)
|
CoinAverageSettings coinAverageSettings)
|
||||||
{
|
{
|
||||||
if (cacheOptions == null)
|
if (cacheOptions == null)
|
||||||
throw new ArgumentNullException(nameof(cacheOptions));
|
throw new ArgumentNullException(nameof(cacheOptions));
|
||||||
|
_CurrencyTable = currencyTable;
|
||||||
_CoinAverageSettings = coinAverageSettings;
|
_CoinAverageSettings = coinAverageSettings;
|
||||||
_Cache = new MemoryCache(cacheOptions);
|
_Cache = new MemoryCache(cacheOptions);
|
||||||
_CacheOptions = cacheOptions;
|
_CacheOptions = cacheOptions;
|
||||||
@@ -161,6 +163,13 @@ namespace BTCPayServer.Services.Rates
|
|||||||
}
|
}
|
||||||
rateRule.Reevaluate();
|
rateRule.Reevaluate();
|
||||||
result.Value = rateRule.Value;
|
result.Value = rateRule.Value;
|
||||||
|
|
||||||
|
var currencyData = _CurrencyTable?.GetCurrencyData(rateRule.CurrencyPair.Right);
|
||||||
|
if(currencyData != null && result.Value.HasValue)
|
||||||
|
{
|
||||||
|
result.Value = decimal.Round(result.Value.Value, currencyData.Divisibility, MidpointRounding.AwayFromZero);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors = rateRule.Errors;
|
result.Errors = rateRule.Errors;
|
||||||
result.EvaluatedRule = rateRule.ToString(true);
|
result.EvaluatedRule = rateRule.ToString(true);
|
||||||
result.Rule = rateRule.ToString(false);
|
result.Rule = rateRule.ToString(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user