Skip to content

Commit

Permalink
Add "Buy BSQ" button next to trade fee selector
Browse files Browse the repository at this point in the history
- For now it doesn't work when Sell Offer tab is open
  • Loading branch information
Jakub-CZ committed Jan 4, 2021
1 parent 2be4822 commit 1cab0ee
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 34 deletions.
4 changes: 4 additions & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ createOffer.triggerPrice.tooltip=As protecting against drastic price movements y
createOffer.triggerPrice.invalid.tooLow=Value must be higher than {0}
createOffer.triggerPrice.invalid.tooHigh=Value must be lower than {0}

createOffer.buyBsq.popupMessage=Trading fees are paid to fund the Bisq DAO when making or taking an offer. Fees can be paid in BSQ or BTC.\n\n\
Bisq encourages traders to use BSQ by offering a discount of approximately 50%, since BSQ fees help fund Bisq's development. \
This discount varies as the BSQ/BTC rate fluctuates. To maintain the 50% discount target, trading fees are updated every cycle as necessary.

# new entries
createOffer.placeOfferButton=Review: Place offer to {0} bitcoin
createOffer.createOfferFundWalletInfo.headline=Fund your offer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public abstract class MutableOfferView<M extends MutableOfferViewModel<?>> exten
private TitledGroupBg payFundsTitledGroupBg, setDepositTitledGroupBg, paymentTitledGroupBg;
protected TitledGroupBg amountTitledGroupBg;
private BusyAnimation waitingForFundsSpinner;
private AutoTooltipButton nextButton, cancelButton1, cancelButton2, placeOfferButton;
private AutoTooltipButton nextButton, cancelButton1, cancelButton2, placeOfferButton, buyBsqButton;
private Button priceTypeToggleButton;
private InputTextField fixedPriceTextField, marketBasedPriceTextField, triggerPriceInputTextField;
protected InputTextField amountTextField, minAmountTextField, volumeTextField, buyerSecurityDepositInputTextField;
Expand Down Expand Up @@ -260,6 +260,8 @@ protected void doActivate() {
tradeFeeInBtcToggle.setManaged(false);
tradeFeeInBsqToggle.setVisible(false);
tradeFeeInBsqToggle.setManaged(false);
buyBsqButton.setVisible(false);
buyBsqButton.setManaged(false);
}

Label popOverLabel = OfferViewUtil.createPopOverLabel(Res.get("createOffer.triggerPrice.tooltip"));
Expand Down Expand Up @@ -382,6 +384,9 @@ private void onShowPayFundsScreen() {
cancelButton1.setVisible(false);
cancelButton1.setManaged(false);
cancelButton1.setOnAction(null);
buyBsqButton.setVisible(false);
buyBsqButton.setManaged(false);
buyBsqButton.setOnAction(null);

tradeFeeInBtcToggle.setMouseTransparent(true);
tradeFeeInBsqToggle.setMouseTransparent(true);
Expand Down Expand Up @@ -845,6 +850,7 @@ private void createListeners() {
if (DevEnv.isDaoActivated()) {
tradeFeeInBtcToggle.setVisible(newValue);
tradeFeeInBsqToggle.setVisible(newValue);
buyBsqButton.setVisible(newValue);
}
};

Expand Down Expand Up @@ -1061,7 +1067,11 @@ private void addOptionsGroup() {
GridPane.setMargin(advancedOptionsBox, new Insets(Layout.COMPACT_FIRST_ROW_AND_GROUP_DISTANCE, 0, 0, 0));
gridPane.getChildren().add(advancedOptionsBox);

advancedOptionsBox.getChildren().addAll(getBuyerSecurityDepositBox(), getTradeFeeFieldsBox());
Tuple2<AutoTooltipButton, VBox> buyBsqButtonBox = OfferViewUtil.createBuyBsqButtonBox(navigation, preferences);
buyBsqButton = buyBsqButtonBox.first;
buyBsqButton.setVisible(false);

advancedOptionsBox.getChildren().addAll(getBuyerSecurityDepositBox(), getTradeFeeFieldsBox(), buyBsqButtonBox.second);

Tuple2<Button, Button> tuple = add2ButtonsAfterGroup(gridPane, ++gridRow,
Res.get("shared.nextStep"), Res.get("shared.cancel"));
Expand Down
68 changes: 37 additions & 31 deletions desktop/src/main/java/bisq/desktop/main/offer/OfferView.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ protected void activate() {
root.getSelectionModel().selectedItemProperty().addListener(tabChangeListener);
root.getTabs().addListener(tabListChangeListener);
navigation.addListener(navigationListener);
navigation.navigateTo(MainView.class, this.getClass(), OfferBookView.class);
if (offerBookView==null) {
navigation.navigateTo(MainView.class, this.getClass(), OfferBookView.class);
}
}

@Override
Expand All @@ -164,39 +166,43 @@ private void loadView(Class<? extends View> viewClass) {
View view;
boolean isBuy = direction == OfferPayload.Direction.BUY;

if (viewClass == OfferBookView.class && offerBookView == null) {
view = viewLoader.load(viewClass);
// Offerbook must not be cached by ViewLoader as we use 2 instances for sell and buy screens.
offerBookTab = new Tab(isBuy ? Res.get("shared.buyBitcoin").toUpperCase() : Res.get("shared.sellBitcoin").toUpperCase());
offerBookTab.setClosable(false);
offerBookTab.setContent(view.getRoot());
tabPane.getTabs().add(offerBookTab);
offerBookView = (OfferBookView) view;
offerBookView.onTabSelected(true);

OfferActionHandler offerActionHandler = new OfferActionHandler() {
@Override
public void onCreateOffer(TradeCurrency tradeCurrency) {
if (createOfferViewOpen) {
tabPane.getTabs().remove(createOfferTab);
}
if (canCreateOrTakeOffer()) {
openCreateOffer(tradeCurrency);
if (viewClass == OfferBookView.class) {
if (offerBookTab != null && offerBookView != null) {
tabPane.getSelectionModel().select(offerBookTab);
} else {
view = viewLoader.load(viewClass);
// Offerbook must not be cached by ViewLoader as we use 2 instances for sell and buy screens.
offerBookTab = new Tab(isBuy ? Res.get("shared.buyBitcoin").toUpperCase() : Res.get("shared.sellBitcoin").toUpperCase());
offerBookTab.setClosable(false);
offerBookTab.setContent(view.getRoot());
tabPane.getTabs().add(offerBookTab);
offerBookView = (OfferBookView) view;
offerBookView.onTabSelected(true);

OfferActionHandler offerActionHandler = new OfferActionHandler() {
@Override
public void onCreateOffer(TradeCurrency tradeCurrency) {
if (createOfferViewOpen) {
tabPane.getTabs().remove(createOfferTab);
}
if (canCreateOrTakeOffer()) {
openCreateOffer(tradeCurrency);
}
}
}

@Override
public void onTakeOffer(Offer offer) {
if (takeOfferViewOpen) {
tabPane.getTabs().remove(takeOfferTab);
}
if (canCreateOrTakeOffer()) {
openTakeOffer(offer);
@Override
public void onTakeOffer(Offer offer) {
if (takeOfferViewOpen) {
tabPane.getTabs().remove(takeOfferTab);
}
if (canCreateOrTakeOffer()) {
openTakeOffer(offer);
}
}
}
};
offerBookView.setOfferActionHandler(offerActionHandler);
offerBookView.setDirection(direction);
};
offerBookView.setOfferActionHandler(offerActionHandler);
offerBookView.setDirection(direction);
}
} else if (viewClass == CreateOfferView.class && createOfferView == null) {
view = viewLoader.load(viewClass);
// CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times
Expand Down
36 changes: 36 additions & 0 deletions desktop/src/main/java/bisq/desktop/main/offer/OfferViewUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,23 @@

package bisq.desktop.main.offer;

import bisq.desktop.Navigation;
import bisq.desktop.components.AutoTooltipButton;
import bisq.desktop.main.MainView;
import bisq.desktop.main.offer.offerbook.OfferBookView;
import bisq.desktop.main.overlays.popups.Popup;

import bisq.core.locale.Res;
import bisq.core.user.Preferences;

import bisq.common.util.Tuple2;

import javafx.scene.control.Label;
import javafx.scene.layout.VBox;

import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;

/**
* Reusable methods for CreateOfferView, TakeOfferView or other related views
Expand All @@ -33,4 +47,26 @@ public static Label createPopOverLabel(String text) {
label.setPadding(new Insets(10));
return label;
}

public static Tuple2<AutoTooltipButton, VBox> createBuyBsqButtonBox(Navigation navigation, Preferences preferences) {
String buyBsqText = Res.get("shared.buyCurrency", "BSQ");
var buyBsqButton = new AutoTooltipButton(buyBsqText);
buyBsqButton.getStyleClass().add("action-button");
buyBsqButton.setStyle("-fx-pref-height: 20; -fx-padding: 3 8 3 8; -fx-font-size: 0.769em; -fx-border-radius: 5;");
buyBsqButton.setOnAction(e -> new Popup().headLine(buyBsqText)
.information(Res.get("createOffer.buyBsq.popupMessage"))
.actionButtonText(buyBsqText)
.buttonAlignment(HPos.CENTER)
.onAction(() -> {
preferences.setSellScreenCurrencyCode("BSQ");
navigation.navigateTo(MainView.class, SellOfferView.class, OfferBookView.class);
}).show());

final VBox buyBsqButtonVBox = new VBox(buyBsqButton);
buyBsqButtonVBox.setAlignment(Pos.BOTTOM_LEFT);
buyBsqButtonVBox.setPadding(new Insets(0, 0, 0, -20));
VBox.setMargin(buyBsqButton, new Insets(0, 0, 4, 0));

return new Tuple2<>(buyBsqButton, buyBsqButtonVBox);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,9 @@ private void addOptionsGroup() {
GridPane.setMargin(advancedOptionsBox, new Insets(Layout.COMPACT_FIRST_ROW_AND_GROUP_DISTANCE, 0, 0, 0));
gridPane.getChildren().add(advancedOptionsBox);

advancedOptionsBox.getChildren().addAll(getTradeFeeFieldsBox());
Tuple2<AutoTooltipButton, VBox> buyBsqButtonBox = OfferViewUtil.createBuyBsqButtonBox(navigation, model.dataModel.preferences);

advancedOptionsBox.getChildren().addAll(getTradeFeeFieldsBox(), buyBsqButtonBox.second);
}

private void addButtons() {
Expand Down

0 comments on commit 1cab0ee

Please sign in to comment.