null-safe testing of device needspin and needspassphrase

This commit is contained in:
Craig Raw 2021-04-16 11:38:01 +02:00
parent d52bade085
commit 1556b8930c
5 changed files with 16 additions and 8 deletions

View file

@ -114,7 +114,7 @@ public abstract class DeviceDialog<R> extends Dialog<R> {
if(operationFingerprints != null) { if(operationFingerprints != null) {
dialogDevices.removeIf(device -> { dialogDevices.removeIf(device -> {
return device.getFingerprint() != null && !operationFingerprints.contains(device.getFingerprint()) && !(device.getNeedsPinSent() || device.getNeedsPassphraseSent()); return device.getFingerprint() != null && !operationFingerprints.contains(device.getFingerprint()) && !(device.isNeedsPinSent() || device.isNeedsPassphraseSent());
}); });
} }

View file

@ -144,9 +144,9 @@ public class DevicePane extends TitledDescriptionPane {
} }
private void initialise(Device device) { private void initialise(Device device) {
if(device.getNeedsPinSent() != null && device.getNeedsPinSent()) { if(device.isNeedsPinSent()) {
unlockButton.setVisible(true); unlockButton.setVisible(true);
} else if(device.getNeedsPassphraseSent() != null && device.getNeedsPassphraseSent()) { } else if(device.isNeedsPassphraseSent()) {
setPassphraseButton.setVisible(true); setPassphraseButton.setVisible(true);
} else if(device.getError() != null) { } else if(device.getError() != null) {
setError("Error", device.getError()); setError("Error", device.getError());
@ -165,7 +165,7 @@ public class DevicePane extends TitledDescriptionPane {
} }
private void setDefaultStatus() { private void setDefaultStatus() {
setDescription(device.getNeedsPinSent() ? "Locked" : device.getNeedsPassphraseSent() ? "Passphrase Required" : "Unlocked"); setDescription(device.isNeedsPinSent() ? "Locked" : device.isNeedsPassphraseSent() ? "Passphrase Required" : "Unlocked");
} }
private void createUnlockButton() { private void createUnlockButton() {
@ -411,7 +411,7 @@ public class DevicePane extends TitledDescriptionPane {
setExpanded(false); setExpanded(false);
unlockButton.setVisible(false); unlockButton.setVisible(false);
if(device.getNeedsPassphraseSent()) { if(device.isNeedsPassphraseSent()) {
setPassphraseButton.setVisible(true); setPassphraseButton.setVisible(true);
setPassphraseButton.setDisable(true); setPassphraseButton.setDisable(true);
setContent(getPassphraseEntry()); setContent(getPassphraseEntry());

View file

@ -22,7 +22,7 @@ public class UsbStatusButton extends MenuButton {
public void setDevices(List<Device> devices) { public void setDevices(List<Device> devices) {
for(Device device : devices) { for(Device device : devices) {
MenuItem deviceItem = new MenuItem(device.getModel().toDisplayString()); MenuItem deviceItem = new MenuItem(device.getModel().toDisplayString());
if(device.getNeedsPinSent()) { if(device.isNeedsPinSent()) {
deviceItem.setGraphic(getLockIcon()); deviceItem.setGraphic(getLockIcon());
} else { } else {
deviceItem.setGraphic(getLockOpenIcon()); deviceItem.setGraphic(getLockOpenIcon());

View file

@ -41,6 +41,10 @@ public class Device {
return needsPinSent; return needsPinSent;
} }
public Boolean isNeedsPinSent() {
return needsPinSent != null && needsPinSent;
}
public void setNeedsPinSent(Boolean needsPinSent) { public void setNeedsPinSent(Boolean needsPinSent) {
this.needsPinSent = needsPinSent; this.needsPinSent = needsPinSent;
} }
@ -49,6 +53,10 @@ public class Device {
return needsPassphraseSent; return needsPassphraseSent;
} }
public Boolean isNeedsPassphraseSent() {
return needsPassphraseSent != null && needsPassphraseSent;
}
public void setNeedsPassphraseSent(Boolean needsPassphraseSent) { public void setNeedsPassphraseSent(Boolean needsPassphraseSent) {
this.needsPassphraseSent = needsPassphraseSent; this.needsPassphraseSent = needsPassphraseSent;
} }

View file

@ -148,7 +148,7 @@ public class ReceiveController extends WalletFormController implements Initializ
List<Device> addressDevices = devices.stream().filter(device -> walletFingerprints.contains(device.getFingerprint())).collect(Collectors.toList()); List<Device> addressDevices = devices.stream().filter(device -> walletFingerprints.contains(device.getFingerprint())).collect(Collectors.toList());
if(addressDevices.isEmpty()) { if(addressDevices.isEmpty()) {
addressDevices = devices.stream().filter(device -> device.getNeedsPinSent() || device.getNeedsPassphraseSent()).collect(Collectors.toList()); addressDevices = devices.stream().filter(device -> device.isNeedsPinSent() || device.isNeedsPassphraseSent()).collect(Collectors.toList());
} }
if(!addressDevices.isEmpty()) { if(!addressDevices.isEmpty()) {
@ -198,7 +198,7 @@ public class ReceiveController extends WalletFormController implements Initializ
List<Device> possibleDevices = (List<Device>)displayAddress.getUserData(); List<Device> possibleDevices = (List<Device>)displayAddress.getUserData();
if(possibleDevices != null && !possibleDevices.isEmpty()) { if(possibleDevices != null && !possibleDevices.isEmpty()) {
if(possibleDevices.size() > 1 || possibleDevices.get(0).getNeedsPinSent() || possibleDevices.get(0).getNeedsPassphraseSent()) { if(possibleDevices.size() > 1 || possibleDevices.get(0).isNeedsPinSent() || possibleDevices.get(0).isNeedsPassphraseSent()) {
DeviceAddressDialog dlg = new DeviceAddressDialog(wallet, addressDescriptor); DeviceAddressDialog dlg = new DeviceAddressDialog(wallet, addressDescriptor);
dlg.showAndWait(); dlg.showAndWait();
} else { } else {