mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-02 20:36:44 +00:00
make all wallet addresses non-editable once child wallets are added
This commit is contained in:
parent
a3e4342d7d
commit
b0877d94bf
4 changed files with 65 additions and 5 deletions
|
@ -27,7 +27,11 @@ public class TextAreaDialog extends Dialog<String> {
|
|||
this("");
|
||||
}
|
||||
|
||||
public TextAreaDialog(@NamedArg("defaultValue") String defaultValue) {
|
||||
public TextAreaDialog(String defaultValue) {
|
||||
this(defaultValue, true);
|
||||
}
|
||||
|
||||
public TextAreaDialog(@NamedArg("defaultValue") String defaultValue, @NamedArg("editable") boolean editable) {
|
||||
final DialogPane dialogPane = new TextAreaDialogPane();
|
||||
setDialogPane(dialogPane);
|
||||
|
||||
|
@ -39,6 +43,7 @@ public class TextAreaDialog extends Dialog<String> {
|
|||
this.textArea.setMaxWidth(Double.MAX_VALUE);
|
||||
this.textArea.setWrapText(true);
|
||||
this.textArea.getStyleClass().add("fixed-width");
|
||||
this.textArea.setEditable(editable);
|
||||
hbox.getChildren().add(textArea);
|
||||
HBox.setHgrow(this.textArea, Priority.ALWAYS);
|
||||
|
||||
|
@ -49,10 +54,13 @@ public class TextAreaDialog extends Dialog<String> {
|
|||
AppServices.setStageIcon(dialogPane.getScene().getWindow());
|
||||
|
||||
dialogPane.getStyleClass().add("text-input-dialog");
|
||||
dialogPane.getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
|
||||
dialogPane.getButtonTypes().add(ButtonType.OK);
|
||||
if(editable) {
|
||||
dialogPane.getButtonTypes().add(ButtonType.CANCEL);
|
||||
|
||||
final ButtonType scanButtonType = new javafx.scene.control.ButtonType("Scan QR", ButtonBar.ButtonData.LEFT);
|
||||
dialogPane.getButtonTypes().add(scanButtonType);
|
||||
final ButtonType scanButtonType = new javafx.scene.control.ButtonType("Scan QR", ButtonBar.ButtonData.LEFT);
|
||||
dialogPane.getButtonTypes().add(scanButtonType);
|
||||
}
|
||||
|
||||
Platform.runLater(textArea::requestFocus);
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.sparrowwallet.drongo.wallet.Wallet;
|
|||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.control.*;
|
||||
import com.sparrowwallet.sparrow.event.ChildWalletAddedEvent;
|
||||
import com.sparrowwallet.sparrow.event.StorageEvent;
|
||||
import com.sparrowwallet.sparrow.event.TimedEvent;
|
||||
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
|
||||
|
@ -161,6 +162,8 @@ public class KeystoreController extends WalletFormController implements Initiali
|
|||
}
|
||||
scanXpubQR.setVisible(!valid);
|
||||
});
|
||||
|
||||
setInputFieldsDisabled(!walletForm.getWallet().isMasterWallet() || !walletForm.getWallet().getChildWallets().isEmpty());
|
||||
}
|
||||
|
||||
private void setXpubContext(ExtendedKey extendedKey) {
|
||||
|
@ -408,6 +411,20 @@ public class KeystoreController extends WalletFormController implements Initiali
|
|||
}
|
||||
}
|
||||
|
||||
private void setInputFieldsDisabled(boolean disabled) {
|
||||
setEditable(fingerprint, !disabled);
|
||||
setEditable(derivation, !disabled);
|
||||
setEditable(xpub, !disabled);
|
||||
importButton.setDisable(disabled);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void childWalletAdded(ChildWalletAddedEvent event) {
|
||||
if(event.getMasterWalletId().equals(walletForm.getWalletId())) {
|
||||
setInputFieldsDisabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void update(SettingsChangedEvent event) {
|
||||
if(walletForm.getWallet().equals(event.getWallet()) && event.getType().equals(SettingsChangedEvent.Type.SCRIPT_TYPE)) {
|
||||
|
|
|
@ -53,6 +53,12 @@ public class SettingsController extends WalletFormController implements Initiali
|
|||
@FXML
|
||||
private Button showDescriptorQR;
|
||||
|
||||
@FXML
|
||||
private Button editDescriptor;
|
||||
|
||||
@FXML
|
||||
private Button showDescriptor;
|
||||
|
||||
@FXML
|
||||
private ComboBox<ScriptType> scriptType;
|
||||
|
||||
|
@ -190,6 +196,9 @@ public class SettingsController extends WalletFormController implements Initiali
|
|||
showDescriptorQR.managedProperty().bind(showDescriptorQR.visibleProperty());
|
||||
showDescriptorQR.prefHeightProperty().bind(descriptor.prefHeightProperty());
|
||||
showDescriptorQR.visibleProperty().bind(scanDescriptorQR.visibleProperty().not());
|
||||
editDescriptor.managedProperty().bind(editDescriptor.visibleProperty());
|
||||
showDescriptor.managedProperty().bind(showDescriptor.visibleProperty());
|
||||
showDescriptor.visibleProperty().bind(editDescriptor.visibleProperty().not());
|
||||
|
||||
revert.setOnAction(event -> {
|
||||
keystoreTabs.getTabs().removeAll(keystoreTabs.getTabs());
|
||||
|
@ -207,6 +216,7 @@ public class SettingsController extends WalletFormController implements Initiali
|
|||
});
|
||||
|
||||
setFieldsFromWallet(walletForm.getWallet());
|
||||
setInputFieldsDisabled(!walletForm.getWallet().isMasterWallet() || !walletForm.getWallet().getChildWallets().isEmpty());
|
||||
}
|
||||
|
||||
private void clearKeystoreTabs() {
|
||||
|
@ -389,6 +399,16 @@ public class SettingsController extends WalletFormController implements Initiali
|
|||
}
|
||||
}
|
||||
|
||||
public void showDescriptor(ActionEvent event) {
|
||||
OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor(walletForm.getWallet());
|
||||
String outputDescriptorString = outputDescriptor.toString(walletForm.getWallet().isValid());
|
||||
|
||||
TextAreaDialog dialog = new TextAreaDialog(outputDescriptorString, false);
|
||||
dialog.setTitle("Show wallet output descriptor");
|
||||
dialog.getDialogPane().setHeaderText("The wallet configuration is specified in the output descriptor.\nThis wallet is no longer editable - create a new wallet to change the descriptor.");
|
||||
dialog.showAndWait();
|
||||
}
|
||||
|
||||
public void showAdvanced(ActionEvent event) {
|
||||
AdvancedDialog advancedDialog = new AdvancedDialog(walletForm);
|
||||
Optional<Boolean> optApply = advancedDialog.showAndWait();
|
||||
|
@ -422,6 +442,13 @@ public class SettingsController extends WalletFormController implements Initiali
|
|||
}
|
||||
}
|
||||
|
||||
private void setInputFieldsDisabled(boolean disabled) {
|
||||
policyType.setDisable(disabled);
|
||||
scriptType.setDisable(disabled);
|
||||
multisigControl.setDisable(disabled);
|
||||
editDescriptor.setVisible(!disabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String describeKeystore(Keystore keystore) {
|
||||
if(!keystore.isValid()) {
|
||||
|
@ -484,6 +511,13 @@ public class SettingsController extends WalletFormController implements Initiali
|
|||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void childWalletAdded(ChildWalletAddedEvent event) {
|
||||
if(event.getMasterWalletId().equals(walletForm.getWalletId())) {
|
||||
setInputFieldsDisabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveWallet(boolean changePassword, boolean suggestChangePassword) {
|
||||
ECKey existingPubKey = walletForm.getStorage().getEncryptionPubKey();
|
||||
|
||||
|
|
|
@ -99,7 +99,8 @@
|
|||
<Tooltip text="Show as QR code" />
|
||||
</tooltip>
|
||||
</Button>
|
||||
<Button text="Edit..." onAction="#editDescriptor" />
|
||||
<Button fx:id="editDescriptor" text="Edit..." onAction="#editDescriptor" />
|
||||
<Button fx:id="showDescriptor" text="Show..." onAction="#showDescriptor" />
|
||||
</Field>
|
||||
</Fieldset>
|
||||
</Form>
|
||||
|
|
Loading…
Reference in a new issue