Implement GetExchangeRatesAsync
MODIFY
MagicalCryptoWallet.Backend/Controllers/BlockchainController.cs
MagicalCryptoWallet.Backend/Controllers/BlockchainController.cs
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
+using System.Threading;
using System.Threading.Tasks;
using MagicalCryptoWallet.Backend.Models;
using MagicalCryptoWallet.Helpers;
using MagicalCryptoWallet.Logging;
+using MagicalCryptoWallet.WebClients.SmartBit;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NBitcoin;
@@ -22,6 +24,8 @@ namespace MagicalCryptoWallet.Backend.Controllers
{
private static RPCClient RpcClient => Global.RpcClient;
+ private static Network Network => Global.Config.Network;
+
/// <summary>
/// Get fees for the requested confirmation targets based on Bitcoin Core's estimatesmartfee output.
/// </summary>
@@ -134,43 +138,23 @@ namespace MagicalCryptoWallet.Backend.Controllers
/// <response code="200">Returns an array of exchange rates.</response>
[HttpGet("exchange-rates")]
[ProducesResponseType(typeof(IEnumerable<ExchangeRate>), 200)]
- public IEnumerable<ExchangeRate> GetExchangeRates()
- {
- using (var client = new HttpClient())
- {
- try
- {
-
- }
- catch
- {
- try
- {
-
- }
- catch
- {
- try
+ public async Task<IEnumerable<ExchangeRate>> GetExchangeRatesAsync()
{
-
- }
- catch
+ // ToDo: Implement caching for instant answers
+ // ToDo: Implement redundancy, call another API if SmartBit fails
+ using (var client = new SmartBitClient(Network, disposeHandler: true))
{
-
- throw;
- }
- }
- }
- }
+ var rates = await client.GetExchangeRatesAsync(CancellationToken.None);
+ var rate = rates.Single(x => x.Code == "USD");
var exchangeRates = new List<ExchangeRate>
{
- new ExchangeRate() { Rate = 10000m, Ticker = "USD" },
- new ExchangeRate() { Rate = 7777.123m, Ticker = "CNY" }
+ new ExchangeRate() { Rate = rate.Rate, Ticker = "USD" },
};
return exchangeRates;
}
+ }
/// <summary>
/// Gets block filters from the specified block hash.

Implement GetExchangeRatesAsync