CodeFactor order fix
MODIFY
WalletWasabi.Gui/Suggestions/SuggestLabelViewModel.cs
WalletWasabi.Gui/Suggestions/SuggestLabelViewModel.cs
@@ -15,7 +15,6 @@ namespace WalletWasabi.Gui.Suggestions
private ObservableCollection<SuggestionViewModel> _suggestions;
private int _caretIndex;
private string _label;
- private WalletService WalletService { get; }
public SuggestLabelViewModel(WalletService walletService)
{
@@ -28,13 +27,6 @@ namespace WalletWasabi.Gui.Suggestions
WalletService = walletService;
}
- public void Reset()
- {
- Suggestions = new ObservableCollection<SuggestionViewModel>();
-
- Label = "";
- }
-
public int CaretIndex
{
get => _caretIndex;
@@ -53,6 +45,33 @@ namespace WalletWasabi.Gui.Suggestions
set => this.RaiseAndSetIfChanged(ref _suggestions, value);
}
+ private WalletService WalletService { get; }
+
+ public void Reset()
+ {
+ Suggestions = new ObservableCollection<SuggestionViewModel>();
+
+ Label = "";
+ }
+
+ public void OnAddWord(string word)
+ {
+ var words = Label.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();
+ if (words.Length == 0)
+ {
+ Label = word + ", ";
+ }
+ else
+ {
+ words[^1] = word;
+ Label = string.Join(", ", words) + ", ";
+ }
+
+ CaretIndex = Label.Length;
+
+ Suggestions.Clear();
+ }
+
private void UpdateSuggestions(string words)
{
if (string.IsNullOrWhiteSpace(words))
@@ -82,23 +101,5 @@ namespace WalletWasabi.Gui.Suggestions
Suggestions.Add(new SuggestionViewModel(suggestion, OnAddWord));
}
}
-
- public void OnAddWord(string word)
- {
- var words = Label.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();
- if (words.Length == 0)
- {
- Label = word + ", ";
- }
- else
- {
- words[^1] = word;
- Label = string.Join(", ", words) + ", ";
- }
-
- CaretIndex = Label.Length;
-
- Suggestions.Clear();
- }
}
}

MODIFY
WalletWasabi.Gui/Suggestions/SuggestionBehavior.cs
WalletWasabi.Gui/Suggestions/SuggestionBehavior.cs
@@ -13,8 +13,6 @@ namespace WalletWasabi.Gui.Suggestions
{
public class SuggestionBehavior : Behavior<TextBox>
{
- private CompositeDisposable Disposables { get; set; }
-
public static readonly AvaloniaProperty<IEnumerable<SuggestionViewModel>> SuggestionItemsProperty =
AvaloniaProperty.Register<SuggestionBehavior, IEnumerable<SuggestionViewModel>>(nameof(SuggestionItems), defaultBindingMode: BindingMode.TwoWay);
@@ -24,6 +22,8 @@ namespace WalletWasabi.Gui.Suggestions
set => SetValue(SuggestionItemsProperty, value);
}
+ private CompositeDisposable Disposables { get; set; }
+
protected override void OnAttached()
{
Disposables = new CompositeDisposable();

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/LoadWallets/LoadWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/LoadWallets/LoadWalletViewModel.cs
@@ -51,18 +51,6 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
private string _loadButtonText;
private bool _isHwWalletSearchTextVisible;
- public bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
-
- private WalletManagerViewModel Owner { get; }
-
- private Global Global { get; }
-
- public LoadWalletType LoadWalletType { get; }
-
- public bool IsPasswordRequired => LoadWalletType == LoadWalletType.Password;
- public bool IsHardwareWallet => LoadWalletType == LoadWalletType.Hardware;
- public bool IsDesktopWallet => LoadWalletType == LoadWalletType.Desktop;
-
public LoadWalletViewModel(WalletManagerViewModel owner, LoadWalletType loadWalletType)
: base(loadWalletType == LoadWalletType.Password ? "Test Password" : loadWalletType == LoadWalletType.Desktop ? "Load Wallet" : "Hardware Wallet")
{
@@ -166,6 +154,12 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
SetLoadButtonText();
}
+ public bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
+
+ public LoadWalletType LoadWalletType { get; }
+ public bool IsPasswordRequired => LoadWalletType == LoadWalletType.Password;
+ public bool IsHardwareWallet => LoadWalletType == LoadWalletType.Hardware;
+ public bool IsDesktopWallet => LoadWalletType == LoadWalletType.Desktop;
public string UDevRulesLink => "https://github.com/bitcoin-core/HWI/tree/master/hwilib/udev";
public bool IsHwWalletSearchTextVisible
@@ -180,8 +174,6 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
set => this.RaiseAndSetIfChanged(ref _wallets, value);
}
- public ErrorDescriptors ValidatePassword() => PasswordHelper.ValidatePassword(Password);
-
[ValidateMethod(nameof(ValidatePassword))]
public string Password
{
@@ -207,39 +199,6 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
set => this.RaiseAndSetIfChanged(ref _isWalletOpened, value);
}
- public void SetLoadButtonText()
- {
- var text = "Load Wallet";
- if (IsHardwareBusy)
- {
- text = "Waiting for Hardware Wallet...";
- }
- else if (IsBusy)
- {
- text = "Loading...";
- }
- else
- {
- // If the hardware wallet was not initialized, then make the button say Setup, not Load.
- // If pin is needed, then make the button say Send Pin instead.
-
- if (SelectedWallet?.HardwareWalletInfo != null)
- {
- if (!SelectedWallet.HardwareWalletInfo.IsInitialized())
- {
- text = "Setup Wallet";
- }
-
- if (SelectedWallet.HardwareWalletInfo.NeedsPinSent is true)
- {
- text = "Send PIN";
- }
- }
- }
-
- LoadButtonText = text;
- }
-
public string LoadButtonText
{
get => _loadButtonText;
@@ -282,6 +241,51 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
}
}
+ public ReactiveCommand<Unit, Unit> LoadCommand { get; }
+ public ReactiveCommand<Unit, KeyManager> TestPasswordCommand { get; }
+ public ReactiveCommand<Unit, Unit> ImportColdcardCommand { get; set; }
+ public ReactiveCommand<Unit, Unit> EnumerateHardwareWalletsCommand { get; set; }
+ public ReactiveCommand<string, Unit> OpenBrowserCommand { get; }
+ public ReactiveCommand<Unit, Unit> OpenFolderCommand { get; }
+ private WalletManagerViewModel Owner { get; }
+
+ private Global Global { get; }
+
+ public ErrorDescriptors ValidatePassword() => PasswordHelper.ValidatePassword(Password);
+
+ public void SetLoadButtonText()
+ {
+ var text = "Load Wallet";
+ if (IsHardwareBusy)
+ {
+ text = "Waiting for Hardware Wallet...";
+ }
+ else if (IsBusy)
+ {
+ text = "Loading...";
+ }
+ else
+ {
+ // If the hardware wallet was not initialized, then make the button say Setup, not Load.
+ // If pin is needed, then make the button say Send Pin instead.
+
+ if (SelectedWallet?.HardwareWalletInfo != null)
+ {
+ if (!SelectedWallet.HardwareWalletInfo.IsInitialized())
+ {
+ text = "Setup Wallet";
+ }
+
+ if (SelectedWallet.HardwareWalletInfo.NeedsPinSent is true)
+ {
+ text = "Send PIN";
+ }
+ }
+ }
+
+ LoadButtonText = text;
+ }
+
public override void OnCategorySelected()
{
if (IsHardwareWallet)
@@ -318,50 +322,6 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
}
}
- private bool TrySetWalletStates()
- {
- try
- {
- if (SelectedWallet is null)
- {
- SelectedWallet = Wallets.FirstOrDefault();
- }
-
- IsWalletSelected = SelectedWallet != null;
- CanTestPassword = IsWalletSelected;
-
- if (Global.WalletManager.AnyWallet())
- {
- IsWalletOpened = true;
- CanLoadWallet = false;
- }
- else
- {
- IsWalletOpened = false;
-
- // If not busy loading.
- // And wallet is selected.
- // And no wallet is opened.
- CanLoadWallet = !IsBusy && IsWalletSelected;
- }
-
- SetLoadButtonText();
- return true;
- }
- catch (Exception ex)
- {
- Logger.LogWarning(ex);
- }
-
- return false;
- }
-
- public ReactiveCommand<Unit, Unit> LoadCommand { get; }
- public ReactiveCommand<Unit, KeyManager> TestPasswordCommand { get; }
- public ReactiveCommand<Unit, Unit> ImportColdcardCommand { get; set; }
- public ReactiveCommand<Unit, Unit> EnumerateHardwareWalletsCommand { get; set; }
- public ReactiveCommand<string, Unit> OpenBrowserCommand { get; }
-
public async Task<KeyManager> LoadKeyManagerAsync(bool requirePassword, bool isHardwareWallet)
{
try
@@ -555,6 +515,100 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
}
}
+ public async Task LoadWalletAsync()
+ {
+ try
+ {
+ IsBusy = true;
+
+ var keyManager = await LoadKeyManagerAsync(IsPasswordRequired, IsHardwareWallet);
+ if (keyManager is null)
+ {
+ return;
+ }
+
+ try
+ {
+ bool isSuccessful = await Global.WaitForInitializationCompletedAsync(CancellationToken.None);
+ if (!isSuccessful)
+ {
+ return;
+ }
+
+ var walletService = await Task.Run(async () => await Global.WalletManager.CreateAndStartWalletServiceAsync(keyManager));
+ // Successfully initialized.
+ Owner.OnClose();
+ // Open Wallet Explorer tabs
+ if (walletService.Coins.Any())
+ {
+ // If already have coins then open the last active tab first.
+ IoC.Get<WalletExplorerViewModel>().OpenWallet(walletService, receiveDominant: false);
+ }
+ else // Else open with Receive tab first.
+ {
+ IoC.Get<WalletExplorerViewModel>().OpenWallet(walletService, receiveDominant: true);
+ }
+ }
+ catch (Exception ex)
+ {
+ // Initialization failed.
+ NotificationHelpers.Error(ex.ToUserFriendlyString());
+ if (!(ex is OperationCanceledException))
+ {
+ Logger.LogError(ex);
+ }
+ }
+ }
+ finally
+ {
+ IsBusy = false;
+ }
+ }
+
+ public void OpenWalletsFolder()
+ {
+ var path = Global.WalletsDir;
+ IoHelpers.OpenFolderInFileExplorer(path);
+ }
+
+ private bool TrySetWalletStates()
+ {
+ try
+ {
+ if (SelectedWallet is null)
+ {
+ SelectedWallet = Wallets.FirstOrDefault();
+ }
+
+ IsWalletSelected = SelectedWallet != null;
+ CanTestPassword = IsWalletSelected;
+
+ if (Global.WalletManager.AnyWallet())
+ {
+ IsWalletOpened = true;
+ CanLoadWallet = false;
+ }
+ else
+ {
+ IsWalletOpened = false;
+
+ // If not busy loading.
+ // And wallet is selected.
+ // And no wallet is opened.
+ CanLoadWallet = !IsBusy && IsWalletSelected;
+ }
+
+ SetLoadButtonText();
+ return true;
+ }
+ catch (Exception ex)
+ {
+ Logger.LogWarning(ex);
+ }
+
+ return false;
+ }
+
private async Task EnumerateHardwareWalletsAsync()
{
var cts = new CancellationTokenSource(TimeSpan.FromMinutes(3));
@@ -616,63 +670,5 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
return false;
}
-
- public async Task LoadWalletAsync()
- {
- try
- {
- IsBusy = true;
-
- var keyManager = await LoadKeyManagerAsync(IsPasswordRequired, IsHardwareWallet);
- if (keyManager is null)
- {
- return;
- }
-
- try
- {
- bool isSuccessful = await Global.WaitForInitializationCompletedAsync(CancellationToken.None);
- if (!isSuccessful)
- {
- return;
- }
-
- var walletService = await Task.Run(async () => await Global.WalletManager.CreateAndStartWalletServiceAsync(keyManager));
- // Successfully initialized.
- Owner.OnClose();
- // Open Wallet Explorer tabs
- if (walletService.Coins.Any())
- {
- // If already have coins then open the last active tab first.
- IoC.Get<WalletExplorerViewModel>().OpenWallet(walletService, receiveDominant: false);
- }
- else // Else open with Receive tab first.
- {
- IoC.Get<WalletExplorerViewModel>().OpenWallet(walletService, receiveDominant: true);
- }
- }
- catch (Exception ex)
- {
- // Initialization failed.
- NotificationHelpers.Error(ex.ToUserFriendlyString());
- if (!(ex is OperationCanceledException))
- {
- Logger.LogError(ex);
- }
- }
- }
- finally
- {
- IsBusy = false;
- }
- }
-
- public ReactiveCommand<Unit, Unit> OpenFolderCommand { get; }
-
- public void OpenWalletsFolder()
- {
- var path = Global.WalletsDir;
- IoHelpers.OpenFolderInFileExplorer(path);
- }
}
}

CodeFactor order fix