Skip to content

Commit

Permalink
Merge pull request #4933 from chimp1984/add-num-items-to-tables
Browse files Browse the repository at this point in the history
Improve funds and portfolio screens
  • Loading branch information
ripcurlx authored Dec 14, 2020
2 parents 6ae33fe + e848e8b commit 7d12b94
Show file tree
Hide file tree
Showing 22 changed files with 767 additions and 168 deletions.
14 changes: 9 additions & 5 deletions core/src/main/java/bisq/core/offer/OfferUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,15 @@ private Optional<Volume> getFeeInUserFiatCurrency(Coin makerFee,
tradeStatisticsManager,
30);
Price bsqPrice = tuple.second;
String inputValue = bsqFormatter.formatCoin(makerFee);
Volume makerFeeAsVolume = Volume.parse(inputValue, "BSQ");
Coin requiredBtc = bsqPrice.getAmountByVolume(makerFeeAsVolume);
Volume volumeByAmount = userCurrencyPrice.getVolumeByAmount(requiredBtc);
return Optional.of(volumeByAmount);
if (bsqPrice.isPositive()) {
String inputValue = bsqFormatter.formatCoin(makerFee);
Volume makerFeeAsVolume = Volume.parse(inputValue, "BSQ");
Coin requiredBtc = bsqPrice.getAmountByVolume(makerFeeAsVolume);
Volume volumeByAmount = userCurrencyPrice.getVolumeByAmount(requiredBtc);
return Optional.of(volumeByAmount);
} else {
return Optional.empty();
}
}
} else {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ public int compareTo(@NotNull PaymentMethod other) {
return id.compareTo(other.id);
}

public String getDisplayString() {
return Res.get(id);
}

public boolean isAsset() {
return this.equals(BLOCK_CHAINS_INSTANT) || this.equals(BLOCK_CHAINS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public TradePresentation(TradeManager tradeManager) {
long numPendingTrades = (long) newValue;
if (numPendingTrades > 0)
this.numPendingTrades.set(String.valueOf(numPendingTrades));
if (numPendingTrades > 9)
this.numPendingTrades.set("★");

showPendingTradesNotification.set(numPendingTrades > 0);
});
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ shared.refundAgentForSupportStaff=Refund agent
shared.delayedPayoutTxId=Delayed payout transaction ID
shared.delayedPayoutTxReceiverAddress=Delayed payout transaction sent to
shared.unconfirmedTransactionsLimitReached=You have too many unconfirmed transactions at the moment. Please try again later.
shared.numItemsLabel=Number of entries: {0}
shared.filter=Filter
shared.enabled=Enabled


####################################################################
Expand Down Expand Up @@ -1053,7 +1056,6 @@ funds.tx.dustAttackTx.popup=This transaction is sending a very small BTC amount
To protect your privacy the Bisq wallet ignores such dust outputs for spending purposes and in the balance display. \
You can set the threshold amount when an output is considered dust in the settings.


####################################################################
# Support
####################################################################
Expand Down
12 changes: 9 additions & 3 deletions desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,16 @@ protected void updatePeerInfoIcon() {
if (!tag.isEmpty())
tagLabel.setText(tag.substring(0, 1));

if (numTrades < 10)
if (numTrades > 0) {
numTradesLabel.setText(String.valueOf(numTrades));
else
numTradesLabel.setText("★");

double scaleFactor = getScaleFactor();
if (numTrades > 9) {
numTradesLabel.relocate(scaleFactor * 2, scaleFactor * 1);
} else {
numTradesLabel.relocate(scaleFactor * 5, scaleFactor * 1);
}
}

numTradesPane.setVisible(numTrades > 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
package bisq.desktop.main.funds.locked;

import bisq.desktop.components.AutoTooltipLabel;
import bisq.desktop.util.DisplayUtils;

import bisq.core.btc.listeners.BalanceListener;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.WalletService;
import bisq.core.trade.Tradable;
import bisq.core.locale.Res;
import bisq.core.trade.Trade;
import bisq.core.util.coin.CoinFormatter;

Expand All @@ -33,37 +34,48 @@

import javafx.scene.control.Label;

import lombok.Getter;

import javax.annotation.Nullable;

class LockedListItem {
private final BalanceListener balanceListener;
private final BtcWalletService btcWalletService;
private final CoinFormatter formatter;

@Getter
private final Label balanceLabel;
@Getter
private final Trade trade;
@Getter
private final AddressEntry addressEntry;
private final BtcWalletService btcWalletService;
private final CoinFormatter formatter;
@Getter
private final String addressString;
@Nullable
private final Address address;
@Getter
private Coin balance;
@Getter
private String balanceString;

public LockedListItem(Trade trade, AddressEntry addressEntry, BtcWalletService btcWalletService, CoinFormatter formatter) {
public LockedListItem(Trade trade,
AddressEntry addressEntry,
BtcWalletService btcWalletService,
CoinFormatter formatter) {
this.trade = trade;
this.addressEntry = addressEntry;
this.btcWalletService = btcWalletService;
this.formatter = formatter;

if (trade.getDepositTx() != null && !trade.getDepositTx().getOutputs().isEmpty()) {
address = WalletService.getAddressFromOutput(trade.getDepositTx().getOutput(0));
addressString = address.toString();
addressString = address != null ? address.toString() : "";
} else {
address = null;
addressString = "";
}

// balance
balanceLabel = new AutoTooltipLabel();
balanceListener = new BalanceListener(getAddress()) {
balanceListener = new BalanceListener(address) {
@Override
public void onBalanceChanged(Coin balance, Transaction tx) {
updateBalance();
Expand All @@ -73,38 +85,36 @@ public void onBalanceChanged(Coin balance, Transaction tx) {
updateBalance();
}

LockedListItem() {
this.trade = null;
this.addressEntry = null;
this.btcWalletService = null;
this.formatter = null;
addressString = null;
address = null;
balanceLabel = null;
balanceListener = null;
}

public void cleanup() {
btcWalletService.removeBalanceListener(balanceListener);
}

private void updateBalance() {
balance = addressEntry.getCoinLockedInMultiSigAsCoin();
balanceLabel.setText(formatter.formatCoin(this.balance));
balanceString = formatter.formatCoin(this.balance);
balanceLabel.setText(balanceString);
}

@Nullable
private Address getAddress() {
return address;
public String getDetails() {
return trade != null ?
Res.get("funds.locked.locked", trade.getShortId()) :
Res.get("shared.noDetailsAvailable");
}

public AddressEntry getAddressEntry() {
return addressEntry;
public String getDateString() {
return trade != null ?
DisplayUtils.formatDateTime(trade.getDate()) :
Res.get("shared.noDateAvailable");
}

public Label getBalanceLabel() {
return balanceLabel;
}

public Coin getBalance() {
return balance;
}

public String getAddressString() {
return addressString;
}

public Tradable getTrade() {
return trade;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
~ along with Bisq. If not, see <http://www.gnu.org/licenses/>.
-->

<?import bisq.desktop.components.AutoTooltipButton?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.VBox?>
<?import javafx.geometry.Insets?>
<VBox fx:id="root" fx:controller="bisq.desktop.main.funds.locked.LockedView"
Expand All @@ -35,5 +39,9 @@
<TableColumn fx:id="balanceColumn" minWidth="110"/>
</columns>
</TableView>

<HBox spacing="10">
<Label fx:id="numItems"/>
<Region fx:id="spacer"/>
<AutoTooltipButton fx:id="exportButton"/>
</HBox>
</VBox>
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

import bisq.desktop.common.view.ActivatableView;
import bisq.desktop.common.view.FxmlView;
import bisq.desktop.components.AutoTooltipButton;
import bisq.desktop.components.AutoTooltipLabel;
import bisq.desktop.components.ExternalHyperlink;
import bisq.desktop.components.HyperlinkWithIcon;
import bisq.desktop.main.overlays.windows.OfferDetailsWindow;
import bisq.desktop.main.overlays.windows.TradeDetailsWindow;
import bisq.desktop.util.DisplayUtils;
import bisq.desktop.util.GUIUtil;

import bisq.core.btc.listeners.BalanceListener;
Expand All @@ -43,19 +43,29 @@
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;

import com.googlecode.jcsv.writer.CSVEntryConverter;

import javax.inject.Inject;
import javax.inject.Named;

import de.jensd.fx.fontawesome.AwesomeIcon;

import javafx.fxml.FXML;

import javafx.stage.Stage;

import javafx.scene.control.Label;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;

import javafx.geometry.Insets;

import javafx.beans.property.ReadOnlyObjectWrapper;

import javafx.collections.FXCollections;
Expand All @@ -77,6 +87,12 @@ public class LockedView extends ActivatableView<VBox, Void> {
TableView<LockedListItem> tableView;
@FXML
TableColumn<LockedListItem, LockedListItem> dateColumn, detailsColumn, addressColumn, balanceColumn;
@FXML
Label numItems;
@FXML
Region spacer;
@FXML
AutoTooltipButton exportButton;

private final BtcWalletService btcWalletService;
private final TradeManager tradeManager;
Expand All @@ -97,8 +113,13 @@ public class LockedView extends ActivatableView<VBox, Void> {
///////////////////////////////////////////////////////////////////////////////////////////

@Inject
private LockedView(BtcWalletService btcWalletService, TradeManager tradeManager, OpenOfferManager openOfferManager, Preferences preferences,
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter, OfferDetailsWindow offerDetailsWindow, TradeDetailsWindow tradeDetailsWindow) {
private LockedView(BtcWalletService btcWalletService,
TradeManager tradeManager,
OpenOfferManager openOfferManager,
Preferences preferences,
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter,
OfferDetailsWindow offerDetailsWindow,
TradeDetailsWindow tradeDetailsWindow) {
this.btcWalletService = btcWalletService;
this.tradeManager = tradeManager;
this.openOfferManager = openOfferManager;
Expand Down Expand Up @@ -138,6 +159,10 @@ public void onBalanceChanged(Coin balance, Transaction tx) {
};
openOfferListChangeListener = c -> updateList();
tradeListChangeListener = c -> updateList();

HBox.setHgrow(spacer, Priority.ALWAYS);
numItems.setPadding(new Insets(-5, 0, 0, 10));
exportButton.updateText(Res.get("shared.exportCSV"));
}

@Override
Expand All @@ -149,6 +174,33 @@ protected void activate() {
updateList();

btcWalletService.addBalanceListener(balanceListener);

numItems.setText(Res.get("shared.numItemsLabel", sortedList.size()));
exportButton.setOnAction(event -> {
ObservableList<TableColumn<LockedListItem, ?>> tableColumns = tableView.getColumns();
int reportColumns = tableColumns.size();
CSVEntryConverter<LockedListItem> headerConverter = transactionsListItem -> {
String[] columns = new String[reportColumns];
for (int i = 0; i < columns.length; i++)
columns[i] = ((AutoTooltipLabel) tableColumns.get(i).getGraphic()).getText();
return columns;
};
CSVEntryConverter<LockedListItem> contentConverter = item -> {
String[] columns = new String[reportColumns];
columns[0] = item.getDateString();
columns[1] = item.getDetails();
columns[2] = item.getAddressString();
columns[3] = item.getBalanceString();
return columns;
};

GUIUtil.exportCSV("lockedInTradesFunds.csv",
headerConverter,
contentConverter,
new LockedListItem(),
sortedList,
(Stage) root.getScene().getWindow());
});
}

@Override
Expand All @@ -158,6 +210,7 @@ protected void deactivate() {
sortedList.comparatorProperty().unbind();
observableList.forEach(LockedListItem::cleanup);
btcWalletService.removeBalanceListener(balanceListener);
exportButton.setOnAction(null);
}


Expand All @@ -169,7 +222,8 @@ private void updateList() {
observableList.forEach(LockedListItem::cleanup);
observableList.setAll(tradeManager.getTradesStreamWithFundsLockedIn()
.map(trade -> {
final Optional<AddressEntry> addressEntryOptional = btcWalletService.getAddressEntry(trade.getId(), AddressEntry.Context.MULTI_SIG);
Optional<AddressEntry> addressEntryOptional = btcWalletService.getAddressEntry(trade.getId(),
AddressEntry.Context.MULTI_SIG);
return addressEntryOptional.map(addressEntry -> new LockedListItem(trade,
addressEntry,
btcWalletService,
Expand Down Expand Up @@ -227,9 +281,9 @@ public void updateItem(final LockedListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
if (getTradable(item).isPresent())
setGraphic(new AutoTooltipLabel(DisplayUtils.formatDateTime(getTradable(item).get().getDate())));
setGraphic(new AutoTooltipLabel(item.getDateString()));
else
setGraphic(new AutoTooltipLabel(Res.get("shared.noDateAvailable")));
setGraphic(new AutoTooltipLabel(item.getDateString()));
} else {
setGraphic(null);
}
Expand Down Expand Up @@ -257,13 +311,13 @@ public void updateItem(final LockedListItem item, boolean empty) {
if (item != null && !empty) {
Optional<Tradable> tradableOptional = getTradable(item);
if (tradableOptional.isPresent()) {
field = new HyperlinkWithIcon(Res.get("funds.locked.locked", item.getTrade().getShortId()),
field = new HyperlinkWithIcon(item.getDetails(),
AwesomeIcon.INFO_SIGN);
field.setOnAction(event -> openDetailPopup(item));
field.setTooltip(new Tooltip(Res.get("tooltip.openPopupForDetails")));
setGraphic(field);
} else {
setGraphic(new AutoTooltipLabel(Res.get("shared.noDetailsAvailable")));
setGraphic(new AutoTooltipLabel(item.getDetails()));
}

} else {
Expand Down
Loading

0 comments on commit 7d12b94

Please sign in to comment.