Use enumb for status instad of string
MODIFY
WalletWasabi.Gui/Controls/StatusBar.xaml
WalletWasabi.Gui/Controls/StatusBar.xaml
<converters:ShowCursorConverter x:Key="ShowCursorConverter" />
<converters:ShouldDisplayValueConverter x:Key="ShouldDisplayValueConverter" />
<converters:PascalToPhraseConverter x:Key="PascalToPhraseConverter" />
+ <converters:StatusBarStatusStringConverter x:Key="StatusBarStatusStringConverter" />
</UserControl.Resources>
<Grid Cursor="{Binding UpdateAvailable, Converter={StaticResource ShowCursorConverter}}" Background="{Binding UpdateStatus, Converter={StaticResource UpdateStatusBrushConverter}}">
</DrawingPresenter.Drawing>
</DrawingPresenter>
</Grid>
- <TextBlock Text="{Binding Status}" />
+ <TextBlock Text="{Binding StatusText}" />
</StackPanel>
</DockPanel>
</Grid>

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
@@ -198,13 +198,10 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
BuildTransactionCommand = ReactiveCommand.CreateFromTask(async () =>
{
- const string buildingTransactionStatusText = "Building transaction...";
- const string signingTransactionStatusText = "Signing transaction...";
- const string broadcastingTransactionStatusText = "Broadcasting transaction...";
try
{
IsBusy = true;
- MainWindowViewModel.Instance.StatusBar.TryAddStatus(buildingTransactionStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.BuildingTransaction);
Password = Guard.Correct(Password);
Label = Label.Trim(',', ' ').Trim();
@@ -253,10 +250,9 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
var label = Label;
var operation = new WalletService.Operation(script, amount, label);
- const string dequeuingSelectedCoinsStatusText = "Dequeueing selected coins...";
try
{
- MainWindowViewModel.Instance.StatusBar.TryAddStatus(dequeuingSelectedCoinsStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.DequeuingSelectedCoins);
TxoRef[] toDequeue = selectedCoinViewModels.Where(x => x.CoinJoinInProgress).Select(x => x.Model.GetTxoRef()).ToArray();
if (toDequeue != null && toDequeue.Any())
{
@@ -270,7 +266,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
finally
{
- MainWindowViewModel.Instance.StatusBar.TryRemoveStatus(dequeuingSelectedCoinsStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryRemoveStatus(StatusBarStatus.DequeuingSelectedCoins);
}
var result = await Task.Run(() => Global.WalletService.BuildTransaction(Password, new[] { operation }, FeeTarget, allowUnconfirmed: true, allowedInputs: selectedCoinReferences));
@@ -291,18 +287,16 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
return;
}
- MainWindowViewModel.Instance.StatusBar.TryAddStatus(signingTransactionStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.SigningTransaction);
SmartTransaction signedTransaction = result.Transaction;
if (IsHardwareWallet && !result.Signed) // If hardware but still has a privkey then it's password, then meh.
{
- const string connectingToHardwareWalletStatusText = "Connecting to hardware wallet...";
- const string acquiringSignatureFromHardwareWalletStatusText = "Acquiring signature from hardware wallet...";
PSBT signedPsbt = null;
try
{
IsHardwareBusy = true;
- MainWindowViewModel.Instance.StatusBar.TryAddStatus(connectingToHardwareWalletStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.ConnectingToHardwareWallet);
// If we have no hardware wallet info then try refresh it. If we failed, then tha's a problem.
if (KeyManager.HardwareWalletInfo is null && !await TryRefreshHardwareWalletInfoAsync(KeyManager))
{
@@ -310,14 +304,14 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
return;
}
- MainWindowViewModel.Instance.StatusBar.TryAddStatus(acquiringSignatureFromHardwareWalletStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.AcquiringSignatureFromHardwareWallet);
signedPsbt = await HwiProcessManager.SignTxAsync(KeyManager.HardwareWalletInfo, result.Psbt);
}
catch (IOException ex) when (ex.Message.Contains("device not found", StringComparison.OrdinalIgnoreCase)
|| ex.Message.Contains("Invalid status 6f04", StringComparison.OrdinalIgnoreCase) // It comes when device asleep too.
|| ex.Message.Contains("Device is asleep", StringComparison.OrdinalIgnoreCase))
{
- MainWindowViewModel.Instance.StatusBar.TryAddStatus(connectingToHardwareWalletStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.ConnectingToHardwareWallet);
// The user may changed USB port. Try again with new enumeration.
if (!await TryRefreshHardwareWalletInfoAsync(KeyManager))
{
@@ -325,19 +319,19 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
return;
}
- MainWindowViewModel.Instance.StatusBar.TryAddStatus(acquiringSignatureFromHardwareWalletStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.AcquiringSignatureFromHardwareWallet);
signedPsbt = await HwiProcessManager.SignTxAsync(KeyManager.HardwareWalletInfo, result.Psbt);
}
finally
{
- MainWindowViewModel.Instance.StatusBar.TryRemoveStatus(connectingToHardwareWalletStatusText, acquiringSignatureFromHardwareWalletStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryRemoveStatus(StatusBarStatus.ConnectingToHardwareWallet, StatusBarStatus.AcquiringSignatureFromHardwareWallet);
IsHardwareBusy = false;
}
signedTransaction = signedPsbt.ExtractSmartTransaction(result.Transaction.Height);
}
- MainWindowViewModel.Instance.StatusBar.TryAddStatus(broadcastingTransactionStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.BroadcastingTransaction);
await Task.Run(async () => await Global.WalletService.SendTransactionAsync(signedTransaction));
TryResetInputsOnSuccess("Transaction is successfully sent!");
@@ -353,7 +347,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
finally
{
- MainWindowViewModel.Instance.StatusBar.TryRemoveStatus(buildingTransactionStatusText, signingTransactionStatusText, broadcastingTransactionStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryRemoveStatus(StatusBarStatus.BuildingTransaction, StatusBarStatus.SigningTransaction, StatusBarStatus.BroadcastingTransaction);
IsBusy = false;
}
},

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/TransactionBroadcasterViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/TransactionBroadcasterViewModel.cs
@@ -7,6 +7,7 @@ using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading.Tasks;
+using WalletWasabi.Gui.Models;
using WalletWasabi.Gui.ViewModels;
using WalletWasabi.Models;
@@ -101,7 +102,6 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
private async Task OnDoTransactionBroadcastAsync()
{
- const string broadcastingTransactionStatusText = "Broadcasting transaction...";
try
{
IsBusy = true;
@@ -124,7 +124,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
transaction = new SmartTransaction(Transaction.Parse(TransactionString, Global.Network ?? Network.Main), WalletWasabi.Models.Height.Unknown);
}
- MainWindowViewModel.Instance.StatusBar.TryAddStatus(broadcastingTransactionStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.BroadcastingTransaction);
await Task.Run(async () => await Global.WalletService.SendTransactionAsync(transaction));
SetSuccessMessage("Transaction is successfully sent!");
@@ -136,7 +136,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
finally
{
- MainWindowViewModel.Instance.StatusBar.TryRemoveStatus(broadcastingTransactionStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryRemoveStatus(StatusBarStatus.BroadcastingTransaction);
IsBusy = false;
ButtonText = "Broadcast Transaction";
}

ADD
WalletWasabi.Gui/Converters/StatusBarStatusStringConverter.cs
+using Avalonia.Data.Converters;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Text;
+using WalletWasabi.Gui.Models;
+
+namespace WalletWasabi.Gui.Converters
+{
+ public class StatusBarStatusStringConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is StatusBarStatus status)
+ {
+ return Convert(status);
+ }
+
+ throw new InvalidOperationException($"Given value isn't a {nameof(StatusBarStatus)} enum.");
+ }
+
+ public static string Convert(StatusBarStatus status)
+ {
+ switch (status)
+ {
+ case StatusBarStatus.Ready: return "Ready";
+ case StatusBarStatus.CriticalUpdate: return "THE BACKEND WAS UPGRADED WITH BREAKING CHANGES - PLEASE UPDATE YOUR SOFTWARE";
+ case StatusBarStatus.OptionalUpdate: return "New Version Is Available";
+ case StatusBarStatus.Connecting: return "Connecting...";
+ case StatusBarStatus.Synchronizing: return "Synchronizing...";
+ case StatusBarStatus.Loading: return "Loading...";
+ case StatusBarStatus.SettingUpHardwareWallet: return "Setting up hardware wallet...";
+ case StatusBarStatus.ConnectingToHardwareWallet: return "Connecting to hardware wallet...";
+ case StatusBarStatus.AcquiringXpubFromHardwareWallet: return "Acquiring xpub from hardware wallet...";
+ case StatusBarStatus.AcquiringSignatureFromHardwareWallet: return "Acquiring signature from hardware wallet...";
+ case StatusBarStatus.BuildingTransaction: return "Building transaction...";
+ case StatusBarStatus.SigningTransaction: return "Signing transaction...";
+ case StatusBarStatus.BroadcastingTransaction: return "Broadcasting transaction...";
+ case StatusBarStatus.DequeuingSelectedCoins: return "Dequeueing selected coins...";
+ default:
+ {
+ Logging.Logger.LogWarning<StatusBarStatusStringConverter>("Status don't have conversion string specified. Calling ToString() on enum.");
+ return status.ToString();
+ }
+ }
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotSupportedException();
+ }
+ }
+}

ADD
WalletWasabi.Gui/Models/StatusBarStatus.cs
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WalletWasabi.Gui.Models
+{
+ public enum StatusBarStatus
+ {
+ Ready,
+ CriticalUpdate,
+ OptionalUpdate,
+ Connecting,
+ Synchronizing,
+ Loading,
+ SettingUpHardwareWallet,
+ ConnectingToHardwareWallet,
+ AcquiringXpubFromHardwareWallet,
+ AcquiringSignatureFromHardwareWallet,
+ BuildingTransaction,
+ SigningTransaction,
+ BroadcastingTransaction,
+ DequeuingSelectedCoins
+ }
+}

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
@@ -388,25 +388,23 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
if (!selectedWallet.HardwareWalletInfo.Initialized)
{
- const string settingUpHardwareWalletStatusText = "Setting up hardware wallet...";
- const string connectingToHardwareWalletStatusText = "Connecting to hardware wallet...";
IEnumerable<HardwareWalletInfo> hwis;
try
{
IsHardwareBusy = true;
- MainWindowViewModel.Instance.StatusBar.TryAddStatus(settingUpHardwareWalletStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.SettingUpHardwareWallet);
if (!await HwiProcessManager.SetupAsync(selectedWallet.HardwareWalletInfo))
{
throw new Exception("Setup failed.");
}
- MainWindowViewModel.Instance.StatusBar.TryAddStatus(connectingToHardwareWalletStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.ConnectingToHardwareWallet);
hwis = await HwiProcessManager.EnumerateAsync();
}
finally
{
IsHardwareBusy = false;
- MainWindowViewModel.Instance.StatusBar.TryRemoveStatus(settingUpHardwareWalletStatusText, connectingToHardwareWalletStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryRemoveStatus(StatusBarStatus.SettingUpHardwareWallet, StatusBarStatus.ConnectingToHardwareWallet);
}
TryRefreshHardwareWallets(hwis);
@@ -420,16 +418,15 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
if (!TryFindWalletByMasterFingerprint(selectedWallet.HardwareWalletInfo.MasterFingerprint.Value, out walletName))
{
- const string acquiringXpubFromHardwareWalletStatusText = "Acquiring xpub from hardware wallet...";
ExtPubKey extPubKey;
try
{
- MainWindowViewModel.Instance.StatusBar.TryAddStatus(acquiringXpubFromHardwareWalletStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.AcquiringXpubFromHardwareWallet);
extPubKey = await HwiProcessManager.GetXpubAsync(selectedWallet.HardwareWalletInfo);
}
finally
{
- MainWindowViewModel.Instance.StatusBar.TryRemoveStatus(acquiringXpubFromHardwareWalletStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryRemoveStatus(StatusBarStatus.AcquiringXpubFromHardwareWallet);
}
Logger.LogInfo<LoadWalletViewModel>("Hardware wallet wasn't used previously on this computer. Creating new wallet file.");
@@ -529,11 +526,10 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
public async Task LoadWalletAsync()
{
- const string loadingStatusText = "Loading...";
try
{
IsBusy = true;
- MainWindowViewModel.Instance.StatusBar.TryAddStatus(loadingStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.Loading);
var keyManager = await LoadKeyManagerAsync(IsPasswordRequired, IsHardwareWallet);
if (keyManager is null)
@@ -570,7 +566,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
}
finally
{
- MainWindowViewModel.Instance.StatusBar.TryRemoveStatus(loadingStatusText);
+ MainWindowViewModel.Instance.StatusBar.TryRemoveStatus(StatusBarStatus.Loading);
IsBusy = false;
}
}

MODIFY
WalletWasabi.Gui/ViewModels/StatusBarViewModel.cs
WalletWasabi.Gui/ViewModels/StatusBarViewModel.cs
@@ -13,7 +13,9 @@ using System.Reactive.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
+using WalletWasabi.Gui.Converters;
using WalletWasabi.Gui.Dialogs;
+using WalletWasabi.Gui.Models;
using WalletWasabi.Gui.Tabs;
using WalletWasabi.Helpers;
using WalletWasabi.Models;
@@ -45,7 +47,8 @@ namespace WalletWasabi.Gui.ViewModels
private int _filtersLeft;
private int _blocksLeft;
private string _btcPrice;
- private string _status;
+ private StatusBarStatus _status;
+ private string _statusText;
public StatusBarViewModel(NodesCollection nodes, WasabiSynchronizer synchronizer, UpdateChecker updateChecker)
{
@@ -138,7 +141,12 @@ namespace WalletWasabi.Gui.ViewModels
RefreshStatus();
});
- this.WhenAnyValue(x => x.Status).Subscribe(async status =>
+ this.WhenAnyValue(x => x.Status).Subscribe(status =>
+ {
+ StatusText = StatusBarStatusStringConverter.Convert(status);
+ });
+
+ this.WhenAnyValue(x => x.StatusText).Subscribe(async status =>
{
if (status.EndsWith(".")) // Then do animation.
{
@@ -155,9 +163,9 @@ namespace WalletWasabi.Gui.ViewModels
if (nextAnimation != null)
{
await Task.Delay(1000);
- if (Status == status) // If still the same.
+ if (StatusText == status) // If still the same.
{
- Status = nextAnimation;
+ StatusText = nextAnimation;
}
}
}
@@ -261,12 +269,18 @@ namespace WalletWasabi.Gui.ViewModels
set => this.RaiseAndSetIfChanged(ref _btcPrice, value);
}
- public string Status
+ public StatusBarStatus Status
{
get => _status;
set => this.RaiseAndSetIfChanged(ref _status, value);
}
+ public string StatusText
+ {
+ get => _statusText;
+ set => this.RaiseAndSetIfChanged(ref _statusText, value);
+ }
+
private void OnResponseArrivedIsGenSocksServFail(bool isGenSocksServFail)
{
if (isGenSocksServFail)
@@ -309,19 +323,13 @@ namespace WalletWasabi.Gui.ViewModels
}
}
- private List<string> StatusQueue { get; } = new List<string>();
+ private List<StatusBarStatus> StatusQueue { get; } = new List<StatusBarStatus>();
private object StatusQueueLock { get; } = new object();
- public void TryAddStatus(string status)
+ public void TryAddStatus(StatusBarStatus status)
{
try
{
- status = Guard.Correct(status);
- if (status == "")
- {
- return;
- }
-
lock (StatusQueueLock)
{
// Make sure it's the last status.
@@ -336,20 +344,14 @@ namespace WalletWasabi.Gui.ViewModels
}
}
- public void TryRemoveStatus(params string[] statuses)
+ public void TryRemoveStatus(params StatusBarStatus[] statuses)
{
try
{
lock (StatusQueueLock)
{
- foreach (var statusRaw in statuses)
+ foreach (StatusBarStatus status in statuses)
{
- var status = Guard.Correct(statusRaw);
- if (status == "")
- {
- return;
- }
-
if (StatusQueue.Remove(status))
{
RefreshStatusNoLock();
@@ -367,7 +369,7 @@ namespace WalletWasabi.Gui.ViewModels
{
lock (StatusQueueLock)
{
- if (!SetPriorityStatus())
+ if (!TrySetPriorityStatus())
{
SetCustomStatusOrReady();
}
@@ -376,7 +378,7 @@ namespace WalletWasabi.Gui.ViewModels
private void RefreshStatusNoLock()
{
- if (!SetPriorityStatus())
+ if (!TrySetPriorityStatus())
{
SetCustomStatusOrReady();
}
@@ -384,34 +386,33 @@ namespace WalletWasabi.Gui.ViewModels
private void SetCustomStatusOrReady()
{
- var status = StatusQueue.LastOrDefault();
- if (status is null)
+ if (StatusQueue.Any())
{
- Status = "Ready";
+ Status = StatusQueue.Last();
}
else
{
- Status = status;
+ Status = StatusBarStatus.Ready;
}
}
- private bool SetPriorityStatus()
+ private bool TrySetPriorityStatus()
{
if (UpdateStatus == UpdateStatus.Critical)
{
- Status = "THE BACKEND WAS UPGRADED WITH BREAKING CHANGES - PLEASE UPDATE YOUR SOFTWARE";
+ Status = StatusBarStatus.CriticalUpdate;
}
else if (UpdateStatus == UpdateStatus.Optional)
{
- Status = "New Version Is Available";
+ Status = StatusBarStatus.OptionalUpdate;
}
else if (Tor == TorStatus.NotRunning || Backend != BackendStatus.Connected || Peers < 1)
{
- Status = "Connecting...";
+ Status = StatusBarStatus.Connecting;
}
else if (FiltersLeft != 0 || BlocksLeft != 0)
{
- Status = "Synchronizing...";
+ Status = StatusBarStatus.Synchronizing;
}
else
{

Use enumb for status instad of string