From 64181d1a938880973157efb2e7ae5f4e3cce2853 Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Fri, 27 Jul 2018 07:54:55 +0200 Subject: [PATCH] use default crypto for /rates route --- BTCPayServer/Controllers/InvoiceController.UI.cs | 2 +- BTCPayServer/Controllers/RateController.cs | 15 +++++---------- BTCPayServer/Controllers/StoresController.cs | 4 ++-- BTCPayServer/Data/StoreData.cs | 4 ++-- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 76ba4f472..378f081c9 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -213,7 +213,7 @@ namespace BTCPayServer.Controllers bool isDefaultCrypto = false; if (paymentMethodIdStr == null) { - paymentMethodIdStr = store.GetDefaultCrypto(); + paymentMethodIdStr = store.GetDefaultCrypto(_NetworkProvider); isDefaultCrypto = true; } diff --git a/BTCPayServer/Controllers/RateController.cs b/BTCPayServer/Controllers/RateController.cs index 7334d6786..7dea18d5d 100644 --- a/BTCPayServer/Controllers/RateController.cs +++ b/BTCPayServer/Controllers/RateController.cs @@ -126,23 +126,18 @@ namespace BTCPayServer.Controllers var supportedMethods = store.GetSupportedPaymentMethods(_NetworkProvider); var currencyCodes = supportedMethods.Where(method => !string.IsNullOrEmpty(method.CryptoCode)) .Select(method => method.CryptoCode).Distinct(); + var defaultCrypto = store.GetDefaultCrypto(_NetworkProvider); foreach (var currencyCode in currencyCodes) { - foreach (var currencyCode2 in currencyCodes) + if (!string.IsNullOrEmpty(currencyPairs)) { - if (currencyCode == currencyCode2) - { - continue; - } - if (!string.IsNullOrEmpty(currencyPairs)) - { - currencyPairs += ","; - } - currencyPairs += $"{currencyCode}_{currencyCode2}"; + currencyPairs += ","; } + currencyPairs += $"{defaultCrypto}_{currencyCode}"; } + if (string.IsNullOrEmpty(currencyPairs)) { var result = Json(new BitpayErrorsModel() { Error = "You need to specify currencyPairs (eg. BTC_USD,LTC_CAD)" }); diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index daef61110..358e06ce5 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -317,7 +317,7 @@ namespace BTCPayServer.Controllers { var storeBlob = StoreData.GetStoreBlob(); var vm = new CheckoutExperienceViewModel(); - vm.SetCryptoCurrencies(_ExplorerProvider, StoreData.GetDefaultCrypto()); + vm.SetCryptoCurrencies(_ExplorerProvider, StoreData.GetDefaultCrypto(_NetworkProvider)); vm.SetLanguages(_LangService, storeBlob.DefaultLang); vm.LightningMaxValue = storeBlob.LightningMaxValue?.ToString() ?? ""; vm.OnChainMinValue = storeBlob.OnChainMinValue?.ToString() ?? ""; @@ -352,7 +352,7 @@ namespace BTCPayServer.Controllers } bool needUpdate = false; var blob = StoreData.GetStoreBlob(); - if (StoreData.GetDefaultCrypto() != model.DefaultCryptoCurrency) + if (StoreData.GetDefaultCrypto(_NetworkProvider) != model.DefaultCryptoCurrency) { needUpdate = true; StoreData.SetDefaultCrypto(model.DefaultCryptoCurrency); diff --git a/BTCPayServer/Data/StoreData.cs b/BTCPayServer/Data/StoreData.cs index 2aff5f446..5d2b0fb81 100644 --- a/BTCPayServer/Data/StoreData.cs +++ b/BTCPayServer/Data/StoreData.cs @@ -197,9 +197,9 @@ namespace BTCPayServer.Data public IEnumerable APIKeys { get; set; } #pragma warning disable CS0618 - public string GetDefaultCrypto() + public string GetDefaultCrypto(BTCPayNetworkProvider networkProvider = null) { - return DefaultCrypto ?? "BTC"; + return DefaultCrypto ?? (networkProvider == null? "BTC" : GetSupportedPaymentMethods(networkProvider).First().CryptoCode); } public void SetDefaultCrypto(string defaultCryptoCurrency) {