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; ...@@ -8,7 +8,9 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using NBitcoin; using NBitcoin;
using Newtonsoft.Json;
using QRCoder; using QRCoder;
using Stratis.Bitcoin.Networks; using Stratis.Bitcoin.Networks;
...@@ -16,9 +18,20 @@ namespace Stratis.Guru.Controllers ...@@ -16,9 +18,20 @@ namespace Stratis.Guru.Controllers
{ {
public class HomeController : Controller public class HomeController : Controller
{ {
private IMemoryCache _memoryCache;
public HomeController(IMemoryCache memoryCache)
{
_memoryCache = memoryCache;
}
public IActionResult Index() 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")] [Route("about")]
...@@ -62,6 +75,11 @@ namespace Stratis.Guru.Controllers ...@@ -62,6 +75,11 @@ namespace Stratis.Guru.Controllers
} }
} }
public class Ticker
{
public double UsdPrice { get; set; }
}
public class StratisAddressPayload public class StratisAddressPayload
{ {
public string PrivateKey { get; set; } public string PrivateKey { get; set; }
......
...@@ -23,11 +23,10 @@ namespace Stratis.Guru.Services ...@@ -23,11 +23,10 @@ namespace Stratis.Guru.Services
updateTimer.Interval = 10000; updateTimer.Interval = 10000;
updateTimer.Elapsed += (sender, args) => 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 coinmarketCapApiRequest = new RestRequest(Method.GET);
var coinmarketcapApi = coinmarketCapApiClient.Execute(coinmarketCapApiRequest); var coinmarketcapApi = coinmarketCapApiClient.Execute(coinmarketCapApiRequest);
_memoryCache.Set("Coinmarketcap", coinmarketcapApi.Content); _memoryCache.Set("Coinmarketcap", coinmarketcapApi.Content);
//dynamic resultAPI = JsonConvert.DeserializeObject(coinmarketcapAPI.Content);
}; };
updateTimer.Start(); updateTimer.Start();
return Task.CompletedTask; return Task.CompletedTask;
......
@{ @model Stratis.Guru.Controllers.Ticker
@{
ViewBag.Title = "Online ticker for Stratis"; ViewBag.Title = "Online ticker for Stratis";
ViewData["Title"] = "Home Page"; ViewData["Title"] = "Home Page";
} }
...@@ -12,7 +13,7 @@ ...@@ -12,7 +13,7 @@
<div> <div>
<span class="click-edit">1 STRAT</span> = <span class="click-edit">1 STRAT</span> =
</div> </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> </h1>
<a href="#" class="btn-secondary-box">Download Whitepaper</a> <a href="#" class="btn-secondary-box">Download Whitepaper</a>
</div> </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