public SettingsViewModel(Global global) : base(global, "Settings")
        {
            Autocopy  = Global.UiConfig?.Autocopy is true;
            CustomFee = Global.UiConfig?.IsCustomFee is true;

            // Use global config's data as default filler until the real data is filled out by the loading of the config onopen.
            var globalConfig = Global.Config;

            Network            = globalConfig.Network;
            TorSocks5EndPoint  = globalConfig.TorSocks5EndPoint.ToString(-1);
            UseTor             = globalConfig.UseTor;
            SomePrivacyLevel   = globalConfig.PrivacyLevelSome.ToString();
            FinePrivacyLevel   = globalConfig.PrivacyLevelFine.ToString();
            StrongPrivacyLevel = globalConfig.PrivacyLevelStrong.ToString();
            DustThreshold      = globalConfig.DustThreshold.ToString();
            BitcoinP2pEndPoint = globalConfig.GetP2PEndpoint().ToString(defaultPort: -1);
            IsModified         = false;

            this.WhenAnyValue(
                x => x.Network,
                x => x.UseTor)
            .ObserveOn(RxApp.TaskpoolScheduler)
            .Subscribe(_ => Save());

            this.WhenAnyValue(x => x.Autocopy)
            .ObserveOn(RxApp.TaskpoolScheduler)
            .Subscribe(x => Global.UiConfig.Autocopy = x);

            this.WhenAnyValue(x => x.CustomFee)
            .ObserveOn(RxApp.TaskpoolScheduler)
            .Subscribe(x => Global.UiConfig.IsCustomFee = x);

            OpenConfigFileCommand = ReactiveCommand.Create(OpenConfigFile);

            LurkingWifeModeCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                Global.UiConfig.LurkingWifeMode = !LurkingWifeMode;
                await Global.UiConfig.ToFileAsync();
            });

            SetClearPinCommand = ReactiveCommand.Create(() =>
            {
                var pinBoxText = PinBoxText?.Trim();
                if (string.IsNullOrWhiteSpace(pinBoxText))
                {
                    PinWarningMessage = "Please provide PIN.";
                    return;
                }

                if (pinBoxText.Length > 10)
                {
                    PinWarningMessage = "PIN too long.";
                    return;
                }

                if (pinBoxText.Any(x => !char.IsDigit(x)))
                {
                    PinWarningMessage = "Invalid PIN.";
                    return;
                }

                var uiConfigPinHash = Global.UiConfig.LockScreenPinHash;
                var enteredPinHash  = HashHelpers.GenerateSha256Hash(pinBoxText);

                if (IsPinSet)
                {
                    if (uiConfigPinHash != enteredPinHash)
                    {
                        PinWarningMessage = "Wrong PIN.";
                        PinBoxText        = string.Empty;
                        return;
                    }

                    Global.UiConfig.LockScreenPinHash = string.Empty;
                }
                else
                {
                    Global.UiConfig.LockScreenPinHash = enteredPinHash;
                }

                PinBoxText        = string.Empty;
                PinWarningMessage = string.Empty;
            });

            TextBoxLostFocusCommand = ReactiveCommand.Create(Save);
        }
        public SettingsViewModel(Global global) : base(global, "Settings")
        {
            var config = new Config(Global.Config.FilePath);

            Autocopy = Global.UiConfig?.Autocopy is true;

            this.WhenAnyValue(x => x.Network)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(async _ =>
            {
                await config.LoadFileAsync();

                var configBitcoinP2pEndPoint = Network == Network.Main
                                                ? config.MainNetBitcoinP2pEndPoint
                                                : (Network == Network.TestNet
                                                        ? config.TestNetBitcoinP2pEndPoint
                                                        : config.RegTestBitcoinP2pEndPoint);

                BitcoinP2pEndPoint = configBitcoinP2pEndPoint.ToString(defaultPort: -1);
            });

            this.WhenAnyValue(
                x => x.Network,
                x => x.UseTor)
            .ObserveOn(RxApp.TaskpoolScheduler)
            .Subscribe(x => Save());

            this.WhenAnyValue(x => x.Autocopy)
            .Subscribe(async x =>
            {
                Global.UiConfig.Autocopy = x;
                await Global.UiConfig.ToFileAsync();
            });

            Dispatcher.UIThread.PostLogException(async() =>
            {
                await config.LoadFileAsync();

                Network           = config.Network;
                TorSocks5EndPoint = config.TorSocks5EndPoint.ToString(-1);
                UseTor            = config.UseTor.Value;

                SomePrivacyLevel   = config.PrivacyLevelSome.ToString();
                FinePrivacyLevel   = config.PrivacyLevelFine.ToString();
                StrongPrivacyLevel = config.PrivacyLevelStrong.ToString();

                DustThreshold = config.DustThreshold.ToString();

                IsModified = await Global.Config.CheckFileChangeAsync();
            });

            OpenConfigFileCommand = ReactiveCommand.Create(OpenConfigFile);

            LurkingWifeModeCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                Global.UiConfig.LurkingWifeMode = !LurkingWifeMode;
                await Global.UiConfig.ToFileAsync();
            });

            SetClearPinCommand = ReactiveCommand.Create(() =>
            {
                var pinBoxText = PinBoxText?.Trim();
                if (string.IsNullOrWhiteSpace(pinBoxText))
                {
                    PinWarningMessage = "Please provide PIN.";
                    return;
                }

                if (pinBoxText.Length > 10)
                {
                    PinWarningMessage = "PIN too long.";
                    return;
                }

                if (pinBoxText.Any(x => !char.IsDigit(x)))
                {
                    PinWarningMessage = "Invalid PIN.";
                    return;
                }

                var uiConfigPinHash = Global.UiConfig.LockScreenPinHash;
                var enteredPinHash  = HashHelpers.GenerateSha256Hash(pinBoxText);

                if (IsPinSet)
                {
                    if (uiConfigPinHash != enteredPinHash)
                    {
                        PinWarningMessage = "Wrong PIN.";
                        PinBoxText        = string.Empty;
                        return;
                    }

                    Global.UiConfig.LockScreenPinHash = string.Empty;
                }
                else
                {
                    Global.UiConfig.LockScreenPinHash = enteredPinHash;
                }

                PinBoxText        = string.Empty;
                PinWarningMessage = string.Empty;
            });

            TextBoxLostFocusCommand = ReactiveCommand.Create(Save);
        }