Merge pull request #2481 from devinbileck/show-btc-valuation

Show valuation in BTC balance tooltips
This commit is contained in:
Manfred Karrer 2019-02-28 20:59:13 -05:00 committed by GitHub
commit bb368d638c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 84 additions and 3 deletions

View File

@ -40,6 +40,7 @@ import bisq.desktop.main.settings.SettingsView;
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;
@ -80,11 +81,17 @@ import javafx.geometry.Insets;
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;
@ -186,6 +193,11 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
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 -> {
@ -231,15 +243,75 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
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);

View File

@ -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;
@ -591,6 +592,10 @@ public class MainViewModel implements ViewModel, BisqSetup.BisqSetupCompleteList
return marketPricePresentation.getMarketPriceUpdated();
}
StringProperty getMarketPrice() {
return marketPricePresentation.getMarketPrice();
}
public ObservableList<PriceFeedComboBoxItem> getPriceFeedComboBoxItems() {
return marketPricePresentation.getPriceFeedComboBoxItems();
}

View File

@ -237,4 +237,8 @@ public class MarketPricePresentation {
public IntegerProperty getMarketPriceUpdated() {
return marketPriceUpdated;
}
public StringProperty getMarketPrice() {
return marketPrice;
}
}