remove logic from ClosedWalletViewModel
MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/ClosedWalletViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/ClosedWalletViewModel.cs
-using System;
-using System.Diagnostics;
using System.Reactive.Disposables;
-using System.Reactive.Linq;
using ReactiveUI;
-using WalletWasabi.Blockchain.Blocks;
-using WalletWasabi.Fluent.Helpers;
using WalletWasabi.Fluent.ViewModels.Login;
using WalletWasabi.Fluent.ViewModels.Navigation;
using WalletWasabi.Wallets;
namespace WalletWasabi.Fluent.ViewModels.Wallets
{
- public partial class ClosedWalletViewModel : WalletViewModelBase
+ public class ClosedWalletViewModel : WalletViewModelBase
{
- private readonly SmartHeaderChain _smartHeaderChain;
-
- private Stopwatch? _stopwatch;
- private uint? _startingFilterIndex;
-
protected ClosedWalletViewModel(WalletManagerViewModel walletManagerViewModel, Wallet wallet)
: base(wallet)
{
- _smartHeaderChain = Services.BitcoinStore.SmartHeaderChain;
-
+ Loading = new LoadingViewModel();
OpenCommand = ReactiveCommand.Create(() => OnOpen(walletManagerViewModel));
}
- public LoadingViewModel Loading { get; } = new();
+ public LoadingViewModel Loading { get; }
protected override void OnNavigatedTo(bool isInHistory, CompositeDisposable disposables)
{
base.OnNavigatedTo(isInHistory, disposables);
- _stopwatch ??= Stopwatch.StartNew();
-
- Observable.Interval(TimeSpan.FromSeconds(1))
- .ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(_ =>
- {
- var segwitActivationHeight = SmartHeader.GetStartingHeader(Wallet.Network).Height;
- if (Wallet.LastProcessedFilter?.Header?.Height is { } lastProcessedFilterHeight
- && lastProcessedFilterHeight > segwitActivationHeight
- && _smartHeaderChain.TipHeight is { } tipHeight
- && tipHeight > segwitActivationHeight)
- {
- var allFilters = tipHeight - segwitActivationHeight;
- var processedFilters = lastProcessedFilterHeight - segwitActivationHeight;
-
- UpdateStatus(allFilters, processedFilters, _stopwatch.ElapsedMilliseconds);
- }
- })
- .DisposeWith(disposables);
- }
-
- private void UpdateStatus(uint allFilters, uint processedFilters, double elapsedMilliseconds)
- {
- var percent = (decimal)processedFilters / allFilters * 100;
- _startingFilterIndex ??= processedFilters; // Store the filter index we started on. It is needed for better remaining time calculation.
- var realProcessedFilters = processedFilters - _startingFilterIndex.Value;
- var remainingFilterCount = allFilters - processedFilters;
-
- var tempPercent = (uint)Math.Round(percent);
-
- if (tempPercent == 0 || realProcessedFilters == 0 || remainingFilterCount == 0)
- {
- return;
- }
-
- Loading.Percent = tempPercent;
- var percentText = $"{Loading.Percent}% completed";
-
- var remainingMilliseconds = elapsedMilliseconds / realProcessedFilters * remainingFilterCount;
- var userFriendlyTime = TextHelpers.TimeSpanToFriendlyString(TimeSpan.FromMilliseconds(remainingMilliseconds));
- var remainingTimeText = string.IsNullOrEmpty(userFriendlyTime) ? "" : $"- {userFriendlyTime} remaining";
-
- Loading.StatusText = $"{percentText} {remainingTimeText}";
+ Loading.Activate(disposables);
}
private void OnOpen(WalletManagerViewModel walletManagerViewModel)

remove logic from ClosedWalletViewModel