Simplify MaxClear logic.
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabView.xaml
WalletWasabi.Gui/Controls/WalletExplorer/SendTabView.xaml
xmlns:local="clr-namespace:WalletWasabi.Gui.Controls.WalletExplorer;assembly=WalletWasabi.Gui">
<UserControl.Resources>
<converters:AmountForegroundConverter x:Key="AmountForegroundConverter" />
+ <converters:MaxClearBoolStringConverter x:Key="MaxClearBoolStringConverter" />
</UserControl.Resources>
<i:Interaction.Behaviors>
<behaviors:ClearPropertyOnLostFocusBehavior TargetProperty="{Binding SelectedCoin}" />
</ItemsControl>
</StackPanel>
<StackPanel Orientation="Horizontal" Spacing="10">
- <Button Content="{Binding MaxClear}" Command="{Binding MaxCommand}" VerticalAlignment="Top" Height="40" />
+ <Button Content="{Binding IsMax, Converter={StaticResource MaxClearBoolStringConverter}}" Command="{Binding MaxCommand}" VerticalAlignment="Top" Height="40" />
<controls:ExtendedTextBox Foreground="{Binding IsMax, Converter={StaticResource AmountForegroundConverter}}" IsReadOnly="{Binding IsMax}" Text="{Binding Amount}" ToolTip.Tip="{Binding AmountToolTip}" Watermark="{Binding AmountWatermarkText}" UseFloatingWatermark="True" MinWidth="124" MinHeight="46" />
<StackPanel>
<StackPanel Orientation="Horizontal" Spacing="10">

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
@@ -34,7 +34,6 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
private string _buildTransactionButtonText;
private bool _isMax;
- private string _maxClear;
private string _amount;
private int _feeTarget;
private int _minimumFeeTarget;
@@ -78,23 +77,39 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
}
- public SendTabViewModel(WalletViewModel walletViewModel, bool isTransactionBuilder = false)
- : base(isTransactionBuilder ? "Build Transaction" : "Send", walletViewModel)
+ private void ResetUi()
{
_suggestions = new ObservableCollection<SuggestionViewModel>();
+ Address = "";
Label = "";
+ Password = "";
AllSelectedAmount = Money.Zero;
- UsdExchangeRate = Global.Synchronizer.UsdExchangeRate;
+ UsdExchangeRate = Global.Synchronizer?.UsdExchangeRate ?? UsdExchangeRate;
+ IsMax = false;
+ LabelToolTip = "Start labelling today and your privacy will thank you tomorrow!";
+
+ IgnoreAmountChanges = true;
+ Amount = "0.0";
+ IgnoreAmountChanges = false;
+ }
+
+ public SendTabViewModel(WalletViewModel walletViewModel, bool isTransactionBuilder = false)
+ : base(isTransactionBuilder ? "Build Transaction" : "Send", walletViewModel)
+ {
IsTransactionBuilder = isTransactionBuilder;
+ BuildTransactionButtonText = IsTransactionBuilder ? BuildTransactionButtonTextString : SendTransactionButtonTextString;
+
+ ResetUi();
SetAmountWatermarkAndToolTip(Money.Zero);
CoinList = new CoinListViewModel();
- Observable.FromEventPattern(CoinList, nameof(CoinList.SelectionChanged)).Subscribe(_ => SetFeesAndTexts());
- Observable.FromEventPattern(CoinList, nameof(CoinList.DequeueCoinsPressed)).Subscribe(_ => OnCoinsListDequeueCoinsPressedAsync());
-
- BuildTransactionButtonText = IsTransactionBuilder ? BuildTransactionButtonTextString : SendTransactionButtonTextString;
+ Observable.FromEventPattern(CoinList, nameof(CoinList.SelectionChanged))
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(_ => SetFeesAndTexts());
+ Observable.FromEventPattern(CoinList, nameof(CoinList.DequeueCoinsPressed))
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(_ => OnCoinsListDequeueCoinsPressedAsync());
- ResetMax();
SetFeeTargetLimits();
FeeTarget = Global.UiConfig.FeeTarget ?? MinimumFeeTarget;
FeeDisplayFormat = (FeeDisplayFormat)(Enum.ToObject(typeof(FeeDisplayFormat), Global.UiConfig.FeeDisplayFormat) ?? FeeDisplayFormat.SatoshiPerByte);
@@ -203,9 +218,28 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
});
- MaxCommand = ReactiveCommand.Create(SetMax);
+ MaxCommand = ReactiveCommand.Create(() => { IsMax = !IsMax; }, outputScheduler: RxApp.MainThreadScheduler);
+ this.WhenAnyValue(x => x.IsMax)
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(x =>
+ {
+ if (IsMax)
+ {
+ SetAmountIfMax();
+
+ LabelToolTip = "Spending whole coins doesn't generate change, thus labeling is unnecessary.";
+ }
+ else
+ {
+ IgnoreAmountChanges = true;
+ Amount = "0.0";
+ IgnoreAmountChanges = false;
+
+ LabelToolTip = "Start labelling today and your privacy will thank you tomorrow!";
+ }
+ });
- FeeRateCommand = ReactiveCommand.Create(ChangeFeeRateDisplay);
+ FeeRateCommand = ReactiveCommand.Create(ChangeFeeRateDisplay, outputScheduler: RxApp.MainThreadScheduler);
BuildTransactionCommand = ReactiveCommand.CreateFromTask(async () =>
{
@@ -700,42 +734,11 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
}
- private void SetMax()
- {
- if (IsMax)
- {
- ResetMax();
- return;
- }
-
- IsMax = true;
- MaxClear = "Clear";
-
- SetAmountIfMax();
-
- LabelToolTip = "Spending whole coins doesn't generate change, thus labeling is unnecessary.";
- }
-
- private void ResetMax()
- {
- IsMax = false;
- MaxClear = "Max";
-
- IgnoreAmountChanges = true;
- Amount = "0.0";
- IgnoreAmountChanges = false;
-
- LabelToolTip = "Start labelling today and your privacy will thank you tomorrow!";
- }
-
private void TryResetInputsOnSuccess(string successMessage)
{
try
{
- ResetMax();
- Address = "";
- Label = "";
- Password = "";
+ ResetUi();
SetSuccessMessage(successMessage);
}
@@ -821,12 +824,6 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
set => this.RaiseAndSetIfChanged(ref _isMax, value);
}
- public string MaxClear
- {
- get => _maxClear;
- set => this.RaiseAndSetIfChanged(ref _maxClear, value);
- }
-
public string Amount
{
get => _amount;

ADD
WalletWasabi.Gui/Converters/MaxClearBoolStringConverter.cs
+using Avalonia.Data.Converters;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Text;
+
+namespace WalletWasabi.Gui.Converters
+{
+ public class MaxClearBoolStringConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is bool boolean)
+ {
+ if (boolean)
+ {
+ return "Clear";
+ }
+ else
+ {
+ return "Max";
+ }
+ }
+
+ throw new InvalidOperationException();
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotSupportedException();
+ }
+ }
+}

Simplify MaxClear logic.