From 3c2dfed96d7dccc9c4fecb087438360d34ad7ded Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 27 Aug 2020 17:16:20 +0200 Subject: [PATCH] locale and other windows related fixes --- build.gradle | 6 +++--- .../sparrowwallet/sparrow/control/CoinTextFormatter.java | 5 +++-- .../java/com/sparrowwallet/sparrow/control/FiatLabel.java | 4 +++- src/main/java/com/sparrowwallet/sparrow/io/Hwi.java | 8 ++++---- .../com/sparrowwallet/sparrow/wallet/SendController.java | 7 ++++--- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index ad708a0e..398ef498 100644 --- a/build.gradle +++ b/build.gradle @@ -97,11 +97,11 @@ run { "--add-opens=javafx.graphics/com.sun.javafx.tk.quantum=centerdevice.nsmenufx", "--add-opens=javafx.graphics/com.sun.glass.ui=centerdevice.nsmenufx", "--add-opens=javafx.controls/com.sun.javafx.scene.control=centerdevice.nsmenufx", - "--add-opens=javafx.graphics/com.sun.javafx.menu=centerdevice.nsmenufx", - "--add-opens=javafx.graphics/com.sun.glass.ui.mac=centerdevice.nsmenufx"] + "--add-opens=javafx.graphics/com.sun.javafx.menu=centerdevice.nsmenufx"] if(os.macOsX) { - applicationDefaultJvmArgs += ["-Xdock:name=Sparrow", "-Xdock:icon=/Users/scy/git/sparrow/src/main/resources/sparrow.png"] + applicationDefaultJvmArgs += ["-Xdock:name=Sparrow", "-Xdock:icon=/Users/scy/git/sparrow/src/main/resources/sparrow.png", + "--add-opens=javafx.graphics/com.sun.glass.ui.mac=centerdevice.nsmenufx"] } } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/CoinTextFormatter.java b/src/main/java/com/sparrowwallet/sparrow/control/CoinTextFormatter.java index 9fbc6216..e6aa35d0 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/CoinTextFormatter.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/CoinTextFormatter.java @@ -4,13 +4,14 @@ import javafx.scene.control.TextFormatter; import javafx.scene.control.TextInputControl; import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; import java.text.ParseException; -import java.util.function.UnaryOperator; +import java.util.Locale; import java.util.regex.Pattern; public class CoinTextFormatter extends TextFormatter { private static final Pattern COIN_VALIDATION = Pattern.compile("[\\d,]*(\\.\\d{0,8})?"); - public static final DecimalFormat COIN_FORMAT = new DecimalFormat("###,###.########"); + public static final DecimalFormat COIN_FORMAT = new DecimalFormat("###,###.########", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); public CoinTextFormatter() { super(new CoinFilter()); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/FiatLabel.java b/src/main/java/com/sparrowwallet/sparrow/control/FiatLabel.java index 61dde11f..add4a16e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/FiatLabel.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/FiatLabel.java @@ -11,10 +11,12 @@ import javafx.scene.input.ClipboardContent; import java.math.BigDecimal; import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; import java.util.Currency; +import java.util.Locale; public class FiatLabel extends CopyableLabel { - private static final DecimalFormat CURRENCY_FORMAT = new DecimalFormat("#,##0.00"); + private static final DecimalFormat CURRENCY_FORMAT = new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); private final LongProperty valueProperty = new SimpleLongProperty(-1); private final DoubleProperty btcRateProperty = new SimpleDoubleProperty(0.0); diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java b/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java index e1fd8a26..6e5c45be 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java @@ -36,7 +36,7 @@ public class Hwi { public List enumerate(String passphrase) throws ImportException { try { List command; - if(passphrase != null) { + if(passphrase != null && !passphrase.isEmpty()) { command = List.of(getHwiExecutable(Command.ENUMERATE).getAbsolutePath(), "--password", passphrase, Command.ENUMERATE.toString()); } else { command = List.of(getHwiExecutable(Command.ENUMERATE).getAbsolutePath(), Command.ENUMERATE.toString()); @@ -72,7 +72,7 @@ public class Hwi { public String getXpub(Device device, String passphrase, String derivationPath) throws ImportException { try { String output; - if(passphrase != null && device.getModel().equals(WalletModel.TREZOR_1)) { + if(passphrase != null && !passphrase.isEmpty() && device.getModel().equals(WalletModel.TREZOR_1)) { output = execute(getDeviceCommand(device, passphrase, Command.GET_XPUB, derivationPath)); } else { output = execute(getDeviceCommand(device, Command.GET_XPUB, derivationPath)); @@ -103,7 +103,7 @@ public class Hwi { } String output; - if(passphrase != null && device.getModel().equals(WalletModel.TREZOR_1)) { + if(passphrase != null && !passphrase.isEmpty() && device.getModel().equals(WalletModel.TREZOR_1)) { output = execute(getDeviceCommand(device, passphrase, Command.DISPLAY_ADDRESS, "--path", derivationPath, type)); } else { output = execute(getDeviceCommand(device, Command.DISPLAY_ADDRESS, "--path", derivationPath, type)); @@ -125,7 +125,7 @@ public class Hwi { String psbtBase64 = psbt.toBase64String(); String output; - if(passphrase != null && device.getModel().equals(WalletModel.TREZOR_1)) { + if(passphrase != null && !passphrase.isEmpty() && device.getModel().equals(WalletModel.TREZOR_1)) { output = execute(getDeviceCommand(device, passphrase, Command.SIGN_TX, psbtBase64)); } else { output = execute(getDeviceCommand(device, Command.SIGN_TX, psbtBase64)); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index 3590ab15..95719ca0 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -35,6 +35,7 @@ import org.controlsfx.validation.decoration.StyleClassValidationDecoration; import java.net.URL; import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; import java.util.*; import java.util.stream.Collectors; @@ -180,7 +181,7 @@ public class SendController extends WalletFormController implements Initializabl amountUnit.valueProperty().addListener((observable, oldValue, newValue) -> { Long value = getRecipientValueSats(oldValue); if(value != null) { - DecimalFormat df = new DecimalFormat("#.#"); + DecimalFormat df = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); df.setMaximumFractionDigits(8); amount.setText(df.format(newValue.getValue(value))); } @@ -374,7 +375,7 @@ public class SendController extends WalletFormController implements Initializabl private void setRecipientValueSats(long recipientValue) { amount.textProperty().removeListener(amountListener); - DecimalFormat df = new DecimalFormat("#.#"); + DecimalFormat df = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); df.setMaximumFractionDigits(8); amount.setText(df.format(amountUnit.getValue().getValue(recipientValue))); amount.textProperty().addListener(amountListener); @@ -395,7 +396,7 @@ public class SendController extends WalletFormController implements Initializabl private void setFeeValueSats(long feeValue) { fee.textProperty().removeListener(feeListener); - DecimalFormat df = new DecimalFormat("#.#"); + DecimalFormat df = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); df.setMaximumFractionDigits(8); fee.setText(df.format(feeAmountUnit.getValue().getValue(feeValue))); fee.textProperty().addListener(feeListener);