Add PinPadViewModel.UnlockAsync
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/PinPadViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/PinPadViewModel.cs
@@ -8,8 +8,13 @@ using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
+using System.Security;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using WalletWasabi.Gui.ViewModels;
+using WalletWasabi.Hwi;
+using WalletWasabi.Hwi.Models;
namespace WalletWasabi.Gui.Controls.WalletExplorer
{
@@ -71,5 +76,31 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
{
SetWarningMessage(ex.ToTypeMessageString());
}
+
+ public static async Task UnlockAsync(Global global, HwiEnumerateEntry hwiEntry)
+ {
+ using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(3)))
+ {
+ var client = new HwiClient(global.Network);
+
+ await client.PromptPinAsync(hwiEntry.Model, hwiEntry.Path, cts.Token);
+
+ PinPadViewModel pinpad = IoC.Get<IShell>().Documents.OfType<PinPadViewModel>().FirstOrDefault();
+ if (pinpad is null)
+ {
+ pinpad = new PinPadViewModel(global);
+ IoC.Get<IShell>().AddOrSelectDocument(pinpad);
+ }
+ var result = await pinpad.ShowDialogAsync();
+ if (!(result is true))
+ {
+ throw new SecurityException("PIN was not provided.");
+ }
+
+ var maskedPin = pinpad.MaskedPin;
+
+ await client.SendPinAsync(hwiEntry.Model, hwiEntry.Path, int.Parse(maskedPin), cts.Token);
+ }
+ }
}
}

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
@@ -371,10 +371,13 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
{
IsHardwareBusy = true;
MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.AcquiringSignatureFromHardwareWallet);
- var cts = new CancellationTokenSource(TimeSpan.FromMinutes(3));
var client = new HwiClient(Global.Network);
+ using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(3)))
+ {
PSBT signedPsbt = await client.SignTxAsync(KeyManager.MasterFingerprint.Value, result.Psbt, cts.Token);
+ signedTransaction = signedPsbt.ExtractSmartTransaction(result.Transaction.Height, result.Transaction.BlockHash, result.Transaction.BlockIndex, result.Transaction.Label, result.Transaction.FirstSeen, result.Transaction.IsReplacement);
+ }
}
catch (Exception ex)
{
@@ -383,12 +386,9 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
finally
{
- cts?.Dispose();
MainWindowViewModel.Instance.StatusBar.TryRemoveStatus(StatusBarStatus.AcquiringSignatureFromHardwareWallet);
IsHardwareBusy = false;
}
-
- signedTransaction = signedPsbt.ExtractSmartTransaction(result.Transaction.Height, result.Transaction.BlockHash, result.Transaction.BlockIndex, result.Transaction.Label, result.Transaction.FirstSeen, result.Transaction.IsReplacement);
}
MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.BroadcastingTransaction);

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
@@ -438,24 +438,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
}
else if (selectedWallet.HardwareWalletInfo.NeedsPinSent is true)
{
- await client.PromptPinAsync(selectedWallet.HardwareWalletInfo.Model, selectedWallet.HardwareWalletInfo.Path, cts.Token);
-
- PinPadViewModel pinpad = IoC.Get<IShell>().Documents.OfType<PinPadViewModel>().FirstOrDefault();
- if (pinpad is null)
- {
- pinpad = new PinPadViewModel(Global);
- IoC.Get<IShell>().AddOrSelectDocument(pinpad);
- }
- var result = await pinpad.ShowDialogAsync();
- if (!(result is true))
- {
- SetValidationMessage("PIN was not provided.");
- return null;
- }
-
- var maskedPin = pinpad.MaskedPin;
-
- await client.SendPinAsync(selectedWallet.HardwareWalletInfo.Model, selectedWallet.HardwareWalletInfo.Path, int.Parse(maskedPin), cts.Token);
+ await PinPadViewModel.UnlockAsync(Global, selectedWallet.HardwareWalletInfo);
var p = selectedWallet.HardwareWalletInfo.Path;
var t = selectedWallet.HardwareWalletInfo.Model;

Add PinPadViewModel.UnlockAsync