Skip to content
Permalink
Browse files

[skip ci] Improve error messages at Send.

Resolves #780
  • Loading branch information...
nopara73 committed Nov 10, 2018
1 parent b4f94ad commit 29a269367930c46c888073105f01583307c253be
Showing with 21 additions and 9 deletions.
  1. +21 −9 WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
@@ -96,14 +96,16 @@ public SendTabViewModel(WalletViewModel walletViewModel)
Password = Guard.Correct(Password);
if (!IsMax && string.IsNullOrWhiteSpace(Label))
{
throw new InvalidOperationException("Label is required.");
SetWarningMessage("Label is required.");
return;
}

var selectedCoins = CoinList.Coins.Where(cvm => cvm.IsSelected).Select(cvm => new TxoRef(cvm.Model.TransactionId, cvm.Model.Index)).ToList();

if (!selectedCoins.Any())
{
throw new InvalidOperationException("No coins are selected to spend.");
SetWarningMessage("No coins are selected to spend.");
return;
}

var address = BitcoinAddress.Create(Address.Trim(), Global.Network);
@@ -114,7 +116,8 @@ public SendTabViewModel(WalletViewModel walletViewModel)
amount = Money.Parse(Amount);
if (amount == Money.Zero)
{
throw new FormatException($"Invalid {nameof(Amount)}");
SetWarningMessage($"Invalid {nameof(Amount)}");
return;
}
}
var operation = new WalletService.Operation(script, amount, Label);
@@ -128,19 +131,16 @@ public SendTabViewModel(WalletViewModel walletViewModel)
Label = "";
Password = "";

SuccessMessage = "Transaction is successfully sent!";
WarningMessage = "";
SetSuccessMessage("Transaction is successfully sent!");
}
catch (InsufficientBalanceException ex)
{
SuccessMessage = "";
Money needed = ex.Minimum - ex.Actual;
WarningMessage = $"Not enough coins selected. You need an estimated {needed.ToString(false, true)} BTC more to make this transaction.";
SetWarningMessage($"Not enough coins selected. You need an estimated {needed.ToString(false, true)} BTC more to make this transaction.");
}
catch (Exception ex)
{
SuccessMessage = "";
WarningMessage = ex.ToTypeMessageString();
SetWarningMessage(ex.ToTypeMessageString());
}
finally
{
@@ -180,6 +180,18 @@ public SendTabViewModel(WalletViewModel walletViewModel)
});
}

private void SetWarningMessage(string message)
{
SuccessMessage = "";
WarningMessage = message;
}

private void SetSuccessMessage(string message)
{
SuccessMessage = message;
WarningMessage = "";
}

private void SetMax()
{
if (IsMax)

0 comments on commit 29a2693

Please sign in to comment.
You can’t perform that action at this time.