Skip to content

Commit

Permalink
Setup for AddressBook
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed May 2, 2024
1 parent 3c25939 commit 65dd007
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 49 deletions.
111 changes: 111 additions & 0 deletions src/aoWebWallet/Pages/AddressBook.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
@page "/address-book"
@using aoWebWallet.Models
@inherits MvvmComponentBase<MainViewModel>
@inject IDialogService DialogService
@inject ISnackbar Snackbar
@inject ClipboardService ClipboardService

<PageTitle>Address Book - @Program.PageTitlePostFix</PageTitle>


<MudContainer Class="mt-16 px-8" MaxWidth="MaxWidth.False">


<MudText Typo="Typo.h5">Address Book</MudText>

<MudContainer Width="100%" Class="d-flex justify-end mb-4 pr-3 d-max-w-100">
@if (BindingContext.WalletList.Data != null && BindingContext.WalletList.Data.Any())
{
<MudTooltip Text="Add contact" Arrow="true" Placement="Placement.Left">
<MudIconButton Icon="@Icons.Material.Filled.AddCircle" aria-label="add contact" Size="Size.Large" OnClick="OpenDialog"></MudIconButton>
</MudTooltip>
}
</MudContainer>

<MudStack>
@if (BindingContext.WalletList.Data != null)
{
if(BindingContext.WalletList.Data.Where(x => x.IsReadOnly).Any())
{
int logoCount = 1;
foreach (var wallet in BindingContext.WalletList.Data.Where(x => x.IsReadOnly))
{
string logoUrl = $"images/account--{logoCount}.svg";
string detailUrl = $"wallet/{wallet.Address}";
<MudPaper Class="pa-4">
<MudStack Row="true">
<MudAvatar Image="@logoUrl" Size="Size.Large" Class="rounded-full" />

<MudStack Class="d-overflow-hidden" Justify="Justify.Center" Spacing="0">
<div Class="d-custom-2">
<MudLink Class="KodeMono tx-wrap" Href="@detailUrl" Typo="Typo.h6">
@wallet.Address
</MudLink>
<MudIconButton Class="copy-clipboard" Icon="@Icons.Material.Filled.ContentCopy" Color="Color.Default" OnClick="async () => { await ClipboardService.CopyToClipboard(wallet.Address); }" />
</div>
<div Class="d-flex flex-row">
<MudText Typo="Typo.body2">@wallet.Name</MudText>
</div>
</MudStack>
<MudSpacer />
@if(BindingContext.ProcessesDataList?.Data?.Where(x => x.Data?.Address == wallet.Address && (x.Data?.Processes?.Any() ?? false)).Any() ?? false)
{
<MudChip>AOS</MudChip>
}

<MudIconButton Class="delete-address" Icon="@Icons.Material.Filled.Delete" aria-label="delete" OnClick="() => { DeleteWallet(wallet); }"></MudIconButton>
</MudStack>
</MudPaper>

logoCount++;
if (logoCount > 5)
logoCount = 1;
}
}
else
{
<MudGrid Row="true" Justify="Justify.Center" Class="p-2">
<MudItem sm="12" xs="12">
<AddWalletComponent IsExpanded="true"></AddWalletComponent>

Check warning on line 69 in src/aoWebWallet/Pages/AddressBook.razor

View workflow job for this annotation

GitHub Actions / build

Found markup element with unexpected name 'AddWalletComponent'. If this is intended to be a component, add a @using directive for its namespace.

Check warning on line 69 in src/aoWebWallet/Pages/AddressBook.razor

View workflow job for this annotation

GitHub Actions / build

Found markup element with unexpected name 'AddWalletComponent'. If this is intended to be a component, add a @using directive for its namespace.
</MudItem>
</MudGrid>

}
}
else
{
<MudText Typo="Typo.h6">Loading address book...</MudText>

<DataLoaderProgress DataLoader="BindingContext.WalletList.DataLoader" Title="wallets" />
}

</MudStack>
</MudContainer>


@code
{
private void OpenDialog()
{
var options = new DialogOptions { CloseOnEscapeKey = true };
DialogService.Show<AddContactComponent>("Add Contact", options);
}

private async void DeleteWallet(Wallet wallet)
{
bool? result = await DialogService.ShowMessageBox(
"Warning",
$"Are you sure you want to delete this contact? {wallet.Address}?",
yesText: "Delete!", cancelText: "Cancel");

if (result != null)
{
await BindingContext.DeleteWallet(wallet);

Snackbar.Add($"Contact deleted ({wallet.Address})", Severity.Info);
}
StateHasChanged();
}


}
27 changes: 27 additions & 0 deletions src/aoWebWallet/Pages/AddressBook.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using aoWebWallet.ViewModels;

namespace aoWebWallet.Pages
{
public partial class AddressBook : MvvmComponentBase<MainViewModel>
{
protected override void OnInitialized()
{
//WatchDataLoaderVM(BindingContext.TokenList);
WatchDataLoaderVM(BindingContext.WalletList);
WatchDataLoaderVM(BindingContext.ProcessesDataList);

base.OnInitialized();
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await BindingContext.LoadWalletList();
}

await base.OnAfterRenderAsync(firstRender);
}

}
}
13 changes: 3 additions & 10 deletions src/aoWebWallet/Pages/Wallets.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<MudContainer Class="mt-16 px-8" MaxWidth="MaxWidth.False">

@if (BindingContext.WalletList.Data == null || BindingContext.WalletList.Data.Count > 1)
@if (BindingContext.WalletList.Data == null || BindingContext.WalletList.Data.Where(x => !x.IsReadOnly).Count() > 1)
{
<MudText Typo="Typo.h5">Wallets</MudText>
}
Expand All @@ -34,10 +34,10 @@
<MudStack>
@if (BindingContext.WalletList.Data != null)
{
if(BindingContext.WalletList.Data.Any())
if (BindingContext.WalletList.Data.Where(x => !x.IsReadOnly).Any())
{
int logoCount = 1;
foreach (var wallet in BindingContext.WalletList.Data)
foreach (var wallet in BindingContext.WalletList.Data.Where(x => !x.IsReadOnly))
{
string logoUrl = $"images/account--{logoCount}.svg";
string detailUrl = $"wallet/{wallet.Address}";
Expand All @@ -53,10 +53,6 @@
<MudIconButton Class="copy-clipboard" Icon="@Icons.Material.Filled.ContentCopy" Color="Color.Default" OnClick="async () => { await ClipboardService.CopyToClipboard(wallet.Address); }" />
</div>
<div Class="d-flex flex-row">
@if (wallet.IsReadOnly)
{
<MudText Typo="Typo.body2">read-only &nbsp;</MudText>
}
<MudText Typo="Typo.body2">@wallet.Name</MudText>

@if (wallet.NeedsBackup)
Expand Down Expand Up @@ -98,9 +94,6 @@
<MudTabPanel Text="Load .json">
<AddUploadWalletComponent IsExpanded="true"></AddUploadWalletComponent>
</MudTabPanel>
<MudTabPanel Text="Read-only" >
<AddWalletComponent IsExpanded="true"></AddWalletComponent>
</MudTabPanel>
</MudTabs>
</MudItem>
</MudGrid>
Expand Down
7 changes: 0 additions & 7 deletions src/aoWebWallet/Pages/Wallets.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,5 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
await base.OnAfterRenderAsync(firstRender);
}

//protected override async Task LoadDataAsync()
//{


// //BindingContext.LoadStats();
//}

}
}
2 changes: 1 addition & 1 deletion src/aoWebWallet/Services/StorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public async ValueTask SaveWallet (Wallet wallet)
{
var list = await GetWallets();

var existing = list.Where(x => x.Address == wallet.Address).FirstOrDefault();
var existing = list.Where(x => x.Address == wallet.Address && x.IsReadOnly == wallet.IsReadOnly).FirstOrDefault();
if(existing != null)
list.Remove(existing);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

<MudPaper Class="pa-8">
<MudStack Spacing="2">
<MudTextField @bind-Value="Address" MaxLength=43 Label="Wallet Address" Variant="Variant.Text"></MudTextField>
<MudTextField @bind-Value="Address" Required RequiredError="Input a wallet address" Mask="@(new RegexMask("[a-zA-Z0-9_\\-]"))" MaxLength=43 Label="Wallet Address" Variant="Variant.Text"></MudTextField>
<MudTextField @bind-Value="Name" Label="Wallet Name" Variant="Variant.Text"></MudTextField>
<MudText Color="Color.Secondary">@Progress</MudText>

<div Class="d-w-100 d-flex justify-end mt-2">
<MudButton OnClick="Submit" Color="Color.Primary" Variant="Variant.Filled">
Add Custom Wallet
Add Contact
</MudButton>
</div>
</MudStack>
Expand All @@ -22,6 +22,8 @@
[Parameter]
public bool HideAddButton { get; set; }

[CascadingParameter] MudDialogInstance? MudDialog { get; set; }

public string? Name { get; set; }
public string? Address { get; set; }
public string? Progress { get; set; }
Expand All @@ -36,13 +38,14 @@

public async Task<bool> Submit()
{
if(string.IsNullOrWhiteSpace(Address))
{
Progress = "Input a wallet address.";
StateHasChanged();
return false;
}
if (Address.Length != 43)
// if(string.IsNullOrWhiteSpace(Address))
// {
// Progress = "Input a wallet address.";
// StateHasChanged();
// return false;
// }
if (string.IsNullOrWhiteSpace(Address) || Address.Length != 43)
{
Progress = "Length must be 43 characters.";
StateHasChanged();
Expand All @@ -60,7 +63,10 @@

await BindingContext.SaveWallet(wallet);

Snackbar.Add($"Wallet added ({Address})", Severity.Info);
Snackbar.Add($"Contact added ({Address})", Severity.Info);

MudDialog?.Close(true);

return true;
}
}
2 changes: 1 addition & 1 deletion src/aoWebWallet/Shared/AddTokenDialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<DialogContent>
Add a token to view your balance. Provide a process-id that implements the token standard.
<MudFocusTrap DefaultFocus="DefaultFocus.FirstChild">
<MudTextField @bind-Value="TokenId" Label="Token Id" Variant="Variant.Text"></MudTextField>
<MudTextField @bind-Value="TokenId" Label="Token Id" Mask="@(new RegexMask("[a-zA-Z0-9_\\-]"))" MaxLength="43" Variant="Variant.Text"></MudTextField>
</MudFocusTrap>
<MudText Color="Color.Secondary">@Progress</MudText>
</DialogContent>
Expand Down
19 changes: 1 addition & 18 deletions src/aoWebWallet/Shared/AddWalletDialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,15 @@
<MudTabPanel Text="Load .json">
<AddUploadWalletComponent></AddUploadWalletComponent>
</MudTabPanel>
<MudTabPanel Text="Read-only" >
<AddWalletComponent @ref="addWalletRef" HideAddButton="true"></AddWalletComponent>
</MudTabPanel>
</MudTabs>
</DialogContent>
</MudDialog>
@code {
[CascadingParameter] MudDialogInstance MudDialog { get; set; } = default!;

private AddWalletComponent? addWalletRef;

public async Task Submit()
{
// Call a function in AddWalletComponent
if (addWalletRef != null)
{
var result = await addWalletRef.Submit();
if(result)
{
MudDialog.Close(DialogResult.Ok(true));
}
}
else
{
MudDialog.Close(DialogResult.Ok(true));
}
MudDialog.Close(DialogResult.Ok(true));
}

//void Submit() => MudDialog.Close(DialogResult.Ok(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ else
}
else if (ActionParam.ParamType == ActionParamType.Process)
{
<MudTextField @ref="mudProcessField" T="string" MaxLength=43 Label="@ActionParam.Key" Validation="@(new Func<string, IEnumerable<string>>(ValidateProcess))" Variant="Variant.Text" ValueChanged="UpdateStringValue" />
<MudTextField @ref="mudProcessField" T="string" Mask="@(new RegexMask("[a-zA-Z0-9_\\-]"))" MaxLength=43 Label="@ActionParam.Key" Validation="@(new Func<string, IEnumerable<string>>(ValidateProcess))" Variant="Variant.Text" ValueChanged="UpdateStringValue" />
}
else if (ActionParam.ParamType == ActionParamType.Integer)
{
Expand Down
2 changes: 2 additions & 0 deletions src/aoWebWallet/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<MudNavLink Href="" Match="NavLinkMatch.All" Class="aoww-main-nav-text mt-2" Icon="@Icons.Material.Filled.Wallet">Wallets</MudNavLink>
}

<MudNavLink Href="/address-book" Match="NavLinkMatch.All" Class="aoww-main-nav-text mt-2" Icon="@Icons.Material.Filled.Contacts">Address Book</MudNavLink>

<MudNavLink Href="token-explorer" Match="NavLinkMatch.Prefix" Class="aoww-main-nav-text" Icon="@Icons.Material.Filled.Explore">Token Explorer</MudNavLink>

<div style="margin-top: auto; display:flex; flex-direction: row;">
Expand Down
2 changes: 1 addition & 1 deletion src/aoWebWallet/Shared/SendTokenDialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@if (!isConfirm)
{
<MudFocusTrap DefaultFocus="DefaultFocus.FirstChild">
<MudTextField Class="mb-4" @bind-Value="Address" MaxLength=43 Label="Wallet address" Variant="Variant.Text"></MudTextField>
<MudTextField Class="mb-4" @bind-Value="Address" Mask="@(new RegexMask("[a-zA-Z0-9_\\-]"))" MaxLength=43 Label="Wallet address" Variant="Variant.Text"></MudTextField>
<MudTextField @bind-Value="Amount" Label="Amount" Variant="Variant.Text" Format="@DenominationFormat"></MudTextField>
</MudFocusTrap>
<MudText Color="Color.Secondary">@Progress</MudText>
Expand Down

0 comments on commit 65dd007

Please sign in to comment.