Implement send
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
@@ -298,24 +298,30 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
IsHardwareBusy = true;
MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.ConnectingToHardwareWallet);
// If we have no hardware wallet info then try refresh it. If we failed, then tha's a problem.
- if (KeyManager.HardwareWalletInfo is null && !await TryRefreshHardwareWalletInfoAsync(KeyManager))
+ if (KeyManager.HardwareWalletInfo is null)
{
- SetWarningMessage("Could not find hardware wallet. Make sure it's plugged in and you're logged in with your PIN.");
+ var refRes = await TryRefreshHardwareWalletInfoAsync(KeyManager);
+ if (!refRes.success)
+ {
+ SetWarningMessage(refRes.error);
return;
}
+ }
MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.AcquiringSignatureFromHardwareWallet);
signedPsbt = await HwiProcessManager.SignTxAsync(KeyManager.HardwareWalletInfo, result.Psbt);
}
catch (IOException ex) when (ex.Message.Contains("device not found", StringComparison.OrdinalIgnoreCase)
|| ex.Message.Contains("Invalid status 6f04", StringComparison.OrdinalIgnoreCase) // It comes when device asleep too.
- || ex.Message.Contains("Device is asleep", StringComparison.OrdinalIgnoreCase))
+ || ex.Message.Contains("Device is asleep", StringComparison.OrdinalIgnoreCase)
+ || ex.Message.Contains("promptpin", StringComparison.OrdinalIgnoreCase))
{
MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.ConnectingToHardwareWallet);
// The user may changed USB port. Try again with new enumeration.
- if (!await TryRefreshHardwareWalletInfoAsync(KeyManager))
+ var refRes = await TryRefreshHardwareWalletInfoAsync(KeyManager);
+ if (!refRes.success)
{
- SetWarningMessage("Could not find hardware wallet. Make sure it's plugged in and you're logged in with your PIN.");
+ SetWarningMessage(refRes.error);
return;
}
@@ -355,7 +361,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
(isMax, amount, address, busy) => (isMax.Value || !string.IsNullOrWhiteSpace(amount.Value)) && !string.IsNullOrWhiteSpace(Address) && !IsBusy));
}
- private async Task<bool> TryRefreshHardwareWalletInfoAsync(KeyManager keyManager)
+ private async Task<(bool success, string error)> TryRefreshHardwareWalletInfoAsync(KeyManager keyManager)
{
var hwis = await HwiProcessManager.EnumerateAsync();
@@ -367,11 +373,75 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
var fingerprint = keyManager.MasterFingerprint;
- if (fingerprint is null) return false;
+ if (fingerprint is null) return (false, "This wallet is a watch-only wallet.");
keyManager.HardwareWalletInfo = hwis.FirstOrDefault(x => x.MasterFingerprint == fingerprint);
- return keyManager.HardwareWalletInfo != null;
+ if (keyManager.HardwareWalletInfo is null)
+ {
+ var needsPinWalletInfo = hwis.FirstOrDefault(x => x.NeedPin);
+
+ if (needsPinWalletInfo != null)
+ {
+ if (!await HwiProcessManager.PromptPinAsync(needsPinWalletInfo))
+ {
+ return (false, "promptpin request failed.");
+ }
+
+ PinPadViewModel pinpad = IoC.Get<IShell>().Documents.OfType<PinPadViewModel>().FirstOrDefault();
+ if (pinpad is null)
+ {
+ pinpad = new PinPadViewModel(null);
+ IoC.Get<IShell>().AddOrSelectDocument(pinpad);
+ }
+ var result = await pinpad.ShowDialogAsync();
+ DisplayActionTab();
+ if (!(result is true))
+ {
+ return (false, "PIN wasn't provided.");
+ }
+
+ var maskedPin = pinpad.MaskedPin;
+ if (!await HwiProcessManager.SendPinAsync(needsPinWalletInfo, maskedPin))
+ {
+ return (false, "Wrong PIN.");
+ }
+ var p = needsPinWalletInfo.Path;
+ var t = needsPinWalletInfo.Type;
+ var enumRes = await HwiProcessManager.EnumerateAsync();
+ needsPinWalletInfo = enumRes.FirstOrDefault(x => x.Type == t && x.Path == p);
+ if (needsPinWalletInfo is null)
+ {
+ return (false, "Couldn't find the hardware wallet you are working with. Did you disconnect it?");
+ }
+ else
+ {
+ keyManager.HardwareWalletInfo = needsPinWalletInfo;
+ }
+
+ if (!keyManager.HardwareWalletInfo.Initialized)
+ {
+ return (false, "Hardware wallet is not initialized.");
+ }
+ if (!keyManager.HardwareWalletInfo.Ready)
+ {
+ return (false, "Hardware wallet is not ready.");
+ }
+ if (keyManager.HardwareWalletInfo.NeedPin)
+ {
+ return (false, "Hardware wallet still needs a PIN.");
+ }
+ }
+ }
+
+ if (keyManager.HardwareWalletInfo is null)
+ {
+ return (false, "Could not find hardware wallet. Make sure it's plugged in and you're logged in with your PIN.");
+ }
+ else
+ {
+ return (true, null);
+ }
}
private void SetSendText()

Implement send