prompt for password on withdraw if password is set

This commit is contained in:
woodser 2023-08-18 13:04:43 -04:00
parent 9b873cf149
commit 8411ebc443

View File

@ -73,6 +73,7 @@ public class WithdrawalView extends ActivatableView<VBox, Void> {
private final XmrWalletService xmrWalletService;
private final TradeManager tradeManager;
private final P2PService p2PService;
private final WalletPasswordWindow walletPasswordWindow;
private XmrBalanceListener balanceListener;
private BigInteger amount = BigInteger.valueOf(0);
private ChangeListener<String> amountListener;
@ -96,6 +97,7 @@ public class WithdrawalView extends ActivatableView<VBox, Void> {
this.xmrWalletService = xmrWalletService;
this.tradeManager = tradeManager;
this.p2PService = p2PService;
this.walletPasswordWindow = walletPasswordWindow;
}
@Override
@ -215,12 +217,34 @@ public class WithdrawalView extends ActivatableView<VBox, Void> {
HavenoUtils.formatXmr(receiverAmount, true));
// popup confirmation message
new Popup().headLine(Res.get("funds.withdrawal.confirmWithdrawalRequest"))
Popup popup = new Popup();
popup.headLine(Res.get("funds.withdrawal.confirmWithdrawalRequest"))
.confirmation(messageText)
.actionButtonText(Res.get("shared.yes"))
.onAction(() -> {
if (xmrWalletService.isWalletEncrypted()) {
walletPasswordWindow.headLine(Res.get("walletPasswordWindow.headline")).onSuccess(() -> {
relayTx(tx, withdrawToAddress, amount, fee);
}).onClose(() -> {
popup.hide();
}).hideForgotPasswordButton().show();
} else {
relayTx(tx, withdrawToAddress, amount, fee);
}
})
.closeButtonText(Res.get("shared.cancel"))
.show();
} catch (Throwable e) {
if (e.getMessage().contains("enough")) new Popup().warning(Res.get("funds.withdrawal.warn.amountExceeds")).show();
else {
e.printStackTrace();
new Popup().warning(e.getMessage()).show();
}
}
}
}
// relay tx
private void relayTx(MoneroTxWallet tx, String withdrawToAddress, BigInteger receiverAmount, BigInteger fee) {
try {
xmrWalletService.getWallet().relayTx(tx);
xmrWalletService.getWallet().setTxNote(tx.getHash(), withdrawMemoTextField.getText()); // TODO (monero-java): tx note does not persist when tx created then relayed
@ -232,6 +256,7 @@ public class WithdrawalView extends ActivatableView<VBox, Void> {
}
log.debug("onWithdraw onSuccess tx ID:{}", tx.getHash());
// TODO: remove this?
List<Trade> trades = new ArrayList<>(tradeManager.getObservableList());
trades.stream()
.filter(Trade::isPayoutPublished)
@ -243,18 +268,6 @@ public class WithdrawalView extends ActivatableView<VBox, Void> {
} catch (Exception e) {
e.printStackTrace();
}
})
.closeButtonText(Res.get("shared.cancel"))
.show();
} catch (Throwable e) {
if (e.getMessage().contains("enough")) new Popup().warning(Res.get("funds.withdrawal.warn.amountExceeds")).show();
else {
e.printStackTrace();
log.error(e.toString());
new Popup().warning(e.toString()).show();
}
}
}
}