mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-24 12:46:45 +00:00
add format toggle to message signing dialog (electrum or trezor)
This commit is contained in:
parent
6f3d4e224e
commit
dbfed31432
3 changed files with 36 additions and 1 deletions
|
@ -24,6 +24,7 @@ import javafx.scene.control.*;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
import org.controlsfx.control.SegmentedButton;
|
||||||
import org.controlsfx.validation.ValidationResult;
|
import org.controlsfx.validation.ValidationResult;
|
||||||
import org.controlsfx.validation.ValidationSupport;
|
import org.controlsfx.validation.ValidationSupport;
|
||||||
import org.controlsfx.validation.decoration.StyleClassValidationDecoration;
|
import org.controlsfx.validation.decoration.StyleClassValidationDecoration;
|
||||||
|
@ -44,6 +45,9 @@ public class MessageSignDialog extends Dialog<ButtonBar.ButtonData> {
|
||||||
private final TextField address;
|
private final TextField address;
|
||||||
private final TextArea message;
|
private final TextArea message;
|
||||||
private final TextArea signature;
|
private final TextArea signature;
|
||||||
|
private final ToggleGroup formatGroup;
|
||||||
|
private final ToggleButton formatTrezor;
|
||||||
|
private final ToggleButton formatElectrum;
|
||||||
private final Wallet wallet;
|
private final Wallet wallet;
|
||||||
private WalletNode walletNode;
|
private WalletNode walletNode;
|
||||||
private boolean electrumSignatureFormat;
|
private boolean electrumSignatureFormat;
|
||||||
|
@ -144,7 +148,22 @@ public class MessageSignDialog extends Dialog<ButtonBar.ButtonData> {
|
||||||
signature.setWrapText(true);
|
signature.setWrapText(true);
|
||||||
signatureField.getInputs().add(signature);
|
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);
|
form.getChildren().add(fieldset);
|
||||||
dialogPane.setContent(form);
|
dialogPane.setContent(form);
|
||||||
|
|
||||||
|
@ -153,6 +172,7 @@ public class MessageSignDialog extends Dialog<ButtonBar.ButtonData> {
|
||||||
address.setEditable(false);
|
address.setEditable(false);
|
||||||
message.setEditable(false);
|
message.setEditable(false);
|
||||||
signature.setEditable(false);
|
signature.setEditable(false);
|
||||||
|
formatButtons.setDisable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonType signButtonType = new javafx.scene.control.ButtonType("Sign", ButtonBar.ButtonData.BACK_PREVIOUS);
|
ButtonType signButtonType = new javafx.scene.control.ButtonType("Sign", ButtonBar.ButtonData.BACK_PREVIOUS);
|
||||||
|
@ -225,6 +245,16 @@ public class MessageSignDialog extends Dialog<ButtonBar.ButtonData> {
|
||||||
|
|
||||||
AppServices.moveToActiveWindowScreen(this);
|
AppServices.moveToActiveWindowScreen(this);
|
||||||
setResultConverter(dialogButton -> dialogButton == signButtonType || dialogButton == verifyButtonType ? ButtonBar.ButtonData.APPLY : dialogButton.getButtonData());
|
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 {
|
private Address getAddress()throws InvalidAddressException {
|
||||||
|
@ -241,6 +271,7 @@ public class MessageSignDialog extends Dialog<ButtonBar.ButtonData> {
|
||||||
* @param electrumSignatureFormat
|
* @param electrumSignatureFormat
|
||||||
*/
|
*/
|
||||||
public void setElectrumSignatureFormat(boolean electrumSignatureFormat) {
|
public void setElectrumSignatureFormat(boolean electrumSignatureFormat) {
|
||||||
|
formatGroup.selectToggle(electrumSignatureFormat ? formatElectrum : formatTrezor);
|
||||||
this.electrumSignatureFormat = electrumSignatureFormat;
|
this.electrumSignatureFormat = electrumSignatureFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ public class FontAwesome5 extends GlyphFont {
|
||||||
ANGLE_DOUBLE_RIGHT('\uf101'),
|
ANGLE_DOUBLE_RIGHT('\uf101'),
|
||||||
ARROW_DOWN('\uf063'),
|
ARROW_DOWN('\uf063'),
|
||||||
ARROW_UP('\uf062'),
|
ARROW_UP('\uf062'),
|
||||||
|
BAN('\uf05e'),
|
||||||
BTC('\uf15a'),
|
BTC('\uf15a'),
|
||||||
CAMERA('\uf030'),
|
CAMERA('\uf030'),
|
||||||
CHECK_CIRCLE('\uf058'),
|
CHECK_CIRCLE('\uf058'),
|
||||||
|
|
|
@ -255,6 +255,9 @@ public class ReceiveController extends WalletFormController implements Initializ
|
||||||
messageSignDialog.setElectrumSignatureFormat(true);
|
messageSignDialog.setElectrumSignatureFormat(true);
|
||||||
Stage stage = (Stage)messageSignDialog.getDialogPane().getScene().getWindow();
|
Stage stage = (Stage)messageSignDialog.getDialogPane().getScene().getWindow();
|
||||||
stage.setAlwaysOnTop(true);
|
stage.setAlwaysOnTop(true);
|
||||||
|
messageSignDialog.setOnShown(event -> {
|
||||||
|
stage.setAlwaysOnTop(false);
|
||||||
|
});
|
||||||
Optional<ButtonBar.ButtonData> buttonData = messageSignDialog.showAndWait();
|
Optional<ButtonBar.ButtonData> buttonData = messageSignDialog.showAndWait();
|
||||||
if(buttonData.isPresent() && buttonData.get() == ButtonBar.ButtonData.OK_DONE) {
|
if(buttonData.isPresent() && buttonData.get() == ButtonBar.ButtonData.OK_DONE) {
|
||||||
Address address = getWalletForm().getWallet().getAddress(currentEntry.getNode());
|
Address address = getWalletForm().getWallet().getAddress(currentEntry.getNode());
|
||||||
|
|
Loading…
Reference in a new issue