mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2026-08-10 08:37:05 +00:00
indicate historical rates support in exchange source drop-down
This commit is contained in:
@@ -21,7 +21,7 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public enum ExchangeSource {
|
||||
NONE("None") {
|
||||
NONE("None", null) {
|
||||
@Override
|
||||
public List<Currency> getSupportedCurrencies() {
|
||||
return Collections.emptyList();
|
||||
@@ -37,7 +37,7 @@ public enum ExchangeSource {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
},
|
||||
COINBASE("Coinbase") {
|
||||
COINBASE("Coinbase", "No historical rates") {
|
||||
@Override
|
||||
public List<Currency> getSupportedCurrencies() {
|
||||
return getRates().data.rates.keySet().stream().filter(code -> isValidISO4217Code(code.toUpperCase(Locale.ROOT)))
|
||||
@@ -121,7 +121,7 @@ public enum ExchangeSource {
|
||||
return historicalRates;
|
||||
}
|
||||
},
|
||||
COINGECKO("Coingecko") {
|
||||
COINGECKO("Coingecko", "No historical rates") {
|
||||
@Override
|
||||
public List<Currency> getSupportedCurrencies() {
|
||||
return getRates().rates.entrySet().stream().filter(rate -> "fiat".equals(rate.getValue().type) && isValidISO4217Code(rate.getKey().toUpperCase(Locale.ROOT)))
|
||||
@@ -189,7 +189,7 @@ public enum ExchangeSource {
|
||||
return historicalRates;
|
||||
}
|
||||
},
|
||||
MEMPOOL_SPACE("mempool.space") {
|
||||
MEMPOOL_SPACE("mempool.space", "Historical rates from Apr 2023") {
|
||||
@Override
|
||||
public List<Currency> getSupportedCurrencies() {
|
||||
return getRates().rates.entrySet().stream().filter(price -> isValidISO4217Code(price.getKey().toUpperCase(Locale.ROOT)))
|
||||
@@ -262,9 +262,11 @@ public enum ExchangeSource {
|
||||
private static final Logger log = LoggerFactory.getLogger(ExchangeSource.class);
|
||||
|
||||
private final String name;
|
||||
private final String description;
|
||||
|
||||
ExchangeSource(String name) {
|
||||
ExchangeSource(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public abstract List<Currency> getSupportedCurrencies();
|
||||
@@ -282,6 +284,14 @@ public enum ExchangeSource {
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
|
||||
@@ -19,6 +19,7 @@ import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.util.StringConverter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -158,6 +159,9 @@ public class GeneralSettingsController extends SettingsDetailController {
|
||||
config.setExchangeSource(exchangeSource.getValue());
|
||||
}
|
||||
|
||||
exchangeSource.setButtonCell(new ExchangeSourceButtonCell());
|
||||
exchangeSource.setCellFactory(_ -> new ExchangeSourceListCell());
|
||||
|
||||
exchangeSource.valueProperty().addListener((observable, oldValue, source) -> {
|
||||
config.setExchangeSource(source);
|
||||
updateCurrencies(source);
|
||||
@@ -253,4 +257,32 @@ public class GeneralSettingsController extends SettingsDetailController {
|
||||
|
||||
fiatCurrency.valueProperty().addListener(fiatCurrencyListener);
|
||||
}
|
||||
|
||||
private static class ExchangeSourceButtonCell extends ListCell<ExchangeSource> {
|
||||
@Override
|
||||
protected void updateItem(ExchangeSource exchangeSource, boolean empty) {
|
||||
super.updateItem(exchangeSource, empty);
|
||||
if(exchangeSource == null || empty) {
|
||||
setText("");
|
||||
} else {
|
||||
setText(exchangeSource.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ExchangeSourceListCell extends ListCell<ExchangeSource> {
|
||||
@Override
|
||||
protected void updateItem(ExchangeSource exchangeSource, boolean empty) {
|
||||
super.updateItem(exchangeSource, empty);
|
||||
if(exchangeSource == null || empty) {
|
||||
setText("");
|
||||
} else {
|
||||
String text = exchangeSource.getName();
|
||||
if(exchangeSource.getDescription() != null && !exchangeSource.getDescription().isEmpty()) {
|
||||
text += " (" + exchangeSource.getDescription() + ")";
|
||||
}
|
||||
setText(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user