ConfigureAwait(false), simplification, async method
MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/ConnectHardwareWalletViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/ConnectHardwareWalletViewModel.cs
@@ -23,7 +23,6 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
public class ConnectHardwareWalletViewModel : RoutableViewModel
{
private HardwareWalletViewModel? _selectedHardwareWallet;
- private bool _walletListVisible;
public ConnectHardwareWalletViewModel(NavigationStateViewModel navigationState, string walletName, Network network, WalletManager walletManager)
: base(navigationState, NavigationTarget.DialogScreen)
@@ -39,20 +38,20 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
this.WhenAnyValue(x => x.SelectedHardwareWallet)
.ObserveOn(RxApp.MainThreadScheduler)
.Select(x => x?.HardwareWalletInfo.Fingerprint is { } && x.HardwareWalletInfo.IsInitialized());
- NextCommand = ReactiveCommand.Create(ConnectSelectedHardwareWallet,nextCommandIsExecute);
+ NextCommand = ReactiveCommand.CreateFromTask(ConnectSelectedHardwareWallet,nextCommandIsExecute);
this.WhenAnyValue(x => x.SelectedHardwareWallet)
.ObserveOn(RxApp.MainThreadScheduler)
.Where(x => x is { } && !x.HardwareWalletInfo.IsInitialized() && x.HardwareWalletInfo.Model != HardwareWalletModels.Coldcard)
.Subscribe(async x =>
{
- if (NavigatedToCts is null)
+ if (DisposeCts is null)
{
return;
}
using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(21));
- using var initCts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, NavigatedToCts.Token);
+ using var initCts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, DisposeCts.Token);
// Trezor T doesn't require interactive mode.
var interactiveMode = !(x!.HardwareWalletInfo.Model == HardwareWalletModels.Trezor_T || x.HardwareWalletInfo.Model == HardwareWalletModels.Trezor_T_Simulator);
@@ -70,22 +69,16 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
this.WhenNavigatedTo(() =>
{
- NavigatedToCts = new CancellationTokenSource();
+ DisposeCts = new CancellationTokenSource();
StartDetection();
return Disposable.Create(() =>
{
- NavigatedToCts.Cancel();
- NavigatedToCts.Dispose();
+ DisposeCts.Cancel();
+ DisposeCts.Dispose();
});
});
-
- this.WhenAnyValue(x => x.HardwareWallets.Count)
- .Subscribe(x =>
- {
- WalletListVisible = x > 0;
- });
}
private string WalletName { get; }
@@ -98,7 +91,7 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
private CancellationTokenSource? DetectionCts { get; set; }
- private CancellationTokenSource? NavigatedToCts { get; set; }
+ private CancellationTokenSource? DisposeCts { get; set; }
public HardwareWalletViewModel? SelectedHardwareWallet
{
@@ -106,17 +99,11 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
set => this.RaiseAndSetIfChanged(ref _selectedHardwareWallet, value);
}
- public bool WalletListVisible
- {
- get => _walletListVisible;
- set => this.RaiseAndSetIfChanged(ref _walletListVisible, value);
- }
-
public ObservableCollection<HardwareWalletViewModel> HardwareWallets { get; }
public ReactiveCommand<string, Unit> OpenBrowserCommand { get; }
- private async void ConnectSelectedHardwareWallet()
+ private async Task ConnectSelectedHardwareWallet()
{
if (SelectedHardwareWallet?.HardwareWalletInfo.Fingerprint is null)
{
@@ -168,7 +155,7 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
private void StartDetection()
{
- if (NavigatedToCts is { } cts)
+ if (DisposeCts is { } cts)
{
DetectionCts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token);
DetectionTask = HardwareWalletDetectionAsync(DetectionCts);
@@ -185,7 +172,7 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
{
using var timeoutCts = new CancellationTokenSource(TimeSpan.FromMinutes(3));
- var detectedHardwareWallets = (await HwiClient.EnumerateAsync(timeoutCts.Token)).Select(x => new HardwareWalletViewModel(x)).ToArray();
+ var detectedHardwareWallets = (await HwiClient.EnumerateAsync(timeoutCts.Token).ConfigureAwait(false)).Select(x => new HardwareWalletViewModel(x)).ToArray();
detectionCts.Token.ThrowIfCancellationRequested();
// The wallets that are already exists in the wallets.
@@ -218,7 +205,7 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
sw.Stop();
if (sw.Elapsed.Milliseconds < 5000)
{
- await Task.Delay(5000 - sw.Elapsed.Milliseconds);
+ await Task.Delay(5000 - sw.Elapsed.Milliseconds).ConfigureAwait(false);
}
}
}

MODIFY
WalletWasabi.Fluent/ViewModels/AddWalletPageViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWalletPageViewModel.cs
@@ -47,7 +47,7 @@ namespace WalletWasabi.Fluent.ViewModels
ImportWalletCommand = ReactiveCommand.Create(() => new ImportWalletViewModel(navigationState, WalletName, walletManager));
- ConnectHardwareWalletCommand = ReactiveCommand.CreateFromTask(async () =>
+ ConnectHardwareWalletCommand = ReactiveCommand.Create(() =>
{
NavigateTo(new ConnectHardwareWalletViewModel(navigationState, WalletName, network, walletManager), NavigationTarget.DialogScreen);
});

MODIFY
WalletWasabi.Fluent/Views/AddWallet/ConnectHardwareWalletView.axaml
WalletWasabi.Fluent/Views/AddWallet/ConnectHardwareWalletView.axaml
<DockPanel>
<Button DockPanel.Dock="Bottom" HorizontalAlignment="Center" Classes="h8 plain activeHyperLink" Foreground="{DynamicResource SystemAccentColor}" Content="More information and help with Hardware Wallets" />
<Panel>
- <ListBox IsVisible="{Binding WalletListVisible}" Background="Transparent" Items="{Binding HardwareWallets}" SelectedItem="{Binding SelectedHardwareWallet}"/>
- <DockPanel IsVisible="{Binding !WalletListVisible}">
+ <ListBox IsVisible="{Binding HardwareWallets.Count}" Background="Transparent" Items="{Binding HardwareWallets}" SelectedItem="{Binding SelectedHardwareWallet}"/>
+ <DockPanel IsVisible="{Binding !HardwareWallets.Count}">
<StackPanel VerticalAlignment="Top" Spacing="20" DockPanel.Dock="Top">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="20">
<Image Height="100" Source="{DynamicResource coldcard}" />

ConfigureAwait(false), simplification, async method