mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Remove some useless intermediary type from Rate Source (#5351)
This commit is contained in:
@@ -1,37 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace BTCPayServer.Rating
|
|
||||||
{
|
|
||||||
public enum RateSource
|
|
||||||
{
|
|
||||||
Coingecko,
|
|
||||||
Direct
|
|
||||||
}
|
|
||||||
public class AvailableRateProvider
|
|
||||||
{
|
|
||||||
public string Name { get; }
|
|
||||||
public string Url { get; }
|
|
||||||
public string Id { get; }
|
|
||||||
public RateSource Source { get; }
|
|
||||||
|
|
||||||
public AvailableRateProvider(string id, string name, string url) : this(id, name, url, RateSource.Direct)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
public AvailableRateProvider(string id, string name, string url, RateSource source)
|
|
||||||
{
|
|
||||||
Id = id;
|
|
||||||
Name = name;
|
|
||||||
Url = url;
|
|
||||||
Source = source;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string DisplayName =>
|
|
||||||
Source switch
|
|
||||||
{
|
|
||||||
RateSource.Direct => Name,
|
|
||||||
RateSource.Coingecko => $"{Name} (via CoinGecko)",
|
|
||||||
_ => throw new NotSupportedException(Source.ToString())
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because one or more lines are too long
@@ -1,21 +1,8 @@
|
|||||||
using System;
|
#nullable enable
|
||||||
using System.Collections.Generic;
|
namespace BTCPayServer.Rating;
|
||||||
using System.Linq;
|
public enum RateSource
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace BTCPayServer.Rating
|
|
||||||
{
|
{
|
||||||
public class RateSourceInfo
|
Coingecko,
|
||||||
{
|
Direct
|
||||||
public RateSourceInfo(string id, string displayName, string url)
|
|
||||||
{
|
|
||||||
Id = id;
|
|
||||||
DisplayName = displayName;
|
|
||||||
Url = url;
|
|
||||||
}
|
|
||||||
public string Id { get; set; }
|
|
||||||
public string DisplayName { get; set; }
|
|
||||||
public string Url { get; set; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
public record RateSourceInfo(string Id, string DisplayName, string Url, RateSource Source = RateSource.Direct);
|
||||||
|
|||||||
@@ -85,14 +85,13 @@ namespace BTCPayServer.Services.Rates
|
|||||||
bgFetcher.RefreshRate = TimeSpan.FromMinutes(1.0);
|
bgFetcher.RefreshRate = TimeSpan.FromMinutes(1.0);
|
||||||
bgFetcher.ValidatyTime = TimeSpan.FromMinutes(5.0);
|
bgFetcher.ValidatyTime = TimeSpan.FromMinutes(5.0);
|
||||||
Providers.Add(supportedExchange.Id, bgFetcher);
|
Providers.Add(supportedExchange.Id, bgFetcher);
|
||||||
var rsi = coingecko.RateSourceInfo;
|
AvailableRateProviders.Add(coingecko.RateSourceInfo);
|
||||||
AvailableRateProviders.Add(new(rsi.Id, rsi.DisplayName, rsi.Url, RateSource.Coingecko));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AvailableRateProviders.Sort((a, b) => StringComparer.Ordinal.Compare(a.DisplayName, b.DisplayName));
|
AvailableRateProviders.Sort((a, b) => StringComparer.Ordinal.Compare(a.DisplayName, b.DisplayName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AvailableRateProvider> AvailableRateProviders { get; } = new List<AvailableRateProvider>();
|
public List<RateSourceInfo> AvailableRateProviders { get; } = new List<RateSourceInfo>();
|
||||||
|
|
||||||
public async Task<QueryRateResult> QueryRates(string exchangeName, CancellationToken cancellationToken)
|
public async Task<QueryRateResult> QueryRates(string exchangeName, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -859,10 +859,9 @@ namespace BTCPayServer.Controllers
|
|||||||
return RedirectToAction(nameof(UIHomeController.Index), "UIHome");
|
return RedirectToAction(nameof(UIHomeController.Index), "UIHome");
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<AvailableRateProvider> GetSupportedExchanges()
|
private IEnumerable<RateSourceInfo> GetSupportedExchanges()
|
||||||
{
|
{
|
||||||
return _RateFactory.RateProviderFactory.AvailableRateProviders
|
return _RateFactory.RateProviderFactory.AvailableRateProviders
|
||||||
.Where(r => !string.IsNullOrWhiteSpace(r.DisplayName))
|
|
||||||
.OrderBy(s => s.DisplayName, StringComparer.OrdinalIgnoreCase);
|
.OrderBy(s => s.DisplayName, StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,12 +125,11 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
var exchanges = _rateFactory.RateProviderFactory
|
var exchanges = _rateFactory.RateProviderFactory
|
||||||
.AvailableRateProviders
|
.AvailableRateProviders
|
||||||
.Where(r => !string.IsNullOrWhiteSpace(r.Name))
|
|
||||||
.OrderBy(s => s.Id, StringComparer.OrdinalIgnoreCase)
|
.OrderBy(s => s.Id, StringComparer.OrdinalIgnoreCase)
|
||||||
.ToList();
|
.ToList();
|
||||||
exchanges.Insert(0, new AvailableRateProvider(null, "Recommended", ""));
|
exchanges.Insert(0, new (null, "Recommended", ""));
|
||||||
var chosen = exchanges.FirstOrDefault(f => f.Id == selected) ?? exchanges.First();
|
var chosen = exchanges.FirstOrDefault(f => f.Id == selected) ?? exchanges.First();
|
||||||
return new SelectList(exchanges, nameof(chosen.Id), nameof(chosen.Name), chosen.Id);
|
return new SelectList(exchanges, nameof(chosen.Id), nameof(chosen.DisplayName), chosen.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ namespace BTCPayServer.Models.StoreViewModels
|
|||||||
public bool Error { get; set; }
|
public bool Error { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetExchangeRates(IEnumerable<AvailableRateProvider> supportedList, string preferredExchange)
|
public void SetExchangeRates(IEnumerable<RateSourceInfo> supportedList, string preferredExchange)
|
||||||
{
|
{
|
||||||
supportedList = supportedList.Select(a => new AvailableRateProvider(a.Id, a.DisplayName, a.Url, a.Source)).ToArray();
|
supportedList = supportedList.ToArray();
|
||||||
var chosen = supportedList.FirstOrDefault(f => f.Id == preferredExchange) ?? supportedList.FirstOrDefault();
|
var chosen = supportedList.FirstOrDefault(f => f.Id == preferredExchange) ?? supportedList.FirstOrDefault();
|
||||||
Exchanges = new SelectList(supportedList, nameof(chosen.Id), nameof(chosen.Name), chosen);
|
Exchanges = new SelectList(supportedList, nameof(chosen.Id), nameof(chosen.DisplayName), chosen);
|
||||||
PreferredExchange = chosen?.Id;
|
PreferredExchange = chosen?.Id;
|
||||||
RateSource = chosen?.Url;
|
RateSource = chosen?.Url;
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace BTCPayServer.Models.StoreViewModels
|
|||||||
public string ScriptTest { get; set; }
|
public string ScriptTest { get; set; }
|
||||||
public string DefaultCurrencyPairs { get; set; }
|
public string DefaultCurrencyPairs { get; set; }
|
||||||
public string StoreId { get; set; }
|
public string StoreId { get; set; }
|
||||||
public IEnumerable<AvailableRateProvider> AvailableExchanges { get; set; }
|
public IEnumerable<RateSourceInfo> AvailableExchanges { get; set; }
|
||||||
|
|
||||||
[Display(Name = "Add Exchange Rate Spread")]
|
[Display(Name = "Add Exchange Rate Spread")]
|
||||||
[Range(0.0, 100.0)]
|
[Range(0.0, 100.0)]
|
||||||
|
|||||||
Reference in New Issue
Block a user