keystore source quick chooser

This commit is contained in:
Craig Raw
2020-05-11 11:38:07 +02:00
parent 82a113afc3
commit 9241f4381f
10 changed files with 118 additions and 24 deletions
@@ -43,7 +43,7 @@ public class MainApp extends Application {
KeystoreImportDialog dlg = new KeystoreImportDialog(wallet);
dlg.showAndWait();
// stage.show();
stage.show();
}
public static void main(String[] args) {
@@ -17,6 +17,7 @@ public class FontAwesome5 extends GlyphFont {
public static enum Glyph implements INamedCharacter {
CIRCLE('\uf111'),
EXCLAMATION_CIRCLE('\uf06a'),
EYE('\uf06e'),
LAPTOP('\uf109'),
SD_CARD('\uf7c2'),
WALLET('\uf555');
@@ -4,10 +4,12 @@ import com.sparrowwallet.drongo.wallet.KeystoreSource;
import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.sparrow.AppController;
import com.sparrowwallet.sparrow.io.Device;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.StackPane;
@@ -51,6 +53,15 @@ public class KeystoreImportController implements Initializable {
});
}
public void selectSource(KeystoreSource keystoreSource) {
for(Toggle toggle : importMenu.getToggles()) {
if(toggle.getUserData().equals(keystoreSource)) {
Platform.runLater(() -> importMenu.selectToggle(toggle));
return;
}
}
}
void showUsbDevices(List<Device> devices) {
FXMLLoader loader = setImportPane("hw_usb-devices");
HwUsbDevicesController controller = loader.getController();
@@ -2,6 +2,7 @@ package com.sparrowwallet.sparrow.keystoreimport;
import com.google.common.eventbus.Subscribe;
import com.sparrowwallet.drongo.wallet.Keystore;
import com.sparrowwallet.drongo.wallet.KeystoreSource;
import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.sparrow.AppController;
import com.sparrowwallet.sparrow.EventManager;
@@ -20,6 +21,10 @@ public class KeystoreImportDialog extends Dialog<Keystore> {
private Keystore keystore;
public KeystoreImportDialog(Wallet wallet) {
this(wallet, KeystoreSource.HW_USB);
}
public KeystoreImportDialog(Wallet wallet, KeystoreSource initialSource) {
EventManager.get().register(this);
final DialogPane dialogPane = getDialogPane();
@@ -28,6 +33,7 @@ public class KeystoreImportDialog extends Dialog<Keystore> {
dialogPane.setContent(Borders.wrap(ksiLoader.load()).lineBorder().outerPadding(0).innerPadding(0).buildAll());
keystoreImportController = ksiLoader.getController();
keystoreImportController.initializeView(wallet);
keystoreImportController.selectSource(initialSource);
final ButtonType cancelButtonType = new javafx.scene.control.ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE);
dialogPane.getButtonTypes().addAll(cancelButtonType);
@@ -12,14 +12,13 @@ import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.*;
import javafx.scene.layout.StackPane;
import org.controlsfx.validation.ValidationResult;
import org.controlsfx.validation.ValidationSupport;
import org.controlsfx.validation.Validator;
import org.controlsfx.validation.decoration.StyleClassValidationDecoration;
import tornadofx.control.Form;
import java.net.URL;
import java.util.Optional;
@@ -29,6 +28,9 @@ import java.util.stream.Collectors;
public class KeystoreController extends WalletFormController implements Initializable {
private Keystore keystore;
@FXML
private StackPane selectSourcePane;
@FXML
private Label type;
@@ -60,6 +62,8 @@ public class KeystoreController extends WalletFormController implements Initiali
public void initializeView() {
Platform.runLater(this::setupValidation);
selectSourcePane.managedProperty().bind(selectSourcePane.visibleProperty());
updateType();
label.setText(keystore.getLabel());
@@ -97,6 +101,16 @@ public class KeystoreController extends WalletFormController implements Initiali
});
}
public void selectSource(ActionEvent event) {
ToggleButton sourceButton = (ToggleButton)event.getSource();
KeystoreSource keystoreSource = (KeystoreSource)sourceButton.getUserData();
if(keystoreSource != KeystoreSource.SW_WATCH) {
launchImportDialog(keystoreSource);
} else {
selectSourcePane.setVisible(false);
}
}
public TextField getLabel() {
return label;
}
@@ -150,27 +164,33 @@ public class KeystoreController extends WalletFormController implements Initiali
return "Software Wallet";
case SW_WATCH:
default:
return "Software Wallet (Watch Only)";
return "Watch Only Wallet";
}
}
public void importKeystore(ActionEvent event) {
KeystoreImportDialog dlg = new KeystoreImportDialog(getWalletForm().getWallet());
Optional<Keystore> result = dlg.showAndWait();
if(result.isPresent()) {
Keystore importedKeystore = result.get();
keystore.setSource(importedKeystore.getSource());
keystore.setWalletModel(importedKeystore.getWalletModel());
keystore.setLabel(importedKeystore.getLabel());
keystore.setKeyDerivation(importedKeystore.getKeyDerivation());
keystore.setExtendedPublicKey(importedKeystore.getExtendedPublicKey());
keystore.setSeed(importedKeystore.getSeed());
launchImportDialog(KeystoreSource.HW_USB);
}
updateType();
label.setText(keystore.getLabel());
fingerprint.setText(keystore.getKeyDerivation().getMasterFingerprint());
derivation.setText(keystore.getKeyDerivation().getDerivationPath());
xpub.setText(keystore.getExtendedPublicKey().toString());
private void launchImportDialog(KeystoreSource initialSource) {
KeystoreImportDialog dlg = new KeystoreImportDialog(getWalletForm().getWallet(), initialSource);
Optional<Keystore> result = dlg.showAndWait();
if (result.isPresent()) {
selectSourcePane.setVisible(false);
Keystore importedKeystore = result.get();
keystore.setSource(importedKeystore.getSource());
keystore.setWalletModel(importedKeystore.getWalletModel());
keystore.setLabel(importedKeystore.getLabel());
keystore.setKeyDerivation(importedKeystore.getKeyDerivation());
keystore.setExtendedPublicKey(importedKeystore.getExtendedPublicKey());
keystore.setSeed(importedKeystore.getSeed());
updateType();
label.setText(keystore.getLabel());
fingerprint.setText(keystore.getKeyDerivation().getMasterFingerprint());
derivation.setText(keystore.getKeyDerivation().getDerivationPath());
xpub.setText(keystore.getExtendedPublicKey().toString());
}
}
}