Skip to content
Permalink
Browse files

[skip ci] Make Warning disappear like in the Send button.

  • Loading branch information...
nopara73 committed Nov 24, 2018
1 parent 11d8fb4 commit 54220de0e7fd2669d975a03b840490f4614e32fe
@@ -15,7 +15,7 @@
<Grid Classes="content">
<DockPanel LastChildFill="True">
<StackPanel Spacing="10" Orientation="Horizontal" DockPanel.Dock="Bottom" Margin="0 10 0 0" HorizontalAlignment="Right">
<TextBlock Text="{Binding WarningMessageEnqueueDequeue}" Classes="warningMessage" />
<TextBlock Text="{Binding WarningMessage}" Classes="warningMessage" />
<TextBox Text="{Binding Password}" PasswordChar="*" Watermark="Password" UseFloatingWatermark="True" MinWidth="173" />
<DockPanel LastChildFill="True" VerticalAlignment="Top">
<Button Content="Enqueue Selected Coins for CoinJoin" Command="{Binding EnqueueCommand}" DockPanel.Dock="Right" />
@@ -7,6 +7,7 @@
using System.Text;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Threading;
using NBitcoin;
using ReactiveUI;
using ReactiveUI.Legacy;
@@ -30,7 +31,7 @@ public class CoinJoinTabViewModel : WalletActionViewModel
private int _peersNeeded;
private string _password;
private Money _amountQueued;
private string _warningMessageEnqueue;
private string _warningMessage;
private const int PreSelectMaxAnonSetExcludingCondition = 50;

public CoinJoinTabViewModel(WalletViewModel walletViewModel)
@@ -101,6 +102,8 @@ public CoinJoinTabViewModel(WalletViewModel walletViewModel)

DequeueCommand = ReactiveCommand.Create(async () =>
{
WarningMessage = "";

var selectedCoins = CoinsList.Coins.Where(c => c.IsSelected).ToList();

foreach (var coin in selectedCoins)
@@ -115,18 +118,17 @@ public CoinJoinTabViewModel(WalletViewModel walletViewModel)
catch (Exception ex)
{
Logger.LogWarning<CoinJoinTabViewModel>(ex);
WarningMessageEnqueueDequeue = ex.ToTypeMessageString();
var warningMessage = ex.ToTypeMessageString();
if (ex is AggregateException aggex)
{
foreach (var iex in aggex.InnerExceptions)
{
WarningMessageEnqueueDequeue += Environment.NewLine + iex.ToTypeMessageString();
warningMessage += Environment.NewLine + iex.ToTypeMessageString();
}
}
SetWarningMessage(warningMessage);
return;
}

WarningMessageEnqueueDequeue = "";
});

this.WhenAnyValue(x => x.Password).Subscribe(async x =>
@@ -145,38 +147,37 @@ public CoinJoinTabViewModel(WalletViewModel walletViewModel)

private async Task DoEnqueueAsync()
{
WarningMessage = "";
Password = Guard.Correct(Password);
var selectedCoins = CoinsList.Coins.Where(c => c.IsSelected).ToList();

if (!selectedCoins.Any())
{
WarningMessageEnqueueDequeue = "No coins are selected to enqueue.";
SetWarningMessage("No coins are selected to enqueue.");
return;
}

WarningMessageEnqueueDequeue = string.Empty;

try
{
await Global.ChaumianClient.QueueCoinsToMixAsync(Password, selectedCoins.Select(c => c.Model).ToArray());
}
catch (Exception ex)
{
Logger.LogWarning<CoinJoinTabViewModel>(ex);
WarningMessageEnqueueDequeue = ex.ToTypeMessageString();
var warningMessage = ex.ToTypeMessageString();
if (ex is AggregateException aggex)
{
foreach (var iex in aggex.InnerExceptions)
{
WarningMessageEnqueueDequeue += Environment.NewLine + iex.ToTypeMessageString();
warningMessage += Environment.NewLine + iex.ToTypeMessageString();
}
}
SetWarningMessage(warningMessage);
Password = string.Empty;
return;
}

Password = string.Empty;
WarningMessageEnqueueDequeue = string.Empty;
}

private void ChaumianClient_CoinDequeued(object sender, SmartCoin e)
@@ -269,6 +270,20 @@ public override void OnDeselected()
Global.ChaumianClient.DeactivateFrequentStatusProcessingIfNotMixing();
}

private void SetWarningMessage(string message)
{
WarningMessage = message;

Dispatcher.UIThread.Post(async () =>
{
await Task.Delay(7000);
if (WarningMessage == message)
{
WarningMessage = "";
}
});
}

public string Password
{
get { return _password; }
@@ -332,10 +347,10 @@ public int PeersNeeded
set { this.RaiseAndSetIfChanged(ref _peersNeeded, value); }
}

public string WarningMessageEnqueueDequeue
public string WarningMessage
{
get { return _warningMessageEnqueue; }
set { this.RaiseAndSetIfChanged(ref _warningMessageEnqueue, value); }
get { return _warningMessage; }
set { this.RaiseAndSetIfChanged(ref _warningMessage, value); }
}

public ReactiveCommand EnqueueCommand { get; }

0 comments on commit 54220de

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