Add info popup for mining fee at deposit funds

This commit is contained in:
Manfred Karrer 2016-05-25 12:04:29 +02:00
parent 5787ef8c1b
commit a677187fe1
6 changed files with 105 additions and 60 deletions

View File

@ -47,6 +47,9 @@ public final class Preferences implements Persistable {
private static final Logger log = LoggerFactory.getLogger(Preferences.class);
public static Preferences INSTANCE;
// Deactivate mBit for now as most screens are not supporting it yet
private static final List<String> BTC_DENOMINATIONS = Arrays.asList(MonetaryFormat.CODE_BTC/*, MonetaryFormat.CODE_MBTC*/);
transient static final private ArrayList<BlockChainExplorer> blockChainExplorersTestNet = new ArrayList<>(Arrays.asList(
@ -128,6 +131,7 @@ public final class Preferences implements Persistable {
@Inject
public Preferences(Storage<Preferences> storage, BitsquareEnvironment bitsquareEnvironment) {
log.debug("Preferences " + this);
INSTANCE = this;
this.storage = storage;
this.bitsquareEnvironment = bitsquareEnvironment;

View File

@ -21,6 +21,7 @@ import de.jensd.fx.fontawesome.AwesomeDude;
import de.jensd.fx.fontawesome.AwesomeIcon;
import io.bitsquare.common.util.Utilities;
import io.bitsquare.gui.main.overlays.popups.Popup;
import io.bitsquare.gui.util.GUIUtil;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
@ -55,7 +56,7 @@ public class AddressTextField extends AnchorPane {
textField.textProperty().bind(address);
String tooltipText = "Open your default bitcoin wallet";
Tooltip.install(textField, new Tooltip(tooltipText));
textField.setOnMouseClicked(mouseEvent -> openExtWallet());
textField.setOnMouseClicked(mouseEvent -> GUIUtil.showFeeInfoBeforeExecute(this::openWallet));
textField.focusTraversableProperty().set(focusTraversableProperty().get());
//TODO app wide focus
//focusedProperty().addListener((ov, oldValue, newValue) -> textField.requestFocus());
@ -65,17 +66,17 @@ public class AddressTextField extends AnchorPane {
extWalletIcon.getStyleClass().add("copy-icon");
Tooltip.install(extWalletIcon, new Tooltip(tooltipText));
AwesomeDude.setIcon(extWalletIcon, AwesomeIcon.SIGNIN);
extWalletIcon.setOnMouseClicked(e -> openExtWallet());
extWalletIcon.setOnMouseClicked(e -> GUIUtil.showFeeInfoBeforeExecute(this::openWallet));
Label copyIcon = new Label();
copyIcon.setLayoutY(3);
copyIcon.getStyleClass().add("copy-icon");
Tooltip.install(copyIcon, new Tooltip("Copy address to clipboard"));
AwesomeDude.setIcon(copyIcon, AwesomeIcon.COPY);
copyIcon.setOnMouseClicked(e -> {
copyIcon.setOnMouseClicked(e -> GUIUtil.showFeeInfoBeforeExecute(() -> {
if (address.get() != null && address.get().length() > 0)
Utilities.copyToClipboard(address.get());
});
}));
AnchorPane.setRightAnchor(copyIcon, 5.0);
AnchorPane.setRightAnchor(extWalletIcon, 30.0);
@ -85,7 +86,7 @@ public class AddressTextField extends AnchorPane {
getChildren().addAll(textField, extWalletIcon, copyIcon);
}
private void openExtWallet() {
private void openWallet() {
try {
Utilities.openURI(URI.create(getBitcoinURI()));
} catch (Exception e) {

View File

@ -23,6 +23,7 @@ import io.bitsquare.btc.AddressEntry;
import io.bitsquare.btc.Restrictions;
import io.bitsquare.btc.WalletService;
import io.bitsquare.btc.listeners.BalanceListener;
import io.bitsquare.common.UserThread;
import io.bitsquare.common.util.Tuple2;
import io.bitsquare.common.util.Utilities;
import io.bitsquare.gui.common.view.ActivatableView;
@ -34,6 +35,7 @@ import io.bitsquare.gui.components.TitledGroupBg;
import io.bitsquare.gui.main.overlays.popups.Popup;
import io.bitsquare.gui.main.overlays.windows.QRCodeWindow;
import io.bitsquare.gui.util.BSFormatter;
import io.bitsquare.gui.util.GUIUtil;
import io.bitsquare.gui.util.Layout;
import io.bitsquare.user.Preferences;
import javafx.beans.property.ReadOnlyObjectWrapper;
@ -61,6 +63,7 @@ import org.jetbrains.annotations.NotNull;
import javax.inject.Inject;
import java.io.ByteArrayInputStream;
import java.util.concurrent.TimeUnit;
import static io.bitsquare.gui.util.FormBuilder.*;
@ -141,7 +144,11 @@ public class DepositView extends ActivatableView<VBox, Void> {
qrCodeImageView = new ImageView();
qrCodeImageView.setStyle("-fx-cursor: hand;");
Tooltip.install(qrCodeImageView, new Tooltip("Open large QR-Code window"));
qrCodeImageView.setOnMouseClicked(e -> new QRCodeWindow(getBitcoinURI()).show());
qrCodeImageView.setOnMouseClicked(e -> GUIUtil.showFeeInfoBeforeExecute(
() -> UserThread.runAfter(
() -> new QRCodeWindow(getBitcoinURI()).show(),
200, TimeUnit.MILLISECONDS)
));
GridPane.setRowIndex(qrCodeImageView, gridRow);
GridPane.setColumnIndex(qrCodeImageView, 1);
GridPane.setMargin(qrCodeImageView, new Insets(Layout.FIRST_ROW_DISTANCE, 0, 0, 0));

View File

@ -41,6 +41,7 @@ import io.bitsquare.gui.main.overlays.windows.QRCodeWindow;
import io.bitsquare.gui.main.portfolio.PortfolioView;
import io.bitsquare.gui.main.portfolio.openoffer.OpenOffersView;
import io.bitsquare.gui.util.FormBuilder;
import io.bitsquare.gui.util.GUIUtil;
import io.bitsquare.gui.util.Layout;
import io.bitsquare.locale.BSResources;
import io.bitsquare.locale.TradeCurrency;
@ -828,7 +829,11 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
qrCodeImageView.setVisible(false);
qrCodeImageView.setStyle("-fx-cursor: hand;");
Tooltip.install(qrCodeImageView, new Tooltip("Open large QR-Code window"));
qrCodeImageView.setOnMouseClicked(e -> new QRCodeWindow(getBitcoinURI()).show());
qrCodeImageView.setOnMouseClicked(e -> GUIUtil.showFeeInfoBeforeExecute(
() -> UserThread.runAfter(
() -> new QRCodeWindow(getBitcoinURI()).show(),
200, TimeUnit.MILLISECONDS)
));
GridPane.setRowIndex(qrCodeImageView, gridRow);
GridPane.setColumnIndex(qrCodeImageView, 2);
GridPane.setRowSpan(qrCodeImageView, 3);
@ -859,15 +864,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
label.setPadding(new Insets(5, 0, 0, 0));
fundFromExternalWalletButton = new Button("Open your external wallet for funding");
fundFromExternalWalletButton.setDefaultButton(false);
fundFromExternalWalletButton.setOnAction(e -> {
try {
Utilities.openURI(URI.create(getBitcoinURI()));
} catch (Exception ex) {
log.warn(ex.getMessage());
new Popup().warning("Opening a default bitcoin wallet application has failed. " +
"Perhaps you don't have one installed?").show();
}
});
fundFromExternalWalletButton.setOnAction(e -> GUIUtil.showFeeInfoBeforeExecute(this::openWallet));
spinner = new ProgressIndicator(0);
spinner.setPrefHeight(18);
spinner.setPrefWidth(18);
@ -908,6 +905,16 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
cancelButton2.setVisible(false);
}
private void openWallet() {
try {
Utilities.openURI(URI.create(getBitcoinURI()));
} catch (Exception ex) {
log.warn(ex.getMessage());
new Popup().warning("Opening a default bitcoin wallet application has failed. " +
"Perhaps you don't have one installed?").show();
}
}
@NotNull
private String getBitcoinURI() {
return model.getAddressAsString() != null ? BitcoinURI.convertToBitcoinURI(model.getAddressAsString(), model.dataModel.missingCoin.get(),

View File

@ -42,6 +42,7 @@ import io.bitsquare.gui.main.overlays.windows.QRCodeWindow;
import io.bitsquare.gui.main.portfolio.PortfolioView;
import io.bitsquare.gui.main.portfolio.pendingtrades.PendingTradesView;
import io.bitsquare.gui.util.BSFormatter;
import io.bitsquare.gui.util.GUIUtil;
import io.bitsquare.gui.util.Layout;
import io.bitsquare.locale.BSResources;
import io.bitsquare.payment.PaymentAccount;
@ -195,44 +196,44 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
///////////////////////////////////////////////////////////////////////////////////////////
public void initWithData(Offer offer) {
model.initWithData(offer);
priceAsPercentageInputBox.setVisible(offer.getUseMarketBasedPrice());
model.initWithData(offer);
priceAsPercentageInputBox.setVisible(offer.getUseMarketBasedPrice());
if (model.getOffer().getDirection() == Offer.Direction.SELL) {
imageView.setId("image-buy-large");
directionLabel.setId("direction-icon-label-buy");
if (model.getOffer().getDirection() == Offer.Direction.SELL) {
imageView.setId("image-buy-large");
directionLabel.setId("direction-icon-label-buy");
takeOfferButton.setId("buy-button-big");
takeOfferButton.setText("Review offer for buying bitcoin");
nextButton.setId("buy-button");
} else {
imageView.setId("image-sell-large");
directionLabel.setId("direction-icon-label-sell");
takeOfferButton.setId("buy-button-big");
takeOfferButton.setText("Review offer for buying bitcoin");
nextButton.setId("buy-button");
} else {
imageView.setId("image-sell-large");
directionLabel.setId("direction-icon-label-sell");
takeOfferButton.setId("sell-button-big");
nextButton.setId("sell-button");
takeOfferButton.setText("Review offer for selling bitcoin");
}
takeOfferButton.setId("sell-button-big");
nextButton.setId("sell-button");
takeOfferButton.setText("Review offer for selling bitcoin");
}
boolean showComboBox = model.getPossiblePaymentAccounts().size() > 1;
paymentAccountsLabel.setVisible(showComboBox);
paymentAccountsLabel.setManaged(showComboBox);
paymentAccountsComboBox.setVisible(showComboBox);
paymentAccountsComboBox.setManaged(showComboBox);
paymentMethodTextField.setVisible(!showComboBox);
paymentMethodTextField.setManaged(!showComboBox);
paymentMethodLabel.setVisible(!showComboBox);
paymentMethodLabel.setManaged(!showComboBox);
if (!showComboBox)
paymentMethodTextField.setText(BSResources.get(model.getPaymentMethod().getId()));
currencyTextField.setText(model.dataModel.getCurrencyNameAndCode());
directionLabel.setText(model.getDirectionLabel());
amountDescriptionLabel.setText(model.getAmountDescription());
amountRangeTextField.setText(model.getAmountRange());
priceTextField.setText(model.getPrice());
priceAsPercentageTextField.setText(model.marketPriceMargin);
addressTextField.setPaymentLabel(model.getPaymentLabel());
addressTextField.setAddress(model.dataModel.getAddressEntry().getAddressString());
boolean showComboBox = model.getPossiblePaymentAccounts().size() > 1;
paymentAccountsLabel.setVisible(showComboBox);
paymentAccountsLabel.setManaged(showComboBox);
paymentAccountsComboBox.setVisible(showComboBox);
paymentAccountsComboBox.setManaged(showComboBox);
paymentMethodTextField.setVisible(!showComboBox);
paymentMethodTextField.setManaged(!showComboBox);
paymentMethodLabel.setVisible(!showComboBox);
paymentMethodLabel.setManaged(!showComboBox);
if (!showComboBox)
paymentMethodTextField.setText(BSResources.get(model.getPaymentMethod().getId()));
currencyTextField.setText(model.dataModel.getCurrencyNameAndCode());
directionLabel.setText(model.getDirectionLabel());
amountDescriptionLabel.setText(model.getAmountDescription());
amountRangeTextField.setText(model.getAmountRange());
priceTextField.setText(model.getPrice());
priceAsPercentageTextField.setText(model.marketPriceMargin);
addressTextField.setPaymentLabel(model.getPaymentLabel());
addressTextField.setAddress(model.dataModel.getAddressEntry().getAddressString());
if (offer.getPrice() == null)
new Popup().warning("You cannot take that offer as it uses a percentage price based on the " +
@ -717,7 +718,11 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
qrCodeImageView.setVisible(false);
qrCodeImageView.setStyle("-fx-cursor: hand;");
Tooltip.install(qrCodeImageView, new Tooltip("Open large QR-Code window"));
qrCodeImageView.setOnMouseClicked(e -> new QRCodeWindow(getBitcoinURI()).show());
qrCodeImageView.setOnMouseClicked(e -> GUIUtil.showFeeInfoBeforeExecute(
() -> UserThread.runAfter(
() -> new QRCodeWindow(getBitcoinURI()).show(),
200, TimeUnit.MILLISECONDS)
));
GridPane.setRowIndex(qrCodeImageView, gridRow);
GridPane.setColumnIndex(qrCodeImageView, 2);
GridPane.setRowSpan(qrCodeImageView, 3);
@ -748,15 +753,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
label.setPadding(new Insets(5, 0, 0, 0));
fundFromExternalWalletButton = new Button("Open your external wallet for funding");
fundFromExternalWalletButton.setDefaultButton(false);
fundFromExternalWalletButton.setOnAction(e -> {
try {
Utilities.openURI(URI.create(getBitcoinURI()));
} catch (Exception ex) {
log.warn(ex.getMessage());
new Popup().warning("Opening a default bitcoin wallet application has failed. " +
"Perhaps you don't have one installed?").show();
}
});
fundFromExternalWalletButton.setOnAction(e -> GUIUtil.showFeeInfoBeforeExecute(this::openWallet));
spinner = new ProgressIndicator(0);
spinner.setPrefHeight(18);
spinner.setPrefWidth(18);
@ -797,6 +794,16 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
cancelButton2.setVisible(false);
}
private void openWallet() {
try {
Utilities.openURI(URI.create(getBitcoinURI()));
} catch (Exception ex) {
log.warn(ex.getMessage());
new Popup().warning("Opening a default bitcoin wallet application has failed. " +
"Perhaps you don't have one installed?").show();
}
}
@NotNull
private String getBitcoinURI() {
String addressString = model.dataModel.getAddressEntry().getAddressString();

View File

@ -17,6 +17,8 @@
package io.bitsquare.gui.util;
import io.bitsquare.gui.main.overlays.popups.Popup;
import io.bitsquare.user.Preferences;
import javafx.geometry.Orientation;
import javafx.scene.Node;
import javafx.scene.control.ScrollBar;
@ -35,4 +37,21 @@ public class GUIUtil {
}
return 0;
}
public static void showFeeInfoBeforeExecute(Runnable runnable) {
String key = "miningFeeInfo";
if (Preferences.INSTANCE.showAgain(key)) {
new Popup<>().information("Please be sure that the mining fee used at your external wallet is " +
"sufficiently high so that the funding transaction will be added to the blockchain.\n" +
"Otherwise the trade transactions cannot be confirmed and a trade would end up in a dispute.\n\n" +
"The recommended fee is about 0.0001 - 0.0002 BTC.\n\n" +
"You can view typically used fees at: https://tradeblock.com/blockchain")
.dontShowAgainId(key, Preferences.INSTANCE)
.onClose(runnable::run)
.closeButtonText("I understand")
.show();
} else {
runnable.run();
}
}
}