From f5254f2cb624d4fb0380f1eb999bd9c2a5f9589c Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Thu, 16 Jun 2016 02:15:22 +0200 Subject: [PATCH] restrict max price deviation to 20% --- .../main/java/io/bitsquare/user/Preferences.java | 5 +---- .../main/settings/preferences/PreferencesView.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/io/bitsquare/user/Preferences.java b/core/src/main/java/io/bitsquare/user/Preferences.java index 9175c78094..9bf4afe342 100644 --- a/core/src/main/java/io/bitsquare/user/Preferences.java +++ b/core/src/main/java/io/bitsquare/user/Preferences.java @@ -173,9 +173,6 @@ public final class Preferences implements Persistable { usePercentageBasedPrice = persisted.getUsePercentageBasedPrice(); showOwnOffersInOfferBook = persisted.getShowOwnOffersInOfferBook(); maxPriceDistanceInPercent = persisted.getMaxPriceDistanceInPercent(); - // Backward compatible to version 0.3.6. Can be removed after a while - if (maxPriceDistanceInPercent == 0d) - maxPriceDistanceInPercent = 0.2; try { setNonTradeTxFeePerKB(persisted.getNonTradeTxFeePerKB()); @@ -195,7 +192,7 @@ public final class Preferences implements Persistable { dontShowAgainMap = new HashMap<>(); preferredLocale = getDefaultLocale(); preferredTradeCurrency = getDefaultTradeCurrency(); - maxPriceDistanceInPercent = 0.2; + maxPriceDistanceInPercent = 0.1; storage.queueUpForSave(); } diff --git a/gui/src/main/java/io/bitsquare/gui/main/settings/preferences/PreferencesView.java b/gui/src/main/java/io/bitsquare/gui/main/settings/preferences/PreferencesView.java index 7501d845aa..0e128c625d 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/settings/preferences/PreferencesView.java +++ b/gui/src/main/java/io/bitsquare/gui/main/settings/preferences/PreferencesView.java @@ -297,15 +297,20 @@ public class PreferencesView extends ActivatableViewAndModel { try { double value = formatter.parsePercentStringToDouble(newValue); - preferences.setMaxPriceDistanceInPercent(value); + if (value <= 0.2) { + preferences.setMaxPriceDistanceInPercent(value); + } else { + new Popup().warning("Amounts larger than 20 % are not allowed.").show(); + UserThread.runAfter(() -> deviationInputTextField.setText(formatter.formatPercentagePrice(preferences.getMaxPriceDistanceInPercent())), 100, TimeUnit.MILLISECONDS); + } } catch (NumberFormatException t) { log.error("Exception at parseDouble deviation: " + t.toString()); - UserThread.runAfter(() -> deviationInputTextField.setText(formatter.formatToPercentWithSymbol(preferences.getMaxPriceDistanceInPercent())), 100, TimeUnit.MILLISECONDS); + UserThread.runAfter(() -> deviationInputTextField.setText(formatter.formatPercentagePrice(preferences.getMaxPriceDistanceInPercent())), 100, TimeUnit.MILLISECONDS); } }; deviationFocusedListener = (observable1, oldValue1, newValue1) -> { if (oldValue1 && !newValue1) - UserThread.runAfter(() -> deviationInputTextField.setText(formatter.formatToPercentWithSymbol(preferences.getMaxPriceDistanceInPercent())), 100, TimeUnit.MILLISECONDS); + UserThread.runAfter(() -> deviationInputTextField.setText(formatter.formatPercentagePrice(preferences.getMaxPriceDistanceInPercent())), 100, TimeUnit.MILLISECONDS); }; transactionFeeInputTextField = addLabelInputTextField(root, ++gridRow, "Withdrawal transaction fee (satoshi/byte):").second; @@ -424,7 +429,7 @@ public class PreferencesView extends ActivatableViewAndModel preferences.setBlockChainExplorer(blockChainExplorerComboBox.getSelectionModel().getSelectedItem())); - deviationInputTextField.setText(formatter.formatToPercentWithSymbol(preferences.getMaxPriceDistanceInPercent())); + deviationInputTextField.setText(formatter.formatPercentagePrice(preferences.getMaxPriceDistanceInPercent())); deviationInputTextField.textProperty().addListener(deviationListener); deviationInputTextField.focusedProperty().addListener(deviationFocusedListener);