mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
Support replacing existing keystore with watch only keystore
This commit is contained in:
parent
10e4d8843d
commit
7d7c5e5064
3 changed files with 24 additions and 10 deletions
|
@ -1,17 +1,16 @@
|
||||||
package com.sparrowwallet.sparrow.keystoreimport;
|
package com.sparrowwallet.sparrow.keystoreimport;
|
||||||
|
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
import com.sparrowwallet.drongo.KeyDerivation;
|
||||||
import com.sparrowwallet.drongo.wallet.Keystore;
|
import com.sparrowwallet.drongo.wallet.Keystore;
|
||||||
import com.sparrowwallet.drongo.wallet.KeystoreSource;
|
import com.sparrowwallet.drongo.wallet.KeystoreSource;
|
||||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||||
|
import com.sparrowwallet.drongo.wallet.WalletModel;
|
||||||
import com.sparrowwallet.sparrow.AppController;
|
import com.sparrowwallet.sparrow.AppController;
|
||||||
import com.sparrowwallet.sparrow.EventManager;
|
import com.sparrowwallet.sparrow.EventManager;
|
||||||
import com.sparrowwallet.sparrow.event.KeystoreImportEvent;
|
import com.sparrowwallet.sparrow.event.KeystoreImportEvent;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.control.ButtonBar;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.ButtonType;
|
|
||||||
import javafx.scene.control.Dialog;
|
|
||||||
import javafx.scene.control.DialogPane;
|
|
||||||
import org.controlsfx.tools.Borders;
|
import org.controlsfx.tools.Borders;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -41,12 +40,13 @@ public class KeystoreImportDialog extends Dialog<Keystore> {
|
||||||
keystoreImportController.initializeView(wallet);
|
keystoreImportController.initializeView(wallet);
|
||||||
keystoreImportController.selectSource(initialSource);
|
keystoreImportController.selectSource(initialSource);
|
||||||
|
|
||||||
|
final ButtonType watchOnlyButtonType = new javafx.scene.control.ButtonType("xPub / Watch Only Wallet", ButtonBar.ButtonData.LEFT);
|
||||||
final ButtonType cancelButtonType = new javafx.scene.control.ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE);
|
final ButtonType cancelButtonType = new javafx.scene.control.ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE);
|
||||||
dialogPane.getButtonTypes().addAll(cancelButtonType);
|
dialogPane.getButtonTypes().addAll(watchOnlyButtonType, cancelButtonType);
|
||||||
dialogPane.setPrefWidth(650);
|
dialogPane.setPrefWidth(650);
|
||||||
dialogPane.setPrefHeight(620);
|
dialogPane.setPrefHeight(620);
|
||||||
|
|
||||||
setResultConverter(dialogButton -> dialogButton != cancelButtonType ? keystore : null);
|
setResultConverter(dialogButton -> dialogButton != cancelButtonType ? getWatchOnlyKeystore() : null);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,14 @@ public class KeystoreImportDialog extends Dialog<Keystore> {
|
||||||
return List.of(KeystoreSource.HW_USB, KeystoreSource.HW_AIRGAPPED, KeystoreSource.SW_SEED);
|
return List.of(KeystoreSource.HW_USB, KeystoreSource.HW_AIRGAPPED, KeystoreSource.SW_SEED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Keystore getWatchOnlyKeystore() {
|
||||||
|
this.keystore = new Keystore();
|
||||||
|
keystore.setSource(KeystoreSource.SW_WATCH);
|
||||||
|
keystore.setWalletModel(WalletModel.SPARROW);
|
||||||
|
keystore.setKeyDerivation(new KeyDerivation("",""));
|
||||||
|
return keystore;
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void keystoreImported(KeystoreImportEvent event) {
|
public void keystoreImported(KeystoreImportEvent event) {
|
||||||
this.keystore = event.getKeystore();
|
this.keystore = event.getKeystore();
|
||||||
|
|
|
@ -259,7 +259,12 @@ public class KeystoreController extends WalletFormController implements Initiali
|
||||||
label.setText(keystore.getLabel());
|
label.setText(keystore.getLabel());
|
||||||
fingerprint.setText(keystore.getKeyDerivation().getMasterFingerprint());
|
fingerprint.setText(keystore.getKeyDerivation().getMasterFingerprint());
|
||||||
derivation.setText(keystore.getKeyDerivation().getDerivationPath());
|
derivation.setText(keystore.getKeyDerivation().getDerivationPath());
|
||||||
|
|
||||||
|
if(keystore.getExtendedPublicKey() != null) {
|
||||||
xpub.setText(keystore.getExtendedPublicKey().toString());
|
xpub.setText(keystore.getExtendedPublicKey().toString());
|
||||||
|
} else {
|
||||||
|
xpub.setText("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
<?import org.controlsfx.control.SegmentedButton?>
|
<?import org.controlsfx.control.SegmentedButton?>
|
||||||
<?import com.sparrowwallet.drongo.wallet.KeystoreSource?>
|
<?import com.sparrowwallet.drongo.wallet.KeystoreSource?>
|
||||||
<?import org.controlsfx.glyphfont.Glyph?>
|
<?import org.controlsfx.glyphfont.Glyph?>
|
||||||
|
<?import com.sparrowwallet.sparrow.control.HelpLabel?>
|
||||||
<StackPane stylesheets="@keystore.css, @settings.css, @../general.css" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.wallet.KeystoreController">
|
<StackPane stylesheets="@keystore.css, @settings.css, @../general.css" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.wallet.KeystoreController">
|
||||||
<padding>
|
<padding>
|
||||||
<Insets left="25.0" right="25.0" />
|
<Insets left="25.0" right="25.0" />
|
||||||
|
@ -40,7 +41,7 @@
|
||||||
<TextField fx:id="label" maxWidth="160"/>
|
<TextField fx:id="label" maxWidth="160"/>
|
||||||
</Field>
|
</Field>
|
||||||
<Field text="Master fingerprint:">
|
<Field text="Master fingerprint:">
|
||||||
<TextField fx:id="fingerprint" maxWidth="80" promptText="ffffffff"/>
|
<TextField fx:id="fingerprint" maxWidth="80" promptText="ffffffff"/> <HelpLabel helpText="A master fingerprint is the first 4 bytes of the master public key hash. It is safe to use any valid value (ffffffff) for Watch Only Wallets." />
|
||||||
</Field>
|
</Field>
|
||||||
<Field text="Derivation:">
|
<Field text="Derivation:">
|
||||||
<TextField fx:id="derivation" maxWidth="200"/>
|
<TextField fx:id="derivation" maxWidth="200"/>
|
||||||
|
@ -80,7 +81,7 @@
|
||||||
<KeystoreSource fx:constant="SW_SEED"/>
|
<KeystoreSource fx:constant="SW_SEED"/>
|
||||||
</userData>
|
</userData>
|
||||||
</ToggleButton>
|
</ToggleButton>
|
||||||
<ToggleButton text="XPUB / Watch Only Wallet" contentDisplay="TOP" wrapText="true" textAlignment="CENTER" toggleGroup="$keystoreSourceToggleGroup" onAction="#selectSource">
|
<ToggleButton text="xPub / Watch Only Wallet" contentDisplay="TOP" wrapText="true" textAlignment="CENTER" toggleGroup="$keystoreSourceToggleGroup" onAction="#selectSource">
|
||||||
<graphic>
|
<graphic>
|
||||||
<Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="20" icon="EYE" />
|
<Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="20" icon="EYE" />
|
||||||
</graphic>
|
</graphic>
|
||||||
|
|
Loading…
Reference in a new issue