From 7fe4d375016234d30c85faba1ac394bab90e666f Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Thu, 14 Apr 2016 22:57:21 +0200 Subject: [PATCH] remove min amount warning -> change amounts it not valid. only update price if perc. price is input source --- .../createoffer/CreateOfferViewModel.java | 75 ++++++++++--------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/gui/src/main/java/io/bitsquare/gui/main/offer/createoffer/CreateOfferViewModel.java b/gui/src/main/java/io/bitsquare/gui/main/offer/createoffer/CreateOfferViewModel.java index 01376879da..14d1a009d6 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/offer/createoffer/CreateOfferViewModel.java +++ b/gui/src/main/java/io/bitsquare/gui/main/offer/createoffer/CreateOfferViewModel.java @@ -116,6 +116,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel { - try { - if (!newValue.isEmpty() && !newValue.equals("-")) { - double percentageBasedPrice = formatter.parsePercentStringToDouble(newValue); - if (percentageBasedPrice >= 1 || percentageBasedPrice <= -1) { - dataModel.setPercentageBasedPrice(0); - UserThread.execute(() -> priceAsPercentage.set("0")); - new Popup().warning("You cannot set a percentage of 100% or larger. Please enter a percentage number like \"5.4\" for 5.4%") - .show(); - } else { - MarketPrice marketPrice = priceFeed.getMarketPrice(dataModel.tradeCurrencyCode.get()); - if (marketPrice != null) { - percentageBasedPrice = formatter.roundDouble(percentageBasedPrice, 4); - dataModel.setPercentageBasedPrice(percentageBasedPrice); - double marketPriceAsDouble = marketPrice.getPrice(priceFeedType); - double factor = dataModel.getDirection() == Offer.Direction.BUY ? 1 - percentageBasedPrice : 1 + percentageBasedPrice; - double targetPrice = marketPriceAsDouble * factor; - price.set(formatter.formatToNumberString(targetPrice, 2)); - setPriceToModel(); - calculateVolume(); - dataModel.calculateTotalToPay(); - updateButtonDisableState(); - } else { - new Popup().warning("There is no price feed available for that currency. You cannot use percent based price.") + if (priceAsPercentageIsInput) { + try { + if (!newValue.isEmpty() && !newValue.equals("-")) { + double percentageBasedPrice = formatter.parsePercentStringToDouble(newValue); + if (percentageBasedPrice >= 1 || percentageBasedPrice <= -1) { + dataModel.setPercentageBasedPrice(0); + UserThread.execute(() -> priceAsPercentage.set("0")); + new Popup().warning("You cannot set a percentage of 100% or larger. Please enter a percentage number like \"5.4\" for 5.4%") .show(); + } else { + MarketPrice marketPrice = priceFeed.getMarketPrice(dataModel.tradeCurrencyCode.get()); + if (marketPrice != null) { + percentageBasedPrice = formatter.roundDouble(percentageBasedPrice, 4); + dataModel.setPercentageBasedPrice(percentageBasedPrice); + double marketPriceAsDouble = marketPrice.getPrice(priceFeedType); + double factor = dataModel.getDirection() == Offer.Direction.BUY ? 1 - percentageBasedPrice : 1 + percentageBasedPrice; + double targetPrice = marketPriceAsDouble * factor; + price.set(formatter.formatToNumberString(targetPrice, 2)); + setPriceToModel(); + calculateVolume(); + dataModel.calculateTotalToPay(); + updateButtonDisableState(); + } else { + new Popup().warning("There is no price feed available for that currency. You cannot use percent based price.") + .show(); + } } + } else { + dataModel.setPercentageBasedPrice(0); } - } else { + } catch (Throwable t) { dataModel.setPercentageBasedPrice(0); + UserThread.execute(() -> priceAsPercentage.set("0")); + new Popup().warning("Your input is not a valid number. Please enter a percentage number like \"5.4\" for 5.4%") + .show(); } - } catch (Throwable t) { - dataModel.setPercentageBasedPrice(0); - UserThread.execute(() -> priceAsPercentage.set("0")); - new Popup().warning("Your input is not a valid number. Please enter a percentage number like \"5.4\" for 5.4%") - .show(); } }; volumeListener = (ov, oldValue, newValue) -> { @@ -475,8 +478,9 @@ class CreateOfferViewModel extends ActivatableWithDataModel