Add error msg in case of bitcoin network problems #320

This commit is contained in:
Manfred Karrer 2014-12-11 16:03:48 +01:00
parent 25cac42700
commit 70f75dd953

View file

@ -35,6 +35,7 @@ import io.bitsquare.trade.Trade;
import io.bitsquare.trade.TradeManager; import io.bitsquare.trade.TradeManager;
import io.bitsquare.user.User; import io.bitsquare.user.User;
import io.bitsquare.util.DSAKeyUtil; import io.bitsquare.util.DSAKeyUtil;
import io.bitsquare.util.Utilities;
import org.bitcoinj.core.Coin; import org.bitcoinj.core.Coin;
import org.bitcoinj.core.ECKey; import org.bitcoinj.core.ECKey;
@ -49,6 +50,7 @@ import java.util.Locale;
import viewfx.model.ViewModel; import viewfx.model.ViewModel;
import javafx.animation.AnimationTimer;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.property.BooleanProperty; import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty; import javafx.beans.property.DoubleProperty;
@ -84,7 +86,7 @@ class MainViewModel implements ViewModel {
final BooleanProperty bankAccountsComboBoxDisable = new SimpleBooleanProperty(); final BooleanProperty bankAccountsComboBoxDisable = new SimpleBooleanProperty();
final StringProperty blockchainSyncState = new SimpleStringProperty("Initializing"); final StringProperty blockchainSyncState = new SimpleStringProperty("Initializing");
final DoubleProperty blockchainSyncProgress = new SimpleDoubleProperty(); final DoubleProperty blockchainSyncProgress = new SimpleDoubleProperty(-1);
final BooleanProperty blockchainSyncIndicatorVisible = new SimpleBooleanProperty(true); final BooleanProperty blockchainSyncIndicatorVisible = new SimpleBooleanProperty(true);
final StringProperty blockchainSyncIconId = new SimpleStringProperty(); final StringProperty blockchainSyncIconId = new SimpleStringProperty();
final StringProperty walletServiceErrorMsg = new SimpleStringProperty(); final StringProperty walletServiceErrorMsg = new SimpleStringProperty();
@ -106,6 +108,7 @@ class MainViewModel implements ViewModel {
private final BSFormatter formatter; private final BSFormatter formatter;
private Persistence persistence; private Persistence persistence;
private AccountSettings accountSettings; private AccountSettings accountSettings;
private AnimationTimer bitcoinNetworkTimeout;
@Inject @Inject
public MainViewModel(User user, WalletService walletService, MessageService messageService, public MainViewModel(User user, WalletService walletService, MessageService messageService,
@ -127,6 +130,7 @@ class MainViewModel implements ViewModel {
bootstrapState.addListener((ov, oldValue, newValue) -> { bootstrapState.addListener((ov, oldValue, newValue) -> {
if (newValue == BootstrapState.DISCOVERY_DIRECT_SUCCEEDED || if (newValue == BootstrapState.DISCOVERY_DIRECT_SUCCEEDED ||
newValue == BootstrapState.DISCOVERY_MANUAL_PORT_FORWARDING_SUCCEEDED ||
newValue == BootstrapState.DISCOVERY_AUTO_PORT_FORWARDING_SUCCEEDED || newValue == BootstrapState.DISCOVERY_AUTO_PORT_FORWARDING_SUCCEEDED ||
newValue == BootstrapState.RELAY_SUCCEEDED) { newValue == BootstrapState.RELAY_SUCCEEDED) {
bootstrapStateText.set("Successfully connected to P2P network: " + newValue.getMessage()); bootstrapStateText.set("Successfully connected to P2P network: " + newValue.getMessage());
@ -134,7 +138,8 @@ class MainViewModel implements ViewModel {
if (newValue == BootstrapState.DISCOVERY_DIRECT_SUCCEEDED) if (newValue == BootstrapState.DISCOVERY_DIRECT_SUCCEEDED)
bootstrapIconId.set("image-connection-direct"); bootstrapIconId.set("image-connection-direct");
else if (newValue == BootstrapState.DISCOVERY_AUTO_PORT_FORWARDING_SUCCEEDED) else if (newValue == BootstrapState.DISCOVERY_MANUAL_PORT_FORWARDING_SUCCEEDED ||
newValue == BootstrapState.DISCOVERY_AUTO_PORT_FORWARDING_SUCCEEDED)
bootstrapIconId.set("image-connection-nat"); bootstrapIconId.set("image-connection-nat");
else if (newValue == BootstrapState.RELAY_SUCCEEDED) else if (newValue == BootstrapState.RELAY_SUCCEEDED)
bootstrapIconId.set("image-connection-relay"); bootstrapIconId.set("image-connection-relay");
@ -156,7 +161,6 @@ class MainViewModel implements ViewModel {
); );
walletServiceException.addListener((ov, oldValue, newValue) -> { walletServiceException.addListener((ov, oldValue, newValue) -> {
blockchainSyncProgress.set(0);
blockchainSyncIndicatorVisible.set(false); blockchainSyncIndicatorVisible.set(false);
blockchainSyncState.set("Startup failed."); blockchainSyncState.set("Startup failed.");
walletServiceErrorMsg.set(((Throwable) newValue).getMessage()); walletServiceErrorMsg.set(((Throwable) newValue).getMessage());
@ -189,8 +193,22 @@ class MainViewModel implements ViewModel {
} }
public void initBackend() { public void initBackend() {
bitcoinNetworkTimeout = Utilities.setTimeout(2000, animationTimer -> {
Platform.runLater(() -> {
networkSyncProgress.set(0);
blockchainSyncState.set("Connection to bitcoin network failed.");
Popups.openErrorPopup("Connection to bitcoin network failed",
"Please check your network connection.\n\n" +
"You need to allow outgoing TCP connections to port 18333 for the bitcoin testnet.");
});
return null;
});
walletService.getDownloadProgress().subscribe( walletService.getDownloadProgress().subscribe(
percentage -> Platform.runLater(() -> networkSyncProgress.set(percentage / 100.0)), percentage -> Platform.runLater(() -> {
if (percentage > 0)
networkSyncProgress.set(percentage / 100.0);
}),
error -> log.error(error.toString()), error -> log.error(error.toString()),
() -> Platform.runLater(() -> networkSyncProgress.set(1.0))); () -> Platform.runLater(() -> networkSyncProgress.set(1.0)));
@ -206,7 +224,11 @@ class MainViewModel implements ViewModel {
next -> { next -> {
}, },
error -> Platform.runLater(() -> walletServiceException.set(error)), error -> Platform.runLater(() -> walletServiceException.set(error)),
() -> log.trace("wallet completed")); () -> {
log.trace("wallet completed");
bitcoinNetworkTimeout.stop();
bitcoinNetworkTimeout = null;
});
Observable<?> backend = Observable.merge(message, wallet); Observable<?> backend = Observable.merge(message, wallet);
backend.subscribe( backend.subscribe(
@ -219,6 +241,7 @@ class MainViewModel implements ViewModel {
private void backEndCompleted() { private void backEndCompleted() {
log.trace("backend completed"); log.trace("backend completed");
tradeManager.getPendingTrades().addListener( tradeManager.getPendingTrades().addListener(
(MapChangeListener<String, Trade>) change -> updateNumPendingTrades()); (MapChangeListener<String, Trade>) change -> updateNumPendingTrades());
updateNumPendingTrades(); updateNumPendingTrades();