fix auto correction to < min amount when creating non-fiat offers #688
This commit is contained in:
parent
99e73abd3b
commit
23c14a496a
@ -84,8 +84,8 @@ public class CoinUtil {
|
|||||||
return getRoundedAtmCashAmount(amount, price, maxTradeLimit);
|
return getRoundedAtmCashAmount(amount, price, maxTradeLimit);
|
||||||
} else if (CurrencyUtil.isVolumeRoundedToNearestUnit(currencyCode)) {
|
} else if (CurrencyUtil.isVolumeRoundedToNearestUnit(currencyCode)) {
|
||||||
return getRoundedAmountUnit(amount, price, maxTradeLimit);
|
return getRoundedAmountUnit(amount, price, maxTradeLimit);
|
||||||
} else if (CurrencyUtil.isTraditionalCurrency(currencyCode)) {
|
} else if (CurrencyUtil.isFiatCurrency(currencyCode)) {
|
||||||
return getRoundedAmountPrecise(amount, price, maxTradeLimit);
|
return getRoundedAmount4Decimals(amount, price, maxTradeLimit);
|
||||||
}
|
}
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ public class CoinUtil {
|
|||||||
return getAdjustedAmount(amount, price, maxTradeLimit, 1);
|
return getAdjustedAmount(amount, price, maxTradeLimit, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BigInteger getRoundedAmountPrecise(BigInteger amount, Price price, long maxTradeLimit) {
|
public static BigInteger getRoundedAmount4Decimals(BigInteger amount, Price price, long maxTradeLimit) {
|
||||||
DecimalFormat decimalFormat = new DecimalFormat("#.####");
|
DecimalFormat decimalFormat = new DecimalFormat("#.####");
|
||||||
double roundedXmrAmount = Double.parseDouble(decimalFormat.format(HavenoUtils.atomicUnitsToXmr(amount)));
|
double roundedXmrAmount = Double.parseDouble(decimalFormat.format(HavenoUtils.atomicUnitsToXmr(amount)));
|
||||||
return HavenoUtils.xmrToAtomicUnits(roundedXmrAmount);
|
return HavenoUtils.xmrToAtomicUnits(roundedXmrAmount);
|
||||||
|
@ -48,7 +48,6 @@ import haveno.core.xmr.model.XmrAddressEntry;
|
|||||||
import haveno.core.xmr.wallet.Restrictions;
|
import haveno.core.xmr.wallet.Restrictions;
|
||||||
import haveno.core.xmr.wallet.XmrWalletService;
|
import haveno.core.xmr.wallet.XmrWalletService;
|
||||||
import haveno.desktop.Navigation;
|
import haveno.desktop.Navigation;
|
||||||
import haveno.desktop.util.DisplayUtils;
|
|
||||||
import haveno.desktop.util.GUIUtil;
|
import haveno.desktop.util.GUIUtil;
|
||||||
import haveno.network.p2p.P2PService;
|
import haveno.network.p2p.P2PService;
|
||||||
import javafx.beans.property.BooleanProperty;
|
import javafx.beans.property.BooleanProperty;
|
||||||
@ -519,12 +518,16 @@ public abstract class MutableOfferDataModel extends OfferDataModel {
|
|||||||
void calculateAmount() {
|
void calculateAmount() {
|
||||||
if (isNonZeroPrice.test(price) && isNonZeroVolume.test(volume) && allowAmountUpdate) {
|
if (isNonZeroPrice.test(price) && isNonZeroVolume.test(volume) && allowAmountUpdate) {
|
||||||
try {
|
try {
|
||||||
BigInteger value = HavenoUtils.coinToAtomicUnits(DisplayUtils.reduceTo4Decimals(HavenoUtils.atomicUnitsToCoin(price.get().getAmountByVolume(volume.get())), btcFormatter));
|
Volume volumeBefore = volume.get();
|
||||||
value = CoinUtil.getRoundedAmount(value, price.get(), getMaxTradeLimit(), tradeCurrencyCode.get(), paymentAccount.getPaymentMethod().getId());
|
|
||||||
|
|
||||||
calculateVolume();
|
calculateVolume();
|
||||||
|
|
||||||
amount.set(value);
|
// if the volume != amount * price, we need to adjust the amount
|
||||||
|
if (amount.get() == null || !volumeBefore.equals(price.get().getVolumeByAmount(amount.get()))) {
|
||||||
|
BigInteger value = price.get().getAmountByVolume(volumeBefore);
|
||||||
|
value = CoinUtil.getRoundedAmount(value, price.get(), getMaxTradeLimit(), tradeCurrencyCode.get(), paymentAccount.getPaymentMethod().getId());
|
||||||
|
amount.set(value);
|
||||||
|
}
|
||||||
|
|
||||||
calculateTotalToPay();
|
calculateTotalToPay();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
log.error(t.toString());
|
log.error(t.toString());
|
||||||
|
Loading…
Reference in New Issue
Block a user