remove popup and improve label for empty or invalid offer amount input

This commit is contained in:
woodser 2025-12-20 08:10:43 -05:00
parent 2c1b60de72
commit 6919552e91
No known key found for this signature in database
GPG key ID: 55A10DD48ADEE5EF
2 changed files with 36 additions and 32 deletions

View file

@ -321,7 +321,7 @@ public class HavenoUtils {
}
public static BigInteger parseXmr(String input) {
if (input == null || input.length() == 0) return BigInteger.ZERO;
if (input == null || input.length() == 0) return BigInteger.ZERO; // TODO: throw instead?
try {
return new BigDecimal(input).multiply(new BigDecimal(XMR_AU_MULTIPLIER)).toBigInteger();
} catch (Exception e) {

View file

@ -741,38 +741,42 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
if (minAmount.get() != null)
minAmountValidationResult.set(isXmrInputValid(minAmount.get()));
} else if (amount.get() != null && xmrValidator.getMaxTradeLimit() != null && xmrValidator.getMaxTradeLimit().longValueExact() == OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.longValueExact()) {
if (ParsingUtils.parseNumberStringToDouble(amount.get()) < HavenoUtils.atomicUnitsToXmr(dataModel.getMinTradeLimit())) {
amountValidationResult.set(result);
} else {
amount.set(HavenoUtils.formatXmr(xmrValidator.getMaxTradeLimit()));
boolean isBuy = dataModel.getDirection() == OfferDirection.BUY;
boolean isSellerWithinReleaseWindow = !isBuy && HavenoUtils.isReleasedWithinDays(HavenoUtils.RELEASE_LIMIT_DAYS);
if (isSellerWithinReleaseWindow) {
// format release date plus days
Date releaseDate = HavenoUtils.getReleaseDate();
Calendar c = Calendar.getInstance();
c.setTime(releaseDate);
c.add(Calendar.DATE, HavenoUtils.RELEASE_LIMIT_DAYS);
Date releaseDatePlusDays = c.getTime();
SimpleDateFormat formatter = new SimpleDateFormat("MMMM d, yyyy");
String releaseDatePlusDaysAsString = formatter.format(releaseDatePlusDays);
// popup temporary restriction
new Popup().information(Res.get("popup.warning.tradeLimitDueAccountAgeRestriction.seller.releaseLimit",
HavenoUtils.formatXmr(OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT, true),
releaseDatePlusDaysAsString,
Res.get("offerbook.warning.newVersionAnnouncement")))
.width(900)
.show();
} else if (amount.get() != null && !amount.get().isEmpty() && xmrValidator.getMaxTradeLimit() != null && xmrValidator.getMaxTradeLimit().longValueExact() == OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.longValueExact()) { // TODO: tolerated small amount will only equal max trade limit for riskiest payment methods, so that logic is not relevant?
try {
if (ParsingUtils.parseNumberStringToDouble(amount.get()) < HavenoUtils.atomicUnitsToXmr(dataModel.getMinTradeLimit())) {
amountValidationResult.set(result);
} else {
new Popup().information(Res.get(isBuy ? "popup.warning.tradeLimitDueAccountAgeRestriction.buyer" : "popup.warning.tradeLimitDueAccountAgeRestriction.seller",
HavenoUtils.formatXmr(OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT, true),
Res.get("offerbook.warning.newVersionAnnouncement")))
.width(900)
.show();
amount.set(HavenoUtils.formatXmr(xmrValidator.getMaxTradeLimit()));
boolean isBuy = dataModel.getDirection() == OfferDirection.BUY;
boolean isSellerWithinReleaseWindow = !isBuy && HavenoUtils.isReleasedWithinDays(HavenoUtils.RELEASE_LIMIT_DAYS);
if (isSellerWithinReleaseWindow) {
// format release date plus days
Date releaseDate = HavenoUtils.getReleaseDate();
Calendar c = Calendar.getInstance();
c.setTime(releaseDate);
c.add(Calendar.DATE, HavenoUtils.RELEASE_LIMIT_DAYS);
Date releaseDatePlusDays = c.getTime();
SimpleDateFormat formatter = new SimpleDateFormat("MMMM d, yyyy");
String releaseDatePlusDaysAsString = formatter.format(releaseDatePlusDays);
// popup temporary restriction
new Popup().information(Res.get("popup.warning.tradeLimitDueAccountAgeRestriction.seller.releaseLimit",
HavenoUtils.formatXmr(xmrValidator.getMaxTradeLimit(), true),
releaseDatePlusDaysAsString,
Res.get("offerbook.warning.newVersionAnnouncement")))
.width(900)
.show();
} else {
new Popup().information(Res.get(isBuy ? "popup.warning.tradeLimitDueAccountAgeRestriction.buyer" : "popup.warning.tradeLimitDueAccountAgeRestriction.seller",
HavenoUtils.formatXmr(xmrValidator.getMaxTradeLimit(), true),
Res.get("offerbook.warning.newVersionAnnouncement")))
.width(900)
.show();
}
}
} catch (Exception e) {
log.warn("Error while parsing amount on focus out: ", e);
}
}
@ -1248,7 +1252,7 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
}
private InputValidator.ValidationResult isXmrInputValid(String input) {
return xmrValidator.validate("" + HavenoUtils.atomicUnitsToXmr(HavenoUtils.parseXmr(input)));
return xmrValidator.validate(input);
}
private InputValidator.ValidationResult isPriceInputValid(String input) {