cap stagenet fiat offers to 1 xmr until trade credits supported (#355)

This commit is contained in:
woodser 2022-07-13 18:09:19 -04:00 committed by GitHub
parent 7157defea5
commit 4a171c9baa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 40 deletions

View File

@ -68,10 +68,12 @@ import bisq.core.payment.UpiAccount;
import bisq.core.payment.VerseAccount;
import bisq.core.payment.WeChatPayAccount;
import bisq.core.payment.WesternUnionAccount;
import bisq.core.util.ParsingUtils;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.Res;
import bisq.core.locale.TradeCurrency;
import bisq.common.config.BaseCurrencyNetwork;
import bisq.common.config.Config;
import bisq.common.proto.persistable.PersistablePayload;
import org.bitcoinj.core.Coin;
@ -113,6 +115,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
private static final Coin DEFAULT_TRADE_LIMIT_LOW_RISK = Coin.parseCoin("50");
private static final Coin DEFAULT_TRADE_LIMIT_MID_RISK = Coin.parseCoin("25");
private static final Coin DEFAULT_TRADE_LIMIT_HIGH_RISK = Coin.parseCoin("12.5");
private static final double MAX_FIAT_STAGENET_XMR = 1.0; // denominated in XMR
public static final String UPHOLD_ID = "UPHOLD";
public static final String MONEY_BEAM_ID = "MONEY_BEAM";
@ -477,9 +480,19 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
Coin.valueOf(maxTradeLimit).toFriendlyString(), this);
}
// get risk based trade limit
TradeLimits tradeLimits = new TradeLimits();
long maxTradeLimit = tradeLimits.getMaxTradeLimit().value;
return Coin.valueOf(tradeLimits.getRoundedRiskBasedTradeLimit(maxTradeLimit, riskFactor));
long riskBasedTradeLimit = tradeLimits.getRoundedRiskBasedTradeLimit(maxTradeLimit, riskFactor); // as centineros
// if fiat and stagenet, cap offer amounts before trade credits supported
// TODO: remove this when trade credits supported
boolean isFiat = CurrencyUtil.isFiatCurrency(currencyCode);
boolean isStagenet = Config.baseCurrencyNetwork() == BaseCurrencyNetwork.XMR_STAGENET;
if (isFiat && isStagenet && ParsingUtils.centinerosToXmr(riskBasedTradeLimit) > MAX_FIAT_STAGENET_XMR) {
riskBasedTradeLimit = ParsingUtils.xmrToCentineros(MAX_FIAT_STAGENET_XMR);
}
return Coin.valueOf(riskBasedTradeLimit);
}
public String getShortName() {

View File

@ -17,53 +17,40 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class ParsingUtils {
/**
* Multiplier to convert centineros (the base XMR unit of Coin) to atomic units.
*
* TODO: change base unit to atomic units and long
* TODO: move these static utilities?
*/
// multipliers to convert units
private static BigInteger CENTINEROS_AU_MULTIPLIER = new BigInteger("10000");
private static BigInteger MONERO_AU_MULTIPLIER = new BigInteger("1000000000000");
private static BigInteger XMR_AU_MULTIPLIER = new BigInteger("1000000000000");
/**
* Convert Coin (denominated in centineros) to atomic units.
*
* @param coin has an amount denominated in centineros
* @return BigInteger the coin amount denominated in atomic units
*/
public static BigInteger coinToAtomicUnits(Coin coin) {
return centinerosToAtomicUnits(coin.value);
}
/**
* Convert centineros (the base unit of Coin) to atomic units.
*
* @param centineros denominates an amount of XMR in centineros
* @return BigInteger the amount denominated in atomic units
*/
public static BigInteger centinerosToAtomicUnits(long centineros) {
return BigInteger.valueOf(centineros).multiply(ParsingUtils.CENTINEROS_AU_MULTIPLIER);
}
/**
* Convert atomic units to centineros.
*
* @param atomicUnits is an amount in atomic units
* @return the amount in centineros
*/
public static long atomicUnitsToCentineros(long atomicUnits) { // TODO: atomic units should be BigInteger, this should return double, else losing precision
public static double centinerosToXmr(long centineros) {
return atomicUnitsToXmr(centinerosToAtomicUnits(centineros));
}
public static long atomicUnitsToCentineros(long atomicUnits) { // TODO: atomic units should be BigInteger; remove this?
return atomicUnits / CENTINEROS_AU_MULTIPLIER.longValue();
}
/**
* Convert atomic units to centineros.
*
* @param atomicUnits is an amount in atomic units
* @return the amount in centineros
*/
public static long atomicUnitsToCentineros(BigInteger atomicUnits) {
return atomicUnits.divide(CENTINEROS_AU_MULTIPLIER).longValueExact();
}
public static double atomicUnitsToXmr(BigInteger atomicUnits) {
return new BigDecimal(atomicUnits).divide(new BigDecimal(MONERO_AU_MULTIPLIER)).doubleValue();
return new BigDecimal(atomicUnits).divide(new BigDecimal(XMR_AU_MULTIPLIER)).doubleValue();
}
public static BigInteger xmrToAtomicUnits(double xmr) {
return BigDecimal.valueOf(xmr).multiply(new BigDecimal(XMR_AU_MULTIPLIER)).toBigInteger();
}
public static long xmrToCentineros(double xmr) {
return atomicUnitsToCentineros(xmrToAtomicUnits(xmr));
}
public static Coin parseToCoin(String input, CoinFormatter coinFormatter) {

View File

@ -72,7 +72,9 @@ public class TextFieldWithIcon extends AnchorPane {
}
public void setText(String text) {
textField.setText(text);
dummyTextField.setText(text);
UserThread.execute(() -> {
textField.setText(text);
dummyTextField.setText(text);
});
}
}

View File

@ -717,9 +717,10 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
minAmountValidationResult.set(isBtcInputValid(minAmount.get()));
} else if (amount.get() != null && btcValidator.getMaxTradeLimit() != null && btcValidator.getMaxTradeLimit().value == OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.value) {
amount.set(btcFormatter.formatCoin(btcValidator.getMaxTradeLimit()));
new Popup().information(Res.get("popup.warning.tradeLimitDueAccountAgeRestriction.buyer",
btcFormatter.formatCoinWithCode(OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT),
Res.get("offerbook.warning.newVersionAnnouncement")))
boolean isBuy = dataModel.getDirection() == OfferDirection.BUY;
new Popup().information(Res.get(isBuy ? "popup.warning.tradeLimitDueAccountAgeRestriction.buyer" : "popup.warning.tradeLimitDueAccountAgeRestriction.seller",
btcFormatter.formatCoinWithCode(OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT),
Res.get("offerbook.warning.newVersionAnnouncement")))
.width(900)
.show();
}