mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2025-11-05 11:56:37 +00:00
indicate historical rates support in exchange source drop-down
This commit is contained in:
parent
62b1dc3900
commit
c7351cd191
3 changed files with 48 additions and 6 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@
|
|||
<ComboBox fx:id="fiatCurrency" />
|
||||
</Field>
|
||||
<Field text="Exchange rate source:">
|
||||
<ComboBox fx:id="exchangeSource">
|
||||
<ComboBox fx:id="exchangeSource" prefWidth="150">
|
||||
<items>
|
||||
<FXCollections fx:factory="observableArrayList">
|
||||
<ExchangeSource fx:constant="NONE" />
|
||||
|
|
|
|||
Loading…
Reference in a new issue