From 5be0a3750e3d0d69ee8b56e068f495a1f99fe051 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 30 Jun 2017 21:03:36 +0200 Subject: [PATCH] Add btc address validator to last trade step for withdrawal. Remove dontshow again option for tx summary popup. --- .../core/btc/wallet/BtcWalletService.java | 2 +- .../main/funds/withdrawal/WithdrawalView.java | 6 +- .../steps/buyer/BuyerStep4View.java | 115 +++++++++--------- 3 files changed, 63 insertions(+), 60 deletions(-) diff --git a/core/src/main/java/io/bisq/core/btc/wallet/BtcWalletService.java b/core/src/main/java/io/bisq/core/btc/wallet/BtcWalletService.java index e399fb5437..1264d83a22 100644 --- a/core/src/main/java/io/bisq/core/btc/wallet/BtcWalletService.java +++ b/core/src/main/java/io/bisq/core/btc/wallet/BtcWalletService.java @@ -390,7 +390,7 @@ public class BtcWalletService extends WalletService { public void resetAddressEntriesForPendingTrade(String offerId) { swapTradeEntryToAvailableEntry(offerId, AddressEntry.Context.MULTI_SIG); - swapTradeEntryToAvailableEntry(offerId, AddressEntry.Context.TRADE_PAYOUT); + // Don't swap TRADE_PAYOUT as it might be still open in the last trade step to be used for external transfer } public void swapAnyTradeEntryContextToAvailableEntry(String offerId) { diff --git a/gui/src/main/java/io/bisq/gui/main/funds/withdrawal/WithdrawalView.java b/gui/src/main/java/io/bisq/gui/main/funds/withdrawal/WithdrawalView.java index aa2b87381d..06ef52435a 100644 --- a/gui/src/main/java/io/bisq/gui/main/funds/withdrawal/WithdrawalView.java +++ b/gui/src/main/java/io/bisq/gui/main/funds/withdrawal/WithdrawalView.java @@ -105,11 +105,13 @@ public class WithdrawalView extends ActivatableView { /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private WithdrawalView(BtcWalletService walletService, TradeManager tradeManager, + private WithdrawalView(BtcWalletService walletService, + TradeManager tradeManager, ClosedTradableManager closedTradableManager, FailedTradesManager failedTradesManager, BSFormatter formatter, Preferences preferences, - BtcAddressValidator btcAddressValidator, WalletPasswordWindow walletPasswordWindow) { + BtcAddressValidator btcAddressValidator, + WalletPasswordWindow walletPasswordWindow) { this.walletService = walletService; this.tradeManager = tradeManager; this.closedTradableManager = closedTradableManager; diff --git a/gui/src/main/java/io/bisq/gui/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java b/gui/src/main/java/io/bisq/gui/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java index d8a720420f..1f2c679144 100644 --- a/gui/src/main/java/io/bisq/gui/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java +++ b/gui/src/main/java/io/bisq/gui/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java @@ -40,6 +40,7 @@ import io.bisq.gui.main.portfolio.pendingtrades.PendingTradesViewModel; import io.bisq.gui.main.portfolio.pendingtrades.steps.TradeStepView; import io.bisq.gui.util.BSFormatter; import io.bisq.gui.util.Layout; +import io.bisq.gui.util.validation.BtcAddressValidator; import javafx.geometry.Insets; import javafx.scene.control.Button; import javafx.scene.control.Label; @@ -168,66 +169,66 @@ public class BuyerStep4View extends TradeStepView { AddressEntry fromAddressesEntry = walletService.getOrCreateAddressEntry(trade.getId(), AddressEntry.Context.TRADE_PAYOUT); String fromAddresses = fromAddressesEntry.getAddressString(); String toAddresses = withdrawAddressTextField.getText(); - - Coin balance = walletService.getBalanceForAddress(fromAddressesEntry.getAddress()); - try { - Transaction feeEstimationTransaction = walletService.getFeeEstimationTransaction(fromAddresses, toAddresses, amount, AddressEntry.Context.TRADE_PAYOUT); - Coin fee = feeEstimationTransaction.getFee(); - //noinspection UnusedAssignment - Coin receiverAmount = amount.subtract(fee); - if (balance.isZero()) { - new Popup<>().warning(Res.get("portfolio.pending.step5_buyer.alreadyWithdrawn")).show(); - model.dataModel.tradeManager.addTradeToClosedTrades(trade); - } else { - if (toAddresses.isEmpty()) { - validateWithdrawAddress(); - } else if (Restrictions.isAboveDust(amount, fee)) { - if (DevEnv.DEV_MODE) { - doWithdrawal(amount, fee); - } else { - BSFormatter formatter = model.btcFormatter; - String key = "reviewWithdrawalAtTradeComplete"; - //noinspection ConstantConditions - if (!DevEnv.DEV_MODE && DontShowAgainLookup.showAgain(key)) { - 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); - }) - .dontShowAgainId(key) - .show(); - } else { - doWithdrawal(amount, fee); - } - } - + if (new BtcAddressValidator().validate(toAddresses).isValid) { + Coin balance = walletService.getBalanceForAddress(fromAddressesEntry.getAddress()); + try { + Transaction feeEstimationTransaction = walletService.getFeeEstimationTransaction(fromAddresses, toAddresses, amount, AddressEntry.Context.TRADE_PAYOUT); + Coin fee = feeEstimationTransaction.getFee(); + //noinspection UnusedAssignment + Coin receiverAmount = amount.subtract(fee); + if (balance.isZero()) { + new Popup<>().warning(Res.get("portfolio.pending.step5_buyer.alreadyWithdrawn")).show(); + model.dataModel.tradeManager.addTradeToClosedTrades(trade); } else { - new Popup<>().warning(Res.get("portfolio.pending.step5_buyer.amountTooLow")).show(); + 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); + } + } + } else { + new Popup<>().warning(Res.get("portfolio.pending.step5_buyer.amountTooLow")).show(); + } } + } catch (AddressFormatException e) { + validateWithdrawAddress(); + } catch (AddressEntryException e) { + log.error(e.getMessage()); + } catch (InsufficientFundsException e) { + log.error(e.getMessage()); + e.printStackTrace(); + new Popup<>().warning(e.getMessage()).show(); } - } catch (AddressFormatException e) { - validateWithdrawAddress(); - } catch (AddressEntryException e) { - log.error(e.getMessage()); - } catch (InsufficientFundsException e) { - log.error(e.getMessage()); - e.printStackTrace(); - new Popup<>().warning(e.getMessage()).show(); + } else { + new Popup<>().warning(Res.get("validation.btc.invalidAddress")).show(); } }