Skip to content

Commit

Permalink
Set preferred currency as top altcoin
Browse files Browse the repository at this point in the history
If it is a crypto currency and not a fiat currency
  • Loading branch information
ripcurlx committed Apr 22, 2022
1 parent 4447435 commit 7ad2dd0
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
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;
Expand Down Expand Up @@ -413,15 +411,15 @@ private void updateScreenCurrencyInPreferences(OfferDirection direction) {
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());
}
}
Expand Down
20 changes: 12 additions & 8 deletions desktop/src/main/java/bisq/desktop/main/offer/OfferView.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@
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;
Expand Down Expand Up @@ -172,6 +170,12 @@ protected void activate() {
if (btcOfferBookView == null) {
navigation.navigateTo(MainView.class, this.getClass(), BtcOfferBookView.class);
}

GUIUtil.updateTopAltcoin(preferences);

if (topAltcoinOfferBookTab != null) {
topAltcoinOfferBookTab.setText(GUIUtil.TOP_ALTCOIN.getCode());
}
}

@Override
Expand Down Expand Up @@ -205,7 +209,7 @@ private void loadView(Class<? extends View> viewClass,
} 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);
Expand All @@ -215,7 +219,7 @@ private void loadView(Class<? extends View> viewClass,
} 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);
Expand All @@ -239,9 +243,9 @@ private void loadView(Class<? extends View> viewClass,
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);
Expand Down Expand Up @@ -363,9 +367,9 @@ private void showCreateOffer(TradeCurrency tradeCurrency, PaymentMethod paymentM
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;
Expand Down
11 changes: 5 additions & 6 deletions desktop/src/main/java/bisq/desktop/main/offer/OfferViewUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
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;
Expand Down Expand Up @@ -132,9 +131,9 @@ private static void openBuyBsqOfferBook(Navigation navigation) {
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;
Expand Down Expand Up @@ -169,7 +168,7 @@ public static TradeCurrency getAnyOfMainCryptoCurrencies() {
@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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -289,8 +287,8 @@ private Optional<PaymentAccount> getAnyPaymentAccount() {
} 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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
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;
Expand Down Expand Up @@ -70,16 +69,16 @@ public void initWithData(OfferDirection direction,
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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
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;
Expand Down Expand Up @@ -175,7 +174,7 @@ public void initWithData(OfferDirection direction,

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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ Predicate<OfferBookListItem> getCurrencyAndMethodPredicate(OfferDirection direct
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);
Expand Down Expand Up @@ -166,7 +166,7 @@ String getCurrencyCodeFromPreferences(OfferDirection direction) {
@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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

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,
Expand All @@ -77,6 +77,12 @@ public TopAltcoinOfferBookViewModel(User user,
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ private void activateDisplayCurrencies() {
TradeCurrency selectedItem = preferredTradeCurrencyComboBox.getSelectionModel().getSelectedItem();
if (selectedItem != null)
preferences.setPreferredTradeCurrency(selectedItem);
GUIUtil.updateTopAltcoin(preferences);
});

fiatCurrenciesComboBox.setItems(allFiatCurrencies);
Expand Down
10 changes: 9 additions & 1 deletion desktop/src/main/java/bisq/desktop/util/GUIUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1249,4 +1249,12 @@ public static void setDefaultTwoColumnConstraintsForGridPane(GridPane gridPane)
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;
}
}

0 comments on commit 7ad2dd0

Please sign in to comment.