mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-11-17 08:17:57 +00:00
fix take offer amount adjustment for range trades
This commit is contained in:
parent
77cf67e6f0
commit
33eb98e3c4
1 changed files with 13 additions and 13 deletions
|
@ -74,7 +74,7 @@ import static javafx.beans.binding.Bindings.createStringBinding;
|
||||||
class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> implements ViewModel {
|
class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> implements ViewModel {
|
||||||
final TakeOfferDataModel dataModel;
|
final TakeOfferDataModel dataModel;
|
||||||
private final OfferUtil offerUtil;
|
private final OfferUtil offerUtil;
|
||||||
private final XmrValidator btcValidator;
|
private final XmrValidator xmrValidator;
|
||||||
private final P2PService p2PService;
|
private final P2PService p2PService;
|
||||||
private final AccountAgeWitnessService accountAgeWitnessService;
|
private final AccountAgeWitnessService accountAgeWitnessService;
|
||||||
private final Navigation navigation;
|
private final Navigation navigation;
|
||||||
|
@ -136,7 +136,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
||||||
super(dataModel);
|
super(dataModel);
|
||||||
this.dataModel = dataModel;
|
this.dataModel = dataModel;
|
||||||
this.offerUtil = offerUtil;
|
this.offerUtil = offerUtil;
|
||||||
this.btcValidator = btcValidator;
|
this.xmrValidator = btcValidator;
|
||||||
this.p2PService = p2PService;
|
this.p2PService = p2PService;
|
||||||
this.accountAgeWitnessService = accountAgeWitnessService;
|
this.accountAgeWitnessService = accountAgeWitnessService;
|
||||||
this.navigation = navigation;
|
this.navigation = navigation;
|
||||||
|
@ -210,9 +210,9 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
||||||
|
|
||||||
errorMessage.set(offer.getErrorMessage());
|
errorMessage.set(offer.getErrorMessage());
|
||||||
|
|
||||||
btcValidator.setMaxValue(offer.getAmount());
|
xmrValidator.setMaxValue(offer.getAmount());
|
||||||
btcValidator.setMaxTradeLimit(BigInteger.valueOf(dataModel.getMaxTradeLimit()).min(offer.getAmount()));
|
xmrValidator.setMaxTradeLimit(BigInteger.valueOf(dataModel.getMaxTradeLimit()).min(offer.getAmount()));
|
||||||
btcValidator.setMinValue(offer.getMinAmount());
|
xmrValidator.setMinValue(offer.getMinAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -240,7 +240,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
||||||
|
|
||||||
public void onPaymentAccountSelected(PaymentAccount paymentAccount) {
|
public void onPaymentAccountSelected(PaymentAccount paymentAccount) {
|
||||||
dataModel.onPaymentAccountSelected(paymentAccount);
|
dataModel.onPaymentAccountSelected(paymentAccount);
|
||||||
btcValidator.setMaxTradeLimit(BigInteger.valueOf(dataModel.getMaxTradeLimit()).min(offer.getAmount()));
|
xmrValidator.setMaxTradeLimit(BigInteger.valueOf(dataModel.getMaxTradeLimit()).min(offer.getAmount()));
|
||||||
updateButtonDisableState();
|
updateButtonDisableState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
||||||
// On focus out we do validation and apply the data to the model
|
// On focus out we do validation and apply the data to the model
|
||||||
void onFocusOutAmountTextField(boolean oldValue, boolean newValue, String userInput) {
|
void onFocusOutAmountTextField(boolean oldValue, boolean newValue, String userInput) {
|
||||||
if (oldValue && !newValue) {
|
if (oldValue && !newValue) {
|
||||||
InputValidator.ValidationResult result = isBtcInputValid(amount.get());
|
InputValidator.ValidationResult result = isXmrInputValid(amount.get());
|
||||||
amountValidationResult.set(result);
|
amountValidationResult.set(result);
|
||||||
if (result.isValid) {
|
if (result.isValid) {
|
||||||
showWarningInvalidBtcDecimalPlaces.set(!DisplayUtils.hasBtcValidDecimals(userInput, xmrFormatter));
|
showWarningInvalidBtcDecimalPlaces.set(!DisplayUtils.hasBtcValidDecimals(userInput, xmrFormatter));
|
||||||
|
@ -328,7 +328,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
||||||
if (dataModel.wouldCreateDustForMaker())
|
if (dataModel.wouldCreateDustForMaker())
|
||||||
amountValidationResult.set(new InputValidator.ValidationResult(false,
|
amountValidationResult.set(new InputValidator.ValidationResult(false,
|
||||||
Res.get("takeOffer.validation.amountLargerThanOfferAmountMinusFee")));
|
Res.get("takeOffer.validation.amountLargerThanOfferAmountMinusFee")));
|
||||||
} else if (btcValidator.getMaxTradeLimit() != null && btcValidator.getMaxTradeLimit().equals(OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT)) {
|
} else if (xmrValidator.getMaxTradeLimit() != null && xmrValidator.getMaxTradeLimit().equals(OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT)) {
|
||||||
if (dataModel.getDirection() == OfferDirection.BUY) {
|
if (dataModel.getDirection() == OfferDirection.BUY) {
|
||||||
new Popup().information(Res.get("popup.warning.tradeLimitDueAccountAgeRestriction.seller",
|
new Popup().information(Res.get("popup.warning.tradeLimitDueAccountAgeRestriction.seller",
|
||||||
HavenoUtils.formatXmr(OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT, true),
|
HavenoUtils.formatXmr(OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT, true),
|
||||||
|
@ -443,7 +443,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateButtonDisableState() {
|
private void updateButtonDisableState() {
|
||||||
boolean inputDataValid = isBtcInputValid(amount.get()).isValid
|
boolean inputDataValid = isXmrInputValid(amount.get()).isValid
|
||||||
&& dataModel.isMinAmountLessOrEqualAmount()
|
&& dataModel.isMinAmountLessOrEqualAmount()
|
||||||
&& !dataModel.isAmountLargerThanOfferAmount()
|
&& !dataModel.isAmountLargerThanOfferAmount()
|
||||||
&& isOfferAvailable.get()
|
&& isOfferAvailable.get()
|
||||||
|
@ -470,7 +470,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
||||||
|
|
||||||
private void createListeners() {
|
private void createListeners() {
|
||||||
amountStrListener = (ov, oldValue, newValue) -> {
|
amountStrListener = (ov, oldValue, newValue) -> {
|
||||||
if (isBtcInputValid(newValue).isValid) {
|
if (isXmrInputValid(newValue).isValid) {
|
||||||
setAmountToModel();
|
setAmountToModel();
|
||||||
calculateVolume();
|
calculateVolume();
|
||||||
dataModel.calculateTotalToPay();
|
dataModel.calculateTotalToPay();
|
||||||
|
@ -580,7 +580,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
||||||
&& !isAmountEqualMinAmount(amount) && !isAmountEqualMaxAmount(amount)) {
|
&& !isAmountEqualMinAmount(amount) && !isAmountEqualMaxAmount(amount)) {
|
||||||
// We only apply the rounding if the amount is variable (minAmount is lower as amount).
|
// We only apply the rounding if the amount is variable (minAmount is lower as amount).
|
||||||
// Otherwise we could get an amount lower then the minAmount set by rounding
|
// Otherwise we could get an amount lower then the minAmount set by rounding
|
||||||
amount = CoinUtil.getRoundedAmount(dataModel.getAmount().get(), price, maxTradeLimit, dataModel.getOffer().getCurrencyCode(), dataModel.getOffer().getPaymentMethodId());
|
amount = CoinUtil.getRoundedAmount(amount, price, maxTradeLimit, dataModel.getOffer().getCurrencyCode(), dataModel.getOffer().getPaymentMethodId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dataModel.applyAmount(amount);
|
dataModel.applyAmount(amount);
|
||||||
|
@ -618,8 +618,8 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputValidator.ValidationResult isBtcInputValid(String input) {
|
private InputValidator.ValidationResult isXmrInputValid(String input) {
|
||||||
return btcValidator.validate(input);
|
return xmrValidator.validate(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Offer getOffer() {
|
public Offer getOffer() {
|
||||||
|
|
Loading…
Reference in a new issue