Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add encrypted wallet password prompt when sending funds from BSQ wallet #4780

Merged
merged 1 commit into from Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -53,6 +54,7 @@

import bisq.network.p2p.P2PService;

import bisq.common.UserThread;
import bisq.common.handlers.ResultHandler;

import org.bitcoinj.core.Coin;
Expand All @@ -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;
Expand All @@ -86,6 +90,7 @@ public class BsqSendView extends ActivatableView<GridPane, Void> 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;
Expand Down Expand Up @@ -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;
Expand All @@ -127,6 +133,7 @@ private BsqSendView(BsqWalletService bsqWalletService,
this.btcValidator = btcValidator;
this.bsqAddressValidator = bsqAddressValidator;
this.btcAddressValidator = btcAddressValidator;
this.walletPasswordWindow = walletPasswordWindow;
}

@Override
Expand Down Expand Up @@ -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());
Expand All @@ -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);
}
}