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

Commit

Permalink
Add QR code viewer for address
Browse files Browse the repository at this point in the history
- Reintroduce the QR code image on address view.
- Hide the total count, which was just confusing.
- Prepare time column with a <time> tag. Indexer need fix before displaying the date.
  • Loading branch information
sondreb committed Apr 12, 2020
1 parent e2b970c commit eaf3082
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/Blockcore.Explorer/Blockcore.Explorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.10" />
<PackageReference Include="NStratis" Version="4.0.0.77" />
<PackageReference Include="QRCoder" Version="1.3.9" />
<PackageReference Include="RestSharp" Version="106.10.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="5.0.0" />
Expand Down
19 changes: 19 additions & 0 deletions src/Blockcore.Explorer/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using Blockcore.Explorer.Models;
using Blockcore.Explorer.Services;
using Blockcore.Explorer.Settings;
Expand All @@ -8,6 +11,7 @@
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using QRCoder;

namespace Blockcore.Explorer.Controllers
{
Expand Down Expand Up @@ -93,5 +97,20 @@ public IActionResult About()

return View();
}

[Route("qr/{value}")]
public IActionResult Qr(string value)
{
ViewBag.Features = settings.Features;
ViewBag.Setup = settings.Setup;

var memoryStream = new MemoryStream();

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(value, QRCodeGenerator.ECCLevel.L);
var qrCode = new QRCode(qrCodeData);
qrCode.GetGraphic(20, Color.Black, Color.White, false).Save(memoryStream, ImageFormat.Png);
return File(memoryStream.ToArray(), "image/png");
}
}
}
4 changes: 2 additions & 2 deletions src/Blockcore.Explorer/Models/ApiModels/AddressModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;

namespace Blockcore.Explorer.Models.ApiModels
{
Expand All @@ -10,7 +10,7 @@ public AddressModel()
UnconfirmedTransactions = new List<TransactionModel>();
}

public string CoinTag { get; set; }
public string Symbol { get; set; }

public string Address { get; set; }

Expand Down
6 changes: 4 additions & 2 deletions src/Blockcore.Explorer/Models/ApiModels/TransactionModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Blockcore.Explorer.Models.ApiModels
namespace Blockcore.Explorer.Models.ApiModels
{
public class TransactionModel
{
Expand All @@ -12,7 +12,9 @@ public class TransactionModel

public string PubScriptHex { get; set; }

public string CoinBase { get; set; }
public bool CoinBase { get; set; }

public bool CoinStake { get; set; }

public long Value { get; set; }

Expand Down
54 changes: 54 additions & 0 deletions src/Blockcore.Explorer/TagHelpers/TimeTagHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Globalization;
using Blockcore.Explorer.Settings;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Blockcore.Explorer.TagHelpers
{
public class TimeTagHelper : TagHelper
{
private readonly ExplorerSettings settings;

private readonly ChainSettings chainSettings;

private readonly ILogger<TimeTagHelper> log;

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

public override void Process(TagHelperContext context, TagHelperOutput output)
{
// TODO: When the Blockcore Indexer returns correct time for transactions, enable the code below!
output.Content.SetContent("-");
return;

string input = output.GetChildContentAsync().Result.GetContent();
bool success = long.TryParse(input, out long value);

if (success)
{
try
{
string text = DateTimeOffset.FromUnixTimeSeconds(value).ToString("F");
string html = $"<span class=\"time-value\">{text}</span>";
output.Content.SetHtmlContent(html);
}
catch (Exception ex)
{
log.LogError(ex, $"Failed to parse in TimeTagHelper. Input was {input} and parsed value was {value}.");
output.Content.SetContent(input);
}
}
else
{
output.Content.SetContent(input);
}
}
}
}
10 changes: 2 additions & 8 deletions src/Blockcore.Explorer/Views/BlockExplorer/Address.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,16 @@
<th>Block</th>
<th>Date/Time</th>
<th>Amount</th>
<th>Balance</th>
</tr>
</thead>
<tbody>
@{
long total = 0;
}
@foreach (var transaction in Model.Transactions)
{
total += (long)transaction.Value;
<tr>
<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><time>@transaction.Time</time></td>
<td><coin positive="@(transaction.Value > 0)">@transaction.Value</coin></td>
<td><coin>@total</coin></td>
</tr>
}
</tbody>
Expand All @@ -122,4 +116,4 @@
})
});
</script>
}
}

0 comments on commit eaf3082

Please sign in to comment.