Add support for customized currency lists

This commit is contained in:
Manfred Karrer 2016-03-01 20:40:15 +01:00
parent 59ad7653b5
commit 2f0f58c478
33 changed files with 769 additions and 357 deletions

View file

@ -33,7 +33,7 @@ public class PoloniexPriceProvider implements PriceProvider {
String response = httpClient.requestWithGET("?command=returnTicker");
LinkedTreeMap<String, Object> treeMap = new Gson().fromJson(response, LinkedTreeMap.class);
Map<String, String> temp = new HashMap<>();
Set<String> supported = CurrencyUtil.getSortedCryptoCurrencies().stream()
Set<String> supported = CurrencyUtil.getAllSortedCryptoCurrencies().stream()
.map(TradeCurrency::getCode)
.collect(Collectors.toSet());
treeMap.entrySet().stream().forEach(e -> {

View file

@ -126,7 +126,7 @@ public class CountryUtil {
selectedRegion != null && country != null && selectedRegion.equals(country.region)));
}
private static List<Country> getAllCountries() {
public static List<Country> getAllCountries() {
final List<Country> allCountries = new ArrayList<>();
for (final Locale locale : getAllCountryLocales()) {
String regionCode = getRegionCode(locale.getCountry());

View file

@ -27,14 +27,96 @@ import java.util.stream.Collectors;
public class CurrencyUtil {
private static final Logger log = LoggerFactory.getLogger(CurrencyUtil.class);
private static final List<TradeCurrency> allSortedCurrencies = createAllSortedCurrenciesList();
private static final List<FiatCurrency> allSortedFiatCurrencies = createAllSortedFiatCurrenciesList();
public static List<TradeCurrency> getAllSortedCurrencies() {
return allSortedCurrencies;
private static List<FiatCurrency> createAllSortedFiatCurrenciesList() {
Set<FiatCurrency> set = CountryUtil.getAllCountries().stream()
.map(country -> getCurrencyByCountryCode(country.code))
.collect(Collectors.toSet());
List<FiatCurrency> list = new ArrayList<>(set);
list.sort(TradeCurrency::compareTo);
return list;
}
// We add all currencies supported by payment methods
private static List<TradeCurrency> createAllSortedCurrenciesList() {
public static List<FiatCurrency> getAllSortedFiatCurrencies() {
return allSortedFiatCurrencies;
}
public static List<FiatCurrency> getAllMainFiatCurrencies() {
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"));
TradeCurrency defaultTradeCurrency = getDefaultTradeCurrency();
FiatCurrency defaultFiatCurrency = defaultTradeCurrency instanceof FiatCurrency ? (FiatCurrency) defaultTradeCurrency : null;
if (defaultFiatCurrency != null && list.contains(defaultFiatCurrency)) {
list.remove(defaultTradeCurrency);
list.add(0, defaultFiatCurrency);
}
return list;
}
private static final List<CryptoCurrency> allSortedCryptoCurrencies = createAllSortedCryptoCurrenciesList();
public static List<CryptoCurrency> getAllSortedCryptoCurrencies() {
return allSortedCryptoCurrencies;
}
public static List<CryptoCurrency> getMainCryptoCurrencies() {
final List<CryptoCurrency> result = new ArrayList<>();
result.add(new CryptoCurrency("ETH", "Ethereum"));
result.add(new CryptoCurrency("LTC", "Litecoin"));
result.add(new CryptoCurrency("NMC", "Namecoin"));
result.add(new CryptoCurrency("DASH", "Dash"));
result.add(new CryptoCurrency("NBT", "NuBits"));
result.add(new CryptoCurrency("DOGE", "Dogecoin"));
result.add(new CryptoCurrency("NXT", "Nxt"));
result.add(new CryptoCurrency("BTS", "BitShares"));
return result;
}
public static List<CryptoCurrency> createAllSortedCryptoCurrenciesList() {
final List<CryptoCurrency> result = new ArrayList<>();
result.add(new CryptoCurrency("ETH", "Ethereum"));
result.add(new CryptoCurrency("LTC", "Litecoin"));
result.add(new CryptoCurrency("NMC", "Namecoin"));
result.add(new CryptoCurrency("DASH", "Dash"));
result.add(new CryptoCurrency("NBT", "NuBits"));
result.add(new CryptoCurrency("NSR", "NuShares"));
result.add(new CryptoCurrency("PPC", "Peercoin"));
result.add(new CryptoCurrency("XPM", "Primecoin"));
result.add(new CryptoCurrency("SC", "Siacoin"));
result.add(new CryptoCurrency("SJCX", "StorjcoinX"));
result.add(new CryptoCurrency("GEMZ", "Gemz"));
result.add(new CryptoCurrency("DOGE", "Dogecoin"));
result.add(new CryptoCurrency("BLK", "Blackcoin"));
result.add(new CryptoCurrency("FCT", "Factom"));
result.add(new CryptoCurrency("NXT", "Nxt"));
result.add(new CryptoCurrency("BTS", "BitShares"));
result.add(new CryptoCurrency("XCP", "Counterparty"));
result.add(new CryptoCurrency("XRP", "Ripple"));
// Unfortunately we cannot support CryptoNote coins yet as there is no way to proof the transaction. Payment ID helps only locate the tx but the
// arbitrator cannot see if the receiving key matches the receivers address. They might add support for exposing the tx key, but that is not
// implemented yet. To use the view key (also not available in GUI wallets) would reveal the complete wallet history for incoming payments, which is
// not acceptable from privacy point of view.
// result.add(new CryptoCurrency("XMR", "Monero"));
// result.add(new CryptoCurrency("BCN", "Bytecoin"));
return result;
}
/* // We add all currencies supported by payment methods
// TODO not used anymore
private static List<TradeCurrency> createAllSortedCurrenciesListDerivedFromPaymentMethods() {
Set<TradeCurrency> set = new HashSet<>();
// Sepa: EUR at first place
@ -52,11 +134,11 @@ public class CurrencyUtil {
// Swish: it is already added by SEPA
// for printing out all codes
/* String res;
*//* String res;
result.stream().forEach(e -> {
res += "list.add(new FiatCurrency(\""+e.code+"\"));\n";
});
log.debug(res);*/
log.debug(res);*//*
List<TradeCurrency> list = getAllManuallySortedFiatCurrencies();
@ -84,9 +166,10 @@ public class CurrencyUtil {
getSortedCryptoCurrencies().stream().forEach(list::add);
return list;
}
}*/
private static List<TradeCurrency> getAllManuallySortedFiatCurrencies() {
/* private static List<TradeCurrency> getAllManuallySortedFiatCurrencies() {
List<TradeCurrency> list = new ArrayList<>();
list.add(new FiatCurrency("EUR"));
list.add(new FiatCurrency("USD"));
@ -116,7 +199,7 @@ public class CurrencyUtil {
list.add(new FiatCurrency("RON"));
return list;
}
}*/
/**
* @return Sorted list of SEPA currencies with EUR as first item
@ -160,41 +243,11 @@ public class CurrencyUtil {
@SuppressWarnings("WeakerAccess")
public static boolean isCryptoCurrency(String currencyCode) {
return getSortedCryptoCurrencies().stream().filter(e -> e.getCode().equals(currencyCode)).findAny().isPresent();
return getAllSortedCryptoCurrencies().stream().filter(e -> e.getCode().equals(currencyCode)).findAny().isPresent();
}
public static Optional<TradeCurrency> getCryptoCurrency(String currencyCode) {
return getSortedCryptoCurrencies().stream().filter(e -> e.getCode().equals(currencyCode)).findAny();
}
public static List<TradeCurrency> getSortedCryptoCurrencies() {
final List<TradeCurrency> result = new ArrayList<>();
result.add(new CryptoCurrency("ETH", "Ethereum"));
result.add(new CryptoCurrency("LTC", "Litecoin"));
result.add(new CryptoCurrency("NMC", "Namecoin"));
result.add(new CryptoCurrency("DASH", "Dash"));
result.add(new CryptoCurrency("NBT", "NuBits"));
result.add(new CryptoCurrency("NSR", "NuShares"));
result.add(new CryptoCurrency("PPC", "Peercoin"));
result.add(new CryptoCurrency("XPM", "Primecoin"));
result.add(new CryptoCurrency("SC", "Siacoin"));
result.add(new CryptoCurrency("SJCX", "StorjcoinX"));
result.add(new CryptoCurrency("GEMZ", "Gemz"));
result.add(new CryptoCurrency("DOGE", "Dogecoin"));
result.add(new CryptoCurrency("BLK", "Blackcoin"));
result.add(new CryptoCurrency("FCT", "Factom"));
result.add(new CryptoCurrency("NXT", "Nxt"));
result.add(new CryptoCurrency("BTS", "BitShares"));
result.add(new CryptoCurrency("XCP", "Counterparty"));
result.add(new CryptoCurrency("XRP", "Ripple"));
// Unfortunately we cannot support CryptoNote coins yet as there is no way to proof the transaction. Payment ID helps only locate the tx but the
// arbitrator cannot see if the receiving key matches the receivers address. They might add support for exposing the tx key, but that is not
// implemented yet. To use the view key (also not available in GUI wallets) would reveal the complete wallet history for incoming payments, which is
// not acceptable from privacy point of view.
// result.add(new CryptoCurrency("XMR", "Monero"));
// result.add(new CryptoCurrency("BCN", "Bytecoin"));
return result;
public static Optional<CryptoCurrency> getCryptoCurrency(String currencyCode) {
return getAllSortedCryptoCurrencies().stream().filter(e -> e.getCode().equals(currencyCode)).findAny();
}
public static boolean isCryptoNoteCoin(String currencyCode) {
@ -206,6 +259,9 @@ public class CurrencyUtil {
if (!countryCode.equals("LT"))
return new FiatCurrency(Currency.getInstance(new Locale(LanguageUtil.getDefaultLanguage(), countryCode)).getCurrencyCode());
else {
if (!Currency.getInstance(new Locale(LanguageUtil.getDefaultLanguage(), countryCode)).getCurrencyCode().equals("EUR"))
log.error("wrong currency reported for LT");
return new FiatCurrency("EUR");
}
}
@ -216,7 +272,7 @@ public class CurrencyUtil {
return Currency.getInstance(currencyCode).getDisplayName(Preferences.getDefaultLocale());
} catch (Throwable t) {
// Seems that it is a cryptocurrency
return getSortedCryptoCurrencies().stream().filter(e -> e.getCode().equals(currencyCode)).findFirst().get().getName();
return getAllSortedCryptoCurrencies().stream().filter(e -> e.getCode().equals(currencyCode)).findFirst().get().getName();
}
}

View file

@ -19,8 +19,9 @@ package io.bitsquare.locale;
import io.bitsquare.app.Version;
import io.bitsquare.common.persistance.Persistable;
import org.jetbrains.annotations.NotNull;
public abstract class TradeCurrency implements Persistable {
public abstract class TradeCurrency implements Persistable, Comparable<TradeCurrency> {
// That object is saved to disc. We need to take care of changes to not break deserialization.
private static final long serialVersionUID = Version.LOCAL_DB_VERSION;
@ -65,6 +66,11 @@ public abstract class TradeCurrency implements Persistable {
return code + " (" + name + ")";
}
@Override
public int compareTo(@NotNull TradeCurrency other) {
return this.getName().compareTo(other.getName());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View file

@ -29,12 +29,12 @@ public abstract class BankAccountContractData extends PaymentAccountContractData
private static final Logger log = LoggerFactory.getLogger(BankAccountContractData.class);
private String holderName;
private String bankName;
private String bankId;
private String branchId;
private String accountNr;
private String holderId;
protected String holderName;
protected String bankName;
protected String bankId;
protected String branchId;
protected String accountNr;
protected String holderId;
public BankAccountContractData(String paymentMethod, String id, int maxTradePeriod) {
super(paymentMethod, id, maxTradePeriod);

View file

@ -31,4 +31,8 @@ public final class SameBankAccount extends PaymentAccount {
protected PaymentAccountContractData setContractData() {
return new SameBankAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod());
}
public String getAcceptedBank() {
return ((SameBankAccountContractData) contractData).getBankName();
}
}

View file

@ -19,6 +19,8 @@ package io.bitsquare.payment;
import io.bitsquare.app.Version;
import java.util.ArrayList;
public final class SpecificBankAccount extends PaymentAccount {
// That object is saved to disc. We need to take care of changes to not break deserialization.
private static final long serialVersionUID = Version.LOCAL_DB_VERSION;
@ -31,4 +33,8 @@ public final class SpecificBankAccount extends PaymentAccount {
protected PaymentAccountContractData setContractData() {
return new SpecificBanksAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod());
}
public ArrayList<String> getAcceptedBanks() {
return ((SpecificBanksAccountContractData) contractData).getAcceptedBanks();
}
}

View file

@ -17,7 +17,10 @@
package io.bitsquare.payment;
import com.google.common.base.Joiner;
import io.bitsquare.app.Version;
import io.bitsquare.locale.BankUtil;
import io.bitsquare.locale.CountryUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -56,4 +59,17 @@ public final class SpecificBanksAccountContractData extends BankAccountContractD
public String getPaymentDetails() {
return "Transfers with specific banks - " + getPaymentDetailsForTradePopup().replace("\n", ", ");
}
@Override
public String getPaymentDetailsForTradePopup() {
String holderIdString = BankUtil.requiresHolderId(countryCode) ? (getHolderIdLabel() + ": " + holderId + "\n") : "";
return "Holder name: " + holderName + "\n" +
holderIdString +
"Bank name: " + bankName + "\n" +
"Bank Nr.: " + bankId + "\n" +
"Branch Nr.: " + branchId + "\n" +
"Account Nr.: " + accountNr + "\n" +
"Accepted banks: " + Joiner.on(", ").join(acceptedBanks) + "\n" +
"Country of bank: " + CountryUtil.getNameAndCode(getCountryCode());
}
}

View file

@ -102,6 +102,8 @@ public final class Offer implements StoragePayload, RequiresOwnerIsOnlinePayload
@Nullable
private final ArrayList<String> acceptedCountryCodes;
@Nullable
private final ArrayList<String> acceptedBanks;
private final ArrayList<NodeAddress> arbitratorNodeAddresses;
// Mutable property. Has to be set before offer is save in P2P network as it changes the objects hash!
@ -136,7 +138,8 @@ public final class Offer implements StoragePayload, RequiresOwnerIsOnlinePayload
@Nullable Country paymentMethodCountry,
String offererPaymentAccountId,
ArrayList<NodeAddress> arbitratorNodeAddresses,
@Nullable ArrayList<String> acceptedCountryCodes) {
@Nullable ArrayList<String> acceptedCountryCodes,
@Nullable ArrayList<String> acceptedBanks) {
this.id = id;
this.offererNodeAddress = offererNodeAddress;
this.pubKeyRing = pubKeyRing;
@ -150,6 +153,7 @@ public final class Offer implements StoragePayload, RequiresOwnerIsOnlinePayload
this.offererPaymentAccountId = offererPaymentAccountId;
this.arbitratorNodeAddresses = arbitratorNodeAddresses;
this.acceptedCountryCodes = acceptedCountryCodes;
this.acceptedBanks = acceptedBanks;
protocolVersion = Version.TRADE_PROTOCOL_VERSION;
@ -336,6 +340,11 @@ public final class Offer implements StoragePayload, RequiresOwnerIsOnlinePayload
return acceptedCountryCodes;
}
@Nullable
public List<String> getAcceptedBanks() {
return acceptedBanks;
}
public String getOfferFeePaymentTxID() {
return offerFeePaymentTxID;
}
@ -389,6 +398,8 @@ public final class Offer implements StoragePayload, RequiresOwnerIsOnlinePayload
return false;
if (acceptedCountryCodes != null ? !acceptedCountryCodes.equals(offer.acceptedCountryCodes) : offer.acceptedCountryCodes != null)
return false;
if (acceptedBanks != null ? !acceptedBanks.equals(offer.acceptedBanks) : offer.acceptedBanks != null)
return false;
if (arbitratorNodeAddresses != null ? !arbitratorNodeAddresses.equals(offer.arbitratorNodeAddresses) : offer.arbitratorNodeAddresses != null)
return false;
return !(offerFeePaymentTxID != null ? !offerFeePaymentTxID.equals(offer.offerFeePaymentTxID) : offer.offerFeePaymentTxID != null);
@ -410,6 +421,7 @@ public final class Offer implements StoragePayload, RequiresOwnerIsOnlinePayload
result = 31 * result + (paymentMethodCountryCode != null ? paymentMethodCountryCode.hashCode() : 0);
result = 31 * result + (offererPaymentAccountId != null ? offererPaymentAccountId.hashCode() : 0);
result = 31 * result + (acceptedCountryCodes != null ? acceptedCountryCodes.hashCode() : 0);
result = 31 * result + (acceptedBanks != null ? acceptedBanks.hashCode() : 0);
result = 31 * result + (arbitratorNodeAddresses != null ? arbitratorNodeAddresses.hashCode() : 0);
result = 31 * result + (offerFeePaymentTxID != null ? offerFeePaymentTxID.hashCode() : 0);
return result;
@ -431,6 +443,7 @@ public final class Offer implements StoragePayload, RequiresOwnerIsOnlinePayload
"\n\tpaymentMethodCountryCode='" + paymentMethodCountryCode + '\'' +
"\n\toffererPaymentAccountId='" + offererPaymentAccountId + '\'' +
"\n\tacceptedCountryCodes=" + acceptedCountryCodes +
"\n\tacceptedBanks=" + acceptedBanks +
"\n\tarbitratorAddresses=" + arbitratorNodeAddresses +
"\n\tofferFeePaymentTxID='" + offerFeePaymentTxID + '\'' +
"\n\tstate=" + state +

View file

@ -22,10 +22,7 @@ import io.bitsquare.app.Version;
import io.bitsquare.btc.BitcoinNetwork;
import io.bitsquare.btc.FeePolicy;
import io.bitsquare.common.persistance.Persistable;
import io.bitsquare.locale.CountryUtil;
import io.bitsquare.locale.CurrencyUtil;
import io.bitsquare.locale.FiatCurrency;
import io.bitsquare.locale.TradeCurrency;
import io.bitsquare.locale.*;
import io.bitsquare.storage.Storage;
import javafx.beans.Observable;
import javafx.beans.property.BooleanProperty;
@ -33,6 +30,7 @@ import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;
@ -94,7 +92,8 @@ public final class Preferences implements Persistable {
private String btcDenomination = MonetaryFormat.CODE_BTC;
private boolean useAnimations = true;
private boolean useEffects = true;
private final ArrayList<TradeCurrency> tradeCurrencies;
private final ArrayList<FiatCurrency> fiatCurrencies;
private final ArrayList<CryptoCurrency> cryptoCurrencies;
private BlockChainExplorer blockChainExplorerMainNet;
private BlockChainExplorer blockChainExplorerTestNet;
private boolean showNotifications = true;
@ -112,6 +111,8 @@ public final class Preferences implements Persistable {
transient private final StringProperty btcDenominationProperty = new SimpleStringProperty(btcDenomination);
transient private final BooleanProperty useAnimationsProperty = new SimpleBooleanProperty(useAnimations);
transient private final BooleanProperty useEffectsProperty = new SimpleBooleanProperty(useEffects);
transient private final ObservableList<FiatCurrency> fiatCurrenciesAsObservable = FXCollections.observableArrayList();
transient private final ObservableList<CryptoCurrency> cryptoCurrenciesAsObservable = FXCollections.observableArrayList();
transient private final ObservableList<TradeCurrency> tradeCurrenciesAsObservable = FXCollections.observableArrayList();
@ -130,8 +131,12 @@ public final class Preferences implements Persistable {
setBtcDenomination(persisted.btcDenomination);
setUseAnimations(persisted.useAnimations);
setUseEffects(persisted.useEffects);
setTradeCurrencies(persisted.tradeCurrencies);
tradeCurrencies = new ArrayList<>(tradeCurrenciesAsObservable);
setFiatCurrencies(persisted.fiatCurrencies);
fiatCurrencies = new ArrayList<>(fiatCurrenciesAsObservable);
setCryptoCurrencies(persisted.cryptoCurrencies);
cryptoCurrencies = new ArrayList<>(cryptoCurrenciesAsObservable);
setBlockChainExplorerTestNet(persisted.getBlockChainExplorerTestNet());
setBlockChainExplorerMainNet(persisted.getBlockChainExplorerMainNet());
@ -160,8 +165,12 @@ public final class Preferences implements Persistable {
// leave default value
}
} else {
setTradeCurrencies(CurrencyUtil.getAllSortedCurrencies());
tradeCurrencies = new ArrayList<>(tradeCurrenciesAsObservable);
setFiatCurrencies(CurrencyUtil.getAllMainFiatCurrencies());
fiatCurrencies = new ArrayList<>(fiatCurrenciesAsObservable);
setCryptoCurrencies(CurrencyUtil.getMainCryptoCurrencies());
cryptoCurrencies = new ArrayList<>(cryptoCurrenciesAsObservable);
setBlockChainExplorerTestNet(blockChainExplorersTestNet.get(0));
setBlockChainExplorerMainNet(blockChainExplorersMainNet.get(0));
@ -193,11 +202,21 @@ public final class Preferences implements Persistable {
useEffects = useEffectsProperty.get();
storage.queueUpForSave(2000);
});
tradeCurrenciesAsObservable.addListener((Observable ov) -> {
tradeCurrencies.clear();
tradeCurrencies.addAll(tradeCurrenciesAsObservable);
fiatCurrenciesAsObservable.addListener((Observable ov) -> {
fiatCurrencies.clear();
fiatCurrencies.addAll(fiatCurrenciesAsObservable);
storage.queueUpForSave();
});
cryptoCurrenciesAsObservable.addListener((Observable ov) -> {
cryptoCurrencies.clear();
cryptoCurrencies.addAll(cryptoCurrenciesAsObservable);
storage.queueUpForSave();
});
fiatCurrenciesAsObservable.addListener((ListChangeListener<FiatCurrency>) this::updateTradeCurrencies);
cryptoCurrenciesAsObservable.addListener((ListChangeListener<CryptoCurrency>) this::updateTradeCurrencies);
tradeCurrenciesAsObservable.addAll(fiatCurrencies);
tradeCurrenciesAsObservable.addAll(cryptoCurrencies);
}
public void dontShowAgain(String id) {
@ -205,6 +224,14 @@ public final class Preferences implements Persistable {
storage.queueUpForSave(2000);
}
private void updateTradeCurrencies(ListChangeListener.Change<? extends TradeCurrency> change) {
change.next();
if (change.wasAdded() && change.getAddedSize() == 1)
tradeCurrenciesAsObservable.add(change.getAddedSubList().get(0));
else if (change.wasRemoved() && change.getRemovedSize() == 1)
tradeCurrenciesAsObservable.remove(change.getRemoved().get(0));
}
///////////////////////////////////////////////////////////////////////////////////////////
// Setter
@ -231,8 +258,46 @@ public final class Preferences implements Persistable {
// We don't store the bitcoinNetwork locally as BitcoinNetwork is not serializable!
}
private void setTradeCurrencies(List<TradeCurrency> tradeCurrencies) {
tradeCurrenciesAsObservable.setAll(tradeCurrencies);
private void setFiatCurrencies(List<FiatCurrency> currencies) {
fiatCurrenciesAsObservable.setAll(currencies);
}
private void setCryptoCurrencies(List<CryptoCurrency> currencies) {
cryptoCurrenciesAsObservable.setAll(currencies);
}
public void addFiatCurrency(FiatCurrency tradeCurrency) {
if (!fiatCurrenciesAsObservable.contains(tradeCurrency))
fiatCurrenciesAsObservable.add(tradeCurrency);
}
public void removeFiatCurrency(FiatCurrency tradeCurrency) {
if (tradeCurrenciesAsObservable.size() > 1) {
if (fiatCurrenciesAsObservable.contains(tradeCurrency))
fiatCurrenciesAsObservable.remove(tradeCurrency);
if (preferredTradeCurrency.equals(tradeCurrency))
setPreferredTradeCurrency(tradeCurrenciesAsObservable.get(0));
} else {
log.error("you cannot remove the last currency");
}
}
public void addCryptoCurrency(CryptoCurrency tradeCurrency) {
if (!cryptoCurrenciesAsObservable.contains(tradeCurrency))
cryptoCurrenciesAsObservable.add(tradeCurrency);
}
public void removeCryptoCurrency(CryptoCurrency tradeCurrency) {
if (tradeCurrenciesAsObservable.size() > 1) {
if (cryptoCurrenciesAsObservable.contains(tradeCurrency))
cryptoCurrenciesAsObservable.remove(tradeCurrency);
if (preferredTradeCurrency.equals(tradeCurrency))
setPreferredTradeCurrency(tradeCurrenciesAsObservable.get(0));
} else {
log.error("you cannot remove the last currency");
}
}
private void setBlockChainExplorerTestNet(BlockChainExplorer blockChainExplorerTestNet) {
@ -274,9 +339,11 @@ public final class Preferences implements Persistable {
}
public void setPreferredTradeCurrency(TradeCurrency preferredTradeCurrency) {
this.preferredTradeCurrency = preferredTradeCurrency;
defaultTradeCurrency = preferredTradeCurrency;
storage.queueUpForSave();
if (preferredTradeCurrency != null) {
this.preferredTradeCurrency = preferredTradeCurrency;
defaultTradeCurrency = preferredTradeCurrency;
storage.queueUpForSave();
}
}
public void setTxFeePerKB(long txFeePerKB) throws Exception {
@ -329,6 +396,14 @@ public final class Preferences implements Persistable {
return bitcoinNetwork;
}
public ObservableList<FiatCurrency> getFiatCurrenciesAsObservable() {
return fiatCurrenciesAsObservable;
}
public ObservableList<CryptoCurrency> getCryptoCurrenciesAsObservable() {
return cryptoCurrenciesAsObservable;
}
public ObservableList<TradeCurrency> getTradeCurrenciesAsObservable() {
return tradeCurrenciesAsObservable;
}