mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-12-12 06:28:49 -05:00
remove min amount warning -> change amounts it not valid. only update price if perc. price is input source
This commit is contained in:
parent
c43575073d
commit
7fe4d37501
1 changed files with 40 additions and 35 deletions
|
|
@ -116,6 +116,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
||||||
private Offer offer;
|
private Offer offer;
|
||||||
private Timer timeoutTimer;
|
private Timer timeoutTimer;
|
||||||
private PriceFeed.Type priceFeedType;
|
private PriceFeed.Type priceFeedType;
|
||||||
|
private boolean priceAsPercentageIsInput;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
@ -256,40 +257,42 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
||||||
updateButtonDisableState();
|
updateButtonDisableState();
|
||||||
};
|
};
|
||||||
priceAsPercentageListener = (ov, oldValue, newValue) -> {
|
priceAsPercentageListener = (ov, oldValue, newValue) -> {
|
||||||
try {
|
if (priceAsPercentageIsInput) {
|
||||||
if (!newValue.isEmpty() && !newValue.equals("-")) {
|
try {
|
||||||
double percentageBasedPrice = formatter.parsePercentStringToDouble(newValue);
|
if (!newValue.isEmpty() && !newValue.equals("-")) {
|
||||||
if (percentageBasedPrice >= 1 || percentageBasedPrice <= -1) {
|
double percentageBasedPrice = formatter.parsePercentStringToDouble(newValue);
|
||||||
dataModel.setPercentageBasedPrice(0);
|
if (percentageBasedPrice >= 1 || percentageBasedPrice <= -1) {
|
||||||
UserThread.execute(() -> priceAsPercentage.set("0"));
|
dataModel.setPercentageBasedPrice(0);
|
||||||
new Popup().warning("You cannot set a percentage of 100% or larger. Please enter a percentage number like \"5.4\" for 5.4%")
|
UserThread.execute(() -> priceAsPercentage.set("0"));
|
||||||
.show();
|
new Popup().warning("You cannot set a percentage of 100% or larger. Please enter a percentage number like \"5.4\" for 5.4%")
|
||||||
} 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();
|
.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);
|
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) -> {
|
volumeListener = (ov, oldValue, newValue) -> {
|
||||||
|
|
@ -475,8 +478,9 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
||||||
|
|
||||||
// handle minAmount/amount relationship
|
// handle minAmount/amount relationship
|
||||||
if (!dataModel.isMinAmountLessOrEqualAmount()) {
|
if (!dataModel.isMinAmountLessOrEqualAmount()) {
|
||||||
amountValidationResult.set(new InputValidator.ValidationResult(false,
|
minAmount.set(amount.get());
|
||||||
BSResources.get("createOffer.validation.amountSmallerThanMinAmount")));
|
/*amountValidationResult.set(new InputValidator.ValidationResult(false,
|
||||||
|
BSResources.get("createOffer.validation.amountSmallerThanMinAmount")));*/
|
||||||
} else {
|
} else {
|
||||||
amountValidationResult.set(result);
|
amountValidationResult.set(result);
|
||||||
if (minAmount.get() != null)
|
if (minAmount.get() != null)
|
||||||
|
|
@ -496,8 +500,9 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
||||||
minAmount.set(formatter.formatCoin(dataModel.minAmountAsCoin.get()));
|
minAmount.set(formatter.formatCoin(dataModel.minAmountAsCoin.get()));
|
||||||
|
|
||||||
if (!dataModel.isMinAmountLessOrEqualAmount()) {
|
if (!dataModel.isMinAmountLessOrEqualAmount()) {
|
||||||
minAmountValidationResult.set(new InputValidator.ValidationResult(false,
|
amount.set(minAmount.get());
|
||||||
BSResources.get("createOffer.validation.minAmountLargerThanAmount")));
|
/* minAmountValidationResult.set(new InputValidator.ValidationResult(false,
|
||||||
|
BSResources.get("createOffer.validation.minAmountLargerThanAmount")));*/
|
||||||
} else {
|
} else {
|
||||||
minAmountValidationResult.set(result);
|
minAmountValidationResult.set(result);
|
||||||
if (amount.get() != null)
|
if (amount.get() != null)
|
||||||
|
|
@ -523,9 +528,9 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
||||||
}
|
}
|
||||||
|
|
||||||
void onFocusOutPriceAsPercentageTextField(boolean oldValue, boolean newValue, String userInput) {
|
void onFocusOutPriceAsPercentageTextField(boolean oldValue, boolean newValue, String userInput) {
|
||||||
if (oldValue && !newValue) {
|
priceAsPercentageIsInput = !oldValue && newValue;
|
||||||
|
if (oldValue && !newValue)
|
||||||
priceAsPercentage.set(formatter.formatToNumberString(dataModel.getPercentageBasedPrice() * 100, 2));
|
priceAsPercentage.set(formatter.formatToNumberString(dataModel.getPercentageBasedPrice() * 100, 2));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onFocusOutVolumeTextField(boolean oldValue, boolean newValue, String userInput) {
|
void onFocusOutVolumeTextField(boolean oldValue, boolean newValue, String userInput) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue