From 03c488cf4db7729596a9ac69e58140d034eeed26 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 20 Aug 2020 17:30:39 +0200 Subject: [PATCH] add warnings to block time, set current height, close once --- .../sparrowwallet/sparrow/AppController.java | 6 ++-- .../sparrow/control/DeviceAddressDialog.java | 1 - .../sparrow/control/DeviceSignDialog.java | 1 - .../sparrow/control/WalletExportDialog.java | 1 - .../sparrow/control/WalletImportDialog.java | 1 - .../sparrow/glyphfont/FontAwesome5.java | 1 + .../keystoreimport/KeystoreImportDialog.java | 1 - .../transaction/HeadersController.java | 35 +++++++++++++++++++ .../sparrow/transaction/headers.css | 9 +++++ .../sparrow/transaction/headers.fxml | 18 ++++++++++ 10 files changed, 67 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 3e728f39..7ad4dc7f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -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"; } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/DeviceAddressDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/DeviceAddressDialog.java index 8f64f1b4..de524a7b 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/DeviceAddressDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/DeviceAddressDialog.java @@ -32,6 +32,5 @@ public class DeviceAddressDialog extends DeviceDialog { @Subscribe public void addressDisplayed(AddressDisplayedEvent event) { setResult(event.getAddress()); - this.close(); } } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/DeviceSignDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/DeviceSignDialog.java index 043f5b93..33d2974f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/DeviceSignDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/DeviceSignDialog.java @@ -30,7 +30,6 @@ public class DeviceSignDialog extends DeviceDialog { public void psbtSigned(PSBTSignedEvent event) { if(psbt == event.getPsbt()) { setResult(event.getSignedPsbt()); - this.close(); } } } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WalletExportDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/WalletExportDialog.java index 73a86e89..e762e8db 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WalletExportDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WalletExportDialog.java @@ -69,6 +69,5 @@ public class WalletExportDialog extends Dialog { public void walletExported(WalletExportEvent event) { wallet = event.getWallet(); setResult(wallet); - this.close(); } } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WalletImportDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/WalletImportDialog.java index 698c53ae..ee68ae6e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WalletImportDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WalletImportDialog.java @@ -56,6 +56,5 @@ public class WalletImportDialog extends Dialog { public void walletImported(WalletImportEvent event) { wallet = event.getWallet(); setResult(wallet); - this.close(); } } diff --git a/src/main/java/com/sparrowwallet/sparrow/glyphfont/FontAwesome5.java b/src/main/java/com/sparrowwallet/sparrow/glyphfont/FontAwesome5.java index bdcc3adf..056dde09 100644 --- a/src/main/java/com/sparrowwallet/sparrow/glyphfont/FontAwesome5.java +++ b/src/main/java/com/sparrowwallet/sparrow/glyphfont/FontAwesome5.java @@ -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'), diff --git a/src/main/java/com/sparrowwallet/sparrow/keystoreimport/KeystoreImportDialog.java b/src/main/java/com/sparrowwallet/sparrow/keystoreimport/KeystoreImportDialog.java index fbce4020..06b25afe 100644 --- a/src/main/java/com/sparrowwallet/sparrow/keystoreimport/KeystoreImportDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/keystoreimport/KeystoreImportDialog.java @@ -59,6 +59,5 @@ public class KeystoreImportDialog extends Dialog { public void keystoreImported(KeystoreImportEvent event) { this.keystore = event.getKeystore(); setResult(keystore); - this.close(); } } diff --git a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java index 10527850..f8564e85 100644 --- a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java +++ b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java @@ -96,9 +96,18 @@ public class HeadersController extends TransactionFormController implements Init @FXML private Spinner 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()); + } } } \ No newline at end of file diff --git a/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.css b/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.css index eb9ad593..755f44e8 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.css +++ b/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.css @@ -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; } diff --git a/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.fxml b/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.fxml index 10bb4197..81324ab6 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.fxml @@ -23,6 +23,7 @@ + @@ -80,9 +81,26 @@ + + +