Skip to content

Commit 48b2bd9

Browse files
Add modal component service & create add node modal (#152)
* Add modal component service & creat add node modal * Add error message * move the code for blazor modal to its own feature * Fix modal * Add refresh button * Lay foundations for tx details * Add wallet selection dropdown * Additional navigation * Move some components to node host * Fix wallet sync calculation Co-authored-by: dangershony <dan.gershony@gmail.com>
1 parent 75fa06c commit 48b2bd9

27 files changed

Lines changed: 599 additions & 166 deletions
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Microsoft.AspNetCore.Components;
2+
using System;
3+
4+
namespace BlazorModal.Services
5+
{
6+
public class ModalService
7+
{
8+
public event Action<string, RenderFragment> OnShow;
9+
10+
public event Action OnClose;
11+
12+
public void Show(string title, Type contentType)
13+
{
14+
if (contentType.BaseType != typeof(ComponentBase))
15+
{
16+
throw new ArgumentException($"{contentType.FullName} must be a Blazor Component");
17+
}
18+
19+
var content = new RenderFragment(x => { x.OpenComponent(1, contentType); x.CloseComponent(); });
20+
21+
OnShow?.Invoke(title, content);
22+
}
23+
24+
public void Close()
25+
{
26+
OnClose?.Invoke();
27+
}
28+
}
29+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@typeparam TItem
2+
<div class="dropdown">
3+
<button class="btn btn-primary btn-sm dropdown-toggle mr-1" data-toggle="dropdown" type="button" @onclick="e => this.show=!this.show "
4+
aria-haspopup="true" aria-expanded="false">
5+
@Tip
6+
</button>
7+
<CascadingValue name="Dropdown" Value="@this">
8+
<div class="dropdown-menu @(show? "show":"")" >
9+
@ChildContent
10+
</div>
11+
</CascadingValue>
12+
</div>
13+
14+
@code {
15+
[Parameter]
16+
public RenderFragment InitialTip{get;set;}
17+
[Parameter]
18+
public RenderFragment ChildContent{get;set;}
19+
[Parameter]
20+
public EventCallback<TItem> OnSelected {get;set;}
21+
22+
private bool show = false;
23+
private RenderFragment Tip ;
24+
25+
protected override void OnInitialized(){ this.Tip = InitialTip; }
26+
public async Task HandleSelect(TItem item, RenderFragment<TItem> contentFragment)
27+
{
28+
this.Tip= contentFragment.Invoke(item);
29+
this.show=false;
30+
StateHasChanged();
31+
await this.OnSelected.InvokeAsync(item);
32+
}
33+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@typeparam TItem
2+
<a class="dropdown-item" Item="@Item" @onclick="e=> Dropdown.HandleSelect(Item, ChildContent)" >@ChildContent(Item)</a>
3+
4+
@code {
5+
[CascadingParameter(Name="Dropdown")]
6+
public Dropdown<TItem> Dropdown {get;set;}
7+
8+
[Parameter]
9+
public TItem Item{get;set;}
10+
[Parameter]
11+
public RenderFragment<TItem> ChildContent {get;set;}
12+
}

src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStake.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
}
121121
}
122122
<td class="text-center">
123-
<button class="btn btn-sm btn-primary"><span class="oi oi-zoom-in" aria-hidden="true"></span></button>
123+
<button class="btn btn-sm btn-secondary"><span class="oi oi-arrow-right" aria-hidden="true"></span></button>
124124
</td>
125125
</tr>
126126
}

src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeEnableWallet.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
@using Blockcore.Features.ColdStaking
44
@using Blockcore.Features.Wallet.Interfaces
55
@using Blockcore.Base.Deployments
6-
@using NBitcoin;
76

87
@inject IWalletManager WalletManager
98
@inject NavigationManager NavigationManager

src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeView.razor

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,25 @@
88
@inject NavigationManager NavigationManager
99
@inject IWalletManager WalletManager
1010
@inject Network Network
11+
@inject ModalService ModalService
1112

1213
@{
13-
1414
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
15-
<h1 style="max-width: 18em" class="h2"><strong>Cold Staking - @walletname</strong></h1>
15+
<h1 style="max-width: 18em" class="h2"><strong>Cold Staking</strong></h1>
1616
<div class="btn-toolbar mb-2 mb-md-0">
17+
<Dropdown TItem="string" OnSelected="@OnSelected" >
18+
<InitialTip>@walletname</InitialTip>
19+
<ChildContent>
20+
@{
21+
foreach (var walletName in this.WalletManager.GetWalletsNames()) {
22+
foreach (var account in this.WalletManager.GetAccounts(walletName))
23+
{
24+
<DropdownListItem Item="@walletName">@walletName</DropdownListItem>
25+
}
26+
}
27+
}
28+
</ChildContent>
29+
</Dropdown>
1730
<button class="btn btn-sm btn-primary mr-1" @onclick="() => { NavigateToSetup(walletname); }">
1831
<span class="oi oi-pulse" aria-hidden="true"></span> Coldstake</button>
1932
<button class="btn btn-sm btn-primary mr-1" @onclick="() => { NavigateToDelegate(walletname); }">
@@ -77,18 +90,22 @@ var model = WalletModelBuilder.GetHistory(this.WalletManager, Network, new Walle
7790
<th class="text-primary text-center"><strong>DATE/TIME</strong></th>
7891
<th class="text-primary text-right"><strong>AMOUNT</strong></th>
7992
<th class="text-primary text-right"><strong>BLOCK</strong></th>
93+
<th class="text-primary text-center"><strong>DETAILS</strong></th>
8094
</tr>
8195
</thead>
8296
<tbody>
8397
@foreach (var history in model.AccountsHistoryModel)
8498
{
8599
foreach (var transaction in history.TransactionsHistory)
86100
{
87-
<tr> @* @onclick="() => { NavigateToViewTx(transaction.Id); }" *@
101+
<tr @onclick="ViewTransaction">
88102
<td>@transaction.Type</td>
89103
<td class="text-center">@String.Format("{0:f}", transaction.Timestamp)</td>
90104
<td class="text-right">@transaction.Amount</td>
91105
<td class="text-right">@transaction.ConfirmedInBlock</td>
106+
<td class="text-center">
107+
<button class="btn btn-sm btn-secondary"><span class="oi oi-list" aria-hidden="true"></span></button>
108+
</td>
92109
</tr>
93110
}
94111
}
@@ -107,7 +124,12 @@ var model = WalletModelBuilder.GetHistory(this.WalletManager, Network, new Walle
107124
public string walletname { get; set; }
108125
[Parameter]
109126
public string accountname { get; set; }
110-
127+
ColdStakingManager ColdStakingManager;
128+
protected override Task OnInitializedAsync()
129+
{
130+
ColdStakingManager = this.WalletManager as ColdStakingManager;
131+
return Task.CompletedTask;
132+
}
111133
private void NavigateToEnableWallet()
112134
{
113135
NavigationManager.NavigateTo("coldstaking-enablewallet");
@@ -126,8 +148,17 @@ var model = WalletModelBuilder.GetHistory(this.WalletManager, Network, new Walle
126148
NavigationManager.NavigateTo("coldstaking-delegate/" + walletName);
127149
}
128150

129-
private void NavigateToViewTx(uint256 txId)
151+
private void ViewTransaction()
152+
{
153+
ModalService.Show("Transaction Details", typeof(ViewTransaction));
154+
}
155+
private void NavigateToColdStakeView(string walletName)
156+
{
157+
NavigationManager.NavigateTo("coldstakeview/" + walletName + "/coldStakingColdAddresses");
158+
}
159+
private void OnSelected(string selection)
130160
{
131-
NavigationManager.NavigateTo("coldStakeviewtx");
161+
Console.WriteLine(selection);
162+
NavigateToColdStakeView(selection);
132163
}
133164
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@if (ShowForm)
2+
{
3+
4+
}
5+
6+
@code
7+
{
8+
bool ShowForm { get; set; } = true;
9+
private void SubmitForm()
10+
{
11+
ShowForm = false;
12+
}
13+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
@using Microsoft.AspNetCore.Components.Web
1+
@using Microsoft.AspNetCore.Components.Web
2+
@using BlazorModal
3+
@using BlazorModal.Services

src/Features/Blockcore.Features.NodeHost/MvcBuilderExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Reflection;
5+
using BlazorModal.Services;
56
using Blockcore.Builder.Feature;
67
using Microsoft.AspNetCore.Mvc;
78
using Microsoft.Extensions.DependencyInjection;
@@ -40,5 +41,10 @@ public static IMvcBuilder AddControllers(this IMvcBuilder builder, IEnumerable<I
4041

4142
return builder;
4243
}
44+
45+
public static IServiceCollection AddBlazorModal(this IServiceCollection services)
46+
{
47+
return services.AddScoped<ModalService>();
48+
}
4349
}
4450
}

src/Features/Blockcore.Features.NodeHost/Startup.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.OpenApi.Models;
1616
using Newtonsoft.Json;
1717
using Swashbuckle.AspNetCore.SwaggerUI;
18+
using BlazorModal;
1819

1920
namespace Blockcore.Features.NodeHost
2021
{
@@ -82,6 +83,9 @@ public void ConfigureServices(IServiceCollection services)
8283
// The UI elements moved under the UI folder
8384
options.RootDirectory = "/UI/Pages";
8485
});
86+
87+
services.AddBlazorModal();
88+
8589
}
8690

8791
if (hostSettings.EnableWS)

0 commit comments

Comments
 (0)