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 f4bf209 commit d6b1863
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 6 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 @@ -233,6 +233,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 @@ -588,8 +588,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
29 changes: 27 additions & 2 deletions desktop/src/main/java/bisq/desktop/main/MainViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import bisq.desktop.main.overlays.windows.TorNetworkSettingsWindow;
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 @@ -65,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 All @@ -89,6 +94,7 @@ public class MainViewModel implements ViewModel, BisqSetup.BisqSetupCompleteList
private final TradePresentation tradePresentation;
private final DisputePresentation disputePresentation;
private final MarketPricePresentation marketPricePresentation;
private final DaoPresentation daoPresentation;
private final P2PService p2PService;
private final TradeManager tradeManager;
private final Preferences preferences;
Expand All @@ -107,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 All @@ -128,6 +135,7 @@ public MainViewModel(BisqSetup bisqSetup,
TradePresentation tradePresentation,
DisputePresentation disputePresentation,
MarketPricePresentation marketPricePresentation,
DaoPresentation daoPresentation,
P2PService p2PService,
TradeManager tradeManager,
Preferences preferences,
Expand All @@ -149,6 +157,7 @@ public MainViewModel(BisqSetup bisqSetup,
this.tradePresentation = tradePresentation;
this.disputePresentation = disputePresentation;
this.marketPricePresentation = marketPricePresentation;
this.daoPresentation = daoPresentation;
this.p2PService = p2PService;
this.tradeManager = tradeManager;
this.preferences = preferences;
Expand Down Expand Up @@ -349,6 +358,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 @@ -455,6 +468,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 @@ -495,11 +518,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
@@ -0,0 +1,97 @@
package bisq.desktop.main.presentation;

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 javax.inject.Inject;

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

import lombok.Getter;

public class DaoPresentation implements DaoStateListener {

private final BtcWalletService btcWalletService;
private final DaoFacade daoFacade;
private final BsqWalletService bsqWalletService;
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"));

@Inject
public DaoPresentation(BtcWalletService btcWalletService,
BsqWalletService bsqWalletService,
DaoStateService daoStateService,
DaoFacade daoFacade) {

this.btcWalletService = btcWalletService;
this.bsqWalletService = bsqWalletService;
this.daoFacade = daoFacade;

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

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

///////////////////////////////////////////////////////////////////////////////////////////
// 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) {

}
}
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 d6b1863

Please sign in to comment.