Better explanation for the price source

This commit is contained in:
nicolas.dorier
2018-01-19 17:13:29 +09:00
parent 293525d480
commit 897da9b07a
5 changed files with 13 additions and 7 deletions

View File

@@ -166,7 +166,7 @@ namespace BTCPayServer.Controllers
vm.MonitoringExpiration = storeBlob.MonitoringExpiration; vm.MonitoringExpiration = storeBlob.MonitoringExpiration;
vm.InvoiceExpiration = storeBlob.InvoiceExpiration; vm.InvoiceExpiration = storeBlob.InvoiceExpiration;
vm.RateMultiplier = (double)storeBlob.GetRateMultiplier(); vm.RateMultiplier = (double)storeBlob.GetRateMultiplier();
vm.PreferredExchange = storeBlob.PreferredExchange; vm.PreferredExchange = storeBlob.PreferredExchange.IsCoinAverage() ? "coinaverage" : storeBlob.PreferredExchange;
return View(vm); return View(vm);
} }
@@ -322,14 +322,14 @@ namespace BTCPayServer.Controllers
needUpdate = true; needUpdate = true;
} }
if (!string.IsNullOrEmpty(blob.PreferredExchange) && newExchange) if (!blob.PreferredExchange.IsCoinAverage() && newExchange)
{ {
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{ {
var rate = await client.GetAsync(model.RateSource); var rate = await client.GetAsync(model.RateSource);
if (rate.StatusCode == System.Net.HttpStatusCode.NotFound) 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); return View(model);
} }
} }

View File

@@ -239,7 +239,7 @@ namespace BTCPayServer.Data
public IRateProvider ApplyRateRules(BTCPayNetwork network, IRateProvider rateProvider) 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 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) if (rateProvider is CachedRateProvider cachedRateProvider)

View File

@@ -31,6 +31,12 @@ namespace BTCPayServer
return activeProvider != "Microsoft.EntityFrameworkCore.Sqlite"; 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<Dictionary<uint256, TransactionResult>> GetTransactions(this BTCPayWallet client, uint256[] hashes, CancellationToken cts = default(CancellationToken)) public static async Task<Dictionary<uint256, TransactionResult>> GetTransactions(this BTCPayWallet client, uint256[] hashes, CancellationToken cts = default(CancellationToken))
{ {
hashes = hashes.Distinct().ToArray(); hashes = hashes.Distinct().ToArray();

View File

@@ -47,14 +47,14 @@ namespace BTCPayServer.Models.StoreViewModels
public List<StoreViewModel.DerivationScheme> DerivationSchemes { get; set; } = new List<StoreViewModel.DerivationScheme>(); public List<StoreViewModel.DerivationScheme> DerivationSchemes { get; set; } = new List<StoreViewModel.DerivationScheme>();
[Display(Name = "Preferred exchange rate...")] [Display(Name = "Preferred price source (eg. bitfinex, bitstamp...)")]
public string PreferredExchange { get; set; } public string PreferredExchange { get; set; }
public string RateSource public string RateSource
{ {
get 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}";
} }
} }

View File

@@ -43,7 +43,7 @@
<input asp-for="PreferredExchange" class="form-control" /> <input asp-for="PreferredExchange" class="form-control" />
<span asp-validation-for="PreferredExchange" class="text-danger"></span> <span asp-validation-for="PreferredExchange" class="text-danger"></span>
<p id="PreferredExchangeHelpBlock" class="form-text text-muted"> <p id="PreferredExchangeHelpBlock" class="form-text text-muted">
Current rate source is <a href="@Model.RateSource" target="_blank">@Model.RateSource</a>.<small> (using 1 minute cache)</small> Current rate source is <a href="@Model.RateSource" target="_blank">@Model.PreferredExchange</a>.<small> (using 1 minute cache)</small>
</p> </p>
</div> </div>
<div class="form-group"> <div class="form-group">