making walletservice observable
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -6,11 +6,13 @@ using NBitcoin.Protocol.Behaviors;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
+using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
+using System.Reactive.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
@@ -66,7 +68,18 @@ namespace WalletWasabi.Gui
public static NodesGroup Nodes { get; private set; }
public static WasabiSynchronizer Synchronizer { get; private set; }
public static CcjClient ChaumianClient { get; private set; }
- public static WalletService WalletService { get; private set; }
+
+ public static WalletService WalletService
+ {
+ get => WalletServiceField;
+ private set
+ {
+ if (WalletServiceField == value) return;
+ WalletServiceField = value;
+ NotifyStaticPropertyChanged(nameof(WalletService));
+ }
+ }
+
public static Node RegTestMemPoolServingNode { get; private set; }
public static UpdateChecker UpdateChecker { get; private set; }
public static TorProcessManager TorManager { get; private set; }
@@ -74,6 +87,25 @@ namespace WalletWasabi.Gui
public static Config Config { get; private set; }
public static UiConfig UiConfig { get; private set; }
+ public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;
+
+ private static void NotifyStaticPropertyChanged(string propertyName)
+ {
+ StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(propertyName));
+ }
+
+ public static IObservable<PropertyChangedEventArgs> WhenPropertyChanged
+ {
+ get
+ {
+ return Observable
+ .FromEventPattern<PropertyChangedEventArgs>(
+ h => StaticPropertyChanged += h,
+ h => StaticPropertyChanged -= h)
+ .Select(x => x.EventArgs);
+ }
+ }
+
public static void InitializeConfig(Config config)
{
Config = Guard.NotNull(nameof(config), config);
@@ -255,6 +287,7 @@ namespace WalletWasabi.Gui
}
private static CancellationTokenSource CancelWalletServiceInitialization = null;
+ private static WalletService WalletServiceField;
public static async Task InitializeWalletServiceAsync(KeyManager keyManager)
{

MODIFY
WalletWasabi.Gui/Shell/Commands/ToolCommands.cs
WalletWasabi.Gui/Shell/Commands/ToolCommands.cs
@@ -9,6 +9,9 @@ using System.Linq;
using WalletWasabi.Gui.Tabs.WalletManager;
using WalletWasabi.Gui.Tabs;
using WalletWasabi.Gui.Tabs.EncryptionManager;
+using System.Reactive.Linq;
+using System.ComponentModel;
+using WalletWasabi.Services;
namespace WalletWasabi.Gui.Shell.Commands
{
@@ -22,10 +25,15 @@ namespace WalletWasabi.Gui.Shell.Commands
commandIconService.GetCompletionKindImage("WalletManager"),
ReactiveCommand.Create(OnWalletManager));
+ var isWalletLoaded = Global.WhenPropertyChanged
+ .Where(x => x.PropertyName == nameof(WalletService)) //looking for the wallet is loaded
+ .Select(ws => ws != null) //if it is not null -> wallet is loaded
+ .ObserveOn(RxApp.MainThreadScheduler); //syncronize with the UI
+
EncryptionManagerCommand = new CommandDefinition(
"Encryption Manager",
commandIconService.GetCompletionKindImage("EncryptionManager"),
- ReactiveCommand.Create(OnEncryptionManager));
+ ReactiveCommand.Create(OnEncryptionManager, isWalletLoaded));
SettingsCommand = new CommandDefinition(
"Settings",

making walletservice observable