Browse Source

dont show message sign context menu item when message signing cant be performed

terminal
Craig Raw 3 years ago
parent
commit
0502eec0cd
  1. 2
      drongo
  2. 12
      src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java
  3. 4
      src/main/java/com/sparrowwallet/sparrow/control/MessageSignDialog.java

2
drongo

@ -1 +1 @@
Subproject commit 5013a0ef2fd0c80d4a568891c77361ed0c436173 Subproject commit e53574ea542aa8311dba61e18658482611d74632

12
src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java

@ -3,6 +3,7 @@ package com.sparrowwallet.sparrow.control;
import com.sparrowwallet.drongo.KeyPurpose; import com.sparrowwallet.drongo.KeyPurpose;
import com.sparrowwallet.drongo.Utils; import com.sparrowwallet.drongo.Utils;
import com.sparrowwallet.drongo.address.Address; import com.sparrowwallet.drongo.address.Address;
import com.sparrowwallet.drongo.protocol.ScriptType;
import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.drongo.protocol.TransactionInput; import com.sparrowwallet.drongo.protocol.TransactionInput;
import com.sparrowwallet.drongo.protocol.TransactionOutput; import com.sparrowwallet.drongo.protocol.TransactionOutput;
@ -118,8 +119,7 @@ public class EntryCell extends TreeTableCell<Entry, Entry> {
}); });
actionBox.getChildren().add(receiveButton); actionBox.getChildren().add(receiveButton);
if(nodeEntry.getWallet().getKeystores().size() == 1 && if(canSignMessage(nodeEntry.getWallet())) {
(nodeEntry.getWallet().getKeystores().get(0).hasPrivateKey() || nodeEntry.getWallet().getKeystores().get(0).getSource() == KeystoreSource.HW_USB)) {
Button signMessageButton = new Button(""); Button signMessageButton = new Button("");
signMessageButton.setGraphic(getSignMessageGlyph()); signMessageButton.setGraphic(getSignMessageGlyph());
signMessageButton.setOnAction(event -> { signMessageButton.setOnAction(event -> {
@ -127,7 +127,6 @@ public class EntryCell extends TreeTableCell<Entry, Entry> {
messageSignDialog.showAndWait(); messageSignDialog.showAndWait();
}); });
actionBox.getChildren().add(signMessageButton); actionBox.getChildren().add(signMessageButton);
setContextMenu(new AddressContextMenu(address, nodeEntry.getOutputDescriptor(), nodeEntry));
} }
setGraphic(actionBox); setGraphic(actionBox);
@ -268,6 +267,11 @@ public class EntryCell extends TreeTableCell<Entry, Entry> {
Platform.runLater(() -> EventManager.get().post(new SpendUtxoEvent(transactionEntry.getWallet(), List.of(utxo), List.of(payment), blockTransaction.getFee(), false))); Platform.runLater(() -> EventManager.get().post(new SpendUtxoEvent(transactionEntry.getWallet(), List.of(utxo), List.of(payment), blockTransaction.getFee(), false)));
} }
private static boolean canSignMessage(Wallet wallet) {
return wallet.getKeystores().size() == 1 && wallet.getScriptType() != ScriptType.P2TR &&
(wallet.getKeystores().get(0).hasPrivateKey() || wallet.getKeystores().get(0).getSource() == KeystoreSource.HW_USB);
}
private static boolean containsWalletOutputs(TransactionEntry transactionEntry) { private static boolean containsWalletOutputs(TransactionEntry transactionEntry) {
return transactionEntry.getChildren().stream() return transactionEntry.getChildren().stream()
.filter(e -> e instanceof HashIndexEntry) .filter(e -> e instanceof HashIndexEntry)
@ -463,7 +467,7 @@ public class EntryCell extends TreeTableCell<Entry, Entry> {
}); });
getItems().add(receiveToAddress); getItems().add(receiveToAddress);
if(nodeEntry != null) { if(nodeEntry != null && canSignMessage(nodeEntry.getWallet())) {
MenuItem signVerifyMessage = new MenuItem("Sign/Verify Message"); MenuItem signVerifyMessage = new MenuItem("Sign/Verify Message");
signVerifyMessage.setGraphic(getSignMessageGlyph()); signVerifyMessage.setGraphic(getSignMessageGlyph());
signVerifyMessage.setOnAction(AE -> { signVerifyMessage.setOnAction(AE -> {

4
src/main/java/com/sparrowwallet/sparrow/control/MessageSignDialog.java

@ -282,8 +282,8 @@ public class MessageSignDialog extends Dialog<ButtonBar.ButtonData> {
private boolean isValidAddress() { private boolean isValidAddress() {
try { try {
getAddress(); Address address = getAddress();
return true; return address.getScriptType() != ScriptType.P2TR;
} catch (InvalidAddressException e) { } catch (InvalidAddressException e) {
return false; return false;
} }

Loading…
Cancel
Save