Add popup for fee currency selection

This commit is contained in:
Manfred Karrer 2017-11-28 12:52:30 -05:00
parent 06b0bdd28d
commit 96cc6dbe3a
No known key found for this signature in database
GPG Key ID: 401250966A6B2C46
4 changed files with 125 additions and 116 deletions

View File

@ -1236,6 +1236,10 @@ torNetworkSettingWindow.info=If Tor is blocked by your internet provider or in y
Visit the Tor web page at: https://bridges.torproject.org/bridges to learn more about \
bridges and pluggable transports.
feeOptionWindow.headline=Choose currency for trade fee payment
feeOptionWindow.info=You can choose to pay the trade fee in BSQ or in BTC. If you choose BSQ you appreciate the discounted trade fee.
feeOptionWindow.optionsLabel=Choose currency for trade fee payment:
####################################################################
# Popups

View File

@ -48,6 +48,7 @@ import io.bisq.gui.main.funds.FundsView;
import io.bisq.gui.main.funds.withdrawal.WithdrawalView;
import io.bisq.gui.main.offer.OfferView;
import io.bisq.gui.main.overlays.popups.Popup;
import io.bisq.gui.main.overlays.windows.FeeOptionWindow;
import io.bisq.gui.main.overlays.windows.OfferDetailsWindow;
import io.bisq.gui.main.overlays.windows.QRCodeWindow;
import io.bisq.gui.main.portfolio.PortfolioView;
@ -499,7 +500,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
addressTextField.amountAsCoinProperty().bind(model.dataModel.getMissingCoin());
buyerSecurityDepositInputTextField.textProperty().bindBidirectional(model.buyerSecurityDeposit);
if (model.dataModel.isBsqForFeeAvailable()) {
if (model.dataModel.isBsqForFeeAvailable() && makerFeeTextField != null) {
makerFeeTextField.textProperty().bind(model.makerFee);
makerFeeCurrencyLabel.textProperty().bind(model.makerFeeCurrencyCode);
}
@ -552,7 +553,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
addressTextField.amountAsCoinProperty().unbind();
buyerSecurityDepositInputTextField.textProperty().unbindBidirectional(model.buyerSecurityDeposit);
if (model.dataModel.isBsqForFeeAvailable()) {
if (model.dataModel.isBsqForFeeAvailable() && makerFeeTextField != null) {
makerFeeTextField.textProperty().unbind();
makerFeeCurrencyLabel.textProperty().unbind();
}
@ -893,10 +894,13 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
cancelButton1.setManaged(false);
cancelButton1.setOnAction(null);
showFeeOption();
int delay = 500;
int diff = 100;
transitions.fadeOutAndRemove(titledGroupBg, delay, (event) -> onShowPayFundsScreen());
if (model.dataModel.isBsqForFeeAvailable()) {
transitions.fadeOutAndRemove(titledGroupBg, delay, (event) -> {
});
if (model.dataModel.isBsqForFeeAvailable() && makerFeeTextLabel!=null) {
delay -= diff;
transitions.fadeOutAndRemove(makerFeeTextLabel, delay);
transitions.fadeOutAndRemove(makerFeeRowHBox, delay);
@ -914,6 +918,20 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
});
}
private void showFeeOption() {
String key = "";
if (model.dataModel.getPreferences().showAgain(key)) {
new FeeOptionWindow(model.makerFeeWithCode, model.dataModel.isCurrencyForMakerFeeBtc())
.onResultHandler(model::setIsCurrencyForMakerFeeBtc)
.onAction(this::onShowPayFundsScreen)
.hideCloseButton()
.dontShowAgainId(key)
.show();
} else {
onShowPayFundsScreen();
}
}
private void addMakerFeeRow() {
makerFeeTextLabel = addLabel(gridPane, gridRow, Res.getWithCol("createOffer.currencyForFee"),
Layout.FIRST_ROW_AND_GROUP_DISTANCE);
@ -1314,7 +1332,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
private void updateFeeToggleButtons(boolean btcSelected) {
if (model.dataModel.isBsqForFeeAvailable()) {
model.setCurrencyForMakerFeeBtc(btcSelected);
model.setIsCurrencyForMakerFeeBtc(btcSelected);
if (btcSelected || model.dataModel.isBsqForFeeAvailable()) {
if (!payFeeInBtcButton.isSelected() && btcSelected)
payFeeInBtcButton.setSelected(true);

View File

@ -17,60 +17,82 @@
package io.bisq.gui.main.overlays.windows;
import io.bisq.common.app.DevEnv;
import io.bisq.common.locale.Res;
import io.bisq.core.filter.PaymentAccountFilter;
import io.bisq.gui.components.InputTextField;
import io.bisq.common.util.Tuple3;
import io.bisq.gui.main.overlays.Overlay;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import static io.bisq.gui.util.FormBuilder.addLabelCheckBox;
import static io.bisq.gui.util.FormBuilder.addLabelInputTextField;
import static io.bisq.gui.util.FormBuilder.*;
public class FeeOptionWindow extends Overlay<FeeOptionWindow> {
///////////////////////////////////////////////////////////////////////////////////////////
// Interface
///////////////////////////////////////////////////////////////////////////////////////////
public interface ResultHandler {
void handle(boolean isCurrencyForMakerFeeBtc);
}
private TextField makerFeeTextField;
private ChangeListener<Toggle> toggleChangeListener;
private ResultHandler resultHandler;
private final StringProperty makerFeeWithCodeProperty;
private final boolean isCurrencyForMakerFeeBtc;
private ToggleGroup toggleGroup;
///////////////////////////////////////////////////////////////////////////////////////////
// Public API
///////////////////////////////////////////////////////////////////////////////////////////
public FeeOptionWindow() {
public FeeOptionWindow(StringProperty makerFeeWithCodeProperty, boolean isCurrencyForMakerFeeBtc) {
this.makerFeeWithCodeProperty = makerFeeWithCodeProperty;
this.isCurrencyForMakerFeeBtc = isCurrencyForMakerFeeBtc;
type = Type.Attention;
}
public void show() {
if (headLine == null)
headLine = Res.get("header.headline");
headLine = Res.get("feeOptionWindow.headline");
width = 900;
createGridPane();
addHeadLine();
addSeparator();
addContent();
addCloseButton();
addDontShowAgainCheckBox();
applyStyles();
display();
}
public FeeOptionWindow onResultHandler(ResultHandler resultHandler) {
this.resultHandler = resultHandler;
return this;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Protected
///////////////////////////////////////////////////////////////////////////////////////////
@Override
protected void createGridPane() {
super.createGridPane();
gridPane.setStyle("-fx-background-color: -bs-content-bg-grey;" +
"-fx-background-radius: 5 5 5 5;" +
"-fx-effect: dropshadow(gaussian, #999, 10, 0, 0, 0);" +
"-fx-background-insets: 10;"
);
}
@Override
protected void setupKeyHandler(Scene scene) {
if (!hideCloseButton) {
@ -83,103 +105,36 @@ public class FeeOptionWindow extends Overlay<FeeOptionWindow> {
}
}
protected void doClose() {
super.doClose();
if (makerFeeTextField != null)
makerFeeTextField.textProperty().unbind();
if (toggleGroup != null)
toggleGroup.selectedToggleProperty().removeListener(toggleChangeListener);
}
private void addContent() {
InputTextField keyInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("shared.unlock"), 10).second;
if (DevEnv.USE_DEV_PRIVILEGE_KEYS)
keyInputTextField.setText(DevEnv.DEV_PRIVILEGE_PRIV_KEY);
Label label = addLabel(gridPane, ++rowIndex, Res.get("feeOptionWindow.info"));
GridPane.setColumnSpan(label, 2);
GridPane.setHalignment(label, HPos.LEFT);
InputTextField offerIdsInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.offers")).second;
InputTextField nodesInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.onions")).second;
InputTextField paymentAccountFilterInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.accounts")).second;
GridPane.setHalignment(paymentAccountFilterInputTextField, HPos.RIGHT);
InputTextField bannedCurrenciesInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.bannedCurrencies")).second;
InputTextField bannedPaymentMethodsInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.bannedPaymentMethods")).second;
InputTextField arbitratorsInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.arbitrators")).second;
InputTextField seedNodesInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.seedNode")).second;
InputTextField priceRelayNodesInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.priceRelayNode")).second;
CheckBox preventPublicBtcNetworkCheckBox = addLabelCheckBox(gridPane, ++rowIndex, Res.get("filterWindow.preventPublicBtcNetwork")).second;
toggleGroup = new ToggleGroup();
Tuple3<Label, RadioButton, RadioButton> tuple = addLabelRadioButtonRadioButton(gridPane,
++rowIndex,
toggleGroup,
Res.get("feeOptionWindow.optionsLabel"),
"BTC",
"BSQ");
RadioButton radioButtonBTC = tuple.second;
RadioButton radioButtonBSQ = tuple.third;
toggleGroup.selectToggle(isCurrencyForMakerFeeBtc ? radioButtonBTC : radioButtonBSQ);
Button sendButton = new Button(Res.get("filterWindow.add"));
sendButton.setOnAction(e -> {
List<String> offerIds = new ArrayList<>();
List<String> nodes = new ArrayList<>();
List<PaymentAccountFilter> paymentAccountFilters = new ArrayList<>();
List<String> bannedCurrencies = new ArrayList<>();
List<String> bannedPaymentMethods = new ArrayList<>();
List<String> arbitrators = new ArrayList<>();
List<String> seedNodes = new ArrayList<>();
List<String> priceRelayNodes = new ArrayList<>();
toggleChangeListener = (observable, oldValue, newValue) -> {
resultHandler.handle(newValue == radioButtonBTC);
};
toggleGroup.selectedToggleProperty().addListener(toggleChangeListener);
if (!offerIdsInputTextField.getText().isEmpty()) {
offerIds = new ArrayList<>(Arrays.asList(StringUtils.deleteWhitespace(offerIdsInputTextField.getText())
.split(",")));
}
if (!nodesInputTextField.getText().isEmpty()) {
nodes = new ArrayList<>(Arrays.asList(StringUtils.deleteWhitespace(nodesInputTextField.getText())
.replace(":9999", "")
.replace(".onion", "")
.split(",")));
}
if (!paymentAccountFilterInputTextField.getText().isEmpty()) {
paymentAccountFilters = new ArrayList<>(Arrays.asList(paymentAccountFilterInputTextField.getText()
.replace(", ", ",")
.split(","))
.stream().map(item -> {
String[] list = item.split("\\|");
if (list.length == 3)
return new PaymentAccountFilter(list[0], list[1], list[2]);
else
return new PaymentAccountFilter("", "", "");
})
.collect(Collectors.toList()));
}
if (!bannedCurrenciesInputTextField.getText().isEmpty()) {
bannedCurrencies = new ArrayList<>(Arrays.asList(StringUtils.deleteWhitespace(bannedCurrenciesInputTextField.getText())
.split(",")));
}
if (!bannedPaymentMethodsInputTextField.getText().isEmpty()) {
bannedPaymentMethods = new ArrayList<>(Arrays.asList(StringUtils.deleteWhitespace(bannedPaymentMethodsInputTextField.getText())
.split(",")));
}
if (!arbitratorsInputTextField.getText().isEmpty()) {
arbitrators = new ArrayList<>(Arrays.asList(StringUtils.deleteWhitespace(arbitratorsInputTextField.getText())
.replace(":9999", "")
.replace(".onion", "")
.split(",")));
}
if (!seedNodesInputTextField.getText().isEmpty()) {
seedNodes = new ArrayList<>(Arrays.asList(StringUtils.deleteWhitespace(seedNodesInputTextField.getText())
.replace(":9999", "")
.replace(".onion", "")
.split(",")));
}
if (!priceRelayNodesInputTextField.getText().isEmpty()) {
priceRelayNodes = new ArrayList<>(Arrays.asList(StringUtils.deleteWhitespace(priceRelayNodesInputTextField.getText())
.replace(":9999", "")
.replace(".onion", "")
.split(",")));
}
});
closeButton = new Button(Res.get("shared.close"));
closeButton.setOnAction(e -> {
hide();
closeHandlerOptional.ifPresent(Runnable::run);
});
HBox hBox = new HBox();
hBox.setSpacing(10);
GridPane.setRowIndex(hBox, ++rowIndex);
GridPane.setColumnIndex(hBox, 1);
gridPane.getChildren().add(hBox);
GridPane.setMargin(hBox, new Insets(10, 0, 0, 0));
makerFeeTextField = addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("createOffer.currencyForFee"), makerFeeWithCodeProperty.get()).second;
makerFeeTextField.textProperty().bind(makerFeeWithCodeProperty);
}
}

View File

@ -515,6 +515,38 @@ public class FormBuilder {
}
///////////////////////////////////////////////////////////////////////////////////////////
// Label + RadioButton + RadioButton
///////////////////////////////////////////////////////////////////////////////////////////
public static Tuple3<Label, RadioButton, RadioButton> addLabelRadioButtonRadioButton(GridPane gridPane,
int rowIndex,
ToggleGroup toggleGroup,
String title,
String radioButtonTitle1,
String radioButtonTitle2) {
Label label = addLabel(gridPane, rowIndex, title, 0);
RadioButton radioButton1 = new RadioButton(radioButtonTitle1);
radioButton1.setToggleGroup(toggleGroup);
radioButton1.setPadding(new Insets(6, 0, 0, 0));
RadioButton radioButton2 = new RadioButton(radioButtonTitle2);
radioButton2.setToggleGroup(toggleGroup);
radioButton2.setPadding(new Insets(6, 0, 0, 0));
HBox hBox = new HBox();
hBox.setSpacing(10);
hBox.getChildren().addAll(radioButton1, radioButton2);
GridPane.setRowIndex(hBox, rowIndex);
GridPane.setColumnIndex(hBox, 1);
gridPane.getChildren().add(hBox);
return new Tuple3<>(label, radioButton1, radioButton2);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Label + CheckBox
///////////////////////////////////////////////////////////////////////////////////////////