simplify code by moving stuff to methods.
MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/TransactionPreviewViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/TransactionPreviewViewModel.cs
@@ -51,9 +51,43 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
if (PreferPsbtWorkflow)
{
- SkipCommand = ReactiveCommand.CreateFromTask(async () => await OnConfirmAsync(_transaction));
+ SkipCommand = ReactiveCommand.CreateFromTask(OnConfirmAsync);
- NextCommand = ReactiveCommand.CreateFromTask(async () =>
+ NextCommand = ReactiveCommand.CreateFromTask(OnExportPsbtAsync);
+
+ _nextButtonText = "Save PSBT file";
+ }
+ else
+ {
+ NextCommand = ReactiveCommand.CreateFromTask(OnConfirmAsync);
+
+ _nextButtonText = "Confirm";
+ }
+
+ AdjustFeeCommand = ReactiveCommand.CreateFromTask(OnAdjustFeeAsync);
+
+ AvoidChangeCommand = ReactiveCommand.CreateFromTask(OnAvoidChangeAsync);
+
+ ChangePocketsCommand = ReactiveCommand.CreateFromTask(OnChangePocketsAsync);
+ }
+
+ public bool PreferPsbtWorkflow => _wallet.KeyManager.PreferPsbtWorkflow;
+
+ public string AddressText { get; }
+
+ public string? PayJoinUrl { get; }
+
+ public bool IsPayJoin { get; }
+
+ public ICommand AdjustFeeCommand { get; }
+
+ public ICommand AvoidChangeCommand { get; }
+
+ public ICommand ChangePocketsCommand { get; }
+
+ private async Task OnExportPsbtAsync()
+ {
+ if (_transaction is { })
{
var saved = await TransactionHelpers.ExportTransactionToBinaryAsync(_transaction);
@@ -61,20 +95,12 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
{
Navigate().To(new SuccessViewModel("The PSBT has been successfully created."));
}
- });
-
- _nextButtonText = "Save PSBT file";
}
- else
- {
- NextCommand = ReactiveCommand.CreateFromTask(async () => await OnConfirmAsync(_transaction));
-
- _nextButtonText = "Confirm";
}
- AdjustFeeCommand = ReactiveCommand.CreateFromTask(async () =>
+ private async Task OnAdjustFeeAsync()
{
- var feeRateDialogResult = await NavigateDialogAsync(new SendFeeViewModel(wallet, info, false));
+ var feeRateDialogResult = await NavigateDialogAsync(new SendFeeViewModel(_wallet, _info, false));
if (feeRateDialogResult.Kind == DialogResultKind.Normal && feeRateDialogResult.Result != _info.FeeRate)
{
@@ -87,23 +113,23 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
UpdateTransaction(newTransaction);
}
}
- });
+ }
- AvoidChangeCommand = ReactiveCommand.CreateFromTask(async () =>
+ private async Task OnAvoidChangeAsync()
{
var optimisePrivacyDialog =
- await NavigateDialogAsync(new OptimisePrivacyViewModel(wallet, info, _transaction!));
+ await NavigateDialogAsync(new OptimisePrivacyViewModel(_wallet, _info, _transaction!));
if (optimisePrivacyDialog.Kind == DialogResultKind.Normal && optimisePrivacyDialog.Result is { })
{
UpdateTransaction(optimisePrivacyDialog.Result);
}
- });
+ }
- ChangePocketsCommand = ReactiveCommand.CreateFromTask(async () =>
+ private async Task OnChangePocketsAsync()
{
var selectPocketsDialog =
- await NavigateDialogAsync(new PrivacyControlViewModel(wallet, info, false));
+ await NavigateDialogAsync(new PrivacyControlViewModel(_wallet, _info, false));
if (selectPocketsDialog.Kind == DialogResultKind.Normal && selectPocketsDialog.Result is { })
{
@@ -116,23 +142,8 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
UpdateTransaction(newTransaction);
}
}
- });
}
- public bool PreferPsbtWorkflow => _wallet.KeyManager.PreferPsbtWorkflow;
-
- public string AddressText { get; }
-
- public string? PayJoinUrl { get; }
-
- public bool IsPayJoin { get; }
-
- public ICommand AdjustFeeCommand { get; }
-
- public ICommand AvoidChangeCommand { get; }
-
- public ICommand ChangePocketsCommand { get; }
-
private async Task<bool> InitialiseTransactionAsync()
{
var privacyControlDialogResult = await NavigateDialogAsync(new PrivacyControlViewModel(_wallet, _info, isSilent: true));
@@ -289,7 +300,6 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
{
if (await InitialiseTransactionAsync())
{
-
var initialTransaction = await BuildTransactionAsync();
if (initialTransaction is { })
@@ -305,8 +315,12 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
}
}
- private async Task OnConfirmAsync(BuildTransactionResult transaction)
+ private async Task OnConfirmAsync()
{
+ if (_transaction is { })
+ {
+ var transaction = _transaction;
+
var transactionAuthorizationInfo = new TransactionAuthorizationInfo(transaction);
var authResult = await AuthorizeAsync(transactionAuthorizationInfo);
@@ -317,18 +331,21 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
try
{
- var finalTransaction = await GetFinalTransactionAsync(transactionAuthorizationInfo.Transaction, _info);
+ var finalTransaction =
+ await GetFinalTransactionAsync(transactionAuthorizationInfo.Transaction, _info);
await SendTransactionAsync(finalTransaction);
Navigate().To(new SendSuccessViewModel(_wallet, finalTransaction));
}
catch (Exception ex)
{
- await ShowErrorAsync("Transaction", ex.ToUserFriendlyString(), "Wasabi was unable to send your transaction.");
+ await ShowErrorAsync("Transaction", ex.ToUserFriendlyString(),
+ "Wasabi was unable to send your transaction.");
}
IsBusy = false;
}
}
+ }
private async Task<bool> AuthorizeAsync(TransactionAuthorizationInfo transactionAuthorizationInfo)
{

simplify code by moving stuff to methods.