mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 10:22:18 +01:00
Add better error text if input is NaN
This commit is contained in:
parent
1134c8bc71
commit
b78a7d7c90
@ -245,23 +245,23 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||||||
private void addBindings() {
|
private void addBindings() {
|
||||||
if (dataModel.getDirection() == OfferPayload.Direction.BUY) {
|
if (dataModel.getDirection() == OfferPayload.Direction.BUY) {
|
||||||
volumeDescriptionLabel.bind(createStringBinding(
|
volumeDescriptionLabel.bind(createStringBinding(
|
||||||
() -> Res.get("createOffer.amountPriceBox.buy.volumeDescription", dataModel.getTradeCurrencyCode().get()),
|
() -> Res.get("createOffer.amountPriceBox.buy.volumeDescription", dataModel.getTradeCurrencyCode().get()),
|
||||||
dataModel.getTradeCurrencyCode()));
|
dataModel.getTradeCurrencyCode()));
|
||||||
} else {
|
} else {
|
||||||
volumeDescriptionLabel.bind(createStringBinding(
|
volumeDescriptionLabel.bind(createStringBinding(
|
||||||
() -> Res.get("createOffer.amountPriceBox.sell.volumeDescription", dataModel.getTradeCurrencyCode().get()),
|
() -> Res.get("createOffer.amountPriceBox.sell.volumeDescription", dataModel.getTradeCurrencyCode().get()),
|
||||||
dataModel.getTradeCurrencyCode()));
|
dataModel.getTradeCurrencyCode()));
|
||||||
}
|
}
|
||||||
volumePromptLabel.bind(createStringBinding(
|
volumePromptLabel.bind(createStringBinding(
|
||||||
() -> Res.get("createOffer.volume.prompt", dataModel.getTradeCurrencyCode().get()),
|
() -> Res.get("createOffer.volume.prompt", dataModel.getTradeCurrencyCode().get()),
|
||||||
dataModel.getTradeCurrencyCode()));
|
dataModel.getTradeCurrencyCode()));
|
||||||
|
|
||||||
totalToPay.bind(createStringBinding(() -> btcFormatter.formatCoinWithCode(dataModel.totalToPayAsCoinProperty().get()),
|
totalToPay.bind(createStringBinding(() -> btcFormatter.formatCoinWithCode(dataModel.totalToPayAsCoinProperty().get()),
|
||||||
dataModel.totalToPayAsCoinProperty()));
|
dataModel.totalToPayAsCoinProperty()));
|
||||||
|
|
||||||
|
|
||||||
tradeAmount.bind(createStringBinding(() -> btcFormatter.formatCoinWithCode(dataModel.getAmount().get()),
|
tradeAmount.bind(createStringBinding(() -> btcFormatter.formatCoinWithCode(dataModel.getAmount().get()),
|
||||||
dataModel.getAmount()));
|
dataModel.getAmount()));
|
||||||
|
|
||||||
|
|
||||||
tradeCurrencyCode.bind(dataModel.getTradeCurrencyCode());
|
tradeCurrencyCode.bind(dataModel.getTradeCurrencyCode());
|
||||||
@ -307,8 +307,8 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||||||
double priceAsDouble = btcFormatter.parseNumberStringToDouble(price.get());
|
double priceAsDouble = btcFormatter.parseNumberStringToDouble(price.get());
|
||||||
double relation = priceAsDouble / marketPriceAsDouble;
|
double relation = priceAsDouble / marketPriceAsDouble;
|
||||||
final OfferPayload.Direction compareDirection = CurrencyUtil.isCryptoCurrency(currencyCode) ?
|
final OfferPayload.Direction compareDirection = CurrencyUtil.isCryptoCurrency(currencyCode) ?
|
||||||
OfferPayload.Direction.SELL :
|
OfferPayload.Direction.SELL :
|
||||||
OfferPayload.Direction.BUY;
|
OfferPayload.Direction.BUY;
|
||||||
double percentage = dataModel.getDirection() == compareDirection ? 1 - relation : relation - 1;
|
double percentage = dataModel.getDirection() == compareDirection ? 1 - relation : relation - 1;
|
||||||
percentage = MathUtils.roundDouble(percentage, 4);
|
percentage = MathUtils.roundDouble(percentage, 4);
|
||||||
dataModel.setMarketPriceMargin(percentage);
|
dataModel.setMarketPriceMargin(percentage);
|
||||||
@ -333,8 +333,8 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||||||
double percentage = btcFormatter.parsePercentStringToDouble(newValue);
|
double percentage = btcFormatter.parsePercentStringToDouble(newValue);
|
||||||
if (percentage >= 1 || percentage <= -1) {
|
if (percentage >= 1 || percentage <= -1) {
|
||||||
new Popup<>().warning(Res.get("popup.warning.tooLargePercentageValue") + "\n" +
|
new Popup<>().warning(Res.get("popup.warning.tooLargePercentageValue") + "\n" +
|
||||||
Res.get("popup.warning.examplePercentageValue"))
|
Res.get("popup.warning.examplePercentageValue"))
|
||||||
.show();
|
.show();
|
||||||
} else {
|
} else {
|
||||||
final String currencyCode = dataModel.getTradeCurrencyCode().get();
|
final String currencyCode = dataModel.getTradeCurrencyCode().get();
|
||||||
MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode);
|
MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode);
|
||||||
@ -343,14 +343,14 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||||||
double marketPriceAsDouble = marketPrice.getPrice();
|
double marketPriceAsDouble = marketPrice.getPrice();
|
||||||
final boolean isCryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode);
|
final boolean isCryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode);
|
||||||
final OfferPayload.Direction compareDirection = isCryptoCurrency ?
|
final OfferPayload.Direction compareDirection = isCryptoCurrency ?
|
||||||
OfferPayload.Direction.SELL :
|
OfferPayload.Direction.SELL :
|
||||||
OfferPayload.Direction.BUY;
|
OfferPayload.Direction.BUY;
|
||||||
double factor = dataModel.getDirection() == compareDirection ?
|
double factor = dataModel.getDirection() == compareDirection ?
|
||||||
1 - percentage :
|
1 - percentage :
|
||||||
1 + percentage;
|
1 + percentage;
|
||||||
double targetPrice = marketPriceAsDouble * factor;
|
double targetPrice = marketPriceAsDouble * factor;
|
||||||
int precision = isCryptoCurrency ?
|
int precision = isCryptoCurrency ?
|
||||||
Altcoin.SMALLEST_UNIT_EXPONENT : Fiat.SMALLEST_UNIT_EXPONENT;
|
Altcoin.SMALLEST_UNIT_EXPONENT : Fiat.SMALLEST_UNIT_EXPONENT;
|
||||||
// protect from triggering unwanted updates
|
// protect from triggering unwanted updates
|
||||||
ignorePriceStringListener = true;
|
ignorePriceStringListener = true;
|
||||||
price.set(btcFormatter.formatRoundedDoubleWithPrecision(targetPrice, precision));
|
price.set(btcFormatter.formatRoundedDoubleWithPrecision(targetPrice, precision));
|
||||||
@ -367,6 +367,10 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (NumberFormatException t) {
|
||||||
|
log.error(t.toString());
|
||||||
|
t.printStackTrace();
|
||||||
|
new Popup<>().warning(Res.get("validation.NaN")).show();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
log.error(t.toString());
|
log.error(t.toString());
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
@ -530,7 +534,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||||||
final boolean isBuy = dataModel.getDirection() == OfferPayload.Direction.BUY;
|
final boolean isBuy = dataModel.getDirection() == OfferPayload.Direction.BUY;
|
||||||
directionLabel = isBuy ? Res.get("shared.buyBitcoin") : Res.get("shared.sellBitcoin");
|
directionLabel = isBuy ? Res.get("shared.buyBitcoin") : Res.get("shared.sellBitcoin");
|
||||||
amountDescription = Res.get("createOffer.amountPriceBox.amountDescription",
|
amountDescription = Res.get("createOffer.amountPriceBox.amountDescription",
|
||||||
isBuy ? Res.get("shared.buy") : Res.get("shared.sell"));
|
isBuy ? Res.get("shared.buy") : Res.get("shared.sell"));
|
||||||
|
|
||||||
buyerSecurityDeposit.set(btcFormatter.formatCoin(dataModel.getBuyerSecurityDeposit().get()));
|
buyerSecurityDeposit.set(btcFormatter.formatCoin(dataModel.getBuyerSecurityDeposit().get()));
|
||||||
|
|
||||||
@ -620,11 +624,11 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||||||
} else {
|
} else {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
new Popup<>().warning(Res.get("shared.notEnoughFunds",
|
new Popup<>().warning(Res.get("shared.notEnoughFunds",
|
||||||
btcFormatter.formatCoinWithCode(dataModel.totalToPayAsCoinProperty().get()),
|
btcFormatter.formatCoinWithCode(dataModel.totalToPayAsCoinProperty().get()),
|
||||||
btcFormatter.formatCoinWithCode(dataModel.totalAvailableBalance)))
|
btcFormatter.formatCoinWithCode(dataModel.totalAvailableBalance)))
|
||||||
.actionButtonTextWithGoTo("navigation.funds.depositFunds")
|
.actionButtonTextWithGoTo("navigation.funds.depositFunds")
|
||||||
.onAction(() -> navigation.navigateTo(MainView.class, FundsView.class, DepositView.class))
|
.onAction(() -> navigation.navigateTo(MainView.class, FundsView.class, DepositView.class))
|
||||||
.show();
|
.show();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -741,25 +745,25 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||||||
Coin defaultSecurityDeposit = Restrictions.getDefaultBuyerSecurityDeposit();
|
Coin defaultSecurityDeposit = Restrictions.getDefaultBuyerSecurityDeposit();
|
||||||
String key = "buyerSecurityDepositLowerAsDefault";
|
String key = "buyerSecurityDepositLowerAsDefault";
|
||||||
if (preferences.showAgain(key) &&
|
if (preferences.showAgain(key) &&
|
||||||
btcFormatter.parseToCoin(buyerSecurityDeposit.get()).compareTo(defaultSecurityDeposit) < 0) {
|
btcFormatter.parseToCoin(buyerSecurityDeposit.get()).compareTo(defaultSecurityDeposit) < 0) {
|
||||||
final String postfix = dataModel.isBuyOffer() ?
|
final String postfix = dataModel.isBuyOffer() ?
|
||||||
Res.get("createOffer.tooLowSecDeposit.makerIsBuyer") :
|
Res.get("createOffer.tooLowSecDeposit.makerIsBuyer") :
|
||||||
Res.get("createOffer.tooLowSecDeposit.makerIsSeller");
|
Res.get("createOffer.tooLowSecDeposit.makerIsSeller");
|
||||||
new Popup<>()
|
new Popup<>()
|
||||||
.warning(Res.get("createOffer.tooLowSecDeposit.warning",
|
.warning(Res.get("createOffer.tooLowSecDeposit.warning",
|
||||||
btcFormatter.formatCoinWithCode(defaultSecurityDeposit)) + "\n\n" + postfix)
|
btcFormatter.formatCoinWithCode(defaultSecurityDeposit)) + "\n\n" + postfix)
|
||||||
.width(800)
|
.width(800)
|
||||||
.actionButtonText(Res.get("createOffer.resetToDefault"))
|
.actionButtonText(Res.get("createOffer.resetToDefault"))
|
||||||
.onAction(() -> {
|
.onAction(() -> {
|
||||||
dataModel.setBuyerSecurityDeposit(defaultSecurityDeposit);
|
dataModel.setBuyerSecurityDeposit(defaultSecurityDeposit);
|
||||||
ignoreSecurityDepositStringListener = true;
|
ignoreSecurityDepositStringListener = true;
|
||||||
buyerSecurityDeposit.set(btcFormatter.formatCoin(dataModel.getBuyerSecurityDeposit().get()));
|
buyerSecurityDeposit.set(btcFormatter.formatCoin(dataModel.getBuyerSecurityDeposit().get()));
|
||||||
ignoreSecurityDepositStringListener = false;
|
ignoreSecurityDepositStringListener = false;
|
||||||
})
|
})
|
||||||
.closeButtonText(Res.get("createOffer.useLowerValue"))
|
.closeButtonText(Res.get("createOffer.useLowerValue"))
|
||||||
.onClose(this::applyBuyerSecurityDepositOnFocusOut)
|
.onClose(this::applyBuyerSecurityDepositOnFocusOut)
|
||||||
.dontShowAgainId(key)
|
.dontShowAgainId(key)
|
||||||
.show();
|
.show();
|
||||||
} else {
|
} else {
|
||||||
applyBuyerSecurityDepositOnFocusOut();
|
applyBuyerSecurityDepositOnFocusOut();
|
||||||
}
|
}
|
||||||
@ -796,12 +800,12 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||||||
Popup popup = new Popup<>();
|
Popup popup = new Popup<>();
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
popup.warning(Res.get("createOffer.priceOutSideOfDeviation",
|
popup.warning(Res.get("createOffer.priceOutSideOfDeviation",
|
||||||
btcFormatter.formatToPercentWithSymbol(preferences.getMaxPriceDistanceInPercent())))
|
btcFormatter.formatToPercentWithSymbol(preferences.getMaxPriceDistanceInPercent())))
|
||||||
.actionButtonText(Res.get("createOffer.changePrice"))
|
.actionButtonText(Res.get("createOffer.changePrice"))
|
||||||
.onAction(popup::hide)
|
.onAction(popup::hide)
|
||||||
.closeButtonTextWithGoTo("navigation.settings.preferences")
|
.closeButtonTextWithGoTo("navigation.settings.preferences")
|
||||||
.onClose(() -> navigation.navigateTo(MainView.class, SettingsView.class, PreferencesView.class))
|
.onClose(() -> navigation.navigateTo(MainView.class, SettingsView.class, PreferencesView.class))
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
BSFormatter getBtcFormatter() {
|
BSFormatter getBtcFormatter() {
|
||||||
@ -822,7 +826,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||||||
|
|
||||||
public String getSecurityDepositInfo() {
|
public String getSecurityDepositInfo() {
|
||||||
return btcFormatter.formatCoinWithCode(dataModel.getSecurityDeposit()) +
|
return btcFormatter.formatCoinWithCode(dataModel.getSecurityDeposit()) +
|
||||||
GUIUtil.getPercentageOfTradeAmount(dataModel.getSecurityDeposit(), dataModel.getAmount().get(), btcFormatter);
|
GUIUtil.getPercentageOfTradeAmount(dataModel.getSecurityDeposit(), dataModel.getAmount().get(), btcFormatter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMakerFee() {
|
public String getMakerFee() {
|
||||||
@ -846,7 +850,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||||||
public String getTxFee() {
|
public String getTxFee() {
|
||||||
Coin txFeeAsCoin = dataModel.getTxFee();
|
Coin txFeeAsCoin = dataModel.getTxFee();
|
||||||
return btcFormatter.formatCoinWithCode(txFeeAsCoin) +
|
return btcFormatter.formatCoinWithCode(txFeeAsCoin) +
|
||||||
GUIUtil.getPercentageOfTradeAmount(txFeeAsCoin, dataModel.getAmount().get(), btcFormatter);
|
GUIUtil.getPercentageOfTradeAmount(txFeeAsCoin, dataModel.getAmount().get(), btcFormatter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -971,8 +975,8 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||||||
|
|
||||||
private void updateSpinnerInfo() {
|
private void updateSpinnerInfo() {
|
||||||
if (!showPayFundsScreenDisplayed.get() ||
|
if (!showPayFundsScreenDisplayed.get() ||
|
||||||
errorMessage.get() != null ||
|
errorMessage.get() != null ||
|
||||||
showTransactionPublishedScreen.get()) {
|
showTransactionPublishedScreen.get()) {
|
||||||
waitingForFundsText.set("");
|
waitingForFundsText.set("");
|
||||||
} else if (dataModel.getIsBtcWalletFunded().get()) {
|
} else if (dataModel.getIsBtcWalletFunded().get()) {
|
||||||
waitingForFundsText.set("");
|
waitingForFundsText.set("");
|
||||||
@ -991,13 +995,13 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||||||
private void updateButtonDisableState() {
|
private void updateButtonDisableState() {
|
||||||
log.debug("updateButtonDisableState");
|
log.debug("updateButtonDisableState");
|
||||||
boolean inputDataValid = isBtcInputValid(amount.get()).isValid &&
|
boolean inputDataValid = isBtcInputValid(amount.get()).isValid &&
|
||||||
isBtcInputValid(minAmount.get()).isValid &&
|
isBtcInputValid(minAmount.get()).isValid &&
|
||||||
isPriceInputValid(price.get()).isValid &&
|
isPriceInputValid(price.get()).isValid &&
|
||||||
securityDepositValidator.validate(buyerSecurityDeposit.get()).isValid &&
|
securityDepositValidator.validate(buyerSecurityDeposit.get()).isValid &&
|
||||||
dataModel.getPrice().get() != null &&
|
dataModel.getPrice().get() != null &&
|
||||||
dataModel.getPrice().get().getValue() != 0 &&
|
dataModel.getPrice().get().getValue() != 0 &&
|
||||||
isVolumeInputValid(volume.get()).isValid &&
|
isVolumeInputValid(volume.get()).isValid &&
|
||||||
dataModel.isMinAmountLessOrEqualAmount();
|
dataModel.isMinAmountLessOrEqualAmount();
|
||||||
|
|
||||||
isNextButtonDisabled.set(!inputDataValid);
|
isNextButtonDisabled.set(!inputDataValid);
|
||||||
// boolean notSufficientFees = dataModel.isWalletFunded.get() && dataModel.isMainNet.get() && !dataModel.isFeeFromFundingTxSufficient.get();
|
// boolean notSufficientFees = dataModel.isWalletFunded.get() && dataModel.isMainNet.get() && !dataModel.isFeeFromFundingTxSufficient.get();
|
||||||
|
Loading…
Reference in New Issue
Block a user