mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Fix a couple of issues regarding default currencies
This commit is contained in:
parent
2055cc5c10
commit
fce247cbc0
@ -1335,6 +1335,7 @@ setting.preferences.prefCurrency=Preferred currency
|
||||
setting.preferences.displayFiat=Display national currencies
|
||||
setting.preferences.noFiat=There are no national currencies selected
|
||||
setting.preferences.cannotRemovePrefCurrency=You cannot remove your selected preferred display currency
|
||||
setting.preferences.cannotRemoveMainAltcoinCurrency=You cannot remove this main altcoin currency
|
||||
setting.preferences.displayAltcoins=Display altcoins
|
||||
setting.preferences.noAltcoins=There are no altcoins selected
|
||||
setting.preferences.addFiat=Add national currency
|
||||
|
@ -295,7 +295,7 @@ public abstract class OfferView extends ActivatableView<TabPane, Void> {
|
||||
// CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times
|
||||
// in different graphs
|
||||
if ((paymentMethod != null && paymentMethod.isBsqSwap()) ||
|
||||
(paymentMethod == null && viewClass.equals(BsqOfferBookView.class))) {
|
||||
viewClass.equals(BsqOfferBookView.class)) {
|
||||
view = viewLoader.load(BsqSwapCreateOfferView.class);
|
||||
((BsqSwapCreateOfferView) view).initWithData(direction, offerActionHandler, payload);
|
||||
} else {
|
||||
|
@ -31,6 +31,7 @@ import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookView;
|
||||
import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel;
|
||||
import bisq.desktop.main.overlays.popups.Popup;
|
||||
|
||||
import bisq.core.locale.CryptoCurrency;
|
||||
import bisq.core.locale.CurrencyUtil;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.locale.TradeCurrency;
|
||||
@ -53,6 +54,9 @@ import javafx.geometry.VPos;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
// Shared utils for Views
|
||||
public class OfferViewUtil {
|
||||
@ -155,8 +159,13 @@ public class OfferViewUtil {
|
||||
}
|
||||
|
||||
public static TradeCurrency getAnyOfMainCryptoCurrencies() {
|
||||
return getMainCryptoCurrencies().findAny().get();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Stream<CryptoCurrency> getMainCryptoCurrencies() {
|
||||
return CurrencyUtil.getMainCryptoCurrencies().stream().filter(cryptoCurrency ->
|
||||
!Objects.equals(cryptoCurrency.getCode(), TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode()) &&
|
||||
!Objects.equals(cryptoCurrency.getCode(), BsqOfferBookViewModel.BSQ.getCode())).findAny().get();
|
||||
!Objects.equals(cryptoCurrency.getCode(), BsqOfferBookViewModel.BSQ.getCode()));
|
||||
}
|
||||
}
|
||||
|
@ -18,12 +18,12 @@
|
||||
package bisq.desktop.main.offer.offerbook;
|
||||
|
||||
import bisq.desktop.Navigation;
|
||||
import bisq.desktop.util.GUIUtil;
|
||||
|
||||
import bisq.core.account.witness.AccountAgeWitnessService;
|
||||
import bisq.core.api.CoreApi;
|
||||
import bisq.core.btc.setup.WalletsSetup;
|
||||
import bisq.core.btc.wallet.BsqWalletService;
|
||||
import bisq.core.locale.CurrencyUtil;
|
||||
import bisq.core.locale.TradeCurrency;
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.OfferDirection;
|
||||
@ -55,7 +55,7 @@ import java.util.stream.Collectors;
|
||||
public class BsqOfferBookViewModel extends OfferBookViewModel {
|
||||
|
||||
|
||||
public static final TradeCurrency BSQ = CurrencyUtil.getTradeCurrency("BSQ").get();
|
||||
public static final TradeCurrency BSQ = GUIUtil.BSQ;
|
||||
|
||||
@Inject
|
||||
public BsqOfferBookViewModel(User user,
|
||||
|
@ -567,10 +567,11 @@ abstract class OfferBookViewModel extends ActivatableViewModel {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
boolean hasPaymentAccountForCurrency() {
|
||||
return (showAllTradeCurrenciesProperty.get() &&
|
||||
user.getPaymentAccounts() != null &&
|
||||
!user.getPaymentAccounts().isEmpty()) ||
|
||||
user.hasPaymentAccountForCurrency(selectedTradeCurrency);
|
||||
return hasPaymentAccountForCurrency(selectedTradeCurrency);
|
||||
}
|
||||
|
||||
boolean hasPaymentAccountForCurrency(TradeCurrency currency) {
|
||||
return user.hasPaymentAccountForCurrency(currency);
|
||||
}
|
||||
|
||||
boolean canCreateOrTakeOffer() {
|
||||
|
@ -52,6 +52,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;
|
||||
|
||||
@ -132,14 +133,25 @@ public class OtherOfferBookViewModel extends OfferBookViewModel {
|
||||
|
||||
@Override
|
||||
TradeCurrency getDefaultTradeCurrency() {
|
||||
// select first currency in list, otherwise if view is not initialized any of the main crypto currencies
|
||||
return !getTradeCurrencies().isEmpty() ? getTradeCurrencies().get(1) :
|
||||
OfferViewUtil.getAnyOfMainCryptoCurrencies();
|
||||
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 OfferViewUtil.getMainCryptoCurrencies().sorted((o1, o2) ->
|
||||
Boolean.compare(!hasPaymentAccountForCurrency(o1),
|
||||
!hasPaymentAccountForCurrency(o2))).collect(Collectors.toList()).get(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
String getCurrencyCodeFromPreferences(OfferDirection direction) {
|
||||
return direction == OfferDirection.BUY ? preferences.getBuyScreenCryptoCurrencyCode() : preferences.getSellScreenCryptoCurrencyCode();
|
||||
return direction == OfferDirection.BUY ? preferences.getBuyScreenCryptoCurrencyCode() :
|
||||
preferences.getSellScreenCryptoCurrencyCode();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@ -18,12 +18,12 @@
|
||||
package bisq.desktop.main.offer.offerbook;
|
||||
|
||||
import bisq.desktop.Navigation;
|
||||
import bisq.desktop.util.GUIUtil;
|
||||
|
||||
import bisq.core.account.witness.AccountAgeWitnessService;
|
||||
import bisq.core.api.CoreApi;
|
||||
import bisq.core.btc.setup.WalletsSetup;
|
||||
import bisq.core.btc.wallet.BsqWalletService;
|
||||
import bisq.core.locale.CurrencyUtil;
|
||||
import bisq.core.locale.TradeCurrency;
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.OfferDirection;
|
||||
@ -54,7 +54,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class TopAltcoinOfferBookViewModel extends OfferBookViewModel {
|
||||
|
||||
public static final TradeCurrency TOP_ALTCOIN = CurrencyUtil.getTradeCurrency("XMR").get();
|
||||
public static final TradeCurrency TOP_ALTCOIN = GUIUtil.TOP_ALTCOIN;
|
||||
|
||||
@Inject
|
||||
public TopAltcoinOfferBookViewModel(User user,
|
||||
|
@ -553,6 +553,9 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
|
||||
removeButton.setOnAction(e -> {
|
||||
if (item.equals(preferences.getPreferredTradeCurrency())) {
|
||||
new Popup().warning(Res.get("setting.preferences.cannotRemovePrefCurrency")).show();
|
||||
}
|
||||
if (item.equals(GUIUtil.BSQ) || item.equals(GUIUtil.TOP_ALTCOIN)) {
|
||||
new Popup().warning(Res.get("setting.preferences.cannotRemoveMainAltcoinCurrency")).show();
|
||||
} else {
|
||||
preferences.removeCryptoCurrency(item);
|
||||
if (!allCryptoCurrencies.contains(item)) {
|
||||
|
@ -168,6 +168,9 @@ public class GUIUtil {
|
||||
public final static int AMOUNT_DECIMALS_WITH_ZEROS = 3;
|
||||
public final static int AMOUNT_DECIMALS = 4;
|
||||
|
||||
public final static TradeCurrency BSQ = CurrencyUtil.getTradeCurrency("BSQ").get();
|
||||
public final static TradeCurrency TOP_ALTCOIN = CurrencyUtil.getTradeCurrency("XMR").get();
|
||||
|
||||
private static FeeService feeService;
|
||||
private static Preferences preferences;
|
||||
|
||||
@ -1246,5 +1249,4 @@ public class GUIUtil {
|
||||
columnConstraints2.setHgrow(Priority.ALWAYS);
|
||||
gridPane.getColumnConstraints().addAll(columnConstraints1, columnConstraints2);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user