Skip to content

Commit

Permalink
add token on wallet details page fix
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed May 15, 2024
1 parent c5e869f commit 538d70e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/aoWebWallet/Pages/WalletDetail.razor
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
private void OpenAddTokenDialog()
{
var options = new DialogOptions { CloseOnEscapeKey = true };
DialogService.Show<AddTokenDialog>("Add Token", options);
DialogService.Show<AddTokenToWalletDialog>("Add Token", options);
}

private async void EditWallet(Wallet wallet)
Expand Down
4 changes: 2 additions & 2 deletions src/aoWebWallet/Pages/WalletDetail.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ private void BindingContext_PropertyChanged(object? sender, System.ComponentMode
}
}

private void TokenList_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
private async void TokenList_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
BindingContext.TokenAddedRefresh();
await BindingContext.TokenAddedRefresh();
}

protected override async Task OnParametersSetAsync()
Expand Down
64 changes: 64 additions & 0 deletions src/aoWebWallet/Shared/AddTokenToWalletDialog.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
@inject TokenDataService dataService
@inherits MvvmComponentBase<WalletDetailViewModel>
@inject ISnackbar Snackbar

<MudDialog>
<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" Mask="@(new RegexMask("^[a-zA-Z0-9_\\-]{0,43}$"))" MaxLength="43" Variant="Variant.Text"></MudTextField>
</MudFocusTrap>
<MudText Color="Color.Secondary">@Progress</MudText>
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel">Cancel</MudButton>
<MudButton Color="Color.Primary" OnClick="Submit">Ok</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter] MudDialogInstance MudDialog { get; set; } = default!;

public string? TokenId { get; set; }
public string? Progress { get; set; }

public async Task Submit()
{
if (string.IsNullOrWhiteSpace(TokenId))
{
Progress = "Input the process-id of an ao-process implementing the token standard.";
return;
}
if(TokenId.Length != 43)
{
Progress = "Length must be 43 characters.";
return;
}

Progress = "Checking metadata...";
try
{
var token = await dataService.LoadTokenAsync(TokenId);
var data = token.TokenData;
if (data != null)
{
BindingContext.VisibleTokenList.Add(TokenId);
BindingContext.TokenAddedRefresh();

Snackbar.Add($"Token added ({data.Name})", Severity.Info);

MudDialog.Close(DialogResult.Ok(true));
}
else
{
Progress = "Could not find token metadata.";
}
}
catch
{
Progress = "Could not find token metadata.";
}
}

//void Submit() => MudDialog.Close(DialogResult.Ok(true));
void Cancel() => MudDialog.Cancel();
}
2 changes: 1 addition & 1 deletion src/aoWebWallet/aoWebWallet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<ItemGroup>
<PackageReference Include="ArweaveAO" Version="0.0.3" />
<PackageReference Include="ArweaveBlazor" Version="0.0.7" />
<PackageReference Include="ArweaveBlazor" Version="0.0.8" />
<PackageReference Include="ClipLazor" Version="2.1.1" />
<PackageReference Include="MudBlazor" Version="6.19.1" />
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
Expand Down

0 comments on commit 538d70e

Please sign in to comment.