From 59d85cdd05d1477c888aed6bd16a51189b66bac4 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 18 Dec 2025 13:12:54 +0200 Subject: [PATCH] improve thp pairing flow, and add passphrase session support --- lark | 2 +- .../com/sparrowwallet/sparrow/io/Hwi.java | 20 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lark b/lark index 5cbdd51c..730956a4 160000 --- a/lark +++ b/lark @@ -1 +1 @@ -Subproject commit 5cbdd51c0f1b2d86c35e600aa57609565524d301 +Subproject commit 730956a4411d6c84d0eef7d788f03609a0ec1793 diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java b/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java index baf426bd..717ff403 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java @@ -20,8 +20,11 @@ import javafx.application.Platform; import javafx.concurrent.ScheduledService; import javafx.concurrent.Service; import javafx.concurrent.Task; +import javafx.geometry.Insets; import javafx.scene.control.Alert; import javafx.scene.control.ButtonType; +import javafx.scene.control.TextFormatter; +import javafx.scene.layout.HBox; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -546,6 +549,8 @@ public class Hwi { } private static final class TrezorFxNoiseConfig extends TrezorFileNoiseConfig { + private String deviceInfo; + public TrezorFxNoiseConfig() { super(Path.of(Storage.getSparrowHome().getAbsolutePath(), LARK_HOME_DIR, TREZOR_FILENAME).toFile()); } @@ -553,14 +558,22 @@ public class Hwi { @Override public String promptForPairingCode() { CompletableFuture future = new CompletableFuture<>(); - Platform.runLater(() -> { TextfieldDialog textfieldDialog = new TextfieldDialog(); textfieldDialog.initOwner(AppServices.getActiveWindow()); textfieldDialog.setTitle("Enter Pairing Code"); - textfieldDialog.setHeaderText("Enter the code shown on the device"); + textfieldDialog.setHeaderText("Enter the code shown on the " + deviceInfo + ":"); textfieldDialog.getDialogPane().setPrefWidth(300); textfieldDialog.getEditor().setOnAction(_ -> textfieldDialog.setResult(textfieldDialog.getEditor().getText())); + textfieldDialog.getEditor().setTextFormatter(new TextFormatter<>(change -> { + String newText = change.getControlNewText(); + if(newText.matches("\\d*")) { + return change; + } + return null; + })); + textfieldDialog.getEditor().setStyle("-fx-font-size: 30px;"); + HBox.setMargin(textfieldDialog.getEditor(), new Insets(0, 60, 0, 60)); textfieldDialog.getEditor().requestFocus(); textfieldDialog.showAndWait().ifPresentOrElse(future::complete, () -> future.complete(null)); }); @@ -578,8 +591,8 @@ public class Hwi { @Override public boolean confirmPairing(String deviceInfo) { + this.deviceInfo = deviceInfo; CompletableFuture future = new CompletableFuture<>(); - Platform.runLater(() -> { AppServices.showAlertDialog("Pairing Required", "Pair the " + deviceInfo + " with " + SparrowWallet.APP_NAME + "?", Alert.AlertType.CONFIRMATION, ButtonType.YES, ButtonType.NO).ifPresentOrElse(future::complete, () -> future.complete(null)); @@ -613,6 +626,7 @@ public class Hwi { @Override public void pairingSuccessful(String deviceInfo) { + this.deviceInfo = deviceInfo; Platform.runLater(() -> AppServices.showSuccessDialog("Pairing Successful", "The " + deviceInfo + " has been successfully paired.")); } }