Add bonding dashboard

This commit is contained in:
sqrrm 2018-06-28 14:47:26 +02:00
parent 60e58f7bcb
commit 90297201f2
No known key found for this signature in database
GPG key ID: 45235F9EF87089EC
7 changed files with 134 additions and 8 deletions

View file

@ -28,7 +28,9 @@ import bisq.desktop.components.MenuItem;
import bisq.desktop.main.MainView;
import bisq.desktop.main.dao.DaoView;
import bisq.desktop.main.dao.bonding.Lock.LockupBSQView;
import bisq.desktop.main.dao.bonding.dashboard.BondingDashboardView;
import bisq.desktop.main.dao.bonding.unlock.UnlockBSQView;
import bisq.desktop.main.dao.voting.dashboard.VotingDashboardView;
import bisq.core.locale.Res;
@ -51,8 +53,7 @@ public class BondingView extends ActivatableViewAndModel {
private final ViewLoader viewLoader;
private final Navigation navigation;
private MenuItem lockupBSQ;
private MenuItem unlockBSQ;
private MenuItem dashboard, lockupBSQ, unlockBSQ;
private Navigation.Listener listener;
@FXML
@ -80,15 +81,18 @@ public class BondingView extends ActivatableViewAndModel {
ToggleGroup toggleGroup = new ToggleGroup();
final List<Class<? extends View>> baseNavPath = Arrays.asList(MainView.class, DaoView.class, bisq.desktop.main.dao.bonding.BondingView.class);
dashboard = new MenuItem(navigation, toggleGroup, Res.get("shared.dashboard"),
BondingDashboardView.class, AwesomeIcon.DASHBOARD, baseNavPath);
lockupBSQ = new MenuItem(navigation, toggleGroup, Res.get("dao.bonding.menuItem.lockupBSQ"),
LockupBSQView.class, AwesomeIcon.LIST_UL, baseNavPath);
unlockBSQ = new MenuItem(navigation, toggleGroup, Res.get("dao.bonding.menuItem.unlockBSQ"),
UnlockBSQView.class, AwesomeIcon.LIST_UL, baseNavPath);
leftVBox.getChildren().addAll(lockupBSQ, unlockBSQ);
leftVBox.getChildren().addAll(dashboard, lockupBSQ, unlockBSQ);
}
@Override
protected void activate() {
dashboard.activate();
lockupBSQ.activate();
unlockBSQ.activate();
@ -111,6 +115,7 @@ public class BondingView extends ActivatableViewAndModel {
protected void deactivate() {
navigation.removeListener(listener);
dashboard.deactivate();
lockupBSQ.deactivate();
unlockBSQ.deactivate();
}
@ -119,7 +124,8 @@ public class BondingView extends ActivatableViewAndModel {
View view = viewLoader.load(viewClass);
content.getChildren().setAll(view.getRoot());
if (view instanceof LockupBSQView) lockupBSQ.setSelected(true);
if (view instanceof BondingDashboardView) dashboard.setSelected(true);
else if (view instanceof LockupBSQView) lockupBSQ.setSelected(true);
else if (view instanceof UnlockBSQView) unlockBSQ.setSelected(true);
}
}

View file

@ -22,8 +22,9 @@
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<GridPane fx:id="root" fx:controller="bisq.desktop.main.dao.bonding.Lock.LockupBSQView"
hgap="5.0" vgap="5.0"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0" AnchorPane.topAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="-10.0"
xmlns:fx="http://javafx.com/fxml">
<columnConstraints>

View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ This file is part of Bisq.
~
~ Bisq is free software: you can redistribute it and/or modify it
~ under the terms of the GNU Affero General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or (at
~ your option) any later version.
~
~ Bisq is distributed in the hope that it will be useful, but WITHOUT
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
~ License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with Bisq. If not, see <http://www.gnu.org/licenses/>.
-->
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<GridPane fx:id="root" fx:controller="bisq.desktop.main.dao.bonding.dashboard.BondingDashboardView"
hgap="5.0" vgap="5.0"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="-10.0"
xmlns:fx="http://javafx.com/fxml">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" halignment="RIGHT" minWidth="160.0"/>
<ColumnConstraints hgrow="ALWAYS" minWidth="300.0"/>
</columnConstraints>
</GridPane>

View file

@ -0,0 +1,58 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.desktop.main.dao.bonding.dashboard;
import bisq.desktop.common.view.ActivatableView;
import bisq.desktop.common.view.FxmlView;
import bisq.desktop.main.dao.wallet.BsqBalanceUtil;
import javax.inject.Inject;
import javafx.scene.layout.GridPane;
@FxmlView
public class BondingDashboardView extends ActivatableView<GridPane, Void> {
private final BsqBalanceUtil bsqBalanceUtil;
private int gridRow = 0;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor, lifecycle
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
private BondingDashboardView(BsqBalanceUtil bsqBalanceUtil) {
this.bsqBalanceUtil = bsqBalanceUtil;
}
public void initialize() {
gridRow = bsqBalanceUtil.addGroup(root, gridRow);
gridRow = bsqBalanceUtil.addBondBalanceGroup(root, gridRow);
}
@Override
protected void activate() {
bsqBalanceUtil.activate();
}
@Override
protected void deactivate() {
bsqBalanceUtil.deactivate();
}
}

View file

@ -22,8 +22,9 @@
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<GridPane fx:id="root" fx:controller="bisq.desktop.main.dao.bonding.unlock.UnlockBSQView"
hgap="5.0" vgap="5.0"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0" AnchorPane.topAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="-10.0"
xmlns:fx="http://javafx.com/fxml">
<columnConstraints>

View file

@ -436,8 +436,6 @@ public class UnlockBSQView extends ActivatableView<GridPane, Void> implements Bs
bsqBalanceUtil.deactivate();
bsqWalletService.removeBsqBalanceListener(this);
bsqBalanceUtil.deactivate();
lockedTxs.predicateProperty().unbind();
bsqWalletService.getWalletTransactions().removeListener(walletBsqTransactionsListener);
bsqWalletService.removeBsqBalanceListener(this);

View file

@ -33,6 +33,7 @@ import javafx.scene.layout.GridPane;
import javafx.geometry.Pos;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import static bisq.desktop.util.FormBuilder.addLabelTextField;
@ -42,9 +43,14 @@ import static bisq.desktop.util.FormBuilder.addTitledGroupBg;
public class BsqBalanceUtil implements BsqBalanceListener {
private final BsqWalletService bsqWalletService;
private final BsqFormatter bsqFormatter;
// Displaying general BSQ info
private TextField confirmedBalanceTextField, pendingBalanceTextField, lockedForVoteBalanceTextField,
lockedInBondsBalanceTextField, totalBalanceTextField;
// Displaying bond dashboard info
private TextField lockedAmountTextField, unlockingAmountTextField;
@Inject
private BsqBalanceUtil(BsqWalletService bsqWalletService,
BsqFormatter bsqFormatter) {
@ -87,6 +93,23 @@ public class BsqBalanceUtil implements BsqBalanceListener {
return gridRow;
}
public int addBondBalanceGroup(GridPane gridPane, int gridRow) {
addTitledGroupBg(gridPane, ++gridRow, 2, Res.get("dao.bonding.dashboard.lockedHeadline"), Layout.GROUP_DISTANCE);
lockedAmountTextField = addLabelTextField(gridPane, gridRow, Res.get("dao.bonding.dashboard.lockedAmount"),
Layout.FIRST_ROW_DISTANCE + Layout.GROUP_DISTANCE).second;
lockedAmountTextField.setMouseTransparent(false);
lockedAmountTextField.setMaxWidth(150);
lockedAmountTextField.setAlignment(Pos.CENTER_RIGHT);
unlockingAmountTextField = addLabelTextField(gridPane, ++gridRow, Res.get("dao.bonding.dashboard.unlockingAmount")).second;
unlockingAmountTextField.setMouseTransparent(false);
unlockingAmountTextField.setMaxWidth(150);
unlockingAmountTextField.setAlignment(Pos.CENTER_RIGHT);
return gridRow;
}
public void activate() {
onUpdateBalances(bsqWalletService.getAvailableBalance(),
bsqWalletService.getPendingBalance(),
@ -112,6 +135,12 @@ public class BsqBalanceUtil implements BsqBalanceListener {
lockedForVoteBalanceTextField.setText(bsqFormatter.formatCoinWithCode(lockedForVotingBalance));
lockedInBondsBalanceTextField.setText(bsqFormatter.formatCoinWithCode(
lockedInBondsBalance.add(unlockingBondsBalance)));
if (lockedAmountTextField != null && unlockingAmountTextField != null) {
lockedAmountTextField.setText(bsqFormatter.formatCoinWithCode(lockedInBondsBalance));
unlockingAmountTextField.setText(bsqFormatter.formatCoinWithCode(unlockingBondsBalance));
}
final Coin total = confirmedBalance
.add(pendingBalance)
.add(lockedForVotingBalance)