mirror of
https://github.com/bisq-network/bisq.git
synced 2025-01-19 05:44:05 +01:00
Split EmptyWalletWindow into BsqEmptyWalletWindow and BtcEmptyWalletWindow
This commit is contained in:
parent
d12a4049ad
commit
fbfda8e151
@ -23,7 +23,8 @@ import bisq.desktop.common.view.ViewLoader;
|
||||
import bisq.desktop.main.MainView;
|
||||
import bisq.desktop.main.debug.DebugView;
|
||||
import bisq.desktop.main.overlays.popups.Popup;
|
||||
import bisq.desktop.main.overlays.windows.EmptyWalletWindow;
|
||||
import bisq.desktop.main.overlays.windows.BsqEmptyWalletWindow;
|
||||
import bisq.desktop.main.overlays.windows.BtcEmptyWalletWindow;
|
||||
import bisq.desktop.main.overlays.windows.FilterWindow;
|
||||
import bisq.desktop.main.overlays.windows.ManualPayoutTxWindow;
|
||||
import bisq.desktop.main.overlays.windows.SendAlertMessageWindow;
|
||||
@ -31,7 +32,6 @@ import bisq.desktop.main.overlays.windows.ShowWalletDataWindow;
|
||||
import bisq.desktop.util.CssTheme;
|
||||
import bisq.desktop.util.ImageUtil;
|
||||
|
||||
import bisq.core.alert.AlertManager;
|
||||
import bisq.core.app.AppOptionKeys;
|
||||
import bisq.core.app.AvoidStandbyModeService;
|
||||
import bisq.core.app.BisqEnvironment;
|
||||
@ -39,7 +39,6 @@ import bisq.core.app.OSXStandbyModeDisabler;
|
||||
import bisq.core.btc.wallet.BtcWalletService;
|
||||
import bisq.core.btc.wallet.WalletsManager;
|
||||
import bisq.core.dao.governance.voteresult.MissingDataRequestService;
|
||||
import bisq.core.filter.FilterManager;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.offer.OpenOffer;
|
||||
import bisq.core.offer.OpenOfferManager;
|
||||
@ -269,9 +268,9 @@ public class BisqApp extends Application implements UncaughtExceptionHandler {
|
||||
shutDownByUser();
|
||||
} else {
|
||||
if (Utilities.isAltOrCtrlPressed(KeyCode.E, keyEvent)) {
|
||||
showBtcEmergencyWalletPopup(injector);
|
||||
injector.getInstance(BtcEmptyWalletWindow.class).show();
|
||||
} else if (Utilities.isAltOrCtrlPressed(KeyCode.B, keyEvent)) {
|
||||
showBsqEmergencyWalletPopup(injector);
|
||||
injector.getInstance(BsqEmptyWalletWindow.class).show();
|
||||
} else if (Utilities.isAltOrCtrlPressed(KeyCode.M, keyEvent)) {
|
||||
injector.getInstance(SendAlertMessageWindow.class).show();
|
||||
} else if (Utilities.isAltOrCtrlPressed(KeyCode.F, keyEvent)) {
|
||||
@ -336,18 +335,6 @@ public class BisqApp extends Application implements UncaughtExceptionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void showBtcEmergencyWalletPopup(Injector injector) {
|
||||
EmptyWalletWindow emptyWalletWindow = injector.getInstance(EmptyWalletWindow.class);
|
||||
emptyWalletWindow.setIsBtc(true);
|
||||
emptyWalletWindow.show();
|
||||
}
|
||||
|
||||
private void showBsqEmergencyWalletPopup(Injector injector) {
|
||||
EmptyWalletWindow emptyWalletWindow = injector.getInstance(EmptyWalletWindow.class);
|
||||
emptyWalletWindow.setIsBtc(false);
|
||||
emptyWalletWindow.show();
|
||||
}
|
||||
|
||||
// Used for debugging trade process
|
||||
private void showDebugWindow(Scene scene, Injector injector) {
|
||||
ViewLoader viewLoader = injector.getInstance(ViewLoader.class);
|
||||
|
@ -0,0 +1,87 @@
|
||||
package bisq.desktop.main.overlays.windows;
|
||||
|
||||
import bisq.desktop.components.AutoTooltipButton;
|
||||
import bisq.desktop.main.overlays.Overlay;
|
||||
|
||||
import bisq.core.btc.wallet.BsqWalletService;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.util.coin.BsqFormatter;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static bisq.desktop.util.FormBuilder.addTopLabelTextField;
|
||||
|
||||
public final class BsqEmptyWalletWindow extends Overlay<BsqEmptyWalletWindow> {
|
||||
protected static final Logger log = LoggerFactory.getLogger(BtcEmptyWalletWindow.class);
|
||||
|
||||
private final BsqWalletService bsqWalletService;
|
||||
private final BsqFormatter bsqFormatter;
|
||||
|
||||
@Inject
|
||||
public BsqEmptyWalletWindow(BsqWalletService bsqWalletService, BsqFormatter bsqFormatter) {
|
||||
headLine(Res.get("emptyWalletWindow.headline", "BSQ"));
|
||||
width = 768;
|
||||
type = Type.Instruction;
|
||||
this.bsqWalletService = bsqWalletService;
|
||||
this.bsqFormatter = bsqFormatter;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
createGridPane();
|
||||
addHeadLine();
|
||||
addContent();
|
||||
applyStyles();
|
||||
display();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupKeyHandler(Scene scene) {
|
||||
if (!hideCloseButton) {
|
||||
scene.setOnKeyPressed(e -> {
|
||||
if (e.getCode() == KeyCode.ESCAPE) {
|
||||
e.consume();
|
||||
doClose();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void addContent() {
|
||||
gridPane.getColumnConstraints().remove(1);
|
||||
|
||||
addTopLabelTextField(gridPane, ++rowIndex, Res.get("emptyWalletWindow.balance"),
|
||||
bsqFormatter.formatCoinWithCode(bsqWalletService.getAvailableConfirmedBalance()), 10);
|
||||
|
||||
addTopLabelTextField(gridPane, ++rowIndex, Res.get("emptyWalletWindow.bsq.btcBalance"),
|
||||
bsqFormatter.formatBTCWithCode(bsqWalletService.getAvailableNonBsqBalance().value), 10);
|
||||
|
||||
closeButton = new AutoTooltipButton(Res.get("shared.cancel"));
|
||||
closeButton.setOnAction(e -> {
|
||||
hide();
|
||||
closeHandlerOptional.ifPresent(Runnable::run);
|
||||
});
|
||||
|
||||
|
||||
closeButton.setDefaultButton(true);
|
||||
closeButton.updateText(Res.get("shared.close"));
|
||||
|
||||
HBox hBox = new HBox();
|
||||
hBox.setSpacing(10);
|
||||
GridPane.setRowIndex(hBox, ++rowIndex);
|
||||
|
||||
hBox.getChildren().addAll(closeButton);
|
||||
|
||||
gridPane.getChildren().add(hBox);
|
||||
GridPane.setMargin(hBox, new Insets(10, 0, 0, 0));
|
||||
}
|
||||
}
|
@ -1,20 +1,3 @@
|
||||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.desktop.main.overlays.windows;
|
||||
|
||||
import bisq.desktop.components.AutoTooltipButton;
|
||||
@ -25,14 +8,11 @@ import bisq.desktop.util.GUIUtil;
|
||||
import bisq.desktop.util.Transitions;
|
||||
|
||||
import bisq.core.btc.setup.WalletsSetup;
|
||||
import bisq.core.btc.wallet.BsqWalletService;
|
||||
import bisq.core.btc.wallet.BtcWalletService;
|
||||
import bisq.core.btc.wallet.Restrictions;
|
||||
import bisq.core.btc.wallet.WalletService;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.offer.OpenOfferManager;
|
||||
import bisq.core.util.FormattingUtils;
|
||||
import bisq.core.util.coin.BsqFormatter;
|
||||
import bisq.core.util.coin.CoinFormatter;
|
||||
|
||||
import bisq.network.p2p.P2PService;
|
||||
@ -43,7 +23,8 @@ import org.bitcoinj.core.AddressFormatException;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.core.InsufficientMoneyException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import javafx.scene.Scene;
|
||||
@ -66,53 +47,40 @@ import static bisq.desktop.util.FormBuilder.addInputTextField;
|
||||
import static bisq.desktop.util.FormBuilder.addMultilineLabel;
|
||||
import static bisq.desktop.util.FormBuilder.addTopLabelTextField;
|
||||
|
||||
public class EmptyWalletWindow extends Overlay<EmptyWalletWindow> {
|
||||
private static final Logger log = LoggerFactory.getLogger(EmptyWalletWindow.class);
|
||||
public final class BtcEmptyWalletWindow extends Overlay<BtcEmptyWalletWindow> {
|
||||
protected static final Logger log = LoggerFactory.getLogger(BtcEmptyWalletWindow.class);
|
||||
|
||||
private final WalletPasswordWindow walletPasswordWindow;
|
||||
private final OpenOfferManager openOfferManager;
|
||||
private final P2PService p2PService;
|
||||
private final WalletsSetup walletsSetup;
|
||||
private final BtcWalletService btcWalletService;
|
||||
private final BsqWalletService bsqWalletService;
|
||||
private final CoinFormatter btcFormatter;
|
||||
private final BsqFormatter bsqFormatter;
|
||||
private final OpenOfferManager openOfferManager;
|
||||
|
||||
private Button emptyWalletButton;
|
||||
private InputTextField addressInputTextField;
|
||||
private TextField balanceTextField;
|
||||
private boolean isBtc;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Public API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
public EmptyWalletWindow(WalletPasswordWindow walletPasswordWindow,
|
||||
OpenOfferManager openOfferManager,
|
||||
P2PService p2PService,
|
||||
WalletsSetup walletsSetup,
|
||||
BtcWalletService btcWalletService,
|
||||
BsqWalletService bsqWalletService,
|
||||
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter,
|
||||
BsqFormatter bsqFormatter) {
|
||||
this.walletPasswordWindow = walletPasswordWindow;
|
||||
this.openOfferManager = openOfferManager;
|
||||
public BtcEmptyWalletWindow(WalletPasswordWindow walletPasswordWindow,
|
||||
OpenOfferManager openOfferManager,
|
||||
P2PService p2PService,
|
||||
WalletsSetup walletsSetup,
|
||||
BtcWalletService btcWalletService,
|
||||
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter) {
|
||||
headLine(Res.get("emptyWalletWindow.headline", "BTC"));
|
||||
width = 768;
|
||||
type = Type.Instruction;
|
||||
|
||||
this.p2PService = p2PService;
|
||||
this.walletsSetup = walletsSetup;
|
||||
this.btcWalletService = btcWalletService;
|
||||
this.bsqWalletService = bsqWalletService;
|
||||
this.btcFormatter = btcFormatter;
|
||||
this.bsqFormatter = bsqFormatter;
|
||||
|
||||
type = Type.Instruction;
|
||||
this.walletPasswordWindow = walletPasswordWindow;
|
||||
this.openOfferManager = openOfferManager;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if (headLine == null)
|
||||
headLine = Res.get("emptyWalletWindow.headline", getCurrency());
|
||||
|
||||
width = 768;
|
||||
createGridPane();
|
||||
addHeadLine();
|
||||
addContent();
|
||||
@ -120,15 +88,6 @@ public class EmptyWalletWindow extends Overlay<EmptyWalletWindow> {
|
||||
display();
|
||||
}
|
||||
|
||||
private String getCurrency() {
|
||||
return isBtc ? "BTC" : "BSQ";
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Protected
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected void setupKeyHandler(Scene scene) {
|
||||
if (!hideCloseButton) {
|
||||
@ -141,67 +100,44 @@ public class EmptyWalletWindow extends Overlay<EmptyWalletWindow> {
|
||||
}
|
||||
}
|
||||
|
||||
public void setIsBtc(boolean isBtc) {
|
||||
this.isBtc = isBtc;
|
||||
}
|
||||
|
||||
private void addContent() {
|
||||
addMultilineLabel(gridPane, ++rowIndex, Res.get("emptyWalletWindow.info"), 0);
|
||||
|
||||
if (!isBtc)
|
||||
gridPane.getColumnConstraints().remove(1);
|
||||
|
||||
if (isBtc)
|
||||
addMultilineLabel(gridPane, ++rowIndex, Res.get("emptyWalletWindow.info"), 0);
|
||||
|
||||
Coin totalBalance = getWalletService().getAvailableConfirmedBalance();
|
||||
Coin totalBalance = btcWalletService.getAvailableConfirmedBalance();
|
||||
balanceTextField = addTopLabelTextField(gridPane, ++rowIndex, Res.get("emptyWalletWindow.balance"),
|
||||
getFormatter().formatCoinWithCode(totalBalance), 10).second;
|
||||
btcFormatter.formatCoinWithCode(totalBalance), 10).second;
|
||||
|
||||
addressInputTextField = addInputTextField(gridPane, ++rowIndex, Res.get("emptyWalletWindow.address"));
|
||||
|
||||
if (isBtc) {
|
||||
addressInputTextField = addInputTextField(gridPane, ++rowIndex, Res.get("emptyWalletWindow.address"));
|
||||
} else {
|
||||
addTopLabelTextField(gridPane, ++rowIndex, Res.get("emptyWalletWindow.bsq.btcBalance"),
|
||||
bsqFormatter.formatBTCWithCode(bsqWalletService.getAvailableNonBsqBalance().value), 10);
|
||||
}
|
||||
closeButton = new AutoTooltipButton(Res.get("shared.cancel"));
|
||||
closeButton.setOnAction(e -> {
|
||||
hide();
|
||||
closeHandlerOptional.ifPresent(Runnable::run);
|
||||
});
|
||||
|
||||
if (isBtc) {
|
||||
emptyWalletButton = new AutoTooltipButton(Res.get("emptyWalletWindow.button"));
|
||||
boolean isBalanceSufficient = Restrictions.isAboveDust(totalBalance);
|
||||
emptyWalletButton.setDefaultButton(isBalanceSufficient);
|
||||
emptyWalletButton.setDisable(!isBalanceSufficient && addressInputTextField.getText().length() > 0);
|
||||
emptyWalletButton.setOnAction(e -> {
|
||||
if (addressInputTextField.getText().length() > 0 && isBalanceSufficient) {
|
||||
if (getWalletService().isEncrypted()) {
|
||||
walletPasswordWindow
|
||||
.onAesKey(this::doEmptyWallet)
|
||||
.onClose(this::blurAgain)
|
||||
.show();
|
||||
} else {
|
||||
doEmptyWallet(null);
|
||||
}
|
||||
emptyWalletButton = new AutoTooltipButton(Res.get("emptyWalletWindow.button"));
|
||||
boolean isBalanceSufficient = Restrictions.isAboveDust(totalBalance);
|
||||
emptyWalletButton.setDefaultButton(isBalanceSufficient);
|
||||
emptyWalletButton.setDisable(!isBalanceSufficient && addressInputTextField.getText().length() > 0);
|
||||
emptyWalletButton.setOnAction(e -> {
|
||||
if (addressInputTextField.getText().length() > 0 && isBalanceSufficient) {
|
||||
if (btcWalletService.isEncrypted()) {
|
||||
walletPasswordWindow
|
||||
.onAesKey(this::doEmptyWallet)
|
||||
.onClose(this::blurAgain)
|
||||
.show();
|
||||
} else {
|
||||
doEmptyWallet(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
closeButton.setDefaultButton(!isBalanceSufficient);
|
||||
} else {
|
||||
closeButton.setDefaultButton(true);
|
||||
closeButton.updateText(Res.get("shared.close"));
|
||||
}
|
||||
closeButton.setDefaultButton(!isBalanceSufficient);
|
||||
|
||||
HBox hBox = new HBox();
|
||||
hBox.setSpacing(10);
|
||||
GridPane.setRowIndex(hBox, ++rowIndex);
|
||||
|
||||
if (isBtc)
|
||||
hBox.getChildren().addAll(emptyWalletButton, closeButton);
|
||||
else
|
||||
hBox.getChildren().addAll(closeButton);
|
||||
|
||||
hBox.getChildren().addAll(emptyWalletButton, closeButton);
|
||||
gridPane.getChildren().add(hBox);
|
||||
GridPane.setMargin(hBox, new Insets(10, 0, 0, 0));
|
||||
}
|
||||
@ -224,11 +160,11 @@ public class EmptyWalletWindow extends Overlay<EmptyWalletWindow> {
|
||||
emptyWalletButton.setDisable(true);
|
||||
openOfferManager.removeAllOpenOffers(() -> {
|
||||
try {
|
||||
getWalletService().emptyWallet(addressInputTextField.getText(),
|
||||
btcWalletService.emptyWallet(addressInputTextField.getText(),
|
||||
aesKey,
|
||||
() -> {
|
||||
closeButton.updateText(Res.get("shared.close"));
|
||||
balanceTextField.setText(getFormatter().formatCoinWithCode(getWalletService().getAvailableConfirmedBalance()));
|
||||
balanceTextField.setText(btcFormatter.formatCoinWithCode(btcWalletService.getAvailableConfirmedBalance()));
|
||||
emptyWalletButton.setDisable(true);
|
||||
log.debug("wallet empty successful");
|
||||
onClose(() -> UserThread.runAfter(() -> new Popup()
|
||||
@ -247,12 +183,4 @@ public class EmptyWalletWindow extends Overlay<EmptyWalletWindow> {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private WalletService getWalletService() {
|
||||
return isBtc ? btcWalletService : bsqWalletService;
|
||||
}
|
||||
|
||||
private CoinFormatter getFormatter() {
|
||||
return isBtc ? btcFormatter : bsqFormatter;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user