dispose tiles
MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/BtcPriceTileViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/BtcPriceTileViewModel.cs
@@ -16,11 +16,16 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
public BtcPriceTileViewModel(Wallet wallet)
{
_wallet = wallet;
+ }
+
+ protected override void OnActivated(CompositeDisposable disposables)
+ {
+ base.OnActivated(disposables);
_wallet.Synchronizer.WhenAnyValue(x => x.UsdExchangeRate)
.ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(usd => BtcPrice = usd.FormattedFiat());
- //.DisposeWith(Disposables);
+ .Subscribe(usd => BtcPrice = usd.FormattedFiat())
+ .DisposeWith(disposables);
}
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/RoundStatusTileViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/RoundStatusTileViewModel.cs
using System;
+using System.Reactive.Disposables;
using System.Reactive.Linq;
-using NBitcoin;
using ReactiveUI;
-using WalletWasabi.CoinJoin.Client.Rounds;
using WalletWasabi.CoinJoin.Common.Models;
using WalletWasabi.Gui.Models;
using WalletWasabi.Wallets;
@@ -15,35 +14,40 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
[AutoNotify] private long _roundId;
[AutoNotify] private RoundPhaseState _roundPhaseState;
[AutoNotify] private DateTimeOffset _roundTimesout;
- [AutoNotify] private string _timeLeftTillRoundTimeout;
- private Money _requiredBTC;
- private string _coordinatorFeePercent;
+ [AutoNotify] private string? _timeLeftTillRoundTimeout;
[AutoNotify] private int _peersRegistered;
[AutoNotify] private int _peersNeeded;
-
[AutoNotify] private int _selectedIndex;
public RoundStatusTileViewModel(Wallet wallet)
{
_wallet = wallet;
+ }
+
+ protected override void OnActivated(CompositeDisposable disposables)
+ {
+ base.OnActivated(disposables);
Observable.FromEventPattern(_wallet.ChaumianClient, nameof(Wallet.ChaumianClient.CoinQueued))
.Merge(Observable.FromEventPattern(_wallet.ChaumianClient, nameof(Wallet.ChaumianClient.OnDequeue)))
.Merge(Observable.FromEventPattern(_wallet.ChaumianClient, nameof(Wallet.ChaumianClient.StateUpdated)))
.ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(_ => UpdateStates());
- //.DisposeWith(disposables);
+ .Subscribe(_ => UpdateStates())
+ .DisposeWith(disposables);
- ClientRound mostAdvancedRound = _wallet.ChaumianClient?.State?.GetMostAdvancedRoundOrDefault();
+ var mostAdvancedRound = _wallet.ChaumianClient.State.GetMostAdvancedRoundOrDefault();
if (mostAdvancedRound is { })
{
RoundId = mostAdvancedRound.State.RoundId;
+
RoundPhaseState = new RoundPhaseState(mostAdvancedRound.State.Phase,
- _wallet.ChaumianClient?.State.IsInErrorState ?? false);
+ _wallet.ChaumianClient?.State?.IsInErrorState ?? false);
+
RoundTimesout = mostAdvancedRound.State.Phase == RoundPhase.InputRegistration
? mostAdvancedRound.State.InputRegistrationTimesout
: DateTimeOffset.UtcNow;
+
PeersRegistered = mostAdvancedRound.State.RegisteredPeerCount;
PeersNeeded = mostAdvancedRound.State.RequiredPeerCount;
}
@@ -60,10 +64,11 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(_ =>
{
- TimeSpan left = RoundTimesout - DateTimeOffset.UtcNow;
+ var left = RoundTimesout - DateTimeOffset.UtcNow;
TimeLeftTillRoundTimeout =
(left > TimeSpan.Zero ? left : TimeSpan.Zero).ToString("hh\\:mm\\:ss"); // Make sure cannot be less than zero.
- }); //.DisposeWith(disposables);
+ })
+ .DisposeWith(disposables);
Observable.Interval(TimeSpan.FromSeconds(8))
.ObserveOn(RxApp.MainThreadScheduler)
@@ -79,29 +84,21 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
}
SelectedIndex = index;
- });
+ })
+ .DisposeWith(disposables);
}
private void UpdateStates()
{
var chaumianClient = _wallet?.ChaumianClient;
+
if (chaumianClient is null)
{
return;
}
- //AmountQueued = chaumianClient.State.SumAllQueuedCoinAmounts();
-
- var registrableRound = chaumianClient.State.GetRegistrableRoundOrDefault();
- if (registrableRound is { })
- {
- //CoordinatorFeePercent = registrableRound.State.CoordinatorFeePercent.ToString();
- //UpdateRequiredBtcLabel(registrableRound);
- }
-
var mostAdvancedRound = chaumianClient.State.GetMostAdvancedRoundOrDefault();
- if (mostAdvancedRound is { })
- {
+
RoundId = mostAdvancedRound.State.RoundId;
if (!chaumianClient.State.IsInErrorState)
{
@@ -122,4 +119,3 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
}
}
}
\ No newline at end of file
-}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/TileViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/TileViewModel.cs
+using System.Reactive.Disposables;
+
namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
{
public abstract class TileViewModel : ViewModelBase
{
+ protected virtual void OnActivated(CompositeDisposable disposables)
+ {
+
+ }
+
+ public void Activate(CompositeDisposable disposables)
+ {
+ OnActivated(disposables);
+ }
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/WalletBalanceChartTileViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/WalletBalanceChartTileViewModel.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
+using System.Reactive.Disposables;
using System.Windows.Input;
using DynamicData.Binding;
using NBitcoin;
@@ -27,23 +28,24 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
_yValues = new ObservableCollection<double>();
_xValues = new ObservableCollection<double>();
- _history.ToObservableChangeSet().Subscribe(_ => UpdateSample());
-
DayCommand = ReactiveCommand.Create(() => UpdateSample(TimePeriodOption.Day));
-
WeekCommand = ReactiveCommand.Create(() => UpdateSample(TimePeriodOption.Week));
-
MonthCommand = ReactiveCommand.Create(() => UpdateSample(TimePeriodOption.Month));
-
ThreeMonthCommand = ReactiveCommand.Create(() => UpdateSample(TimePeriodOption.ThreeMonths));
-
SixMonthCommand = ReactiveCommand.Create(() => UpdateSample(TimePeriodOption.SixMonths));
-
YearCommand = ReactiveCommand.Create(() => UpdateSample(TimePeriodOption.Year));
-
AllCommand = ReactiveCommand.Create(() => { UpdateSample(TimePeriodOption.All); });
}
+ protected override void OnActivated(CompositeDisposable disposables)
+ {
+ base.OnActivated(disposables);
+
+ _history.ToObservableChangeSet()
+ .Subscribe(_ => UpdateSample())
+ .DisposeWith(disposables);
+ }
+
private enum TimePeriodOption
{
All,

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/WalletBalanceTileViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/WalletBalanceTileViewModel.cs
using System;
using System.Reactive;
+using System.Reactive.Disposables;
using NBitcoin;
using WalletWasabi.Wallets;
using WalletWasabi.Fluent.Helpers;
@@ -9,14 +10,23 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
public partial class WalletBalanceTileViewModel : TileViewModel
{
private readonly Wallet _wallet;
- [AutoNotify] private string _balanceBtc;
- [AutoNotify] private string _balanceFiat;
+ private readonly IObservable<Unit> _balanceChanged;
+ [AutoNotify] private string? _balanceBtc;
+ [AutoNotify] private string? _balanceFiat;
public WalletBalanceTileViewModel(Wallet wallet, IObservable<Unit> balanceChanged)
{
_wallet = wallet;
+ _balanceChanged = balanceChanged;
+ }
+
+ protected override void OnActivated(CompositeDisposable disposables)
+ {
+ base.OnActivated(disposables);
- balanceChanged.Subscribe(_ => UpdateBalance());
+ _balanceChanged
+ .Subscribe(_ => UpdateBalance())
+ .DisposeWith(disposables);
UpdateBalance();
}

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/WalletPieChartTileViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/WalletPieChartTileViewModel.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
+using System.Reactive.Disposables;
using NBitcoin;
using WalletWasabi.Wallets;
@@ -26,15 +27,24 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
public partial class WalletPieChartTileViewModel : TileViewModel
{
private readonly Wallet _wallet;
+ private readonly IObservable<Unit> _balanceChanged;
[AutoNotify] private IList<(string color, double percentShare)>? _testDataPoints;
[AutoNotify] private IList<DataLegend>? _testDataPointsLegend;
public WalletPieChartTileViewModel(Wallet wallet, IObservable<Unit> balanceChanged)
{
+ _balanceChanged = balanceChanged;
_wallet = wallet;
+ }
+
+ protected override void OnActivated(CompositeDisposable disposables)
+ {
+ base.OnActivated(disposables);
- balanceChanged.Subscribe(_ => Update());
+ _balanceChanged
+ .Subscribe(_ => Update())
+ .DisposeWith(disposables);
Update();
}

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/WalletViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/WalletViewModel.cs
using ReactiveUI;
using System;
+using System.Collections.Generic;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
@@ -14,6 +15,8 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets
{
public partial class WalletViewModel : WalletViewModelBase
{
+ private readonly List<TileViewModel> _tiles;
+
protected WalletViewModel(UiConfig uiConfig, Wallet wallet) : base(wallet)
{
Disposables = Disposables is null
@@ -29,11 +32,31 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets
.ObserveOn(RxApp.MainThreadScheduler);
History = new HistoryViewModel(wallet, uiConfig, balanceChanged);
+
BalanceTile = new WalletBalanceTileViewModel(wallet, balanceChanged);
BalanceChartTile = new WalletBalanceChartTileViewModel(History.UnfilteredTransactions);
WalletPieChart = new WalletPieChartTileViewModel(wallet, balanceChanged);
RoundStatusTile = new RoundStatusTileViewModel(wallet);
BtcPriceTile= new BtcPriceTileViewModel(wallet);
+
+ _tiles = new List<TileViewModel>
+ {
+ BalanceTile,
+ BalanceChartTile,
+ WalletPieChart,
+ RoundStatusTile,
+ BtcPriceTile
+ };
+ }
+
+ protected override void OnNavigatedTo(bool isInHistory, CompositeDisposable disposables)
+ {
+ base.OnNavigatedTo(isInHistory, disposables);
+
+ foreach (var tile in _tiles)
+ {
+ tile.Activate(disposables);
+ }
}
private CompositeDisposable Disposables { get; set; }

dispose tiles