handle exception on PrivacyControl
ADD
WalletWasabi.Fluent/Helpers/TransactionHelpers.cs
+using System.Collections.Generic;
+using System.Linq;
+using NBitcoin;
+using WalletWasabi.Blockchain.Analysis.Clustering;
+using WalletWasabi.Blockchain.TransactionBuilding;
+using WalletWasabi.Blockchain.TransactionOutputs;
+using WalletWasabi.Wallets;
+
+namespace WalletWasabi.Fluent.Helpers
+{
+ public static class TransactionHelpers
+ {
+ public static BuildTransactionResult BuildTransaction(Wallet wallet, BitcoinAddress address, Money amount, SmartLabel labels, FeeRate feeRate, IEnumerable<SmartCoin> coins, bool subtractFee)
+ {
+ var intent = new PaymentIntent(
+ destination: address,
+ amount: amount,
+ subtractFee: subtractFee,
+ label: labels);
+
+ var txRes = wallet.BuildTransaction(
+ wallet.Kitchen.SaltSoup(),
+ intent,
+ FeeStrategy.CreateFromFeeRate(feeRate),
+ allowUnconfirmed: true,
+ coins.Select(coin => coin.OutPoint));
+
+ return txRes;
+ }
+ }
+}

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/PrivacyControlViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/PrivacyControlViewModel.cs
@@ -8,7 +8,10 @@ using NBitcoin;
using ReactiveUI;
using WalletWasabi.Blockchain.TransactionBroadcasting;
using WalletWasabi.Blockchain.TransactionBuilding;
+using WalletWasabi.Blockchain.Transactions;
+using WalletWasabi.Exceptions;
using WalletWasabi.Fluent.Helpers;
+using WalletWasabi.Fluent.ViewModels.Dialogs;
using WalletWasabi.Fluent.ViewModels.Navigation;
using WalletWasabi.Wallets;
@@ -49,23 +52,30 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
StillNeeded = transactionInfo.Amount.ToDecimal(MoneyUnit.BTC);
- NextCommand = ReactiveCommand.Create(
- () =>
+ NextCommand = ReactiveCommand.CreateFromTask(
+ async () =>
{
- var coins = selectedList.Items.SelectMany(x => x.Coins);
-
- var intent = new PaymentIntent(
- transactionInfo.Address,
- transactionInfo.Amount,
- subtractFee: false,
- transactionInfo.Labels);
-
- var transactionResult = _wallet.BuildTransaction(
- _wallet.Kitchen.SaltSoup(),
- intent,
- FeeStrategy.CreateFromFeeRate(transactionInfo.FeeRate),
- true,
- coins.Select(x => x.OutPoint));
+ BuildTransactionResult transactionResult;
+ var coins = selectedList.Items.SelectMany(x => x.Coins).ToArray();
+
+ try
+ {
+ transactionResult = TransactionHelpers.BuildTransaction(_wallet, transactionInfo.Address, transactionInfo.Amount, transactionInfo.Labels, transactionInfo.FeeRate, coins, subtractFee: false);
+ }
+ catch (InsufficientBalanceException)
+ {
+ var dialog = new InsufficientBalanceDialogViewModel();
+ var result = await NavigateDialog(dialog, NavigationTarget.DialogScreen);
+
+ if (result.Result)
+ {
+ transactionResult = TransactionHelpers.BuildTransaction(_wallet, transactionInfo.Address, transactionInfo.Amount, transactionInfo.Labels, transactionInfo.FeeRate, coins, subtractFee: true);
+ }
+ else
+ {
+ return;
+ }
+ }
Navigate().To(new TransactionPreviewViewModel(wallet, transactionInfo, broadcaster, transactionResult));
},

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/SendViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/SendViewModel.cs
@@ -14,9 +14,8 @@ using NBitcoin.Payment;
using ReactiveUI;
using WalletWasabi.Blockchain.Analysis.Clustering;
using WalletWasabi.Blockchain.TransactionBroadcasting;
-using WalletWasabi.Blockchain.TransactionBuilding;
-using WalletWasabi.Blockchain.TransactionOutputs;
using WalletWasabi.Exceptions;
+using WalletWasabi.Fluent.Helpers;
using WalletWasabi.Fluent.MathNet;
using WalletWasabi.Fluent.Validation;
using WalletWasabi.Fluent.ViewModels.Dialogs;
@@ -25,7 +24,6 @@ using WalletWasabi.Gui.Converters;
using WalletWasabi.Helpers;
using WalletWasabi.Models;
using WalletWasabi.Userfacing;
-using WalletWasabi.Wallets;
namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
{
@@ -123,7 +121,7 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
{
try
{
- var txRes = BuildTransaction(wallet, transactionInfo.Address, transactionInfo.Amount, transactionInfo.Labels, transactionInfo.FeeRate, mixedCoins, subtractFee: false);
+ var txRes = TransactionHelpers.BuildTransaction(wallet, transactionInfo.Address, transactionInfo.Amount, transactionInfo.Labels, transactionInfo.FeeRate, mixedCoins, subtractFee: false);
Navigate().To(new OptimisePrivacyViewModel(wallet, transactionInfo, broadcaster, txRes));
return;
}
@@ -134,7 +132,7 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
if (result.Result)
{
- var txRes = BuildTransaction(wallet, transactionInfo.Address, totalMixedCoinsAmount, transactionInfo.Labels, transactionInfo.FeeRate, mixedCoins, subtractFee: true);
+ var txRes = TransactionHelpers.BuildTransaction(wallet, transactionInfo.Address, totalMixedCoinsAmount, transactionInfo.Labels, transactionInfo.FeeRate, mixedCoins, subtractFee: true);
Navigate().To(new OptimisePrivacyViewModel(wallet, transactionInfo, broadcaster, txRes));
return;
}
@@ -149,23 +147,7 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
}, this.WhenAnyValue(x=>x.Labels.Count).Any());
}
- private BuildTransactionResult BuildTransaction(Wallet wallet, BitcoinAddress address, Money amount, SmartLabel labels, FeeRate feeRate, List<SmartCoin> coins, bool subtractFee)
- {
- var intent = new PaymentIntent(
- destination: address,
- amount: amount,
- subtractFee: subtractFee,
- label: labels);
-
- var txRes = wallet.BuildTransaction(
- wallet.Kitchen.SaltSoup(),
- intent,
- FeeStrategy.CreateFromFeeRate(feeRate),
- allowUnconfirmed: true,
- coins.Select(coin => coin.OutPoint));
- return txRes;
- }
private void SetXAxisCurrentValueIndex(double xAxisCurrentValue)
{

handle exception on PrivacyControl