Skip to content

Commit

Permalink
Add BM account UI
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikJannsen committed Nov 23, 2022
1 parent 0435594 commit def6083
Show file tree
Hide file tree
Showing 9 changed files with 837 additions and 221 deletions.
87 changes: 53 additions & 34 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2257,40 +2257,59 @@ dao.burnBsq.assets.trialFee=Fee for trial period
dao.burnBsq.assets.totalFee=Total fees paid
dao.burnBsq.assets.days={0} days
dao.burnBsq.assets.toFewDays=The asset fee is too low. The min. amount of days for the trial period is {0}.

dao.burningmen.target.header=Burn target
dao.burningmen.burn.header=Burn BSQ
dao.burningmen.amount.prompt=Amount to burn
dao.burningmen.amount.prompt.max=Amount to burn: {0} - {1} BSQ
dao.burningmen.candidates.table.header=Burningmen candidates
dao.burningmen.burnOutput.table.header=Burn outputs
dao.burningmen.compensations.table.header=Compensations
dao.burningmen.reimbursement.table.header=Reimbursement requests
dao.burningmen.expectedRevenue=Past 3-month average distribution
dao.burningmen.burnTarget.label=Amount of BSQ to burn
dao.burningmen.burnTarget.fromTo={0} - {1} BSQ
dao.burningmen.filter=Filter burningman candidates
dao.burningmen.toggle=Show only active burningmen
dao.burningmen.contributorsComboBox.prompt=Select any of my contributors
dao.burningmen.selectedContributor=Selected contributor
dao.burningmen.selectedContributorName=Contributor name
dao.burningmen.selectedContributorAddress=Receiver address
dao.burningmen.table.name=Contributor name
dao.burningmen.table.burnTarget=Burn target
dao.burningmen.table.expectedRevenue=Expected to receive
dao.burningmen.table.burnAmount=Burned amount
dao.burningmen.table.decayedBurnAmount=Decayed burned amount
dao.burningmen.table.burnAmountShare.label=Receiver share
dao.burningmen.table.burnAmountShare.capped={0} (capped from {1})
dao.burningmen.table.numBurnOutputs=Num. Burns
dao.burningmen.table.issuanceAmount=Issued amount
dao.burningmen.table.decayedIssuanceAmount=Decayed issued amount
dao.burningmen.table.issuanceShare=Issuance share
dao.burningmen.table.numIssuances=Num. issuances
dao.burningmen.table.reimbursedAmount=Reimbursed amount
dao.burningmen.shared.table.height=Block height
dao.burningmen.shared.table.cycle=Cycle
dao.burningmen.shared.table.date=Date
dao.burningman.target.header=Burn target
dao.burningman.burn.header=Burn BSQ
dao.burningman.amount.prompt=Amount to burn
dao.burningman.amount.prompt.max=Amount to burn: {0} - {1} BSQ
dao.burningman.candidates.table.header=Burningmen candidates
dao.burningman.burnOutput.table.header=Burn outputs
dao.burningman.balanceEntry.table.header=Revenue
dao.burningman.balanceEntry.table.showMonthlyToggle=By month
dao.burningman.balanceEntry.table.radio.all=All
dao.burningman.balanceEntry.table.radio.fee=BTC fees only
dao.burningman.balanceEntry.table.radio.dpt=DPT only
dao.burningman.balanceEntry.table.radio.burn=Burned BSQ

dao.burningman.compensations.table.header=Compensations
dao.burningman.reimbursement.table.header=Reimbursement requests
dao.burningman.expectedRevenue=Past 3-month average distribution
dao.burningman.burnTarget.label=Amount of BSQ to burn
dao.burningman.burnTarget.fromTo={0} - {1} BSQ
dao.burningman.filter=Filter burningman candidates
dao.burningman.toggle=Show only active burningmen
dao.burningman.contributorsComboBox.prompt=Select any of my contributors
dao.burningman.selectedContributor=Selected contributor
dao.burningman.selectedContributorName=Contributor name
dao.burningman.selectedContributorAddress=Receiver address
dao.burningman.shared.table.height=Block height
dao.burningman.shared.table.cycle=Cycle
dao.burningman.shared.table.date=Date
dao.burningman.table.name=Contributor name
dao.burningman.table.burnTarget=Burn target
dao.burningman.table.expectedRevenue=Expected to receive
dao.burningman.table.burnAmount=Burned amount
dao.burningman.table.decayedBurnAmount=Decayed burned amount
dao.burningman.table.burnAmountShare.label=Receiver share
dao.burningman.table.burnAmountShare.capped={0} (capped from {1})
dao.burningman.table.numBurnOutputs=Num. Burns
dao.burningman.table.issuanceAmount=Issued amount
dao.burningman.table.decayedIssuanceAmount=Decayed issued amount
dao.burningman.table.issuanceShare=Issuance share
dao.burningman.table.numIssuances=Num. issuances
dao.burningman.table.reimbursedAmount=Reimbursed amount
dao.burningman.table.balanceEntry.date=Date
dao.burningman.table.balanceEntry.receivedBtc=Received BTC
dao.burningman.table.balanceEntry.receivedBtcAsBsq=Received BTC as BSQ
dao.burningman.table.balanceEntry.burnedBsq=Burned BSQ
dao.burningman.table.balanceEntry.revenue=Revenue
dao.burningman.table.balanceEntry.price=BSQ/BTC price
dao.burningman.table.balanceEntry.type=Type

# From BalanceEntry.Type enum names
dao.burningman.balanceEntry.type.UNDEFINED=Undefined
dao.burningman.balanceEntry.type.BTC_TRADE_FEE_TX=Trade fee
dao.burningman.balanceEntry.type.DPT_TX=DPT
dao.burningman.balanceEntry.type.BURN_TX=Burned BSQ

# suppress inspection "UnusedProperty"
dao.assetState.UNDEFINED=Undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import bisq.desktop.main.MainView;
import bisq.desktop.main.dao.DaoView;
import bisq.desktop.main.dao.burnbsq.assetfee.AssetFeeView;
import bisq.desktop.main.dao.burnbsq.burningmen.BurningmenView;
import bisq.desktop.main.dao.burnbsq.burningman.BurningManView;
import bisq.desktop.main.dao.burnbsq.proofofburn.ProofOfBurnView;

import bisq.core.locale.Res;
Expand All @@ -50,7 +50,7 @@ public class BurnBsqView extends ActivatableView<AnchorPane, Void> {
private final ViewLoader viewLoader;
private final Navigation navigation;

private MenuItem proofOfBurn, burningmen, assetFee;
private MenuItem proofOfBurn, burningMan, assetFee;
private Navigation.Listener listener;

@FXML
Expand Down Expand Up @@ -81,25 +81,25 @@ public void initialize() {
List<Class<? extends View>> baseNavPath = Arrays.asList(MainView.class, DaoView.class, BurnBsqView.class);
proofOfBurn = new MenuItem(navigation, toggleGroup, Res.get("dao.burnBsq.menuItem.proofOfBurn"),
ProofOfBurnView.class, baseNavPath);
burningmen = new MenuItem(navigation, toggleGroup, Res.get("dao.burnBsq.menuItem.burningMan"),
BurningmenView.class, baseNavPath);
burningMan = new MenuItem(navigation, toggleGroup, Res.get("dao.burnBsq.menuItem.burningMan"),
BurningManView.class, baseNavPath);
assetFee = new MenuItem(navigation, toggleGroup, Res.get("dao.burnBsq.menuItem.assetFee"),
AssetFeeView.class, baseNavPath);
leftVBox.getChildren().addAll(burningmen, proofOfBurn, assetFee);
leftVBox.getChildren().addAll(burningMan, proofOfBurn, assetFee);
}

@Override
protected void activate() {
proofOfBurn.activate();
burningmen.activate();
burningMan.activate();
assetFee.activate();

navigation.addListener(listener);
ViewPath viewPath = navigation.getCurrentPath();
if (viewPath.size() == 3 && viewPath.indexOf(BurnBsqView.class) == 2 ||
viewPath.size() == 2 && viewPath.indexOf(DaoView.class) == 1) {
if (selectedViewClass == null)
selectedViewClass = BurningmenView.class;
selectedViewClass = BurningManView.class;

loadView(selectedViewClass);

Expand All @@ -115,7 +115,7 @@ protected void deactivate() {
navigation.removeListener(listener);

proofOfBurn.deactivate();
burningmen.deactivate();
burningMan.deactivate();
assetFee.deactivate();
}

Expand All @@ -124,7 +124,7 @@ private void loadView(Class<? extends View> viewClass) {
content.getChildren().setAll(view.getRoot());

if (view instanceof ProofOfBurnView) toggleGroup.selectToggle(proofOfBurn);
else if (view instanceof BurningmenView) toggleGroup.selectToggle(burningmen);
else if (view instanceof BurningManView) toggleGroup.selectToggle(burningMan);
else if (view instanceof AssetFeeView) toggleGroup.selectToggle(assetFee);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/*
* 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.burnbsq.burningman;

import bisq.desktop.util.DisplayUtils;

import bisq.core.dao.burningman.accounting.balance.BalanceEntry;
import bisq.core.dao.burningman.accounting.balance.BaseBalanceEntry;
import bisq.core.dao.burningman.accounting.balance.BurnedBsqBalanceEntry;
import bisq.core.dao.burningman.accounting.balance.MonthlyBalanceEntry;
import bisq.core.locale.Res;
import bisq.core.monetary.Price;
import bisq.core.util.coin.BsqFormatter;
import bisq.core.util.coin.CoinFormatter;

import bisq.common.util.MathUtils;

import org.bitcoinj.core.Coin;

import com.google.common.base.Joiner;

import java.text.SimpleDateFormat;

import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Slf4j

@EqualsAndHashCode
class BalanceEntryItem {
private final BalanceEntry balanceEntry;
private final BsqFormatter bsqFormatter;
private final CoinFormatter btcFormatter;
@Getter
private final Date date;
@Getter
private final Date month;
@Getter
private final Optional<Price> price;
@Getter
private final Optional<BalanceEntry.Type> type;
@Getter
private final Optional<Long> receivedBtc;
@Getter
private final Optional<Long> receivedBtcAsBsq;
@Getter
private final Optional<Long> burnedBsq;
@Getter
private final Optional<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,
priceAsString, typeAsString;

BalanceEntryItem(BalanceEntry balanceEntry,
Map<Date, Price> averageBsqPriceByMonth,
BsqFormatter bsqFormatter,
CoinFormatter btcFormatter) {
this.balanceEntry = balanceEntry;
this.bsqFormatter = bsqFormatter;
this.btcFormatter = btcFormatter;

date = balanceEntry.getDate();
month = balanceEntry.getMonth();
price = Optional.ofNullable(averageBsqPriceByMonth.get(month));
if (balanceEntry instanceof MonthlyBalanceEntry) {
MonthlyBalanceEntry monthlyBalanceEntry = (MonthlyBalanceEntry) balanceEntry;
receivedBtc = Optional.of(monthlyBalanceEntry.getReceivedBtc());
burnedBsq = Optional.of(-monthlyBalanceEntry.getBurnedBsq());
type = monthlyBalanceEntry.getTypes().size() == 1 ?
Optional.of(new ArrayList<>(monthlyBalanceEntry.getTypes()).get(0)) :
Optional.empty();
} else if (balanceEntry instanceof BurnedBsqBalanceEntry) {
BurnedBsqBalanceEntry burnedBsqBalanceEntry = (BurnedBsqBalanceEntry) balanceEntry;
receivedBtc = Optional.empty();
burnedBsq = Optional.of(-burnedBsqBalanceEntry.getAmount());
type = Optional.of(burnedBsqBalanceEntry.getType());
} else {
BaseBalanceEntry baseBalanceEntry = (BaseBalanceEntry) balanceEntry;
receivedBtc = Optional.of(baseBalanceEntry.getAmount());
burnedBsq = Optional.empty();
type = Optional.of(baseBalanceEntry.getType());
}

if (price.isEmpty() || receivedBtc.isEmpty()) {
receivedBtcAsBsq = Optional.empty();
} else {
long volume = price.get().getVolumeByAmount(Coin.valueOf(receivedBtc.get())).getValue();
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();
}
}

String getMonthAsString() {
if (monthAsString != null) {
return monthAsString;
}

monthAsString = new SimpleDateFormat("MMM-yyyy").format(month);
return monthAsString;
}

String getDateAsString() {
if (dateAsString != null) {
return dateAsString;
}

dateAsString = DisplayUtils.formatDateTime(date);
return dateAsString;
}

String getReceivedBtcAsString() {
if (receivedBtcAsString != null) {
return receivedBtcAsString;
}

receivedBtcAsString = receivedBtc.filter(e -> e != 0).map(btcFormatter::formatCoin).orElse("");
return receivedBtcAsString;
}

String getReceivedBtcAsBsqAsString() {
if (receivedBtcAsBsqAsString != null) {
return receivedBtcAsBsqAsString;
}

receivedBtcAsBsqAsString = receivedBtcAsBsq.filter(e -> e != 0).map(bsqFormatter::formatCoin).orElse("");
return receivedBtcAsBsqAsString;
}

String getBurnedBsqAsString() {
if (burnedBsqAsString != null) {
return burnedBsqAsString;
}

burnedBsqAsString = burnedBsq.filter(e -> e != 0).map(bsqFormatter::formatCoin).orElse("");
return burnedBsqAsString;
}

String getRevenueAsString() {
if (revenueAsString != null) {
return revenueAsString;
}

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

String getPriceAsString() {
if (priceAsString != null) {
return priceAsString;
}

priceAsString = price.map(Price::toString).orElse("");
return priceAsString;
}

String getTypeAsString() {
if (typeAsString != null) {
return typeAsString;
}

if (balanceEntry instanceof MonthlyBalanceEntry) {
MonthlyBalanceEntry monthlyBalanceEntry = (MonthlyBalanceEntry) balanceEntry;
typeAsString = type.map(type -> Res.get("dao.burningman.balanceEntry.type." + type.name()))
.orElse(Joiner.on(", ")
.join(monthlyBalanceEntry.getTypes().stream()
.map(type -> Res.get("dao.burningman.balanceEntry.type." + type.name()))
.sorted()
.collect(Collectors.toList())));
} else {
typeAsString = type.map(type -> Res.get("dao.burningman.balanceEntry.type." + type.name())).orElse("");
}
return typeAsString;
}

// Dummy for CSV export
@SuppressWarnings("OptionalAssignedToNull")
BalanceEntryItem() {
balanceEntry = null;
bsqFormatter = null;
btcFormatter = null;

date = null;
type = null;
price = null;
month = null;
receivedBtc = null;
receivedBtcAsBsq = null;
burnedBsq = null;
revenue = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.desktop.main.dao.burnbsq.burningmen;
package bisq.desktop.main.dao.burnbsq.burningman;

import bisq.desktop.util.DisplayUtils;

Expand Down
Loading

0 comments on commit def6083

Please sign in to comment.