ui fixes to mix start and stop

This commit is contained in:
Craig Raw 2021-09-23 14:18:37 +02:00
parent f74287697c
commit 0b55dd8a1e
2 changed files with 25 additions and 6 deletions

View file

@ -79,7 +79,14 @@ public class UtxosController extends WalletFormController implements Initializab
}; };
private final ChangeListener<Boolean> mixingStartingListener = (observable, oldValue, newValue) -> { private final ChangeListener<Boolean> mixingStartingListener = (observable, oldValue, newValue) -> {
startMix.setDisable(newValue); startMix.setDisable(newValue || !AppServices.onlineProperty().get());
Platform.runLater(() -> startMix.setText(newValue && AppServices.onlineProperty().get() ? "Starting Mixing..." : "Start Mixing"));
mixTo.setDisable(newValue);
};
private final ChangeListener<Boolean> mixingStoppingListener = (observable, oldValue, newValue) -> {
startMix.setDisable(newValue || !AppServices.onlineProperty().get());
Platform.runLater(() -> startMix.setText(newValue ? "Stopping Mixing..." : "Start Mixing"));
mixTo.setDisable(newValue); mixTo.setDisable(newValue);
}; };
@ -101,7 +108,6 @@ public class UtxosController extends WalletFormController implements Initializab
startMix.visibleProperty().bind(stopMix.visibleProperty().not()); startMix.visibleProperty().bind(stopMix.visibleProperty().not());
stopMix.visibleProperty().addListener((observable, oldValue, newValue) -> { stopMix.visibleProperty().addListener((observable, oldValue, newValue) -> {
stopMix.setDisable(!newValue); stopMix.setDisable(!newValue);
startMix.setDisable(newValue || !AppServices.onlineProperty().get());
}); });
mixTo.managedProperty().bind(mixTo.visibleProperty()); mixTo.managedProperty().bind(mixTo.visibleProperty());
mixTo.setVisible(getWalletForm().getWallet().getStandardAccountType() == StandardAccount.WHIRLPOOL_POSTMIX); mixTo.setVisible(getWalletForm().getWallet().getStandardAccountType() == StandardAccount.WHIRLPOOL_POSTMIX);
@ -111,6 +117,7 @@ public class UtxosController extends WalletFormController implements Initializab
if(whirlpool != null) { if(whirlpool != null) {
stopMix.visibleProperty().bind(whirlpool.mixingProperty()); stopMix.visibleProperty().bind(whirlpool.mixingProperty());
whirlpool.startingProperty().addListener(new WeakChangeListener<>(mixingStartingListener)); whirlpool.startingProperty().addListener(new WeakChangeListener<>(mixingStartingListener));
whirlpool.stoppingProperty().addListener(new WeakChangeListener<>(mixingStoppingListener));
updateMixToButton(); updateMixToButton();
} }
} }
@ -322,7 +329,7 @@ public class UtxosController extends WalletFormController implements Initializab
public void stopMixing(ActionEvent event) { public void stopMixing(ActionEvent event) {
stopMix.setDisable(true); stopMix.setDisable(true);
startMix.setDisable(false); startMix.setDisable(!AppServices.onlineProperty().get());
getWalletForm().getWallet().getMasterMixConfig().setMixOnStartup(Boolean.FALSE); getWalletForm().getWallet().getMasterMixConfig().setMixOnStartup(Boolean.FALSE);
EventManager.get().post(new WalletMasterMixConfigChangedEvent(getWalletForm().getWallet())); EventManager.get().post(new WalletMasterMixConfigChangedEvent(getWalletForm().getWallet()));

View file

@ -76,6 +76,7 @@ public class Whirlpool {
private String mixToWalletId; private String mixToWalletId;
private final BooleanProperty startingProperty = new SimpleBooleanProperty(false); private final BooleanProperty startingProperty = new SimpleBooleanProperty(false);
private final BooleanProperty stoppingProperty = new SimpleBooleanProperty(false);
private final BooleanProperty mixingProperty = new SimpleBooleanProperty(false); private final BooleanProperty mixingProperty = new SimpleBooleanProperty(false);
public Whirlpool(Network network, HostAndPort torProxy) { public Whirlpool(Network network, HostAndPort torProxy) {
@ -408,6 +409,14 @@ public class Whirlpool {
return startingProperty; return startingProperty;
} }
public boolean isStopping() {
return stoppingProperty.get();
}
public BooleanProperty stoppingProperty() {
return stoppingProperty;
}
@Subscribe @Subscribe
public void onMixSuccess(MixSuccessEvent e) { public void onMixSuccess(MixSuccessEvent e) {
WalletUtxo walletUtxo = getUtxo(e.getWhirlpoolUtxo()); WalletUtxo walletUtxo = getUtxo(e.getWhirlpoolUtxo());
@ -547,8 +556,8 @@ public class Whirlpool {
WhirlpoolWallet whirlpoolWallet = whirlpool.getWhirlpoolWallet(); WhirlpoolWallet whirlpoolWallet = whirlpool.getWhirlpoolWallet();
if(AppServices.onlineProperty().get()) { if(AppServices.onlineProperty().get()) {
whirlpoolWallet.start(); whirlpoolWallet.start();
whirlpool.startingProperty.set(false);
} }
whirlpool.startingProperty.set(false);
return whirlpoolWallet; return whirlpoolWallet;
} }
@ -569,8 +578,9 @@ public class Whirlpool {
protected Boolean call() throws Exception { protected Boolean call() throws Exception {
updateProgress(-1, 1); updateProgress(-1, 1);
updateMessage("Disconnecting from Whirlpool..."); updateMessage("Disconnecting from Whirlpool...");
whirlpool.stoppingProperty.set(true);
whirlpool.shutdown(); whirlpool.shutdown();
whirlpool.stoppingProperty.set(false);
return true; return true;
} }
}; };
@ -590,15 +600,17 @@ public class Whirlpool {
protected Boolean call() throws Exception { protected Boolean call() throws Exception {
updateProgress(-1, 1); updateProgress(-1, 1);
updateMessage("Disconnecting from Whirlpool..."); updateMessage("Disconnecting from Whirlpool...");
whirlpool.stoppingProperty.set(true);
whirlpool.shutdown(); whirlpool.shutdown();
whirlpool.stoppingProperty.set(false);
updateMessage("Starting Whirlpool..."); updateMessage("Starting Whirlpool...");
whirlpool.startingProperty.set(true); whirlpool.startingProperty.set(true);
WhirlpoolWallet whirlpoolWallet = whirlpool.getWhirlpoolWallet(); WhirlpoolWallet whirlpoolWallet = whirlpool.getWhirlpoolWallet();
if(AppServices.onlineProperty().get()) { if(AppServices.onlineProperty().get()) {
whirlpoolWallet.start(); whirlpoolWallet.start();
whirlpool.startingProperty.set(false);
} }
whirlpool.startingProperty.set(false);
return true; return true;
} }