remaining text, cancel token
MODIFY
WalletWasabi.Fluent/ViewModels/Login/PasswordFinder/SearchPasswordViewModel.cs
WalletWasabi.Fluent/ViewModels/Login/PasswordFinder/SearchPasswordViewModel.cs
using System;
+using System.Linq;
+using System.Threading;
using System.Threading.Tasks;
+using ReactiveUI;
using WalletWasabi.Fluent.ViewModels.Navigation;
using WalletWasabi.Wallets.PasswordFinder;
@@ -14,32 +17,47 @@ namespace WalletWasabi.Fluent.ViewModels.Login.PasswordFinder
[AutoNotify] private string _hourText;
[AutoNotify] private string _minText;
[AutoNotify] private string _secText;
-
+ [AutoNotify] private bool _remainingTimeReceived;
public SearchPasswordViewModel(PasswordFinderOptions options)
{
Title = "Password Finder";
+ _hourText = "";
+ _minText = "";
+ _secText = "";
+ CancelToken = new CancellationTokenSource();
Task.Run(() =>
{
- PasswordFinderHelper.TryFind(options, out var foundPassword, SetStatus);
+ PasswordFinderHelper.TryFind(options, out var foundPassword, SetStatus, CancelToken.Token);
Navigate().To(new PasswordFinderResultViewModel(foundPassword));
});
+
+ CancelCommand = ReactiveCommand.Create(() =>
+ {
+ CancelToken.Cancel();
+ Navigate().Clear();
+ });
}
+ private CancellationTokenSource CancelToken { get; }
+
private void SetStatus(int percentage, TimeSpan remainingTime)
{
+ RemainingTimeReceived = true;
Percentage = percentage;
RemainingHour = remainingTime.Hours;
RemainingMin = remainingTime.Minutes;
RemainingSec = remainingTime.Seconds;
- HourText = $" hour{AddSIfPlural(RemainingHour)} ";
- MinText = $" minute{AddSIfPlural(RemainingMin)} ";
+ HourText = $" hour{AddSIfPlural(RemainingHour)}{CloseSentenceIfZero(RemainingMin,RemainingSec)}";
+ MinText = $" minute{AddSIfPlural(RemainingMin)}{CloseSentenceIfZero(RemainingSec)}";
SecText = $" second{AddSIfPlural(RemainingSec)}.";
}
private static string AddSIfPlural(int n) => n > 1 ? "s" : "";
+
+ private static string CloseSentenceIfZero(params int[] counts) => counts.All(x => x == 0) ? "." : " ";
}
}

MODIFY
WalletWasabi.Fluent/Views/Login/PasswordFinder/SearchPasswordView.axaml
WalletWasabi.Fluent/Views/Login/PasswordFinder/SearchPasswordView.axaml
ScrollViewer.VerticalScrollBarVisibility="Disabled">
<DockPanel VerticalAlignment="Center" HorizontalAlignment="Stretch">
- <Viewbox MaxHeight="200" DockPanel.Dock="Top">
- <Panel HorizontalAlignment="Center">
- <c:ProgressRing Height="150" Width="150" IsIndeterminate="True"/>
- <TextBlock Text="{Binding Percentage, StringFormat={}{0}%}" FontSize="20" VerticalAlignment="Center" HorizontalAlignment="Center"/>
- </Panel>
- </Viewbox>
- <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0 30" DockPanel.Dock="Bottom">
+ <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" DockPanel.Dock="Bottom" Height="30">
<StackPanel.Styles>
<Style Selector="TextBlock">
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="Foreground" Value="{DynamicResource SystemAccentColor}"/>
</Style>
</StackPanel.Styles>
- <TextBlock Text="The search will finish in " />
+ <TextBlock Text="The search will finish in " IsVisible="{Binding RemainingTimeReceived}"/>
<TextBlock Text="{Binding RemainingHour}" Classes="countValue" IsVisible="{Binding !!RemainingHour}"/>
<TextBlock Text="{Binding HourText}" IsVisible="{Binding !!RemainingHour}"/>
<TextBlock Text="{Binding RemainingMin}" Classes="countValue" IsVisible="{Binding !!RemainingMin}"/>
<TextBlock Text="{Binding MinText}" IsVisible="{Binding !!RemainingMin}"/>
- <TextBlock Text="{Binding RemainingSec}" Classes="countValue"/>
- <TextBlock Text="{Binding SecText}"/>
+ <TextBlock Text="{Binding RemainingSec}" Classes="countValue" IsVisible="{Binding !!RemainingSec}"/>
+ <TextBlock Text="{Binding SecText}" IsVisible="{Binding !!RemainingSec}"/>
</StackPanel>
+
+ <Viewbox MaxHeight="200" DockPanel.Dock="Top" Margin="0 0 0 10">
+ <Panel HorizontalAlignment="Center">
+ <c:ProgressRing Height="150" Width="150" IsIndeterminate="True"/>
+ <TextBlock Text="{Binding Percentage, StringFormat={}{0}%}" FontSize="20" VerticalAlignment="Center" HorizontalAlignment="Center"/>
+ </Panel>
+ </Viewbox>
</DockPanel>
</c:ContentArea>
</UserControl>

remaining text, cancel token