Commit 8e1aa96a authored by Sondre Bjellås's avatar Sondre Bjellås

Make Stratis.Guru more configureable and adaptable

- Nako supports many different chains, and returns the CoinType from API calls. Use that to show current currency in explorer.
- Enable the configuration of features, enable all by default.
parent f00137e6
......@@ -61,6 +61,22 @@ To run the Stratis.Guru, you need a appsettings.json. This is currently not incl
"Logging": {
"MinimumBreadcrumbLevel": "Information"
}
},
"Setup": {
"Title": "Stratis.guru",
"Chain": "Stratis",
"Footer": ""
},
"Features": {
"Home": true,
"Ticker": false,
"Lottery": false,
"Explorer": true,
"Vanity": false,
"Generator": false,
"API": true,
"About": true,
"Footer": false
}
}
```
......
......@@ -20,17 +20,29 @@ namespace Stratis.Guru.Controllers
private readonly IMemoryCache _memoryCache;
private readonly dynamic _stats;
private readonly BlockIndexService _indexService;
public BlockExplorerController(IMemoryCache memoryCache, IOptions<NakoApiSettings> nakoApiSettings, BlockIndexService indexService)
private readonly SetupSettings _setupSettings;
private readonly FeaturesSettings _featuresSettings;
public BlockExplorerController(IMemoryCache memoryCache,
BlockIndexService indexService,
IOptions<NakoApiSettings> nakoApiSettings,
IOptions<SetupSettings> setupSettings,
IOptions<FeaturesSettings> featuresSettings)
{
_nakoApiSettings = nakoApiSettings.Value;
_memoryCache = memoryCache;
_stats = JsonConvert.DeserializeObject(_memoryCache.Get("BlockchainStats").ToString());
_indexService = indexService;
_nakoApiSettings = nakoApiSettings.Value;
_setupSettings = setupSettings.Value;
_featuresSettings = featuresSettings.Value;
}
public IActionResult Index()
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
var latestBlock = _indexService.GetLatestBlock();
ViewBag.LatestBlock = latestBlock;
......@@ -53,6 +65,9 @@ namespace Stratis.Guru.Controllers
[Route("search")]
public IActionResult Search(SearchBlockExplorer searchBlockExplorer)
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
if (searchBlockExplorer.Query.Length == 34)
{
return RedirectToAction("Address", new {address = searchBlockExplorer.Query});
......@@ -71,6 +86,8 @@ namespace Stratis.Guru.Controllers
[Route("block/{block}")]
public IActionResult Block(string block)
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
ViewBag.BlockchainHeight = _stats.SyncBlockIndex;
var result = (block.ToLower() == "latest") ? _indexService.GetLatestBlock() : _indexService.GetBlockByHeight(int.Parse(block));
......@@ -80,6 +97,8 @@ namespace Stratis.Guru.Controllers
[Route("block/hash/{hash}")]
public IActionResult BlockHash(string hash)
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
ViewBag.BlockchainHeight = _stats.SyncBlockIndex;
return View("Block", _indexService.GetBlockByHash(hash));
......@@ -88,6 +107,8 @@ namespace Stratis.Guru.Controllers
[Route("address/{address}")]
public IActionResult Address(string address)
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
ViewBag.BlockchainHeight = _stats.SyncBlockIndex;
return View(_indexService.GetTransactionsByAddress(address));
......@@ -96,6 +117,8 @@ namespace Stratis.Guru.Controllers
[Route("transaction/{transactionId}")]
public IActionResult Transaction(string transactionId)
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
ViewBag.BlockchainHeight = _stats.SyncBlockIndex;
return View(_indexService.GetTransaction(transactionId));
......
......@@ -35,8 +35,17 @@ namespace Stratis.Guru.Controllers
private readonly IParticipation _participation;
private readonly IDraws _draws;
private readonly DrawSettings _drawSettings;
private readonly SetupSettings _setupSettings;
private readonly FeaturesSettings _featuresSettings;
public HomeController(IMemoryCache memoryCache, IAsk ask, ISettings settings, IParticipation participation, IDraws draws, IOptions<DrawSettings> drawSettings)
public HomeController(IMemoryCache memoryCache,
IAsk ask,
ISettings settings,
IParticipation participation,
IDraws draws,
IOptions<DrawSettings> drawSettings,
IOptions<SetupSettings> setupSettings,
IOptions<FeaturesSettings> featuresSettings)
{
_memoryCache = memoryCache;
_ask = ask;
......@@ -44,10 +53,15 @@ namespace Stratis.Guru.Controllers
_participation = participation;
_draws = draws;
_drawSettings = drawSettings.Value;
_setupSettings = setupSettings.Value;
_featuresSettings = featuresSettings.Value;
}
public IActionResult Index()
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
double displayPrice = 0;
var rqf = Request.HttpContext.Features.Get<IRequestCultureFeature>();
dynamic coinmarketcap = JsonConvert.DeserializeObject(_memoryCache.Get("Coinmarketcap").ToString());
......@@ -83,6 +97,9 @@ namespace Stratis.Guru.Controllers
[Route("lottery")]
public IActionResult Lottery()
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
ViewBag.NextDraw = long.Parse(_memoryCache.Get("NextDraw").ToString());
ViewBag.Jackpot = _memoryCache.Get("Jackpot");
ViewBag.Players = _participation.GetPlayers(_draws.GetLastDraw());
......@@ -94,6 +111,9 @@ namespace Stratis.Guru.Controllers
[Route("lottery/participate")]
public IActionResult Participate()
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
if (ModelState.IsValid)
{
var lastDraw = _draws.GetLastDraw();
......@@ -111,7 +131,10 @@ namespace Stratis.Guru.Controllers
[Route("lottery/participate/{id}")]
public IActionResult Participate(string id)
{
if(HttpContext.Session.GetString("HaveBeginParticipation") == null)
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
if (HttpContext.Session.GetString("HaveBeginParticipation") == null)
{
return RedirectToAction("Lottery");
}
......@@ -130,6 +153,9 @@ namespace Stratis.Guru.Controllers
[Route("lottery/check-payment")]
public IActionResult CheckPayment()
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
var pubkey = ExtPubKey.Parse(_drawSettings.PublicKey);
var depositAddress = pubkey.Derive(0).Derive(_settings.GetIterator()).PubKey.GetAddress(Network.StratisMain).ToString();
ViewBag.DepositAddress = depositAddress;
......@@ -150,6 +176,9 @@ namespace Stratis.Guru.Controllers
[Route("lottery/new-participation")]
public IActionResult NewParticipation()
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
var ticket = Guid.NewGuid().ToString();
HttpContext.Session.SetString("Ticket", ticket);
ViewBag.Ticket = ticket;
......@@ -168,6 +197,9 @@ namespace Stratis.Guru.Controllers
[Route("lottery/participated")]
public IActionResult Participated()
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
ViewBag.NextDraw = long.Parse(_memoryCache.Get("NextDraw").ToString());
ViewBag.Jackpot = _memoryCache.Get("Jackpot");
ViewBag.Players = _participation.GetPlayers(_draws.GetLastDraw());
......@@ -178,12 +210,18 @@ namespace Stratis.Guru.Controllers
[Route("about")]
public IActionResult About()
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
return View();
}
[Route("vanity")]
public IActionResult Vanity()
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
return View();
}
......@@ -191,6 +229,9 @@ namespace Stratis.Guru.Controllers
[Route("vanity")]
public IActionResult Vanity(Vanity vanity)
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
if (ModelState.IsValid)
{
_ask.NewVanity(vanity);
......@@ -202,6 +243,9 @@ namespace Stratis.Guru.Controllers
[Route("generator")]
public IActionResult Generator()
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
var stratisAddress = new Key();
return View(new StratisAddressPayload
{
......@@ -213,6 +257,9 @@ namespace Stratis.Guru.Controllers
[Route("qr/{value}")]
public IActionResult Qr(string value)
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
var memoryStream = new MemoryStream();
var qrGenerator = new QRCodeGenerator();
var qrCodeData = qrGenerator.CreateQrCode(value, QRCodeGenerator.ECCLevel.L);
......@@ -223,6 +270,9 @@ namespace Stratis.Guru.Controllers
public IActionResult Documentation()
{
ViewBag.Features = _featuresSettings;
ViewBag.Setup = _setupSettings;
return Redirect("/documentation");
}
}
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Stratis.Guru.Settings
{
public class FeaturesSettings
{
public bool Home { get; set; } = true;
public bool Ticker { get; set; } = true;
public bool Lottery { get; set; } = true;
public bool Explorer { get; set; } = true;
public bool Vanity { get; set; } = true;
public bool Generator { get; set; } = true;
public bool API { get; set; } = true;
public bool About { get; set; } = true;
public bool Footer { get; set; } = true;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Stratis.Guru.Settings
{
public class SetupSettings
{
public SetupSettings()
{
Title = "Stratis.guru";
Chain = "Stratis";
}
public string Title { get; set; }
public string Chain { get; set; }
public string Footer { get; set; }
}
}
......@@ -53,6 +53,8 @@ namespace Stratis.Guru
services.Configure<FixerApiSettings>(Configuration.GetSection("FixerApi"));
services.Configure<DrawSettings>(Configuration.GetSection("Draw"));
services.Configure<TickerSettings>(Configuration.GetSection("Ticker"));
services.Configure<SetupSettings>(Configuration.GetSection("Setup"));
services.Configure<FeaturesSettings>(Configuration.GetSection("Features"));
services.AddMemoryCache();
......
......@@ -41,20 +41,20 @@
</tr>
<tr>
<td><strong>Balance</strong></td>
<td>@Model.Balance.ToString("N8") STRAT</td>
<td>@Model.Balance.ToString("N8") @Model.CoinTag</td>
</tr>
<tr>
<td><strong>Unconfirmed Balance</strong></td>
<td>@Model.UnconfirmedBalance.ToString("N8") STRAT</td>
<td>@Model.UnconfirmedBalance.ToString("N8") @Model.CoinTag</td>
</tr>
<tr>
<td><strong>Total Received</strong></td>
<td>@Model.TotalReceived.ToString("N8") STRAT</td>
<td>@Model.TotalReceived.ToString("N8") @Model.CoinTag</td>
</tr>
<tr>
<td><strong>Total Sent</strong></td>
<td>@Model.TotalSent.ToString("N8") STRAT</td>
<td>@Model.TotalSent.ToString("N8") @Model.CoinTag</td>
</tr>
</tbody>
</table>
......@@ -97,8 +97,8 @@
<td><a asp-controller="BlockExplorer" asp-action="Transaction" asp-route-transactionId="@transaction.TransactionHash">@transaction.TransactionHash.ToString().Substring(0, 25)...</a></td>
<td><a asp-controller="BlockExplorer" asp-action="Block" asp-route-block="@transaction.BlockIndex">@transaction.BlockIndex</a></td>
<td>-</td>
<td><span class="@(transaction.Value > 0 ? "green" : "red")">@transaction.Value.ToString("N8") STRAT</span></td>
<td>@total.ToString("N8") STRAT</td>
<td><span class="@(transaction.Value > 0 ? "green" : "red")">@transaction.Value.ToString("N8") @Model.CoinTag</span></td>
<td>@total.ToString("N8") @Model.CoinTag</td>
</tr>
}
</tbody>
......
@model dynamic
@{
ViewBag.Title = "Stratis Block Explorer";
ViewBag.Title = ViewBag.Setup.Chain + " Block Explorer";
Layout = "_Layout";
}
@section Style
......
......@@ -4,10 +4,10 @@
<div class="container text-center">
<div class="row">
<div class="col-lg-12 align-self-center">
<h1>Stratis Blockchain Explorer</h1>
<h1>@ViewBag.Setup.Chain Block Explorer</h1>
</div>
<div class="offset-lg-3 col-lg-6">
<p>Actual Stratis Blocks Height: @(ViewBag.BlockchainHeight??"Loading...") @*<i class="fa help fa-info-circle" data-toggle="tooltip" data-placement="right" title="Last Stratis Block Height, updated every 10 min."></i>*@</p>
<p>Actual Blocks Height: @(ViewBag.BlockchainHeight ?? "Loading...") @*<i class="fa help fa-info-circle" data-toggle="tooltip" data-placement="right" title="Last Stratis Block Height, updated every 10 min."></i>*@</p>
</div>
</div>
</div>
......
......@@ -73,9 +73,9 @@
}
@foreach (var t in Model.Outputs)
{
totalOutpus += (double) t.Balance;
totalOutpus += (double)t.Balance;
}
@totalOutpus.ToString("N8") STRAT
@totalOutpus.ToString("N8") @Model.CoinTag
</td>
</tr>
}
......@@ -140,7 +140,7 @@
<td>@output.Index</td>
<td><a asp-controller="BlockExplorer" asp-action="Address" asp-route-address="@output.Address">@output.Address</a></td>
<td>@output.OutputType</td>
<td>@output.Balance.ToString("N8") STRAT</td>
<td>@output.Balance.ToString("N8") @Model.CoinTag</td>
</tr>
}
</tbody>
......
......@@ -8,14 +8,19 @@
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 align-self-center text-center">
@if (ViewBag.Features.Ticker)
{
<h1 class="m-0">The <strong>$STRAT</strong> price in real time.</h1>
<h1 class="align-middle">
<div class="d-lg-inline-block d-md-block align-middle">
<span class="click-edit" spellcheck="false">1</span> STRAT <span class="d-none d-lg-inline-block">=</span>
</div>
<span class="align-middle display-1 font-weight-bold" id="amount">@(Model.DisplayPrice.ToString("C2"))</span>
<span id="lastchange" class="d-block d-lg-inline-block change-@(Model.Last24Change > 0 ? "success":"danger") font-weight-bold"><sup> <span class="d-none d-lg-inline-block">@((Model.Last24Change > 0 ? "+":""))</span> <span class="inner">@(Model.Last24Change.ToString("P2"))</span></sup></span>
<span id="lastchange" class="d-block d-lg-inline-block change-@(Model.Last24Change > 0 ? "success":"danger") font-weight-bold"><sup> <span class="d-none d-lg-inline-block">@((Model.Last24Change > 0 ? "+" : ""))</span> <span class="inner">@(Model.Last24Change.ToString("P2"))</span></sup></span>
</h1>
}
<a asp-controller="BlockExplorer" asp-action="Index" class="btn-secondary-box"><i class="fa fa-cube"></i> Go to Block Explorer</a>
</div>
</div>
......
......@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Stratis.Guru | @ViewBag.Title</title>
<title>@ViewBag.Setup.Title | @ViewBag.Title</title>
<meta name="Content-Language" content="en">
<meta name="Description" content="@(ViewBag.Description ?? "Stratis.Guru is a Simple and Free $STRAT ticker, an Stratis Address Generator and a Vanity Address service.")">
<meta name="Keywords" content="stratis,bitcoin,cryptos,cryptocurrencies,coins,$STRAT,ticker,explorer,block explorer,vanity address,stratis block explorer,$strat block explorer,stratis generator,stratis price ticker,stratis preev,stratis vanity address,clint.network,SR2ZXnhRnMqJNoeDiCFUnaug7TKHJocwDd,">
......@@ -14,7 +14,7 @@
<meta name="Revisit-After" content="1 day">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="clint_network">
<meta name="twitter:title" content="Stratis.Guru | Online Stratis ($STRAT) price ticker">
<meta name="twitter:title" content="@ViewBag.Setup.Title | Online Stratis ($STRAT) price ticker">
<meta name="twitter:description" content="Stratis.Guru is a Simple and Free $STRAT ticker, an Stratis Address Generator and a Vanity Address service.">
<link rel="icon" href="~/favicon.ico" />
<link href="~/css/bootstrap.min.css" rel="stylesheet" type="text/css">
......@@ -31,22 +31,49 @@
@RenderSection("Style", false)
</head>
<body>
<header class="header-area">
<header class="header-area">
<div class="container">
<div class="row">
<div class="col-12">
<nav class="main-nav">
<a asp-controller="Home" asp-action="Index" class="logo ">
<img src="~/images/logo.png" class="" alt="Stratis.guru"/> <span class="text-white">Stratis</span><span class="text-muted">.guru</span> <span class="text-info text-hide">v2</span>
<img src="~/images/logo.png" class="" alt="Stratis.guru" /> <span class="text-white">@ViewBag.Setup.Title</span> <span class="text-info text-hide">v2</span>
</a>
<ul class="nav">
@if (ViewBag.Features.Home)
{
<li class="@(Context.Request.Path.Equals(Url.Action("Index", "Home")) ? "active":"")"><a asp-action="Index" asp-controller="Home"><i class="fa fa-home"></i> HOME</a></li>
}
@if (ViewBag.Features.Lottery)
{
<li class="@(Context.Request.Path.Equals(Url.Action("Lottery", "Home")) ? "active":"")"><a asp-action="Lottery" asp-controller="Home"><i class="fa fa-trophy"></i> LOTTERY</a></li>
}
@if (ViewBag.Features.Explorer)
{
<li class="@(Context.Request.Path.Equals(Url.Action("Index", "BlockExplorer")) ? "active":"")"><a asp-action="Index" asp-controller="BlockExplorer"><i class="fa fa-cube"></i> BLOCK EXPLORER</a></li>
}
@if (ViewBag.Features.Vanity)
{
<li class="@(Context.Request.Path.Equals(Url.Action("Vanity", "Home")) ? "active":"")"><a asp-action="Vanity" asp-controller="Home"><i class="fa fa-at"></i> VANITY</a></li>
}
@if (ViewBag.Features.Generator)
{
<li class="@(Context.Request.Path.Equals(Url.Action("Generator", "Home")) ? "active":"")"><a asp-action="Generator" asp-controller="Home"><i class="fa fa-qrcode"></i> GENERATOR</a></li>
}
@if (ViewBag.Features.API)
{
<li class="@(Context.Request.Path.Equals(Url.Action("Documentation", "Home")) ? "active":"")"><a asp-action="Documentation" asp-controller="Home"><i class="fa fa-book"></i> API</a></li>
}
@if (ViewBag.Features.About)
{
<li class="@(Context.Request.Path.Equals(Url.Action("About", "Home")) ? "active":"")"><a asp-action="About" asp-controller="Home"><i class="fa fa-info-circle"></i> ABOUT</a></li>
}
</ul>
<a class='menu-trigger'>
<span>Menu</span>
......@@ -55,28 +82,34 @@
</div>
</div>
</div>
</header>
@RenderBody()
<div id="crafted">
</header>
@RenderBody()
@if (ViewBag.Features.Footer)
{
<div id="crafted">
<p class="text-center small">Proudly Crafted with 💖 by <a href="https://twitter.com/clint_network" target="_blank">Clint.Network</a> — Help me to maintain by sending some $STRAT at <a asp-controller="BlockExplorer" asp-action="Address" asp-route-address="SXDaQGs56aC9ZjFzTdbhudNXTbyxU5aNXJ">SXDaQGs56aC9ZjFzTdbhudNXTbyxU5aNXJ</a>.</p>
</div>
<script src="~/js/jquery-2.1.0.min.js"></script>
<script src="~/js/popper.js"></script>
<script src="~/js/bootstrap.min.js"></script>
<script src="~/js/particles.min.js"></script>
<script src="~/js/scrollreveal.min.js"></script>
<script src="~/js/jquery.downCount.js"></script>
<script src="~/js/parallax.min.js"></script>
<script src="~/js/owl.carousel.min.js"></script>
<script src="~/js/particle-green.js"></script>
<script src="~/lib/nprogress/nprogress.js"></script>
<environment include="Development">
</div>
}
<script src="~/js/jquery-2.1.0.min.js"></script>
<script src="~/js/popper.js"></script>
<script src="~/js/bootstrap.min.js"></script>
<script src="~/js/particles.min.js"></script>
<script src="~/js/scrollreveal.min.js"></script>
<script src="~/js/jquery.downCount.js"></script>
<script src="~/js/parallax.min.js"></script>
<script src="~/js/owl.carousel.min.js"></script>
<script src="~/js/particle-green.js"></script>
<script src="~/lib/nprogress/nprogress.js"></script>
<environment include="Development">
<script src="~/js/default.js"></script>
</environment>
<environment exclude="Development">
</environment>
<environment exclude="Development">
<script src="~/js/default.min.js"></script>
</environment>
@RenderSection("Scripts", false)
</environment>
@RenderSection("Scripts", false)
</body>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-111742056-1"></script>
<script>
......
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