Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Fix Tezos/Ethereum receive view addresses doubling; #9

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,4 @@ ASALocalRun/
.mfractor/

# Local History for Visual Studio
.localhistory/
.localhistory/.DS_Store
1 change: 1 addition & 0 deletions Atomex.Client.Wpf/Atomex.Client.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@
<Compile Include="Common\BitmapExtensions.cs" />
<Compile Include="Common\DecimalExtensions.cs" />
<Compile Include="Common\DesignTime.cs" />
<Compile Include="Common\DistinctExtensions.cs" />
<Compile Include="Common\Environment.cs" />
<Compile Include="Common\Msi\MsiApi.cs" />
<Compile Include="Common\Msi\MsiPackage.cs" />
Expand Down
21 changes: 21 additions & 0 deletions Atomex.Client.Wpf/Common/DistinctExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;

namespace Atomex.Client.Wpf.Common
{
public static class DistinctExtensions
{
public static IEnumerable<TSource> DistinctBy<TSource, TKey>
(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
HashSet<TKey> seenKeys = new HashSet<TKey>();
foreach (TSource element in source)
{
if (seenKeys.Add(keySelector(element)))
{
yield return element;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public override Currency Currency
.GetFreeExternalAddressAsync(_currency.Name)
.WaitForResult();

var receiveAddresses = activeTokenAddresses.Select(w => new WalletAddressViewModel(w, _currency.Format))
var receiveAddresses = activeTokenAddresses
.DistinctBy(wa => wa.Address)
.Select(w => new WalletAddressViewModel(w, _currency.Format))
.Concat(activeAddresses.Select(w => new WalletAddressViewModel(w, _currency.Format)))
.ToList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public override Currency Currency
.GetFreeExternalAddressAsync(_currency.Name)
.WaitForResult();

var receiveAddresses = activeTokenAddresses.Select(w => new WalletAddressViewModel(w, _currency.Format))
var receiveAddresses = activeTokenAddresses
.DistinctBy(wa => wa.Address)
.Select(w => new WalletAddressViewModel(w, _currency.Format))
.Concat(activeAddresses.Select(w => new WalletAddressViewModel(w, _currency.Format)))
.ToList();

Expand Down