Refactor Wallets commands execute to methods
MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/ClosedWalletViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/ClosedWalletViewModel.cs
@@ -17,7 +17,10 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets
{
_items = new ObservableCollection<NavBarItemViewModel>();
- OpenCommand = ReactiveCommand.Create(() =>
+ OpenCommand = ReactiveCommand.Create(() => OpenExecute(walletManagerViewModel));
+ }
+
+ private void OpenExecute(WalletManagerViewModel walletManagerViewModel)
{
if (!Wallet.IsLoggedIn)
{
@@ -27,7 +30,6 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets
{
Navigate().To(this);
}
- });
}
public override string IconName => "web_asset_regular";

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Receive/ReceiveAddressViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Receive/ReceiveAddressViewModel.cs
@@ -28,7 +28,18 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Receive
CopyAddressCommand = ReactiveCommand.CreateFromTask(async () => await Application.Current.Clipboard.SetTextAsync(Address));
- ShowOnHwWalletCommand = ReactiveCommand.CreateFromTask(async () =>
+ ShowOnHwWalletCommand = ReactiveCommand.CreateFromTask(async () => await ShowOnHwWalletExecute(model, network, masterFingerprint));
+
+ SaveQrCodeCommand = ReactiveCommand.CreateFromTask(async () => { await SaveQrCodeExecute(); });
+
+ SaveQrCodeCommand.ThrownExceptions
+ .ObserveOn(RxApp.TaskpoolScheduler)
+ .Subscribe(ex => Logger.LogError(ex));
+
+ NextCommand = CancelCommand;
+ }
+
+ private async Task ShowOnHwWalletExecute(HdPubKey model, Network network, HDFingerprint? masterFingerprint)
{
if (masterFingerprint is null)
{
@@ -55,21 +66,14 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Receive
await ShowErrorAsync(Title, ex.ToUserFriendlyString(), "We were unable to send the address to the device");
}
});
- });
+ }
- SaveQrCodeCommand = ReactiveCommand.CreateFromTask(async () =>
+ private async Task SaveQrCodeExecute()
{
if (QrCodeCommand is { } cmd)
{
await cmd.Execute(Address);
}
- });
-
- SaveQrCodeCommand.ThrownExceptions
- .ObserveOn(RxApp.TaskpoolScheduler)
- .Subscribe(ex => Logger.LogError(ex));
-
- NextCommand = CancelCommand;
}
public ReactiveCommand<string, Unit>? QrCodeCommand { get; set; }

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Receive/ReceiveViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Receive/ReceiveViewModel.cs
@@ -37,8 +37,12 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Receive
.ObserveOn(RxApp.MainThreadScheduler)
.Select(reference => !string.IsNullOrEmpty(reference));
- NextCommand = ReactiveCommand.Create(
- () =>
+ NextCommand = ReactiveCommand.Create(NextExecute, nextCommandCanExecute);
+
+ ShowExistingAddressesCommand = ReactiveCommand.Create(ShowExistingAddressesExecute);
+ }
+
+ private void NextExecute()
{
var newKey = WasabiWallet.KeyManager.GetNextReceiveKey(Reference, out bool minGapLimitIncreased);
@@ -50,11 +54,13 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Receive
// TODO: notification
}
- Navigate().To(new ReceiveAddressViewModel(newKey, WasabiWallet.Network, WasabiWallet.KeyManager.MasterFingerprint, WasabiWallet.KeyManager.IsHardwareWallet));
- },
- nextCommandCanExecute);
+ Navigate().To(new ReceiveAddressViewModel(newKey, WasabiWallet.Network, WasabiWallet.KeyManager.MasterFingerprint,
+ WasabiWallet.KeyManager.IsHardwareWallet));
+ }
- ShowExistingAddressesCommand = ReactiveCommand.Create(() => Navigate().To(new ReceiveAddressesViewModel(WasabiWallet)));
+ private void ShowExistingAddressesExecute()
+ {
+ Navigate().To(new ReceiveAddressesViewModel(WasabiWallet));
}
public Wallet WasabiWallet { get; }

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/OptimisePrivacyViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/OptimisePrivacyViewModel.cs
@@ -38,10 +38,15 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
_privacySuggestions = new ObservableCollection<PrivacySuggestionControlViewModel>();
- NextCommand = ReactiveCommand.Create(() =>
+ NextCommand = ReactiveCommand.Create(
+ () => NextExecute(wallet, transactionInfo, broadcaster),
+ this.WhenAnyValue(x => x.SelectedPrivacySuggestion).Select(x => x is { }));
+ }
+
+ private void NextExecute(Wallet wallet, TransactionInfo transactionInfo, TransactionBroadcaster broadcaster)
{
- Navigate().To(new TransactionPreviewViewModel(wallet, transactionInfo, broadcaster, SelectedPrivacySuggestion!.TransactionResult));
- }, this.WhenAnyValue(x => x.SelectedPrivacySuggestion).Select(x => x is { }));
+ Navigate().To(new TransactionPreviewViewModel(wallet, transactionInfo, broadcaster,
+ SelectedPrivacySuggestion!.TransactionResult));
}
protected override void OnNavigatedTo(bool inHistory, CompositeDisposable disposables)

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/SendViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/SendViewModel.cs
@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
+using System.Threading.Tasks;
using System.Windows.Input;
using Avalonia;
using Avalonia.Threading;
@@ -92,7 +93,14 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
_transactionInfo.Labels = new SmartLabel(_labels.ToArray());
});
- PasteCommand = ReactiveCommand.CreateFromTask(async () =>
+ PasteCommand = ReactiveCommand.CreateFromTask(async () => await PasteExecute());
+
+ NextCommand = ReactiveCommand.Create(
+ () => NextExecute(broadcaster),
+ this.WhenAnyValue(x=>x.Labels.Count).Any());
+ }
+
+ private async Task PasteExecute()
{
var text = await Application.Current.Clipboard.GetTextAsync();
@@ -105,9 +113,9 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
}
_parsingUrl = false;
- });
+ }
- NextCommand = ReactiveCommand.Create(() =>
+ private void NextExecute(TransactionBroadcaster broadcaster)
{
var transactionInfo = _transactionInfo;
var wallet = _owner.Wallet;
@@ -142,7 +150,6 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
}
Navigate().To(new PrivacyControlViewModel());
- }, this.WhenAnyValue(x=>x.Labels.Count).Any());
}
private void SetXAxisCurrentValueIndex(double xAxisCurrentValue)

Refactor Wallets commands execute to methods