diff --git a/src/main/java/com/sparrowwallet/sparrow/control/DeviceAddressDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/DeviceAddressDialog.java index b1629c9d..bc24f38a 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/DeviceAddressDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/DeviceAddressDialog.java @@ -25,8 +25,8 @@ public class DeviceAddressDialog extends DeviceDialog { } @Override - protected DevicePane getDevicePane(Device device) { - return new DevicePane(wallet, outputDescriptor, device); + protected DevicePane getDevicePane(Device device, boolean defaultDevice) { + return new DevicePane(wallet, outputDescriptor, device, defaultDevice); } @Subscribe diff --git a/src/main/java/com/sparrowwallet/sparrow/control/DeviceDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/DeviceDialog.java index b02cd5c8..4b18119f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/DeviceDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/DeviceDialog.java @@ -22,6 +22,7 @@ import java.util.Objects; public abstract class DeviceDialog extends Dialog { private final List operationFingerprints; private final Accordion deviceAccordion; + private final Button scanButton; private final VBox scanBox; private final Label scanLabel; @@ -57,18 +58,19 @@ public abstract class DeviceDialog extends Dialog { Glyph usb = new Glyph(FontAwesome5Brands.FONT_NAME, FontAwesome5Brands.Glyph.USB); usb.setFontSize(50); scanLabel = new Label("Connect Hardware Wallet"); - Button button = new Button("Scan..."); - button.setPrefSize(120, 60); - button.setOnAction(event -> { + scanButton = new Button("Scan..."); + scanButton.setPrefSize(120, 60); + scanButton.setOnAction(event -> { scan(); }); - scanBox.getChildren().addAll(usb, scanLabel, button); + scanBox.getChildren().addAll(usb, scanLabel, scanButton); scanBox.managedProperty().bind(scanBox.visibleProperty()); stackPane.getChildren().addAll(anchorPane, scanBox); List devices = AppServices.getDevices(); if(devices == null || devices.isEmpty()) { + scanButton.setDefaultButton(true); scanBox.setVisible(true); } else { Platform.runLater(() -> setDevices(devices)); @@ -97,15 +99,21 @@ public abstract class DeviceDialog extends Dialog { private void scan() { Hwi.EnumerateService enumerateService = new Hwi.EnumerateService(null); enumerateService.setOnSucceeded(workerStateEvent -> { + scanButton.setText("Scan..."); List devices = enumerateService.getValue(); setDevices(devices); Platform.runLater(() -> EventManager.get().post(new UsbDeviceEvent(devices))); }); enumerateService.setOnFailed(workerStateEvent -> { + scanButton.setText("Scan..."); deviceAccordion.getPanes().clear(); + scanButton.setDefaultButton(true); scanBox.setVisible(true); scanLabel.setText(workerStateEvent.getSource().getException().getMessage()); }); + enumerateService.setOnRunning(workerStateEvent -> { + scanButton.setText("Scanning..."); + }); enumerateService.start(); } @@ -122,16 +130,17 @@ public abstract class DeviceDialog extends Dialog { deviceAccordion.getPanes().clear(); if(dialogDevices.isEmpty()) { + scanButton.setDefaultButton(true); scanBox.setVisible(true); scanLabel.setText("No matching devices found"); } else { scanBox.setVisible(false); for(Device device : dialogDevices) { - DevicePane devicePane = getDevicePane(device); + DevicePane devicePane = getDevicePane(device, dialogDevices.size() == 1); deviceAccordion.getPanes().add(devicePane); } } } - protected abstract DevicePane getDevicePane(Device device); + protected abstract DevicePane getDevicePane(Device device, boolean defaultDevice); } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java b/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java index 8c219f30..a63c04e8 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java @@ -59,7 +59,9 @@ public class DevicePane extends TitledDescriptionPane { private final SimpleStringProperty passphrase = new SimpleStringProperty(""); - public DevicePane(Wallet wallet, Device device) { + private boolean defaultDevice; + + public DevicePane(Wallet wallet, Device device, boolean defaultDevice) { super(device.getModel().toDisplayString(), "", "", "image/" + device.getType() + ".png"); this.deviceOperation = DeviceOperation.IMPORT; this.wallet = wallet; @@ -68,6 +70,7 @@ public class DevicePane extends TitledDescriptionPane { this.keyDerivation = null; this.message = null; this.device = device; + this.defaultDevice = defaultDevice; setDefaultStatus(); showHideLink.setVisible(false); @@ -80,7 +83,7 @@ public class DevicePane extends TitledDescriptionPane { buttonBox.getChildren().addAll(setPassphraseButton, importButton); } - public DevicePane(PSBT psbt, Device device) { + public DevicePane(PSBT psbt, Device device, boolean defaultDevice) { super(device.getModel().toDisplayString(), "", "", "image/" + device.getType() + ".png"); this.deviceOperation = DeviceOperation.SIGN; this.wallet = null; @@ -89,6 +92,7 @@ public class DevicePane extends TitledDescriptionPane { this.keyDerivation = null; this.message = null; this.device = device; + this.defaultDevice = defaultDevice; setDefaultStatus(); showHideLink.setVisible(false); @@ -101,7 +105,7 @@ public class DevicePane extends TitledDescriptionPane { buttonBox.getChildren().addAll(setPassphraseButton, signButton); } - public DevicePane(Wallet wallet, OutputDescriptor outputDescriptor, Device device) { + public DevicePane(Wallet wallet, OutputDescriptor outputDescriptor, Device device, boolean defaultDevice) { super(device.getModel().toDisplayString(), "", "", "image/" + device.getType() + ".png"); this.deviceOperation = DeviceOperation.DISPLAY_ADDRESS; this.wallet = wallet; @@ -110,6 +114,7 @@ public class DevicePane extends TitledDescriptionPane { this.keyDerivation = null; this.message = null; this.device = device; + this.defaultDevice = defaultDevice; setDefaultStatus(); showHideLink.setVisible(false); @@ -122,7 +127,7 @@ public class DevicePane extends TitledDescriptionPane { buttonBox.getChildren().addAll(setPassphraseButton, displayAddressButton); } - public DevicePane(Wallet wallet, String message, KeyDerivation keyDerivation, Device device) { + public DevicePane(Wallet wallet, String message, KeyDerivation keyDerivation, Device device, boolean defaultDevice) { super(device.getModel().toDisplayString(), "", "", "image/" + device.getType() + ".png"); this.deviceOperation = DeviceOperation.SIGN_MESSAGE; this.wallet = wallet; @@ -131,6 +136,7 @@ public class DevicePane extends TitledDescriptionPane { this.keyDerivation = keyDerivation; this.message = message; this.device = device; + this.defaultDevice = defaultDevice; setDefaultStatus(); showHideLink.setVisible(false); @@ -145,6 +151,7 @@ public class DevicePane extends TitledDescriptionPane { private void initialise(Device device) { if(device.isNeedsPinSent()) { + unlockButton.setDefaultButton(defaultDevice); unlockButton.setVisible(true); } else if(device.isNeedsPassphraseSent()) { setPassphraseButton.setVisible(true); @@ -229,7 +236,6 @@ public class DevicePane extends TitledDescriptionPane { private void createSignButton() { signButton = new Button("Sign"); - signButton.setDefaultButton(true); signButton.setAlignment(Pos.CENTER_RIGHT); signButton.setMinWidth(44); signButton.setOnAction(event -> { @@ -242,7 +248,6 @@ public class DevicePane extends TitledDescriptionPane { private void createDisplayAddressButton() { displayAddressButton = new Button("Display Address"); - displayAddressButton.setDefaultButton(true); displayAddressButton.setAlignment(Pos.CENTER_RIGHT); displayAddressButton.setOnAction(event -> { displayAddressButton.setDisable(true); @@ -259,7 +264,6 @@ public class DevicePane extends TitledDescriptionPane { private void createSignMessageButton() { signMessageButton = new Button("Sign Message"); - signMessageButton.setDefaultButton(true); signMessageButton.setAlignment(Pos.CENTER_RIGHT); signMessageButton.setOnAction(event -> { signMessageButton.setDisable(true); @@ -284,7 +288,9 @@ public class DevicePane extends TitledDescriptionPane { vBox.setMaxHeight(120); vBox.setSpacing(42); pinField = (CustomPasswordField)TextFields.createClearablePasswordField(); + Platform.runLater(() -> pinField.requestFocus()); enterPinButton = new Button("Enter PIN"); + enterPinButton.setDefaultButton(true); enterPinButton.setOnAction(event -> { enterPinButton.setDisable(true); sendPin(pinField.getText()); @@ -324,9 +330,15 @@ public class DevicePane extends TitledDescriptionPane { CustomPasswordField passphraseField = (CustomPasswordField)TextFields.createClearablePasswordField(); passphrase.bind(passphraseField.textProperty()); HBox.setHgrow(passphraseField, Priority.ALWAYS); + passphraseField.setOnAction(event -> { + setExpanded(false); + setDescription("Confirm passphrase on device..."); + sendPassphrase(passphrase.get()); + }); SplitMenuButton sendPassphraseButton = new SplitMenuButton(); sendPassphraseButton.setText("Send Passphrase"); + sendPassphraseButton.getStyleClass().add("default-button"); sendPassphraseButton.setOnAction(event -> { setExpanded(false); setDescription("Confirm passphrase on device..."); @@ -604,17 +616,23 @@ public class DevicePane extends TitledDescriptionPane { private void showOperationButton() { if(deviceOperation.equals(DeviceOperation.IMPORT)) { + if(defaultDevice) { + importButton.getStyleClass().add("default-button"); + } importButton.setVisible(true); showHideLink.setText("Show derivation..."); showHideLink.setVisible(true); setContent(getDerivationEntry(wallet.getScriptType() == null ? ScriptType.P2WPKH.getDefaultDerivation() : wallet.getScriptType().getDefaultDerivation())); } else if(deviceOperation.equals(DeviceOperation.SIGN)) { + signButton.setDefaultButton(defaultDevice); signButton.setVisible(true); showHideLink.setVisible(false); } else if(deviceOperation.equals(DeviceOperation.DISPLAY_ADDRESS)) { + displayAddressButton.setDefaultButton(defaultDevice); displayAddressButton.setVisible(true); showHideLink.setVisible(false); } else if(deviceOperation.equals(DeviceOperation.SIGN_MESSAGE)) { + signMessageButton.setDefaultButton(defaultDevice); signMessageButton.setVisible(true); showHideLink.setVisible(false); } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/DeviceSignDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/DeviceSignDialog.java index e430eb17..dbadb5bf 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/DeviceSignDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/DeviceSignDialog.java @@ -22,8 +22,8 @@ public class DeviceSignDialog extends DeviceDialog { } @Override - protected DevicePane getDevicePane(Device device) { - return new DevicePane(psbt, device); + protected DevicePane getDevicePane(Device device, boolean defaultDevice) { + return new DevicePane(psbt, device, defaultDevice); } @Subscribe diff --git a/src/main/java/com/sparrowwallet/sparrow/control/DeviceSignMessageDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/DeviceSignMessageDialog.java index 2a1a630d..692d519f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/DeviceSignMessageDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/DeviceSignMessageDialog.java @@ -26,8 +26,8 @@ public class DeviceSignMessageDialog extends DeviceDialog { } @Override - protected DevicePane getDevicePane(Device device) { - return new DevicePane(wallet, message, keyDerivation, device); + protected DevicePane getDevicePane(Device device, boolean defaultDevice) { + return new DevicePane(wallet, message, keyDerivation, device, defaultDevice); } @Subscribe diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WalletImportDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/WalletImportDialog.java index 8e5a440e..aa511b91 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WalletImportDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WalletImportDialog.java @@ -92,7 +92,7 @@ public class WalletImportDialog extends Dialog { List devices = enumerateService.getValue(); importAccordion.getPanes().removeIf(titledPane -> titledPane instanceof DevicePane); for(Device device : devices) { - DevicePane devicePane = new DevicePane(new Wallet(), device); + DevicePane devicePane = new DevicePane(new Wallet(), device, devices.size() == 1); importAccordion.getPanes().add(0, devicePane); } Platform.runLater(() -> EventManager.get().post(new UsbDeviceEvent(devices))); diff --git a/src/main/java/com/sparrowwallet/sparrow/keystoreimport/HwUsbDevicesController.java b/src/main/java/com/sparrowwallet/sparrow/keystoreimport/HwUsbDevicesController.java index 6e636021..c2d7f9c4 100644 --- a/src/main/java/com/sparrowwallet/sparrow/keystoreimport/HwUsbDevicesController.java +++ b/src/main/java/com/sparrowwallet/sparrow/keystoreimport/HwUsbDevicesController.java @@ -2,7 +2,6 @@ package com.sparrowwallet.sparrow.keystoreimport; import com.sparrowwallet.sparrow.control.DevicePane; import com.sparrowwallet.sparrow.io.Device; -import javafx.collections.FXCollections; import javafx.fxml.FXML; import javafx.scene.control.Accordion; @@ -14,7 +13,7 @@ public class HwUsbDevicesController extends KeystoreImportDetailController { public void initializeView(List devices) { for(Device device : devices) { - DevicePane devicePane = new DevicePane(getMasterController().getWallet(), device); + DevicePane devicePane = new DevicePane(getMasterController().getWallet(), device, devices.size() == 1); deviceAccordion.getPanes().add(devicePane); } } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java index 304e07e7..a42f0aa5 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java @@ -462,7 +462,9 @@ public class WalletForm { for(WalletTabData tabData : event.getClosedWalletTabData()) { if(tabData.getWalletForm() == this) { storage.close(); - AppServices.clearTransactionHistoryCache(wallet); + if(wallet.isValid()) { + AppServices.clearTransactionHistoryCache(wallet); + } EventManager.get().unregister(this); } } diff --git a/src/main/resources/com/sparrowwallet/sparrow/keystoreimport/hw_usb-error.fxml b/src/main/resources/com/sparrowwallet/sparrow/keystoreimport/hw_usb-error.fxml index e163ce13..01288e92 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/keystoreimport/hw_usb-error.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/keystoreimport/hw_usb-error.fxml @@ -11,5 +11,5 @@