remove more passing of global by ctor.
MODIFY
WalletWasabi.Gui/Controls/LockScreen/LockScreenViewModel.cs
WalletWasabi.Gui/Controls/LockScreen/LockScreenViewModel.cs
@@ -4,6 +4,7 @@ using System.Reactive.Disposables;
using WalletWasabi.Helpers;
using System.Reactive.Linq;
using WalletWasabi.Gui.ViewModels;
+using Splat;
namespace WalletWasabi.Gui.Controls.LockScreen
{
@@ -11,11 +12,8 @@ namespace WalletWasabi.Gui.Controls.LockScreen
{
private CompositeDisposable Disposables { get; }
- public Global Global { get; }
-
- public LockScreenViewModel(Global global)
+ public LockScreenViewModel()
{
- Global = Guard.NotNull(nameof(Global), global);
Disposables = new CompositeDisposable();
}
@@ -40,7 +38,9 @@ namespace WalletWasabi.Gui.Controls.LockScreen
public void Initialize()
{
- Global.UiConfig
+ var global = Locator.Current.GetService<Global>();
+
+ global.UiConfig
.WhenAnyValue(x => x.LockScreenActive)
.ObserveOn(RxApp.MainThreadScheduler)
.BindTo(this, y => y.IsLocked)
@@ -48,10 +48,10 @@ namespace WalletWasabi.Gui.Controls.LockScreen
this.WhenAnyValue(x => x.IsLocked)
.ObserveOn(RxApp.MainThreadScheduler)
- .BindTo(Global.UiConfig, y => y.LockScreenActive)
+ .BindTo(global.UiConfig, y => y.LockScreenActive)
.DisposeWith(Disposables);
- _pinHash = Global.UiConfig
+ _pinHash = global.UiConfig
.WhenAnyValue(x => x.LockScreenPinHash)
.ObserveOn(RxApp.MainThreadScheduler)
.Do(x => CheckLockScreenType(x))

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/CoinListViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/CoinListViewModel.cs
@@ -435,7 +435,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
RootList.RemoveMany(coinToRemove.Select(kp => kp.Value));
- var newCoinViewModels = coinToAdd.Select(c => new CoinViewModel(this, Global, c)).ToArray();
+ var newCoinViewModels = coinToAdd.Select(c => new CoinViewModel(this, c)).ToArray();
foreach (var cvm in newCoinViewModels)
{
SubscribeToCoinEvents(cvm);

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/CoinViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/CoinViewModel.cs
using NBitcoin;
using ReactiveUI;
+using Splat;
using System;
using System.Globalization;
using System.Linq;
@@ -31,16 +32,17 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
public ReactiveCommand<Unit, bool> ToggleDetails { get; }
public CoinListViewModel Owner { get; }
- public Global Global { get; set; }
+ private Global Global { get; }
public bool InCoinJoinContainer { get; }
public ReactiveCommand<Unit, Unit> DequeueCoin { get; }
- public CoinViewModel(CoinListViewModel owner, Global global, SmartCoin model)
+ public CoinViewModel(CoinListViewModel owner, SmartCoin model)
{
+ Global = Locator.Current.GetService<Global>();
+
Model = model;
Owner = owner;
- Global = global;
InCoinJoinContainer = owner.CoinListContainerType == CoinListContainerType.CoinJoinTabViewModel;
RefreshSmartCoinStatus();

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/PinPadViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/PinPadViewModel.cs
@@ -2,6 +2,7 @@ using Avalonia.Threading;
using AvalonStudio.Extensibility;
using AvalonStudio.Shell;
using ReactiveUI;
+using Splat;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -76,22 +77,26 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
return base.OnClose();
}
- public static async Task UnlockAsync(Global global)
+ public static async Task UnlockAsync()
{
+ var global = Locator.Current.GetService<Global>();
+
using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(3));
var client = new HwiClient(global.Network);
IEnumerable<HwiEnumerateEntry> hwiEntries = await client.EnumerateAsync(cts.Token);
foreach (var hwiEntry in hwiEntries.Where(x => x.NeedsPinSent is true))
{
- await UnlockAsync(global, hwiEntry);
+ await UnlockAsync(hwiEntry);
}
}
- public static async Task UnlockAsync(Global global, HwiEnumerateEntry hwiEntry)
+ public static async Task UnlockAsync(HwiEnumerateEntry hwiEntry)
{
// Make sure to select back the document that was selected.
var selectedDocument = IoC.Get<IShell>().SelectedDocument;
+ var global = Locator.Current.GetService<Global>();
+
try
{
using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(3));

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
@@ -385,7 +385,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
catch (HwiException)
{
- await PinPadViewModel.UnlockAsync(Global);
+ await PinPadViewModel.UnlockAsync();
signedPsbt = await client.SignTxAsync(KeyManager.MasterFingerprint.Value, result.Psbt, cts.Token);
}
signedTransaction = signedPsbt.ExtractSmartTransaction(result.Transaction);

MODIFY
WalletWasabi.Gui/Dialogs/CannotCloseDialogViewModel.cs
WalletWasabi.Gui/Dialogs/CannotCloseDialogViewModel.cs
using Avalonia.Threading;
using AvalonStudio.Extensibility.Dialogs;
using ReactiveUI;
+using Splat;
using System;
using System.Linq;
using System.Reactive;
@@ -36,7 +37,7 @@ namespace WalletWasabi.Gui.Dialogs
set => this.RaiseAndSetIfChanged(ref _warningMessage, value);
}
- private readonly Global Global;
+ private Global Global { get; }
public string OperationMessage
{
@@ -50,9 +51,9 @@ namespace WalletWasabi.Gui.Dialogs
//http://blog.stephencleary.com/2013/01/async-oop-2-constructors.html
public Task Initialization { get; private set; }
- public CannotCloseDialogViewModel(Global global) : base("", false, false)
+ public CannotCloseDialogViewModel() : base("", false, false)
{
- Global = global;
+ Global = Locator.Current.GetService<Global>();
OperationMessage = "Dequeuing coins...Please wait";
var canCancel = this.WhenAnyValue(x => x.IsBusy);
var canOk = this.WhenAnyValue(x => x.IsBusy, (isbusy) => !isbusy);

MODIFY
WalletWasabi.Gui/MainWindow.xaml.cs
WalletWasabi.Gui/MainWindow.xaml.cs
@@ -53,7 +53,7 @@ namespace WalletWasabi.Gui
Locator.CurrentMutable.RegisterConstant<INotificationManager>(notificationManager);
}
- public Global Global { get; }
+ private Global Global { get; }
private void InitializeComponent()
{
@@ -135,7 +135,7 @@ namespace WalletWasabi.Gui
if (!MainWindowViewModel.Instance.CanClose)
{
- var dialog = new CannotCloseDialogViewModel(Global);
+ var dialog = new CannotCloseDialogViewModel();
closeApplication = await MainWindowViewModel.Instance.ShowDialogAsync(dialog); // start the deque process with a dialog
}

MODIFY
WalletWasabi.Gui/Program.cs
WalletWasabi.Gui/Program.cs
@@ -73,7 +73,7 @@ namespace WalletWasabi.Gui
MainWindowViewModel.Instance = new MainWindowViewModel();
StatusBar = new StatusBarViewModel();
MainWindowViewModel.Instance.StatusBar = StatusBar;
- MainWindowViewModel.Instance.LockScreen = new LockScreenViewModel(Global);
+ MainWindowViewModel.Instance.LockScreen = new LockScreenViewModel();
await Global.InitializeNoWalletAsync();

MODIFY
WalletWasabi.Gui/Shell/Commands/SystemCommands.cs
WalletWasabi.Gui/Shell/Commands/SystemCommands.cs
@@ -3,6 +3,7 @@ using Avalonia.Controls.ApplicationLifetimes;
using AvalonStudio.Commands;
using AvalonStudio.Shell;
using ReactiveUI;
+using Splat;
using System;
using System.Composition;
using System.Reactive.Linq;
@@ -13,8 +14,6 @@ namespace WalletWasabi.Gui.Shell.Commands
{
internal class SystemCommands
{
- public Global Global { get; }
-
[DefaultKeyGesture("ALT+F4")]
[ExportCommandDefinition("File.Exit")]
public CommandDefinition ExitCommand { get; }
@@ -26,6 +25,8 @@ namespace WalletWasabi.Gui.Shell.Commands
[ImportingConstructor]
public SystemCommands(CommandIconService commandIconService)
{
+ var global = Locator.Current.GetService<Global>();
+
ExitCommand = new CommandDefinition(
"Exit",
commandIconService.GetCompletionKindImage("Exit"),
@@ -34,7 +35,7 @@ namespace WalletWasabi.Gui.Shell.Commands
LockScreenCommand = new CommandDefinition(
"Lock Screen",
commandIconService.GetCompletionKindImage("Lock"),
- ReactiveCommand.Create(() => { Global.UiConfig.LockScreenActive = true; }));
+ ReactiveCommand.Create(() => { global.UiConfig.LockScreenActive = true; }));
Observable
.Merge(ExitCommand.GetReactiveCommand().ThrownExceptions)

MODIFY
WalletWasabi.Gui/ViewModels/AddressViewModel.cs
WalletWasabi.Gui/ViewModels/AddressViewModel.cs
@@ -118,7 +118,7 @@ namespace WalletWasabi.Gui.ViewModels
}
catch (HwiException)
{
- await PinPadViewModel.UnlockAsync(Global);
+ await PinPadViewModel.UnlockAsync();
await client.DisplayAddressAsync(KeyManager.MasterFingerprint.Value, Model.FullKeyPath, cts.Token);
}
});

remove more passing of global by ctor.