From 538d70e9ce85def910c1429d293695e59571a852 Mon Sep 17 00:00:00 2001 From: Michiel Post Date: Wed, 15 May 2024 11:32:56 +0200 Subject: [PATCH] add token on wallet details page fix --- src/aoWebWallet/Pages/WalletDetail.razor | 2 +- src/aoWebWallet/Pages/WalletDetail.razor.cs | 4 +- .../Shared/AddTokenToWalletDialog.razor | 64 +++++++++++++++++++ src/aoWebWallet/aoWebWallet.csproj | 2 +- 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 src/aoWebWallet/Shared/AddTokenToWalletDialog.razor diff --git a/src/aoWebWallet/Pages/WalletDetail.razor b/src/aoWebWallet/Pages/WalletDetail.razor index 3cff8fa..714219a 100644 --- a/src/aoWebWallet/Pages/WalletDetail.razor +++ b/src/aoWebWallet/Pages/WalletDetail.razor @@ -202,7 +202,7 @@ private void OpenAddTokenDialog() { var options = new DialogOptions { CloseOnEscapeKey = true }; - DialogService.Show("Add Token", options); + DialogService.Show("Add Token", options); } private async void EditWallet(Wallet wallet) diff --git a/src/aoWebWallet/Pages/WalletDetail.razor.cs b/src/aoWebWallet/Pages/WalletDetail.razor.cs index 4c2ab9c..86a72f1 100644 --- a/src/aoWebWallet/Pages/WalletDetail.razor.cs +++ b/src/aoWebWallet/Pages/WalletDetail.razor.cs @@ -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() diff --git a/src/aoWebWallet/Shared/AddTokenToWalletDialog.razor b/src/aoWebWallet/Shared/AddTokenToWalletDialog.razor new file mode 100644 index 0000000..9facebe --- /dev/null +++ b/src/aoWebWallet/Shared/AddTokenToWalletDialog.razor @@ -0,0 +1,64 @@ +@inject TokenDataService dataService +@inherits MvvmComponentBase +@inject ISnackbar Snackbar + + + + Add a token to view your balance. Provide a process-id that implements the token standard. + + + + @Progress + + + Cancel + Ok + + +@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(); +} \ No newline at end of file diff --git a/src/aoWebWallet/aoWebWallet.csproj b/src/aoWebWallet/aoWebWallet.csproj index 96bd239..5a32973 100644 --- a/src/aoWebWallet/aoWebWallet.csproj +++ b/src/aoWebWallet/aoWebWallet.csproj @@ -13,7 +13,7 @@ - +