Skip to content
This repository has been archived by the owner on Jan 31, 2022. It is now read-only.

Commit

Permalink
Update with latest configuration schema (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreb authored Feb 3, 2020
1 parent a4346c1 commit 8f3f8bc
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blockcoreexplorer",
"version": "0.0.1",
"version": "0.0.2",
"license": "MIT",
"author": {
"name": "Blockcore",
Expand Down
10 changes: 9 additions & 1 deletion src/Blockcore.Explorer/Controllers/BlockExplorerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ namespace Blockcore.Explorer.Controllers
public class BlockExplorerController : Controller
{
private readonly ExplorerSettings settings;
private readonly ChainSettings chainSettings;
private readonly IMemoryCache memoryCache;
private readonly Status stats;
private readonly BlockIndexService indexService;

public BlockExplorerController(IMemoryCache memoryCache,
BlockIndexService indexService,
IOptions<ExplorerSettings> settings)
IOptions<ExplorerSettings> settings,
IOptions<ChainSettings> chainSettings)
{
this.memoryCache = memoryCache;

Expand All @@ -38,13 +40,15 @@ public BlockExplorerController(IMemoryCache memoryCache,

this.indexService = indexService;
this.settings = settings.Value;
this.chainSettings = chainSettings.Value;
}

[HttpGet]
public IActionResult Index()
{
ViewBag.Features = settings.Features;
ViewBag.Setup = settings.Setup;
ViewBag.Chain = chainSettings;

try
{
Expand Down Expand Up @@ -78,6 +82,7 @@ public IActionResult Search(SearchBlockExplorer searchBlockExplorer)
{
ViewBag.Features = settings.Features;
ViewBag.Setup = settings.Setup;
ViewBag.Chain = chainSettings;

if (searchBlockExplorer.Query == null)
{
Expand Down Expand Up @@ -105,6 +110,7 @@ public IActionResult Block(string block)
{
ViewBag.Features = settings.Features;
ViewBag.Setup = settings.Setup;
ViewBag.Chain = chainSettings;

ViewBag.BlockchainHeight = stats.SyncBlockIndex;

Expand All @@ -130,6 +136,7 @@ public IActionResult Address(string address)
{
ViewBag.Features = settings.Features;
ViewBag.Setup = settings.Setup;
ViewBag.Chain = chainSettings;

ViewBag.BlockchainHeight = stats.SyncBlockIndex;

Expand All @@ -142,6 +149,7 @@ public IActionResult Transaction(string transactionId)
{
ViewBag.Features = settings.Features;
ViewBag.Setup = settings.Setup;
ViewBag.Chain = chainSettings;

ViewBag.BlockchainHeight = stats.SyncBlockIndex;

Expand Down
7 changes: 6 additions & 1 deletion src/Blockcore.Explorer/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ public class HomeController : Controller
private readonly TickerService tickerService;
private readonly CurrencyService currencyService;
private readonly ExplorerSettings settings;
private readonly ChainSettings chainSettings;
private readonly ILogger<HomeController> log;

public HomeController(IMemoryCache memoryCache,
ILogger<HomeController> log,
TickerService tickerService,
CurrencyService currencyService,
IOptions<ExplorerSettings> settings)
IOptions<ExplorerSettings> settings,
IOptions<ChainSettings> chainSettings)
{
this.memoryCache = memoryCache;
this.log = log;
this.settings = settings.Value;
this.chainSettings = chainSettings.Value;
this.tickerService = tickerService;
this.currencyService = currencyService;
}
Expand All @@ -42,6 +45,7 @@ public IActionResult Index()

ViewBag.Features = settings.Features;
ViewBag.Setup = settings.Setup;
ViewBag.Chain = chainSettings;
ViewBag.Ticker = settings.Ticker;
ViewBag.Url = Request.Host.ToString();

Expand Down Expand Up @@ -75,6 +79,7 @@ public IActionResult About()
{
ViewBag.Features = settings.Features;
ViewBag.Setup = settings.Setup;
ViewBag.Chain = chainSettings;

return View();
}
Expand Down
8 changes: 4 additions & 4 deletions src/Blockcore.Explorer/Handlers/FavoriteIconHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class FavoriteIconHandler
{
private readonly RequestDelegate next;

private readonly ExplorerSettings settings;
private readonly ChainSettings settings;

private readonly HttpClient http;

public FavoriteIconHandler(RequestDelegate next, IOptions<ExplorerSettings> settings)
public FavoriteIconHandler(RequestDelegate next, IOptions<ChainSettings> settings)
{
this.next = next;
this.settings = settings.Value;
Expand All @@ -26,14 +26,14 @@ public FavoriteIconHandler(RequestDelegate next, IOptions<ExplorerSettings> sett

public async Task Invoke(HttpContext context)
{
if (string.IsNullOrWhiteSpace(settings.Setup.Icon))
if (string.IsNullOrWhiteSpace(settings.Icon))
{
context.Response.StatusCode = 404;
return;
}

// Perhaps in the future this can be improved a tiny bit?
byte[] bytes = await http.GetByteArrayAsync(settings.Setup.Icon);
byte[] bytes = await http.GetByteArrayAsync(settings.Icon);
await context.Response.Body.WriteAsync(bytes, 0, bytes.Length);
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/Blockcore.Explorer/Settings/ChainSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Blockcore.Explorer.Settings
{
public class ChainSettings
{
public string Name { get; set; }

public string Symbol { get; set; }

public string Description { get; set; }

public string Url { get; set; }

public string Logo { get; set; }

public string Icon { get; set; }
}
}
7 changes: 0 additions & 7 deletions src/Blockcore.Explorer/Settings/SetupSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@ public class SetupSettings
public SetupSettings()
{
Title = "Blockcore Explorer";
Chain = "BTC";
DocumentationUrl = "/docs";
}

public string Title { get; set; }

public string Chain { get; set; }

public string Coin { get; set; }

public string Footer { get; set; }

public string Icon { get; set; }

public string DocumentationUrl { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Blockcore.Explorer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public Startup(IConfiguration configuration)

public void ConfigureServices(IServiceCollection services)
{
services.Configure<ChainSettings>(Configuration.GetSection("Chain"));
services.Configure<ExplorerSettings>(Configuration.GetSection("Explorer"));

services.AddSingleton<BlockIndexService>();
Expand Down
7 changes: 5 additions & 2 deletions src/Blockcore.Explorer/TagHelpers/CoinTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ public class CoinTagHelper : TagHelper
{
private readonly ExplorerSettings settings;

private readonly ChainSettings chainSettings;

private readonly ILogger<CoinTagHelper> log;

[HtmlAttributeName("Positive")]
public bool? Positive { get; set; }

public CoinTagHelper(IOptions<ExplorerSettings> settings, ILogger<CoinTagHelper> log)
public CoinTagHelper(IOptions<ExplorerSettings> settings, IOptions<ChainSettings> chainSettings, ILogger<CoinTagHelper> log)
{
this.settings = settings.Value;
this.chainSettings = chainSettings.Value;
this.log = log;
}

Expand All @@ -39,7 +42,7 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
try
{
string[] values = (value / 100000000d).ToString("N8").Split(NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator);
string html = $"<span class=\"coin-value-upper {cssExtra}\">{values[0]}</span><span class=\"coin-value-lower {cssExtra}\">{NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator}{values[1]}</span> <span class=\"coin-value-tag {cssExtra}\">{settings.Setup.Coin}</span>";
string html = $"<span class=\"coin-value-upper {cssExtra}\">{values[0]}</span><span class=\"coin-value-lower {cssExtra}\">{NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator}{values[1]}</span> <span class=\"coin-value-tag {cssExtra}\">{chainSettings.Symbol}</span>";
output.Content.SetHtmlContent(html);
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="container text-center">
<div class="row">
<div class="col-lg-12 align-self-center">
<h1>@ViewBag.Setup.Chain Block Explorer</h1>
<h1>@ViewBag.Chain.Name Block Explorer</h1>
</div>
<div class="offset-lg-3 col-lg-6">
<p>Actual Blocks Height: @(ViewBag.BlockchainHeight ?? "Loading...")
Expand Down
4 changes: 2 additions & 2 deletions src/Blockcore.Explorer/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@{
if (ViewBag.Features.Ticker)
{
ViewBag.Title = $"{ViewBag.Setup.Chain} (${ViewBag.Setup.Coin}) price ticker";
ViewBag.Title = $"{ViewBag.Chain.Name} (${ViewBag.Chain.Symbol}) price ticker";
}
else
{
Expand All @@ -18,7 +18,7 @@

@if (ViewBag.Features.Ticker)
{
<h1 class="m-0">The <strong>$@ViewBag.Setup.Coin</strong> price in real time.</h1>
<h1 class="m-0">The <strong>$@ViewBag.Chain.Symbol</strong> price in real time.</h1>
<h1 class="align-middle">
<span class="align-middle display-1 font-weight-bold" id="amount">@(Model.PriceBtc) <i class="reduced-fab fab fa-btc"></i></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>
Expand Down
8 changes: 4 additions & 4 deletions src/Blockcore.Explorer/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>@ViewBag.Title | @ViewBag.Setup.Title</title>
<meta name="Content-Language" content="en">
<meta name="Description" content="@(ViewBag.Description ?? $"{ViewBag.Setup.Title} is a Simple and Free ${ViewBag.Setup.Coin} ticker, an Address Generator and a Vanity Address service.")">
<meta name="Keywords" content="bitcoin,cryptos,cryptocurrencies,coins,$@ViewBag.Setup.Coin,ticker,explorer,block explorer">
<meta name="Description" content="@(ViewBag.Description ?? $"{ViewBag.Setup.Title} is a simple and free ${ViewBag.Chain.Symbol} ticker.")">
<meta name="Keywords" content="bitcoin,cryptos,cryptocurrencies,coins,$@ViewBag.Chain.Symbol,ticker,explorer,block explorer">
<link rel="icon" type="image/png" href="/favicon">
<link href="~/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="~/css/all.css?v2" rel="stylesheet" type="text/css">
Expand All @@ -27,9 +27,9 @@
<div class="col-12">
<nav class="main-nav">
<a asp-controller="Home" asp-action="Index" class="logo ">
@if (!string.IsNullOrWhiteSpace(ViewBag.Setup.Icon))
@if (!string.IsNullOrWhiteSpace(ViewBag.Chain.Icon))
{
<img src="@ViewBag.Setup.Icon" class="" alt="@ViewBag.Setup.Title" />
<img src="@ViewBag.Chain.Icon" class="" alt="@ViewBag.Setup.Title" />
}
else
{
Expand Down
15 changes: 10 additions & 5 deletions src/Blockcore.Explorer/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@
"IncludeScopes": true
}
},
"Chain": {
"Name": "City Chain",
"Symbol": "CITY",
"Description": "Blockchain for Smart Cities",
"Url": "https://www.city-chain.org/",
"Logo": "https://www.city-chain.org/images/icons/city-coin-128x128.png",
"Icon": "https://www.city-chain.org/images/icons/city-coin-128x128.png"
},
"Explorer": {
"Indexer": {
"ApiUrl": "http://indexer.city-chain.org/api/" // Default port for locally running Blockcore Indexer.
"ApiUrl": "http://city.indexer.blockcore.net/api/" // Default port for locally running Blockcore Indexer.
// "ApiUrl": "http://localhost:9910/api/" // Default port for locally running Blockcore Indexer.
},
"Currency": {
Expand All @@ -36,10 +44,7 @@
//},
"Setup": {
"Title": "City Chain Explorer",
"Chain": "City Chain",
"Coin": "CITY",
"Footer": "https://www.city-chain.org",
"Icon": "https://www.city-chain.org/images/icons/city-coin-128x128.png"
"Footer": "https://www.city-chain.org"
},
"Features": {
"Home": true,
Expand Down

0 comments on commit 8f3f8bc

Please sign in to comment.