From 2b248c542659848e5bd31a841365cc89273c0fcf Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sun, 26 Nov 2017 20:06:11 -0500 Subject: [PATCH] Separate fees in trade complete screen. Show withdrawal btc address only after button click --- .../resources/i18n/displayStrings.properties | 4 +- .../pendingtrades/PendingTradesDataModel.java | 37 ++++++-- .../pendingtrades/PendingTradesViewModel.java | 29 +++++-- .../steps/buyer/BuyerStep4View.java | 87 +++++++++++-------- 4 files changed, 103 insertions(+), 54 deletions(-) diff --git a/common/src/main/resources/i18n/displayStrings.properties b/common/src/main/resources/i18n/displayStrings.properties index 3b84fd5fc4..6b87b6cd7a 100644 --- a/common/src/main/resources/i18n/displayStrings.properties +++ b/common/src/main/resources/i18n/displayStrings.properties @@ -560,7 +560,9 @@ portfolio.pending.step3_seller.onPaymentReceived.confirm.headline=Confirm that y portfolio.pending.step3_seller.onPaymentReceived.confirm.yes=Yes, I have received the payment portfolio.pending.step5_buyer.groupTitle=Summary of completed trade -portfolio.pending.step5_buyer.totalPaid=Total fees paid: +portfolio.pending.step5_buyer.tradeFee=Trade fee: +portfolio.pending.step5_buyer.makersMiningFee=Mining fee: +portfolio.pending.step5_buyer.takersMiningFee=Total mining fees: portfolio.pending.step5_buyer.refunded=Refunded security deposit: portfolio.pending.step5_buyer.withdrawBTC=Withdraw your bitcoin portfolio.pending.step5_buyer.amount=Amount to withdraw: diff --git a/gui/src/main/java/io/bisq/gui/main/portfolio/pendingtrades/PendingTradesDataModel.java b/gui/src/main/java/io/bisq/gui/main/portfolio/pendingtrades/PendingTradesDataModel.java index 9219056907..fb3c8a7309 100644 --- a/gui/src/main/java/io/bisq/gui/main/portfolio/pendingtrades/PendingTradesDataModel.java +++ b/gui/src/main/java/io/bisq/gui/main/portfolio/pendingtrades/PendingTradesDataModel.java @@ -223,24 +223,45 @@ public class PendingTradesDataModel extends ActivatableDataModel { return tradeManager.isMyOffer(offer); } - private boolean isMaker() { + public boolean isMaker() { return isMaker; } - Coin getTotalFees() { + Coin getTradeFeeInBTC() { + Trade trade = getTrade(); + if (trade != null) { + Offer offer = trade.getOffer(); + if (isMaker()) { + if (offer.isCurrencyForMakerFeeBtc()) + return offer.getMakerFee(); + else + return Coin.ZERO;// getTradeFeeAsBsq is used for BSQ + } else { + if (trade.isCurrencyForTakerFeeBtc()) + return trade.getTakerFee(); + else + return Coin.ZERO; // getTradeFeeAsBsq is used for BSQ + } + } else { + log.error("Trade is null at getTotalFees"); + return Coin.ZERO; + } + } + + Coin getTxFee() { Trade trade = getTrade(); if (trade != null) { if (isMaker()) { Offer offer = trade.getOffer(); if (offer.isCurrencyForMakerFeeBtc()) - return offer.getMakerFee().add(offer.getTxFee()); + return offer.getTxFee(); else - return offer.getTxFee().subtract(offer.getMakerFee()); + return offer.getTxFee().subtract(offer.getMakerFee()); // BSQ will be used as part of the miner fee } else { if (trade.isCurrencyForTakerFeeBtc()) - return trade.getTakerFee().add(trade.getTxFee().multiply(3)); + return trade.getTxFee().multiply(3); else - return trade.getTxFee().multiply(3).subtract(trade.getTakerFee()); + return trade.getTxFee().multiply(3).subtract(trade.getTakerFee()); // BSQ will be used as part of the miner fee } } else { log.error("Trade is null at getTotalFees"); @@ -254,12 +275,12 @@ public class PendingTradesDataModel extends ActivatableDataModel { if (isMaker()) { Offer offer = trade.getOffer(); if (offer.isCurrencyForMakerFeeBtc()) - return Coin.ZERO; + return Coin.ZERO; // getTradeFeeInBTC is used for BTC else return offer.getMakerFee(); } else { if (trade.isCurrencyForTakerFeeBtc()) - return Coin.ZERO; + return Coin.ZERO; // getTradeFeeInBTC is used for BTC else return trade.getTakerFee(); } diff --git a/gui/src/main/java/io/bisq/gui/main/portfolio/pendingtrades/PendingTradesViewModel.java b/gui/src/main/java/io/bisq/gui/main/portfolio/pendingtrades/PendingTradesViewModel.java index 143dff8992..738c417cc3 100644 --- a/gui/src/main/java/io/bisq/gui/main/portfolio/pendingtrades/PendingTradesViewModel.java +++ b/gui/src/main/java/io/bisq/gui/main/portfolio/pendingtrades/PendingTradesViewModel.java @@ -35,7 +35,9 @@ import io.bisq.gui.util.BsqFormatter; import io.bisq.gui.util.GUIUtil; import io.bisq.gui.util.validation.BtcAddressValidator; import io.bisq.network.p2p.P2PService; -import javafx.beans.property.*; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.ReadOnlyObjectProperty; +import javafx.beans.property.SimpleObjectProperty; import org.bitcoinj.core.Coin; import org.fxmisc.easybind.EasyBind; import org.fxmisc.easybind.Subscription; @@ -242,15 +244,24 @@ public class PendingTradesViewModel extends ActivatableWithDataModel tuple2 = addLabelInputTextField(gridPane, ++gridRow, Res.get("portfolio.pending.step5_buyer.withdrawToAddress")); + withdrawAddressLabel = tuple2.first; + withdrawAddressLabel.setManaged(false); + withdrawAddressLabel.setVisible(false); + withdrawAddressTextField = tuple2.second; + withdrawAddressTextField.setManaged(false); + withdrawAddressTextField.setVisible(false); HBox hBox = new HBox(); hBox.setSpacing(10); @@ -142,7 +156,7 @@ public class BuyerStep4View extends TradeStepView { handleTradeCompleted(); model.dataModel.tradeManager.addTradeToClosedTrades(trade); }); - withdrawToExternalWalletButton.setOnAction(e -> reviewWithdrawal()); + withdrawToExternalWalletButton.setOnAction(e -> onWithdrawal()); String key = "tradeCompleted" + trade.getId(); //noinspection ConstantConditions @@ -155,6 +169,16 @@ public class BuyerStep4View extends TradeStepView { } } + private void onWithdrawal() { + withdrawAddressLabel.setManaged(true); + withdrawAddressLabel.setVisible(true); + withdrawAddressTextField.setManaged(true); + withdrawAddressTextField.setVisible(true); + GridPane.setRowSpan(withdrawTitledGroupBg, 2); + withdrawToExternalWalletButton.setDefaultButton(true); + withdrawToExternalWalletButton.setOnAction(e -> reviewWithdrawal()); + } + @SuppressWarnings("PointlessBooleanExpression") private void reviewWithdrawal() { Coin amount = trade.getPayoutAmount(); @@ -177,37 +201,28 @@ public class BuyerStep4View extends TradeStepView { if (toAddresses.isEmpty()) { validateWithdrawAddress(); } else if (Restrictions.isAboveDust(amount, fee)) { - if (DevEnv.DEV_MODE) { - doWithdrawal(amount, fee); - } else { - BSFormatter formatter = model.btcFormatter; - //noinspection ConstantConditions - if (!DevEnv.DEV_MODE) { - int txSize = feeEstimationTransaction.bitcoinSerialize().length; - double feePerByte = CoinUtil.getFeePerByte(fee, txSize); - double kb = txSize / 1000d; - String recAmount = formatter.formatCoinWithCode(receiverAmount); - new Popup<>().headLine(Res.get("portfolio.pending.step5_buyer.confirmWithdrawal")) - .confirmation(Res.get("shared.sendFundsDetailsWithFee", - formatter.formatCoinWithCode(amount), - fromAddresses, - toAddresses, - formatter.formatCoinWithCode(fee), - feePerByte, - kb, - recAmount)) - .actionButtonText(Res.get("shared.yes")) - .onAction(() -> doWithdrawal(amount, fee)) - .closeButtonText(Res.get("shared.cancel")) - .onClose(() -> { - useSavingsWalletButton.setDisable(false); - withdrawToExternalWalletButton.setDisable(false); - }) - .show(); - } else { - doWithdrawal(amount, fee); - } - } + BSFormatter formatter = model.btcFormatter; + int txSize = feeEstimationTransaction.bitcoinSerialize().length; + double feePerByte = CoinUtil.getFeePerByte(fee, txSize); + double kb = txSize / 1000d; + String recAmount = formatter.formatCoinWithCode(receiverAmount); + new Popup<>().headLine(Res.get("portfolio.pending.step5_buyer.confirmWithdrawal")) + .confirmation(Res.get("shared.sendFundsDetailsWithFee", + formatter.formatCoinWithCode(amount), + fromAddresses, + toAddresses, + formatter.formatCoinWithCode(fee), + feePerByte, + kb, + recAmount)) + .actionButtonText(Res.get("shared.yes")) + .onAction(() -> doWithdrawal(amount, fee)) + .closeButtonText(Res.get("shared.cancel")) + .onClose(() -> { + useSavingsWalletButton.setDisable(false); + withdrawToExternalWalletButton.setDisable(false); + }) + .show(); } else { new Popup<>().warning(Res.get("portfolio.pending.step5_buyer.amountTooLow")).show(); }