Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve portfolio history #5315

Merged
merged 5 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions core/src/main/java/bisq/core/util/VolumeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@

package bisq.core.util;

import bisq.core.monetary.Altcoin;
import bisq.core.monetary.AltcoinExchangeRate;
import bisq.core.monetary.Price;
import bisq.core.monetary.Volume;

import org.bitcoinj.core.Coin;
import org.bitcoinj.utils.ExchangeRate;
import org.bitcoinj.utils.Fiat;

public class VolumeUtil {

public static Volume getRoundedFiatVolume(Volume volumeByAmount) {
Expand Down Expand Up @@ -47,4 +54,12 @@ public static Volume getAdjustedFiatVolume(Volume volumeByAmount, int factor) {
roundedVolume = Math.max(factor, roundedVolume);
return Volume.parse(String.valueOf(roundedVolume), volumeByAmount.getCurrencyCode());
}

public static Volume getVolume(Coin amount, Price price) {
if (price.getMonetary() instanceof Altcoin) {
return new Volume(new AltcoinExchangeRate((Altcoin) price.getMonetary()).coinToAltcoin(amount));
} else {
return new Volume(new ExchangeRate((Fiat) price.getMonetary()).coinToFiat(amount));
}
}
}
13 changes: 8 additions & 5 deletions core/src/main/java/bisq/core/util/coin/BsqFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import org.jetbrains.annotations.NotNull;

@Slf4j
@Singleton
public class BsqFormatter implements CoinFormatter {
Expand Down Expand Up @@ -224,10 +222,15 @@ public String parseParamValueToString(Param param, String inputValue) throws Pro
}

public String formatCoin(Coin coin) {
return immutableCoinFormatter.formatCoin(coin);
return formatCoin(coin, false);
}

public String formatCoin(Coin coin, boolean appendCode) {
return appendCode ?
immutableCoinFormatter.formatCoinWithCode(coin) :
immutableCoinFormatter.formatCoin(coin);
}

@NotNull
public String formatCoin(Coin coin, int decimalPlaces) {
return immutableCoinFormatter.formatCoin(coin, decimalPlaces);
}
Expand All @@ -240,7 +243,7 @@ public String formatCoin(Coin coin,
}

public String formatCoinWithCode(Coin coin) {
return immutableCoinFormatter.formatCoinWithCode(coin);
return formatCoin(coin, true);
}

public String formatCoinWithCode(long value) {
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/bisq/core/util/coin/CoinFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import org.bitcoinj.core.Coin;

import org.jetbrains.annotations.NotNull;

public interface CoinFormatter {
String formatCoin(Coin coin);

@NotNull
String formatCoin(Coin coin, boolean appendCode);

String formatCoin(Coin coin, int decimalPlaces);

String formatCoin(Coin coin, int decimalPlaces, boolean decimalAligned, int maxNumberOfDigits);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import org.jetbrains.annotations.NotNull;

@Slf4j
public class ImmutableCoinFormatter implements CoinFormatter {

Expand Down Expand Up @@ -56,7 +54,11 @@ public String formatCoin(Coin coin) {
}

@Override
@NotNull
public String formatCoin(Coin coin, boolean appendCode) {
return appendCode ? formatCoinWithCode(coin) : formatCoin(coin);
}

@Override
public String formatCoin(Coin coin, int decimalPlaces) {
return formatCoin(coin, decimalPlaces, false, 0);
}
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ shared.sendingConfirmation=Sending confirmation...
shared.sendingConfirmationAgain=Please send confirmation again
shared.exportCSV=Export to CSV
shared.exportJSON=Export to JSON
shared.summary=Show summary
shared.noDateAvailable=No date available
shared.noDetailsAvailable=No details available
shared.notUsedYet=Not used yet
Expand Down Expand Up @@ -2722,6 +2723,17 @@ txDetailsWindow.bsq.note=You have sent BSQ funds. \
txDetailsWindow.sentTo=Sent to
txDetailsWindow.txId=TxId

closedTradesSummaryWindow.headline=Trade history summary
closedTradesSummaryWindow.totalAmount.title=Total trade amount
closedTradesSummaryWindow.totalAmount.value={0} ({1} with current market price)
closedTradesSummaryWindow.totalVolume.title=Total amount traded in {0}
closedTradesSummaryWindow.totalMinerFee.title=Sum of all miner fees
closedTradesSummaryWindow.totalMinerFee.value={0} ({1} of total trade amount)
closedTradesSummaryWindow.totalTradeFeeInBtc.title=Sum of all trade fees paid in BTC
closedTradesSummaryWindow.totalTradeFeeInBtc.value={0} ({1} of total trade amount)
closedTradesSummaryWindow.totalTradeFeeInBsq.title=Sum of all trade fees paid in BSQ
closedTradesSummaryWindow.totalTradeFeeInBsq.value={0} ({1} of total trade amount)

walletPasswordWindow.headline=Enter password to unlock

torNetworkSettingWindow.header=Tor networks settings
Expand Down
11 changes: 11 additions & 0 deletions desktop/src/main/java/bisq/desktop/main/PriceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ public static InputValidator.ValidationResult isTriggerPriceValid(String trigger
}
}

public static Price marketPriceToPrice(MarketPrice marketPrice) {
String currencyCode = marketPrice.getCurrencyCode();
double priceAsDouble = marketPrice.getPrice();
int precision = CurrencyUtil.isCryptoCurrency(currencyCode) ?
Altcoin.SMALLEST_UNIT_EXPONENT :
Fiat.SMALLEST_UNIT_EXPONENT;
double scaled = MathUtils.scaleUpByPowerOf10(priceAsDouble, precision);
long roundedToLong = MathUtils.roundDoubleToLong(scaled);
return Price.valueOf(currencyCode, roundedToLong);
}

public void recalculateBsq30DayAveragePrice() {
bsq30DayAveragePrice = null;
bsq30DayAveragePrice = getBsq30DayAveragePrice();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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.overlays.windows;

import bisq.desktop.main.overlays.Overlay;
import bisq.desktop.main.portfolio.closedtrades.ClosedTradesViewModel;
import bisq.desktop.util.Layout;

import bisq.core.locale.Res;

import org.bitcoinj.core.Coin;

import javax.inject.Inject;

import javafx.geometry.Insets;

import java.util.Map;

import static bisq.desktop.util.FormBuilder.addConfirmationLabelLabel;
import static bisq.desktop.util.FormBuilder.addTitledGroupBg;

public class ClosedTradesSummaryWindow extends Overlay<ClosedTradesSummaryWindow> {
private final ClosedTradesViewModel model;

@Inject
public ClosedTradesSummaryWindow(ClosedTradesViewModel model) {
this.model = model;
type = Type.Information;
}

public void show() {
rowIndex = 0;
width = 900;
createGridPane();
addContent();
addButtons();
display();
}


///////////////////////////////////////////////////////////////////////////////////////////
// Protected
///////////////////////////////////////////////////////////////////////////////////////////

@Override
protected void createGridPane() {
super.createGridPane();
gridPane.setPadding(new Insets(35, 40, 30, 40));
gridPane.getStyleClass().add("grid-pane");
}

private void addContent() {
Map<String, String> totalVolumeByCurrency = model.getTotalVolumeByCurrency();
int rowSpan = totalVolumeByCurrency.size() + 4;
addTitledGroupBg(gridPane, rowIndex, rowSpan, Res.get("closedTradesSummaryWindow.headline"));
Coin totalTradeAmount = model.getTotalTradeAmount();
addConfirmationLabelLabel(gridPane, rowIndex,
Res.get("closedTradesSummaryWindow.totalAmount.title"),
model.getTotalAmountWithVolume(totalTradeAmount), Layout.TWICE_FIRST_ROW_DISTANCE);
totalVolumeByCurrency.entrySet().forEach(entry -> {
addConfirmationLabelLabel(gridPane, ++rowIndex,
Res.get("closedTradesSummaryWindow.totalVolume.title", entry.getKey()), entry.getValue());
});
addConfirmationLabelLabel(gridPane, ++rowIndex,
Res.get("closedTradesSummaryWindow.totalMinerFee.title"),
model.getTotalTxFee(totalTradeAmount));
addConfirmationLabelLabel(gridPane, ++rowIndex,
Res.get("closedTradesSummaryWindow.totalTradeFeeInBtc.title"),
model.getTotalTradeFeeInBtc(totalTradeAmount));
addConfirmationLabelLabel(gridPane, ++rowIndex,
Res.get("closedTradesSummaryWindow.totalTradeFeeInBsq.title") + " ", // lets give some extra space
model.getTotalTradeFeeInBsq(totalTradeAmount));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private void addContent() {

String txFee = Res.get("shared.makerTxFee", formatter.formatCoinWithCode(offer.getTxFee())) +
" / " +
Res.get("shared.takerTxFee", formatter.formatCoinWithCode(offer.getTxFee().multiply(3L)));
Res.get("shared.takerTxFee", formatter.formatCoinWithCode(trade.getTxFee().multiply(3)));
addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("tradeDetailsWindow.txFee"), txFee);

NodeAddress arbitratorNodeAddress = trade.getArbitratorNodeAddress();
Expand Down
Loading