Avoid that at repeated onDaoStateHashesChanged calls that we show multiple popups.

Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
HenrikJannsen 2023-01-06 19:29:53 -05:00 committed by Alejandro García
parent 0f5f676fbe
commit 1f505cd184
No known key found for this signature in database
GPG Key ID: F806F422E222AA02

View File

@ -16,6 +16,8 @@ import bisq.core.dao.state.model.blockchain.Block;
import bisq.core.locale.Res;
import bisq.core.user.Preferences;
import bisq.common.UserThread;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -30,7 +32,11 @@ import javafx.beans.value.ChangeListener;
import javafx.collections.MapChangeListener;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.Nullable;
@Slf4j
@Singleton
public class DaoPresentation implements DaoStateListener, DaoStateMonitoringService.Listener {
public static final String DAO_NEWS = "daoNews";
@ -47,6 +53,8 @@ public class DaoPresentation implements DaoStateListener, DaoStateMonitoringServ
@Getter
private final StringProperty daoStateInfo = new SimpleStringProperty("");
private final SimpleBooleanProperty showNotification = new SimpleBooleanProperty(false);
@Nullable
private Popup popup;
@Inject
public DaoPresentation(Preferences preferences,
@ -107,19 +115,33 @@ public class DaoPresentation implements DaoStateListener, DaoStateMonitoringServ
@Override
public void onDaoStateHashesChanged() {
if (!daoStateService.isParseBlockChainComplete()) {
if (!daoStateService.isParseBlockChainComplete() || bsqWalletService.getBestChainHeight() != daoStateService.getChainHeight()) {
return;
}
if (daoStateMonitoringService.isInConflictWithSeedNode() ||
daoStateMonitoringService.isDaoStateBlockChainNotConnecting()) {
new Popup().warning(Res.get("popup.warning.daoNeedsResync"))
// We might get multiple times called onDaoStateHashesChanged. To avoid multiple popups we
// check against null and set it back to null after a 30 sec delay once the user closed it.
if (popup == null &&
(daoStateMonitoringService.isInConflictWithSeedNode() ||
daoStateMonitoringService.isDaoStateBlockChainNotConnecting())) {
popup = new Popup().warning(Res.get("popup.warning.daoNeedsResync"))
.actionButtonTextWithGoTo("navigation.dao.networkMonitor")
.onAction(() -> navigation.navigateTo(MainView.class, DaoView.class, MonitorView.class, DaoStateMonitorView.class))
.show();
.onAction(() -> {
navigation.navigateTo(MainView.class, DaoView.class, MonitorView.class, DaoStateMonitorView.class);
resetPopupAndCheckAgain();
})
.onClose(this::resetPopupAndCheckAgain);
popup.show();
}
}
private void resetPopupAndCheckAgain() {
UserThread.runAfter(() -> {
popup = null;
onDaoStateHashesChanged();
}, 30);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private