Skip to content

Commit

Permalink
Merge pull request #6624 from HenrikJannsen/add_total_revenue_to_burn…
Browse files Browse the repository at this point in the history
…ingmen_view

Add total revenue to burningmen view
  • Loading branch information
alejandrogarcia83 authored Apr 2, 2023
2 parents 6c09a49 + ee83607 commit 8318867
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 75 deletions.
2 changes: 2 additions & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2324,6 +2324,8 @@ 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
dao.burningman.shared.table.cycle=Cycle
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 @@ -24,6 +24,7 @@
import bisq.desktop.components.AutoTooltipRadioButton;
import bisq.desktop.components.AutoTooltipSlideToggleButton;
import bisq.desktop.components.AutoTooltipTableColumn;
import bisq.desktop.components.BisqTextField;
import bisq.desktop.components.InputTextField;
import bisq.desktop.components.TitledGroupBg;
import bisq.desktop.main.overlays.popups.Popup;
Expand Down Expand Up @@ -136,10 +137,13 @@ public class BurningManView extends ActivatableView<ScrollPane, Void> implements
private Button burnButton, exportBalanceEntriesButton;
private TitledGroupBg burnOutputsTitledGroupBg, compensationsTitledGroupBg, selectedContributorTitledGroupBg;
private AutoTooltipSlideToggleButton showOnlyActiveBurningmenToggle, showMonthlyBalanceEntryToggle;
private TextField expectedRevenueField, daoBalanceTotalBurnedField, daoBalanceTotalDistributedField, selectedContributorNameField, selectedContributorAddressField, burnTargetField;
private TextField expectedRevenueField, daoBalanceTotalBurnedField, daoBalanceTotalDistributedField,
selectedContributorNameField, selectedContributorTotalRevenueField, selectedContributorTotalReceivedField,
selectedContributorAddressField, burnTargetField;
private ToggleGroup balanceEntryToggleGroup;
private HBox balanceEntryHBox;
private VBox selectedContributorNameBox, selectedContributorAddressBox;
private VBox selectedContributorNameBox, selectedContributorTotalReceivedBox, selectedContributorTotalRevenueBox,
selectedContributorAddressBox;
private TableView<BurningManListItem> burningManTableView;
private TableView<BalanceEntryItem> balanceEntryTableView;
private TableView<BurnOutputListItem> burnOutputsTableView;
Expand Down Expand Up @@ -224,12 +228,17 @@ 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);
selectedContributorAddressBox.setVisible(isValueSet);
if (isValueSet) {
onBurningManSelected(newValue);
} else {
selectedContributorNameField.clear();
selectedContributorTotalRevenueField.clear();
selectedContributorAddressField.clear();
}
};
Expand Down Expand Up @@ -324,7 +333,7 @@ public BurningManListItem fromString(String string) {
Tuple3<Label, TextField, VBox> daoBalanceTotalBurnedTuple = addCompactTopLabelTextField(gridPane, ++gridRow,
Res.get("dao.burningman.daoBalanceTotalBurned"), "",
Layout.COMPACT_GROUP_DISTANCE + Layout.FLOATING_LABEL_DISTANCE);
daoBalanceTotalBurnedField =daoBalanceTotalBurnedTuple.second;
daoBalanceTotalBurnedField = daoBalanceTotalBurnedTuple.second;
Tuple3<Label, TextField, VBox> daoBalanceTotalDistributedTuple = addCompactTopLabelTextField(gridPane, gridRow,
Res.get("dao.burningman.daoBalanceTotalDistributed"), "",
Layout.COMPACT_GROUP_DISTANCE + Layout.FLOATING_LABEL_DISTANCE);
Expand All @@ -347,24 +356,58 @@ 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);

Tuple3<Label, TextField, VBox> addressTuple = addCompactTopLabelTextField(gridPane, gridRow,
Res.get("dao.burningman.selectedContributorAddress"), "",
Layout.COMPACT_GROUP_DISTANCE + Layout.FLOATING_LABEL_DISTANCE);
selectedContributorAddressField = addressTuple.second;
selectedContributorAddressBox = addressTuple.third;
GridPane.setColumnSpan(selectedContributorAddressBox, 2);
GridPane.setColumnIndex(selectedContributorAddressBox, 1);
selectedContributorTotalRevenueField = new BisqTextField();
selectedContributorTotalRevenueField.setEditable(false);
selectedContributorTotalRevenueField.setFocusTraversable(false);
selectedContributorTotalRevenueBox = getTopLabelWithVBox(Res.get("dao.burningman.selectedContributorTotalRevenue"),
selectedContributorTotalRevenueField).second;
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);
selectedContributorAddressBox = getTopLabelWithVBox(Res.get("dao.burningman.selectedContributorAddress"),
selectedContributorAddressField).second;
selectedContributorAddressBox.setManaged(false);
selectedContributorAddressBox.setVisible(false);

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);

// BalanceEntry
TitledGroupBg balanceEntryTitledGroupBg = new TitledGroupBg();
balanceEntryTitledGroupBg.setText(Res.get("dao.burningman.balanceEntry.table.header"));
Expand Down Expand Up @@ -461,7 +504,7 @@ private void writeReport() {
CSVEntryConverter<String> contentConverter = item -> item.split(separator);
int year = 2022;
int month = 11;
while(true) {
while (true) {
Date date = DateUtil.getStartOfMonth(year, month);
long feeAmount = burningManAccountingService.getDistributedBtcBalanceByMonth(date)
.filter(ee -> ee.getType() == BalanceEntry.Type.BTC_TRADE_FEE_TX).mapToLong(BaseBalanceEntry::getAmount).sum();
Expand Down Expand Up @@ -703,8 +746,21 @@ private void onBurningManSelected(BurningManListItem burningManListItem) {
balanceEntryObservableList.setAll(balanceEntries.stream()
.map(balanceEntry -> new BalanceEntryItem(balanceEntry, averageBsqPriceByMonth, bsqFormatter, btcFormatter))
.collect(Collectors.toList()));

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();
selectedContributorTotalReceivedField.setText(btcFormatter.formatCoinWithCode(totalReceivedAsBtc));
} else {
balanceEntryObservableList.clear();
selectedContributorTotalRevenueField.clear();
selectedContributorTotalReceivedField.clear();
}
GUIUtil.setFitToRowsForTableView(balanceEntryTableView, 36, 28, 4, 6);

Expand Down Expand Up @@ -915,6 +971,7 @@ public void updateItem(final BurningManListItem item, boolean empty) {
burningManTableView.getColumns().add(column);
column.setComparator(Comparator.comparing(BurningManListItem::getAccumulatedDecayedBurnAmount));
column.setSortType(TableColumn.SortType.DESCENDING);
column.setVisible(false);

column = new AutoTooltipTableColumn<>(Res.get("dao.burningman.table.burnAmount"));
column.setMinWidth(130);
Expand All @@ -940,31 +997,6 @@ public void updateItem(final BurningManListItem item, boolean empty) {
column.setComparator(Comparator.comparing(BurningManListItem::getAccumulatedBurnAmount));
column.setSortType(TableColumn.SortType.DESCENDING);

/* column = new AutoTooltipTableColumn<>(Res.get("dao.burningman.table.numBurnOutputs"));
column.setMinWidth(90);
column.setMaxWidth(column.getMinWidth());
column.getStyleClass().add("last-column");
column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
column.setCellFactory(new Callback<>() {
@Override
public TableCell<BurningManListItem, BurningManListItem> call(TableColumn<BurningManListItem,
BurningManListItem> column) {
return new TableCell<>() {
@Override
public void updateItem(final BurningManListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
setText(String.valueOf(item.getNumBurnOutputs()));
} else
setText("");
}
};
}
});
burningManTableView.getColumns().add(column);
column.setComparator(Comparator.comparing(BurningManListItem::getNumBurnOutputs));
column.setSortType(TableColumn.SortType.DESCENDING);*/

column = new AutoTooltipTableColumn<>(Res.get("dao.burningman.table.issuanceShare"));
column.setMinWidth(110);
column.getStyleClass().add("last-column");
Expand Down Expand Up @@ -1012,6 +1044,7 @@ public void updateItem(final BurningManListItem item, boolean empty) {
burningManTableView.getColumns().add(column);
column.setComparator(Comparator.comparing(BurningManListItem::getAccumulatedDecayedCompensationAmount));
column.setSortType(TableColumn.SortType.DESCENDING);
column.setVisible(false);

column = new AutoTooltipTableColumn<>(Res.get("dao.burningman.table.issuanceAmount"));
column.setMinWidth(120);
Expand All @@ -1036,31 +1069,6 @@ public void updateItem(final BurningManListItem item, boolean empty) {
burningManTableView.getColumns().add(column);
column.setComparator(Comparator.comparing(BurningManListItem::getAccumulatedCompensationAmount));
column.setSortType(TableColumn.SortType.DESCENDING);

/* column = new AutoTooltipTableColumn<>(Res.get("dao.burningman.table.numIssuances"));
column.setMinWidth(110);
column.setMaxWidth(column.getMinWidth());
column.getStyleClass().add("last-column");
column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
column.setCellFactory(new Callback<>() {
@Override
public TableCell<BurningManListItem, BurningManListItem> call(TableColumn<BurningManListItem,
BurningManListItem> column) {
return new TableCell<>() {
@Override
public void updateItem(final BurningManListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
setText(item.getNumIssuancesAsString());
} else
setText("");
}
};
}
});
burningManTableView.getColumns().add(column);
column.setComparator(Comparator.comparing(BurningManListItem::getNumIssuances));
column.setSortType(TableColumn.SortType.DESCENDING);*/
}

private void createBurnOutputsColumns() {
Expand Down Expand Up @@ -1339,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 8318867

Please sign in to comment.