Skip to content

Commit

Permalink
Add indication that BSQ transactions are not up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
ripcurlx committed Feb 11, 2019
1 parent 4c10620 commit 6bea5da
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 9 deletions.
2 changes: 2 additions & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ mainView.footer.usingTor=(using Tor)
mainView.footer.localhostBitcoinNode=(localhost)
mainView.footer.btcInfo=Bitcoin network peers: {0} / {1} {2}
mainView.footer.btcInfo.initializing=Initializing
mainView.footer.bsqInfo.initializing=/ Initializing DAO
mainView.footer.bsqInfo.synchronizing=/ Synchronizing DAO
mainView.footer.btcInfo.synchronizedWith=synchronized with
mainView.footer.btcInfo.connectingTo=connecting to
mainView.footer.btcInfo.connectionFailed=connection failed
Expand Down
4 changes: 3 additions & 1 deletion desktop/src/main/java/bisq/desktop/DesktopModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import bisq.desktop.common.view.ViewFactory;
import bisq.desktop.common.view.ViewLoader;
import bisq.desktop.common.view.guice.InjectorViewFactory;
import bisq.desktop.main.MarketPricePresentation;
import bisq.desktop.main.dao.bonding.BondingViewUtils;
import bisq.desktop.main.funds.transactions.DisplayedTransactionsFactory;
import bisq.desktop.main.funds.transactions.TradableRepository;
Expand All @@ -31,6 +30,8 @@
import bisq.desktop.main.offer.offerbook.OfferBook;
import bisq.desktop.main.overlays.notifications.NotificationCenter;
import bisq.desktop.main.overlays.windows.TorNetworkSettingsWindow;
import bisq.desktop.main.presentation.DaoPresentation;
import bisq.desktop.main.presentation.MarketPricePresentation;
import bisq.desktop.util.Transitions;

import bisq.core.app.AppOptionKeys;
Expand Down Expand Up @@ -72,6 +73,7 @@ protected void configure() {
bind(BsqFormatter.class).in(Singleton.class);
bind(TorNetworkSettingsWindow.class).in(Singleton.class);
bind(MarketPricePresentation.class).in(Singleton.class);
bind(DaoPresentation.class).in(Singleton.class);

bind(Transitions.class).in(Singleton.class);

Expand Down
4 changes: 2 additions & 2 deletions desktop/src/main/java/bisq/desktop/main/MainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,8 @@ private AnchorPane createFooter() {
btcInfoLabel.setId("footer-pane");
btcInfoLabel.textProperty().bind(model.getBtcInfo());

ProgressBar blockchainSyncIndicator = new ProgressBar(-1);
blockchainSyncIndicator.setPrefWidth(120);
ProgressBar blockchainSyncIndicator = new JFXProgressBar(-1);
blockchainSyncIndicator.setPrefWidth(80);
blockchainSyncIndicator.setMaxHeight(10);
blockchainSyncIndicator.progressProperty().bind(model.getBtcSyncProgress());

Expand Down
25 changes: 23 additions & 2 deletions desktop/src/main/java/bisq/desktop/main/MainViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import bisq.desktop.main.overlays.windows.WalletPasswordWindow;
import bisq.desktop.main.overlays.windows.downloadupdate.DisplayUpdateDownloadWindow;
import bisq.desktop.main.presentation.DaoPresentation;
import bisq.desktop.main.presentation.MarketPricePresentation;
import bisq.desktop.util.GUIUtil;

import bisq.core.alert.PrivateNotificationManager;
Expand Down Expand Up @@ -66,11 +67,14 @@
import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.monadic.MonadicBinding;

import javafx.beans.binding.Bindings;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import javafx.collections.ObservableList;
Expand Down Expand Up @@ -109,6 +113,7 @@ public class MainViewModel implements ViewModel, BisqSetup.BisqSetupCompleteList

@Getter
private BooleanProperty showAppScreen = new SimpleBooleanProperty();
private DoubleProperty combinedSyncProgress = new SimpleDoubleProperty();
private final BooleanProperty isSplashScreenRemoved = new SimpleBooleanProperty();
private Timer checkNumberOfBtcPeersTimer;
private Timer checkNumberOfP2pNetworkPeersTimer;
Expand Down Expand Up @@ -354,6 +359,10 @@ private void setupHandlers() {
tradeManager.setTakeOfferRequestErrorMessageHandler(errorMessage -> new Popup<>()
.warning(Res.get("popup.error.takeOfferRequestFailed", errorMessage))
.show());

bisqSetup.getBtcSyncProgress().addListener((observable, oldValue, newValue) -> updateBtcSyncProgress());
daoPresentation.getBsqSyncProgress().addListener((observable, oldValue, newValue) -> updateBtcSyncProgress());

}

private void setupP2PNumPeersWatcher() {
Expand Down Expand Up @@ -460,6 +469,16 @@ public void onUpdatedDataReceived() {
}
}

private void updateBtcSyncProgress() {
final DoubleProperty btcSyncProgress = bisqSetup.getBtcSyncProgress();

if (btcSyncProgress.doubleValue() < 1) {
combinedSyncProgress.set(btcSyncProgress.doubleValue());
} else {
combinedSyncProgress.set(daoPresentation.getBsqSyncProgress().doubleValue());
}
}


///////////////////////////////////////////////////////////////////////////////////////////
// MainView delegate getters
Expand Down Expand Up @@ -500,11 +519,13 @@ StringProperty getLockedBalance() {

// Wallet
StringProperty getBtcInfo() {
return bisqSetup.getBtcInfo();
final StringProperty combinedInfo = new SimpleStringProperty();
combinedInfo.bind(Bindings.concat(bisqSetup.getBtcInfo(), " ", daoPresentation.getBsqInfo()));
return combinedInfo;
}

DoubleProperty getBtcSyncProgress() {
return bisqSetup.getBtcSyncProgress();
return combinedSyncProgress;
}

StringProperty getWalletServiceErrorMsg() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,115 @@
package bisq.desktop.main.presentation;

import bisq.core.app.BisqEnvironment;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.dao.DaoFacade;
import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.blockchain.Block;
import bisq.core.locale.Res;
import bisq.core.user.Preferences;

import javax.inject.Inject;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;

import javafx.collections.MapChangeListener;

public class DaoPresentation {
import lombok.Getter;

public class DaoPresentation implements DaoStateListener {

private final Preferences preferences;
public static final String DAO_NEWS = "daoNewsVersion0.9.4";

private final Preferences preferences;
private final BtcWalletService btcWalletService;
private final DaoFacade daoFacade;
private final BsqWalletService bsqWalletService;
private final DaoStateService daoStateService;

private final ChangeListener<Number> walletChainHeightListener;

@Getter
private final DoubleProperty bsqSyncProgress = new SimpleDoubleProperty(-1);
@Getter
private final StringProperty bsqInfo = new SimpleStringProperty(Res.get("mainView.footer.bsqInfo.initializing"));
private final SimpleBooleanProperty showNotification = new SimpleBooleanProperty(false);

@Inject
public DaoPresentation(Preferences preferences) {
public DaoPresentation(Preferences preferences,
BtcWalletService btcWalletService,
BsqWalletService bsqWalletService,
DaoStateService daoStateService,
DaoFacade daoFacade) {
this.preferences = preferences;
this.btcWalletService = btcWalletService;
this.bsqWalletService = bsqWalletService;
this.daoFacade = daoFacade;
this.daoStateService = daoStateService;

preferences.getDontShowAgainMapAsObservable().addListener((MapChangeListener<? super String, ? super Boolean>) change -> {
if (change.getKey().equals(DAO_NEWS) && !BisqEnvironment.isDAOActivatedAndBaseCurrencySupportingBsq()) {
showNotification.set(!change.wasAdded());
}
});

walletChainHeightListener = (observable, oldValue, newValue) -> onUpdateAnyChainHeight();
}

///////////////////////////////////////////////////////////////////////////////////////////
// Private
///////////////////////////////////////////////////////////////////////////////////////////

private void onUpdateAnyChainHeight() {
final int bsqBlockChainHeight = daoFacade.getChainHeight();
final int bsqWalletChainHeight = bsqWalletService.getBestChainHeight();
if (bsqWalletChainHeight > 0) {
final boolean synced = bsqWalletChainHeight == bsqBlockChainHeight;
if (bsqBlockChainHeight != bsqWalletChainHeight) {
bsqSyncProgress.set(-1);
} else {
bsqSyncProgress.set(0);
}

if (synced) {
bsqInfo.set("");
} else {
bsqInfo.set(Res.get("mainView.footer.bsqInfo.synchronizing"));
}
} else {
bsqInfo.set(Res.get("mainView.footer.bsqInfo.synchronizing"));
}
}

///////////////////////////////////////////////////////////////////////////////////////////
// DaoStateListener
///////////////////////////////////////////////////////////////////////////////////////////

@Override
public void onNewBlockHeight(int blockHeight) {

}

@Override
public void onParseBlockChainComplete() {

}

@Override
public void onParseTxsCompleteAfterBatchProcessing(Block block) {
onUpdateAnyChainHeight();
}

@Override
public void onParseTxsComplete(Block block) {

}

public BooleanProperty getShowDaoUpdatesNotification() {
Expand All @@ -34,5 +119,10 @@ public BooleanProperty getShowDaoUpdatesNotification() {
public void setup() {
if (!BisqEnvironment.isDAOActivatedAndBaseCurrencySupportingBsq())
showNotification.set(preferences.showAgain(DAO_NEWS));

this.btcWalletService.getChainHeightProperty().addListener(walletChainHeightListener);
daoStateService.addBsqStateListener(this);

onUpdateAnyChainHeight();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.desktop.main;
package bisq.desktop.main.presentation;

import bisq.desktop.components.BalanceWithConfirmationTextField;
import bisq.desktop.components.TxIdTextField;
import bisq.desktop.main.PriceFeedComboBoxItem;
import bisq.desktop.util.GUIUtil;

import bisq.core.btc.wallet.BtcWalletService;
Expand Down

0 comments on commit 6bea5da

Please sign in to comment.