Keep coinaverage compatibility, improve UX, hardcode feed provider supported exchanges

This commit is contained in:
nicolas.dorier
2020-01-13 22:20:45 +09:00
parent 58d9a48787
commit 5dbdb4b399
16 changed files with 280 additions and 167 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using BTCPayServer.Rating;
@@ -17,13 +18,29 @@ namespace BTCPayServer.Models.StoreViewModels
}
public void SetExchangeRates(IEnumerable<AvailableRateProvider> supportedList, string preferredExchange)
{
var defaultStore = preferredExchange ?? CoinAverageRateProvider.CoinAverageName;
var defaultStore = preferredExchange ?? CoinGeckoRateProvider.CoinGeckoName;
supportedList = supportedList.Select(a => new AvailableRateProvider(a.Id, GetName(a), a.Url, a.Source)).ToArray();
var chosen = supportedList.FirstOrDefault(f => f.Id == defaultStore) ?? supportedList.FirstOrDefault();
Exchanges = new SelectList(supportedList, nameof(chosen.Id), nameof(chosen.Name), chosen);
PreferredExchange = chosen.Id;
RateSource = chosen.Url;
}
private string GetName(AvailableRateProvider a)
{
switch (a.Source)
{
case Rating.RateSource.Direct:
return a.Name;
case Rating.RateSource.Coingecko:
return $"{a.Name} (via CoinGecko, free)";
case Rating.RateSource.CoinAverage:
return $"{a.Name} (via BitcoinAverage, commercial)";
default:
throw new NotSupportedException(a.Source.ToString());
}
}
public List<TestResultViewModel> TestRateRules { get; set; }
public SelectList Exchanges { get; set; }