Skip to content

Commit

Permalink
implemented CopyToClipboard and refresh balances
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed Mar 27, 2024
1 parent 183ee99 commit 4c471cb
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/aoWebWallet/Pages/WalletDetail.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</MudText>
<MudText Typo="Typo.body2">@BindingContext.SelectedWallet?.Name</MudText>
</MudStack>
<MudIconButton Class="copy-clipboard" Icon="@Icons.Material.Filled.ContentCopy" Color="Color.Default" OnClick="async () => { await BindingContext.CopyToClipboard(BindingContext.SelectedWallet?.Address); }" />
<MudSpacer />
@if(BindingContext.SelectedWallet?.Source == WalletTypes.Explorer)
{
Expand Down Expand Up @@ -69,6 +70,7 @@
}

<MudContainer style="max-width: 100%;" Width="100%" Class="d-flex justify-end mb-4 pr-2">
<MudIconButton Icon="@Icons.Material.Filled.Refresh" aria-label="refresh transactions" OnClick="RefreshBalances"></MudIconButton>
<MudIconButton Icon="@Icons.Material.Filled.AddCircle" aria-label="add token" Size="Size.Large" OnClick="OpenAddTokenDialog"></MudIconButton>
</MudContainer>

Expand Down Expand Up @@ -99,7 +101,6 @@
@if (balance.Data?.BalanceData != null)
{
<MudContainer style="max-width: 100%;" Width="100%" Class="d-flex align-center">
<MudIconButton Icon="@Icons.Material.Filled.Refresh" aria-label="refresh transactions" OnClick="RefreshTransactions"></MudIconButton>
<MudText Typo="Typo.h5">@BalanceHelper.FormatBalance(balance.Data.BalanceData.Balance, balance.Data.Token?.TokenData?.Denomination ?? 0)</MudText>
</MudContainer>
}
Expand Down Expand Up @@ -228,6 +229,12 @@
DialogService.Show<SendTokenDialog>("Transfer Token", options);
}

private async Task RefreshBalances()
{
if (BindingContext.SelectedAddress != null)
await BindingContext.LoadBalanceDataList(BindingContext.SelectedAddress);
}

private async Task RefreshTransactions()
{
if(BindingContext.SelectedAddress != null)
Expand Down
2 changes: 1 addition & 1 deletion src/aoWebWallet/Pages/Wallets.razor
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<MudLink Class="KodeMono" style="text-overflow: ellipsis; white-space: nowrap;overflow: hidden;" Href="@detailUrl" Typo="Typo.h6">
@wallet.Address
</MudLink>
<MudIcon Class="copy-clipboard" Icon="@Icons.Material.Filled.ContentCopy" Color="Color.Default" />
<MudIconButton Class="copy-clipboard" Icon="@Icons.Material.Filled.ContentCopy" Color="Color.Default" OnClick="async () => { await BindingContext.CopyToClipboard(wallet.Address); }" />
</div>

<div style="display:flex; flex-direction:row;">
Expand Down
3 changes: 3 additions & 0 deletions src/aoWebWallet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using ArweaveAO;
using ArweaveBlazor;
using System.Globalization;
using ClipLazor.Extention;

namespace aoWebWallet
{
Expand Down Expand Up @@ -102,6 +103,8 @@ private static void ConfigureServices(IServiceCollection services, string baseAd
services.AddScoped<MainViewModel>();

services.AddBlazoredLocalStorage();

services.AddClipboard();
}
}
}
4 changes: 2 additions & 2 deletions src/aoWebWallet/Shared/AddGenerateWalletComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

<MudPaper Class="pa-8">
<MudStack Spacing="2">
<MudButton OnClick="OnExpandCollapseClick">@(IsExpanded ? "Generate new wallet" : "Generate new wallet")</MudButton>
<MudButton OnClick="OnExpandCollapseClick">@(IsExpanded ? "Create a new wallet" : "Create a new wallet")</MudButton>
<MudDivider />
<MudCollapse Expanded="IsExpanded">
<MudTextField @bind-Value="Name" Label="Name (optional)" Variant="Variant.Text"></MudTextField>
<MudText Color="Color.Secondary">@Progress</MudText>
<div style="width:100%;">
<MudButton style="margin-top:10px; display:flex; margin-left:auto;" Color="Color.Primary" OnClick="Submit">Generate</MudButton>
<MudButton style="margin-top:10px; display:flex; margin-left:auto;" Color="Color.Primary" OnClick="Submit">Create</MudButton>
</div>
</MudCollapse>
</MudStack>
Expand Down
13 changes: 11 additions & 2 deletions src/aoWebWallet/Shared/AddUploadWalletComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
Outlined="true"
Class="@_dragClass">
<MudText Typo="Typo.h6">
Drag and drop wallet file or click here
Drag and drop wallet file or click here.
</MudText>
<MudText Typo="Typo.subtitle1">
Your files won't be uploaded and are only read by the local app.
</MudText>
@foreach (var file in _fileNames)
{
Expand Down Expand Up @@ -113,6 +116,9 @@
var address = await ArweaveService.GetAddress(jwk);
var name = file.Name;

if (string.IsNullOrEmpty(address))
throw new Exception("No address");

var wallet = new Wallet
{
Address = address,
Expand All @@ -125,7 +131,10 @@

_fileNames.Add(wallet);
}
catch { }
catch
{
Snackbar.Add($"Unable to read wallet file: {file.Name}", Severity.Error);
}

}
}
Expand Down
22 changes: 22 additions & 0 deletions src/aoWebWallet/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using ArweaveAO;
using ArweaveAO.Models.Token;
using ArweaveBlazor;
using ClipLazor.Components;
using ClipLazor.Enums;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using MudBlazor;
Expand All @@ -21,6 +23,7 @@ public partial class MainViewModel : ObservableRecipient
private readonly ArweaveService arweaveService;
private readonly GraphqlClient graphqlClient;
private readonly ISnackbar snackbar;
private readonly IClipLazor clipboard;
private readonly MemoryDataCache memoryDataCache;

[ObservableProperty]
Expand Down Expand Up @@ -84,6 +87,7 @@ public MainViewModel(DataService dataService,
ArweaveService arweaveService,
GraphqlClient graphqlClient,
ISnackbar snackbar,
IClipLazor clipboard,
MemoryDataCache memoryDataCache) : base()
{
this.dataService = dataService;
Expand All @@ -92,6 +96,7 @@ public MainViewModel(DataService dataService,
this.arweaveService = arweaveService;
this.graphqlClient = graphqlClient;
this.snackbar = snackbar;
this.clipboard = clipboard;
this.memoryDataCache = memoryDataCache;
}

Expand Down Expand Up @@ -538,6 +543,23 @@ public async Task GetActiveArConnectAddress()
}
}

public async Task CopyToClipboard(string? text)
{
bool isSupported = await clipboard.IsClipboardSupported();
bool isWritePermitted = await clipboard.IsPermitted(PermissionCommand.Write);
if (isSupported && !string.IsNullOrEmpty(text))
{
if (isWritePermitted)
{
var isCopied = await clipboard.WriteTextAsync(text.AsMemory());
if (isCopied)
{
snackbar.Add($"Text copied: {text}", Severity.Info);
}
}
}
}

public Task<Transaction?> SendToken(Wallet wallet, string tokenId, string address, long amount)
{
if (wallet.Source == WalletTypes.ArConnect)
Expand Down
1 change: 1 addition & 0 deletions src/aoWebWallet/aoWebWallet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ItemGroup>
<PackageReference Include="ArweaveAO" Version="0.0.1" />
<PackageReference Include="ArweaveBlazor" Version="0.0.3" />
<PackageReference Include="ClipLazor" Version="2.1.1" />
<PackageReference Include="MudBlazor" Version="6.19.1" />
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageReference Include="BlazorWasmPreRendering.Build" Version="3.1.0-preview.4" />
Expand Down
3 changes: 2 additions & 1 deletion src/aoWebWallet/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</svg>
<div class="loading-progress-text"></div>
</div>
<img style="margin-top: 22px;" width="262px" src='data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyBpZD0iTGF5ZXJfMiIgZGF0YS1uYW1lPSJMYXllciAyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMzExLjU4IDI0MC45MiI+CiAgPGRlZnM+CiAgICA8c3R5bGU+CiAgICAgIC5jbHMtMSB7CiAgICAgICAgZmlsbDogI2ZmZjsKICAgICAgICBmaWxsLXJ1bGU6IGV2ZW5vZGQ7CiAgICAgIH0KICAgIDwvc3R5bGU+CiAgPC9kZWZzPgogIDxnIGlkPSJM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cuMDEgMTc4Ljk4IDk2Mi43MiAxLjEyIDkwMiAxLjEyIi8+CiAgICAgIDxwb2x5Z29uIGNsYXNzPSJjbHMtMSIgcG9pbnRzPSIxMTQzLjM0IDEuNTkgMTE0My41OCAxLjEyIDEwNjMuMzggMS4xMiAxMDQ3LjAxIDQ1LjM4IDEwODMuODQgMTIwLjc5IDExMTIuNjQgNjMuMSAxMjAxIDI0MC45MiAxMjI4LjAxIDE3OS40NSAxMTQzLjcyIDEuNTkgMTE0My4zNCAxLjU5Ii8+CiAgICAgIDxwYXRoIGNsYXNzPSJjbHMtMSIgZD0ibTM2MS44LDBjLTY2LjQsMC0xMjAuMjMsNTMuODMtMTIwLjIzLDEyMC4yM3M1My44MywxMjAuMjMsMTIwLjIzLDEyMC4yMywxMjAuMjMtNTMuODMsMTIwLjIzLTEyMC4yM1M0MjguMiwwLDM2MS44LDBabTAsMTkzLjI2Yy00MC4zNCwwLTczLjAzLTMyLjctNzMuMDMtNzMuMDNzMzIuNy03My4wMyw3My4wMy03My4wMyw3My4wMywzMi43LDczLjAzLDczLjAzLTMyLjcsNzMuMDMtNzMuMDMsNzMuMDNaIi8+CiAgICA8L2c+CiAgPC9nPgo8L3N2Zz4=' />
</div>
</div>

Expand All @@ -76,6 +76,7 @@
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script src="_content/ClipLazor/clipboard.min.js"></script>
<script src="_framework/blazor.webassembly.js" autostart="false"></script>
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
<script type="module">
Expand Down

0 comments on commit 4c471cb

Please sign in to comment.