From ff90a2c3e6e35e4c5df99ab906a4f958b247a7ff Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 28 Nov 2022 09:43:08 +0200 Subject: [PATCH] add block height to terminal connected label --- .../sparrow/terminal/SparrowTextGui.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/terminal/SparrowTextGui.java b/src/main/java/com/sparrowwallet/sparrow/terminal/SparrowTextGui.java index 07257c2f..221c1b20 100644 --- a/src/main/java/com/sparrowwallet/sparrow/terminal/SparrowTextGui.java +++ b/src/main/java/com/sparrowwallet/sparrow/terminal/SparrowTextGui.java @@ -67,9 +67,13 @@ public class SparrowTextGui extends MultiWindowTextGUI { return mainWindow; } - private void setConnectedLabel(boolean connected) { + private void setDisconnectedLabel() { + setConnectedLabel(null); + } + + private void setConnectedLabel(Integer height) { getGUIThread().invokeLater(() -> { - connectedLabel.setText(connected ? "Connected" : "Disconnected"); + connectedLabel.setText(height == null ? "Disconnected" : "Connected at " + height); }); } @@ -80,24 +84,29 @@ public class SparrowTextGui extends MultiWindowTextGUI { @Subscribe public void connectionFailed(ConnectionFailedEvent event) { - setConnectedLabel(false); + setDisconnectedLabel(); statusUpdated(new StatusEvent("Connection failed: " + event.getMessage())); } @Subscribe public void connection(ConnectionEvent event) { - setConnectedLabel(true); + setConnectedLabel(event.getBlockHeight()); statusUpdated(new StatusEvent("Connected to " + Config.get().getServerDisplayName() + " at height " + event.getBlockHeight())); } @Subscribe public void disconnection(DisconnectionEvent event) { if(!AppServices.isConnecting() && !AppServices.isConnected()) { - setConnectedLabel(false); + setDisconnectedLabel(); statusUpdated(new StatusEvent("Disconnected")); } } + @Subscribe + public void newBlock(NewBlockEvent event) { + setConnectedLabel(event.getHeight()); + } + @Subscribe public void statusUpdated(StatusEvent event) { getGUIThread().invokeLater(() -> statusLabel.setText(event.getStatus()));