Skip to content

Commit

Permalink
Merge pull request #4676 from jmacxx/show_tx_fee
Browse files Browse the repository at this point in the history
Show current tx fee rate on main screen
  • Loading branch information
ripcurlx authored Oct 24, 2020
2 parents 93a3188 + 7c7887d commit 55c663a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 37 deletions.
17 changes: 11 additions & 6 deletions core/src/main/java/bisq/core/app/P2PNetworkSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package bisq.core.app;

import bisq.core.btc.setup.WalletsSetup;
import bisq.core.locale.Res;
import bisq.core.provider.price.PriceFeedService;
import bisq.core.user.Preferences;
Expand Down Expand Up @@ -50,6 +51,7 @@
public class P2PNetworkSetup {
private final PriceFeedService priceFeedService;
private final P2PService p2PService;
private final WalletsSetup walletsSetup;
private final Preferences preferences;

@SuppressWarnings("FieldCanBeLocal")
Expand All @@ -73,10 +75,12 @@ public class P2PNetworkSetup {
@Inject
public P2PNetworkSetup(PriceFeedService priceFeedService,
P2PService p2PService,
WalletsSetup walletsSetup,
Preferences preferences) {

this.priceFeedService = priceFeedService;
this.p2PService = p2PService;
this.walletsSetup = walletsSetup;
this.preferences = preferences;
}

Expand All @@ -86,18 +90,19 @@ BooleanProperty init(Runnable initWalletServiceHandler, @Nullable Consumer<Boole
BooleanProperty hiddenServicePublished = new SimpleBooleanProperty();
BooleanProperty initialP2PNetworkDataReceived = new SimpleBooleanProperty();

p2PNetworkInfoBinding = EasyBind.combine(bootstrapState, bootstrapWarning, p2PService.getNumConnectedPeers(), hiddenServicePublished, initialP2PNetworkDataReceived,
(state, warning, numPeers, hiddenService, dataReceived) -> {
p2PNetworkInfoBinding = EasyBind.combine(bootstrapState, bootstrapWarning, p2PService.getNumConnectedPeers(),
walletsSetup.numPeersProperty(), hiddenServicePublished, initialP2PNetworkDataReceived,
(state, warning, numP2pPeers, numBtcPeers, hiddenService, dataReceived) -> {
String result;
String daoFullNode = preferences.isDaoFullNode() ? Res.get("mainView.footer.daoFullNode") + " / " : "";
int peers = (int) numPeers;
if (warning != null && peers == 0) {
int p2pPeers = (int) numP2pPeers;
if (warning != null && p2pPeers == 0) {
result = warning;
} else {
String p2pInfo = Res.get("mainView.footer.p2pInfo", numPeers);
String p2pInfo = Res.get("mainView.footer.p2pInfo", numBtcPeers, numP2pPeers);
if (dataReceived && hiddenService) {
result = p2pInfo;
} else if (peers == 0)
} else if (p2pPeers == 0)
result = state;
else
result = state + " / " + p2pInfo;
Expand Down
21 changes: 9 additions & 12 deletions core/src/main/java/bisq/core/app/WalletAppSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.wallet.WalletsManager;
import bisq.core.locale.Res;
import bisq.core.provider.fee.FeeService;
import bisq.core.offer.OpenOfferManager;
import bisq.core.trade.TradeManager;
import bisq.core.user.Preferences;
Expand Down Expand Up @@ -64,6 +65,7 @@ public class WalletAppSetup {

private final WalletsManager walletsManager;
private final WalletsSetup walletsSetup;
private final FeeService feeService;
private final Config config;
private final Preferences preferences;

Expand All @@ -81,17 +83,17 @@ public class WalletAppSetup {
@Getter
private final ObjectProperty<RejectedTxException> rejectedTxException = new SimpleObjectProperty<>();
@Getter
private int numBtcPeers = 0;
@Getter
private final BooleanProperty useTorForBTC = new SimpleBooleanProperty();

@Inject
public WalletAppSetup(WalletsManager walletsManager,
WalletsSetup walletsSetup,
FeeService feeService,
Config config,
Preferences preferences) {
this.walletsManager = walletsManager;
this.walletsSetup = walletsSetup;
this.feeService = feeService;
this.config = config;
this.preferences = preferences;
this.useTorForBTC.set(preferences.getUseTorForBitcoinJ());
Expand All @@ -109,36 +111,33 @@ void init(@Nullable Consumer<String> chainFileLockedExceptionHandler,

ObjectProperty<Throwable> walletServiceException = new SimpleObjectProperty<>();
btcInfoBinding = EasyBind.combine(walletsSetup.downloadPercentageProperty(),
walletsSetup.numPeersProperty(),
feeService.feeUpdateCounterProperty(),
walletServiceException,
(downloadPercentage, numPeers, exception) -> {
(downloadPercentage, feeUpdate, exception) -> {
String result;
if (exception == null) {
double percentage = (double) downloadPercentage;
int peers = (int) numPeers;
long fees = feeService.getTxFeePerByte().longValue();
btcSyncProgress.set(percentage);
if (percentage == 1) {
String feeRate = Res.get("mainView.footer.btcFeeRate", fees);
result = Res.get("mainView.footer.btcInfo",
peers,
Res.get("mainView.footer.btcInfo.synchronizedWith"),
getBtcNetworkAsString());
getBtcNetworkAsString() + " / " + feeRate);
getBtcSplashSyncIconId().set("image-connection-synced");

downloadCompleteHandler.run();
} else if (percentage > 0.0) {
result = Res.get("mainView.footer.btcInfo",
peers,
Res.get("mainView.footer.btcInfo.synchronizingWith"),
getBtcNetworkAsString() + ": " + FormattingUtils.formatToPercentWithSymbol(percentage));
} else {
result = Res.get("mainView.footer.btcInfo",
peers,
Res.get("mainView.footer.btcInfo.connectingTo"),
getBtcNetworkAsString());
}
} else {
result = Res.get("mainView.footer.btcInfo",
getNumBtcPeers(),
Res.get("mainView.footer.btcInfo.connectionFailed"),
getBtcNetworkAsString());
log.error(exception.toString());
Expand All @@ -164,8 +163,6 @@ void init(@Nullable Consumer<String> chainFileLockedExceptionHandler,

walletsSetup.initialize(null,
() -> {
numBtcPeers = walletsSetup.numPeersProperty().get();

// We only check one wallet as we apply encryption to all or none
if (walletsManager.areWalletsEncrypted()) {
walletPasswordHandler.run();
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,15 @@ mainView.balance.locked.short=Locked

mainView.footer.usingTor=(using Tor)
mainView.footer.localhostBitcoinNode=(localhost)
mainView.footer.btcInfo=Bitcoin network peers: {0} / {1} {2}
mainView.footer.btcInfo={0} {1}
mainView.footer.btcFeeRate=Current fee rate: {0} sat/vB
mainView.footer.btcInfo.initializing=Connecting to Bitcoin network
mainView.footer.bsqInfo.synchronizing=/ Synchronizing DAO
mainView.footer.btcInfo.synchronizingWith=Synchronizing with
mainView.footer.btcInfo.synchronizedWith=Synchronized with
mainView.footer.btcInfo.synchronizedWith=Synced with
mainView.footer.btcInfo.connectingTo=Connecting to
mainView.footer.btcInfo.connectionFailed=Connection failed to
mainView.footer.p2pInfo=Bisq network peers: {0}
mainView.footer.p2pInfo=Bitcoin network peers: {0} / Bisq network peers: {1}
mainView.footer.daoFullNode=DAO full node

mainView.bootstrapState.connectionToTorNetwork=(1/4) Connecting to Tor network...
Expand Down
28 changes: 13 additions & 15 deletions desktop/src/main/java/bisq/desktop/main/MainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import bisq.common.BisqException;
import bisq.common.Timer;
import bisq.common.UserThread;
import bisq.common.app.Version;
import bisq.common.util.Tuple2;
import bisq.common.util.Utilities;

Expand Down Expand Up @@ -115,7 +114,6 @@ public class MainView extends InitializableView<StackPane, MainViewModel>
implements DaoStateMonitoringService.Listener {
// If after 30 sec we have not got connected we show "open network settings" button
private final static int SHOW_TOR_SETTINGS_DELAY_SEC = 90;
private Label versionLabel;
@Setter
private Runnable onApplicationStartedHandler;

Expand Down Expand Up @@ -687,6 +685,8 @@ private AnchorPane createFooter() {
Label btcInfoLabel = new AutoTooltipLabel();
btcInfoLabel.setId("footer-pane");
btcInfoLabel.textProperty().bind(model.getBtcInfo());
setLeftAnchor(btcInfoLabel, 10d);
setBottomAnchor(btcInfoLabel, 7d);

ProgressBar blockchainSyncIndicator = new JFXProgressBar(-1);
blockchainSyncIndicator.setPrefWidth(80);
Expand Down Expand Up @@ -715,34 +715,32 @@ private AnchorPane createFooter() {
}
});

HBox blockchainSyncBox = new HBox();
blockchainSyncBox.setSpacing(10);
blockchainSyncBox.setAlignment(Pos.CENTER);
blockchainSyncBox.getChildren().addAll(btcInfoLabel, blockchainSyncIndicator);
setLeftAnchor(blockchainSyncBox, 10d);
setBottomAnchor(blockchainSyncBox, 7d);

// version
versionLabel = new AutoTooltipLabel();
Label versionLabel = new AutoTooltipLabel();
versionLabel.setId("footer-pane");
versionLabel.setTextAlignment(TextAlignment.CENTER);
versionLabel.setAlignment(Pos.BASELINE_CENTER);
versionLabel.setText("v" + Version.VERSION);
versionLabel.textProperty().bind(model.getCombinedFooterInfo());
root.widthProperty().addListener((ov, oldValue, newValue) ->
versionLabel.setLayoutX(((double) newValue - versionLabel.getWidth()) / 2));
setBottomAnchor(versionLabel, 7d);
model.getNewVersionAvailableProperty().addListener((observable, oldValue, newValue) -> {
versionLabel.getStyleClass().removeAll("version-new", "version");
if (newValue) {
versionLabel.getStyleClass().add("version-new");
versionLabel.setOnMouseClicked(e -> model.onOpenDownloadWindow());
versionLabel.setText("v" + Version.VERSION + " " + Res.get("mainView.version.update"));
} else {
versionLabel.getStyleClass().add("version");
versionLabel.setOnMouseClicked(null);
versionLabel.setText("v" + Version.VERSION);
}
});
HBox versionBox = new HBox();
versionBox.setSpacing(10);
versionBox.setAlignment(Pos.CENTER);
versionBox.setAlignment(Pos.BASELINE_CENTER);
versionBox.getChildren().addAll(versionLabel, blockchainSyncIndicator);
setLeftAnchor(versionBox, 10d);
setRightAnchor(versionBox, 10d);
setBottomAnchor(versionBox, 7d);

// P2P Network
Label p2PNetworkLabel = new AutoTooltipLabel();
Expand Down Expand Up @@ -779,7 +777,7 @@ private AnchorPane createFooter() {
setRightAnchor(vBox, 33d);
setBottomAnchor(vBox, 5d);

return new AnchorPane(separator, blockchainSyncBox, versionLabel, vBox, p2PNetworkIcon) {{
return new AnchorPane(separator, btcInfoLabel, versionBox, vBox, p2PNetworkIcon) {{
setId("footer-pane");
setMinHeight(30);
setMaxHeight(30);
Expand Down
19 changes: 18 additions & 1 deletion desktop/src/main/java/bisq/desktop/main/MainViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import bisq.common.Timer;
import bisq.common.UserThread;
import bisq.common.app.DevEnv;
import bisq.common.app.Version;
import bisq.common.config.Config;
import bisq.common.file.CorruptedStorageFileHandler;

Expand Down Expand Up @@ -133,6 +134,7 @@ public class MainViewModel implements ViewModel, BisqSetup.BisqSetupListener {
private final BooleanProperty showAppScreen = new SimpleBooleanProperty();
private final DoubleProperty combinedSyncProgress = new SimpleDoubleProperty(-1);
private final BooleanProperty isSplashScreenRemoved = new SimpleBooleanProperty();
private final StringProperty footerVersionInfo = new SimpleStringProperty();
private Timer checkNumberOfBtcPeersTimer;
private Timer checkNumberOfP2pNetworkPeersTimer;
@SuppressWarnings("FieldCanBeLocal")
Expand Down Expand Up @@ -414,6 +416,15 @@ private void setupHandlers() {
daoPresentation.getBsqSyncProgress().addListener((observable, oldValue, newValue) -> updateBtcSyncProgress());

bisqSetup.setFilterWarningHandler(warning -> new Popup().warning(warning).show());

this.footerVersionInfo.setValue("v" + Version.VERSION);
this.getNewVersionAvailableProperty().addListener((observable, oldValue, newValue) -> {
if (newValue) {
this.footerVersionInfo.setValue("v" + Version.VERSION + " " + Res.get("mainView.version.update"));
} else {
this.footerVersionInfo.setValue("v" + Version.VERSION);
}
});
}

private void showRevolutAccountUpdateWindow(List<RevolutAccount> revolutAccountList) {
Expand Down Expand Up @@ -596,7 +607,13 @@ StringProperty getLockedBalance() {
// Wallet
StringProperty getBtcInfo() {
final StringProperty combinedInfo = new SimpleStringProperty();
combinedInfo.bind(Bindings.concat(bisqSetup.getBtcInfo(), " ", daoPresentation.getBsqInfo()));
combinedInfo.bind(bisqSetup.getBtcInfo());
return combinedInfo;
}

StringProperty getCombinedFooterInfo() {
final StringProperty combinedInfo = new SimpleStringProperty();
combinedInfo.bind(Bindings.concat(this.footerVersionInfo, " ", daoPresentation.getBsqInfo()));
return combinedInfo;
}

Expand Down

0 comments on commit 55c663a

Please sign in to comment.