clear send details on mempool tx, edit wallet output descriptor

This commit is contained in:
Craig Raw 2020-09-25 13:43:55 +02:00
parent 9a395f5dd1
commit ead8fa2207
10 changed files with 76 additions and 6 deletions

2
drongo

@ -1 +1 @@
Subproject commit 5e281982cb3f4711486f53b02b1ea9d9b12a493e Subproject commit 2650dafa66623c1205582c555369a5118a343ccf

View file

@ -5,6 +5,7 @@ import javafx.application.Platform;
import javafx.beans.NamedArg; import javafx.beans.NamedArg;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
public class TextAreaDialog extends Dialog<String> { public class TextAreaDialog extends Dialog<String> {
private final TextArea textArea; private final TextArea textArea;
@ -21,7 +22,9 @@ public class TextAreaDialog extends Dialog<String> {
this.textArea = new TextArea(defaultValue); this.textArea = new TextArea(defaultValue);
this.textArea.setMaxWidth(Double.MAX_VALUE); this.textArea.setMaxWidth(Double.MAX_VALUE);
this.textArea.setWrapText(true); this.textArea.setWrapText(true);
this.textArea.getStyleClass().add("fixed-width");
hbox.getChildren().add(textArea); hbox.getChildren().add(textArea);
HBox.setHgrow(this.textArea, Priority.ALWAYS);
this.defaultValue = defaultValue; this.defaultValue = defaultValue;
@ -38,6 +41,9 @@ public class TextAreaDialog extends Dialog<String> {
ButtonBar.ButtonData data = dialogButton == null ? null : dialogButton.getButtonData(); ButtonBar.ButtonData data = dialogButton == null ? null : dialogButton.getButtonData();
return data == ButtonBar.ButtonData.OK_DONE ? textArea.getText() : null; return data == ButtonBar.ButtonData.OK_DONE ? textArea.getText() : null;
}); });
dialogPane.setPrefWidth(700);
dialogPane.setPrefHeight(400);
} }
public final TextArea getEditor() { public final TextArea getEditor() {

View file

@ -84,7 +84,7 @@ public class KeystoreController extends WalletFormController implements Initiali
Platform.runLater(this::setupValidation); Platform.runLater(this::setupValidation);
selectSourcePane.managedProperty().bind(selectSourcePane.visibleProperty()); selectSourcePane.managedProperty().bind(selectSourcePane.visibleProperty());
if(keystore.isValid()) { if(keystore.isValid() || keystore.getExtendedPublicKey() != null) {
selectSourcePane.setVisible(false); selectSourcePane.setVisible(false);
} }
@ -303,7 +303,7 @@ public class KeystoreController extends WalletFormController implements Initiali
public void update(SettingsChangedEvent event) { public void update(SettingsChangedEvent event) {
if(walletForm.getWallet().equals(event.getWallet()) && event.getType().equals(SettingsChangedEvent.Type.SCRIPT_TYPE)) { if(walletForm.getWallet().equals(event.getWallet()) && event.getType().equals(SettingsChangedEvent.Type.SCRIPT_TYPE)) {
derivation.setPromptText(event.getWallet().getScriptType().getDefaultDerivationPath()); derivation.setPromptText(event.getWallet().getScriptType().getDefaultDerivationPath());
if(!derivation.getText().isEmpty()) { if(derivation.getText() != null && !derivation.getText().isEmpty()) {
String derivationPath = derivation.getText(); String derivationPath = derivation.getText();
derivation.setText(derivationPath + " "); derivation.setText(derivationPath + " ");
derivation.setText(derivationPath); derivation.setText(derivationPath);

View file

@ -562,9 +562,33 @@ public class SendController extends WalletFormController implements Initializabl
@Subscribe @Subscribe
public void walletHistoryChanged(WalletHistoryChangedEvent event) { public void walletHistoryChanged(WalletHistoryChangedEvent event) {
if(event.getWallet().equals(walletForm.getWallet())) { if(event.getWallet().equals(walletForm.getWallet())) {
if(walletTransactionProperty.get() != null && walletTransactionProperty.get().getSelectedUtxos() != null && allSelectedUtxosSpent(event.getHistoryChangedNodes())) {
clear(null);
} else {
updateTransaction(); updateTransaction();
} }
} }
}
private boolean allSelectedUtxosSpent(List<WalletNode> historyChangedNodes) {
Set<BlockTransactionHashIndex> unspentUtxos = new HashSet<>(walletTransactionProperty.get().getSelectedUtxos().keySet());
for(Map.Entry<BlockTransactionHashIndex, WalletNode> selectedUtxoEntry : walletTransactionProperty.get().getSelectedUtxos().entrySet()) {
BlockTransactionHashIndex utxo = selectedUtxoEntry.getKey();
WalletNode utxoWalletNode = selectedUtxoEntry.getValue();
for(WalletNode changedNode : historyChangedNodes) {
if(utxoWalletNode.equals(changedNode)) {
Optional<BlockTransactionHashIndex> spentTxo = changedNode.getTransactionOutputs().stream().filter(txo -> txo.getHash().equals(utxo.getHash()) && txo.getIndex() == utxo.getIndex() && txo.isSpent()).findAny();
if(spentTxo.isPresent()) {
unspentUtxos.remove(utxo);
}
}
}
}
return unspentUtxos.isEmpty();
}
@Subscribe @Subscribe
public void walletEntryLabelChanged(WalletEntryLabelChangedEvent event) { public void walletEntryLabelChanged(WalletEntryLabelChangedEvent event) {

View file

@ -1,6 +1,7 @@
package com.sparrowwallet.sparrow.wallet; package com.sparrowwallet.sparrow.wallet;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import com.sparrowwallet.drongo.OutputDescriptor;
import com.sparrowwallet.drongo.SecureString; import com.sparrowwallet.drongo.SecureString;
import com.sparrowwallet.drongo.crypto.*; import com.sparrowwallet.drongo.crypto.*;
import com.sparrowwallet.drongo.policy.Policy; import com.sparrowwallet.drongo.policy.Policy;
@ -14,6 +15,7 @@ import com.sparrowwallet.sparrow.AppController;
import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.control.CopyableLabel; import com.sparrowwallet.sparrow.control.CopyableLabel;
import com.sparrowwallet.sparrow.control.DescriptorArea; import com.sparrowwallet.sparrow.control.DescriptorArea;
import com.sparrowwallet.sparrow.control.TextAreaDialog;
import com.sparrowwallet.sparrow.control.WalletPasswordDialog; import com.sparrowwallet.sparrow.control.WalletPasswordDialog;
import com.sparrowwallet.sparrow.event.SettingsChangedEvent; import com.sparrowwallet.sparrow.event.SettingsChangedEvent;
import com.sparrowwallet.sparrow.event.StorageEvent; import com.sparrowwallet.sparrow.event.StorageEvent;
@ -248,6 +250,34 @@ public class SettingsController extends WalletFormController implements Initiali
} }
} }
public void editDescriptor(ActionEvent event) {
OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor(walletForm.getWallet());
String outputDescriptorString = outputDescriptor.toString(walletForm.getWallet().isValid());
TextAreaDialog dialog = new TextAreaDialog(outputDescriptorString);
dialog.setTitle("Edit wallet output descriptor");
dialog.getDialogPane().setHeaderText("Wallet output descriptor:");
Optional<String> text = dialog.showAndWait();
if(text.isPresent() && !text.get().isEmpty() && !text.get().equals(outputDescriptorString)) {
try {
OutputDescriptor editedOutputDescriptor = OutputDescriptor.getOutputDescriptor(text.get());
Wallet editedWallet = editedOutputDescriptor.toWallet();
editedWallet.setName(getWalletForm().getWallet().getName());
keystoreTabs.getTabs().removeAll(keystoreTabs.getTabs());
totalKeystores.unbind();
totalKeystores.setValue(0);
walletForm.setWallet(editedWallet);
initialising = true;
setFieldsFromWallet(editedWallet);
EventManager.get().post(new SettingsChangedEvent(editedWallet, SettingsChangedEvent.Type.POLICY));
} catch(Exception e) {
AppController.showErrorDialog("Invalid output descriptor", e.getMessage());
}
}
}
public void showAdvanced(ActionEvent event) { public void showAdvanced(ActionEvent event) {
AdvancedDialog advancedDialog = new AdvancedDialog(walletForm.getWallet()); AdvancedDialog advancedDialog = new AdvancedDialog(walletForm.getWallet());
advancedDialog.showAndWait(); advancedDialog.showAndWait();

View file

@ -25,6 +25,11 @@ public class SettingsWalletForm extends WalletForm {
return walletCopy; return walletCopy;
} }
@Override
public void setWallet(Wallet wallet) {
this.walletCopy = wallet;
}
@Override @Override
public void revert() { public void revert() {
this.walletCopy = super.getWallet().copy(); this.walletCopy = super.getWallet().copy();

View file

@ -46,6 +46,10 @@ public class WalletForm {
return storage.getWalletFile(); return storage.getWalletFile();
} }
public void setWallet(Wallet wallet) {
throw new UnsupportedOperationException("Only SettingsWalletForm supports setWallet");
}
public void revert() { public void revert() {
throw new UnsupportedOperationException("Only SettingsWalletForm supports revert"); throw new UnsupportedOperationException("Only SettingsWalletForm supports revert");
} }

View file

@ -101,7 +101,7 @@
-fx-border-width: 1px; -fx-border-width: 1px;
} }
.root .duplicate-warning { .root .duplicate-warning, .root #transactionDiagram .fee-warning-icon {
-fx-text-fill: #e06c75; -fx-text-fill: #e06c75;
} }

View file

@ -27,7 +27,7 @@
-fx-padding: 3 5; -fx-padding: 3 5;
} }
.id { .id, .fixed-width {
-fx-font-size: 13px; -fx-font-size: 13px;
-fx-font-family: 'Roboto Mono'; -fx-font-family: 'Roboto Mono';
} }

View file

@ -79,6 +79,7 @@
<DescriptorArea fx:id="descriptor" editable="false" styleClass="uneditable-codearea" prefHeight="27" maxHeight="27" /> <DescriptorArea fx:id="descriptor" editable="false" styleClass="uneditable-codearea" prefHeight="27" maxHeight="27" />
</content> </content>
</VirtualizedScrollPane> </VirtualizedScrollPane>
<Button text="Edit..." onAction="#editDescriptor" />
</Field> </Field>
</Fieldset> </Fieldset>
</Form> </Form>