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(); String fileName = selectedTab.getText();
if(fileName != null && !fileName.isEmpty()) { if(fileName != null && !fileName.isEmpty()) {
if(transactionTabData.getPsbt() != null && !fileName.endsWith(".psbt")) { if(transactionTabData.getPsbt() != null) {
if(!fileName.endsWith(".psbt")) {
fileName += ".psbt"; fileName += ".psbt";
}
} else if(!fileName.endsWith(".txn")) { } else if(!fileName.endsWith(".txn")) {
fileName += ".txn"; fileName += ".txn";
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -23,6 +23,7 @@
<?import javafx.scene.control.Hyperlink?> <?import javafx.scene.control.Hyperlink?>
<?import com.sparrowwallet.sparrow.control.SignaturesProgressBar?> <?import com.sparrowwallet.sparrow.control.SignaturesProgressBar?>
<?import javafx.scene.control.ProgressBar?> <?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"> <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> <padding>
@ -80,9 +81,26 @@
</Field> </Field>
<Field fx:id="locktimeBlockField" text="Block:"> <Field fx:id="locktimeBlockField" text="Block:">
<Spinner fx:id="locktimeBlock" editable="true" prefWidth="120"/> <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>
<Field fx:id="locktimeDateField" text="Date:"> <Field fx:id="locktimeDateField" text="Date:">
<DateTimePicker fx:id="locktimeDate" prefWidth="180"/> <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> </Field>
</Fieldset> </Fieldset>
</Form> </Form>