Fix privacy ring rendering twice
MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/PrivacyRing/PrivacyRingViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/PrivacyRing/PrivacyRingViewModel.cs
@@ -21,8 +21,8 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles.PrivacyRing;
public partial class PrivacyRingViewModel : RoutableViewModel
{
private readonly CompositeDisposable _disposables = new();
- private readonly SourceList<PrivacyRingItemViewModel> _itemsSourceList = new();
- private IObservable<Unit> _coinsUpdated;
+ private readonly WalletViewModel _walletViewModel;
+
[AutoNotify] private PrivacyRingItemViewModel? _selectedItem;
[AutoNotify] private double _height;
[AutoNotify] private double _width;
@@ -31,6 +31,7 @@ public partial class PrivacyRingViewModel : RoutableViewModel
public PrivacyRingViewModel(WalletViewModel walletViewModel)
{
+ _walletViewModel = walletViewModel;
Wallet = walletViewModel.Wallet;
NextCommand = CancelCommand;
@@ -39,53 +40,60 @@ public partial class PrivacyRingViewModel : RoutableViewModel
PreviewItems.Add(PrivacyTile);
- _itemsSourceList
+ SetupCancel(enableCancel: true, enableCancelOnEscape: true, enableCancelOnPressed: true);
+ }
+
+ public PrivacyControlTileViewModel PrivacyTile { get; }
+
+ public ObservableCollectionExtended<PrivacyRingItemViewModel> Items { get; } = new();
+ public ObservableCollectionExtended<IPrivacyRingPreviewItem> PreviewItems { get; } = new();
+
+ public Wallet Wallet { get; }
+
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "Uses DisposeWith()")]
+ protected override void OnNavigatedTo(bool isInHistory, CompositeDisposable disposables)
+ {
+ var itemsSourceList = new SourceList<PrivacyRingItemViewModel>();
+
+ itemsSourceList
.Connect()
.ObserveOn(RxApp.MainThreadScheduler)
.Bind(Items)
.DisposeMany()
- .Subscribe();
-
- _coinsUpdated =
- walletViewModel.UiTriggers.PrivacyProgressUpdateTrigger
- .Merge(walletViewModel
- .WhenAnyValue(w => w.IsCoinJoining)
- .ToSignal());
-
- _coinsUpdated
- .Select(_ => walletViewModel.Wallet.GetPockets())
+ .Subscribe()
+ .DisposeWith(disposables);
+
+ _walletViewModel.UiTriggers
+ .PrivacyProgressUpdateTrigger
+ .Merge(_walletViewModel.WhenAnyValue(w => w.IsCoinJoining).ToSignal())
+ .Skip(3)
+ .Select(_ => _walletViewModel.Wallet.GetPockets())
.ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(RefreshCoinsList);
-
- _disposables.Add(_itemsSourceList);
+ .Subscribe(_ => RefreshCoinsList(itemsSourceList))
+ .DisposeWith(disposables);
this.WhenAnyValue(x => x.Width, x => x.Height)
+ .Where(tuple => tuple.Item1 != 0 && tuple.Item2 != 0)
.Subscribe(x =>
{
var usableHeight = x.Item2;
var usableWidth = x.Item1;
Margin = new Thickness(usableWidth / 2, usableHeight / 2, 0, 0);
NegativeMargin = new Thickness(Margin.Left * -1, Margin.Top * -1, 0, 0);
- RefreshCoinsList(walletViewModel.Wallet.GetPockets());
- });
-
- SetupCancel(enableCancel: true, enableCancelOnEscape: true, enableCancelOnPressed: true);
+ RefreshCoinsList(itemsSourceList);
+ })
+ .DisposeWith(disposables);
}
- public PrivacyControlTileViewModel PrivacyTile { get; }
-
- public ObservableCollectionExtended<PrivacyRingItemViewModel> Items { get; } = new();
- public ObservableCollectionExtended<IPrivacyRingPreviewItem> PreviewItems { get; } = new();
-
- public Wallet Wallet { get; }
-
- private void RefreshCoinsList(IEnumerable<Pocket> pockets)
+ private void RefreshCoinsList(SourceList<PrivacyRingItemViewModel> itemsSourceList)
{
- _itemsSourceList.Edit(list => CreateSegments(pockets, list));
+ var pockets = _walletViewModel.Wallet.GetPockets();
+ itemsSourceList.Edit(list => CreateSegments(pockets, list));
}
private void CreateSegments(IEnumerable<Pocket> pockets, IExtendedList<PrivacyRingItemViewModel> list)
{
+ Items.Clear();
list.Clear();
if (Width == 0d)
@@ -165,10 +173,4 @@ public partial class PrivacyRingViewModel : RoutableViewModel
start = end;
}
}
-
- public void Dispose()
- {
- _itemsSourceList?.Dispose();
- _disposables.Dispose();
- }
}

Fix privacy ring rendering twice