diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index fd3bc1723..8c04f188c 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -166,7 +166,7 @@ namespace BTCPayServer.Controllers vm.MonitoringExpiration = storeBlob.MonitoringExpiration; vm.InvoiceExpiration = storeBlob.InvoiceExpiration; vm.RateMultiplier = (double)storeBlob.GetRateMultiplier(); - vm.PreferredExchange = storeBlob.PreferredExchange; + vm.PreferredExchange = storeBlob.PreferredExchange.IsCoinAverage() ? "coinaverage" : storeBlob.PreferredExchange; return View(vm); } @@ -322,14 +322,14 @@ namespace BTCPayServer.Controllers needUpdate = true; } - if (!string.IsNullOrEmpty(blob.PreferredExchange) && newExchange) + if (!blob.PreferredExchange.IsCoinAverage() && newExchange) { using (HttpClient client = new HttpClient()) { var rate = await client.GetAsync(model.RateSource); if (rate.StatusCode == System.Net.HttpStatusCode.NotFound) { - ModelState.AddModelError(nameof(model.PreferredExchange), $"Invalid exchange ({model.RateSource})"); + ModelState.AddModelError(nameof(model.PreferredExchange), $"Unsupported exchange ({model.RateSource})"); return View(model); } } diff --git a/BTCPayServer/Data/StoreData.cs b/BTCPayServer/Data/StoreData.cs index b948cea3a..609329e33 100644 --- a/BTCPayServer/Data/StoreData.cs +++ b/BTCPayServer/Data/StoreData.cs @@ -239,7 +239,7 @@ namespace BTCPayServer.Data public IRateProvider ApplyRateRules(BTCPayNetwork network, IRateProvider rateProvider) { - if (!string.IsNullOrEmpty(PreferredExchange)) + if (!PreferredExchange.IsCoinAverage()) { // If the original rateProvider is a cache, use the same inner provider as fallback, and same memory cache to wrap it all if (rateProvider is CachedRateProvider cachedRateProvider) diff --git a/BTCPayServer/Extensions.cs b/BTCPayServer/Extensions.cs index 3853ec7a0..317da6cdf 100644 --- a/BTCPayServer/Extensions.cs +++ b/BTCPayServer/Extensions.cs @@ -31,6 +31,12 @@ namespace BTCPayServer return activeProvider != "Microsoft.EntityFrameworkCore.Sqlite"; } + public static bool IsCoinAverage(this string exchangeName) + { + string[] coinAverages = new[] { "coinaverage", "bitcoinaverage" }; + return String.IsNullOrWhiteSpace(exchangeName) ? true : coinAverages.Contains(exchangeName, StringComparer.OrdinalIgnoreCase) ? true : false; + } + public static async Task> GetTransactions(this BTCPayWallet client, uint256[] hashes, CancellationToken cts = default(CancellationToken)) { hashes = hashes.Distinct().ToArray(); diff --git a/BTCPayServer/Models/StoreViewModels/StoreViewModel.cs b/BTCPayServer/Models/StoreViewModels/StoreViewModel.cs index f5f76e1b4..1e47744af 100644 --- a/BTCPayServer/Models/StoreViewModels/StoreViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/StoreViewModel.cs @@ -47,14 +47,14 @@ namespace BTCPayServer.Models.StoreViewModels public List DerivationSchemes { get; set; } = new List(); - [Display(Name = "Preferred exchange rate...")] + [Display(Name = "Preferred price source (eg. bitfinex, bitstamp...)")] public string PreferredExchange { get; set; } public string RateSource { get { - return string.IsNullOrEmpty(PreferredExchange) ? "https://apiv2.bitcoinaverage.com/indices/global/ticker/short" : $"https://apiv2.bitcoinaverage.com/exchanges/{PreferredExchange}"; + return PreferredExchange.IsCoinAverage() ? "https://apiv2.bitcoinaverage.com/indices/global/ticker/short" : $"https://apiv2.bitcoinaverage.com/exchanges/{PreferredExchange}"; } } diff --git a/BTCPayServer/Views/Stores/UpdateStore.cshtml b/BTCPayServer/Views/Stores/UpdateStore.cshtml index f968ac4fb..51317d85d 100644 --- a/BTCPayServer/Views/Stores/UpdateStore.cshtml +++ b/BTCPayServer/Views/Stores/UpdateStore.cshtml @@ -43,7 +43,7 @@

- Current rate source is @Model.RateSource. (using 1 minute cache) + Current rate source is @Model.PreferredExchange. (using 1 minute cache)