From 343cb2271ccb1f74834e9ca24eee08b6a6db25f5 Mon Sep 17 00:00:00 2001 From: krzyczak Date: Fri, 22 Dec 2023 17:29:22 +0000 Subject: [PATCH] feat: Implement bitcoin unit toggle on bitcoin balance --- .../sparrow/control/CopyableCoinLabel.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/CopyableCoinLabel.java b/src/main/java/com/sparrowwallet/sparrow/control/CopyableCoinLabel.java index 5e431825..500280c7 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/CopyableCoinLabel.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/CopyableCoinLabel.java @@ -10,19 +10,40 @@ import javafx.scene.control.MenuItem; import javafx.scene.control.Tooltip; import javafx.scene.input.Clipboard; import javafx.scene.input.ClipboardContent; +import javafx.event.EventHandler; +import javafx.scene.input.MouseEvent; public class CopyableCoinLabel extends CopyableLabel { private final LongProperty valueProperty = new SimpleLongProperty(-1); private final Tooltip tooltip; private final CoinContextMenu contextMenu; + private BitcoinUnit bitcoinUnit; + public CopyableCoinLabel() { this("Unknown"); } + private final EventHandler toggleBitcoinUnit = event -> { + if(bitcoinUnit == null) { + bitcoinUnit = Config.get().getBitcoinUnit(); + } + + if(bitcoinUnit == BitcoinUnit.SATOSHIS) { + bitcoinUnit = BitcoinUnit.BTC; + } else { + bitcoinUnit = BitcoinUnit.SATOSHIS; + } + + refresh(Config.get().getUnitFormat(), bitcoinUnit); + }; + public CopyableCoinLabel(String text) { super(text); valueProperty().addListener((observable, oldValue, newValue) -> setValueAsText((Long)newValue, Config.get().getUnitFormat(), Config.get().getBitcoinUnit())); + + setOnMouseClicked(toggleBitcoinUnit); + tooltip = new Tooltip(); contextMenu = new CoinContextMenu(); } @@ -63,6 +84,8 @@ public class CopyableCoinLabel extends CopyableLabel { unit = (value >= BitcoinUnit.getAutoThreshold() ? BitcoinUnit.BTC : BitcoinUnit.SATOSHIS); } + this.bitcoinUnit = unit; + if(unit.equals(BitcoinUnit.BTC)) { tooltip.setText(satsValue); setText(btcValue);