Fix PinPadView Initialization
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/PinPadViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/PinPadViewModel.cs
@@ -9,10 +9,11 @@ using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Text;
+using WalletWasabi.Gui.ViewModels;
namespace WalletWasabi.Gui.Controls.WalletExplorer
{
- internal class PinPadViewModel : WalletActionViewModel
+ internal class PinPadViewModel : WasabiDocumentTabViewModel
{
private CompositeDisposable Disposables { get; set; }
private string _maskedPin;
@@ -32,12 +33,12 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
set => this.RaiseAndSetIfChanged(ref _maskedPin, value);
}
- public PinPadViewModel(WalletViewModel walletViewModel) : base("Pin Pad", walletViewModel)
+ public PinPadViewModel(Global global) : base(global, "Pin Pad")
{
SendPinCommand = ReactiveCommand.Create(() =>
{
DialogResult = true;
- Close();
+ OnClose();
},
this.WhenAny(x => x.MaskedPin, (maskedPin) => (!string.IsNullOrWhiteSpace(maskedPin.Value))));

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
@@ -423,7 +423,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
PinPadViewModel pinpad = IoC.Get<IShell>().Documents.OfType<PinPadViewModel>().FirstOrDefault();
if (pinpad is null)
{
- pinpad = new PinPadViewModel(null);
+ pinpad = new PinPadViewModel(Global);
IoC.Get<IShell>().AddOrSelectDocument(pinpad);
}
var result = await pinpad.ShowDialogAsync();

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/WalletActionViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/WalletActionViewModel.cs
@@ -12,9 +12,6 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
{
public class WalletActionViewModel : WasabiDocumentTabViewModel
{
- private string _warningMessage;
- private string _successMessage;
- private object _dialogResult;
public WalletViewModel Wallet { get; }
public WalletService WalletService => Wallet.WalletService;
@@ -26,98 +23,6 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
: base(walletViewModel.Global, title)
{
Wallet = walletViewModel;
- DoItCommand = ReactiveCommand.Create(DisplayActionTab);
- }
-
- public ReactiveCommand<Unit, Unit> DoItCommand { get; }
-
- public void DisplayActionTab()
- {
- IoC.Get<IShell>().AddOrSelectDocument(this);
- }
-
- public void Select()
- {
- IoC.Get<IShell>().Select(this);
- }
-
- public void Close()
- {
- OnClose();
- }
-
- public async Task<object> ShowDialogAsync()
- {
- DialogResult = null;
- DisplayActionTab();
-
- while (!IsClosed)
- {
- if (!IsSelected) // Prevent de-selection of tab.
- {
- Select();
- }
- await Task.Delay(100);
- }
- return DialogResult;
- }
-
- protected void SetWarningMessage(string message)
- {
- SuccessMessage = "";
- WarningMessage = message;
-
- if (string.IsNullOrWhiteSpace(message))
- {
- return;
- }
-
- Dispatcher.UIThread.PostLogException(async () =>
- {
- await Task.Delay(7000);
- if (WarningMessage == message)
- {
- WarningMessage = "";
- }
- });
- }
-
- public void SetSuccessMessage(string message)
- {
- SuccessMessage = message;
- WarningMessage = "";
-
- if (string.IsNullOrWhiteSpace(message))
- {
- return;
- }
-
- Dispatcher.UIThread.PostLogException(async () =>
- {
- await Task.Delay(7000);
- if (SuccessMessage == message)
- {
- SuccessMessage = "";
- }
- });
- }
-
- public string WarningMessage
- {
- get => _warningMessage;
- set => this.RaiseAndSetIfChanged(ref _warningMessage, value);
- }
-
- public string SuccessMessage
- {
- get => _successMessage;
- set => this.RaiseAndSetIfChanged(ref _successMessage, value);
- }
-
- public object DialogResult
- {
- get => _dialogResult;
- set => this.RaiseAndSetIfChanged(ref _dialogResult, value);
}
}
}

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/WalletViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/WalletViewModel.cs
@@ -18,7 +18,6 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
private ObservableCollection<WalletActionViewModel> _actions;
- private string _title;
private bool _isExpanded;
public bool IsExpanded
@@ -124,12 +123,6 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
public WalletService WalletService { get; }
- public override string Title
- {
- get => _title;
- set => this.RaiseAndSetIfChanged(ref _title, value);
- }
-
public ReactiveCommand<Unit, Unit> LurkingWifeModeCommand { get; }
public ObservableCollection<WalletActionViewModel> Actions

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
@@ -487,7 +487,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
PinPadViewModel pinpad = IoC.Get<IShell>().Documents.OfType<PinPadViewModel>().FirstOrDefault();
if (pinpad is null)
{
- pinpad = new PinPadViewModel(null);
+ pinpad = new PinPadViewModel(Global);
IoC.Get<IShell>().AddOrSelectDocument(pinpad);
}
var result = await pinpad.ShowDialogAsync();

MODIFY
WalletWasabi.Gui/ViewModels/WasabiDocumentTabViewModel.cs
WalletWasabi.Gui/ViewModels/WasabiDocumentTabViewModel.cs
+using Avalonia.Threading;
using AvalonStudio.Documents;
using AvalonStudio.Extensibility;
using AvalonStudio.Shell;
using Dock.Model;
using ReactiveUI;
using System;
+using System.Reactive;
using System.Threading.Tasks;
+using WalletWasabi.Helpers;
namespace WalletWasabi.Gui.ViewModels
{
public abstract class WasabiDocumentTabViewModel : ViewModelBase, IDocumentTabViewModel
{
+ private string _title;
+ private bool _isSelected;
+ private bool _isClosed;
+ private string _warningMessage;
+ private string _successMessage;
+ private object _dialogResult;
+
public WasabiDocumentTabViewModel(Global global, string title)
{
Title = title;
- Global = global ?? throw new ArgumentNullException(nameof(global));
- }
-
- public WasabiDocumentTabViewModel(Global global)
- {
- Global = global ?? throw new ArgumentNullException(nameof(global));
+ Global = Guard.NotNull(nameof(global), global);
+ DoItCommand = ReactiveCommand.Create(DisplayActionTab);
}
public Global Global { get; }
public Guid Id { get; set; } = Guid.NewGuid();
- public virtual string Title { get; set; }
public object Context { get; set; }
public double Width { get; set; }
public double Height { get; set; }
public IView Parent { get; set; }
- private bool _isSelected;
- private bool _isClosed;
+
+ public string Title
+ {
+ get => _title;
+ set => this.RaiseAndSetIfChanged(ref _title, value);
+ }
public bool IsSelected
{
@@ -43,6 +52,24 @@ namespace WalletWasabi.Gui.ViewModels
set => this.RaiseAndSetIfChanged(ref _isClosed, value);
}
+ public string WarningMessage
+ {
+ get => _warningMessage;
+ set => this.RaiseAndSetIfChanged(ref _warningMessage, value);
+ }
+
+ public string SuccessMessage
+ {
+ get => _successMessage;
+ set => this.RaiseAndSetIfChanged(ref _successMessage, value);
+ }
+
+ public object DialogResult
+ {
+ get => _dialogResult;
+ set => this.RaiseAndSetIfChanged(ref _dialogResult, value);
+ }
+
public bool IsDirty { get; set; }
public virtual void OnSelected()
@@ -67,5 +94,73 @@ namespace WalletWasabi.Gui.ViewModels
IsClosed = true;
return true;
}
+
+ public void DisplayActionTab()
+ {
+ IoC.Get<IShell>().AddOrSelectDocument(this);
+ }
+
+ public ReactiveCommand<Unit, Unit> DoItCommand { get; }
+
+ public void Select()
+ {
+ IoC.Get<IShell>().Select(this);
+ }
+
+ public async Task<object> ShowDialogAsync()
+ {
+ DialogResult = null;
+ DisplayActionTab();
+
+ while (!IsClosed)
+ {
+ if (!IsSelected) // Prevent de-selection of tab.
+ {
+ Select();
+ }
+ await Task.Delay(100);
+ }
+ return DialogResult;
+ }
+
+ protected void SetWarningMessage(string message)
+ {
+ SuccessMessage = "";
+ WarningMessage = message;
+
+ if (string.IsNullOrWhiteSpace(message))
+ {
+ return;
+ }
+
+ Dispatcher.UIThread.PostLogException(async () =>
+ {
+ await Task.Delay(7000);
+ if (WarningMessage == message)
+ {
+ WarningMessage = "";
+ }
+ });
+ }
+
+ public void SetSuccessMessage(string message)
+ {
+ SuccessMessage = message;
+ WarningMessage = "";
+
+ if (string.IsNullOrWhiteSpace(message))
+ {
+ return;
+ }
+
+ Dispatcher.UIThread.PostLogException(async () =>
+ {
+ await Task.Delay(7000);
+ if (SuccessMessage == message)
+ {
+ SuccessMessage = "";
+ }
+ });
+ }
}
}

Fix PinPadView Initialization