Skip to content

Commit 29194d6

Browse files
authored
Add favorite icon handling for the UI (#167)
1 parent 3ad6e00 commit 29194d6

15 files changed

Lines changed: 62 additions & 6 deletions

File tree

src/External/NBitcoin/NBitcoin.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@
5151
</AssemblyAttribute>
5252
</ItemGroup>
5353

54+
<ItemGroup>
55+
<EmbeddedResource Include="icon.png" />
56+
</ItemGroup>
57+
5458
</Project>

src/External/NBitcoin/Network.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public NetworksSelector(Func<Network> mainnet, Func<Network> testnet, Func<Netwo
6262

6363
public abstract class Network
6464
{
65+
private string icon = string.Empty;
66+
6567
protected Block Genesis;
6668

6769
/// <summary>
@@ -789,5 +791,30 @@ public Transaction CreateTransaction(byte[] bytes)
789791
{
790792
return this.Consensus.ConsensusFactory.CreateTransaction(bytes);
791793
}
794+
795+
public string FavoriteIcon()
796+
{
797+
if (!string.IsNullOrWhiteSpace(this.icon))
798+
{
799+
return this.icon;
800+
}
801+
802+
System.Reflection.Assembly assembly = this.GetType().Assembly;
803+
var iconResource = assembly.GetManifestResourceNames().FirstOrDefault(r => r.Contains("icon"));
804+
805+
if (string.IsNullOrWhiteSpace(iconResource))
806+
{
807+
assembly = typeof(NBitcoin.Network).Assembly;
808+
iconResource = assembly.GetManifestResourceNames().FirstOrDefault(r => r.Contains("icon"));
809+
}
810+
811+
using (Stream stream = assembly.GetManifestResourceStream(iconResource))
812+
{
813+
byte[] bytes = new BinaryReader(stream).ReadBytes((int)stream.Length);
814+
this.icon = Convert.ToBase64String(bytes);
815+
}
816+
817+
return this.icon;
818+
}
792819
}
793820
}

src/External/NBitcoin/icon.png

2.14 KB
Loading

src/Features/Blockcore.Features.NodeHost/UI/Pages/_Host.cshtml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@page "/"
22
@namespace Blockcore.Features.NodeHost.UI.Pages
3+
@inject NBitcoin.Network Network
34
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
45
@addTagHelper *, BlazorModal
56
@{
@@ -14,7 +15,8 @@
1415
<title>Dashboard</title>
1516
<base href="~/" />
1617
<link rel="stylesheet" href="css/bootstrap/darkstrap.min.css" />
17-
<link rel="stylesheet" href="css/site.css"/>
18+
<link rel="stylesheet" href="css/site.css" />
19+
<link id="favicon" rel="shortcut icon" type="image/png" href="data:image/png;base64,@this.Network.FavoriteIcon()">
1820
</head>
1921
<body>
2022
<app>
@@ -35,12 +37,12 @@
3537
<script src="_framework/blazor.server.js"></script>
3638
<script>
3739
window.clipboardCopy = {
38-
copyText: function(text) {
40+
copyText: function (text) {
3941
navigator.clipboard.writeText(text).then(function () {
4042
})
41-
.catch(function (error) {
42-
alert(error);
43-
});
43+
.catch(function (error) {
44+
alert(error);
45+
});
4446
}
4547
};
4648
</script>

src/Networks/Bitcoin/Blockcore.Networks.Bitcoin/Blockcore.Networks.Bitcoin.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
<IsPackable>true</IsPackable>
1010
</PropertyGroup>
1111

12+
<ItemGroup>
13+
<EmbeddedResource Include="icon.png" />
14+
</ItemGroup>
15+
1216
<ItemGroup>
1317
<ProjectReference Include="..\..\..\External\NBitcoin\NBitcoin.csproj" />
1418
<ProjectReference Include="..\..\..\Features\Blockcore.Features.Consensus\Blockcore.Features.Consensus.csproj" />
2.97 KB
Loading

src/Networks/City/City/Blockcore.Networks.City.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Authors>Blockcore</Authors>
@@ -13,6 +13,10 @@
1313
<LangVersion>latest</LangVersion>
1414
</PropertyGroup>
1515

16+
<ItemGroup>
17+
<EmbeddedResource Include="ico.png" />
18+
</ItemGroup>
19+
1620
<ItemGroup>
1721
<ProjectReference Include="..\..\..\External\NBitcoin\NBitcoin.csproj" />
1822
<ProjectReference Include="..\..\..\Features\Blockcore.Features.Consensus\Blockcore.Features.Consensus.csproj" />

src/Networks/City/City/CitySetup.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Reflection;
5+
using System.Runtime.Versioning;
36
using City.Networks;
47
using City.Networks.Setup;
58
using NBitcoin;

src/Networks/City/City/ico.png

3.55 KB
Loading

src/Networks/Stratis/Blockcore.Networks.Stratis/Blockcore.Networks.Stratis.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
<IsPackable>true</IsPackable>
99
</PropertyGroup>
1010

11+
<ItemGroup>
12+
<EmbeddedResource Include="icon.png" />
13+
</ItemGroup>
14+
1115
<ItemGroup>
1216
<ProjectReference Include="..\..\..\External\NBitcoin\NBitcoin.csproj" />
1317
<ProjectReference Include="..\..\..\Features\Blockcore.Features.Consensus\Blockcore.Features.Consensus.csproj" />

0 commit comments

Comments
 (0)