Use Offer.isFiat helper method

This commit is contained in:
Christoph Atteneder 2022-04-11 12:31:54 +02:00
parent 63ea054026
commit 9a3ed33238
No known key found for this signature in database
GPG key ID: CD5DC1C529CDFD3B
14 changed files with 21 additions and 27 deletions

View file

@ -269,7 +269,7 @@ public class Offer implements NetworkPayload, PersistablePayload {
Volume volumeByAmount = price.getVolumeByAmount(amount);
if (offerPayloadBase.getPaymentMethodId().equals(PaymentMethod.HAL_CASH_ID))
volumeByAmount = VolumeUtil.getAdjustedVolumeForHalCash(volumeByAmount);
else if (CurrencyUtil.isFiatCurrency(offerPayloadBase.getCurrencyCode()))
else if (isFiatOffer())
volumeByAmount = VolumeUtil.getRoundedFiatVolume(volumeByAmount);
return volumeByAmount;

View file

@ -19,7 +19,6 @@ package bisq.core.offer;
import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.filter.FilterManager;
import bisq.core.locale.CurrencyUtil;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.PaymentAccountUtil;
import bisq.core.user.Preferences;
@ -178,7 +177,7 @@ public class OfferFilterService {
return insufficientCounterpartyTradeLimitCache.get(offerId);
}
boolean result = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) &&
boolean result = offer.isFiatOffer() &&
!accountAgeWitnessService.verifyPeersTradeAmount(offer, offer.getAmount(),
errorMessage -> {
});
@ -205,7 +204,7 @@ public class OfferFilterService {
accountOptional.isPresent() ? accountOptional.get().getAccountName() : "null",
Coin.valueOf(myTradeLimit).toFriendlyString(),
Coin.valueOf(offerMinAmount).toFriendlyString());
boolean result = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) &&
boolean result = offer.isFiatOffer() &&
accountOptional.isPresent() &&
myTradeLimit < offerMinAmount;
myInsufficientTradeLimitCache.put(offerId, result);

View file

@ -20,7 +20,6 @@ package bisq.core.offer.bisq_v1;
import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.locale.CurrencyUtil;
import bisq.core.monetary.Price;
import bisq.core.monetary.Volume;
import bisq.core.offer.Offer;
@ -196,7 +195,7 @@ public class TakeOfferModel implements Model {
if (offer.getPaymentMethod().getId().equals(PaymentMethod.HAL_CASH_ID))
volumeByAmount = getAdjustedVolumeForHalCash(volumeByAmount);
else if (CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()))
else if (offer.isFiatOffer())
volumeByAmount = getRoundedFiatVolume(volumeByAmount);
volume = volumeByAmount;

View file

@ -18,7 +18,6 @@
package bisq.core.trade.model.bisq_v1;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.locale.CurrencyUtil;
import bisq.core.monetary.Price;
import bisq.core.monetary.Volume;
import bisq.core.offer.Offer;
@ -776,7 +775,7 @@ public abstract class Trade extends TradeModel {
if (offer != null) {
if (offer.getPaymentMethod().getId().equals(PaymentMethod.HAL_CASH_ID))
volumeByAmount = VolumeUtil.getAdjustedVolumeForHalCash(volumeByAmount);
else if (CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()))
else if (offer.isFiatOffer())
volumeByAmount = VolumeUtil.getRoundedFiatVolume(volumeByAmount);
}
return volumeByAmount;

View file

@ -19,7 +19,6 @@ package bisq.desktop.components;
import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.alert.PrivateNotificationManager;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.Res;
import bisq.core.offer.Offer;
import bisq.core.payment.payload.PaymentMethod;
@ -107,7 +106,7 @@ public class PeerInfoIconTrading extends PeerInfoIcon {
offer = tradeModel.getOffer();
}
checkNotNull(offer, "Offer must not be null");
isFiatCurrency = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode());
isFiatCurrency = offer.isFiatOffer();
initialize(role, offer, tradeModel, privateNotificationManager, useDevPrivilegeKeys);
}

View file

@ -253,13 +253,13 @@ class OfferBookChartViewModel extends ActivatableViewModel {
}
public int getMaxNumberOfPriceZeroDecimalsToColorize(Offer offer) {
return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())
return offer.isFiatOffer()
? GUIUtil.FIAT_DECIMALS_WITH_ZEROS
: GUIUtil.ALTCOINS_DECIMALS_WITH_ZEROS;
}
public int getZeroDecimalsForPrice(Offer offer) {
return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())
return offer.isFiatOffer()
? GUIUtil.FIAT_PRICE_DECIMALS_WITH_ZEROS
: GUIUtil.ALTCOINS_DECIMALS_WITH_ZEROS;
}

View file

@ -492,7 +492,7 @@ class TakeOfferDataModel extends OfferDataModel {
Volume volumeByAmount = tradePrice.getVolumeByAmount(amount.get());
if (offer.getPaymentMethod().getId().equals(PaymentMethod.HAL_CASH_ID))
volumeByAmount = VolumeUtil.getAdjustedVolumeForHalCash(volumeByAmount);
else if (CurrencyUtil.isFiatCurrency(getCurrencyCode()))
else if (offer.isFiatOffer())
volumeByAmount = VolumeUtil.getRoundedFiatVolume(volumeByAmount);
volume.set(volumeByAmount);

View file

@ -406,7 +406,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
addressTextField.setPaymentLabel(model.getPaymentLabel());
addressTextField.setAddress(model.dataModel.getAddressEntry().getAddressString());
if (CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())) {
if (offer.isFiatOffer()) {
Label popOverLabel = OfferViewUtil.createPopOverLabel(Res.get("offerbook.info.roundedFiatVolume"));
volumeInfoTextField.setContentForPrivacyPopOver(popOverLabel);
}
@ -1344,7 +1344,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
@NotNull
private String getTakeOfferLabel(Offer offer, String direction) {
return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ?
return offer.isFiatOffer() ?
Res.get("takeOffer.takeOfferButton", direction) :
Res.get("takeOffer.takeOfferButtonAltcoin",
direction,

View file

@ -31,7 +31,6 @@ import bisq.desktop.util.validation.BtcValidator;
import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.btc.wallet.Restrictions;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.Res;
import bisq.core.monetary.Price;
import bisq.core.offer.Offer;
@ -341,7 +340,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
maxTradeLimit);
dataModel.applyAmount(adjustedAmountForHalCash);
amount.set(btcFormatter.formatCoin(dataModel.getAmount().get()));
} else if (CurrencyUtil.isFiatCurrency(dataModel.getCurrencyCode())) {
} else if (dataModel.getOffer().isFiatOffer()) {
if (!isAmountEqualMinAmount(dataModel.getAmount().get()) && (!isAmountEqualMaxAmount(dataModel.getAmount().get()))) {
// 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
@ -624,7 +623,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
if (price != null) {
if (dataModel.isUsingHalCashAccount()) {
amount = CoinUtil.getAdjustedAmountForHalCash(amount, price, maxTradeLimit);
} else if (CurrencyUtil.isFiatCurrency(dataModel.getCurrencyCode())
} else if (dataModel.getOffer().isFiatOffer()
&& !isAmountEqualMinAmount(amount) && !isAmountEqualMaxAmount(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

View file

@ -120,7 +120,7 @@ public class BtcOfferBookViewModel extends OfferBookViewModel {
return offerBookListItem -> {
Offer offer = offerBookListItem.getOffer();
boolean directionResult = offer.getDirection() != direction;
boolean currencyResult = (showAllTradeCurrenciesProperty.get() && CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())) ||
boolean currencyResult = (showAllTradeCurrenciesProperty.get() && offer.isFiatOffer()) ||
offer.getCurrencyCode().equals(selectedTradeCurrency.getCode());
boolean paymentMethodResult = showAllPaymentMethods ||
offer.getPaymentMethod().equals(selectedPaymentMethod);

View file

@ -774,7 +774,7 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
}).show();
} else {
var accountViewClass = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? FiatAccountsView.class : AltCoinAccountsView.class;
var accountViewClass = offer.isFiatOffer() ? FiatAccountsView.class : AltCoinAccountsView.class;
new Popup().headLine(headline)
.instruction(Res.get("offerbook.warning.noMatchingAccount.msg"))

View file

@ -450,7 +450,7 @@ abstract class OfferBookViewModel extends ActivatableViewModel {
}
int getNumberOfDecimalsForVolume(OfferBookListItem item) {
return CurrencyUtil.isFiatCurrency(item.getOffer().getCurrencyCode()) ? GUIUtil.FIAT_DECIMALS_WITH_ZEROS : GUIUtil.ALTCOINS_DECIMALS_WITH_ZEROS;
return item.getOffer().isFiatOffer() ? GUIUtil.FIAT_DECIMALS_WITH_ZEROS : GUIUtil.ALTCOINS_DECIMALS_WITH_ZEROS;
}
String getPaymentMethod(OfferBookListItem item) {

View file

@ -392,20 +392,20 @@ public class OfferDetailsWindow extends Overlay<OfferDetailsWindow> {
boolean isBuyerRole = isPlaceOffer == isBuyOffer;
String tradeCurrencyByCode = offer.getCurrencyCode();
String placeOfferButtonText = isBuyerRole ?
CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ?
offer.isFiatOffer() ?
Res.get("offerDetailsWindow.confirm.maker", Res.get("shared.buy")) :
Res.get("offerDetailsWindow.confirm.makerAltcoin", Res.get("shared.buy"),
tradeCurrencyByCode) :
CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ?
offer.isFiatOffer() ?
Res.get("offerDetailsWindow.confirm.maker", Res.get("shared.sell")) :
Res.get("offerDetailsWindow.confirm.makerAltcoin", Res.get("shared.sell"),
tradeCurrencyByCode);
String takeOfferButtonText = isBuyerRole ?
CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ?
offer.isFiatOffer() ?
Res.get("offerDetailsWindow.confirm.taker", Res.get("shared.buy")) :
Res.get("offerDetailsWindow.confirm.takerAltcoin", Res.get("shared.buy"),
tradeCurrencyByCode) :
CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ?
offer.isFiatOffer() ?
Res.get("offerDetailsWindow.confirm.taker", Res.get("shared.sell")) :
Res.get("offerDetailsWindow.confirm.takerAltcoin", Res.get("shared.sell"),
tradeCurrencyByCode);

View file

@ -27,7 +27,6 @@ import bisq.desktop.util.Layout;
import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.Res;
import bisq.core.offer.Offer;
import bisq.core.payment.payload.PaymentAccountPayload;
@ -340,7 +339,7 @@ public class TradeDetailsWindow extends Overlay<TradeDetailsWindow> {
data += "\n\nOther detail data:";
data += "\n\nBuyerMultiSigPubKeyHex: " + Utils.HEX.encode(contract.getBuyerMultiSigPubKey());
data += "\nSellerMultiSigPubKeyHex: " + Utils.HEX.encode(contract.getSellerMultiSigPubKey());
if (CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())) {
if (offer.isFiatOffer()) {
data += "\n\nBuyersAccountAge: " + buyersAccountAge;
data += "\nSellersAccountAge: " + sellersAccountAge;
}