simplify percent calculation
MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/ClosedWalletViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/ClosedWalletViewModel.cs
@@ -15,15 +15,18 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets
{
public partial class ClosedWalletViewModel : WalletViewModelBase
{
+ private readonly Wallet _wallet;
+ private readonly SmartHeaderChain _smartHeaderChain;
+
[AutoNotify] private ObservableCollection<NavBarItemViewModel> _items;
[AutoNotify] private string _estimationText;
- [AutoNotify] private decimal _percent;
+ [AutoNotify] private uint _percent;
- private SmartHeaderChain _smartHeaderChain;
protected ClosedWalletViewModel(WalletManagerViewModel walletManagerViewModel, Wallet wallet)
: base(wallet)
{
+ _wallet = wallet;
_items = new ObservableCollection<NavBarItemViewModel>();
_smartHeaderChain = walletManagerViewModel.BitcoinStore.SmartHeaderChain;
_estimationText = "";
@@ -48,19 +51,12 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets
{
base.OnNavigatedTo(isInHistory, disposables);
- IDisposable? walletCheckingInterval = null;
- Observable.FromEventPattern<bool>(typeof(Wallet), nameof(Wallet.InitializingChanged))
- .ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(x =>
- {
- if (x.EventArgs && x.Sender is Wallet wallet)
- {
- walletCheckingInterval ??= Observable.Interval(TimeSpan.FromSeconds(1))
+ Observable.Interval(TimeSpan.FromSeconds(1))
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(_ =>
{
- var segwitActivationHeight = SmartHeader.GetStartingHeader(wallet.Network).Height;
- if (wallet.LastProcessedFilter?.Header?.Height is uint lastProcessedFilterHeight
+ var segwitActivationHeight = SmartHeader.GetStartingHeader(_wallet.Network).Height;
+ if (_wallet.LastProcessedFilter?.Header?.Height is uint lastProcessedFilterHeight
&& lastProcessedFilterHeight > segwitActivationHeight
&& _smartHeaderChain.TipHeight is uint tipHeight
&& tipHeight > segwitActivationHeight)
@@ -69,22 +65,14 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets
var processedFilters = lastProcessedFilterHeight - segwitActivationHeight;
var perc = allFilters == 0
? 100
- : ((decimal) processedFilters / allFilters * 100);
+ : (decimal)processedFilters / allFilters * 100;
- Percent = perc;
+ Percent = (uint)perc;
EstimationText = $"{Percent}% completed - 25 minutes remaining";
}
})
.DisposeWith(disposables);
}
- else
- {
- walletCheckingInterval?.Dispose();
- walletCheckingInterval = null;
- }
- })
- .DisposeWith(disposables);
- }
public static WalletViewModelBase Create(WalletManagerViewModel walletManager, Wallet wallet)
{

simplify percent calculation