add warnings to block time, set current height, close once

This commit is contained in:
Craig Raw 2020-08-20 17:30:39 +02:00
parent ca64a1d307
commit 03c488cf4d
10 changed files with 67 additions and 7 deletions

View file

@ -495,8 +495,10 @@ public class AppController implements Initializable {
String fileName = selectedTab.getText();
if(fileName != null && !fileName.isEmpty()) {
if(transactionTabData.getPsbt() != null && !fileName.endsWith(".psbt")) {
fileName += ".psbt";
if(transactionTabData.getPsbt() != null) {
if(!fileName.endsWith(".psbt")) {
fileName += ".psbt";
}
} else if(!fileName.endsWith(".txn")) {
fileName += ".txn";
}

View file

@ -32,6 +32,5 @@ public class DeviceAddressDialog extends DeviceDialog<String> {
@Subscribe
public void addressDisplayed(AddressDisplayedEvent event) {
setResult(event.getAddress());
this.close();
}
}

View file

@ -30,7 +30,6 @@ public class DeviceSignDialog extends DeviceDialog<PSBT> {
public void psbtSigned(PSBTSignedEvent event) {
if(psbt == event.getPsbt()) {
setResult(event.getSignedPsbt());
this.close();
}
}
}

View file

@ -69,6 +69,5 @@ public class WalletExportDialog extends Dialog<Wallet> {
public void walletExported(WalletExportEvent event) {
wallet = event.getWallet();
setResult(wallet);
this.close();
}
}

View file

@ -56,6 +56,5 @@ public class WalletImportDialog extends Dialog<Wallet> {
public void walletImported(WalletImportEvent event) {
wallet = event.getWallet();
setResult(wallet);
this.close();
}
}

View file

@ -23,6 +23,7 @@ public class FontAwesome5 extends GlyphFont {
CIRCLE('\uf111'),
COINS('\uf51e'),
EXCLAMATION_CIRCLE('\uf06a'),
EXCLAMATION_TRIANGLE('\uf071'),
EXTERNAL_LINK_ALT('\uf35d'),
ELLIPSIS_H('\uf141'),
EYE('\uf06e'),

View file

@ -59,6 +59,5 @@ public class KeystoreImportDialog extends Dialog<Keystore> {
public void keystoreImported(KeystoreImportEvent event) {
this.keystore = event.getKeystore();
setResult(keystore);
this.close();
}
}

View file

@ -96,9 +96,18 @@ public class HeadersController extends TransactionFormController implements Init
@FXML
private Spinner<Integer> locktimeBlock;
@FXML
private Hyperlink locktimeCurrentHeight;
@FXML
private Label futureBlockWarning;
@FXML
private DateTimePicker locktimeDate;
@FXML
private Label futureDateWarning;
@FXML
private CopyableLabel size;
@ -236,6 +245,8 @@ public class HeadersController extends TransactionFormController implements Init
locktimeFieldset.getChildren().add(locktimeBlockField);
Integer block = locktimeBlock.getValue();
if(block != null) {
locktimeCurrentHeight.setVisible(headersForm.isEditable() && AppController.getCurrentBlockHeight() != null && block < AppController.getCurrentBlockHeight());
futureBlockWarning.setVisible(AppController.getCurrentBlockHeight() != null && block > AppController.getCurrentBlockHeight());
tx.setLocktime(block);
if(old_toggle != null) {
EventManager.get().post(new TransactionChangedEvent(tx));
@ -249,6 +260,7 @@ public class HeadersController extends TransactionFormController implements Init
LocalDateTime date = locktimeDate.getDateTimeValue();
if(date != null) {
locktimeDate.setDateTimeValue(date);
futureDateWarning.setVisible(date.isAfter(LocalDateTime.now()));
tx.setLocktime(date.toEpochSecond(OffsetDateTime.now(ZoneId.systemDefault()).getOffset()));
if(old_toggle != null) {
EventManager.get().post(new TransactionChangedEvent(tx));
@ -258,6 +270,13 @@ public class HeadersController extends TransactionFormController implements Init
}
});
locktimeCurrentHeight.managedProperty().bind(locktimeCurrentHeight.visibleProperty());
locktimeCurrentHeight.setVisible(false);
futureBlockWarning.managedProperty().bind(futureBlockWarning.visibleProperty());
futureBlockWarning.setVisible(false);
futureDateWarning.managedProperty().bind(futureDateWarning.visibleProperty());
futureDateWarning.setVisible(false);
locktimeNone.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, (int)Transaction.MAX_BLOCK_LOCKTIME-1, 0));
if(tx.getLocktime() < Transaction.MAX_BLOCK_LOCKTIME) {
locktimeBlock.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, (int)Transaction.MAX_BLOCK_LOCKTIME-1, (int)tx.getLocktime()));
@ -277,6 +296,8 @@ public class HeadersController extends TransactionFormController implements Init
locktimeBlock.valueProperty().addListener((obs, oldValue, newValue) -> {
tx.setLocktime(newValue);
locktimeCurrentHeight.setVisible(headersForm.isEditable() && AppController.getCurrentBlockHeight() != null && newValue < AppController.getCurrentBlockHeight());
futureBlockWarning.setVisible(AppController.getCurrentBlockHeight() != null && newValue > AppController.getCurrentBlockHeight());
if(oldValue != null) {
EventManager.get().post(new TransactionChangedEvent(tx));
EventManager.get().post(new TransactionLocktimeChangedEvent(tx));
@ -286,6 +307,7 @@ public class HeadersController extends TransactionFormController implements Init
locktimeDate.setFormat(LOCKTIME_DATE_FORMAT);
locktimeDate.dateTimeValueProperty().addListener((obs, oldValue, newValue) -> {
tx.setLocktime(newValue.toEpochSecond(OffsetDateTime.now(ZoneId.systemDefault()).getOffset()));
futureDateWarning.setVisible(newValue.isAfter(LocalDateTime.now()));
if(oldValue != null) {
EventManager.get().post(new TransactionChangedEvent(tx));
}
@ -296,6 +318,7 @@ public class HeadersController extends TransactionFormController implements Init
locktimeDateType.setDisable(!headersForm.isEditable());
locktimeBlock.setDisable(!headersForm.isEditable());
locktimeDate.setDisable(!headersForm.isEditable());
locktimeCurrentHeight.setDisable(!headersForm.isEditable());
updateSize();
@ -539,6 +562,13 @@ public class HeadersController extends TransactionFormController implements Init
Clipboard.getSystemClipboard().setContent(content);
}
public void setLocktimeToCurrentHeight(ActionEvent event) {
if(AppController.getCurrentBlockHeight() != null && locktimeBlock.isEditable()) {
locktimeBlock.getValueFactory().setValue(AppController.getCurrentBlockHeight());
Platform.runLater(() -> locktimeBlockType.requestFocus());
}
}
public void openWallet(ActionEvent event) {
EventManager.get().post(new RequestWalletOpenEvent());
}
@ -758,6 +788,7 @@ public class HeadersController extends TransactionFormController implements Init
locktimeBlock.setDisable(!locktimeEnabled);
locktimeDateType.setDisable(!locktimeEnabled);
locktimeDate.setDisable(!locktimeEnabled);
locktimeCurrentHeight.setDisable(!locktimeEnabled);
}
}
@ -844,6 +875,7 @@ public class HeadersController extends TransactionFormController implements Init
locktimeDateType.setDisable(true);
locktimeBlock.setDisable(true);
locktimeDate.setDisable(true);
locktimeCurrentHeight.setVisible(false);
updateTxId();
headersForm.setSigningWallet(event.getSigningWallet());
@ -953,5 +985,8 @@ public class HeadersController extends TransactionFormController implements Init
if(headersForm.getBlockTransaction() != null) {
updateBlockchainForm(headersForm.getBlockTransaction(), event.getHeight());
}
if(futureBlockWarning.isVisible()) {
futureBlockWarning.setVisible(AppController.getCurrentBlockHeight() != null && locktimeBlock.getValue() > event.getHeight());
}
}
}

View file

@ -20,6 +20,15 @@
.locktime { -fx-fill: #986801 }
#locktimeCurrentHeight {
-fx-padding: 0 0 0 12;
}
.future-warning {
-fx-text-fill: rgb(238, 210, 2);
-fx-padding: 0 0 0 12;
}
.unfinalized-txid {
-fx-text-fill: #a0a1a7;
}

View file

@ -23,6 +23,7 @@
<?import javafx.scene.control.Hyperlink?>
<?import com.sparrowwallet.sparrow.control.SignaturesProgressBar?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.control.Tooltip?>
<GridPane hgap="10.0" vgap="10.0" styleClass="tx-pane" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.HeadersController" stylesheets="@headers.css, @transaction.css, @../general.css">
<padding>
@ -80,9 +81,26 @@
</Field>
<Field fx:id="locktimeBlockField" text="Block:">
<Spinner fx:id="locktimeBlock" editable="true" prefWidth="120"/>
<Hyperlink fx:id="locktimeCurrentHeight" text="Set current height" onAction="#setLocktimeToCurrentHeight" />
<Label fx:id="futureBlockWarning">
<graphic>
<Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="12" icon="EXCLAMATION_TRIANGLE" styleClass="future-warning" />
</graphic>
<tooltip>
<Tooltip text="Future block specified - transaction will not be mined until this block"/>
</tooltip>
</Label>
</Field>
<Field fx:id="locktimeDateField" text="Date:">
<DateTimePicker fx:id="locktimeDate" prefWidth="180"/>
<Label fx:id="futureDateWarning">
<graphic>
<Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="12" icon="EXCLAMATION_TRIANGLE" styleClass="future-warning" />
</graphic>
<tooltip>
<Tooltip text="Future date specified - transaction will not be mined until this date"/>
</tooltip>
</Label>
</Field>
</Fieldset>
</Form>