Fix handling of preferred currency

This commit is contained in:
Christoph Atteneder 2022-04-20 21:05:58 +02:00
parent 108255bf8e
commit e43a8aed36
No known key found for this signature in database
GPG Key ID: CD5DC1C529CDFD3B
2 changed files with 29 additions and 1 deletions

View File

@ -53,6 +53,7 @@ import javax.inject.Named;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@ -131,7 +132,25 @@ public class BtcOfferBookViewModel extends OfferBookViewModel {
@Override
TradeCurrency getDefaultTradeCurrency() {
return GlobalSettings.getDefaultTradeCurrency();
TradeCurrency defaultTradeCurrency = GlobalSettings.getDefaultTradeCurrency();
if (CurrencyUtil.isFiatCurrency(defaultTradeCurrency.getCode())) {
return defaultTradeCurrency;
}
ObservableList<TradeCurrency> tradeCurrencies = FXCollections.observableArrayList(getTradeCurrencies());
if (!tradeCurrencies.isEmpty()) {
// drop show all entry and select first currency with payment account available
tradeCurrencies.remove(0);
List<TradeCurrency> sortedList = tradeCurrencies.stream().sorted((o1, o2) ->
Boolean.compare(!hasPaymentAccountForCurrency(o1),
!hasPaymentAccountForCurrency(o2))).collect(Collectors.toList());
return sortedList.get(0);
} else {
return CurrencyUtil.getMainFiatCurrencies().stream().sorted((o1, o2) ->
Boolean.compare(!hasPaymentAccountForCurrency(o1),
!hasPaymentAccountForCurrency(o2))).collect(Collectors.toList()).get(0);
}
}
@Override

View File

@ -27,6 +27,7 @@ import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.locale.CryptoCurrency;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.GlobalSettings;
import bisq.core.locale.TradeCurrency;
import bisq.core.offer.Offer;
import bisq.core.offer.OfferDirection;
@ -133,6 +134,14 @@ public class OtherOfferBookViewModel extends OfferBookViewModel {
@Override
TradeCurrency getDefaultTradeCurrency() {
TradeCurrency defaultTradeCurrency = GlobalSettings.getDefaultTradeCurrency();
if (!CurrencyUtil.isFiatCurrency(defaultTradeCurrency.getCode()) &&
!defaultTradeCurrency.equals(GUIUtil.BSQ) &&
!defaultTradeCurrency.equals(GUIUtil.TOP_ALTCOIN)) {
return defaultTradeCurrency;
}
ObservableList<TradeCurrency> tradeCurrencies = FXCollections.observableArrayList(getTradeCurrencies());
if (!tradeCurrencies.isEmpty()) {
// drop show all entry and select first currency with payment account available