Dispose subscriptions to SmartCoin
MODIFY
WalletWasabi.Fluent/Extensions/ObservableExtension.cs
WalletWasabi.Fluent/Extensions/ObservableExtension.cs
@@ -12,6 +12,5 @@ public static class ObservableExtension
.Concat()
.Subscribe();
-
public static IObservable<Unit> ToSignal<T>(this IObservable<T> source) => source.Select(_ => Unit.Default);
}

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Advanced/WalletCoins/WalletCoinViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Advanced/WalletCoins/WalletCoinViewModel.cs
using NBitcoin;
using ReactiveUI;
-using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Reactive.Disposables;
using WalletWasabi.Blockchain.Analysis.Clustering;
using WalletWasabi.Blockchain.TransactionOutputs;
namespace WalletWasabi.Fluent.ViewModels.Wallets.Advanced.WalletCoins;
-public partial class WalletCoinViewModel : ViewModelBase
+public partial class WalletCoinViewModel : ViewModelBase, IDisposable
{
+ private readonly CompositeDisposable _disposables = new();
[AutoNotify] private Money _amount = Money.Zero;
[AutoNotify] private int _anonymitySet;
[AutoNotify] private SmartLabel _smartLabel = "";
@@ -22,10 +20,10 @@ public partial class WalletCoinViewModel : ViewModelBase
{
Amount = coin.Amount;
- coin.WhenAnyValue(c => c.Confirmed).Subscribe(x => Confirmed = x);
- coin.WhenAnyValue(c => c.HdPubKey.Cluster.Labels).Subscribe(x => SmartLabel = x);
- coin.WhenAnyValue(c => c.HdPubKey.AnonymitySet).Subscribe(x => AnonymitySet = x);
- coin.WhenAnyValue(c => c.CoinJoinInProgress).Subscribe(x => CoinJoinInProgress = x);
+ coin.WhenAnyValue(c => c.Confirmed).Subscribe(x => Confirmed = x).DisposeWith(_disposables);
+ coin.WhenAnyValue(c => c.HdPubKey.Cluster.Labels).Subscribe(x => SmartLabel = x).DisposeWith(_disposables);
+ coin.WhenAnyValue(c => c.HdPubKey.AnonymitySet).Subscribe(x => AnonymitySet = x).DisposeWith(_disposables);
+ coin.WhenAnyValue(c => c.CoinJoinInProgress).Subscribe(x => CoinJoinInProgress = x).DisposeWith(_disposables);
}
public static Comparison<WalletCoinViewModel?> SortAscending<T>(Func<WalletCoinViewModel, T> selector)
@@ -73,4 +71,9 @@ public partial class WalletCoinViewModel : ViewModelBase
}
};
}
+
+ public void Dispose()
+ {
+ _disposables.Dispose();
+ }
}

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Advanced/WalletCoins/WalletCoinsViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Advanced/WalletCoins/WalletCoinsViewModel.cs
@@ -36,6 +36,7 @@ public partial class WalletCoinsViewModel : RoutableViewModel
.Connect()
.ObserveOn(RxApp.MainThreadScheduler)
.Bind(_coins)
+ .DisposeMany()
.Subscribe();
// [Column] [View] [Header] [Width] [MinWidth] [MaxWidth] [CanUserSort]
@@ -105,6 +106,12 @@ public partial class WalletCoinsViewModel : RoutableViewModel
public FlatTreeDataGridSource<WalletCoinViewModel> Source { get; }
+ private IObservable<Unit> CoinsUpdated => _balanceChanged
+ .ToSignal()
+ .Merge(_walletViewModel
+ .WhenAnyValue(w => w.IsCoinJoining)
+ .ToSignal());
+
protected override void OnNavigatedTo(bool isInHistory, CompositeDisposable disposables)
{
base.OnNavigatedTo(isInHistory, disposables);
@@ -115,12 +122,6 @@ public partial class WalletCoinsViewModel : RoutableViewModel
.DisposeWith(disposables);
}
- private IObservable<Unit> CoinsUpdated => _balanceChanged
- .ToSignal()
- .Merge(_walletViewModel
- .WhenAnyValue(w => w.IsCoinJoining)
- .ToSignal());
-
private ICoinsView GetCoins()
{
return _walletViewModel.Wallet.Coins;

Dispose subscriptions to SmartCoin