Skip to content

Commit

Permalink
Add encrypted wallet password prompt when sending funds from BSQ wallet
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jmacxx committed Nov 11, 2020
1 parent 0345c79 commit 48a515b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
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);
}
}

0 comments on commit 48a515b

Please sign in to comment.