Commit 352b90cc authored by Clint Mourlevat's avatar Clint Mourlevat

Adding display price from coinmarket API

parent 5542d755
......@@ -8,7 +8,9 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using NBitcoin;
using Newtonsoft.Json;
using QRCoder;
using Stratis.Bitcoin.Networks;
......@@ -16,9 +18,20 @@ namespace Stratis.Guru.Controllers
{
public class HomeController : Controller
{
private IMemoryCache _memoryCache;
public HomeController(IMemoryCache memoryCache)
{
_memoryCache = memoryCache;
}
public IActionResult Index()
{
return View();
dynamic coinmarketcap = JsonConvert.DeserializeObject(_memoryCache.Get("Coinmarketcap").ToString());
return View(new Ticker()
{
UsdPrice = coinmarketcap.data.quotes.USD.price
});
}
[Route("about")]
......@@ -62,6 +75,11 @@ namespace Stratis.Guru.Controllers
}
}
public class Ticker
{
public double UsdPrice { get; set; }
}
public class StratisAddressPayload
{
public string PrivateKey { get; set; }
......
......@@ -23,11 +23,10 @@ namespace Stratis.Guru.Services
updateTimer.Interval = 10000;
updateTimer.Elapsed += (sender, args) =>
{
var coinmarketCapApiClient = new RestSharp.RestClient("https://api.coinmarketcap.com/v2/ticker/1343/");
var coinmarketCapApiClient = new RestClient("https://api.coinmarketcap.com/v2/ticker/1343/");
var coinmarketCapApiRequest = new RestRequest(Method.GET);
var coinmarketcapApi = coinmarketCapApiClient.Execute(coinmarketCapApiRequest);
_memoryCache.Set("Coinmarketcap", coinmarketcapApi.Content);
//dynamic resultAPI = JsonConvert.DeserializeObject(coinmarketcapAPI.Content);
};
updateTimer.Start();
return Task.CompletedTask;
......
@{
@model Stratis.Guru.Controllers.Ticker
@{
ViewBag.Title = "Online ticker for Stratis";
ViewData["Title"] = "Home Page";
}
......@@ -12,7 +13,7 @@
<div>
<span class="click-edit">1 STRAT</span> =
</div>
<span class="display-1 font-weight-bold">@(2.ToString("C2"))</span>
<span class="display-1 font-weight-bold">@(Model.UsdPrice.ToString("C2"))</span>
</h1>
<a href="#" class="btn-secondary-box">Download Whitepaper</a>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment