Remove all open offer when using the empty wallet tool

This commit is contained in:
Manfred Karrer 2016-03-31 14:00:38 +02:00
parent a1d9dd47df
commit 6a01be8d29

View file

@ -26,6 +26,7 @@ import io.bitsquare.gui.main.overlays.Overlay;
import io.bitsquare.gui.main.overlays.popups.Popup; import io.bitsquare.gui.main.overlays.popups.Popup;
import io.bitsquare.gui.util.BSFormatter; import io.bitsquare.gui.util.BSFormatter;
import io.bitsquare.gui.util.Transitions; import io.bitsquare.gui.util.Transitions;
import io.bitsquare.trade.offer.OpenOfferManager;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
@ -48,6 +49,7 @@ public class EmptyWalletWindow extends Overlay<EmptyWalletWindow> {
private static final Logger log = LoggerFactory.getLogger(EmptyWalletWindow.class); private static final Logger log = LoggerFactory.getLogger(EmptyWalletWindow.class);
private final WalletService walletService; private final WalletService walletService;
private final WalletPasswordWindow walletPasswordWindow; private final WalletPasswordWindow walletPasswordWindow;
private OpenOfferManager openOfferManager;
private final BSFormatter formatter; private final BSFormatter formatter;
private Button emptyWalletButton; private Button emptyWalletButton;
private InputTextField addressInputTextField; private InputTextField addressInputTextField;
@ -59,9 +61,10 @@ public class EmptyWalletWindow extends Overlay<EmptyWalletWindow> {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@Inject @Inject
public EmptyWalletWindow(WalletService walletService, WalletPasswordWindow walletPasswordWindow, BSFormatter formatter) { public EmptyWalletWindow(WalletService walletService, WalletPasswordWindow walletPasswordWindow, OpenOfferManager openOfferManager, BSFormatter formatter) {
this.walletService = walletService; this.walletService = walletService;
this.walletPasswordWindow = walletPasswordWindow; this.walletPasswordWindow = walletPasswordWindow;
this.openOfferManager = openOfferManager;
this.formatter = formatter; this.formatter = formatter;
type = Type.Instruction; type = Type.Instruction;
@ -86,10 +89,11 @@ public class EmptyWalletWindow extends Overlay<EmptyWalletWindow> {
private void addContent() { private void addContent() {
addMultilineLabel(gridPane, ++rowIndex, addMultilineLabel(gridPane, ++rowIndex,
"Please use that only in emergency case if you cannot access your fund from the UI.\n" + "Please use that only in emergency case if you cannot access your fund from the UI.\n\n" +
"Before you use this tool, you should backup your data directory. After you have successfully transferred your wallet balance, remove" + "Please note that all open offers will be closed automatically when using this tool.\n\n" +
" the db directory inside the data directory to start with a newly created and consistent data structure.\n" + "Before you use this tool, please backup your data directory. " +
"Please make a bug report on Github so that we can investigate what was causing the problem.", "You can do this under \"Account/Backup\".\n\n" +
"Please file a bug report on Github so that we can investigate what was causing the problem.",
10); 10);
Coin totalBalance = walletService.getAvailableBalance(); Coin totalBalance = walletService.getAvailableBalance();
@ -105,8 +109,8 @@ public class EmptyWalletWindow extends Overlay<EmptyWalletWindow> {
if (addressInputTextField.getText().length() > 0 && isBalanceSufficient) { if (addressInputTextField.getText().length() > 0 && isBalanceSufficient) {
if (walletService.getWallet().isEncrypted()) { if (walletService.getWallet().isEncrypted()) {
walletPasswordWindow walletPasswordWindow
.onClose(() -> blurAgain()) .onAesKey(this::doEmptyWallet)
.onAesKey(aesKey -> doEmptyWallet(aesKey)) .onClose(this::blurAgain)
.show(); .show();
} else { } else {
doEmptyWallet(null); doEmptyWallet(null);
@ -117,7 +121,7 @@ public class EmptyWalletWindow extends Overlay<EmptyWalletWindow> {
closeButton = new Button("Cancel"); closeButton = new Button("Cancel");
closeButton.setOnAction(e -> { closeButton.setOnAction(e -> {
hide(); hide();
closeHandlerOptional.ifPresent(closeHandler -> closeHandler.run()); closeHandlerOptional.ifPresent(Runnable::run);
}); });
closeButton.setDefaultButton(!isBalanceSufficient); closeButton.setDefaultButton(!isBalanceSufficient);
@ -132,27 +136,29 @@ public class EmptyWalletWindow extends Overlay<EmptyWalletWindow> {
private void doEmptyWallet(KeyParameter aesKey) { private void doEmptyWallet(KeyParameter aesKey) {
emptyWalletButton.setDisable(true); emptyWalletButton.setDisable(true);
try { openOfferManager.closeAllOpenOffers(() -> {
walletService.emptyWallet(addressInputTextField.getText(), try {
aesKey, walletService.emptyWallet(addressInputTextField.getText(),
() -> { aesKey,
closeButton.setText("Close"); () -> {
addressTextField.setText(formatter.formatCoinWithCode(walletService.getAvailableBalance())); closeButton.setText("Close");
emptyWalletButton.setDisable(true); addressTextField.setText(formatter.formatCoinWithCode(walletService.getAvailableBalance()));
log.debug("wallet empty successful"); emptyWalletButton.setDisable(true);
UserThread.runAfter(() -> new Popup() log.debug("wallet empty successful");
.feedback("The balance of your wallet was successfully transferred.") UserThread.runAfter(() -> new Popup()
.onClose(() -> blurAgain()).show(), Transitions.DEFAULT_DURATION, TimeUnit.MILLISECONDS); .feedback("The balance of your wallet was successfully transferred.")
}, .onClose(this::hide)
(errorMessage) -> { .show(), Transitions.DEFAULT_DURATION, TimeUnit.MILLISECONDS);
emptyWalletButton.setDisable(false); },
log.debug("wallet empty failed " + errorMessage); (errorMessage) -> {
}); emptyWalletButton.setDisable(false);
} catch (InsufficientMoneyException | AddressFormatException e1) { log.debug("wallet empty failed " + errorMessage);
e1.printStackTrace(); });
log.error(e1.getMessage()); } catch (InsufficientMoneyException | AddressFormatException e1) {
emptyWalletButton.setDisable(false); e1.printStackTrace();
} log.error(e1.getMessage());
emptyWalletButton.setDisable(false);
}
});
} }
} }