From 4a171c9baa076081a56942affdd2a5038af6be90 Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 13 Jul 2022 18:09:19 -0400 Subject: [PATCH] cap stagenet fiat offers to 1 xmr until trade credits supported (#355) --- .../core/payment/payload/PaymentMethod.java | 17 +++++- .../java/bisq/core/util/ParsingUtils.java | 53 +++++++------------ .../desktop/components/TextFieldWithIcon.java | 6 ++- .../main/offer/MutableOfferViewModel.java | 7 +-- 4 files changed, 43 insertions(+), 40 deletions(-) diff --git a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java index d3e35fdf..bbe8ede6 100644 --- a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java +++ b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java @@ -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 MAX_FIAT_STAGENET_XMR) { + riskBasedTradeLimit = ParsingUtils.xmrToCentineros(MAX_FIAT_STAGENET_XMR); + } + return Coin.valueOf(riskBasedTradeLimit); } public String getShortName() { diff --git a/core/src/main/java/bisq/core/util/ParsingUtils.java b/core/src/main/java/bisq/core/util/ParsingUtils.java index 7c230aea..de6c8fd2 100644 --- a/core/src/main/java/bisq/core/util/ParsingUtils.java +++ b/core/src/main/java/bisq/core/util/ParsingUtils.java @@ -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) { diff --git a/desktop/src/main/java/bisq/desktop/components/TextFieldWithIcon.java b/desktop/src/main/java/bisq/desktop/components/TextFieldWithIcon.java index eee8e4cc..4684d4b7 100644 --- a/desktop/src/main/java/bisq/desktop/components/TextFieldWithIcon.java +++ b/desktop/src/main/java/bisq/desktop/components/TextFieldWithIcon.java @@ -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); + }); } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java index e31f460d..e4f724a7 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java @@ -717,9 +717,10 @@ public abstract class MutableOfferViewModel 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(); }