Put DisplayAddressOnHw into AddressViewModel
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabView.xaml
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabView.xaml
<DrawingPresenter HorizontalAlignment="Left" Height="16" Width="16" Stretch="Fill" Drawing="{StaticResource ReceiveTabView_ChangeLabel}" />
</MenuItem.Icon>
</MenuItem>
- <MenuItem IsVisible="{Binding IsHardwareWallet}" Header="Display address on hardware wallet" Command="{Binding DisplayAddressOnHwCommand}">
+ <MenuItem IsVisible="{Binding IsHardwareWallet}" Header="Display address on hardware wallet" Command="{Binding DisplayAddressOnHw}">
<MenuItem.Icon>
<DrawingPresenter HorizontalAlignment="Left" Height="16" Width="16" Stretch="Fill" Drawing="{StaticResource ReceiveTabView_IsHardwareWallet}" />
</MenuItem.Icon>

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabViewModel.cs
@@ -29,7 +29,6 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
private AddressViewModel _selectedAddress;
private SuggestLabelViewModel _labelSuggestion;
- public ReactiveCommand<Unit, Unit> DisplayAddressOnHwCommand { get; }
public ReactiveCommand<Unit, Unit> GenerateCommand { get; }
public ReceiveTabViewModel(WalletViewModel walletViewModel)
@@ -61,7 +60,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
NotificationHelpers.Warning($"{nameof(KeyManager.MinGapLimit)} increased from {prevMinGapLimit} to {minGapLimit}.");
}
- var newAddress = new AddressViewModel(newKey, Global);
+ var newAddress = new AddressViewModel(newKey, Global, KeyManager);
Addresses.Insert(0, newAddress);
SelectedAddress = newAddress;
_labelSuggestion.Label = "";
@@ -79,29 +78,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
await address.TryCopyToClipboardAsync();
});
- DisplayAddressOnHwCommand = ReactiveCommand.CreateFromTask(async () =>
- {
- var selectedAddress = SelectedAddress;
- if (selectedAddress is null)
- {
- return;
- }
-
- var client = new HwiClient(Global.Network);
- using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
- try
- {
- await client.DisplayAddressAsync(KeyManager.MasterFingerprint.Value, selectedAddress.Model.FullKeyPath, cts.Token);
- }
- catch (HwiException)
- {
- await PinPadViewModel.UnlockAsync(Global);
- await client.DisplayAddressAsync(KeyManager.MasterFingerprint.Value, selectedAddress.Model.FullKeyPath, cts.Token);
- }
- });
-
Observable
- .Merge(DisplayAddressOnHwCommand.ThrownExceptions)
.Merge(GenerateCommand.ThrownExceptions)
.ObserveOn(RxApp.TaskpoolScheduler)
.Subscribe(ex =>
@@ -150,7 +127,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
IEnumerable<HdPubKey> keys = walletService.KeyManager.GetKeys(x => !x.Label.IsEmpty && !x.IsInternal && x.KeyState == KeyState.Clean).Reverse();
foreach (HdPubKey key in keys)
{
- _addresses.Add(new AddressViewModel(key, Global));
+ _addresses.Add(new AddressViewModel(key, Global, KeyManager));
}
}
catch (Exception ex)

MODIFY
WalletWasabi.Gui/ViewModels/AddressViewModel.cs
WalletWasabi.Gui/ViewModels/AddressViewModel.cs
@@ -10,7 +10,10 @@ using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Blockchain.Analysis.Clustering;
using WalletWasabi.Blockchain.Keys;
+using WalletWasabi.Gui.Controls.WalletExplorer;
using WalletWasabi.Gui.Helpers;
+using WalletWasabi.Hwi;
+using WalletWasabi.Hwi.Exceptions;
using WalletWasabi.Logging;
namespace WalletWasabi.Gui.ViewModels
@@ -31,13 +34,18 @@ namespace WalletWasabi.Gui.ViewModels
public ReactiveCommand<Unit, Unit> CopyAddress { get; }
public ReactiveCommand<Unit, Unit> CopyLabel { get; }
public ReactiveCommand<Unit, bool> ChangeLabel { get; }
+ public ReactiveCommand<Unit, Unit> DisplayAddressOnHw { get; }
public HdPubKey Model { get; }
public Global Global { get; }
+ public KeyManager KeyManager { get; }
+ public bool IsHardwareWallet { get; }
- public AddressViewModel(HdPubKey model, Global global)
+ public AddressViewModel(HdPubKey model, Global global, KeyManager km)
{
Global = global;
+ KeyManager = km;
+ IsHardwareWallet = km.IsHardwareWallet;
Model = model;
ClipboardNotificationVisible = false;
ClipboardNotificationOpacity = 0;
@@ -99,12 +107,28 @@ namespace WalletWasabi.Gui.ViewModels
ChangeLabel = ReactiveCommand.Create(() => InEditMode = true);
+ DisplayAddressOnHw = ReactiveCommand.CreateFromTask(async () =>
+ {
+ var client = new HwiClient(Global.Network);
+ using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
+ try
+ {
+ await client.DisplayAddressAsync(KeyManager.MasterFingerprint.Value, Model.FullKeyPath, cts.Token);
+ }
+ catch (HwiException)
+ {
+ await PinPadViewModel.UnlockAsync(Global);
+ await client.DisplayAddressAsync(KeyManager.MasterFingerprint.Value, Model.FullKeyPath, cts.Token);
+ }
+ });
+
Observable
.Merge(ToggleQrCode.ThrownExceptions)
.Merge(SaveQRCode.ThrownExceptions)
.Merge(CopyAddress.ThrownExceptions)
.Merge(CopyLabel.ThrownExceptions)
.Merge(ChangeLabel.ThrownExceptions)
+ .Merge(DisplayAddressOnHw.ThrownExceptions)
.Subscribe(ex =>
{
NotificationHelpers.Error(ex.ToTypeMessageString());

Put DisplayAddressOnHw into AddressViewModel