From dbfed3143273b8a9507c926cae7709e3e7a874b9 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 22 Jun 2021 16:00:15 +0200 Subject: [PATCH] add format toggle to message signing dialog (electrum or trezor) --- .../sparrow/control/MessageSignDialog.java | 33 ++++++++++++++++++- .../sparrow/glyphfont/FontAwesome5.java | 1 + .../sparrow/wallet/ReceiveController.java | 3 ++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/MessageSignDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/MessageSignDialog.java index ba7e8189..c00b329e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/MessageSignDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/MessageSignDialog.java @@ -24,6 +24,7 @@ import javafx.scene.control.*; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.VBox; +import org.controlsfx.control.SegmentedButton; import org.controlsfx.validation.ValidationResult; import org.controlsfx.validation.ValidationSupport; import org.controlsfx.validation.decoration.StyleClassValidationDecoration; @@ -44,6 +45,9 @@ public class MessageSignDialog extends Dialog { private final TextField address; private final TextArea message; private final TextArea signature; + private final ToggleGroup formatGroup; + private final ToggleButton formatTrezor; + private final ToggleButton formatElectrum; private final Wallet wallet; private WalletNode walletNode; private boolean electrumSignatureFormat; @@ -144,7 +148,22 @@ public class MessageSignDialog extends Dialog { signature.setWrapText(true); signatureField.getInputs().add(signature); - fieldset.getChildren().addAll(addressField, messageField, signatureField); + Field formatField = new Field(); + formatField.setText("Format:"); + formatGroup = new ToggleGroup(); + formatElectrum = new ToggleButton("Standard (Electrum)"); + formatTrezor = new ToggleButton("BIP137 (Trezor)"); + SegmentedButton formatButtons = new SegmentedButton(formatElectrum, formatTrezor); + formatButtons.setToggleGroup(formatGroup); + formatField.getInputs().add(formatButtons); + + formatGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> { + electrumSignatureFormat = (newValue == formatElectrum); + }); + + formatButtons.setDisable(wallet != null && walletNode != null && wallet.getScriptType() == ScriptType.P2PKH); + + fieldset.getChildren().addAll(addressField, messageField, signatureField, formatField); form.getChildren().add(fieldset); dialogPane.setContent(form); @@ -153,6 +172,7 @@ public class MessageSignDialog extends Dialog { address.setEditable(false); message.setEditable(false); signature.setEditable(false); + formatButtons.setDisable(true); } ButtonType signButtonType = new javafx.scene.control.ButtonType("Sign", ButtonBar.ButtonData.BACK_PREVIOUS); @@ -225,6 +245,16 @@ public class MessageSignDialog extends Dialog { AppServices.moveToActiveWindowScreen(this); setResultConverter(dialogButton -> dialogButton == signButtonType || dialogButton == verifyButtonType ? ButtonBar.ButtonData.APPLY : dialogButton.getButtonData()); + + Platform.runLater(() -> { + if(address.getText().isEmpty()) { + address.requestFocus(); + } else if(message.getText().isEmpty()) { + message.requestFocus(); + } + + formatGroup.selectToggle(formatElectrum); + }); } private Address getAddress()throws InvalidAddressException { @@ -241,6 +271,7 @@ public class MessageSignDialog extends Dialog { * @param electrumSignatureFormat */ public void setElectrumSignatureFormat(boolean electrumSignatureFormat) { + formatGroup.selectToggle(electrumSignatureFormat ? formatElectrum : formatTrezor); this.electrumSignatureFormat = electrumSignatureFormat; } diff --git a/src/main/java/com/sparrowwallet/sparrow/glyphfont/FontAwesome5.java b/src/main/java/com/sparrowwallet/sparrow/glyphfont/FontAwesome5.java index e64db9bb..5dc5a873 100644 --- a/src/main/java/com/sparrowwallet/sparrow/glyphfont/FontAwesome5.java +++ b/src/main/java/com/sparrowwallet/sparrow/glyphfont/FontAwesome5.java @@ -19,6 +19,7 @@ public class FontAwesome5 extends GlyphFont { ANGLE_DOUBLE_RIGHT('\uf101'), ARROW_DOWN('\uf063'), ARROW_UP('\uf062'), + BAN('\uf05e'), BTC('\uf15a'), CAMERA('\uf030'), CHECK_CIRCLE('\uf058'), diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/ReceiveController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/ReceiveController.java index ed571041..3255c50f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/ReceiveController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/ReceiveController.java @@ -255,6 +255,9 @@ public class ReceiveController extends WalletFormController implements Initializ messageSignDialog.setElectrumSignatureFormat(true); Stage stage = (Stage)messageSignDialog.getDialogPane().getScene().getWindow(); stage.setAlwaysOnTop(true); + messageSignDialog.setOnShown(event -> { + stage.setAlwaysOnTop(false); + }); Optional buttonData = messageSignDialog.showAndWait(); if(buttonData.isPresent() && buttonData.get() == ButtonBar.ButtonData.OK_DONE) { Address address = getWalletForm().getWallet().getAddress(currentEntry.getNode());