Set preferred currency as top altcoin

If it is a crypto currency and not a fiat currency
This commit is contained in:
Christoph Atteneder 2022-04-22 10:41:15 +02:00
parent 4447435e5f
commit 7ad2dd0ba6
No known key found for this signature in database
GPG key ID: CD5DC1C529CDFD3B
10 changed files with 52 additions and 40 deletions

View file

@ -24,10 +24,8 @@ import bisq.desktop.main.offer.BuyOfferView;
import bisq.desktop.main.offer.OfferView;
import bisq.desktop.main.offer.OfferViewUtil;
import bisq.desktop.main.offer.SellOfferView;
import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel;
import bisq.desktop.main.offer.offerbook.OfferBook;
import bisq.desktop.main.offer.offerbook.OfferBookListItem;
import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel;
import bisq.desktop.main.settings.SettingsView;
import bisq.desktop.main.settings.preferences.PreferencesView;
import bisq.desktop.util.CurrencyList;
@ -413,15 +411,15 @@ class OfferBookChartViewModel extends ActivatableViewModel {
if (isSellOffer(direction)) {
if (CurrencyUtil.isFiatCurrency(getCurrencyCode())) {
preferences.setBuyScreenCurrencyCode(getCurrencyCode());
} else if (!getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode()) &&
!getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) {
} else if (!getCurrencyCode().equals(GUIUtil.BSQ.getCode()) &&
!getCurrencyCode().equals(GUIUtil.TOP_ALTCOIN.getCode())) {
preferences.setBuyScreenCryptoCurrencyCode(getCurrencyCode());
}
} else {
if (CurrencyUtil.isFiatCurrency(getCurrencyCode())) {
preferences.setSellScreenCurrencyCode(getCurrencyCode());
} else if (!getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode()) &&
!getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) {
} else if (!getCurrencyCode().equals(GUIUtil.BSQ.getCode()) &&
!getCurrencyCode().equals(GUIUtil.TOP_ALTCOIN.getCode())) {
preferences.setSellScreenCryptoCurrencyCode(getCurrencyCode());
}
}

View file

@ -27,12 +27,10 @@ import bisq.desktop.main.offer.bisq_v1.takeoffer.TakeOfferView;
import bisq.desktop.main.offer.bsq_swap.create_offer.BsqSwapCreateOfferView;
import bisq.desktop.main.offer.bsq_swap.take_offer.BsqSwapTakeOfferView;
import bisq.desktop.main.offer.offerbook.BsqOfferBookView;
import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel;
import bisq.desktop.main.offer.offerbook.BtcOfferBookView;
import bisq.desktop.main.offer.offerbook.OfferBookView;
import bisq.desktop.main.offer.offerbook.OtherOfferBookView;
import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookView;
import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel;
import bisq.desktop.util.GUIUtil;
import bisq.core.locale.CurrencyUtil;
@ -172,6 +170,12 @@ public abstract class OfferView extends ActivatableView<TabPane, Void> {
if (btcOfferBookView == null) {
navigation.navigateTo(MainView.class, this.getClass(), BtcOfferBookView.class);
}
GUIUtil.updateTopAltcoin(preferences);
if (topAltcoinOfferBookTab != null) {
topAltcoinOfferBookTab.setText(GUIUtil.TOP_ALTCOIN.getCode());
}
}
@Override
@ -205,7 +209,7 @@ public abstract class OfferView extends ActivatableView<TabPane, Void> {
} else if (data instanceof BsqSwapOfferPayload) {
loadCreateViewClass(bsqOfferBookView, viewClass, childViewClass, bsqOfferBookTab, PaymentMethod.BSQ_SWAP, (BsqSwapOfferPayload) data);
} else {
tradeCurrency = BsqOfferBookViewModel.BSQ;
tradeCurrency = GUIUtil.BSQ;
loadCreateViewClass(bsqOfferBookView, viewClass, childViewClass, bsqOfferBookTab, (PaymentMethod) data, null);
}
tabPane.getSelectionModel().select(bsqOfferBookTab);
@ -215,7 +219,7 @@ public abstract class OfferView extends ActivatableView<TabPane, Void> {
} else if (childViewClass == TakeOfferView.class) {
loadTakeViewClass(viewClass, childViewClass, topAltcoinOfferBookTab);
} else {
tradeCurrency = TopAltcoinOfferBookViewModel.TOP_ALTCOIN;
tradeCurrency = GUIUtil.TOP_ALTCOIN;
loadCreateViewClass(topAltcoinOfferBookView, viewClass, childViewClass, topAltcoinOfferBookTab, (PaymentMethod) data, null);
}
tabPane.getSelectionModel().select(topAltcoinOfferBookTab);
@ -239,9 +243,9 @@ public abstract class OfferView extends ActivatableView<TabPane, Void> {
if (btcOfferBookTab == null) {
btcOfferBookTab = new Tab(Res.getBaseCurrencyName().toUpperCase());
btcOfferBookTab.setClosable(false);
bsqOfferBookTab = new Tab(BsqOfferBookViewModel.BSQ.getCode());
bsqOfferBookTab = new Tab(GUIUtil.BSQ.getCode());
bsqOfferBookTab.setClosable(false);
topAltcoinOfferBookTab = new Tab(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode());
topAltcoinOfferBookTab = new Tab(GUIUtil.TOP_ALTCOIN.getCode());
topAltcoinOfferBookTab.setClosable(false);
otherOfferBookTab = new Tab(Res.get("shared.other").toUpperCase());
otherOfferBookTab.setClosable(false);
@ -363,9 +367,9 @@ public abstract class OfferView extends ActivatableView<TabPane, Void> {
Class<? extends OfferBookView<?, ?>> offerBookViewClass;
if (CurrencyUtil.isFiatCurrency(currencyCode)) {
offerBookViewClass = BtcOfferBookView.class;
} else if (currencyCode.equals(BsqOfferBookViewModel.BSQ.getCode())) {
} else if (currencyCode.equals(GUIUtil.BSQ.getCode())) {
offerBookViewClass = BsqOfferBookView.class;
} else if (currencyCode.equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) {
} else if (currencyCode.equals(GUIUtil.TOP_ALTCOIN.getCode())) {
offerBookViewClass = TopAltcoinOfferBookView.class;
} else {
offerBookViewClass = OtherOfferBookView.class;

View file

@ -23,13 +23,12 @@ import bisq.desktop.components.AutoTooltipLabel;
import bisq.desktop.components.HyperlinkWithIcon;
import bisq.desktop.main.MainView;
import bisq.desktop.main.offer.offerbook.BsqOfferBookView;
import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel;
import bisq.desktop.main.offer.offerbook.BtcOfferBookView;
import bisq.desktop.main.offer.offerbook.OfferBookView;
import bisq.desktop.main.offer.offerbook.OtherOfferBookView;
import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookView;
import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel;
import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.util.GUIUtil;
import bisq.core.locale.CryptoCurrency;
import bisq.core.locale.CurrencyUtil;
@ -132,9 +131,9 @@ public class OfferViewUtil {
Class<? extends OfferBookView<?, ?>> offerBookViewClazz;
if (CurrencyUtil.isFiatCurrency(currencyCode)) {
offerBookViewClazz = BtcOfferBookView.class;
} else if (currencyCode.equals(BsqOfferBookViewModel.BSQ.getCode())) {
} else if (currencyCode.equals(GUIUtil.BSQ.getCode())) {
offerBookViewClazz = BsqOfferBookView.class;
} else if (currencyCode.equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) {
} else if (currencyCode.equals(GUIUtil.TOP_ALTCOIN.getCode())) {
offerBookViewClazz = TopAltcoinOfferBookView.class;
} else {
offerBookViewClazz = OtherOfferBookView.class;
@ -169,7 +168,7 @@ public class OfferViewUtil {
@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()));
!Objects.equals(cryptoCurrency.getCode(), GUIUtil.TOP_ALTCOIN.getCode()) &&
!Objects.equals(cryptoCurrency.getCode(), GUIUtil.BSQ.getCode()));
}
}

View file

@ -18,8 +18,6 @@
package bisq.desktop.main.offer.bisq_v1;
import bisq.desktop.Navigation;
import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel;
import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel;
import bisq.desktop.util.DisplayUtils;
import bisq.desktop.util.GUIUtil;
@ -289,8 +287,8 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs
} else {
return paymentAccounts.stream().filter(paymentAccount1 -> paymentAccount1.getPaymentMethod().isAltcoin() &&
paymentAccount1.getTradeCurrency().isPresent() &&
!Objects.equals(paymentAccount1.getTradeCurrency().get().getCode(), BsqOfferBookViewModel.BSQ.getCode()) &&
!Objects.equals(paymentAccount1.getTradeCurrency().get().getCode(), TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())).findAny();
!Objects.equals(paymentAccount1.getTradeCurrency().get().getCode(), GUIUtil.BSQ.getCode()) &&
!Objects.equals(paymentAccount1.getTradeCurrency().get().getCode(), GUIUtil.TOP_ALTCOIN.getCode())).findAny();
}
}

View file

@ -21,9 +21,8 @@ import bisq.desktop.Navigation;
import bisq.desktop.common.view.FxmlView;
import bisq.desktop.main.offer.OfferView;
import bisq.desktop.main.offer.bisq_v1.MutableOfferView;
import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel;
import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel;
import bisq.desktop.main.overlays.windows.OfferDetailsWindow;
import bisq.desktop.util.GUIUtil;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.TradeCurrency;
@ -70,16 +69,16 @@ public class CreateOfferView extends MutableOfferView<CreateOfferViewModel> {
protected ObservableList<PaymentAccount> filterPaymentAccounts(ObservableList<PaymentAccount> paymentAccounts) {
return FXCollections.observableArrayList(
paymentAccounts.stream().filter(paymentAccount -> {
if (model.getTradeCurrency().equals(BsqOfferBookViewModel.BSQ)) {
return Objects.equals(paymentAccount.getSingleTradeCurrency(), BsqOfferBookViewModel.BSQ);
} else if (model.getTradeCurrency().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN)) {
return Objects.equals(paymentAccount.getSingleTradeCurrency(), TopAltcoinOfferBookViewModel.TOP_ALTCOIN);
if (model.getTradeCurrency().equals(GUIUtil.BSQ)) {
return Objects.equals(paymentAccount.getSingleTradeCurrency(), GUIUtil.BSQ);
} else if (model.getTradeCurrency().equals(GUIUtil.TOP_ALTCOIN)) {
return Objects.equals(paymentAccount.getSingleTradeCurrency(), GUIUtil.TOP_ALTCOIN);
} else if (CurrencyUtil.isFiatCurrency(model.getTradeCurrency().getCode())) {
return !paymentAccount.getPaymentMethod().isAltcoin();
} else {
return paymentAccount.getPaymentMethod().isAltcoin() &&
!(Objects.equals(paymentAccount.getSingleTradeCurrency(), BsqOfferBookViewModel.BSQ) ||
Objects.equals(paymentAccount.getSingleTradeCurrency(), TopAltcoinOfferBookViewModel.TOP_ALTCOIN));
!(Objects.equals(paymentAccount.getSingleTradeCurrency(), GUIUtil.BSQ) ||
Objects.equals(paymentAccount.getSingleTradeCurrency(), GUIUtil.TOP_ALTCOIN));
}
}).collect(Collectors.toList()));
}

View file

@ -29,7 +29,6 @@ import bisq.desktop.main.offer.OfferView;
import bisq.desktop.main.offer.OfferViewUtil;
import bisq.desktop.main.offer.SelectableView;
import bisq.desktop.main.offer.bsq_swap.BsqSwapOfferView;
import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel;
import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.main.overlays.windows.BsqSwapOfferDetailsWindow;
import bisq.desktop.main.portfolio.PortfolioView;
@ -175,7 +174,7 @@ public class BsqSwapCreateOfferView extends BsqSwapOfferView<BsqSwapCreateOfferV
model.initWithData(offerPayload != null ? offerPayload.getDirection() : offerDirection, offerPayload);
if (OfferViewUtil.isShownAsBuyOffer(offerDirection, BsqOfferBookViewModel.BSQ)) {
if (OfferViewUtil.isShownAsBuyOffer(offerDirection, GUIUtil.BSQ)) {
actionButton.setId("buy-button-big");
actionButton.updateText(Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.buy"), BSQ));
nextButton.setId("buy-button");

View file

@ -122,8 +122,8 @@ public class OtherOfferBookViewModel extends OfferBookViewModel {
boolean directionResult = offer.getDirection() == direction;
boolean currencyResult = CurrencyUtil.isCryptoCurrency(offer.getCurrencyCode()) &&
((showAllTradeCurrenciesProperty.get() &&
!offer.getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode()) &&
!offer.getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode())) ||
!offer.getCurrencyCode().equals(GUIUtil.TOP_ALTCOIN.getCode()) &&
!offer.getCurrencyCode().equals(GUIUtil.BSQ.getCode())) ||
offer.getCurrencyCode().equals(selectedTradeCurrency.getCode()));
boolean paymentMethodResult = showAllPaymentMethods ||
offer.getPaymentMethod().equals(selectedPaymentMethod);
@ -166,7 +166,7 @@ public class OtherOfferBookViewModel extends OfferBookViewModel {
@NotNull
private Predicate<CryptoCurrency> withoutBSQAndTopAltcoin() {
return cryptoCurrency ->
!cryptoCurrency.equals(BsqOfferBookViewModel.BSQ) &&
!cryptoCurrency.equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN);
!cryptoCurrency.equals(GUIUtil.BSQ) &&
!cryptoCurrency.equals(GUIUtil.TOP_ALTCOIN);
}
}

View file

@ -54,7 +54,7 @@ import java.util.stream.Collectors;
public class TopAltcoinOfferBookViewModel extends OfferBookViewModel {
public static final TradeCurrency TOP_ALTCOIN = GUIUtil.TOP_ALTCOIN;
public static TradeCurrency TOP_ALTCOIN = GUIUtil.TOP_ALTCOIN;
@Inject
public TopAltcoinOfferBookViewModel(User user,
@ -77,6 +77,12 @@ public class TopAltcoinOfferBookViewModel extends OfferBookViewModel {
super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, bsqSwapTradeManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, bsqFormatter, bsqWalletService, coreApi);
}
@Override
protected void activate() {
super.activate();
TOP_ALTCOIN = GUIUtil.TOP_ALTCOIN;
}
@Override
void saveSelectedCurrencyCodeInPreferences(OfferDirection direction, String code) {
// No need to store anything as it is just one Altcoin offers anyway

View file

@ -944,6 +944,7 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
TradeCurrency selectedItem = preferredTradeCurrencyComboBox.getSelectionModel().getSelectedItem();
if (selectedItem != null)
preferences.setPreferredTradeCurrency(selectedItem);
GUIUtil.updateTopAltcoin(preferences);
});
fiatCurrenciesComboBox.setItems(allFiatCurrencies);

View file

@ -169,7 +169,7 @@ public class GUIUtil {
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();
public static TradeCurrency TOP_ALTCOIN = CurrencyUtil.getTradeCurrency("XMR").get();
private static FeeService feeService;
private static Preferences preferences;
@ -1249,4 +1249,12 @@ public class GUIUtil {
columnConstraints2.setHgrow(Priority.ALWAYS);
gridPane.getColumnConstraints().addAll(columnConstraints1, columnConstraints2);
}
public static void updateTopAltcoin(Preferences preferences) {
TradeCurrency tradeCurrency = preferences.getPreferredTradeCurrency();
if (CurrencyUtil.isFiatCurrency(tradeCurrency.getCode()) || tradeCurrency.equals(BSQ)) {
return;
}
TOP_ALTCOIN = tradeCurrency;
}
}