Skip to content

Commit

Permalink
Add favorite icon handling for the UI (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreb authored Jun 23, 2020
1 parent 3ad6e00 commit 29194d6
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/External/NBitcoin/NBitcoin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="icon.png" />
</ItemGroup>

</Project>
27 changes: 27 additions & 0 deletions src/External/NBitcoin/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public NetworksSelector(Func<Network> mainnet, Func<Network> testnet, Func<Netwo

public abstract class Network
{
private string icon = string.Empty;

protected Block Genesis;

/// <summary>
Expand Down Expand Up @@ -789,5 +791,30 @@ public Transaction CreateTransaction(byte[] bytes)
{
return this.Consensus.ConsensusFactory.CreateTransaction(bytes);
}

public string FavoriteIcon()
{
if (!string.IsNullOrWhiteSpace(this.icon))
{
return this.icon;
}

System.Reflection.Assembly assembly = this.GetType().Assembly;
var iconResource = assembly.GetManifestResourceNames().FirstOrDefault(r => r.Contains("icon"));

if (string.IsNullOrWhiteSpace(iconResource))
{
assembly = typeof(NBitcoin.Network).Assembly;
iconResource = assembly.GetManifestResourceNames().FirstOrDefault(r => r.Contains("icon"));
}

using (Stream stream = assembly.GetManifestResourceStream(iconResource))
{
byte[] bytes = new BinaryReader(stream).ReadBytes((int)stream.Length);
this.icon = Convert.ToBase64String(bytes);
}

return this.icon;
}
}
}
Binary file added src/External/NBitcoin/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions src/Features/Blockcore.Features.NodeHost/UI/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@page "/"
@namespace Blockcore.Features.NodeHost.UI.Pages
@inject NBitcoin.Network Network
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, BlazorModal
@{
Expand All @@ -14,7 +15,8 @@
<title>Dashboard</title>
<base href="~/" />
<link rel="stylesheet" href="css/bootstrap/darkstrap.min.css" />
<link rel="stylesheet" href="css/site.css"/>
<link rel="stylesheet" href="css/site.css" />
<link id="favicon" rel="shortcut icon" type="image/png" href="data:image/png;base64,@this.Network.FavoriteIcon()">
</head>
<body>
<app>
Expand All @@ -35,12 +37,12 @@
<script src="_framework/blazor.server.js"></script>
<script>
window.clipboardCopy = {
copyText: function(text) {
copyText: function (text) {
navigator.clipboard.writeText(text).then(function () {
})
.catch(function (error) {
alert(error);
});
.catch(function (error) {
alert(error);
});
}
};
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="icon.png" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\External\NBitcoin\NBitcoin.csproj" />
<ProjectReference Include="..\..\..\Features\Blockcore.Features.Consensus\Blockcore.Features.Consensus.csproj" />
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion src/Networks/City/City/Blockcore.Networks.City.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Authors>Blockcore</Authors>
Expand All @@ -13,6 +13,10 @@
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="ico.png" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\External\NBitcoin\NBitcoin.csproj" />
<ProjectReference Include="..\..\..\Features\Blockcore.Features.Consensus\Blockcore.Features.Consensus.csproj" />
Expand Down
3 changes: 3 additions & 0 deletions src/Networks/City/City/CitySetup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.Versioning;
using City.Networks;
using City.Networks.Setup;
using NBitcoin;
Expand Down
Binary file added src/Networks/City/City/ico.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="icon.png" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\External\NBitcoin\NBitcoin.csproj" />
<ProjectReference Include="..\..\..\Features\Blockcore.Features.Consensus\Blockcore.Features.Consensus.csproj" />
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="icon.png" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\External\NBitcoin\NBitcoin.csproj" />
<ProjectReference Include="..\..\..\Features\Blockcore.Features.Consensus\Blockcore.Features.Consensus.csproj" />
Expand Down
Binary file added src/Networks/Xds/Blockcore.Networks.Xds/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Networks/x42/x42/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/Networks/x42/x42/x42.Networks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="icon.png" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\External\NBitcoin\NBitcoin.csproj" />
<ProjectReference Include="..\..\..\Features\Blockcore.Features.Consensus\Blockcore.Features.Consensus.csproj" />
Expand Down

0 comments on commit 29194d6

Please sign in to comment.