mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
improve ux when validating transaction locktime datetime field
This commit is contained in:
parent
3c94664ac3
commit
90a2c3b89b
2 changed files with 20 additions and 1 deletions
|
@ -32,6 +32,8 @@ import javafx.scene.Node;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.input.Clipboard;
|
import javafx.scene.input.Clipboard;
|
||||||
import javafx.scene.input.ClipboardContent;
|
import javafx.scene.input.ClipboardContent;
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
|
@ -52,6 +54,7 @@ import java.net.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.*;
|
import java.time.*;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -320,6 +323,9 @@ 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) -> {
|
||||||
|
int caret = locktimeDate.getEditor().getCaretPosition();
|
||||||
|
locktimeDate.getEditor().setText(newValue.format(DateTimeFormatter.ofPattern(locktimeDate.getFormat())));
|
||||||
|
locktimeDate.getEditor().positionCaret(caret);
|
||||||
tx.setLocktime(newValue.toEpochSecond(OffsetDateTime.now(ZoneId.systemDefault()).getOffset()));
|
tx.setLocktime(newValue.toEpochSecond(OffsetDateTime.now(ZoneId.systemDefault()).getOffset()));
|
||||||
futureDateWarning.setVisible(newValue.isAfter(LocalDateTime.now()));
|
futureDateWarning.setVisible(newValue.isAfter(LocalDateTime.now()));
|
||||||
if(oldValue != null) {
|
if(oldValue != null) {
|
||||||
|
@ -327,6 +333,19 @@ public class HeadersController extends TransactionFormController implements Init
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
locktimeDate.getEditor().textProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
String controlValue = locktimeDate.getDateTimeValue().format(DateTimeFormatter.ofPattern(locktimeDate.getFormat()));
|
||||||
|
if(!controlValue.equals(newValue) && !locktimeDate.getStyleClass().contains("edited")) {
|
||||||
|
locktimeDate.getStyleClass().add("edited");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
locktimeDate.addEventFilter(KeyEvent.ANY, event -> {
|
||||||
|
if(event.getCode() == KeyCode.ENTER) {
|
||||||
|
locktimeDate.getStyleClass().remove("edited");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
boolean locktimeEnabled = headersForm.getTransaction().isLocktimeSequenceEnabled();
|
boolean locktimeEnabled = headersForm.getTransaction().isLocktimeSequenceEnabled();
|
||||||
locktimeNoneType.setDisable(!headersForm.isEditable() || !locktimeEnabled);
|
locktimeNoneType.setDisable(!headersForm.isEditable() || !locktimeEnabled);
|
||||||
locktimeBlockType.setDisable(!headersForm.isEditable() || !locktimeEnabled);
|
locktimeBlockType.setDisable(!headersForm.isEditable() || !locktimeEnabled);
|
||||||
|
|
|
@ -90,7 +90,7 @@
|
||||||
-fx-padding: 0 0 0 12;
|
-fx-padding: 0 0 0 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
.unfinalized-txid {
|
.unfinalized-txid, .edited > .text-field {
|
||||||
-fx-text-fill: #a0a1a7;
|
-fx-text-fill: #a0a1a7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue