mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 21:36:45 +00:00
copy non-xpub value
This commit is contained in:
parent
d5a26fdf5d
commit
dc8a8dd857
1 changed files with 31 additions and 6 deletions
|
@ -24,7 +24,8 @@ import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.Clipboard;
|
||||||
|
import javafx.scene.input.ClipboardContent;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
import org.controlsfx.glyphfont.Glyph;
|
import org.controlsfx.glyphfont.Glyph;
|
||||||
import org.controlsfx.validation.ValidationResult;
|
import org.controlsfx.validation.ValidationResult;
|
||||||
|
@ -98,7 +99,7 @@ public class KeystoreController extends WalletFormController implements Initiali
|
||||||
|
|
||||||
if(keystore.getExtendedPublicKey() != null) {
|
if(keystore.getExtendedPublicKey() != null) {
|
||||||
xpub.setText(keystore.getExtendedPublicKey().toString());
|
xpub.setText(keystore.getExtendedPublicKey().toString());
|
||||||
setXpubTooltip(keystore.getExtendedPublicKey());
|
setXpubContext(keystore.getExtendedPublicKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(keystore.getKeyDerivation() != null) {
|
if(keystore.getKeyDerivation() != null) {
|
||||||
|
@ -125,23 +126,47 @@ public class KeystoreController extends WalletFormController implements Initiali
|
||||||
xpub.textProperty().addListener((observable, oldValue, newValue) -> {
|
xpub.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
if(ExtendedKey.isValid(newValue)) {
|
if(ExtendedKey.isValid(newValue)) {
|
||||||
ExtendedKey extendedKey = ExtendedKey.fromDescriptor(newValue);
|
ExtendedKey extendedKey = ExtendedKey.fromDescriptor(newValue);
|
||||||
setXpubTooltip(extendedKey);
|
setXpubContext(extendedKey);
|
||||||
keystore.setExtendedPublicKey(extendedKey);
|
keystore.setExtendedPublicKey(extendedKey);
|
||||||
EventManager.get().post(new SettingsChangedEvent(walletForm.getWallet(), SettingsChangedEvent.Type.KEYSTORE_XPUB));
|
EventManager.get().post(new SettingsChangedEvent(walletForm.getWallet(), SettingsChangedEvent.Type.KEYSTORE_XPUB));
|
||||||
} else {
|
} else {
|
||||||
xpub.setTooltip(null);
|
xpub.setTooltip(null);
|
||||||
|
xpub.setContextMenu(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setXpubTooltip(ExtendedKey extendedKey) {
|
private void setXpubContext(ExtendedKey extendedKey) {
|
||||||
|
ContextMenu contextMenu = new ContextMenu();
|
||||||
|
MenuItem copyXPub = new MenuItem("Copy xPub");
|
||||||
|
copyXPub.setOnAction(AE -> {
|
||||||
|
contextMenu.hide();
|
||||||
|
ClipboardContent content = new ClipboardContent();
|
||||||
|
content.putString(extendedKey.toString());
|
||||||
|
Clipboard.getSystemClipboard().setContent(content);
|
||||||
|
});
|
||||||
|
contextMenu.getItems().add(copyXPub);
|
||||||
|
|
||||||
ExtendedKey.Header header = ExtendedKey.Header.fromScriptType(walletForm.getWallet().getScriptType(), false);
|
ExtendedKey.Header header = ExtendedKey.Header.fromScriptType(walletForm.getWallet().getScriptType(), false);
|
||||||
if(header != ExtendedKey.Header.xpub) {
|
if(header != ExtendedKey.Header.xpub) {
|
||||||
Tooltip tooltip = new Tooltip(extendedKey.getExtendedKey(header));
|
String otherPub = extendedKey.getExtendedKey(header);
|
||||||
|
|
||||||
|
MenuItem copyOtherPub = new MenuItem("Copy " + header.getName().replace('p', 'P'));
|
||||||
|
copyOtherPub.setOnAction(AE -> {
|
||||||
|
contextMenu.hide();
|
||||||
|
ClipboardContent content = new ClipboardContent();
|
||||||
|
content.putString(otherPub);
|
||||||
|
Clipboard.getSystemClipboard().setContent(content);
|
||||||
|
});
|
||||||
|
contextMenu.getItems().add(copyOtherPub);
|
||||||
|
|
||||||
|
Tooltip tooltip = new Tooltip(otherPub);
|
||||||
xpub.setTooltip(tooltip);
|
xpub.setTooltip(tooltip);
|
||||||
} else {
|
} else {
|
||||||
xpub.setTooltip(null);
|
xpub.setTooltip(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xpub.setContextMenu(contextMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectSource(ActionEvent event) {
|
public void selectSource(ActionEvent event) {
|
||||||
|
@ -309,7 +334,7 @@ public class KeystoreController extends WalletFormController implements Initiali
|
||||||
derivation.setText(derivationPath);
|
derivation.setText(derivationPath);
|
||||||
}
|
}
|
||||||
if(keystore.getExtendedPublicKey() != null) {
|
if(keystore.getExtendedPublicKey() != null) {
|
||||||
setXpubTooltip(keystore.getExtendedPublicKey());
|
setXpubContext(keystore.getExtendedPublicKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue