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); Volume volumeByAmount = price.getVolumeByAmount(amount);
if (offerPayloadBase.getPaymentMethodId().equals(PaymentMethod.HAL_CASH_ID)) if (offerPayloadBase.getPaymentMethodId().equals(PaymentMethod.HAL_CASH_ID))
volumeByAmount = VolumeUtil.getAdjustedVolumeForHalCash(volumeByAmount); volumeByAmount = VolumeUtil.getAdjustedVolumeForHalCash(volumeByAmount);
else if (CurrencyUtil.isFiatCurrency(offerPayloadBase.getCurrencyCode())) else if (isFiatOffer())
volumeByAmount = VolumeUtil.getRoundedFiatVolume(volumeByAmount); volumeByAmount = VolumeUtil.getRoundedFiatVolume(volumeByAmount);
return volumeByAmount; return volumeByAmount;

View file

@ -19,7 +19,6 @@ package bisq.core.offer;
import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.filter.FilterManager; import bisq.core.filter.FilterManager;
import bisq.core.locale.CurrencyUtil;
import bisq.core.payment.PaymentAccount; import bisq.core.payment.PaymentAccount;
import bisq.core.payment.PaymentAccountUtil; import bisq.core.payment.PaymentAccountUtil;
import bisq.core.user.Preferences; import bisq.core.user.Preferences;
@ -178,7 +177,7 @@ public class OfferFilterService {
return insufficientCounterpartyTradeLimitCache.get(offerId); return insufficientCounterpartyTradeLimitCache.get(offerId);
} }
boolean result = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) && boolean result = offer.isFiatOffer() &&
!accountAgeWitnessService.verifyPeersTradeAmount(offer, offer.getAmount(), !accountAgeWitnessService.verifyPeersTradeAmount(offer, offer.getAmount(),
errorMessage -> { errorMessage -> {
}); });
@ -205,7 +204,7 @@ public class OfferFilterService {
accountOptional.isPresent() ? accountOptional.get().getAccountName() : "null", accountOptional.isPresent() ? accountOptional.get().getAccountName() : "null",
Coin.valueOf(myTradeLimit).toFriendlyString(), Coin.valueOf(myTradeLimit).toFriendlyString(),
Coin.valueOf(offerMinAmount).toFriendlyString()); Coin.valueOf(offerMinAmount).toFriendlyString());
boolean result = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) && boolean result = offer.isFiatOffer() &&
accountOptional.isPresent() && accountOptional.isPresent() &&
myTradeLimit < offerMinAmount; myTradeLimit < offerMinAmount;
myInsufficientTradeLimitCache.put(offerId, result); 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.account.witness.AccountAgeWitnessService;
import bisq.core.btc.model.AddressEntry; import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.locale.CurrencyUtil;
import bisq.core.monetary.Price; import bisq.core.monetary.Price;
import bisq.core.monetary.Volume; import bisq.core.monetary.Volume;
import bisq.core.offer.Offer; import bisq.core.offer.Offer;
@ -196,7 +195,7 @@ public class TakeOfferModel implements Model {
if (offer.getPaymentMethod().getId().equals(PaymentMethod.HAL_CASH_ID)) if (offer.getPaymentMethod().getId().equals(PaymentMethod.HAL_CASH_ID))
volumeByAmount = getAdjustedVolumeForHalCash(volumeByAmount); volumeByAmount = getAdjustedVolumeForHalCash(volumeByAmount);
else if (CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())) else if (offer.isFiatOffer())
volumeByAmount = getRoundedFiatVolume(volumeByAmount); volumeByAmount = getRoundedFiatVolume(volumeByAmount);
volume = volumeByAmount; volume = volumeByAmount;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -450,7 +450,7 @@ abstract class OfferBookViewModel extends ActivatableViewModel {
} }
int getNumberOfDecimalsForVolume(OfferBookListItem item) { 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) { String getPaymentMethod(OfferBookListItem item) {

View file

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

View file

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