From 48a515be01dd674d241be04cddb18c0e823e91b4 Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Tue, 10 Nov 2020 19:35:31 -0600 Subject: [PATCH] Add encrypted wallet password prompt when sending funds from BSQ wallet Correct wording of transaction confirmation popup to use 'mining fee' instead of 'transaction fee' to make it consistent with wording of the BTC confirmation popup. --- .../resources/i18n/displayStrings.properties | 2 +- .../main/dao/wallet/send/BsqSendView.java | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index a68cd42224c..e65e1126dfe 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -2262,7 +2262,7 @@ dao.wallet.send.setDestinationAddress=Fill in your destination address dao.wallet.send.send=Send BSQ funds dao.wallet.send.sendBtc=Send BTC funds dao.wallet.send.sendFunds.headline=Confirm withdrawal request -dao.wallet.send.sendFunds.details=Sending: {0}\nTo receiving address: {1}.\nRequired transaction fee is: {2} ({3} satoshis/byte)\nTransaction size: {4} Kb\n\nThe recipient will receive: {5}\n\nAre you sure you want to withdraw that amount? +dao.wallet.send.sendFunds.details=Sending: {0}\nTo receiving address: {1}.\nRequired mining fee is: {2} ({3} satoshis/byte)\nTransaction size: {4} Kb\n\nThe recipient will receive: {5}\n\nAre you sure you want to withdraw that amount? dao.wallet.chainHeightSynced=Latest verified block: {0} dao.wallet.chainHeightSyncing=Awaiting blocks... Verified {0} blocks out of {1} dao.wallet.tx.type=Type diff --git a/desktop/src/main/java/bisq/desktop/main/dao/wallet/send/BsqSendView.java b/desktop/src/main/java/bisq/desktop/main/dao/wallet/send/BsqSendView.java index 0c8a6cd8418..fa638c4a19c 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/wallet/send/BsqSendView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/wallet/send/BsqSendView.java @@ -27,6 +27,7 @@ import bisq.desktop.main.funds.FundsView; import bisq.desktop.main.funds.deposit.DepositView; import bisq.desktop.main.overlays.popups.Popup; +import bisq.desktop.main.overlays.windows.WalletPasswordWindow; import bisq.desktop.util.GUIUtil; import bisq.desktop.util.Layout; import bisq.desktop.util.validation.BsqAddressValidator; @@ -53,6 +54,7 @@ import bisq.network.p2p.P2PService; +import bisq.common.UserThread; import bisq.common.handlers.ResultHandler; import org.bitcoinj.core.Coin; @@ -67,6 +69,8 @@ import javafx.beans.value.ChangeListener; +import java.util.concurrent.TimeUnit; + import static bisq.desktop.util.FormBuilder.addButtonAfterGroup; import static bisq.desktop.util.FormBuilder.addInputTextField; import static bisq.desktop.util.FormBuilder.addTitledGroupBg; @@ -86,6 +90,7 @@ public class BsqSendView extends ActivatableView implements BsqB private final BtcValidator btcValidator; private final BsqAddressValidator bsqAddressValidator; private final BtcAddressValidator btcAddressValidator; + private final WalletPasswordWindow walletPasswordWindow; private int gridRow = 0; private InputTextField amountInputTextField, btcAmountInputTextField; @@ -113,7 +118,8 @@ private BsqSendView(BsqWalletService bsqWalletService, BsqValidator bsqValidator, BtcValidator btcValidator, BsqAddressValidator bsqAddressValidator, - BtcAddressValidator btcAddressValidator) { + BtcAddressValidator btcAddressValidator, + WalletPasswordWindow walletPasswordWindow) { this.bsqWalletService = bsqWalletService; this.btcWalletService = btcWalletService; this.walletsManager = walletsManager; @@ -127,6 +133,7 @@ private BsqSendView(BsqWalletService bsqWalletService, this.btcValidator = btcValidator; this.bsqAddressValidator = bsqAddressValidator; this.btcAddressValidator = btcAddressValidator; + this.walletPasswordWindow = walletPasswordWindow; } @Override @@ -362,7 +369,7 @@ private void showPublishTxPopup(Coin receiverAmount, amountFormatter.formatCoinWithCode(receiverAmount))) .actionButtonText(Res.get("shared.yes")) .onAction(() -> { - walletsManager.publishAndCommitBsqTx(txWithBtcFee, txType, new TxBroadcaster.Callback() { + doWithdraw(txWithBtcFee, txType, new TxBroadcaster.Callback() { @Override public void onSuccess(Transaction transaction) { log.debug("Successfully sent tx with id {}", txWithBtcFee.getTxId().toString()); @@ -378,5 +385,19 @@ public void onFailure(TxBroadcastException exception) { .closeButtonText(Res.get("shared.cancel")) .show(); } + + private void doWithdraw(Transaction txWithBtcFee, TxType txType, TxBroadcaster.Callback callback) { + if (btcWalletService.isEncrypted()) { + UserThread.runAfter(() -> walletPasswordWindow.onAesKey(aesKey -> + sendFunds(txWithBtcFee, txType, callback)) + .show(), 300, TimeUnit.MILLISECONDS); + } else { + sendFunds(txWithBtcFee, txType, callback); + } + } + + private void sendFunds(Transaction txWithBtcFee, TxType txType, TxBroadcaster.Callback callback) { + walletsManager.publishAndCommitBsqTx(txWithBtcFee, txType, callback); + } }