Skip to content

Commit

Permalink
Do not add token multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed May 10, 2024
1 parent ecba2e9 commit 5314ed3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
5 changes: 3 additions & 2 deletions src/aoWebWallet/Pages/ActionPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
<MudStack>
@if (BindingContext.WalletList.Data != null)
{
if (!BindingContext.WalletList.Data.Any())
var sendWallets = BindingContext.WalletList.Data.Where(x => !x.IsReadOnly).ToList();
if (!sendWallets.Any())
{
<MudButton aria-label="add wallet" Size="Size.Large" OnClick="OpenDialog">Add Wallet</MudButton>
}
else
{
<MudSelect @bind-Value="@selectedWallet" Label="Select a wallet" Variant="Variant.Outlined" MaxHeight="250" ReadOnly="@readOnly">
@foreach (var wallet in BindingContext.WalletList.Data ?? new())
@foreach (var wallet in sendWallets ?? new())
{
<MudSelectItem Value="@wallet.Address">
<MudStack Row="true">
Expand Down
18 changes: 0 additions & 18 deletions src/aoWebWallet/Services/StorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,6 @@ private void AddSystemToken(List<Token> list, string tokenId)
list.Add(new Token { TokenId = tokenId, IsSystemToken = true });
}

public async Task AddTokenId(string tokenId, bool isUserAdded = true, bool isVisible = false)
{
if(tokenId.Length != 43)
return;

var list = await GetTokenIds();

var existing = list.Where(x => x.TokenId == tokenId).FirstOrDefault();
if (existing != null)
return;


existing = new Token { TokenId = tokenId, IsUserAdded = isUserAdded, IsVisible = isVisible };
list.Add(existing);

await SaveTokenList(list);
}

public async ValueTask<Token> AddToken(string tokenId, TokenData data, bool isUserAdded, bool? isVisible)
{
var list = await GetTokenIds();
Expand Down
7 changes: 5 additions & 2 deletions src/aoWebWallet/Services/TokenDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public TokenDataService(StorageService storageService, TokenClient tokenClient)

public async Task TryAddTokenIds(List<string?> allTokenIds)
{
allTokenIds = allTokenIds.Distinct(StringComparer.OrdinalIgnoreCase).ToList();

foreach (var tokenId in allTokenIds)
{
if (string.IsNullOrEmpty(tokenId) || tokenId.Length != 43)
Expand Down Expand Up @@ -76,7 +78,9 @@ public async Task<Token> LoadTokenAsync(string tokenId)

token.TokenData = data;

TokenList.Add(token);
var existing = TokenList.Where(x => x.TokenId.Equals(tokenId, StringComparison.OrdinalIgnoreCase)).Any();
if(!existing)
TokenList.Add(token);

await storageService.AddToken(tokenId, data, false, null);
}
Expand Down Expand Up @@ -127,7 +131,6 @@ private async IAsyncEnumerable<Token> LoadTokenDataAsync()
}

await storageService.SaveTokenList(tokens);

}

public async Task DeleteToken(string tokenId)
Expand Down
4 changes: 3 additions & 1 deletion src/aoWebWallet/Services/TransactionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public void Reset()
public Task<MessageResult?> DryRunAction(Wallet wallet, AoAction action)
=> DryRunResult.DataLoader.LoadAsync(async () =>
{
DryRunResult.Data = null;
var target = action.Target?.Value ?? string.Empty;
var druRunRequest = new DryRunRequest()
{
Expand Down Expand Up @@ -74,7 +76,7 @@ public async Task SendAction(Wallet wallet, Wallet? ownerWallet, AoAction action
if (!string.IsNullOrEmpty(wallet.Jwk))
await SendActionWithJwk(wallet.Jwk, action);

Console.WriteLine("No Wallet to send");
//Console.WriteLine("No Wallet to send");
return;
}

Expand Down
11 changes: 7 additions & 4 deletions src/aoww.Services.Tests/aoww.Services.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 5314ed3

Please sign in to comment.