Improve readability of transformation pipeline
MODIFY
WalletWasabi.Fluent/Extensions/ObservableExtension.cs
WalletWasabi.Fluent/Extensions/ObservableExtension.cs
+using System.Reactive;
using System.Reactive.Linq;
using System.Threading.Tasks;
@@ -10,4 +11,7 @@ public static class ObservableExtension
.Select(x => Observable.FromAsync(() => onNextAsync(x)))
.Concat()
.Subscribe();
+
+
+ public static IObservable<Unit> ToSignal<T>(this IObservable<T> source) => source.Select(_ => Unit.Default);
}

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Advanced/WalletCoins/WalletCoinsViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Advanced/WalletCoins/WalletCoinsViewModel.cs
+using System.Collections.Generic;
using DynamicData;
using ReactiveUI;
using System.Linq;
@@ -8,6 +9,8 @@ using Avalonia.Controls;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Controls.Templates;
using DynamicData.Binding;
+using WalletWasabi.Blockchain.TransactionOutputs;
+using WalletWasabi.Fluent.Extensions;
using WalletWasabi.Fluent.ViewModels.Navigation;
using WalletWasabi.Fluent.Views.Wallets.Advanced.WalletCoins.Columns;
@@ -106,21 +109,29 @@ public partial class WalletCoinsViewModel : RoutableViewModel
{
base.OnNavigatedTo(isInHistory, disposables);
- disposables.Add(_balanceChanged
- .Select(_ => Unit.Default)
- .Merge(_walletViewModel.WhenAnyValue(w => w.IsCoinJoining)
- .Select(_ => Unit.Default))
- .Subscribe(_ => Update()));
+ CoinsUpdated
+ .Select(_ => GetCoins())
+ .Subscribe(RefreshCoinsList)
+ .DisposeWith(disposables);
}
- private void Update()
+ private IObservable<Unit> CoinsUpdated => _balanceChanged
+ .ToSignal()
+ .Merge(_walletViewModel
+ .WhenAnyValue(w => w.IsCoinJoining)
+ .ToSignal());
+
+ private ICoinsView GetCoins()
{
- var coins = _walletViewModel.Wallet.Coins.Select(c => new WalletCoinViewModel(c));
+ return _walletViewModel.Wallet.Coins;
+ }
+ private void RefreshCoinsList(ICoinsView items)
+ {
_coinsSourceList.Edit(x =>
{
x.Clear();
- x.AddRange(coins);
+ x.AddRange(items.Select(coin => new WalletCoinViewModel(coin)));
});
}
}
\ No newline at end of file

Improve readability of transformation pipeline