Skip to content

Commit

Permalink
Add total received BTC field
Browse files Browse the repository at this point in the history
Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
  • Loading branch information
HenrikJannsen committed Mar 31, 2023
1 parent afe4bcc commit ee83607
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 25 deletions.
1 change: 1 addition & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2324,6 +2324,7 @@ dao.burningman.daoBalanceTotalBurned=Total amount of burned BSQ
dao.burningman.daoBalanceTotalDistributed=Total amount of distributed BTC / BSQ
dao.burningman.selectedContributor=Selected contributor
dao.burningman.selectedContributorName=Contributor name
dao.burningman.selectedContributorTotalReceived=Total received
dao.burningman.selectedContributorTotalRevenue=Total revenue
dao.burningman.selectedContributorAddress=Receiver address
dao.burningman.shared.table.height=Block height
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class BalanceEntryItem {
@Getter
private final Optional<Long> burnedBsq;
@Getter
private final Optional<Long> revenue;
private final long revenue;

// We create the strings on demand and cache them. For large data sets it would be a bit slow otherwise.
private String monthAsString, dateAsString, receivedBtcAsString, receivedBtcAsBsqAsString, burnedBsqAsString, revenueAsString,
Expand Down Expand Up @@ -111,11 +111,7 @@ class BalanceEntryItem {
receivedBtcAsBsq = Optional.of(MathUtils.roundDoubleToLong(MathUtils.scaleDownByPowerOf10(volume, 6)));
}

if (balanceEntry instanceof MonthlyBalanceEntry) {
revenue = Optional.of(receivedBtcAsBsq.orElse(0L) + burnedBsq.get());
} else {
revenue = Optional.empty();
}
revenue = receivedBtcAsBsq.orElse(0L) + burnedBsq.orElse(0L);
}

String getMonthAsString() {
Expand Down Expand Up @@ -168,7 +164,8 @@ String getRevenueAsString() {
return revenueAsString;
}

revenueAsString = revenue.filter(e -> e != 0).map(bsqFormatter::formatCoin).orElse("");
revenueAsString = balanceEntry instanceof MonthlyBalanceEntry ?
bsqFormatter.formatCoin(revenue) : "";
return revenueAsString;
}

Expand Down Expand Up @@ -214,6 +211,6 @@ String getTypeAsString() {
receivedBtc = null;
receivedBtcAsBsq = null;
burnedBsq = null;
revenue = null;
revenue = 0L;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,12 @@ public class BurningManView extends ActivatableView<ScrollPane, Void> implements
private TitledGroupBg burnOutputsTitledGroupBg, compensationsTitledGroupBg, selectedContributorTitledGroupBg;
private AutoTooltipSlideToggleButton showOnlyActiveBurningmenToggle, showMonthlyBalanceEntryToggle;
private TextField expectedRevenueField, daoBalanceTotalBurnedField, daoBalanceTotalDistributedField,
selectedContributorNameField, selectedContributorTotalRevenueField, selectedContributorAddressField,
burnTargetField;
selectedContributorNameField, selectedContributorTotalRevenueField, selectedContributorTotalReceivedField,
selectedContributorAddressField, burnTargetField;
private ToggleGroup balanceEntryToggleGroup;
private HBox balanceEntryHBox;
private VBox selectedContributorNameBox, selectedContributorTotalRevenueBox, selectedContributorAddressBox;
private VBox selectedContributorNameBox, selectedContributorTotalReceivedBox, selectedContributorTotalRevenueBox,
selectedContributorAddressBox;
private TableView<BurningManListItem> burningManTableView;
private TableView<BalanceEntryItem> balanceEntryTableView;
private TableView<BurnOutputListItem> burnOutputsTableView;
Expand Down Expand Up @@ -227,6 +228,8 @@ private BurningManView(DaoFacade daoFacade,
selectedContributorTitledGroupBg.setVisible(isValueSet);
selectedContributorNameBox.setManaged(isValueSet);
selectedContributorNameBox.setVisible(isValueSet);
selectedContributorTotalReceivedBox.setManaged(isValueSet);
selectedContributorTotalReceivedBox.setVisible(isValueSet);
selectedContributorTotalRevenueBox.setManaged(isValueSet);
selectedContributorTotalRevenueBox.setVisible(isValueSet);
selectedContributorAddressBox.setManaged(isValueSet);
Expand Down Expand Up @@ -353,11 +356,13 @@ public BurningManListItem fromString(String string) {
Res.get("dao.burningman.selectedContributor"), Layout.COMPACT_GROUP_DISTANCE);
selectedContributorTitledGroupBg.setManaged(false);
selectedContributorTitledGroupBg.setVisible(false);
Tuple3<Label, TextField, VBox> nameTuple = addCompactTopLabelTextField(gridPane, ++gridRow,
Res.get("dao.burningman.selectedContributorName"), "",
Layout.COMPACT_GROUP_DISTANCE + Layout.FLOATING_LABEL_DISTANCE);
selectedContributorNameField = nameTuple.second;
selectedContributorNameBox = nameTuple.third;

// left box
selectedContributorNameField = new BisqTextField();
selectedContributorNameField.setEditable(false);
selectedContributorNameField.setFocusTraversable(false);
selectedContributorNameBox = getTopLabelWithVBox(Res.get("dao.burningman.selectedContributorName"),
selectedContributorNameField).second;
selectedContributorNameBox.setManaged(false);
selectedContributorNameBox.setVisible(false);

Expand All @@ -369,6 +374,23 @@ public BurningManListItem fromString(String string) {
selectedContributorTotalRevenueBox.setManaged(false);
selectedContributorTotalRevenueBox.setVisible(false);

HBox leftHBox = new HBox(5, selectedContributorNameBox, selectedContributorTotalRevenueBox);
HBox.setHgrow(selectedContributorNameBox, Priority.ALWAYS);
HBox.setHgrow(selectedContributorTotalRevenueBox, Priority.ALWAYS);

GridPane.setRowIndex(leftHBox, ++gridRow);
GridPane.setMargin(leftHBox, new Insets(Layout.COMPACT_GROUP_DISTANCE + Layout.FLOATING_LABEL_DISTANCE, 0, 0, 0));
gridPane.getChildren().add(leftHBox);

// right box
selectedContributorTotalReceivedField = new BisqTextField();
selectedContributorTotalReceivedField.setEditable(false);
selectedContributorTotalReceivedField.setFocusTraversable(false);
selectedContributorTotalReceivedBox = getTopLabelWithVBox(Res.get("dao.burningman.selectedContributorTotalReceived"),
selectedContributorTotalReceivedField).second;
selectedContributorTotalReceivedBox.setManaged(false);
selectedContributorTotalReceivedBox.setVisible(false);

selectedContributorAddressField = new BisqTextField();
selectedContributorAddressField.setEditable(false);
selectedContributorAddressField.setFocusTraversable(false);
Expand All @@ -377,15 +399,14 @@ public BurningManListItem fromString(String string) {
selectedContributorAddressBox.setManaged(false);
selectedContributorAddressBox.setVisible(false);

HBox rightHBox = new HBox(5, selectedContributorTotalRevenueBox, selectedContributorAddressBox);
HBox.setHgrow(selectedContributorTotalRevenueBox, Priority.ALWAYS);
HBox rightHBox = new HBox(5, selectedContributorTotalReceivedBox, selectedContributorAddressBox);
HBox.setHgrow(selectedContributorTotalReceivedBox, Priority.ALWAYS);
HBox.setHgrow(selectedContributorAddressBox, Priority.ALWAYS);

GridPane.setRowIndex(rightHBox, gridRow);
GridPane.setColumnIndex(rightHBox, 1);
GridPane.setMargin(rightHBox, new Insets(Layout.COMPACT_GROUP_DISTANCE + Layout.FLOATING_LABEL_DISTANCE, 0, 0, 0));
gridPane.getChildren().add(rightHBox);
GridPane.setColumnSpan(rightHBox, 2);

// BalanceEntry
TitledGroupBg balanceEntryTitledGroupBg = new TitledGroupBg();
Expand Down Expand Up @@ -726,15 +747,20 @@ private void onBurningManSelected(BurningManListItem burningManListItem) {
.map(balanceEntry -> new BalanceEntryItem(balanceEntry, averageBsqPriceByMonth, bsqFormatter, btcFormatter))
.collect(Collectors.toList()));

long totalRevenue = balanceEntryObservableList.stream()
.filter(item -> item.getRevenue().isPresent())
.mapToLong(item -> item.getRevenue().get())
long totalRevenueAsBsq = balanceEntryObservableList.stream()
.mapToLong(item -> item.getRevenue())
.sum();
selectedContributorTotalRevenueField.setText(bsqFormatter.formatCoinWithCode(totalRevenueAsBsq));

long totalReceivedAsBtc = balanceEntryObservableList.stream()
.filter(item -> item.getReceivedBtc().isPresent())
.mapToLong(item -> item.getReceivedBtc().get())
.sum();
String totalRevenueAsBsq = bsqFormatter.formatCoinWithCode(totalRevenue);
selectedContributorTotalRevenueField.setText(totalRevenueAsBsq);
selectedContributorTotalReceivedField.setText(btcFormatter.formatCoinWithCode(totalReceivedAsBtc));
} else {
balanceEntryObservableList.clear();
selectedContributorTotalRevenueField.clear();
selectedContributorTotalReceivedField.clear();
}
GUIUtil.setFitToRowsForTableView(balanceEntryTableView, 36, 28, 4, 6);

Expand Down Expand Up @@ -1321,7 +1347,7 @@ public void updateItem(final BalanceEntryItem item, boolean empty) {
}
});
balanceEntryTableView.getColumns().add(column);
column.setComparator(Comparator.comparing(e -> e.getRevenue().orElse(null)));
column.setComparator(Comparator.comparing(BalanceEntryItem::getRevenue));
column.setSortType(TableColumn.SortType.DESCENDING);

column = new AutoTooltipTableColumn<>(Res.get("dao.burningman.table.balanceEntry.type"));
Expand Down

0 comments on commit ee83607

Please sign in to comment.