Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show valuation in BTC balance tooltips #2481

Merged
merged 1 commit into from Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
78 changes: 75 additions & 3 deletions desktop/src/main/java/bisq/desktop/main/MainView.java
Expand Up @@ -40,6 +40,7 @@
import bisq.desktop.util.Transitions;

import bisq.core.exceptions.BisqException;
import bisq.core.locale.GlobalSettings;
import bisq.core.locale.Res;
import bisq.core.util.BSFormatter;

Expand Down Expand Up @@ -80,11 +81,17 @@
import javafx.geometry.Orientation;
import javafx.geometry.Pos;

import javafx.beans.binding.ObjectBinding;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;

import java.text.DecimalFormat;
import java.text.NumberFormat;

import java.util.Locale;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -186,6 +193,11 @@ protected void initialize() {
JFXBadge daoButtonWithBadge = new JFXBadge(daoButton);
daoButtonWithBadge.getStyleClass().add("new");

Locale locale = GlobalSettings.getLocale();
DecimalFormat currencyFormat = (DecimalFormat) NumberFormat.getNumberInstance(locale);
currencyFormat.setMinimumFractionDigits(2);
currencyFormat.setMaximumFractionDigits(2);

root.sceneProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
newValue.addEventHandler(KeyEvent.KEY_RELEASED, keyEvent -> {
Expand Down Expand Up @@ -231,15 +243,75 @@ protected void initialize() {
Tuple2<Label, VBox> availableBalanceBox = getBalanceBox(Res.get("mainView.balance.available"));
availableBalanceBox.first.textProperty().bind(model.getAvailableBalance());
availableBalanceBox.first.setPrefWidth(100);
availableBalanceBox.first.setTooltip(new Tooltip(Res.get("mainView.balance.available")));
availableBalanceBox.first.tooltipProperty().bind(new ObjectBinding<>() {
{
bind(model.getAvailableBalance());
bind(model.getMarketPrice());
}

@Override
protected Tooltip computeValue() {
String tooltipText = Res.get("mainView.balance.available");
try {
double availableBalance = Double.parseDouble(
model.getAvailableBalance().getValue().replace("BTC", ""));
double marketPrice = Double.parseDouble(model.getMarketPrice().getValue());
tooltipText += "\n" + currencyFormat.format(availableBalance * marketPrice) +
" " + model.getPreferences().getPreferredTradeCurrency().getCode();
} catch (NullPointerException | NumberFormatException e) {
// Either the balance or market price is not available yet
}
return new Tooltip(tooltipText);
}
});

Tuple2<Label, VBox> reservedBalanceBox = getBalanceBox(Res.get("mainView.balance.reserved.short"));
reservedBalanceBox.first.textProperty().bind(model.getReservedBalance());
reservedBalanceBox.first.setTooltip(new Tooltip(Res.get("mainView.balance.reserved")));
reservedBalanceBox.first.tooltipProperty().bind(new ObjectBinding<>() {
{
bind(model.getReservedBalance());
bind(model.getMarketPrice());
}

@Override
protected Tooltip computeValue() {
String tooltipText = Res.get("mainView.balance.reserved");
try {
double reservedBalance = Double.parseDouble(
model.getReservedBalance().getValue().replace("BTC", ""));
double marketPrice = Double.parseDouble(model.getMarketPrice().getValue());
tooltipText += "\n" + currencyFormat.format(reservedBalance * marketPrice) +
" " + model.getPreferences().getPreferredTradeCurrency().getCode();
} catch (NullPointerException | NumberFormatException e) {
// Either the balance or market price is not available yet
}
return new Tooltip(tooltipText);
}
});

Tuple2<Label, VBox> lockedBalanceBox = getBalanceBox(Res.get("mainView.balance.locked.short"));
lockedBalanceBox.first.textProperty().bind(model.getLockedBalance());
lockedBalanceBox.first.setTooltip(new Tooltip(Res.get("mainView.balance.locked")));
lockedBalanceBox.first.tooltipProperty().bind(new ObjectBinding<>() {
{
bind(model.getLockedBalance());
bind(model.getMarketPrice());
}

@Override
protected Tooltip computeValue() {
String tooltipText = Res.get("mainView.balance.locked");
try {
double lockedBalance = Double.parseDouble(
model.getLockedBalance().getValue().replace("BTC", ""));
double marketPrice = Double.parseDouble(model.getMarketPrice().getValue());
tooltipText += "\n" + currencyFormat.format(lockedBalance * marketPrice) +
" " + model.getPreferences().getPreferredTradeCurrency().getCode();
} catch (NullPointerException | NumberFormatException e) {
// Either the balance or market price is not available yet
}
return new Tooltip(tooltipText);
}
});

HBox primaryNav = new HBox(marketButton, getNavigationSeparator(), buyButton, getNavigationSeparator(),
sellButton, getNavigationSeparator(), portfolioButtonWithBadge, getNavigationSeparator(), fundsButton);
Expand Down
5 changes: 5 additions & 0 deletions desktop/src/main/java/bisq/desktop/main/MainViewModel.java
Expand Up @@ -97,6 +97,7 @@ public class MainViewModel implements ViewModel, BisqSetup.BisqSetupCompleteList
private final DaoPresentation daoPresentation;
private final P2PService p2PService;
private final TradeManager tradeManager;
@Getter
private final Preferences preferences;
private final PrivateNotificationManager privateNotificationManager;
private final WalletPasswordWindow walletPasswordWindow;
Expand Down Expand Up @@ -591,6 +592,10 @@ IntegerProperty getMarketPriceUpdated() {
return marketPricePresentation.getMarketPriceUpdated();
}

StringProperty getMarketPrice() {
return marketPricePresentation.getMarketPrice();
}

public ObservableList<PriceFeedComboBoxItem> getPriceFeedComboBoxItems() {
return marketPricePresentation.getPriceFeedComboBoxItems();
}
Expand Down
Expand Up @@ -237,4 +237,8 @@ public BooleanProperty getIsPriceAvailable() {
public IntegerProperty getMarketPriceUpdated() {
return marketPriceUpdated;
}

public StringProperty getMarketPrice() {
return marketPrice;
}
}