diff --git a/WalletWasabi.Fluent/Extensions/ObservableExtensions.cs b/WalletWasabi.Fluent/Extensions/ObservableExtensions.cs index ddac3101e84..1a4f6102649 100644 --- a/WalletWasabi.Fluent/Extensions/ObservableExtensions.cs +++ b/WalletWasabi.Fluent/Extensions/ObservableExtensions.cs @@ -116,26 +116,4 @@ public static IObservableCache Fetch(this IObserva .DisposeMany() .AsObservableCache(); } - - public static (IObservableCache, IObservableCache) Fetch( - this IObservable signal, - (Func> Source, Func KeySelector, IEqualityComparer? EqualityComparer) first, - (Func> Source, Func KeySelector, IEqualityComparer? EqualityComparer) second) - where TKey1 : notnull - where TKey2 : notnull - where TObject1 : notnull - where TObject2 : notnull - { - var cache1 = signal.Select(_ => first.Source()) - .EditDiff(first.KeySelector, first.EqualityComparer) - .DisposeMany() - .AsObservableCache(); - - var cache2 = signal.Select(_ => second.Source()) - .EditDiff(second.KeySelector, second.EqualityComparer) - .DisposeMany() - .AsObservableCache(); - - return (cache1, cache2); - } } diff --git a/WalletWasabi.Fluent/Models/Wallets/CoinListModel.cs b/WalletWasabi.Fluent/Models/Wallets/CoinListModel.cs index 425729b41fc..4c5708d952a 100644 --- a/WalletWasabi.Fluent/Models/Wallets/CoinListModel.cs +++ b/WalletWasabi.Fluent/Models/Wallets/CoinListModel.cs @@ -16,8 +16,6 @@ public abstract partial class CoinListModel : IDisposable { private readonly CompositeDisposable _disposables = new(); - private object Lock { get; } = new(); - public CoinListModel(Wallet wallet, IWalletModel walletModel) { Wallet = wallet; @@ -34,13 +32,8 @@ public CoinListModel(Wallet wallet, IWalletModel walletModel) .Merge(isSelected) .Publish(); - (List, Pockets) = signals.Fetch( - first: (Source: CreateCoinModels, KeySelector: x => x.Key, EqualityComparer: null), - second: (Source: GetPockets, KeySelector: x => x.Labels, EqualityComparer: null) - ); - - List.DisposeWith(_disposables); - Pockets.DisposeWith(_disposables); + List = signals.Fetch(CreateCoinModels, x => x.Key).DisposeWith(_disposables); + Pockets = signals.Fetch(GetPockets, x => x.Labels).DisposeWith(_disposables); signals .Do(_ => Logger.LogDebug($"Refresh signal emitted in {walletModel.Name}")) diff --git a/WalletWasabi.Fluent/Models/Wallets/UserSelectionCoinListModel.cs b/WalletWasabi.Fluent/Models/Wallets/UserSelectionCoinListModel.cs index ae784b9dcaa..87b0a977391 100644 --- a/WalletWasabi.Fluent/Models/Wallets/UserSelectionCoinListModel.cs +++ b/WalletWasabi.Fluent/Models/Wallets/UserSelectionCoinListModel.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; using System.Reactive.Linq; using WalletWasabi.Blockchain.TransactionOutputs; using WalletWasabi.Fluent.Helpers; diff --git a/WalletWasabi.Fluent/ViewModels/CoinControl/SelectCoinsDialogViewModel.cs b/WalletWasabi.Fluent/ViewModels/CoinControl/SelectCoinsDialogViewModel.cs index ec29adeca0a..3bd81990142 100644 --- a/WalletWasabi.Fluent/ViewModels/CoinControl/SelectCoinsDialogViewModel.cs +++ b/WalletWasabi.Fluent/ViewModels/CoinControl/SelectCoinsDialogViewModel.cs @@ -26,7 +26,7 @@ public SelectCoinsDialogViewModel(IWalletModel wallet, IList selecte { var transactionInfo = sendFlow.TransactionInfo ?? throw new InvalidOperationException($"Missing required TransactionInfo."); - CoinList = new CoinListViewModel(wallet, sendFlow.CoinList, selectedCoins, allowCoinjoiningCoinSelection: true, ignorePrivacyMode: true, allowSelection: true); + CoinList = new CoinListViewModel(sendFlow.CoinList, selectedCoins, allowCoinjoiningCoinSelection: true, ignorePrivacyMode: true, allowSelection: true); EnoughSelected = CoinList.Selection.ToObservableChangeSet() .ToCollection() diff --git a/WalletWasabi.Fluent/ViewModels/Wallets/Advanced/WalletCoinsViewModel.cs b/WalletWasabi.Fluent/ViewModels/Wallets/Advanced/WalletCoinsViewModel.cs index 1cb6e796252..87f9028a0c2 100644 --- a/WalletWasabi.Fluent/ViewModels/Wallets/Advanced/WalletCoinsViewModel.cs +++ b/WalletWasabi.Fluent/ViewModels/Wallets/Advanced/WalletCoinsViewModel.cs @@ -28,7 +28,7 @@ public WalletCoinsViewModel(UiContext uiContext, IWalletModel wallet) _wallet = wallet; SetupCancel(enableCancel: false, enableCancelOnEscape: true, enableCancelOnPressed: true); NextCommand = CancelCommand; - CoinList = new CoinListViewModel(_wallet, _wallet.Coins, new List(), allowCoinjoiningCoinSelection: false, ignorePrivacyMode: false, allowSelection: false); + CoinList = new CoinListViewModel(_wallet.Coins, new List(), allowCoinjoiningCoinSelection: false, ignorePrivacyMode: false, allowSelection: false); } public CoinListViewModel CoinList { get; } diff --git a/WalletWasabi.Fluent/ViewModels/Wallets/Coins/CoinListViewModel.cs b/WalletWasabi.Fluent/ViewModels/Wallets/Coins/CoinListViewModel.cs index a7ad2493806..27363234929 100644 --- a/WalletWasabi.Fluent/ViewModels/Wallets/Coins/CoinListViewModel.cs +++ b/WalletWasabi.Fluent/ViewModels/Wallets/Coins/CoinListViewModel.cs @@ -22,14 +22,12 @@ public class CoinListViewModel : ViewModelBase, IDisposable { private readonly CompositeDisposable _disposables = new(); private readonly ReadOnlyObservableCollection _itemsCollection; - private readonly IWalletModel _wallet; private readonly bool _ignorePrivacyMode; private readonly bool _allowCoinjoiningCoinSelection; [System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "Uses DisposeWith()")] - public CoinListViewModel(IWalletModel wallet, ICoinListModel availableCoins, IList initialCoinSelection, bool allowCoinjoiningCoinSelection, bool ignorePrivacyMode, bool allowSelection = true) + public CoinListViewModel(ICoinListModel availableCoins, IList initialCoinSelection, bool allowCoinjoiningCoinSelection, bool ignorePrivacyMode, bool allowSelection = true) { - _wallet = wallet; _ignorePrivacyMode = ignorePrivacyMode; _allowCoinjoiningCoinSelection = allowCoinjoiningCoinSelection; @@ -84,7 +82,7 @@ public CoinListViewModel(IWalletModel wallet, ICoinListModel availableCoins, ILi { IList oldSelection = Selection.ToArray(); var oldExpandedItemsLabel = _itemsCollection.Where(x => x.IsExpanded).Select(x => x.Labels).ToArray(); - Rebuild(viewModels, pockets); + Rebuild(viewModels, pockets, availableCoins); UpdateSelection(coinItemsCollection, oldSelection); RestoreExpandedRows(oldExpandedItemsLabel); }) @@ -95,8 +93,6 @@ public CoinListViewModel(IWalletModel wallet, ICoinListModel availableCoins, ILi TreeDataGridSource.DisposeWith(_disposables); CoinItems = coinItemsCollection; - _wallet = wallet; - ExpandAllCommand = ReactiveCommand.Create( () => { @@ -155,7 +151,7 @@ private static void UpdateSelection(IEnumerable coinItems, IList< } } - private void Rebuild(ISourceList source, IEnumerable pockets) + private void Rebuild(ISourceList source, IEnumerable pockets, ICoinListModel availableCoins) { var newItems = pockets.Select(pocket => @@ -164,12 +160,12 @@ private void Rebuild(ISourceList source, IEnumerable pocke if (pocket.Coins.Count() == 1) { var coin = pocket.Coins.First(); - var coinModel = _wallet.Coins.GetCoinModel(coin); + var coinModel = availableCoins.GetCoinModel(coin); return (CoinListItem)new CoinViewModel(pocket.Labels, coinModel, _ignorePrivacyMode, _allowCoinjoiningCoinSelection); } - return new PocketViewModel(_wallet, pocket, _allowCoinjoiningCoinSelection, _ignorePrivacyMode); + return new PocketViewModel(pocket, availableCoins, _allowCoinjoiningCoinSelection, _ignorePrivacyMode); }); source.EditDiff(newItems, new LambdaComparer((a, b) => Equals(a?.Key, b?.Key))); diff --git a/WalletWasabi.Fluent/ViewModels/Wallets/Coins/PocketViewModel.cs b/WalletWasabi.Fluent/ViewModels/Wallets/Coins/PocketViewModel.cs index 655b32383ef..b60c0ba0095 100644 --- a/WalletWasabi.Fluent/ViewModels/Wallets/Coins/PocketViewModel.cs +++ b/WalletWasabi.Fluent/ViewModels/Wallets/Coins/PocketViewModel.cs @@ -14,7 +14,7 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Coins; public class PocketViewModel : CoinListItem { - public PocketViewModel(IWalletModel wallet, Pocket pocket, bool canSelectCoinjoiningCoins, bool ignorePrivacyMode) + public PocketViewModel(Pocket pocket, ICoinListModel availableCoins, bool canSelectCoinjoiningCoins, bool ignorePrivacyMode) { var pocketCoins = pocket.Coins.ToList(); @@ -30,9 +30,9 @@ public PocketViewModel(IWalletModel wallet, Pocket pocket, bool canSelectCoinjoi Labels = pocket.Labels; Children = pocketCoins - .Select(wallet.Coins.GetCoinModel) + .Select(availableCoins.GetCoinModel) .OrderByDescending(x => x.AnonScore) - .Select(coin => new CoinViewModel("", coin, canSelectCoinjoiningCoins, ignorePrivacyMode) { IsChild = true }) + .Select(coin => new CoinViewModel("", coin, canSelectCoinjoiningCoins, ignorePrivacyMode) { IsChild = true }) .ToList(); Children diff --git a/WalletWasabi.Fluent/ViewModels/Wallets/Send/ManualControlDialogViewModel.cs b/WalletWasabi.Fluent/ViewModels/Wallets/Send/ManualControlDialogViewModel.cs index 1ad93e2fc92..6ba936a7cd6 100644 --- a/WalletWasabi.Fluent/ViewModels/Wallets/Send/ManualControlDialogViewModel.cs +++ b/WalletWasabi.Fluent/ViewModels/Wallets/Send/ManualControlDialogViewModel.cs @@ -16,12 +16,12 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send; [NavigationMetaData( - Title = "Manual Control", - IconName = "wallet_action_send", - NavBarPosition = NavBarPosition.None, - Searchable = false, - NavigationTarget = NavigationTarget.DialogScreen)] -public partial class ManualControlDialogViewModel: DialogViewModelBase> + Title = "Manual Control", + IconName = "wallet_action_send", + NavBarPosition = NavBarPosition.None, + Searchable = false, + NavigationTarget = NavigationTarget.DialogScreen)] +public partial class ManualControlDialogViewModel : DialogViewModelBase> { [AutoNotify] private bool _hasSelection; @@ -30,7 +30,7 @@ public partial class ManualControlDialogViewModel: DialogViewModelBase c.Any() ? walletModel.AmountProvider.Create(c.TotalAmount()) : null); + .ToObservableChangeSet() + .ToCollection() + .Select(c => c.Any() ? walletModel.AmountProvider.Create(c.TotalAmount()) : null); ToggleSelectionCommand = ReactiveCommand.Create(() => SelectAll(!CoinList.Selection.Any())); diff --git a/WalletWasabi.Fluent/ViewModels/Wallets/Settings/ExcludedCoinsViewModel.cs b/WalletWasabi.Fluent/ViewModels/Wallets/Settings/ExcludedCoinsViewModel.cs index ed885ae58e8..904de5c2ed2 100644 --- a/WalletWasabi.Fluent/ViewModels/Wallets/Settings/ExcludedCoinsViewModel.cs +++ b/WalletWasabi.Fluent/ViewModels/Wallets/Settings/ExcludedCoinsViewModel.cs @@ -24,7 +24,7 @@ public ExcludedCoinsViewModel(IWalletModel wallet) { _wallet = wallet; var initialCoins = wallet.Coins.List.Items.Where(x => x.IsExcludedFromCoinJoin); - CoinList = new CoinListViewModel(wallet, wallet.Coins, initialCoins.ToList(), allowCoinjoiningCoinSelection: false, ignorePrivacyMode: true); + CoinList = new CoinListViewModel(wallet.Coins, initialCoins.ToList(), allowCoinjoiningCoinSelection: false, ignorePrivacyMode: true); SetupCancel(enableCancel: true, enableCancelOnEscape: true, enableCancelOnPressed: true); NextCommand = ReactiveCommand.Create(() => Close()); ToggleSelectionCommand = ReactiveCommand.Create(() => SelectAll(!CoinList.Selection.Any()));