mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-21 07:54:25 +01:00
unwrap rates in api/rates
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||||
<Version>1.0.1.15</Version>
|
<Version>1.0.1.16</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Remove="Build\dockerfiles\**" />
|
<Compile Remove="Build\dockerfiles\**" />
|
||||||
|
|||||||
@@ -33,16 +33,27 @@ namespace BTCPayServer.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[BitpayAPIConstraint]
|
[BitpayAPIConstraint]
|
||||||
public async Task<IActionResult> GetRates(string cryptoCode = null, string storeId = null)
|
public async Task<IActionResult> GetRates(string cryptoCode = null, string storeId = null)
|
||||||
|
{
|
||||||
|
var result = await GetRates2(cryptoCode, storeId);
|
||||||
|
var rates = (result as JsonResult)?.Value as NBitpayClient.Rate[];
|
||||||
|
if(rates == null)
|
||||||
|
return result;
|
||||||
|
return Json(new DataWrapper<NBitpayClient.Rate[]>(rates));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route("api/rates")]
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> GetRates2(string cryptoCode = null, string storeId = null)
|
||||||
{
|
{
|
||||||
cryptoCode = cryptoCode ?? "BTC";
|
cryptoCode = cryptoCode ?? "BTC";
|
||||||
var network= _NetworkProvider.GetNetwork(cryptoCode);
|
var network = _NetworkProvider.GetNetwork(cryptoCode);
|
||||||
if (network == null)
|
if (network == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
var rateProvider = _RateProviderFactory.GetRateProvider(network);
|
var rateProvider = _RateProviderFactory.GetRateProvider(network);
|
||||||
if (rateProvider == null)
|
if (rateProvider == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
if(storeId != null)
|
if (storeId != null)
|
||||||
{
|
{
|
||||||
var store = await _StoreRepo.FindStore(storeId);
|
var store = await _StoreRepo.FindStore(storeId);
|
||||||
if (store == null)
|
if (store == null)
|
||||||
@@ -51,22 +62,13 @@ namespace BTCPayServer.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
var allRates = (await rateProvider.GetRatesAsync());
|
var allRates = (await rateProvider.GetRatesAsync());
|
||||||
return Json(new DataWrapper<NBitpayClient.Rate[]>
|
return Json(allRates.Select(r =>
|
||||||
(allRates.Select(r =>
|
|
||||||
new NBitpayClient.Rate()
|
new NBitpayClient.Rate()
|
||||||
{
|
{
|
||||||
Code = r.Currency,
|
Code = r.Currency,
|
||||||
Name = _CurrencyNameTable.GetCurrencyData(r.Currency)?.Name,
|
Name = _CurrencyNameTable.GetCurrencyData(r.Currency)?.Name,
|
||||||
Value = r.Value
|
Value = r.Value
|
||||||
}).Where(n => n.Name != null).ToArray()));
|
}).Where(n => n.Name != null).ToArray());
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("api/rates")]
|
|
||||||
[HttpGet]
|
|
||||||
public Task<IActionResult> GetRates2(string cryptoCode = null, string storeId = null)
|
|
||||||
{
|
|
||||||
return GetRates(cryptoCode, storeId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user