add gold and silver, refactor money types to traditional and crypto

This commit is contained in:
woodser 2023-05-15 17:10:01 -04:00
parent 65bc78d3d7
commit 29706339ef
210 changed files with 2629 additions and 2373 deletions

View file

@ -210,16 +210,16 @@ public class AccountAgeWitnessService {
}
private void onBootStrapped() {
republishAllFiatAccounts();
republishAllTraditionalAccounts();
signAndPublishSameNameAccounts();
}
// At startup we re-publish the witness data of all fiat accounts to ensure we got our data well distributed.
private void republishAllFiatAccounts() {
// At startup we re-publish the witness data of all traditional accounts to ensure we got our data well distributed.
private void republishAllTraditionalAccounts() {
if (user.getPaymentAccounts() != null)
user.getPaymentAccounts().stream()
.filter(account -> account.getPaymentMethod().isFiat())
.filter(account -> account.getPaymentMethod().isTraditional())
.forEach(account -> {
AccountAgeWitness myWitness = getMyWitness(account.getPaymentAccountPayload());
// We only publish if the date of our witness is inside the date tolerance.

View file

@ -19,8 +19,10 @@ package haveno.core.api;
import haveno.common.crypto.KeyRing;
import haveno.common.handlers.ErrorMessageHandler;
import haveno.core.monetary.Altcoin;
import haveno.core.locale.CurrencyUtil;
import haveno.core.monetary.CryptoMoney;
import haveno.core.monetary.Price;
import haveno.core.monetary.TraditionalMoney;
import haveno.core.offer.CreateOfferService;
import haveno.core.offer.Offer;
import haveno.core.offer.OfferBookService;
@ -35,7 +37,6 @@ import haveno.core.user.User;
import haveno.core.util.PriceUtil;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.utils.Fiat;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -53,7 +54,6 @@ import java.util.stream.Collectors;
import static haveno.common.util.MathUtils.exactMultiply;
import static haveno.common.util.MathUtils.roundDoubleToLong;
import static haveno.common.util.MathUtils.scaleUpByPowerOf10;
import static haveno.core.locale.CurrencyUtil.isCryptoCurrency;
import static haveno.core.offer.OfferDirection.BUY;
import static haveno.core.payment.PaymentAccountUtil.isPaymentAccountValidForOffer;
import static java.lang.String.format;
@ -285,7 +285,7 @@ public class CoreOffersService {
if ("".equals(direction)) direction = null;
if ("".equals(currencyCode)) currencyCode = null;
var offerOfWantedDirection = direction == null || offer.getDirection().name().equalsIgnoreCase(direction);
var counterAssetCode = isCryptoCurrency(currencyCode) ? offer.getOfferPayload().getBaseCurrencyCode() : offer.getOfferPayload().getCounterCurrencyCode(); // TODO: crypto pairs invert base and counter currencies
var counterAssetCode = CurrencyUtil.isCryptoCurrency(currencyCode) ? offer.getOfferPayload().getBaseCurrencyCode() : offer.getOfferPayload().getCounterCurrencyCode();
var offerInWantedCurrency = currencyCode == null || counterAssetCode.equalsIgnoreCase(currencyCode);
return offerOfWantedDirection && offerInWantedCurrency;
}
@ -299,7 +299,7 @@ public class CoreOffersService {
}
private long priceStringToLong(String priceAsString, String currencyCode) {
int precision = isCryptoCurrency(currencyCode) ? Altcoin.SMALLEST_UNIT_EXPONENT : Fiat.SMALLEST_UNIT_EXPONENT;
int precision = CurrencyUtil.isTraditionalCurrency(currencyCode) ? TraditionalMoney.SMALLEST_UNIT_EXPONENT : CryptoMoney.SMALLEST_UNIT_EXPONENT;
double priceAsDouble = new BigDecimal(priceAsString).doubleValue();
double scaled = scaleUpByPowerOf10(priceAsDouble, precision);
return roundDoubleToLong(scaled);

View file

@ -153,7 +153,7 @@ class CorePaymentAccountsService {
List<PaymentMethod> getCryptoCurrencyPaymentMethods() {
return PaymentMethod.getPaymentMethods().stream()
.filter(PaymentMethod::isAltcoin)
.filter(PaymentMethod::isCrypto)
.sorted(Comparator.comparing(PaymentMethod::getId))
.collect(Collectors.toList());
}

View file

@ -53,7 +53,7 @@ class CorePriceService {
}
/**
* @return Price per 1 XMR in the given currency (fiat or crypto)
* @return Price per 1 XMR in the given currency (traditional or crypto)
*/
public double getMarketPrice(String currencyCode) throws ExecutionException, InterruptedException, TimeoutException, IllegalArgumentException {
var marketPrice = priceFeedService.requestAllPrices().get(currencyCode);
@ -64,7 +64,7 @@ class CorePriceService {
}
/**
* @return Price per 1 XMR in all supported currencies (fiat & crypto)
* @return Price per 1 XMR in all supported currencies (traditional & crypto)
*/
public List<MarketPriceInfo> getMarketPrices() throws ExecutionException, InterruptedException, TimeoutException {
return priceFeedService.requestAllPrices().values().stream()
@ -84,8 +84,8 @@ class CorePriceService {
// Offer price can be null (if price feed unavailable), thus a null-tolerant comparator is used.
Comparator<Offer> offerPriceComparator = Comparator.comparing(Offer::getPrice, Comparator.nullsLast(Comparator.naturalOrder()));
// Trading btc-fiat is considered as buying/selling BTC, but trading btc-altcoin is
// considered as buying/selling Altcoin. Because of this, when viewing a btc-altcoin pair,
// Trading xmr-traditional is considered as buying/selling XMR, but trading xmr-crypto is
// considered as buying/selling crypto. Because of this, when viewing a xmr-crypto pair,
// the buy column is actually the sell column and vice versa. To maintain the expected
// ordering, we have to reverse the price comparator.
boolean isCrypto = CurrencyUtil.isCryptoCurrency(currencyCode);
@ -141,14 +141,14 @@ class CorePriceService {
}
/**
* PriceProvider returns different values for crypto and fiat,
* PriceProvider returns different values for crypto and traditional,
* e.g. 1 XMR = X USD
* but 1 DOGE = X XMR
* Here we convert all to:
* 1 XMR = X (FIAT or CRYPTO)
*/
private double mapPriceFeedServicePrice(double price, String currencyCode) {
if (CurrencyUtil.isFiatCurrency(currencyCode)) {
if (CurrencyUtil.isTraditionalCurrency(currencyCode)) {
return price;
}
return price == 0 ? 0 : 1 / price;

View file

@ -62,8 +62,8 @@ public class OfferInfo implements Payload {
private final String paymentAccountId;
private final String paymentMethodId;
private final String paymentMethodShortName;
// For fiat offer the baseCurrencyCode is BTC and the counterCurrencyCode is the fiat currency
// For altcoin offers it is the opposite. baseCurrencyCode is the altcoin and the counterCurrencyCode is BTC.
// For traditional offer the baseCurrencyCode is XMR and the counterCurrencyCode is the traditional currency
// For crypto offers it is the opposite. baseCurrencyCode is the crypto and the counterCurrencyCode is XMR.
private final String baseCurrencyCode;
private final String counterCurrencyCode;
private final long date;

View file

@ -17,18 +17,19 @@
package haveno.core.locale;
import haveno.core.monetary.TraditionalMoney;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode
public class CurrencyTuple {
public final String code;
public final String name;
public final int precision; // precision 4 is 1/10000 -> 0.0001 is smallest unit
public final int precision; // precision 8 is 1/100000000 -> 0.00000001 is smallest unit
public CurrencyTuple(String code, String name) {
// We use Fiat class and the precision is 4
// We use TraditionalCurrency class and the precision is 8
// In future we might add custom precision per currency
this(code, name, 4);
this(code, name, TraditionalMoney.SMALLEST_UNIT_EXPONENT);
}
public CurrencyTuple(String code, String name, int precision) {

View file

@ -56,16 +56,16 @@ public class CurrencyUtil {
private static String baseCurrencyCode = "XMR";
// Calls to isFiatCurrency and isCryptoCurrency are very frequent so we use a cache of the results.
// Calls to isTraditionalCurrency and isCryptoCurrency are very frequent so we use a cache of the results.
// The main improvement was already achieved with using memoize for the source maps, but
// the caching still reduces performance costs by about 20% for isCryptoCurrency (1752 ms vs 2121 ms) and about 50%
// for isFiatCurrency calls (1777 ms vs 3467 ms).
// for isTraditionalCurrency calls (1777 ms vs 3467 ms).
// See: https://github.com/bisq-network/bisq/pull/4955#issuecomment-745302802
private static final Map<String, Boolean> isFiatCurrencyMap = new ConcurrentHashMap<>();
private static final Map<String, Boolean> isTraditionalCurrencyMap = new ConcurrentHashMap<>();
private static final Map<String, Boolean> isCryptoCurrencyMap = new ConcurrentHashMap<>();
private static final Supplier<Map<String, FiatCurrency>> fiatCurrencyMapSupplier = Suppliers.memoize(
CurrencyUtil::createFiatCurrencyMap);
private static final Supplier<Map<String, TraditionalCurrency>> traditionalCurrencyMapSupplier = Suppliers.memoize(
CurrencyUtil::createTraditionalCurrencyMap);
private static final Supplier<Map<String, CryptoCurrency>> cryptoCurrencyMapSupplier = Suppliers.memoize(
CurrencyUtil::createCryptoCurrencyMap);
@ -73,48 +73,52 @@ public class CurrencyUtil {
CurrencyUtil.baseCurrencyCode = baseCurrencyCode;
}
public static Collection<FiatCurrency> getAllSortedFiatCurrencies() {
return fiatCurrencyMapSupplier.get().values(); // sorted by currency name
public static Collection<TraditionalCurrency> getAllSortedTraditionalCurrencies() {
return traditionalCurrencyMapSupplier.get().values(); // sorted by currency name
}
public static List<TradeCurrency> getAllFiatCurrencies() {
return new ArrayList<>(fiatCurrencyMapSupplier.get().values());
public static List<TradeCurrency> getAllTraditionalCurrencies() {
return new ArrayList<>(traditionalCurrencyMapSupplier.get().values());
}
public static Collection<FiatCurrency> getAllSortedFiatCurrencies(Comparator comparator) {
return (List<FiatCurrency>) getAllSortedFiatCurrencies().stream()
public static Collection<TraditionalCurrency> getAllSortedTraditionalCurrencies(Comparator comparator) {
return (List<TraditionalCurrency>) getAllSortedTraditionalCurrencies().stream()
.sorted(comparator) // sorted by comparator param
.collect(Collectors.toList());
}
private static Map<String, FiatCurrency> createFiatCurrencyMap() {
return CountryUtil.getAllCountries().stream()
private static Map<String, TraditionalCurrency> createTraditionalCurrencyMap() {
List<TraditionalCurrency> currencies = CountryUtil.getAllCountries().stream()
.map(country -> getCurrencyByCountryCode(country.code))
.sorted(TradeCurrency::compareTo)
.collect(Collectors.toList());
currencies.add(new TraditionalCurrency(Currency.getInstance("XAG"))); // add silver
currencies.add(new TraditionalCurrency(Currency.getInstance("XAU"))); // add gold
return currencies.stream().sorted(TradeCurrency::compareTo)
.distinct()
.collect(Collectors.toMap(TradeCurrency::getCode, Function.identity(), (x, y) -> x, LinkedHashMap::new));
}
public static List<FiatCurrency> getMainFiatCurrencies() {
public static List<TraditionalCurrency> getMainTraditionalCurrencies() {
TradeCurrency defaultTradeCurrency = getDefaultTradeCurrency();
List<FiatCurrency> list = new ArrayList<>();
// Top traded currencies
list.add(new FiatCurrency("USD"));
list.add(new FiatCurrency("EUR"));
list.add(new FiatCurrency("GBP"));
list.add(new FiatCurrency("CAD"));
list.add(new FiatCurrency("AUD"));
list.add(new FiatCurrency("RUB"));
list.add(new FiatCurrency("INR"));
list.add(new FiatCurrency("NGN"));
List<TraditionalCurrency> list = new ArrayList<>();
list.add(new TraditionalCurrency("USD"));
list.add(new TraditionalCurrency("EUR"));
list.add(new TraditionalCurrency("GBP"));
list.add(new TraditionalCurrency("CAD"));
list.add(new TraditionalCurrency("AUD"));
list.add(new TraditionalCurrency("RUB"));
list.add(new TraditionalCurrency("INR"));
list.add(new TraditionalCurrency("NGN"));
list.add(new TraditionalCurrency("XAG"));
list.add(new TraditionalCurrency("XAU"));
list.sort(TradeCurrency::compareTo);
FiatCurrency defaultFiatCurrency =
defaultTradeCurrency instanceof FiatCurrency ? (FiatCurrency) defaultTradeCurrency : null;
if (defaultFiatCurrency != null && list.contains(defaultFiatCurrency)) {
TraditionalCurrency defaultTraditionalCurrency =
defaultTradeCurrency instanceof TraditionalCurrency ? (TraditionalCurrency) defaultTradeCurrency : null;
if (defaultTraditionalCurrency != null && list.contains(defaultTraditionalCurrency)) {
list.remove(defaultTradeCurrency);
list.add(0, defaultFiatCurrency);
list.add(0, defaultTraditionalCurrency);
}
return list;
}
@ -165,53 +169,59 @@ public class CurrencyUtil {
public static List<TradeCurrency> getMatureMarketCurrencies() {
ArrayList<TradeCurrency> currencies = new ArrayList<>(Arrays.asList(
new FiatCurrency("EUR"),
new FiatCurrency("USD"),
new FiatCurrency("GBP"),
new FiatCurrency("CAD"),
new FiatCurrency("AUD"),
new FiatCurrency("BRL")
new TraditionalCurrency("EUR"),
new TraditionalCurrency("USD"),
new TraditionalCurrency("GBP"),
new TraditionalCurrency("CAD"),
new TraditionalCurrency("AUD"),
new TraditionalCurrency("BRL")
));
currencies.sort(Comparator.comparing(TradeCurrency::getCode));
return currencies;
}
public static boolean isFiatCurrency(String currencyCode) {
if (currencyCode != null && isFiatCurrencyMap.containsKey(currencyCode)) {
return isFiatCurrencyMap.get(currencyCode);
if (!isTraditionalCurrency(currencyCode)) return false;
if ("xag".equalsIgnoreCase(currencyCode) || "xau".equalsIgnoreCase(currencyCode)) return false;
return true;
}
public static boolean isTraditionalCurrency(String currencyCode) {
if (currencyCode != null && isTraditionalCurrencyMap.containsKey(currencyCode)) {
return isTraditionalCurrencyMap.get(currencyCode);
}
try {
boolean isFiatCurrency = currencyCode != null
boolean isTraditionalCurrency = currencyCode != null
&& !currencyCode.isEmpty()
&& !isCryptoCurrency(currencyCode)
&& Currency.getInstance(currencyCode) != null;
if (currencyCode != null) {
isFiatCurrencyMap.put(currencyCode, isFiatCurrency);
isTraditionalCurrencyMap.put(currencyCode, isTraditionalCurrency);
}
return isFiatCurrency;
return isTraditionalCurrency;
} catch (Throwable t) {
isFiatCurrencyMap.put(currencyCode, false);
isTraditionalCurrencyMap.put(currencyCode, false);
return false;
}
}
public static Optional<FiatCurrency> getFiatCurrency(String currencyCode) {
return Optional.ofNullable(fiatCurrencyMapSupplier.get().get(currencyCode));
public static Optional<TraditionalCurrency> getTraditionalCurrency(String currencyCode) {
return Optional.ofNullable(traditionalCurrencyMapSupplier.get().get(currencyCode));
}
/**
* We return true if it is BTC or any of our currencies available in the assetRegistry.
* For removed assets it would fail as they are not found but we don't want to conclude that they are fiat then.
* As the caller might not deal with the case that a currency can be neither a cryptoCurrency nor Fiat if not found
* we return true as well in case we have no fiat currency for the code.
* For removed assets it would fail as they are not found but we don't want to conclude that they are traditional then.
* As the caller might not deal with the case that a currency can be neither a cryptoCurrency nor Traditional if not found
* we return true as well in case we have no traditional currency for the code.
*
* As we use a boolean result for isCryptoCurrency and isFiatCurrency we do not treat missing currencies correctly.
* As we use a boolean result for isCryptoCurrency and isTraditionalCurrency we do not treat missing currencies correctly.
* To throw an exception might be an option but that will require quite a lot of code change, so we don't do that
* for the moment, but could be considered for the future. Another maybe better option is to introduce an enum which
* contains 3 entries (CryptoCurrency, Fiat, Undefined).
* contains 3 entries (CryptoCurrency, Traditional, Undefined).
*/
public static boolean isCryptoCurrency(String currencyCode) {
if (currencyCode != null) currencyCode = currencyCode.toUpperCase();
@ -230,14 +240,14 @@ public class CurrencyUtil {
} else if (getCryptoCurrency(currencyCode).isPresent()) {
// If we find the code in our assetRegistry we return true.
// It might be that an asset was removed from the assetsRegistry, we deal with such cases below by checking if
// it is a fiat currency
// it is a traditional currency
isCryptoCurrency = true;
} else if (getFiatCurrency(currencyCode).isEmpty()) {
// In case the code is from a removed asset we cross check if there exist a fiat currency with that code,
// if we don't find a fiat currency we treat it as a crypto currency.
} else if (getTraditionalCurrency(currencyCode).isEmpty()) {
// In case the code is from a removed asset we cross check if there exist a traditional currency with that code,
// if we don't find a traditional currency we treat it as a crypto currency.
isCryptoCurrency = true;
} else {
// If we would have found a fiat currency we return false
// If we would have found a traditional currency we return false
isCryptoCurrency = false;
}
@ -253,9 +263,9 @@ public class CurrencyUtil {
}
public static Optional<TradeCurrency> getTradeCurrency(String currencyCode) {
Optional<FiatCurrency> fiatCurrencyOptional = getFiatCurrency(currencyCode);
if (fiatCurrencyOptional.isPresent() && isFiatCurrency(currencyCode))
return Optional.of(fiatCurrencyOptional.get());
Optional<TraditionalCurrency> traditionalCurrencyOptional = getTraditionalCurrency(currencyCode);
if (traditionalCurrencyOptional.isPresent() && isTraditionalCurrency(currencyCode))
return Optional.of(traditionalCurrencyOptional.get());
Optional<CryptoCurrency> cryptoCurrencyOptional = getCryptoCurrency(currencyCode);
if (cryptoCurrencyOptional.isPresent() && isCryptoCurrency(currencyCode))
@ -290,12 +300,12 @@ public class CurrencyUtil {
return tradeCurrencies;
}
public static FiatCurrency getCurrencyByCountryCode(String countryCode) {
public static TraditionalCurrency getCurrencyByCountryCode(String countryCode) {
if (countryCode.equals("XK"))
return new FiatCurrency("EUR");
return new TraditionalCurrency("EUR");
Currency currency = Currency.getInstance(new Locale(LanguageUtil.getDefaultLanguage(), countryCode));
return new FiatCurrency(currency.getCurrencyCode());
return new TraditionalCurrency(currency.getCurrencyCode());
}
@ -412,14 +422,14 @@ public class CurrencyUtil {
}
public static String getCurrencyPair(String currencyCode) {
if (isFiatCurrency(currencyCode))
if (isTraditionalCurrency(currencyCode))
return Res.getBaseCurrencyCode() + "/" + currencyCode;
else
return currencyCode + "/" + Res.getBaseCurrencyCode();
}
public static String getCounterCurrency(String currencyCode) {
if (isFiatCurrency(currencyCode))
if (isTraditionalCurrency(currencyCode))
return currencyCode;
else
return Res.getBaseCurrencyCode();
@ -453,6 +463,6 @@ public class CurrencyUtil {
}
public static List<TradeCurrency> getAllTransferwiseUSDCurrencies() {
return List.of(new FiatCurrency("USD"));
return List.of(new TraditionalCurrency("USD"));
}
}

View file

@ -50,8 +50,8 @@ public class GlobalSettings {
GlobalSettings.useAnimations = useAnimations;
}
public static void setDefaultTradeCurrency(TradeCurrency fiatCurrency) {
GlobalSettings.defaultTradeCurrency = fiatCurrency;
public static void setDefaultTradeCurrency(TradeCurrency tradeCurrency) {
GlobalSettings.defaultTradeCurrency = tradeCurrency;
}

View file

@ -45,8 +45,8 @@ public abstract class TradeCurrency implements PersistablePayload, Comparable<Tr
public static TradeCurrency fromProto(protobuf.TradeCurrency proto) {
switch (proto.getMessageCase()) {
case FIAT_CURRENCY:
return FiatCurrency.fromProto(proto);
case TRADITIONAL_CURRENCY:
return TraditionalCurrency.fromProto(proto);
case CRYPTO_CURRENCY:
return CryptoCurrency.fromProto(proto);
default:

View file

@ -29,23 +29,23 @@ import java.util.Locale;
@EqualsAndHashCode(callSuper = true)
@ToString
@Getter
public final class FiatCurrency extends TradeCurrency {
public final class TraditionalCurrency extends TradeCurrency {
// http://boschista.deviantart.com/journal/Cool-ASCII-Symbols-214218618
private final static String PREFIX = "";
private final Currency currency;
public FiatCurrency(String currencyCode) {
public TraditionalCurrency(String currencyCode) {
this(Currency.getInstance(currencyCode), getLocale());
}
@SuppressWarnings("WeakerAccess")
public FiatCurrency(Currency currency) {
public TraditionalCurrency(Currency currency) {
this(currency, getLocale());
}
@SuppressWarnings("WeakerAccess")
public FiatCurrency(Currency currency, Locale locale) {
public TraditionalCurrency(Currency currency, Locale locale) {
super(currency.getCurrencyCode(), currency.getDisplayName(locale));
this.currency = currency;
}
@ -58,14 +58,14 @@ public final class FiatCurrency extends TradeCurrency {
@Override
public Message toProtoMessage() {
protobuf.Currency.Builder currencyBuilder = protobuf.Currency.newBuilder().setCurrencyCode(currency.getCurrencyCode());
protobuf.FiatCurrency.Builder fiatCurrencyBuilder = protobuf.FiatCurrency.newBuilder().setCurrency(currencyBuilder);
protobuf.TraditionalCurrency.Builder traditionalCurrencyBuilder = protobuf.TraditionalCurrency.newBuilder().setCurrency(currencyBuilder);
return getTradeCurrencyBuilder()
.setFiatCurrency(fiatCurrencyBuilder)
.setTraditionalCurrency(traditionalCurrencyBuilder)
.build();
}
public static FiatCurrency fromProto(protobuf.TradeCurrency proto) {
return new FiatCurrency(proto.getCode());
public static TraditionalCurrency fromProto(protobuf.TradeCurrency proto) {
return new TraditionalCurrency(proto.getCode());
}

View file

@ -24,61 +24,61 @@ import java.math.BigInteger;
import static com.google.common.base.Preconditions.checkArgument;
// Cloned from ExchangeRate. Use Altcoin instead of Fiat.
// Cloned from ExchangeRate. Use Crypto instead of Fiat.
@Slf4j
public class AltcoinExchangeRate {
public class CryptoExchangeRate {
/**
* An exchange rate is expressed as a ratio of a {@link Coin} and a {@link Altcoin} amount.
* An exchange rate is expressed as a ratio of a {@link Coin} and a {@link CryptoMoney} amount.
*/
public final Coin coin;
public final Altcoin altcoin;
public final CryptoMoney crypto;
/**
* Construct exchange rate. This amount of coin is worth that amount of altcoin.
* Construct exchange rate. This amount of coin is worth that amount of crypto.
*/
@SuppressWarnings("SameParameterValue")
public AltcoinExchangeRate(Coin coin, Altcoin altcoin) {
public CryptoExchangeRate(Coin coin, CryptoMoney crypto) {
checkArgument(coin.isPositive());
checkArgument(altcoin.isPositive());
checkArgument(altcoin.currencyCode != null, "currency code required");
checkArgument(crypto.isPositive());
checkArgument(crypto.currencyCode != null, "currency code required");
this.coin = coin;
this.altcoin = altcoin;
this.crypto = crypto;
}
/**
* Construct exchange rate. One coin is worth this amount of altcoin.
* Construct exchange rate. One coin is worth this amount of crypto.
*/
public AltcoinExchangeRate(Altcoin altcoin) {
this(Coin.COIN, altcoin);
public CryptoExchangeRate(CryptoMoney crypto) {
this(Coin.COIN, crypto);
}
/**
* Convert a coin amount to an altcoin amount using this exchange rate.
* Convert a coin amount to an crypto amount using this exchange rate.
*
* @throws ArithmeticException if the converted altcoin amount is too high or too low.
* @throws ArithmeticException if the converted crypto amount is too high or too low.
*/
public Altcoin coinToAltcoin(Coin convertCoin) {
public CryptoMoney coinToCrypto(Coin convertCoin) {
BigInteger converted = BigInteger.valueOf(coin.value)
.multiply(BigInteger.valueOf(convertCoin.value))
.divide(BigInteger.valueOf(altcoin.value));
.divide(BigInteger.valueOf(crypto.value));
if (converted.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0
|| converted.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0)
throw new ArithmeticException("Overflow");
return Altcoin.valueOf(altcoin.currencyCode, converted.longValue());
return CryptoMoney.valueOf(crypto.currencyCode, converted.longValue());
}
/**
* Convert a altcoin amount to a coin amount using this exchange rate.
* Convert a crypto amount to a coin amount using this exchange rate.
*
* @throws ArithmeticException if the converted coin amount is too high or too low.
*/
public Coin altcoinToCoin(Altcoin convertAltcoin) {
checkArgument(convertAltcoin.currencyCode.equals(altcoin.currencyCode), "Currency mismatch: %s vs %s",
convertAltcoin.currencyCode, altcoin.currencyCode);
public Coin cryptoToCoin(CryptoMoney convertCrypto) {
checkArgument(convertCrypto.currencyCode.equals(crypto.currencyCode), "Currency mismatch: %s vs %s",
convertCrypto.currencyCode, crypto.currencyCode);
// Use BigInteger because it's much easier to maintain full precision without overflowing.
BigInteger converted = BigInteger.valueOf(altcoin.value)
.multiply(BigInteger.valueOf(convertAltcoin.value))
BigInteger converted = BigInteger.valueOf(crypto.value)
.multiply(BigInteger.valueOf(convertCrypto.value))
.divide(BigInteger.valueOf(coin.value));
if (converted.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0
|| converted.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0)

View file

@ -30,12 +30,12 @@ import static com.google.common.base.Preconditions.checkArgument;
/**
* Cloned from Fiat class and altered SMALLEST_UNIT_EXPONENT as Fiat is final.
* <p/>
* Represents a monetary fiat value. It was decided to not fold this into {@link org.bitcoinj.core.Coin} because of type
* Represents a monetary crypto value. It was decided to not fold this into {@link org.bitcoinj.core.Coin} because of type
* safety. Volume values always come with an attached currency code.
* <p/>
* This class is immutable.
*/
public final class Altcoin implements Monetary, Comparable<Altcoin> {
public final class CryptoMoney implements Monetary, Comparable<CryptoMoney> {
/**
* The absolute value of exponent of the value of a "smallest unit" in scientific notation. We picked 4 rather than
* 2, because in financial applications it's common to use sub-cent precision.
@ -50,13 +50,13 @@ public final class Altcoin implements Monetary, Comparable<Altcoin> {
public final long value;
public final String currencyCode;
private Altcoin(final String currencyCode, final long value) {
private CryptoMoney(final String currencyCode, final long value) {
this.value = value;
this.currencyCode = currencyCode;
}
public static Altcoin valueOf(final String currencyCode, final long value) {
return new Altcoin(currencyCode, value);
public static CryptoMoney valueOf(final String currencyCode, final long value) {
return new CryptoMoney(currencyCode, value);
}
@Override
@ -85,40 +85,40 @@ public final class Altcoin implements Monetary, Comparable<Altcoin> {
*
* @throws IllegalArgumentException if you try to specify fractional satoshis, or a value out of range.
*/
public static Altcoin parseAltcoin(final String currencyCode, String input) {
public static CryptoMoney parseCrypto(final String currencyCode, String input) {
String cleaned = ParsingUtils.convertCharsForNumber(input);
try {
long val = new BigDecimal(cleaned).movePointRight(SMALLEST_UNIT_EXPONENT)
.toBigIntegerExact().longValue();
return Altcoin.valueOf(currencyCode, val);
return CryptoMoney.valueOf(currencyCode, val);
} catch (ArithmeticException e) {
throw new IllegalArgumentException(e);
}
}
public Altcoin add(final Altcoin value) {
public CryptoMoney add(final CryptoMoney value) {
checkArgument(value.currencyCode.equals(currencyCode));
return new Altcoin(currencyCode, LongMath.checkedAdd(this.value, value.value));
return new CryptoMoney(currencyCode, LongMath.checkedAdd(this.value, value.value));
}
public Altcoin subtract(final Altcoin value) {
public CryptoMoney subtract(final CryptoMoney value) {
checkArgument(value.currencyCode.equals(currencyCode));
return new Altcoin(currencyCode, LongMath.checkedSubtract(this.value, value.value));
return new CryptoMoney(currencyCode, LongMath.checkedSubtract(this.value, value.value));
}
public Altcoin multiply(final long factor) {
return new Altcoin(currencyCode, LongMath.checkedMultiply(this.value, factor));
public CryptoMoney multiply(final long factor) {
return new CryptoMoney(currencyCode, LongMath.checkedMultiply(this.value, factor));
}
public Altcoin divide(final long divisor) {
return new Altcoin(currencyCode, this.value / divisor);
public CryptoMoney divide(final long divisor) {
return new CryptoMoney(currencyCode, this.value / divisor);
}
public Altcoin[] divideAndRemainder(final long divisor) {
return new Altcoin[]{new Altcoin(currencyCode, this.value / divisor), new Altcoin(currencyCode, this.value % divisor)};
public CryptoMoney[] divideAndRemainder(final long divisor) {
return new CryptoMoney[]{new CryptoMoney(currencyCode, this.value / divisor), new CryptoMoney(currencyCode, this.value % divisor)};
}
public long divide(final Altcoin divisor) {
public long divide(final CryptoMoney divisor) {
checkArgument(divisor.currencyCode.equals(currencyCode));
return this.value / divisor.value;
}
@ -148,7 +148,7 @@ public final class Altcoin implements Monetary, Comparable<Altcoin> {
* Returns true if the monetary value represented by this instance is greater than that of the given other Coin,
* otherwise false.
*/
public boolean isGreaterThan(Altcoin other) {
public boolean isGreaterThan(CryptoMoney other) {
return compareTo(other) > 0;
}
@ -156,7 +156,7 @@ public final class Altcoin implements Monetary, Comparable<Altcoin> {
* Returns true if the monetary value represented by this instance is less than that of the given other Coin,
* otherwise false.
*/
public boolean isLessThan(Altcoin other) {
public boolean isLessThan(CryptoMoney other) {
return compareTo(other) < 0;
}
@ -167,8 +167,8 @@ public final class Altcoin implements Monetary, Comparable<Altcoin> {
return this.value < 0 ? -1 : 1;
}
public Altcoin negate() {
return new Altcoin(currencyCode, -this.value);
public CryptoMoney negate() {
return new CryptoMoney(currencyCode, -this.value);
}
public String toFriendlyString() {
@ -196,7 +196,7 @@ public final class Altcoin implements Monetary, Comparable<Altcoin> {
return true;
if (o == null || o.getClass() != getClass())
return false;
final Altcoin other = (Altcoin) o;
final CryptoMoney other = (CryptoMoney) o;
return this.value == other.value && this.currencyCode.equals(other.currencyCode);
}
@ -206,7 +206,7 @@ public final class Altcoin implements Monetary, Comparable<Altcoin> {
}
@Override
public int compareTo(@NotNull final Altcoin other) {
public int compareTo(@NotNull final CryptoMoney other) {
if (!this.currencyCode.equals(other.currencyCode))
return this.currencyCode.compareTo(other.currencyCode);
if (this.value != other.value)

View file

@ -25,10 +25,10 @@ import org.slf4j.LoggerFactory;
public abstract class MonetaryWrapper {
private static final Logger log = LoggerFactory.getLogger(MonetaryWrapper.class);
/// Instance of Fiat or Altcoin
/// Instance of TraditionalMoney or CryptoMoney
protected final Monetary monetary;
protected final MonetaryFormat fiatFormat = MonetaryFormat.FIAT.repeatOptionalDecimals(0, 0);
protected final MonetaryFormat altCoinFormat = MonetaryFormat.FIAT.repeatOptionalDecimals(0, 0);
protected final MonetaryFormat traditionalFormat = MonetaryFormat.FIAT.repeatOptionalDecimals(0, 0);
protected final MonetaryFormat cryptoFormat = MonetaryFormat.FIAT.repeatOptionalDecimals(0, 0);
public MonetaryWrapper(Monetary monetary) {
this.monetary = monetary;

View file

@ -21,8 +21,6 @@ import haveno.core.locale.CurrencyUtil;
import haveno.core.trade.HavenoUtils;
import haveno.core.util.ParsingUtils;
import org.bitcoinj.core.Monetary;
import org.bitcoinj.utils.ExchangeRate;
import org.bitcoinj.utils.Fiat;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -36,7 +34,7 @@ import java.math.BigInteger;
* <br/>
* We wrap an object implementing the {@link Monetary} interface from bitcoinj. We respect the
* number of decimal digits of precision specified in the {@code smallestUnitExponent()}, defined in
* those classes, like {@link Fiat} or {@link Altcoin}.
* those classes, like {@link TraditionalMoney} or {@link CryptoMoney}.
*/
public class Price extends MonetaryWrapper implements Comparable<Price> {
private static final Logger log = LoggerFactory.getLogger(Price.class);
@ -59,10 +57,10 @@ public class Price extends MonetaryWrapper implements Comparable<Price> {
*/
public static Price parse(String currencyCode, String input) {
String cleaned = ParsingUtils.convertCharsForNumber(input);
if (CurrencyUtil.isFiatCurrency(currencyCode))
return new Price(Fiat.parseFiat(currencyCode, cleaned));
if (CurrencyUtil.isTraditionalCurrency(currencyCode))
return new Price(TraditionalMoney.parseTraditionalMoney(currencyCode, cleaned));
else
return new Price(Altcoin.parseAltcoin(currencyCode, cleaned));
return new Price(CryptoMoney.parseCrypto(currencyCode, cleaned));
}
/**
@ -73,34 +71,34 @@ public class Price extends MonetaryWrapper implements Comparable<Price> {
* @return The parsed Price.
*/
public static Price valueOf(String currencyCode, long value) {
if (CurrencyUtil.isFiatCurrency(currencyCode)) {
return new Price(Fiat.valueOf(currencyCode, value));
if (CurrencyUtil.isTraditionalCurrency(currencyCode)) {
return new Price(TraditionalMoney.valueOf(currencyCode, value));
} else {
return new Price(Altcoin.valueOf(currencyCode, value));
return new Price(CryptoMoney.valueOf(currencyCode, value));
}
}
public Volume getVolumeByAmount(BigInteger amount) {
if (monetary instanceof Fiat)
return new Volume(new ExchangeRate((Fiat) monetary).coinToFiat(HavenoUtils.atomicUnitsToCoin(amount)));
else if (monetary instanceof Altcoin)
return new Volume(new AltcoinExchangeRate((Altcoin) monetary).coinToAltcoin(HavenoUtils.atomicUnitsToCoin(amount)));
if (monetary instanceof TraditionalMoney)
return new Volume(new TraditionalExchangeRate((TraditionalMoney) monetary).coinToTraditionalMoney(HavenoUtils.atomicUnitsToCoin(amount)));
else if (monetary instanceof CryptoMoney)
return new Volume(new CryptoExchangeRate((CryptoMoney) monetary).coinToCrypto(HavenoUtils.atomicUnitsToCoin(amount)));
else
throw new IllegalStateException("Monetary must be either of type Fiat or Altcoin");
throw new IllegalStateException("Monetary must be either of type TraditionalMoney or CryptoMoney");
}
public BigInteger getAmountByVolume(Volume volume) {
Monetary monetary = volume.getMonetary();
if (monetary instanceof Fiat && this.monetary instanceof Fiat)
return HavenoUtils.coinToAtomicUnits(new ExchangeRate((Fiat) this.monetary).fiatToCoin((Fiat) monetary));
else if (monetary instanceof Altcoin && this.monetary instanceof Altcoin)
return HavenoUtils.coinToAtomicUnits(new AltcoinExchangeRate((Altcoin) this.monetary).altcoinToCoin((Altcoin) monetary));
if (monetary instanceof TraditionalMoney && this.monetary instanceof TraditionalMoney)
return HavenoUtils.coinToAtomicUnits(new TraditionalExchangeRate((TraditionalMoney) this.monetary).traditionalMoneyToCoin((TraditionalMoney) monetary));
else if (monetary instanceof CryptoMoney && this.monetary instanceof CryptoMoney)
return HavenoUtils.coinToAtomicUnits(new CryptoExchangeRate((CryptoMoney) this.monetary).cryptoToCoin((CryptoMoney) monetary));
else
return BigInteger.valueOf(0);
}
public String getCurrencyCode() {
return monetary instanceof Altcoin ? ((Altcoin) monetary).getCurrencyCode() : ((Fiat) monetary).getCurrencyCode();
return monetary instanceof CryptoMoney ? ((CryptoMoney) monetary).getCurrencyCode() : ((TraditionalMoney) monetary).getCurrencyCode();
}
@Override
@ -109,7 +107,7 @@ public class Price extends MonetaryWrapper implements Comparable<Price> {
}
/**
* Get the amount of whole coins or fiat units as double.
* Get the amount of whole coins or units as double.
*/
public double getDoubleValue() {
return BigDecimal.valueOf(monetary.getValue()).movePointLeft(monetary.smallestUnitExponent()).doubleValue();
@ -125,25 +123,25 @@ public class Price extends MonetaryWrapper implements Comparable<Price> {
}
public boolean isPositive() {
return monetary instanceof Altcoin ? ((Altcoin) monetary).isPositive() : ((Fiat) monetary).isPositive();
return monetary instanceof CryptoMoney ? ((CryptoMoney) monetary).isPositive() : ((TraditionalMoney) monetary).isPositive();
}
public Price subtract(Price other) {
if (monetary instanceof Altcoin) {
return new Price(((Altcoin) monetary).subtract((Altcoin) other.monetary));
if (monetary instanceof CryptoMoney) {
return new Price(((CryptoMoney) monetary).subtract((CryptoMoney) other.monetary));
} else {
return new Price(((Fiat) monetary).subtract((Fiat) other.monetary));
return new Price(((TraditionalMoney) monetary).subtract((TraditionalMoney) other.monetary));
}
}
public String toFriendlyString() {
return monetary instanceof Altcoin ?
((Altcoin) monetary).toFriendlyString() + "/XMR" :
((Fiat) monetary).toFriendlyString().replace(((Fiat) monetary).currencyCode, "") + "XMR/" + ((Fiat) monetary).currencyCode;
return monetary instanceof CryptoMoney ?
((CryptoMoney) monetary).toFriendlyString() + "/XMR" :
((TraditionalMoney) monetary).toFriendlyString().replace(((TraditionalMoney) monetary).currencyCode, "") + "XMR/" + ((TraditionalMoney) monetary).currencyCode;
}
public String toPlainString() {
return monetary instanceof Altcoin ? ((Altcoin) monetary).toPlainString() : ((Fiat) monetary).toPlainString();
return monetary instanceof CryptoMoney ? ((CryptoMoney) monetary).toPlainString() : ((TraditionalMoney) monetary).toPlainString();
}
@Override

View file

@ -0,0 +1,98 @@
/*
* This file is part of Haveno.
*
* Haveno is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Haveno is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Haveno. If not, see <http://www.gnu.org/licenses/>.
*/
package haveno.core.monetary;
import static com.google.common.base.Preconditions.checkArgument;
import java.io.Serializable;
import java.math.BigInteger;
import org.bitcoinj.core.Coin;
import com.google.common.base.Objects;
/**
* An exchange rate is expressed as a ratio of a {@link Coin} and a traditional money amount.
*/
public class TraditionalExchangeRate implements Serializable {
public final Coin coin;
public final TraditionalMoney traditionalMoney;
/** Construct exchange rate. This amount of coin is worth that amount of money. */
public TraditionalExchangeRate(Coin coin, TraditionalMoney traditionalMoney) {
checkArgument(coin.isPositive());
checkArgument(traditionalMoney.isPositive());
checkArgument(traditionalMoney.currencyCode != null, "currency code required");
this.coin = coin;
this.traditionalMoney = traditionalMoney;
}
/** Construct exchange rate. One coin is worth this amount of traditional money. */
public TraditionalExchangeRate(TraditionalMoney traditionalMoney) {
this(Coin.COIN, traditionalMoney);
}
/**
* Convert a coin amount to a traditional money amount using this exchange rate.
* @throws ArithmeticException if the converted amount is too high or too low.
*/
public TraditionalMoney coinToTraditionalMoney(Coin convertCoin) {
// Use BigInteger because it's much easier to maintain full precision without overflowing.
final BigInteger converted = BigInteger.valueOf(convertCoin.value).multiply(BigInteger.valueOf(traditionalMoney.value))
.divide(BigInteger.valueOf(coin.value));
if (converted.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0
|| converted.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0)
throw new ArithmeticException("Overflow");
return TraditionalMoney.valueOf(traditionalMoney.currencyCode, converted.longValue());
}
/**
* Convert a traditional money amount to a coin amount using this exchange rate.
* @throws ArithmeticException if the converted coin amount is too high or too low.
*/
public Coin traditionalMoneyToCoin(TraditionalMoney convertTraditionalMoney) {
checkArgument(convertTraditionalMoney.currencyCode.equals(traditionalMoney.currencyCode), "Currency mismatch: %s vs %s",
convertTraditionalMoney.currencyCode, traditionalMoney.currencyCode);
// Use BigInteger because it's much easier to maintain full precision without overflowing.
final BigInteger converted = BigInteger.valueOf(convertTraditionalMoney.value).multiply(BigInteger.valueOf(coin.value))
.divide(BigInteger.valueOf(traditionalMoney.value));
if (converted.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0
|| converted.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0)
throw new ArithmeticException("Overflow");
try {
return Coin.valueOf(converted.longValue());
} catch (IllegalArgumentException x) {
throw new ArithmeticException("Overflow: " + x.getMessage());
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TraditionalExchangeRate other = (TraditionalExchangeRate) o;
return Objects.equal(this.coin, other.coin) && Objects.equal(this.traditionalMoney, other.traditionalMoney);
}
@Override
public int hashCode() {
return Objects.hashCode(coin, traditionalMoney);
}
}

View file

@ -0,0 +1,243 @@
/*
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package haveno.core.monetary;
import static com.google.common.base.Preconditions.checkArgument;
import java.io.Serializable;
import java.math.BigDecimal;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Monetary;
import org.bitcoinj.utils.MonetaryFormat;
import com.google.common.base.Objects;
import com.google.common.math.LongMath;
import com.google.common.primitives.Longs;
/**
* Represents a monetary value. It was decided to not fold this into
* {@link Coin} because of type
* safety. Traditional money values always come with an attached currency code.
*
* This class is immutable.
*/
public final class TraditionalMoney implements Monetary, Comparable<TraditionalMoney>, Serializable {
/**
* The absolute value of exponent of the value of a "smallest unit" in
* scientific notation. We picked 8 rather than
* 2, because in financial applications it's common to use sub-cent precision.
*/
public static final int SMALLEST_UNIT_EXPONENT = 8;
/**
* The number of smallest units of this monetary value.
*/
public final long value;
public final String currencyCode;
private TraditionalMoney(final String currencyCode, final long value) {
this.value = value;
this.currencyCode = currencyCode;
}
public static TraditionalMoney valueOf(final String currencyCode, final long value) {
return new TraditionalMoney(currencyCode, value);
}
@Override
public int smallestUnitExponent() {
return SMALLEST_UNIT_EXPONENT;
}
/**
* Returns the number of "smallest units" of this monetary value.
*/
@Override
public long getValue() {
return value;
}
public String getCurrencyCode() {
return currencyCode;
}
/**
* <p>Parses an amount expressed in the way humans are used to.</p>
* <p>This takes string in a format understood by {@link BigDecimal#BigDecimal(String)}, for example "0", "1", "0.10",
* "1.23E3", "1234.5E-5".</p>
*
* @throws IllegalArgumentException
* if you try to specify more than 8 digits after the comma, or a value out of range.
*/
public static TraditionalMoney parseTraditionalMoney(final String currencyCode, final String str) {
try {
long val = new BigDecimal(str).movePointRight(SMALLEST_UNIT_EXPONENT).longValueExact();
return TraditionalMoney.valueOf(currencyCode, val);
} catch (ArithmeticException e) {
throw new IllegalArgumentException(e);
}
}
/**
* <p>Parses an amount expressed in the way humans are used to. The amount is cut to 8 digits after the comma.</p>
* <p>This takes string in a format understood by {@link BigDecimal#BigDecimal(String)}, for example "0", "1", "0.10",
* "1.23E3", "1234.5E-5".</p>
*
* @throws IllegalArgumentException
* if you try to specify a value out of range.
*/
public static TraditionalMoney parseTraditionalMoneyInexact(final String currencyCode, final String str) {
try {
long val = new BigDecimal(str).movePointRight(SMALLEST_UNIT_EXPONENT).longValue();
return TraditionalMoney.valueOf(currencyCode, val);
} catch (ArithmeticException e) {
throw new IllegalArgumentException(e);
}
}
public TraditionalMoney add(final TraditionalMoney value) {
checkArgument(value.currencyCode.equals(currencyCode));
return new TraditionalMoney(currencyCode, LongMath.checkedAdd(this.value, value.value));
}
public TraditionalMoney subtract(final TraditionalMoney value) {
checkArgument(value.currencyCode.equals(currencyCode));
return new TraditionalMoney(currencyCode, LongMath.checkedSubtract(this.value, value.value));
}
public TraditionalMoney multiply(final long factor) {
return new TraditionalMoney(currencyCode, LongMath.checkedMultiply(this.value, factor));
}
public TraditionalMoney divide(final long divisor) {
return new TraditionalMoney(currencyCode, this.value / divisor);
}
public TraditionalMoney[] divideAndRemainder(final long divisor) {
return new TraditionalMoney[] { new TraditionalMoney(currencyCode, this.value / divisor), new TraditionalMoney(currencyCode, this.value % divisor) };
}
public long divide(final TraditionalMoney divisor) {
checkArgument(divisor.currencyCode.equals(currencyCode));
return this.value / divisor.value;
}
/**
* Returns true if and only if this instance represents a monetary value greater than zero, otherwise false.
*/
public boolean isPositive() {
return signum() == 1;
}
/**
* Returns true if and only if this instance represents a monetary value less than zero, otherwise false.
*/
public boolean isNegative() {
return signum() == -1;
}
/**
* Returns true if and only if this instance represents zero monetary value, otherwise false.
*/
public boolean isZero() {
return signum() == 0;
}
/**
* Returns true if the monetary value represented by this instance is greater than that of the given other TraditionalMoney,
* otherwise false.
*/
public boolean isGreaterThan(TraditionalMoney other) {
return compareTo(other) > 0;
}
/**
* Returns true if the monetary value represented by this instance is less than that of the given other TraditionalMoney,
* otherwise false.
*/
public boolean isLessThan(TraditionalMoney other) {
return compareTo(other) < 0;
}
@Override
public int signum() {
if (this.value == 0)
return 0;
return this.value < 0 ? -1 : 1;
}
public TraditionalMoney negate() {
return new TraditionalMoney(currencyCode, -this.value);
}
/**
* Returns the number of "smallest units" of this monetary value. It's deprecated in favour of accessing {@link #value}
* directly.
*/
public long longValue() {
return this.value;
}
private static final MonetaryFormat FRIENDLY_FORMAT = MonetaryFormat.FIAT.postfixCode();
/**
* Returns the value as a 0.12 type string. More digits after the decimal place will be used if necessary, but two
* will always be present.
*/
public String toFriendlyString() {
return FRIENDLY_FORMAT.code(0, currencyCode).format(this).toString();
}
private static final MonetaryFormat PLAIN_FORMAT = MonetaryFormat.FIAT.minDecimals(0).repeatOptionalDecimals(1, 8).noCode();
/**
* <p>
* Returns the value as a plain string. The result is unformatted with no trailing zeroes. For
* instance, a value of 150000 "smallest units" gives an output string of "0.0015".
* </p>
*/
public String toPlainString() {
return PLAIN_FORMAT.format(this).toString();
}
@Override
public String toString() {
return Long.toString(value);
}
@Override
public boolean equals(final Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
final TraditionalMoney other = (TraditionalMoney) o;
return this.value == other.value && this.currencyCode.equals(other.currencyCode);
}
@Override
public int hashCode() {
return Objects.hashCode(value, currencyCode);
}
@Override
public int compareTo(final TraditionalMoney other) {
if (!this.currencyCode.equals(other.currencyCode))
return this.currencyCode.compareTo(other.currencyCode);
return Longs.compare(this.value, other.value);
}
}

View file

@ -20,7 +20,6 @@ package haveno.core.monetary;
import haveno.core.locale.CurrencyUtil;
import haveno.core.util.ParsingUtils;
import org.bitcoinj.core.Monetary;
import org.bitcoinj.utils.Fiat;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -34,10 +33,10 @@ public class Volume extends MonetaryWrapper implements Comparable<Volume> {
public static Volume parse(String input, String currencyCode) {
String cleaned = ParsingUtils.convertCharsForNumber(input);
if (CurrencyUtil.isFiatCurrency(currencyCode))
return new Volume(Fiat.parseFiat(currencyCode, cleaned));
if (CurrencyUtil.isTraditionalCurrency(currencyCode))
return new Volume(TraditionalMoney.parseTraditionalMoney(currencyCode, cleaned));
else
return new Volume(Altcoin.parseAltcoin(currencyCode, cleaned));
return new Volume(CryptoMoney.parseCrypto(currencyCode, cleaned));
}
@Override
@ -50,11 +49,11 @@ public class Volume extends MonetaryWrapper implements Comparable<Volume> {
}
public String getCurrencyCode() {
return monetary instanceof Altcoin ? ((Altcoin) monetary).getCurrencyCode() : ((Fiat) monetary).getCurrencyCode();
return monetary instanceof CryptoMoney ? ((CryptoMoney) monetary).getCurrencyCode() : ((TraditionalMoney) monetary).getCurrencyCode();
}
public String toPlainString() {
return monetary instanceof Altcoin ? ((Altcoin) monetary).toPlainString() : ((Fiat) monetary).toPlainString();
return monetary instanceof CryptoMoney ? ((CryptoMoney) monetary).toPlainString() : ((TraditionalMoney) monetary).toPlainString();
}
@Override

View file

@ -21,8 +21,9 @@ import haveno.common.crypto.KeyRing;
import haveno.common.util.MathUtils;
import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.Res;
import haveno.core.monetary.Altcoin;
import haveno.core.monetary.CryptoMoney;
import haveno.core.monetary.Price;
import haveno.core.monetary.TraditionalMoney;
import haveno.core.notifications.MobileMessage;
import haveno.core.notifications.MobileMessageType;
import haveno.core.notifications.MobileNotificationService;
@ -34,7 +35,6 @@ import haveno.core.provider.price.PriceFeedService;
import haveno.core.user.User;
import haveno.core.util.FormattingUtils;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.utils.Fiat;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -103,7 +103,7 @@ public class MarketAlerts {
// We combine the offer ID and the price (either as % price or as fixed price) to get also updates for edited offers
// % price get multiplied by 10000 to have 0.12% be converted to 12. For fixed price we have precision of 8 for
// altcoins and precision of 4 for fiat.
// crypto and traditional.
private String getAlertId(Offer offer) {
double price = offer.isUseMarketBasedPrice() ? offer.getMarketPriceMarginPct() * 10000 : offer.getOfferPayload().getPrice();
String priceString = String.valueOf((long) price);
@ -117,7 +117,7 @@ public class MarketAlerts {
if (marketPrice != null && offerPrice != null) {
boolean isSellOffer = offer.getDirection() == OfferDirection.SELL;
String shortOfferId = offer.getShortId();
boolean isFiatCurrency = CurrencyUtil.isFiatCurrency(currencyCode);
boolean isTraditionalCurrency = CurrencyUtil.isTraditionalCurrency(currencyCode);
String alertId = getAlertId(offer);
user.getMarketAlertFilters().stream()
.filter(marketAlertFilter -> !offer.isMyOffer(keyRing))
@ -127,16 +127,16 @@ public class MarketAlerts {
int triggerValue = marketAlertFilter.getTriggerValue();
boolean isTriggerForBuyOffer = marketAlertFilter.isBuyOffer();
double marketPriceAsDouble1 = marketPrice.getPrice();
int precision = CurrencyUtil.isCryptoCurrency(currencyCode) ?
Altcoin.SMALLEST_UNIT_EXPONENT :
Fiat.SMALLEST_UNIT_EXPONENT;
int precision = CurrencyUtil.isTraditionalCurrency(currencyCode) ?
TraditionalMoney.SMALLEST_UNIT_EXPONENT :
CryptoMoney.SMALLEST_UNIT_EXPONENT;
double marketPriceAsDouble = MathUtils.scaleUpByPowerOf10(marketPriceAsDouble1, precision);
double offerPriceValue = offerPrice.getValue();
double ratio = offerPriceValue / marketPriceAsDouble;
ratio = 1 - ratio;
if (isFiatCurrency && isSellOffer)
if (isTraditionalCurrency && isSellOffer)
ratio *= -1;
else if (!isFiatCurrency && !isSellOffer)
else if (!isTraditionalCurrency && !isSellOffer)
ratio *= -1;
ratio = ratio * 10000;
@ -149,7 +149,7 @@ public class MarketAlerts {
if (isTriggerForBuyOfferAndTriggered || isTriggerForSellOfferAndTriggered) {
String direction = isSellOffer ? Res.get("shared.sell") : Res.get("shared.buy");
String marketDir;
if (isFiatCurrency) {
if (isTraditionalCurrency) {
if (isSellOffer) {
marketDir = ratio > 0 ?
Res.get("account.notifications.marketAlert.message.msg.above") :

View file

@ -20,7 +20,8 @@ package haveno.core.notifications.alerts.price;
import haveno.common.util.MathUtils;
import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.Res;
import haveno.core.monetary.Altcoin;
import haveno.core.monetary.CryptoMoney;
import haveno.core.monetary.TraditionalMoney;
import haveno.core.notifications.MobileMessage;
import haveno.core.notifications.MobileMessageType;
import haveno.core.notifications.MobileNotificationService;
@ -29,7 +30,6 @@ import haveno.core.provider.price.PriceFeedService;
import haveno.core.user.User;
import haveno.core.util.FormattingUtils;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.utils.Fiat;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -58,7 +58,7 @@ public class PriceAlert {
String currencyCode = filter.getCurrencyCode();
MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode);
if (marketPrice != null) {
int exp = CurrencyUtil.isCryptoCurrency(currencyCode) ? Altcoin.SMALLEST_UNIT_EXPONENT : Fiat.SMALLEST_UNIT_EXPONENT;
int exp = CurrencyUtil.isTraditionalCurrency(currencyCode) ? TraditionalMoney.SMALLEST_UNIT_EXPONENT : CryptoMoney.SMALLEST_UNIT_EXPONENT;
double priceAsDouble = marketPrice.getPrice();
long priceAsLong = MathUtils.roundDoubleToLong(MathUtils.scaleUpByPowerOf10(priceAsDouble, exp));
String currencyName = CurrencyUtil.getNameByCode(currencyCode);

View file

@ -28,8 +28,9 @@ import haveno.common.util.MathUtils;
import haveno.common.util.Utilities;
import haveno.core.exceptions.TradePriceOutOfToleranceException;
import haveno.core.locale.CurrencyUtil;
import haveno.core.monetary.Altcoin;
import haveno.core.monetary.CryptoMoney;
import haveno.core.monetary.Price;
import haveno.core.monetary.TraditionalMoney;
import haveno.core.monetary.Volume;
import haveno.core.offer.availability.OfferAvailabilityModel;
import haveno.core.offer.availability.OfferAvailabilityProtocol;
@ -46,7 +47,6 @@ import javafx.beans.property.StringProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.utils.Fiat;
import javax.annotation.Nullable;
import java.math.BigInteger;
@ -182,9 +182,9 @@ public class Offer implements NetworkPayload, PersistablePayload {
double marketPriceAsDouble = marketPrice.getPrice();
double targetPriceAsDouble = marketPriceAsDouble * factor;
try {
int precision = CurrencyUtil.isCryptoCurrency(currencyCode) ?
Altcoin.SMALLEST_UNIT_EXPONENT :
Fiat.SMALLEST_UNIT_EXPONENT;
int precision = CurrencyUtil.isTraditionalCurrency(currencyCode) ?
TraditionalMoney.SMALLEST_UNIT_EXPONENT :
CryptoMoney.SMALLEST_UNIT_EXPONENT;
double scaled = MathUtils.scaleUpByPowerOf10(targetPriceAsDouble, precision);
final long roundedToLong = MathUtils.roundDoubleToLong(scaled);
return Price.valueOf(currencyCode, roundedToLong);
@ -528,6 +528,10 @@ public class Offer implements NetworkPayload, PersistablePayload {
return getCurrencyCode().equals("XMR");
}
public boolean isTraditionalOffer() {
return CurrencyUtil.isTraditionalCurrency(currencyCode);
}
public boolean isFiatOffer() {
return CurrencyUtil.isFiatCurrency(currencyCode);
}

View file

@ -188,7 +188,7 @@ public class OfferFilterService {
return insufficientCounterpartyTradeLimitCache.get(offerId);
}
boolean result = offer.isFiatOffer() &&
boolean result = offer.isTraditionalOffer() &&
!accountAgeWitnessService.verifyPeersTradeAmount(offer, offer.getAmount(),
errorMessage -> {
});
@ -215,7 +215,7 @@ public class OfferFilterService {
accountOptional.isPresent() ? accountOptional.get().getAccountName() : "null",
Coin.valueOf(myTradeLimit).toFriendlyString(),
Coin.valueOf(offerMinAmount).toFriendlyString());
boolean result = offer.isFiatOffer() &&
boolean result = offer.isTraditionalOffer() &&
accountOptional.isPresent() &&
myTradeLimit < offerMinAmount;
myInsufficientTradeLimitCache.put(offerId, result);

View file

@ -18,9 +18,9 @@
package haveno.core.offer;
import com.fasterxml.jackson.annotation.JsonIgnore;
import haveno.common.util.MathUtils;
import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.Res;
import haveno.core.monetary.CryptoMoney;
import haveno.core.monetary.Price;
import haveno.core.monetary.Volume;
import haveno.core.payment.payload.PaymentMethod;
@ -64,9 +64,9 @@ public class OfferForJson {
public long primaryMarketMinVolume;
@JsonIgnore
transient private final MonetaryFormat fiatFormat = new MonetaryFormat().shift(0).minDecimals(4).repeatOptionalDecimals(0, 0);
transient private final MonetaryFormat traditionalFormat = new MonetaryFormat().shift(0).minDecimals(4).repeatOptionalDecimals(0, 0);
@JsonIgnore
transient private final MonetaryFormat altcoinFormat = new MonetaryFormat().shift(0).minDecimals(8).repeatOptionalDecimals(0, 0);
transient private final MonetaryFormat cryptoFormat = new MonetaryFormat().shift(0).minDecimals(CryptoMoney.SMALLEST_UNIT_EXPONENT).repeatOptionalDecimals(0, 0);
@JsonIgnore
transient private final MonetaryFormat coinFormat = MonetaryFormat.BTC;
@ -99,43 +99,34 @@ public class OfferForJson {
private void setDisplayStrings() {
try {
final Price price = getPrice();
if (CurrencyUtil.isCryptoCurrency(currencyCode)) {
primaryMarketDirection = direction == OfferDirection.BUY ? OfferDirection.SELL : OfferDirection.BUY;
currencyPair = currencyCode + "/" + Res.getBaseCurrencyCode();
// int precision = 8;
//decimalFormat.setMaximumFractionDigits(precision);
// amount and volume is inverted for json
priceDisplayString = altcoinFormat.noCode().format(price.getMonetary()).toString();
primaryMarketMinAmountDisplayString = altcoinFormat.noCode().format(getMinVolume().getMonetary()).toString();
primaryMarketAmountDisplayString = altcoinFormat.noCode().format(getVolume().getMonetary()).toString();
primaryMarketMinVolumeDisplayString = HavenoUtils.formatXmr(getMinAmount()).toString();
primaryMarketVolumeDisplayString = HavenoUtils.formatXmr(getAmount()).toString();
primaryMarketPrice = price.getValue();
primaryMarketMinAmount = getMinVolume().getValue();
primaryMarketAmount = getVolume().getValue();
primaryMarketMinVolume = getMinAmount().longValueExact();
primaryMarketVolume = getAmount().longValueExact();
} else {
primaryMarketDirection = direction;
currencyPair = Res.getBaseCurrencyCode() + "/" + currencyCode;
}
priceDisplayString = fiatFormat.noCode().format(price.getMonetary()).toString();
if (CurrencyUtil.isTraditionalCurrency(currencyCode)) {
priceDisplayString = traditionalFormat.noCode().format(price.getMonetary()).toString();
primaryMarketMinAmountDisplayString = HavenoUtils.formatXmr(getMinAmount()).toString();
primaryMarketAmountDisplayString = HavenoUtils.formatXmr(getAmount()).toString();
primaryMarketMinVolumeDisplayString = fiatFormat.noCode().format(getMinVolume().getMonetary()).toString();
primaryMarketVolumeDisplayString = fiatFormat.noCode().format(getVolume().getMonetary()).toString();
// we use precision 4 for fiat based price but on the markets api we use precision 8 so we scale up by 10000
primaryMarketPrice = (long) MathUtils.scaleUpByPowerOf10(price.getValue(), 4);
primaryMarketMinVolume = (long) MathUtils.scaleUpByPowerOf10(getMinVolume().getValue(), 4);
primaryMarketVolume = (long) MathUtils.scaleUpByPowerOf10(getVolume().getValue(), 4);
primaryMarketMinAmount = getMinAmount().longValueExact();
primaryMarketAmount = getAmount().longValueExact();
primaryMarketMinVolumeDisplayString = traditionalFormat.noCode().format(getMinVolume().getMonetary()).toString();
primaryMarketVolumeDisplayString = traditionalFormat.noCode().format(getVolume().getMonetary()).toString();
} else {
// amount and volume is inverted for json
priceDisplayString = cryptoFormat.noCode().format(price.getMonetary()).toString();
primaryMarketMinAmountDisplayString = cryptoFormat.noCode().format(getMinVolume().getMonetary()).toString();
primaryMarketAmountDisplayString = cryptoFormat.noCode().format(getVolume().getMonetary()).toString();
primaryMarketMinVolumeDisplayString = HavenoUtils.formatXmr(getMinAmount()).toString();
primaryMarketVolumeDisplayString = HavenoUtils.formatXmr(getAmount()).toString();
}
primaryMarketPrice = price.getValue();
primaryMarketMinAmount = getMinVolume().getValue();
primaryMarketAmount = getVolume().getValue();
primaryMarketMinVolume = getMinAmount().longValueExact();
primaryMarketVolume = getAmount().longValueExact();
} catch (Throwable t) {
log.error("Error at setDisplayStrings: " + t.getMessage());

View file

@ -56,8 +56,8 @@ public final class OfferPayload implements ProtectedStoragePayload, ExpirablePay
protected final String id;
protected final long date;
// For fiat offer the baseCurrencyCode is BTC and the counterCurrencyCode is the fiat currency
// For altcoin offers it is the opposite. baseCurrencyCode is the altcoin and the counterCurrencyCode is BTC.
// For traditional offer the baseCurrencyCode is XMR and the counterCurrencyCode is the traditional currency
// For crypto offers it is the opposite. baseCurrencyCode is the crypto and the counterCurrencyCode is XMR.
protected final String baseCurrencyCode;
protected final String counterCurrencyCode;
// price if fixed price is used (usePercentageBasedPrice = false), otherwise 0
@ -89,7 +89,7 @@ public final class OfferPayload implements ProtectedStoragePayload, ExpirablePay
protected List<String> reserveTxKeyImages;
// Keys for extra map
// Only set for fiat offers
// Only set for traditional offers
public static final String ACCOUNT_AGE_WITNESS_HASH = "accountAgeWitnessHash";
public static final String REFERRAL_ID = "referralId";
// Only used in payment method F2F
@ -255,7 +255,7 @@ public final class OfferPayload implements ProtectedStoragePayload, ExpirablePay
// In the offer we support base and counter currency
// Fiat offers have base currency XMR and counterCurrency Fiat
// Altcoins have base currency Altcoin and counterCurrency XMR
// Cryptos have base currency Crypto and counterCurrency XMR
// The rest of the app does not support yet that concept of base currency and counter currencies
// so we map here for convenience
public String getCurrencyCode() {

View file

@ -26,6 +26,7 @@ import haveno.core.filter.FilterManager;
import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.Res;
import haveno.core.monetary.Price;
import haveno.core.monetary.TraditionalMoney;
import haveno.core.monetary.Volume;
import haveno.core.payment.CashByMailAccount;
import haveno.core.payment.F2FAccount;
@ -42,7 +43,6 @@ import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionInput;
import org.bitcoinj.core.TransactionOutput;
import org.bitcoinj.utils.Fiat;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -169,7 +169,7 @@ public class OfferUtil {
CoinFormatter formatter) {
String userCurrencyCode = preferences.getPreferredTradeCurrency().getCode();
if (CurrencyUtil.isCryptoCurrency(userCurrencyCode)) {
// In case the user has selected a altcoin as preferredTradeCurrency
// In case the user has selected a crypto as preferredTradeCurrency
// we derive the fiat currency from the user country
String countryCode = preferences.getUserCountry().code;
userCurrencyCode = CurrencyUtil.getCurrencyByCountryCode(countryCode).getCode();
@ -184,7 +184,7 @@ public class OfferUtil {
String currencyCode,
OfferDirection direction) {
Map<String, String> extraDataMap = new HashMap<>();
if (CurrencyUtil.isFiatCurrency(currencyCode)) {
if (CurrencyUtil.isTraditionalCurrency(currencyCode)) {
String myWitnessHashAsHex = accountAgeWitnessService
.getMyWitnessHashAsHex(paymentAccount.getPaymentAccountPayload());
extraDataMap.put(ACCOUNT_AGE_WITNESS_HASH, myWitnessHashAsHex);
@ -236,7 +236,7 @@ public class OfferUtil {
private Optional<Volume> getFeeInUserFiatCurrency(BigInteger makerFee, String userCurrencyCode, CoinFormatter formatter) {
MarketPrice marketPrice = priceFeedService.getMarketPrice(userCurrencyCode);
if (marketPrice != null && makerFee != null) {
long marketPriceAsLong = roundDoubleToLong(scaleUpByPowerOf10(marketPrice.getPrice(), Fiat.SMALLEST_UNIT_EXPONENT));
long marketPriceAsLong = roundDoubleToLong(scaleUpByPowerOf10(marketPrice.getPrice(), TraditionalMoney.SMALLEST_UNIT_EXPONENT));
Price userCurrencyPrice = Price.valueOf(userCurrencyCode, marketPriceAsLong);
return Optional.of(userCurrencyPrice.getVolumeByAmount(makerFee));
} else {
@ -244,11 +244,11 @@ public class OfferUtil {
}
}
public static boolean isFiatOffer(Offer offer) {
public static boolean isTraditionalOffer(Offer offer) {
return offer.getBaseCurrencyCode().equals("XMR");
}
public static boolean isAltcoinOffer(Offer offer) {
public static boolean isCryptoOffer(Offer offer) {
return offer.getCounterCurrencyCode().equals("XMR");
}

View file

@ -19,8 +19,9 @@ package haveno.core.offer;
import haveno.common.util.MathUtils;
import haveno.core.locale.CurrencyUtil;
import haveno.core.monetary.Altcoin;
import haveno.core.monetary.CryptoMoney;
import haveno.core.monetary.Price;
import haveno.core.monetary.TraditionalMoney;
import haveno.core.provider.mempool.MempoolService;
import haveno.core.provider.price.MarketPrice;
import haveno.core.provider.price.PriceFeedService;
@ -28,7 +29,6 @@ import haveno.network.p2p.BootstrapListener;
import haveno.network.p2p.P2PService;
import javafx.collections.ListChangeListener;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.utils.Fiat;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -110,10 +110,10 @@ public class TriggerPriceService {
}
String currencyCode = openOffer.getOffer().getCurrencyCode();
boolean cryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode);
int smallestUnitExponent = cryptoCurrency ?
Altcoin.SMALLEST_UNIT_EXPONENT :
Fiat.SMALLEST_UNIT_EXPONENT;
boolean traditionalCurrency = CurrencyUtil.isTraditionalCurrency(currencyCode);
int smallestUnitExponent = traditionalCurrency ?
TraditionalMoney.SMALLEST_UNIT_EXPONENT :
CryptoMoney.SMALLEST_UNIT_EXPONENT;
long marketPriceAsLong = roundDoubleToLong(
scaleUpByPowerOf10(marketPrice.getPrice(), smallestUnitExponent));
long triggerPrice = openOffer.getTriggerPrice();
@ -123,6 +123,7 @@ public class TriggerPriceService {
OfferDirection direction = openOffer.getOffer().getDirection();
boolean isSellOffer = direction == OfferDirection.SELL;
boolean cryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode);
boolean condition = isSellOffer && !cryptoCurrency || !isSellOffer && cryptoCurrency;
return condition ?
marketPriceAsLong < triggerPrice :
@ -132,9 +133,9 @@ public class TriggerPriceService {
private void checkPriceThreshold(MarketPrice marketPrice, OpenOffer openOffer) {
if (wasTriggered(marketPrice, openOffer)) {
String currencyCode = openOffer.getOffer().getCurrencyCode();
int smallestUnitExponent = CurrencyUtil.isCryptoCurrency(currencyCode) ?
Altcoin.SMALLEST_UNIT_EXPONENT :
Fiat.SMALLEST_UNIT_EXPONENT;
int smallestUnitExponent = CurrencyUtil.isTraditionalCurrency(currencyCode) ?
TraditionalMoney.SMALLEST_UNIT_EXPONENT :
CryptoMoney.SMALLEST_UNIT_EXPONENT;
long triggerPrice = openOffer.getTriggerPrice();
log.info("Market price exceeded the trigger price of the open offer.\n" +

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.AchTransferAccountPayload;
import haveno.core.payment.payload.BankAccountPayload;
@ -32,7 +32,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class AchTransferAccount extends CountryBasedPaymentAccount implements SameCountryRestrictedBankAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("USD"));
public AchTransferAccount() {
super(PaymentMethod.ACH_TRANSFER);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.AdvancedCashAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -32,13 +32,13 @@ import java.util.List;
public final class AdvancedCashAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(
new FiatCurrency("BRL"),
new FiatCurrency("EUR"),
new FiatCurrency("GBP"),
new FiatCurrency("KZT"),
new FiatCurrency("RUB"),
new FiatCurrency("UAH"),
new FiatCurrency("USD"));
new TraditionalCurrency("BRL"),
new TraditionalCurrency("EUR"),
new TraditionalCurrency("GBP"),
new TraditionalCurrency("KZT"),
new TraditionalCurrency("RUB"),
new TraditionalCurrency("UAH"),
new TraditionalCurrency("USD"));
public AdvancedCashAccount() {
super(PaymentMethod.ADVANCED_CASH);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.AliPayAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -31,7 +31,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class AliPayAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("CNY"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("CNY"));
public AliPayAccount() {
super(PaymentMethod.ALI_PAY);

View file

@ -20,7 +20,7 @@ package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.Country;
import haveno.core.locale.CountryUtil;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.AmazonGiftCardAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -33,17 +33,17 @@ import java.util.List;
public final class AmazonGiftCardAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(
new FiatCurrency("AUD"),
new FiatCurrency("CAD"),
new FiatCurrency("EUR"),
new FiatCurrency("GBP"),
new FiatCurrency("INR"),
new FiatCurrency("JPY"),
new FiatCurrency("SAR"),
new FiatCurrency("SEK"),
new FiatCurrency("SGD"),
new FiatCurrency("TRY"),
new FiatCurrency("USD")
new TraditionalCurrency("AUD"),
new TraditionalCurrency("CAD"),
new TraditionalCurrency("EUR"),
new TraditionalCurrency("GBP"),
new TraditionalCurrency("INR"),
new TraditionalCurrency("JPY"),
new TraditionalCurrency("SAR"),
new TraditionalCurrency("SEK"),
new TraditionalCurrency("SGD"),
new TraditionalCurrency("TRY"),
new TraditionalCurrency("USD")
);
@Nullable

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.AustraliaPayidAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -29,7 +29,7 @@ import java.util.List;
public final class AustraliaPayidAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("AUD"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("AUD"));
public AustraliaPayidAccount() {
super(PaymentMethod.AUSTRALIA_PAYID);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.BizumAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -31,7 +31,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class BizumAccount extends CountryBasedPaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("EUR"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("EUR"));
public BizumAccount() {
super(PaymentMethod.BIZUM);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.CapitualAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -32,10 +32,10 @@ import java.util.List;
public final class CapitualAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(
new FiatCurrency("BRL"),
new FiatCurrency("EUR"),
new FiatCurrency("GBP"),
new FiatCurrency("USD")
new TraditionalCurrency("BRL"),
new TraditionalCurrency("EUR"),
new TraditionalCurrency("GBP"),
new TraditionalCurrency("USD")
);
public CapitualAccount() {

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.CashAppAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -34,7 +34,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class CashAppAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("USD"));
public CashAppAccount() {
super(PaymentMethod.CASH_APP);

View file

@ -29,7 +29,7 @@ import java.util.List;
public final class CashByMailAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = CurrencyUtil.getAllFiatCurrencies();
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = CurrencyUtil.getAllTraditionalCurrencies();
public CashByMailAccount() {
super(PaymentMethod.CASH_BY_MAIL);

View file

@ -30,7 +30,7 @@ import java.util.List;
public final class CashDepositAccount extends CountryBasedPaymentAccount implements SameCountryRestrictedBankAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = CurrencyUtil.getAllFiatCurrencies();
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = CurrencyUtil.getAllTraditionalCurrencies();
public CashDepositAccount() {
super(PaymentMethod.CASH_DEPOSIT);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.CelPayAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -33,11 +33,11 @@ public final class CelPayAccount extends PaymentAccount {
// https://github.com/bisq-network/growth/issues/231
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(
new FiatCurrency("AUD"),
new FiatCurrency("CAD"),
new FiatCurrency("GBP"),
new FiatCurrency("HKD"),
new FiatCurrency("USD")
new TraditionalCurrency("AUD"),
new TraditionalCurrency("CAD"),
new TraditionalCurrency("GBP"),
new TraditionalCurrency("HKD"),
new TraditionalCurrency("USD")
);
public CelPayAccount() {

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.ChaseQuickPayAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -34,7 +34,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class ChaseQuickPayAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("USD"));
public ChaseQuickPayAccount() {
super(PaymentMethod.CHASE_QUICK_PAY);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.BankAccountPayload;
import haveno.core.payment.payload.DomesticWireTransferAccountPayload;
@ -32,7 +32,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class DomesticWireTransferAccount extends CountryBasedPaymentAccount implements SameCountryRestrictedBankAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("USD"));
public DomesticWireTransferAccount() {
super(PaymentMethod.DOMESTIC_WIRE_TRANSFER);

View file

@ -32,7 +32,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class F2FAccount extends CountryBasedPaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = CurrencyUtil.getAllFiatCurrencies();
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = CurrencyUtil.getAllTraditionalCurrencies();
private static final List<PaymentAccountFormField.FieldId> INPUT_FIELD_IDS = List.of(
PaymentAccountFormField.FieldId.ACCOUNT_NAME,

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.FasterPaymentsAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -39,7 +39,7 @@ public final class FasterPaymentsAccount extends PaymentAccount {
PaymentAccountFormField.FieldId.SALT
);
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("GBP"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("GBP"));
public FasterPaymentsAccount() {
super(PaymentMethod.FASTER_PAYMENTS);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.HalCashAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -31,7 +31,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class HalCashAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("EUR"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("EUR"));
public HalCashAccount() {
super(PaymentMethod.HAL_CASH);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentMethod;
import lombok.NonNull;
@ -27,7 +27,7 @@ import java.util.List;
abstract public class IfscBasedAccount extends CountryBasedPaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("INR"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("INR"));
protected IfscBasedAccount(PaymentMethod paymentMethod) {
super(paymentMethod);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.ImpsAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -31,7 +31,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class ImpsAccount extends CountryBasedPaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("INR"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("INR"));
public ImpsAccount() {
super(PaymentMethod.IMPS);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.InteracETransferAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -31,7 +31,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class InteracETransferAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("CAD"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("CAD"));
public InteracETransferAccount() {
super(PaymentMethod.INTERAC_E_TRANSFER);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.JapanBankAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -29,7 +29,7 @@ import java.util.List;
public final class JapanBankAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("JPY"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("JPY"));
public JapanBankAccount() {
super(PaymentMethod.JAPAN_BANK);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.MoneseAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -33,9 +33,9 @@ public final class MoneseAccount extends PaymentAccount {
// https://github.com/bisq-network/growth/issues/227
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(
new FiatCurrency("EUR"),
new FiatCurrency("GBP"),
new FiatCurrency("RON")
new TraditionalCurrency("EUR"),
new TraditionalCurrency("GBP"),
new TraditionalCurrency("RON")
);
public MoneseAccount() {

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.MoneyBeamAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -32,7 +32,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class MoneyBeamAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("EUR"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("EUR"));
public MoneyBeamAccount() {
super(PaymentMethod.MONEY_BEAM);

View file

@ -20,7 +20,7 @@ package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.Country;
import haveno.core.locale.CountryUtil;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.MoneyGramAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -48,54 +48,54 @@ public final class MoneyGramAccount extends PaymentAccount {
);
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(
new FiatCurrency("AED"),
new FiatCurrency("ARS"),
new FiatCurrency("AUD"),
new FiatCurrency("BND"),
new FiatCurrency("CAD"),
new FiatCurrency("CHF"),
new FiatCurrency("CZK"),
new FiatCurrency("DKK"),
new FiatCurrency("EUR"),
new FiatCurrency("FJD"),
new FiatCurrency("GBP"),
new FiatCurrency("HKD"),
new FiatCurrency("HUF"),
new FiatCurrency("IDR"),
new FiatCurrency("ILS"),
new FiatCurrency("INR"),
new FiatCurrency("JPY"),
new FiatCurrency("KRW"),
new FiatCurrency("KWD"),
new FiatCurrency("LKR"),
new FiatCurrency("MAD"),
new FiatCurrency("MGA"),
new FiatCurrency("MXN"),
new FiatCurrency("MYR"),
new FiatCurrency("NOK"),
new FiatCurrency("NZD"),
new FiatCurrency("OMR"),
new FiatCurrency("PEN"),
new FiatCurrency("PGK"),
new FiatCurrency("PHP"),
new FiatCurrency("PKR"),
new FiatCurrency("PLN"),
new FiatCurrency("SAR"),
new FiatCurrency("SBD"),
new FiatCurrency("SCR"),
new FiatCurrency("SEK"),
new FiatCurrency("SGD"),
new FiatCurrency("THB"),
new FiatCurrency("TOP"),
new FiatCurrency("TRY"),
new FiatCurrency("TWD"),
new FiatCurrency("USD"),
new FiatCurrency("VND"),
new FiatCurrency("VUV"),
new FiatCurrency("WST"),
new FiatCurrency("XOF"),
new FiatCurrency("XPF"),
new FiatCurrency("ZAR")
new TraditionalCurrency("AED"),
new TraditionalCurrency("ARS"),
new TraditionalCurrency("AUD"),
new TraditionalCurrency("BND"),
new TraditionalCurrency("CAD"),
new TraditionalCurrency("CHF"),
new TraditionalCurrency("CZK"),
new TraditionalCurrency("DKK"),
new TraditionalCurrency("EUR"),
new TraditionalCurrency("FJD"),
new TraditionalCurrency("GBP"),
new TraditionalCurrency("HKD"),
new TraditionalCurrency("HUF"),
new TraditionalCurrency("IDR"),
new TraditionalCurrency("ILS"),
new TraditionalCurrency("INR"),
new TraditionalCurrency("JPY"),
new TraditionalCurrency("KRW"),
new TraditionalCurrency("KWD"),
new TraditionalCurrency("LKR"),
new TraditionalCurrency("MAD"),
new TraditionalCurrency("MGA"),
new TraditionalCurrency("MXN"),
new TraditionalCurrency("MYR"),
new TraditionalCurrency("NOK"),
new TraditionalCurrency("NZD"),
new TraditionalCurrency("OMR"),
new TraditionalCurrency("PEN"),
new TraditionalCurrency("PGK"),
new TraditionalCurrency("PHP"),
new TraditionalCurrency("PKR"),
new TraditionalCurrency("PLN"),
new TraditionalCurrency("SAR"),
new TraditionalCurrency("SBD"),
new TraditionalCurrency("SCR"),
new TraditionalCurrency("SEK"),
new TraditionalCurrency("SGD"),
new TraditionalCurrency("THB"),
new TraditionalCurrency("TOP"),
new TraditionalCurrency("TRY"),
new TraditionalCurrency("TWD"),
new TraditionalCurrency("USD"),
new TraditionalCurrency("VND"),
new TraditionalCurrency("VUV"),
new TraditionalCurrency("WST"),
new TraditionalCurrency("XOF"),
new TraditionalCurrency("XPF"),
new TraditionalCurrency("ZAR")
);
public MoneyGramAccount() {

View file

@ -32,7 +32,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class NationalBankAccount extends CountryBasedPaymentAccount implements SameCountryRestrictedBankAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = CurrencyUtil.getAllFiatCurrencies();
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = CurrencyUtil.getAllTraditionalCurrencies();
public NationalBankAccount() {
super(PaymentMethod.NATIONAL_BANK);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.NequiAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -31,7 +31,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class NequiAccount extends CountryBasedPaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("COP"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("COP"));
public NequiAccount() {
super(PaymentMethod.NEQUI);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.OKPayAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -34,29 +34,29 @@ import java.util.List;
public final class OKPayAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(
new FiatCurrency("AED"),
new FiatCurrency("ARS"),
new FiatCurrency("AUD"),
new FiatCurrency("BRL"),
new FiatCurrency("CAD"),
new FiatCurrency("CHF"),
new FiatCurrency("CNY"),
new FiatCurrency("DKK"),
new FiatCurrency("EUR"),
new FiatCurrency("GBP"),
new FiatCurrency("HKD"),
new FiatCurrency("ILS"),
new FiatCurrency("INR"),
new FiatCurrency("JPY"),
new FiatCurrency("KES"),
new FiatCurrency("MXN"),
new FiatCurrency("NOK"),
new FiatCurrency("NZD"),
new FiatCurrency("PHP"),
new FiatCurrency("PLN"),
new FiatCurrency("SEK"),
new FiatCurrency("SGD"),
new FiatCurrency("USD")
new TraditionalCurrency("AED"),
new TraditionalCurrency("ARS"),
new TraditionalCurrency("AUD"),
new TraditionalCurrency("BRL"),
new TraditionalCurrency("CAD"),
new TraditionalCurrency("CHF"),
new TraditionalCurrency("CNY"),
new TraditionalCurrency("DKK"),
new TraditionalCurrency("EUR"),
new TraditionalCurrency("GBP"),
new TraditionalCurrency("HKD"),
new TraditionalCurrency("ILS"),
new TraditionalCurrency("INR"),
new TraditionalCurrency("JPY"),
new TraditionalCurrency("KES"),
new TraditionalCurrency("MXN"),
new TraditionalCurrency("NOK"),
new TraditionalCurrency("NZD"),
new TraditionalCurrency("PHP"),
new TraditionalCurrency("PLN"),
new TraditionalCurrency("SEK"),
new TraditionalCurrency("SGD"),
new TraditionalCurrency("USD")
);
public OKPayAccount() {

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaxumAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -40,24 +40,24 @@ public final class PaxumAccount extends PaymentAccount {
// https://github.com/bisq-network/growth/issues/235
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(
new FiatCurrency("AUD"),
new FiatCurrency("CAD"),
new FiatCurrency("CHF"),
new FiatCurrency("CZK"),
new FiatCurrency("DKK"),
new FiatCurrency("EUR"),
new FiatCurrency("GBP"),
new FiatCurrency("HUF"),
new FiatCurrency("IDR"),
new FiatCurrency("INR"),
new FiatCurrency("NOK"),
new FiatCurrency("NZD"),
new FiatCurrency("PLN"),
new FiatCurrency("RON"),
new FiatCurrency("SEK"),
new FiatCurrency("THB"),
new FiatCurrency("USD"),
new FiatCurrency("ZAR")
new TraditionalCurrency("AUD"),
new TraditionalCurrency("CAD"),
new TraditionalCurrency("CHF"),
new TraditionalCurrency("CZK"),
new TraditionalCurrency("DKK"),
new TraditionalCurrency("EUR"),
new TraditionalCurrency("GBP"),
new TraditionalCurrency("HUF"),
new TraditionalCurrency("IDR"),
new TraditionalCurrency("INR"),
new TraditionalCurrency("NOK"),
new TraditionalCurrency("NZD"),
new TraditionalCurrency("PLN"),
new TraditionalCurrency("RON"),
new TraditionalCurrency("SEK"),
new TraditionalCurrency("THB"),
new TraditionalCurrency("USD"),
new TraditionalCurrency("ZAR")
);
public PaxumAccount() {

View file

@ -24,7 +24,7 @@ import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import haveno.core.locale.Country;
import haveno.core.locale.CountryUtil;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.Res;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -435,7 +435,7 @@ class PaymentAccountTypeAdapter extends TypeAdapter<PaymentAccount> {
if (account.isCountryBasedPaymentAccount()) {
((CountryBasedPaymentAccount) account).setCountry(country.get());
FiatCurrency fiatCurrency = getCurrencyByCountryCode(checkNotNull(countryCode));
TraditionalCurrency fiatCurrency = getCurrencyByCountryCode(checkNotNull(countryCode));
account.setSingleTradeCurrency(fiatCurrency);
} else if (account.hasPaymentMethodWithId(MONEY_GRAM_ID)) {
((MoneyGramAccount) account).setCountry(country.get());

View file

@ -295,7 +295,7 @@ public class PaymentAccountUtil {
@Nullable
public static String getCountryCode(PaymentAccount paymentAccount) {
// That is optional and set to null if not supported (AltCoins,...)
// That is optional and set to null if not supported (Cryptos,...)
if (paymentAccount instanceof CountryBasedPaymentAccount) {
Country country = (((CountryBasedPaymentAccount) paymentAccount)).getCountry();
return country != null ? country.code : null;

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -33,38 +33,38 @@ public final class PayseraAccount extends PaymentAccount {
// https://github.com/bisq-network/growth/issues/233
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(
new FiatCurrency("AUD"),
new FiatCurrency("BGN"),
new FiatCurrency("BYN"),
new FiatCurrency("CAD"),
new FiatCurrency("CHF"),
new FiatCurrency("CNY"),
new FiatCurrency("CZK"),
new FiatCurrency("DKK"),
new FiatCurrency("EUR"),
new FiatCurrency("GBP"),
new FiatCurrency("GEL"),
new FiatCurrency("HKD"),
new FiatCurrency("HRK"),
new FiatCurrency("HUF"),
new FiatCurrency("ILS"),
new FiatCurrency("INR"),
new FiatCurrency("JPY"),
new FiatCurrency("KZT"),
new FiatCurrency("MXN"),
new FiatCurrency("NOK"),
new FiatCurrency("NZD"),
new FiatCurrency("PHP"),
new FiatCurrency("PLN"),
new FiatCurrency("RON"),
new FiatCurrency("RSD"),
new FiatCurrency("RUB"),
new FiatCurrency("SEK"),
new FiatCurrency("SGD"),
new FiatCurrency("THB"),
new FiatCurrency("TRY"),
new FiatCurrency("USD"),
new FiatCurrency("ZAR")
new TraditionalCurrency("AUD"),
new TraditionalCurrency("BGN"),
new TraditionalCurrency("BYN"),
new TraditionalCurrency("CAD"),
new TraditionalCurrency("CHF"),
new TraditionalCurrency("CNY"),
new TraditionalCurrency("CZK"),
new TraditionalCurrency("DKK"),
new TraditionalCurrency("EUR"),
new TraditionalCurrency("GBP"),
new TraditionalCurrency("GEL"),
new TraditionalCurrency("HKD"),
new TraditionalCurrency("HRK"),
new TraditionalCurrency("HUF"),
new TraditionalCurrency("ILS"),
new TraditionalCurrency("INR"),
new TraditionalCurrency("JPY"),
new TraditionalCurrency("KZT"),
new TraditionalCurrency("MXN"),
new TraditionalCurrency("NOK"),
new TraditionalCurrency("NZD"),
new TraditionalCurrency("PHP"),
new TraditionalCurrency("PLN"),
new TraditionalCurrency("RON"),
new TraditionalCurrency("RSD"),
new TraditionalCurrency("RUB"),
new TraditionalCurrency("SEK"),
new TraditionalCurrency("SGD"),
new TraditionalCurrency("THB"),
new TraditionalCurrency("TRY"),
new TraditionalCurrency("USD"),
new TraditionalCurrency("ZAR")
);
public PayseraAccount() {

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -31,7 +31,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class PerfectMoneyAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("USD"));
public PerfectMoneyAccount() {
super(PaymentMethod.PERFECT_MONEY);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -31,7 +31,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class PixAccount extends CountryBasedPaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("BRL"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("BRL"));
public PixAccount() {
super(PaymentMethod.PIX);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -32,7 +32,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class PopmoneyAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("USD"));
public PopmoneyAccount() {
super(PaymentMethod.POPMONEY);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -31,7 +31,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class PromptPayAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("THB"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("THB"));
public PromptPayAccount() {
super(PaymentMethod.PROMPT_PAY);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -40,37 +40,37 @@ public final class RevolutAccount extends PaymentAccount {
// https://www.revolut.com/help/getting-started/exchanging-currencies/what-fiat-currencies-are-supported-for-holding-and-exchange
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(
new FiatCurrency("AED"),
new FiatCurrency("AUD"),
new FiatCurrency("BGN"),
new FiatCurrency("CAD"),
new FiatCurrency("CHF"),
new FiatCurrency("CZK"),
new FiatCurrency("DKK"),
new FiatCurrency("EUR"),
new FiatCurrency("GBP"),
new FiatCurrency("HKD"),
new FiatCurrency("HRK"),
new FiatCurrency("HUF"),
new FiatCurrency("ILS"),
new FiatCurrency("ISK"),
new FiatCurrency("JPY"),
new FiatCurrency("MAD"),
new FiatCurrency("MXN"),
new FiatCurrency("NOK"),
new FiatCurrency("NZD"),
new FiatCurrency("PLN"),
new FiatCurrency("QAR"),
new FiatCurrency("RON"),
new FiatCurrency("RSD"),
new FiatCurrency("RUB"),
new FiatCurrency("SAR"),
new FiatCurrency("SEK"),
new FiatCurrency("SGD"),
new FiatCurrency("THB"),
new FiatCurrency("TRY"),
new FiatCurrency("USD"),
new FiatCurrency("ZAR")
new TraditionalCurrency("AED"),
new TraditionalCurrency("AUD"),
new TraditionalCurrency("BGN"),
new TraditionalCurrency("CAD"),
new TraditionalCurrency("CHF"),
new TraditionalCurrency("CZK"),
new TraditionalCurrency("DKK"),
new TraditionalCurrency("EUR"),
new TraditionalCurrency("GBP"),
new TraditionalCurrency("HKD"),
new TraditionalCurrency("HRK"),
new TraditionalCurrency("HUF"),
new TraditionalCurrency("ILS"),
new TraditionalCurrency("ISK"),
new TraditionalCurrency("JPY"),
new TraditionalCurrency("MAD"),
new TraditionalCurrency("MXN"),
new TraditionalCurrency("NOK"),
new TraditionalCurrency("NZD"),
new TraditionalCurrency("PLN"),
new TraditionalCurrency("QAR"),
new TraditionalCurrency("RON"),
new TraditionalCurrency("RSD"),
new TraditionalCurrency("RUB"),
new TraditionalCurrency("SAR"),
new TraditionalCurrency("SEK"),
new TraditionalCurrency("SGD"),
new TraditionalCurrency("THB"),
new TraditionalCurrency("TRY"),
new TraditionalCurrency("USD"),
new TraditionalCurrency("ZAR")
);
public RevolutAccount() {

View file

@ -32,7 +32,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class SameBankAccount extends CountryBasedPaymentAccount implements BankNameRestrictedBankAccount, SameCountryRestrictedBankAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = CurrencyUtil.getAllFiatCurrencies();
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = CurrencyUtil.getAllTraditionalCurrencies();
public SameBankAccount() {
super(PaymentMethod.SAME_BANK);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -31,7 +31,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class SatispayAccount extends CountryBasedPaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("EUR"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("EUR"));
public SatispayAccount() {
super(PaymentMethod.SATISPAY);

View file

@ -21,7 +21,7 @@ import haveno.core.api.model.PaymentAccountForm;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.Country;
import haveno.core.locale.CountryUtil;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -46,7 +46,7 @@ public final class SepaAccount extends CountryBasedPaymentAccount implements Ban
PaymentAccountFormField.FieldId.SALT
);
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("EUR"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("EUR"));
public SepaAccount() {
super(PaymentMethod.SEPA);

View file

@ -21,7 +21,7 @@ import haveno.core.api.model.PaymentAccountForm;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.Country;
import haveno.core.locale.CountryUtil;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -36,7 +36,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class SepaInstantAccount extends CountryBasedPaymentAccount implements BankAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("EUR"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("EUR"));
public SepaInstantAccount() {
super(PaymentMethod.SEPA_INSTANT);

View file

@ -32,7 +32,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class SpecificBanksAccount extends CountryBasedPaymentAccount implements BankNameRestrictedBankAccount, SameCountryRestrictedBankAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = CurrencyUtil.getAllFiatCurrencies();
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = CurrencyUtil.getAllTraditionalCurrencies();
public SpecificBanksAccount() {
super(PaymentMethod.SPECIFIC_BANKS);

View file

@ -20,7 +20,7 @@ package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.Country;
import haveno.core.locale.CountryUtil;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -34,7 +34,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class StrikeAccount extends CountryBasedPaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("USD"));
public static final List<Country> SUPPORTED_COUNTRIES = CountryUtil.getCountries(List.of("US"));
private static final List<PaymentAccountFormField.FieldId> INPUT_FIELD_IDS = List.of(

View file

@ -28,13 +28,13 @@ import lombok.NonNull;
import java.util.ArrayList;
import java.util.List;
import static haveno.core.locale.CurrencyUtil.getAllSortedFiatCurrencies;
import static haveno.core.locale.CurrencyUtil.getAllSortedTraditionalCurrencies;
import static java.util.Comparator.comparing;
@EqualsAndHashCode(callSuper = true)
public final class SwiftAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = new ArrayList<>(getAllSortedFiatCurrencies(comparing(TradeCurrency::getCode)));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = new ArrayList<>(getAllSortedTraditionalCurrencies(comparing(TradeCurrency::getCode)));
private static final List<PaymentAccountFormField.FieldId> INPUT_FIELD_IDS = List.of(
PaymentAccountFormField.FieldId.ACCOUNT_NAME,

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -31,7 +31,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class SwishAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("SEK"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("SEK"));
public SwishAccount() {
super(PaymentMethod.SWISH);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -31,7 +31,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class TikkieAccount extends CountryBasedPaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("EUR"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("EUR"));
public TikkieAccount() {
super(PaymentMethod.TIKKIE);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -40,48 +40,48 @@ public final class TransferwiseAccount extends PaymentAccount {
// https://github.com/bisq-network/proposals/issues/243
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(
new FiatCurrency("AED"),
new FiatCurrency("ARS"),
new FiatCurrency("AUD"),
new FiatCurrency("BGN"),
new FiatCurrency("CAD"),
new FiatCurrency("CHF"),
new FiatCurrency("CLP"),
new FiatCurrency("CZK"),
new FiatCurrency("DKK"),
new FiatCurrency("EGP"),
new FiatCurrency("EUR"),
new FiatCurrency("GBP"),
new FiatCurrency("GEL"),
new FiatCurrency("HKD"),
new FiatCurrency("HRK"),
new FiatCurrency("HUF"),
new FiatCurrency("IDR"),
new FiatCurrency("ILS"),
new FiatCurrency("JPY"),
new FiatCurrency("KES"),
new FiatCurrency("KRW"),
new FiatCurrency("MAD"),
new FiatCurrency("MXN"),
new FiatCurrency("MYR"),
new FiatCurrency("NOK"),
new FiatCurrency("NPR"),
new FiatCurrency("NZD"),
new FiatCurrency("PEN"),
new FiatCurrency("PHP"),
new FiatCurrency("PKR"),
new FiatCurrency("PLN"),
new FiatCurrency("RON"),
new FiatCurrency("RUB"),
new FiatCurrency("SEK"),
new FiatCurrency("SGD"),
new FiatCurrency("THB"),
new FiatCurrency("TRY"),
new FiatCurrency("UGX"),
new FiatCurrency("VND"),
new FiatCurrency("XOF"),
new FiatCurrency("ZAR"),
new FiatCurrency("ZMW")
new TraditionalCurrency("AED"),
new TraditionalCurrency("ARS"),
new TraditionalCurrency("AUD"),
new TraditionalCurrency("BGN"),
new TraditionalCurrency("CAD"),
new TraditionalCurrency("CHF"),
new TraditionalCurrency("CLP"),
new TraditionalCurrency("CZK"),
new TraditionalCurrency("DKK"),
new TraditionalCurrency("EGP"),
new TraditionalCurrency("EUR"),
new TraditionalCurrency("GBP"),
new TraditionalCurrency("GEL"),
new TraditionalCurrency("HKD"),
new TraditionalCurrency("HRK"),
new TraditionalCurrency("HUF"),
new TraditionalCurrency("IDR"),
new TraditionalCurrency("ILS"),
new TraditionalCurrency("JPY"),
new TraditionalCurrency("KES"),
new TraditionalCurrency("KRW"),
new TraditionalCurrency("MAD"),
new TraditionalCurrency("MXN"),
new TraditionalCurrency("MYR"),
new TraditionalCurrency("NOK"),
new TraditionalCurrency("NPR"),
new TraditionalCurrency("NZD"),
new TraditionalCurrency("PEN"),
new TraditionalCurrency("PHP"),
new TraditionalCurrency("PKR"),
new TraditionalCurrency("PLN"),
new TraditionalCurrency("RON"),
new TraditionalCurrency("RUB"),
new TraditionalCurrency("SEK"),
new TraditionalCurrency("SGD"),
new TraditionalCurrency("THB"),
new TraditionalCurrency("TRY"),
new TraditionalCurrency("UGX"),
new TraditionalCurrency("VND"),
new TraditionalCurrency("XOF"),
new TraditionalCurrency("ZAR"),
new TraditionalCurrency("ZMW")
);
public TransferwiseAccount() {

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -31,7 +31,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class TransferwiseUsdAccount extends CountryBasedPaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("USD"));
public TransferwiseUsdAccount() {
super(PaymentMethod.TRANSFERWISE_USD);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -31,7 +31,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class USPostalMoneyOrderAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("USD"));
public USPostalMoneyOrderAccount() {
super(PaymentMethod.US_POSTAL_MONEY_ORDER);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -42,29 +42,29 @@ public final class UpholdAccount extends PaymentAccount {
// https://support.uphold.com/hc/en-us/articles/202473803-Supported-currencies
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(
new FiatCurrency("AED"),
new FiatCurrency("ARS"),
new FiatCurrency("AUD"),
new FiatCurrency("BRL"),
new FiatCurrency("CAD"),
new FiatCurrency("CHF"),
new FiatCurrency("CNY"),
new FiatCurrency("DKK"),
new FiatCurrency("EUR"),
new FiatCurrency("GBP"),
new FiatCurrency("HKD"),
new FiatCurrency("ILS"),
new FiatCurrency("INR"),
new FiatCurrency("JPY"),
new FiatCurrency("KES"),
new FiatCurrency("MXN"),
new FiatCurrency("NOK"),
new FiatCurrency("NZD"),
new FiatCurrency("PHP"),
new FiatCurrency("PLN"),
new FiatCurrency("SEK"),
new FiatCurrency("SGD"),
new FiatCurrency("USD")
new TraditionalCurrency("AED"),
new TraditionalCurrency("ARS"),
new TraditionalCurrency("AUD"),
new TraditionalCurrency("BRL"),
new TraditionalCurrency("CAD"),
new TraditionalCurrency("CHF"),
new TraditionalCurrency("CNY"),
new TraditionalCurrency("DKK"),
new TraditionalCurrency("EUR"),
new TraditionalCurrency("GBP"),
new TraditionalCurrency("HKD"),
new TraditionalCurrency("ILS"),
new TraditionalCurrency("INR"),
new TraditionalCurrency("JPY"),
new TraditionalCurrency("KES"),
new TraditionalCurrency("MXN"),
new TraditionalCurrency("NOK"),
new TraditionalCurrency("NZD"),
new TraditionalCurrency("PHP"),
new TraditionalCurrency("PLN"),
new TraditionalCurrency("SEK"),
new TraditionalCurrency("SGD"),
new TraditionalCurrency("USD")
);
public UpholdAccount() {

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -34,7 +34,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class VenmoAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("USD"));
public VenmoAccount() {
super(PaymentMethod.VENMO);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -33,11 +33,11 @@ public final class VerseAccount extends PaymentAccount {
// https://github.com/bisq-network/growth/issues/223
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(
new FiatCurrency("DKK"),
new FiatCurrency("EUR"),
new FiatCurrency("HUF"),
new FiatCurrency("PLN"),
new FiatCurrency("SEK")
new TraditionalCurrency("DKK"),
new TraditionalCurrency("EUR"),
new TraditionalCurrency("HUF"),
new TraditionalCurrency("PLN"),
new TraditionalCurrency("SEK")
);
public VerseAccount() {

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
@ -31,7 +31,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class WeChatPayAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("CNY"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("CNY"));
public WeChatPayAccount() {
super(PaymentMethod.WECHAT_PAY);

View file

@ -29,7 +29,7 @@ import java.util.List;
public final class WesternUnionAccount extends CountryBasedPaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = CurrencyUtil.getAllFiatCurrencies();
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = CurrencyUtil.getAllTraditionalCurrencies();
public WesternUnionAccount() {
super(PaymentMethod.WESTERN_UNION);

View file

@ -18,7 +18,7 @@
package haveno.core.payment;
import haveno.core.api.model.PaymentAccountFormField;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.payload.ZelleAccountPayload;
import haveno.core.payment.payload.PaymentAccountPayload;
@ -31,7 +31,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public final class ZelleAccount extends PaymentAccount {
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD"));
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = List.of(new TraditionalCurrency("USD"));
public ZelleAccount() {
super(PaymentMethod.ZELLE);

View file

@ -63,7 +63,7 @@ public abstract class AssetAccountPayload extends PaymentAccountPayload {
@Override
public String getPaymentDetails() {
return Res.getWithCol("payment.altcoin.receiver.address") + " " + address;
return Res.getWithCol("payment.crypto.receiver.address") + " " + address;
}
@Override

View file

@ -320,9 +320,9 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
// Thailand
PROMPT_PAY = new PaymentMethod(PROMPT_PAY_ID, DAY, DEFAULT_TRADE_LIMIT_LOW_RISK, getAssetCodes(PromptPayAccount.SUPPORTED_CURRENCIES)),
// Altcoins
// Cryptos
BLOCK_CHAINS = new PaymentMethod(BLOCK_CHAINS_ID, DAY, DEFAULT_TRADE_LIMIT_VERY_LOW_RISK, Arrays.asList()),
// Altcoins with 1 hour trade period
// Cryptos with 1 hour trade period
BLOCK_CHAINS_INSTANT = new PaymentMethod(BLOCK_CHAINS_INSTANT_ID, TimeUnit.HOURS.toMillis(1), DEFAULT_TRADE_LIMIT_VERY_LOW_RISK, Arrays.asList())
);
@ -483,10 +483,10 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
long maxTradeLimit = tradeLimits.getMaxTradeLimit().longValueExact();
long riskBasedTradeLimit = tradeLimits.getRoundedRiskBasedTradeLimit(maxTradeLimit, riskFactor);
// if fiat and stagenet, cap offer amounts to avoid offers which cannot be taken
boolean isFiat = CurrencyUtil.isFiatCurrency(currencyCode);
// if traditional and stagenet, cap offer amounts to avoid offers which cannot be taken
boolean isTraditional = CurrencyUtil.isTraditionalCurrency(currencyCode);
boolean isStagenet = Config.baseCurrencyNetwork() == BaseCurrencyNetwork.XMR_STAGENET;
if (isFiat && isStagenet && riskBasedTradeLimit > OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.longValueExact()) {
if (isTraditional && isStagenet && riskBasedTradeLimit > OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.longValueExact()) {
riskBasedTradeLimit = OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.longValueExact();
}
return BigInteger.valueOf(riskBasedTradeLimit);
@ -507,8 +507,8 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
return Res.get(id);
}
public boolean isFiat() {
return !isAltcoin();
public boolean isTraditional() {
return !isCrypto();
}
public boolean isBlockchain() {
@ -516,7 +516,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
}
// Includes any non btc asset, not limited to blockchain payment methods
public boolean isAltcoin() {
public boolean isCrypto() {
return isBlockchain() || isBsqSwap();
}

View file

@ -30,13 +30,13 @@ import lombok.extern.slf4j.Slf4j;
import java.util.Optional;
@Slf4j
public final class AltCoinAddressValidator extends InputValidator {
public final class CryptoAddressValidator extends InputValidator {
private final AssetRegistry assetRegistry;
private String currencyCode;
@Inject
public AltCoinAddressValidator(AssetRegistry assetRegistry) {
public CryptoAddressValidator(AssetRegistry assetRegistry) {
this.assetRegistry = assetRegistry;
}

View file

@ -28,7 +28,9 @@ import haveno.common.handlers.FaultHandler;
import haveno.common.util.MathUtils;
import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.TradeCurrency;
import haveno.core.monetary.CryptoMoney;
import haveno.core.monetary.Price;
import haveno.core.monetary.TraditionalMoney;
import haveno.core.provider.PriceHttpClient;
import haveno.core.provider.ProvidersRepository;
import haveno.core.trade.HavenoUtils;
@ -272,7 +274,7 @@ public class PriceFeedService {
private void setHavenoMarketPrice(String currencyCode, Price price) {
if (!cache.containsKey(currencyCode) || !cache.get(currencyCode).isExternallyProvidedPrice()) {
cache.put(currencyCode, new MarketPrice(currencyCode,
MathUtils.scaleDownByPowerOf10(price.getValue(), CurrencyUtil.isCryptoCurrency(currencyCode) ? 8 : 4),
MathUtils.scaleDownByPowerOf10(price.getValue(), CurrencyUtil.isCryptoCurrency(currencyCode) ? CryptoMoney.SMALLEST_UNIT_EXPONENT : TraditionalMoney.SMALLEST_UNIT_EXPONENT),
0,
false));
updateCounter.set(updateCounter.get() + 1);
@ -340,7 +342,7 @@ public class PriceFeedService {
/**
* Returns prices for all available currencies.
* For crypto currencies the value is XMR price for 1 unit of given crypto currency (e.g. 1 DOGE = X XMR).
* For fiat currencies the value is price in the given fiat currency per 1 XMR (e.g. 1 XMR = X USD).
* For traditional currencies the value is price in the given traditional currency per 1 XMR (e.g. 1 XMR = X USD).
*
* TODO: instrument requestPrices() result and fault handlers instead of using CountDownLatch and timeout
*/

View file

@ -30,8 +30,9 @@ import haveno.core.api.CoreMoneroConnectionsService;
import haveno.core.api.CoreNotificationService;
import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.Res;
import haveno.core.monetary.Altcoin;
import haveno.core.monetary.CryptoMoney;
import haveno.core.monetary.Price;
import haveno.core.monetary.TraditionalMoney;
import haveno.core.offer.OfferPayload;
import haveno.core.offer.OpenOfferManager;
import haveno.core.provider.price.MarketPrice;
@ -63,7 +64,6 @@ import lombok.extern.slf4j.Slf4j;
import monero.common.MoneroError;
import monero.wallet.model.MoneroTxConfig;
import monero.wallet.model.MoneroTxWallet;
import org.bitcoinj.utils.Fiat;
import javax.annotation.Nullable;
import java.math.BigInteger;
@ -1092,9 +1092,9 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
if (marketPrice != null && marketPrice.isRecentExternalPriceAvailable()) {
double marketPriceAsDouble = marketPrice.getPrice();
try {
int precision = CurrencyUtil.isCryptoCurrency(currencyCode) ?
Altcoin.SMALLEST_UNIT_EXPONENT :
Fiat.SMALLEST_UNIT_EXPONENT;
int precision = CurrencyUtil.isTraditionalCurrency(currencyCode) ?
TraditionalMoney.SMALLEST_UNIT_EXPONENT :
CryptoMoney.SMALLEST_UNIT_EXPONENT;
double scaled = MathUtils.scaleUpByPowerOf10(marketPriceAsDouble, precision);
long roundedToLong = MathUtils.roundDoubleToLong(scaled);
return Price.valueOf(currencyCode, roundedToLong);

View file

@ -19,13 +19,13 @@ package haveno.core.trade;
import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.Res;
import haveno.core.monetary.Altcoin;
import haveno.core.monetary.CryptoMoney;
import haveno.core.monetary.TraditionalMoney;
import haveno.core.monetary.Volume;
import haveno.core.offer.OpenOffer;
import haveno.core.util.FormattingUtils;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.core.Monetary;
import org.bitcoinj.utils.Fiat;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -131,9 +131,9 @@ public class ClosedTradableFormatter {
String currencyCode = entry.getKey();
Monetary monetary;
if (CurrencyUtil.isCryptoCurrency(currencyCode)) {
monetary = Altcoin.valueOf(currencyCode, entry.getValue());
monetary = CryptoMoney.valueOf(currencyCode, entry.getValue());
} else {
monetary = Fiat.valueOf(currencyCode, entry.getValue());
monetary = TraditionalMoney.valueOf(currencyCode, entry.getValue());
}
return formatVolumeWithCode(new Volume(monetary));
}

View file

@ -22,9 +22,6 @@ import com.google.inject.Inject;
import haveno.common.crypto.KeyRing;
import haveno.common.persistence.PersistenceManager;
import haveno.common.proto.persistable.PersistedDataHost;
import haveno.common.util.Tuple2;
import haveno.core.monetary.Price;
import haveno.core.monetary.Volume;
import haveno.core.offer.Offer;
import haveno.core.offer.OpenOffer;
import haveno.core.provider.price.PriceFeedService;
@ -33,8 +30,6 @@ import haveno.core.user.Preferences;
import haveno.network.p2p.NodeAddress;
import javafx.collections.ObservableList;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.core.Coin;
import org.bitcoinj.utils.Fiat;
import java.math.BigInteger;
import java.time.Instant;
@ -49,7 +44,6 @@ import java.util.stream.Stream;
import static haveno.core.offer.OpenOffer.State.CANCELED;
import static haveno.core.trade.ClosedTradableUtil.castToTradeModel;
import static haveno.core.trade.ClosedTradableUtil.isOpenOffer;
import static haveno.core.util.AveragePriceUtil.getAveragePriceTuple;
/**
* Manages closed trades or offers.
@ -230,13 +224,6 @@ public class ClosedTradableManager implements PersistedDataHost {
return tradable instanceof MakerTrade || tradable.getOffer().isMyOffer(keyRing);
}
public Volume getBsqVolumeInUsdWithAveragePrice(Coin amount) {
Tuple2<Price, Price> tuple = getAveragePriceTuple(preferences, tradeStatisticsManager, 30);
Price usdPrice = tuple.first;
long value = Math.round(amount.value * usdPrice.getValue() / 100d);
return new Volume(Fiat.valueOf("USD", value));
}
private void requestPersistence() {
persistenceManager.requestPersistence();
}

View file

@ -32,7 +32,7 @@ import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
import static haveno.core.locale.CurrencyUtil.getCurrencyPair;
import static haveno.core.locale.CurrencyUtil.isFiatCurrency;
import static haveno.core.locale.CurrencyUtil.isTraditionalCurrency;
import static haveno.core.util.FormattingUtils.formatDurationAsWords;
import static java.lang.String.format;
@ -194,7 +194,7 @@ public class TradeUtil {
* @return String describing a trader's role
*/
public String getRole(boolean isBuyerMakerAndSellerTaker, boolean isMaker, String currencyCode) {
if (isFiatCurrency(currencyCode)) {
if (isTraditionalCurrency(currencyCode)) {
String baseCurrencyCode = Res.getBaseCurrencyCode();
if (isBuyerMakerAndSellerTaker)
return isMaker

View file

@ -34,7 +34,7 @@ public class MakerSetLockTime extends TradeTask {
try {
runInterceptHook();
// 10 days for altcoins, 20 days for other payment methods
// 10 days for cryptos, 20 days for other payment methods
// For regtest dev environment we use 5 blocks
int delay = Config.baseCurrencyNetwork().isTestnet() ?
5 :

View file

@ -44,7 +44,7 @@ public class VerifyPeersAccountAgeWitness extends TradeTask {
try {
runInterceptHook();
// only verify fiat offer
// only verify traditional offer
Offer offer = checkNotNull(trade.getOffer());
if (CurrencyUtil.isCryptoCurrency(offer.getCurrencyCode())) {
complete();

View file

@ -28,9 +28,12 @@ import haveno.common.util.CollectionUtils;
import haveno.common.util.ExtraDataMapValidator;
import haveno.common.util.JsonExclude;
import haveno.common.util.Utilities;
import haveno.core.monetary.Altcoin;
import haveno.core.monetary.AltcoinExchangeRate;
import haveno.core.locale.CurrencyUtil;
import haveno.core.monetary.CryptoMoney;
import haveno.core.monetary.CryptoExchangeRate;
import haveno.core.monetary.Price;
import haveno.core.monetary.TraditionalMoney;
import haveno.core.monetary.TraditionalExchangeRate;
import haveno.core.monetary.Volume;
import haveno.core.offer.Offer;
import haveno.core.offer.OfferPayload;
@ -45,8 +48,6 @@ import haveno.network.p2p.storage.payload.ProcessOncePersistableNetworkPayload;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.core.Coin;
import org.bitcoinj.utils.ExchangeRate;
import org.bitcoinj.utils.Fiat;
import javax.annotation.Nullable;
import java.time.LocalDateTime;
@ -194,7 +195,7 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl
private transient final Date dateObj;
@JsonExclude
private transient Volume volume = null; // Fiat or altcoin volume
private transient Volume volume = null; // Traditional or crypto volume
@JsonExclude
private transient LocalDateTime localDateTime;
@ -375,11 +376,12 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl
public Volume getTradeVolume() {
if (volume == null) {
if (getTradePrice().getMonetary() instanceof Altcoin) {
volume = new Volume(new AltcoinExchangeRate((Altcoin) getTradePrice().getMonetary()).coinToAltcoin(getTradeAmount()));
if (getTradePrice().getMonetary() instanceof CryptoMoney) {
volume = new Volume(new CryptoExchangeRate((CryptoMoney) getTradePrice().getMonetary()).coinToCrypto(getTradeAmount()));
} else {
Volume exactVolume = new Volume(new ExchangeRate((Fiat) getTradePrice().getMonetary()).coinToFiat(getTradeAmount()));
volume = VolumeUtil.getRoundedFiatVolume(exactVolume);
Volume exactVolume = new Volume(new TraditionalExchangeRate((TraditionalMoney) getTradePrice().getMonetary()).coinToTraditionalMoney(getTradeAmount()));
boolean isFiat = CurrencyUtil.isFiatCurrency(exactVolume.getCurrencyCode());
if (isFiat) volume = VolumeUtil.getRoundedFiatVolume(exactVolume);
}
}
return volume;

View file

@ -17,7 +17,6 @@
package haveno.core.trade.statistics;
import haveno.common.util.MathUtils;
import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.Res;
import haveno.core.monetary.Price;
@ -65,12 +64,10 @@ public final class TradeStatisticsForJson {
primaryMarketTradeVolume = getTradeAmount().longValueExact();
} else {
currencyPair = Res.getBaseCurrencyCode() + "/" + currency;
// we use precision 4 for fiat based price but on the markets api we use precision 8 so we scale up by 10000
primaryMarketTradePrice = (long) MathUtils.scaleUpByPowerOf10(tradePrice.getValue(), 4);
primaryMarketTradePrice = tradePrice.getValue();
primaryMarketTradeAmount = getTradeAmount().longValueExact();
// we use precision 4 for fiat but on the markets api we use precision 8 so we scale up by 10000
primaryMarketTradeVolume = getTradeVolume() != null ?
(long) MathUtils.scaleUpByPowerOf10(getTradeVolume().getValue(), 4) :
getTradeVolume().getValue() :
0;
}
} catch (Throwable t) {

View file

@ -119,10 +119,10 @@ public class TradeStatisticsManager {
jsonFileManager = new JsonFileManager(storageDir);
// We only dump once the currencies as they do not change during runtime
ArrayList<CurrencyTuple> fiatCurrencyList = CurrencyUtil.getAllSortedFiatCurrencies().stream()
ArrayList<CurrencyTuple> traditionalCurrencyList = CurrencyUtil.getAllSortedTraditionalCurrencies().stream()
.map(e -> new CurrencyTuple(e.getCode(), e.getName(), 8))
.collect(Collectors.toCollection(ArrayList::new));
jsonFileManager.writeToDiscThreaded(JsonUtil.objectToJson(fiatCurrencyList), "fiat_currency_list");
jsonFileManager.writeToDiscThreaded(JsonUtil.objectToJson(traditionalCurrencyList), "traditional_currency_list");
ArrayList<CurrencyTuple> cryptoCurrencyList = CurrencyUtil.getAllSortedCryptoCurrencies().stream()
.map(e -> new CurrencyTuple(e.getCode(), e.getName(), 8))
@ -136,11 +136,11 @@ public class TradeStatisticsManager {
.map(p -> p.getCurrency())
.collect(Collectors.toSet());
ArrayList<CurrencyTuple> activeFiatCurrencyList = fiatCurrencyList.stream()
ArrayList<CurrencyTuple> activeTraditionalCurrencyList = traditionalCurrencyList.stream()
.filter(e -> activeCurrencies.contains(e.code))
.map(e -> new CurrencyTuple(e.code, e.name, 8))
.collect(Collectors.toCollection(ArrayList::new));
jsonFileManager.writeToDiscThreaded(JsonUtil.objectToJson(activeFiatCurrencyList), "active_fiat_currency_list");
jsonFileManager.writeToDiscThreaded(JsonUtil.objectToJson(activeTraditionalCurrencyList), "active_traditional_currency_list");
ArrayList<CurrencyTuple> activeCryptoCurrencyList = cryptoCurrencyList.stream()
.filter(e -> activeCurrencies.contains(e.code))

View file

@ -26,7 +26,7 @@ import haveno.core.locale.Country;
import haveno.core.locale.CountryUtil;
import haveno.core.locale.CryptoCurrency;
import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.GlobalSettings;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.PaymentAccount;
@ -146,7 +146,7 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
@Getter
private final IntegerProperty cssThemeProperty = new SimpleIntegerProperty(prefPayload.getCssTheme());
private final ObservableList<FiatCurrency> fiatCurrenciesAsObservable = FXCollections.observableArrayList();
private final ObservableList<TraditionalCurrency> traditionalCurrenciesAsObservable = FXCollections.observableArrayList();
private final ObservableList<CryptoCurrency> cryptoCurrenciesAsObservable = FXCollections.observableArrayList();
private final ObservableList<TradeCurrency> tradeCurrenciesAsObservable = FXCollections.observableArrayList();
private final ObservableMap<String, Boolean> dontShowAgainMapAsObservable = FXCollections.observableHashMap();
@ -189,10 +189,10 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
requestPersistence();
});
fiatCurrenciesAsObservable.addListener((javafx.beans.Observable ov) -> {
prefPayload.getFiatCurrencies().clear();
prefPayload.getFiatCurrencies().addAll(fiatCurrenciesAsObservable);
prefPayload.getFiatCurrencies().sort(TradeCurrency::compareTo);
traditionalCurrenciesAsObservable.addListener((javafx.beans.Observable ov) -> {
prefPayload.getTraditionalCurrencies().clear();
prefPayload.getTraditionalCurrencies().addAll(traditionalCurrenciesAsObservable);
prefPayload.getTraditionalCurrencies().sort(TradeCurrency::compareTo);
requestPersistence();
});
cryptoCurrenciesAsObservable.addListener((javafx.beans.Observable ov) -> {
@ -202,7 +202,7 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
requestPersistence();
});
fiatCurrenciesAsObservable.addListener(this::updateTradeCurrencies);
traditionalCurrenciesAsObservable.addListener(this::updateTradeCurrencies);
cryptoCurrenciesAsObservable.addListener(this::updateTradeCurrencies);
}
@ -225,7 +225,7 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
GlobalSettings.setUseAnimations(prefPayload.isUseAnimations());
TradeCurrency preferredTradeCurrency = checkNotNull(prefPayload.getPreferredTradeCurrency(), "preferredTradeCurrency must not be null");
setPreferredTradeCurrency(preferredTradeCurrency);
setFiatCurrencies(prefPayload.getFiatCurrencies());
setFiatCurrencies(prefPayload.getTraditionalCurrencies());
setCryptoCurrencies(prefPayload.getCryptoCurrencies());
GlobalSettings.setDefaultTradeCurrency(preferredTradeCurrency);
@ -255,7 +255,7 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
}
prefPayload.setPreferredTradeCurrency(preferredTradeCurrency);
setFiatCurrencies(CurrencyUtil.getMainFiatCurrencies());
setFiatCurrencies(CurrencyUtil.getMainTraditionalCurrencies());
setCryptoCurrencies(CurrencyUtil.getMainCryptoCurrencies());
BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork();
@ -298,7 +298,7 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
getBlockChainExplorer().name.length() == 0) {
setBlockChainExplorer(btcExplorers.get(0));
}
tradeCurrenciesAsObservable.addAll(prefPayload.getFiatCurrencies());
tradeCurrenciesAsObservable.addAll(prefPayload.getTraditionalCurrencies());
tradeCurrenciesAsObservable.addAll(prefPayload.getCryptoCurrencies());
dontShowAgainMapAsObservable.putAll(getDontShowAgainMap());
@ -370,14 +370,14 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
this.cssThemeProperty.set(useDarkMode ? 1 : 0);
}
public void addFiatCurrency(FiatCurrency tradeCurrency) {
if (!fiatCurrenciesAsObservable.contains(tradeCurrency))
fiatCurrenciesAsObservable.add(tradeCurrency);
public void addTraditionalCurrency(TraditionalCurrency tradeCurrency) {
if (!traditionalCurrenciesAsObservable.contains(tradeCurrency))
traditionalCurrenciesAsObservable.add(tradeCurrency);
}
public void removeFiatCurrency(FiatCurrency tradeCurrency) {
public void removeTraditionalCurrency(TraditionalCurrency tradeCurrency) {
if (tradeCurrenciesAsObservable.size() > 1) {
fiatCurrenciesAsObservable.remove(tradeCurrency);
traditionalCurrenciesAsObservable.remove(tradeCurrency);
if (prefPayload.getPreferredTradeCurrency() != null &&
prefPayload.getPreferredTradeCurrency().equals(tradeCurrency))
@ -608,9 +608,9 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
requestPersistence();
}
private void setFiatCurrencies(List<FiatCurrency> currencies) {
fiatCurrenciesAsObservable.setAll(currencies.stream()
.map(fiatCurrency -> new FiatCurrency(fiatCurrency.getCurrency()))
private void setFiatCurrencies(List<TraditionalCurrency> currencies) {
traditionalCurrenciesAsObservable.setAll(currencies.stream()
.map(fiatCurrency -> new TraditionalCurrency(fiatCurrency.getCurrency()))
.distinct().collect(Collectors.toList()));
requestPersistence();
}
@ -745,8 +745,8 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
return useAnimationsProperty;
}
public ObservableList<FiatCurrency> getFiatCurrenciesAsObservable() {
return fiatCurrenciesAsObservable;
public ObservableList<TraditionalCurrency> getTraditionalCurrenciesAsObservable() {
return traditionalCurrenciesAsObservable;
}
public ObservableList<CryptoCurrency> getCryptoCurrenciesAsObservable() {
@ -909,7 +909,7 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
void setPayFeeInXmr(boolean payFeeInXmr);
void setFiatCurrencies(List<FiatCurrency> currencies);
void setFiatCurrencies(List<TraditionalCurrency> currencies);
void setCryptoCurrencies(List<CryptoCurrency> currencies);

View file

@ -23,7 +23,7 @@ import haveno.common.proto.ProtoUtil;
import haveno.common.proto.persistable.PersistableEnvelope;
import haveno.core.locale.Country;
import haveno.core.locale.CryptoCurrency;
import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TraditionalCurrency;
import haveno.core.locale.TradeCurrency;
import haveno.core.payment.PaymentAccount;
import haveno.core.proto.CoreProtoResolver;
@ -48,7 +48,7 @@ import static haveno.core.xmr.wallet.Restrictions.getDefaultBuyerSecurityDeposit
public final class PreferencesPayload implements PersistableEnvelope {
private String userLanguage;
private Country userCountry;
private List<FiatCurrency> fiatCurrencies = new ArrayList<>();
private List<TraditionalCurrency> traditionalCurrencies = new ArrayList<>();
private List<CryptoCurrency> cryptoCurrencies = new ArrayList<>();
private BlockChainExplorer blockChainExplorerMainNet;
private BlockChainExplorer blockChainExplorerTestNet;
@ -148,8 +148,8 @@ public final class PreferencesPayload implements PersistableEnvelope {
protobuf.PreferencesPayload.Builder builder = protobuf.PreferencesPayload.newBuilder()
.setUserLanguage(userLanguage)
.setUserCountry((protobuf.Country) userCountry.toProtoMessage())
.addAllFiatCurrencies(fiatCurrencies.stream()
.map(fiatCurrency -> ((protobuf.TradeCurrency) fiatCurrency.toProtoMessage()))
.addAllTraditionalCurrencies(traditionalCurrencies.stream()
.map(traditionalCurrency -> ((protobuf.TradeCurrency) traditionalCurrency.toProtoMessage()))
.collect(Collectors.toList()))
.addAllCryptoCurrencies(cryptoCurrencies.stream()
.map(cryptoCurrency -> ((protobuf.TradeCurrency) cryptoCurrency.toProtoMessage()))
@ -227,9 +227,9 @@ public final class PreferencesPayload implements PersistableEnvelope {
return new PreferencesPayload(
proto.getUserLanguage(),
Country.fromProto(userCountry),
proto.getFiatCurrenciesList().isEmpty() ? new ArrayList<>() :
new ArrayList<>(proto.getFiatCurrenciesList().stream()
.map(FiatCurrency::fromProto)
proto.getTraditionalCurrenciesList().isEmpty() ? new ArrayList<>() :
new ArrayList<>(proto.getTraditionalCurrenciesList().stream()
.map(TraditionalCurrency::fromProto)
.collect(Collectors.toList())),
proto.getCryptoCurrenciesList().isEmpty() ? new ArrayList<>() :
new ArrayList<>(proto.getCryptoCurrenciesList().stream()

View file

@ -19,12 +19,12 @@ package haveno.core.util;
import haveno.common.util.MathUtils;
import haveno.common.util.Tuple2;
import haveno.core.monetary.Altcoin;
import haveno.core.monetary.CryptoMoney;
import haveno.core.monetary.Price;
import haveno.core.monetary.TraditionalMoney;
import haveno.core.trade.statistics.TradeStatistics3;
import haveno.core.trade.statistics.TradeStatisticsManager;
import haveno.core.user.Preferences;
import org.bitcoinj.utils.Fiat;
import java.util.ArrayList;
import java.util.Calendar;
@ -87,7 +87,7 @@ public class AveragePriceUtil {
accumulatedAmount += item.getTradeAmount().getValue(); // Amount of BTC traded
}
long averagePrice;
double accumulatedAmountAsDouble = MathUtils.scaleUpByPowerOf10((double) accumulatedAmount, Altcoin.SMALLEST_UNIT_EXPONENT);
double accumulatedAmountAsDouble = MathUtils.scaleUpByPowerOf10((double) accumulatedAmount, CryptoMoney.SMALLEST_UNIT_EXPONENT);
averagePrice = accumulatedVolume > 0 ? MathUtils.roundDoubleToLong(accumulatedAmountAsDouble / accumulatedVolume) : 0;
return averagePrice;
@ -105,13 +105,13 @@ public class AveragePriceUtil {
usdBTCPrice = usdList.stream()
.filter(usd -> usd.getDateAsLong() > item.getDateAsLong())
.map(usd -> MathUtils.scaleDownByPowerOf10((double) usd.getTradePrice().getValue(),
Fiat.SMALLEST_UNIT_EXPONENT))
TraditionalMoney.SMALLEST_UNIT_EXPONENT))
.findFirst()
.orElse(usdBTCPrice);
var bsqAmount = MathUtils.scaleDownByPowerOf10((double) item.getTradeVolume().getValue(),
Altcoin.SMALLEST_UNIT_EXPONENT);
CryptoMoney.SMALLEST_UNIT_EXPONENT);
var btcAmount = MathUtils.scaleDownByPowerOf10((double) item.getTradeAmount().getValue(),
Altcoin.SMALLEST_UNIT_EXPONENT);
CryptoMoney.SMALLEST_UNIT_EXPONENT);
usdBsqList.add(new Tuple2<>(usdBTCPrice * btcAmount, bsqAmount));
}
long averagePrice;
@ -122,7 +122,7 @@ public class AveragePriceUtil {
.mapToDouble(item -> item.second)
.sum();
var averageAsDouble = bsqTraded > 0 ? usdTraded / bsqTraded : 0d;
var averageScaledUp = MathUtils.scaleUpByPowerOf10(averageAsDouble, Fiat.SMALLEST_UNIT_EXPONENT);
var averageScaledUp = MathUtils.scaleUpByPowerOf10(averageAsDouble, TraditionalMoney.SMALLEST_UNIT_EXPONENT);
averagePrice = bsqTraded > 0 ? MathUtils.roundDoubleToLong(averageScaledUp) : 0;
return averagePrice;

View file

@ -4,14 +4,14 @@ import haveno.common.util.MathUtils;
import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.GlobalSettings;
import haveno.core.locale.Res;
import haveno.core.monetary.Altcoin;
import haveno.core.monetary.CryptoMoney;
import haveno.core.monetary.Price;
import haveno.core.monetary.TraditionalMoney;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DurationFormatUtils;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Monetary;
import org.bitcoinj.utils.Fiat;
import org.bitcoinj.utils.MonetaryFormat;
import org.jetbrains.annotations.NotNull;
@ -29,8 +29,8 @@ public class FormattingUtils {
public final static String RANGE_SEPARATOR = " - ";
private static final MonetaryFormat fiatPriceFormat = new MonetaryFormat().shift(0).minDecimals(4).repeatOptionalDecimals(0, 0);
private static final MonetaryFormat altcoinFormat = new MonetaryFormat().shift(0).minDecimals(8).repeatOptionalDecimals(0, 0);
private static final MonetaryFormat traditionalPriceFormat = new MonetaryFormat().shift(0).minDecimals(4).repeatOptionalDecimals(0, 0);
private static final MonetaryFormat cryptoFormat = new MonetaryFormat().shift(0).minDecimals(CryptoMoney.SMALLEST_UNIT_EXPONENT).repeatOptionalDecimals(0, 0);
private static final DecimalFormat decimalFormat = new DecimalFormat("#.#");
public static String formatCoinWithCode(long value, MonetaryFormat coinFormat) {
@ -82,84 +82,84 @@ public class FormattingUtils {
return formattedCoin;
}
public static String formatFiat(Fiat fiat, MonetaryFormat format, boolean appendCurrencyCode) {
if (fiat != null) {
public static String formatTraditionalMoney(TraditionalMoney traditionalMoney, MonetaryFormat format, boolean appendCurrencyCode) {
if (traditionalMoney != null) {
try {
final String res = format.noCode().format(fiat).toString();
final String res = format.noCode().format(traditionalMoney).toString();
if (appendCurrencyCode)
return res + " " + fiat.getCurrencyCode();
return res + " " + traditionalMoney.getCurrencyCode();
else
return res;
} catch (Throwable t) {
log.warn("Exception at formatFiatWithCode: " + t.toString());
return Res.get("shared.na") + " " + fiat.getCurrencyCode();
log.warn("Exception at formatTraditionalMoneyWithCode: " + t.toString());
return Res.get("shared.na") + " " + traditionalMoney.getCurrencyCode();
}
} else {
return Res.get("shared.na");
}
}
private static String formatAltcoin(Altcoin altcoin, boolean appendCurrencyCode) {
if (altcoin != null) {
private static String formatCrypto(CryptoMoney crypto, boolean appendCurrencyCode) {
if (crypto != null) {
try {
String res = altcoinFormat.noCode().format(altcoin).toString();
String res = cryptoFormat.noCode().format(crypto).toString();
if (appendCurrencyCode)
return res + " " + altcoin.getCurrencyCode();
return res + " " + crypto.getCurrencyCode();
else
return res;
} catch (Throwable t) {
log.warn("Exception at formatAltcoin: " + t.toString());
return Res.get("shared.na") + " " + altcoin.getCurrencyCode();
log.warn("Exception at formatCrypto: " + t.toString());
return Res.get("shared.na") + " " + crypto.getCurrencyCode();
}
} else {
return Res.get("shared.na");
}
}
public static String formatAltcoinVolume(Altcoin altcoin, boolean appendCurrencyCode) {
if (altcoin != null) {
public static String formatCryptoVolume(CryptoMoney crypto, boolean appendCurrencyCode) {
if (crypto != null) {
try {
// TODO quick hack...
String res;
if (altcoin.getCurrencyCode().equals("BSQ"))
res = altcoinFormat.noCode().minDecimals(2).repeatOptionalDecimals(0, 0).format(altcoin).toString();
if (crypto.getCurrencyCode().equals("BSQ"))
res = cryptoFormat.noCode().minDecimals(2).repeatOptionalDecimals(0, 0).format(crypto).toString();
else
res = altcoinFormat.noCode().format(altcoin).toString();
res = cryptoFormat.noCode().format(crypto).toString();
if (appendCurrencyCode)
return res + " " + altcoin.getCurrencyCode();
return res + " " + crypto.getCurrencyCode();
else
return res;
} catch (Throwable t) {
log.warn("Exception at formatAltcoinVolume: " + t.toString());
return Res.get("shared.na") + " " + altcoin.getCurrencyCode();
log.warn("Exception at formatCryptoVolume: " + t.toString());
return Res.get("shared.na") + " " + crypto.getCurrencyCode();
}
} else {
return Res.get("shared.na");
}
}
public static String formatPrice(Price price, MonetaryFormat fiatPriceFormat, boolean appendCurrencyCode) {
public static String formatPrice(Price price, MonetaryFormat priceFormat, boolean appendCurrencyCode) {
if (price != null) {
Monetary monetary = price.getMonetary();
if (monetary instanceof Fiat)
return formatFiat((Fiat) monetary, fiatPriceFormat, appendCurrencyCode);
if (monetary instanceof TraditionalMoney)
return formatTraditionalMoney((TraditionalMoney) monetary, priceFormat, appendCurrencyCode);
else
return formatAltcoin((Altcoin) monetary, appendCurrencyCode);
return formatCrypto((CryptoMoney) monetary, appendCurrencyCode);
} else {
return Res.get("shared.na");
}
}
public static String formatPrice(Price price, boolean appendCurrencyCode) {
return formatPrice(price, fiatPriceFormat, appendCurrencyCode);
return formatPrice(price, getMonetaryFormat(price.getCurrencyCode()), appendCurrencyCode);
}
public static String formatPrice(Price price) {
return formatPrice(price, fiatPriceFormat, false);
return formatPrice(price, getMonetaryFormat(price.getCurrencyCode()), false);
}
public static String formatMarketPrice(double price, String currencyCode) {
if (CurrencyUtil.isFiatCurrency(currencyCode))
if (CurrencyUtil.isTraditionalCurrency(currencyCode))
return formatMarketPrice(price, 2);
else
return formatMarketPrice(price, 8);
@ -290,4 +290,8 @@ public class FormattingUtils {
}*/
return formattedNumber;
}
public static MonetaryFormat getMonetaryFormat(String currencyCode) {
return CurrencyUtil.isTraditionalCurrency(currencyCode) ? traditionalPriceFormat : cryptoFormat;
}
}

View file

@ -20,20 +20,20 @@ package haveno.core.util;
import haveno.common.util.MathUtils;
import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.Res;
import haveno.core.monetary.Altcoin;
import haveno.core.monetary.CryptoMoney;
import haveno.core.monetary.Price;
import haveno.core.monetary.TraditionalMoney;
import haveno.core.offer.Offer;
import haveno.core.offer.OfferDirection;
import haveno.core.provider.price.MarketPrice;
import haveno.core.provider.price.PriceFeedService;
import haveno.core.trade.statistics.TradeStatisticsManager;
import haveno.core.user.Preferences;
import haveno.core.util.validation.AltcoinValidator;
import haveno.core.util.validation.NonFiatPriceValidator;
import haveno.core.util.validation.FiatPriceValidator;
import haveno.core.util.validation.InputValidator;
import haveno.core.util.validation.MonetaryValidator;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.utils.Fiat;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -56,7 +56,7 @@ public class PriceUtil {
public static MonetaryValidator getPriceValidator(boolean isFiatCurrency) {
return isFiatCurrency ?
new FiatPriceValidator() :
new AltcoinValidator();
new NonFiatPriceValidator();
}
public static InputValidator.ValidationResult isTriggerPriceValid(String triggerPriceAsString,
@ -96,9 +96,9 @@ public class PriceUtil {
public static Price marketPriceToPrice(MarketPrice marketPrice) {
String currencyCode = marketPrice.getCurrencyCode();
double priceAsDouble = marketPrice.getPrice();
int precision = CurrencyUtil.isCryptoCurrency(currencyCode) ?
Altcoin.SMALLEST_UNIT_EXPONENT :
Fiat.SMALLEST_UNIT_EXPONENT;
int precision = CurrencyUtil.isTraditionalCurrency(currencyCode) ?
TraditionalMoney.SMALLEST_UNIT_EXPONENT :
CryptoMoney.SMALLEST_UNIT_EXPONENT;
double scaled = MathUtils.scaleUpByPowerOf10(priceAsDouble, precision);
long roundedToLong = MathUtils.roundDoubleToLong(scaled);
return Price.valueOf(currencyCode, roundedToLong);
@ -137,14 +137,14 @@ public class PriceUtil {
// If the offer did not use % price we calculate % from current market price
String currencyCode = offer.getCurrencyCode();
Price price = offer.getPrice();
int precision = CurrencyUtil.isCryptoCurrency(currencyCode) ?
Altcoin.SMALLEST_UNIT_EXPONENT :
Fiat.SMALLEST_UNIT_EXPONENT;
int precision = CurrencyUtil.isTraditionalCurrency(currencyCode) ?
TraditionalMoney.SMALLEST_UNIT_EXPONENT :
CryptoMoney.SMALLEST_UNIT_EXPONENT;
long priceAsLong = checkNotNull(price).getValue();
double scaled = MathUtils.scaleDownByPowerOf10(priceAsLong, precision);
double value;
if (direction == OfferDirection.SELL) {
if (CurrencyUtil.isFiatCurrency(currencyCode)) {
if (CurrencyUtil.isTraditionalCurrency(currencyCode)) {
if (marketPrice == 0) {
return Optional.empty();
}
@ -156,7 +156,7 @@ public class PriceUtil {
value = scaled / marketPrice - 1;
}
} else {
if (CurrencyUtil.isFiatCurrency(currencyCode)) {
if (CurrencyUtil.isTraditionalCurrency(currencyCode)) {
if (marketPrice == 1) {
return Optional.empty();
}
@ -202,7 +202,7 @@ public class PriceUtil {
}
public static int getMarketPricePrecision(String currencyCode) {
return CurrencyUtil.isCryptoCurrency(currencyCode) ?
Altcoin.SMALLEST_UNIT_EXPONENT : Fiat.SMALLEST_UNIT_EXPONENT;
return CurrencyUtil.isTraditionalCurrency(currencyCode) ?
TraditionalMoney.SMALLEST_UNIT_EXPONENT : CryptoMoney.SMALLEST_UNIT_EXPONENT;
}
}

View file

@ -17,16 +17,17 @@
package haveno.core.util;
import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.Res;
import haveno.core.monetary.Altcoin;
import haveno.core.monetary.AltcoinExchangeRate;
import haveno.core.monetary.CryptoMoney;
import haveno.core.monetary.CryptoExchangeRate;
import haveno.core.monetary.Price;
import haveno.core.monetary.TraditionalMoney;
import haveno.core.monetary.TraditionalExchangeRate;
import haveno.core.monetary.Volume;
import haveno.core.offer.Offer;
import haveno.core.trade.HavenoUtils;
import org.bitcoinj.core.Monetary;
import org.bitcoinj.utils.ExchangeRate;
import org.bitcoinj.utils.Fiat;
import org.bitcoinj.utils.MonetaryFormat;
import java.math.BigInteger;
@ -37,6 +38,7 @@ import java.util.Locale;
public class VolumeUtil {
private static final MonetaryFormat FIAT_VOLUME_FORMAT = new MonetaryFormat().shift(0).minDecimals(0).repeatOptionalDecimals(0, 0);
private static final MonetaryFormat TRADITIONAL_VOLUME_FORMAT = new MonetaryFormat().shift(0).minDecimals(4).repeatOptionalDecimals(0, 0);
public static Volume getRoundedFiatVolume(Volume volumeByAmount) {
// We want to get rounded to 1 unit of the fiat currency, e.g. 1 EUR.
@ -44,7 +46,7 @@ public class VolumeUtil {
}
public static Volume getAdjustedVolumeForHalCash(Volume volumeByAmount) {
// EUR has precision 4 and we want multiple of 10 so we divide by 100000 then
// EUR has precision 8 and we want multiple of 10 so we divide by 1000000000 then
// round and multiply with 10
return getAdjustedFiatVolume(volumeByAmount, 10);
}
@ -57,9 +59,9 @@ public class VolumeUtil {
* @return The adjusted Fiat volume
*/
public static Volume getAdjustedFiatVolume(Volume volumeByAmount, int factor) {
// Fiat currencies use precision 4 and we want multiple of factor so we divide by 10000 * factor then
// Fiat currencies use precision 8 and we want multiple of factor so we divide by 100000000 * factor then
// round and multiply with factor
long roundedVolume = Math.round((double) volumeByAmount.getValue() / (10000d * factor)) * factor;
long roundedVolume = Math.round((double) volumeByAmount.getValue() / (100000000d * factor)) * factor;
// Smallest allowed volume is factor (e.g. 10 EUR or 1 EUR,...)
roundedVolume = Math.max(factor, roundedVolume);
return Volume.parse(String.valueOf(roundedVolume), volumeByAmount.getCurrencyCode());
@ -67,10 +69,10 @@ public class VolumeUtil {
public static Volume getVolume(BigInteger amount, Price price) {
// TODO: conversion to Coin loses precision
if (price.getMonetary() instanceof Altcoin) {
return new Volume(new AltcoinExchangeRate((Altcoin) price.getMonetary()).coinToAltcoin(HavenoUtils.atomicUnitsToCoin(amount)));
if (price.getMonetary() instanceof CryptoMoney) {
return new Volume(new CryptoExchangeRate((CryptoMoney) price.getMonetary()).coinToCrypto(HavenoUtils.atomicUnitsToCoin(amount)));
} else {
return new Volume(new ExchangeRate((Fiat) price.getMonetary()).coinToFiat(HavenoUtils.atomicUnitsToCoin(amount)));
return new Volume(new TraditionalExchangeRate((TraditionalMoney) price.getMonetary()).coinToTraditionalMoney(HavenoUtils.atomicUnitsToCoin(amount)));
}
}
@ -110,16 +112,16 @@ public class VolumeUtil {
}
public static String formatVolume(Volume volume) {
return formatVolume(volume, FIAT_VOLUME_FORMAT, false);
return formatVolume(volume, getMonetaryFormat(volume.getCurrencyCode()), false);
}
private static String formatVolume(Volume volume, MonetaryFormat fiatVolumeFormat, boolean appendCurrencyCode) {
if (volume != null) {
Monetary monetary = volume.getMonetary();
if (monetary instanceof Fiat)
return FormattingUtils.formatFiat((Fiat) monetary, fiatVolumeFormat, appendCurrencyCode);
if (monetary instanceof TraditionalMoney)
return FormattingUtils.formatTraditionalMoney((TraditionalMoney) monetary, fiatVolumeFormat, appendCurrencyCode);
else
return FormattingUtils.formatAltcoinVolume((Altcoin) monetary, appendCurrencyCode);
return FormattingUtils.formatCryptoVolume((CryptoMoney) monetary, appendCurrencyCode);
} else {
return "";
}
@ -130,11 +132,11 @@ public class VolumeUtil {
}
public static String formatVolume(Volume volume, boolean appendCode) {
return formatVolume(volume, FIAT_VOLUME_FORMAT, appendCode);
return formatVolume(volume, getMonetaryFormat(volume.getCurrencyCode()), appendCode);
}
public static String formatAverageVolumeWithCode(Volume volume) {
return formatVolume(volume, FIAT_VOLUME_FORMAT.minDecimals(2), true);
return formatVolume(volume, getMonetaryFormat(volume.getCurrencyCode()).minDecimals(2), true);
}
public static String formatVolumeLabel(String currencyCode) {
@ -145,4 +147,8 @@ public class VolumeUtil {
return Res.get("formatter.formatVolumeLabel",
currencyCode, postFix);
}
private static MonetaryFormat getMonetaryFormat(String currencyCode) {
return CurrencyUtil.isFiatCurrency(currencyCode) ? FIAT_VOLUME_FORMAT : TRADITIONAL_VOLUME_FORMAT;
}
}

View file

@ -54,7 +54,7 @@ public abstract class MonetaryValidator extends NumberValidator {
protected ValidationResult validateIfNotExceedsMinValue(String input) {
double d = Double.parseDouble(input);
if (d < getMinValue())
return new ValidationResult(false, Res.get("validation.fiat.tooSmall"));
return new ValidationResult(false, Res.get("validation.traditional.tooSmall"));
else
return new ValidationResult(true);
}
@ -62,7 +62,7 @@ public abstract class MonetaryValidator extends NumberValidator {
protected ValidationResult validateIfNotExceedsMaxValue(String input) {
double d = Double.parseDouble(input);
if (d > getMaxValue())
return new ValidationResult(false, Res.get("validation.fiat.tooLarge"));
return new ValidationResult(false, Res.get("validation.traditional.tooLarge"));
else
return new ValidationResult(true);
}

View file

@ -19,7 +19,7 @@ package haveno.core.util.validation;
import javax.inject.Inject;
public class AltcoinValidator extends MonetaryValidator {
public class NonFiatPriceValidator extends MonetaryValidator {
@Override
public double getMinValue() {
return 0.00000001;
@ -27,11 +27,11 @@ public class AltcoinValidator extends MonetaryValidator {
@Override
public double getMaxValue() {
// hard to say what the max value should be with altcoins
// hard to say what the max value should be with cryptos
return 100_000_000;
}
@Inject
public AltcoinValidator() {
public NonFiatPriceValidator() {
}
}

View file

@ -88,7 +88,7 @@ public class Restrictions {
}
public static int getLockTime(boolean isAsset) {
// 10 days for altcoins, 20 days for other payment methods
// 10 days for cryptos, 20 days for other payment methods
return isAsset ? 144 * 10 : 144 * 20;
}
}