mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-21 16:16:27 -04:00
Add edit field in currency list
This commit is contained in:
parent
2f0f58c478
commit
61eee8f445
@ -62,7 +62,6 @@ public class CurrencyUtil {
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
private static final List<CryptoCurrency> allSortedCryptoCurrencies = createAllSortedCryptoCurrenciesList();
|
||||
|
||||
public static List<CryptoCurrency> getAllSortedCryptoCurrencies() {
|
||||
@ -112,94 +111,6 @@ public class CurrencyUtil {
|
||||
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
|
||||
set.addAll(getSortedSEPACurrencyCodes());
|
||||
|
||||
// PerfectMoney:
|
||||
set.add(new FiatCurrency("USD"));
|
||||
|
||||
// Alipay:
|
||||
set.add(new FiatCurrency("CNY"));
|
||||
|
||||
// OKPay: We want to maintain the order so we don't use a Set but add items if nto already in list
|
||||
getAllOKPayCurrencies().stream().forEach(set::add);
|
||||
|
||||
// Swish: it is already added by SEPA
|
||||
|
||||
// for printing out all codes
|
||||
*//* String res;
|
||||
result.stream().forEach(e -> {
|
||||
res += "list.add(new FiatCurrency(\""+e.code+"\"));\n";
|
||||
});
|
||||
log.debug(res);*//*
|
||||
|
||||
|
||||
List<TradeCurrency> list = getAllManuallySortedFiatCurrencies();
|
||||
|
||||
// check if the list derived form the payment methods is containing exactly the same as our manually sorted one
|
||||
|
||||
List<String> list1 = set.stream().map(e -> e.code).collect(Collectors.toList());
|
||||
list1.sort(String::compareTo);
|
||||
List<String> list2 = list.stream().map(e -> e.code).collect(Collectors.toList());
|
||||
list2.sort(String::compareTo);
|
||||
|
||||
if (list1.size() != list2.size()) {
|
||||
log.error("manually defined currencies are not matching currencies derived form our payment methods");
|
||||
log.error("list1 " + list1.toString());
|
||||
log.error("list2 " + list2.toString());
|
||||
}
|
||||
|
||||
if (!list1.toString().equals(list2.toString())) {
|
||||
log.error("List derived form the payment methods is not matching exactly the same as our manually sorted one");
|
||||
log.error("list1 " + list1.toString());
|
||||
log.error("list2 " + list2.toString());
|
||||
}
|
||||
|
||||
// Blockchain
|
||||
getSortedCryptoCurrencies().stream().forEach(list::add);
|
||||
|
||||
return list;
|
||||
}*/
|
||||
|
||||
|
||||
/* private static List<TradeCurrency> getAllManuallySortedFiatCurrencies() {
|
||||
List<TradeCurrency> list = new ArrayList<>();
|
||||
list.add(new FiatCurrency("EUR"));
|
||||
list.add(new FiatCurrency("USD"));
|
||||
list.add(new FiatCurrency("GBP"));
|
||||
list.add(new FiatCurrency("CNY"));
|
||||
list.add(new FiatCurrency("HKD"));
|
||||
list.add(new FiatCurrency("CHF"));
|
||||
list.add(new FiatCurrency("JPY"));
|
||||
list.add(new FiatCurrency("CAD"));
|
||||
list.add(new FiatCurrency("AUD"));
|
||||
list.add(new FiatCurrency("NZD"));
|
||||
list.add(new FiatCurrency("ZAR"));
|
||||
list.add(new FiatCurrency("RUB"));
|
||||
|
||||
list.add(new FiatCurrency("SEK"));
|
||||
list.add(new FiatCurrency("NOK"));
|
||||
list.add(new FiatCurrency("DKK"));
|
||||
list.add(new FiatCurrency("ISK"));
|
||||
|
||||
list.add(new FiatCurrency("PLN"));
|
||||
list.add(new FiatCurrency("CZK"));
|
||||
list.add(new FiatCurrency("TRY"));
|
||||
|
||||
list.add(new FiatCurrency("BGN"));
|
||||
list.add(new FiatCurrency("HRK"));
|
||||
list.add(new FiatCurrency("HUF"));
|
||||
list.add(new FiatCurrency("RON"));
|
||||
|
||||
return list;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* @return Sorted list of SEPA currencies with EUR as first item
|
||||
@ -255,15 +166,7 @@ public class CurrencyUtil {
|
||||
}
|
||||
|
||||
public static FiatCurrency getCurrencyByCountryCode(String countryCode) {
|
||||
// java 1.8.8_0_20 reports wrong currency (Lita instead of EUR)
|
||||
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");
|
||||
}
|
||||
return new FiatCurrency(Currency.getInstance(new Locale(LanguageUtil.getDefaultLanguage(), countryCode)).getCurrencyCode());
|
||||
}
|
||||
|
||||
|
||||
|
@ -39,6 +39,7 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class MarketsChartsViewModel extends ActivatableViewModel {
|
||||
final static String EDIT_FLAG = "EDIT_FLAG";
|
||||
|
||||
private final OfferBook offerBook;
|
||||
private final Preferences preferences;
|
||||
|
@ -93,10 +93,13 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
currencyComboBox.setConverter(new StringConverter<TradeCurrency>() {
|
||||
@Override
|
||||
public String toString(TradeCurrency tradeCurrency) {
|
||||
if (!tradeCurrency.getCode().equals(OfferBookViewModel.SHOW_ALL_FLAG))
|
||||
return tradeCurrency.getNameAndCode();
|
||||
String code = tradeCurrency.getCode();
|
||||
if (code.equals(OfferBookViewModel.SHOW_ALL_FLAG))
|
||||
return ">> Show all";
|
||||
else if (code.equals(OfferBookViewModel.EDIT_FLAG))
|
||||
return ">> Edit currency list";
|
||||
else
|
||||
return "Show all";
|
||||
return tradeCurrency.getNameAndCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -111,7 +114,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
@Override
|
||||
public String toString(PaymentMethod paymentMethod) {
|
||||
String id = paymentMethod.getId();
|
||||
return BSResources.get(!id.equals(OfferBookViewModel.SHOW_ALL_FLAG) ? id : "Show all");
|
||||
return BSResources.get(!id.equals(OfferBookViewModel.SHOW_ALL_FLAG) ? id : ">> Show all");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,7 +23,11 @@ import io.bitsquare.app.Version;
|
||||
import io.bitsquare.btc.pricefeed.PriceFeed;
|
||||
import io.bitsquare.common.handlers.ErrorMessageHandler;
|
||||
import io.bitsquare.common.handlers.ResultHandler;
|
||||
import io.bitsquare.gui.Navigation;
|
||||
import io.bitsquare.gui.common.model.ActivatableViewModel;
|
||||
import io.bitsquare.gui.main.MainView;
|
||||
import io.bitsquare.gui.main.settings.SettingsView;
|
||||
import io.bitsquare.gui.main.settings.preferences.PreferencesView;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.locale.*;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
@ -49,7 +53,8 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
class OfferBookViewModel extends ActivatableViewModel {
|
||||
final static String SHOW_ALL_FLAG = "XXX";
|
||||
final static String SHOW_ALL_FLAG = "SHOW_ALL_FLAG";
|
||||
final static String EDIT_FLAG = "EDIT_FLAG";
|
||||
|
||||
private final OpenOfferManager openOfferManager;
|
||||
private final User user;
|
||||
@ -57,6 +62,7 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||
private final Preferences preferences;
|
||||
private final P2PService p2PService;
|
||||
private final PriceFeed priceFeed;
|
||||
private Navigation navigation;
|
||||
final BSFormatter formatter;
|
||||
|
||||
private final FilteredList<OfferBookListItem> filteredItems;
|
||||
@ -88,7 +94,7 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||
@Inject
|
||||
public OfferBookViewModel(User user, OpenOfferManager openOfferManager, OfferBook offerBook,
|
||||
Preferences preferences, P2PService p2PService, PriceFeed priceFeed,
|
||||
BSFormatter formatter) {
|
||||
Navigation navigation, BSFormatter formatter) {
|
||||
super();
|
||||
|
||||
this.openOfferManager = openOfferManager;
|
||||
@ -97,6 +103,7 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||
this.preferences = preferences;
|
||||
this.p2PService = p2PService;
|
||||
this.priceFeed = priceFeed;
|
||||
this.navigation = navigation;
|
||||
this.formatter = formatter;
|
||||
|
||||
offerBookListItems = offerBook.getOfferBookListItems();
|
||||
@ -133,9 +140,9 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||
private void fillAllTradeCurrencies() {
|
||||
allTradeCurrencies.clear();
|
||||
// Used for ignoring filter (show all)
|
||||
TradeCurrency dummy = new FiatCurrency(SHOW_ALL_FLAG);
|
||||
allTradeCurrencies.add(dummy);
|
||||
allTradeCurrencies.add(new CryptoCurrency(SHOW_ALL_FLAG, SHOW_ALL_FLAG));
|
||||
allTradeCurrencies.addAll(preferences.getTradeCurrenciesAsObservable());
|
||||
allTradeCurrencies.add(new CryptoCurrency(EDIT_FLAG, EDIT_FLAG));
|
||||
}
|
||||
|
||||
private void setMarketPriceFeedCurrency() {
|
||||
@ -168,7 +175,9 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||
public void onSetTradeCurrency(TradeCurrency tradeCurrency) {
|
||||
String code = tradeCurrency.getCode();
|
||||
showAllTradeCurrenciesProperty.set(isShowAllEntry(code));
|
||||
if (!showAllTradeCurrenciesProperty.get()) {
|
||||
if (isEditEntry(code))
|
||||
navigation.navigateTo(MainView.class, SettingsView.class, PreferencesView.class);
|
||||
else if (!showAllTradeCurrenciesProperty.get()) {
|
||||
this.selectedTradeCurrency = tradeCurrency;
|
||||
tradeCurrencyCode.set(code);
|
||||
}
|
||||
@ -366,4 +375,8 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||
private boolean isShowAllEntry(String id) {
|
||||
return id.equals(SHOW_ALL_FLAG);
|
||||
}
|
||||
|
||||
private boolean isEditEntry(String id) {
|
||||
return id.equals(EDIT_FLAG);
|
||||
}
|
||||
}
|
||||
|
@ -313,6 +313,7 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Activatab
|
||||
private void activateDisplayCurrencies() {
|
||||
preferredTradeCurrencyComboBox.setItems(tradeCurrencies);
|
||||
preferredTradeCurrencyComboBox.getSelectionModel().select(preferences.getPreferredTradeCurrency());
|
||||
preferredTradeCurrencyComboBox.setVisibleRowCount(Math.min(preferredTradeCurrencyComboBox.getItems().size(), 25));
|
||||
preferredTradeCurrencyComboBox.setOnAction(e -> {
|
||||
TradeCurrency selectedItem = preferredTradeCurrencyComboBox.getSelectionModel().getSelectedItem();
|
||||
if (selectedItem != null)
|
||||
|
Loading…
x
Reference in New Issue
Block a user