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

Add a 'payment method details' screen #5052

Merged
merged 2 commits into from Jan 4, 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
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 @@ -292,7 +292,8 @@ mainView.version.update=(Update available)
####################################################################

market.tabs.offerBook=Offer book
market.tabs.spread=Details
market.tabs.spreadCurrency=Offers by Currency
market.tabs.spreadPayment=Offers by Payment Method
market.tabs.trades=Trades

# OfferBookChartView
Expand All @@ -311,6 +312,7 @@ market.spread.numberOfBuyOffersColumn=Buy BTC ({0})
market.spread.numberOfSellOffersColumn=Sell BTC ({0})
market.spread.totalAmountColumn=Total BTC ({0})
market.spread.spreadColumn=Spread
market.spread.expanded=Expanded view

# TradesChartsView
market.trades.nrOfTrades=Trades: {0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"/>
</Tab>
<Tab fx:id="spreadTab" closable="false"/>
<Tab fx:id="spreadTabPaymentMethod" closable="false"/>
<Tab fx:id="tradesTab" closable="false">
<ScrollPane fitToWidth="true" hbarPolicy="NEVER"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
Expand Down
13 changes: 10 additions & 3 deletions desktop/src/main/java/bisq/desktop/main/market/MarketView.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import bisq.desktop.main.MainView;
import bisq.desktop.main.market.offerbook.OfferBookChartView;
import bisq.desktop.main.market.spread.SpreadView;
import bisq.desktop.main.market.spread.SpreadViewPaymentMethod;
import bisq.desktop.main.market.trades.TradesChartsView;
import bisq.desktop.main.offer.offerbook.OfferBook;
import bisq.desktop.main.offer.offerbook.OfferBookListItem;
Expand Down Expand Up @@ -69,7 +70,7 @@
@FxmlView
public class MarketView extends ActivatableView<TabPane, Void> {
@FXML
Tab offerBookTab, tradesTab, spreadTab;
Tab offerBookTab, tradesTab, spreadTab, spreadTabPaymentMethod;
private final ViewLoader viewLoader;
private final P2PService p2PService;
private final OfferBook offerBook;
Expand Down Expand Up @@ -97,7 +98,8 @@ public MarketView(CachingViewLoader viewLoader,
@Override
public void initialize() {
offerBookTab.setText(Res.get("market.tabs.offerBook").toUpperCase());
spreadTab.setText(Res.get("market.tabs.spread").toUpperCase());
spreadTab.setText(Res.get("market.tabs.spreadCurrency").toUpperCase());
spreadTabPaymentMethod.setText(Res.get("market.tabs.spreadPayment").toUpperCase());
tradesTab.setText(Res.get("market.tabs.trades").toUpperCase());

navigationListener = viewPath -> {
Expand All @@ -112,6 +114,8 @@ else if (newValue == tradesTab)
navigation.navigateTo(MainView.class, MarketView.class, TradesChartsView.class);
else if (newValue == spreadTab)
navigation.navigateTo(MainView.class, MarketView.class, SpreadView.class);
else if (newValue == spreadTabPaymentMethod)
navigation.navigateTo(MainView.class, MarketView.class, SpreadViewPaymentMethod.class);
};

keyEventEventHandler = keyEvent -> {
Expand Down Expand Up @@ -140,8 +144,10 @@ protected void activate() {
navigation.navigateTo(MainView.class, MarketView.class, OfferBookChartView.class);
else if (root.getSelectionModel().getSelectedItem() == tradesTab)
navigation.navigateTo(MainView.class, MarketView.class, TradesChartsView.class);
else
else if (root.getSelectionModel().getSelectedItem() == spreadTab)
navigation.navigateTo(MainView.class, MarketView.class, SpreadView.class);
else
navigation.navigateTo(MainView.class, MarketView.class, SpreadViewPaymentMethod.class);

if (root.getScene() != null) {
scene = root.getScene();
Expand All @@ -165,6 +171,7 @@ private void loadView(Class<? extends View> viewClass) {

if (view instanceof OfferBookChartView) tab = offerBookTab;
else if (view instanceof TradesChartsView) tab = tradesTab;
else if (view instanceof SpreadViewPaymentMethod) tab = spreadTabPaymentMethod;
else if (view instanceof SpreadView) tab = spreadTab;
else throw new IllegalArgumentException("Navigation to " + viewClass + " is not supported");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public void initialize() {
tableView.getColumns().add(spreadColumn);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

currencyColumn.setComparator(Comparator.comparing(o -> CurrencyUtil.getNameByCode(o.currencyCode)));
currencyColumn.setComparator(Comparator.comparing(o ->
model.isIncludePaymentMethod() ? o.currencyCode : CurrencyUtil.getNameByCode(o.currencyCode)));
numberOfOffersColumn.setComparator(Comparator.comparingInt(o3 -> o3.numberOfOffers));
numberOfBuyOffersColumn.setComparator(Comparator.comparingInt(o3 -> o3.numberOfBuyOffers));
numberOfSellOffersColumn.setComparator(Comparator.comparingInt(o2 -> o2.numberOfSellOffers));
Expand Down Expand Up @@ -139,7 +140,7 @@ private void updateHeaders() {
///////////////////////////////////////////////////////////////////////////////////////////

private TableColumn<SpreadItem, SpreadItem> getCurrencyColumn() {
TableColumn<SpreadItem, SpreadItem> column = new AutoTooltipTableColumn<>(Res.get("shared.currency")) {
TableColumn<SpreadItem, SpreadItem> column = new AutoTooltipTableColumn<>(model.getKeyColumnName()) {
{
setMinWidth(160);
}
Expand All @@ -156,7 +157,10 @@ public TableCell<SpreadItem, SpreadItem> call(
public void updateItem(final SpreadItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty)
setText(CurrencyUtil.getNameAndCode(item.currencyCode));
if (model.isIncludePaymentMethod())
setText(item.currencyCode);
else
setText(CurrencyUtil.getNameAndCode(item.currencyCode));
else
setText("");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.util.GUIUtil;

import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.Res;
import bisq.core.monetary.Altcoin;
import bisq.core.monetary.Price;
import bisq.core.offer.Offer;
Expand Down Expand Up @@ -60,6 +60,9 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.Setter;

class SpreadViewModel extends ActivatableViewModel {

private final OfferBook offerBook;
Expand All @@ -69,7 +72,11 @@ class SpreadViewModel extends ActivatableViewModel {
private final ListChangeListener<OfferBookListItem> listChangeListener;
final ObservableList<SpreadItem> spreadItems = FXCollections.observableArrayList();
final IntegerProperty maxPlacesForAmount = new SimpleIntegerProperty();

@Setter
@Getter
private boolean includePaymentMethod;
@Getter
private boolean expandedView;

///////////////////////////////////////////////////////////////////////////////////////////
// Constructor, lifecycle
Expand All @@ -80,11 +87,20 @@ public SpreadViewModel(OfferBook offerBook, PriceFeedService priceFeedService, @
this.offerBook = offerBook;
this.priceFeedService = priceFeedService;
this.formatter = formatter;

includePaymentMethod = false;
offerBookListItems = offerBook.getOfferBookListItems();
listChangeListener = c -> update(offerBookListItems);
}

public String getKeyColumnName() {
return includePaymentMethod ? Res.get("shared.paymentMethod") : Res.get("shared.currency");
}

public void setExpandedView(boolean expandedView) {
this.expandedView = expandedView;
update(offerBookListItems);
}

@Override
protected void activate() {
offerBookListItems.addListener(listChangeListener);
Expand All @@ -106,18 +122,24 @@ private void update(ObservableList<OfferBookListItem> offerBookListItems) {
Map<String, List<Offer>> offersByCurrencyMap = new HashMap<>();
for (OfferBookListItem offerBookListItem : offerBookListItems) {
Offer offer = offerBookListItem.getOffer();
String currencyCode = offer.getCurrencyCode();
if (!offersByCurrencyMap.containsKey(currencyCode))
offersByCurrencyMap.put(currencyCode, new ArrayList<>());
offersByCurrencyMap.get(currencyCode).add(offer);
String key = offer.getCurrencyCode();
if (includePaymentMethod) {
key = offer.getPaymentMethod().getShortName();
if (expandedView) {
key += ":" + offer.getCurrencyCode();
}
}
if (!offersByCurrencyMap.containsKey(key))
offersByCurrencyMap.put(key, new ArrayList<>());
offersByCurrencyMap.get(key).add(offer);
}
spreadItems.clear();

Coin totalAmount = null;

for (String currencyCode : offersByCurrencyMap.keySet()) {
List<Offer> offers = offersByCurrencyMap.get(currencyCode);
final boolean isFiatCurrency = CurrencyUtil.isFiatCurrency(currencyCode);
for (String key : offersByCurrencyMap.keySet()) {
List<Offer> offers = offersByCurrencyMap.get(key);
final boolean isFiatCurrency = (offers.size() > 0 && !offers.get(0).getPaymentMethod().isAsset());

List<Offer> uniqueOffers = offers.stream().filter(distinctByKey(Offer::getId)).collect(Collectors.toList());

Expand Down Expand Up @@ -160,8 +182,9 @@ private void update(ObservableList<OfferBookListItem> offerBookListItems) {
double percentageValue = 0;
Price bestSellOfferPrice = sellOffers.isEmpty() ? null : sellOffers.get(0).getPrice();
Price bestBuyOfferPrice = buyOffers.isEmpty() ? null : buyOffers.get(0).getPrice();
if (bestBuyOfferPrice != null && bestSellOfferPrice != null) {
MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode);
if (bestBuyOfferPrice != null && bestSellOfferPrice != null &&
sellOffers.get(0).getCurrencyCode().equals(buyOffers.get(0).getCurrencyCode())) {
MarketPrice marketPrice = priceFeedService.getMarketPrice(sellOffers.get(0).getCurrencyCode());

// There have been some bug reports that an offer caused an overflow exception.
// We never found out which offer it was. So add here a try/catch to get better info if it
Expand Down Expand Up @@ -213,7 +236,7 @@ private void update(ObservableList<OfferBookListItem> offerBookListItems) {
}

totalAmount = Coin.valueOf(offers.stream().mapToLong(offer -> offer.getAmount().getValue()).sum());
spreadItems.add(new SpreadItem(currencyCode, buyOffers.size(), sellOffers.size(),
spreadItems.add(new SpreadItem(key, buyOffers.size(), sellOffers.size(),
uniqueOffers.size(), spread, percentage, percentageValue, totalAmount));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ 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/>.
-->

<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.geometry.Insets?>
<GridPane fx:id="root" fx:controller="bisq.desktop.main.market.spread.SpreadViewPaymentMethod"
hgap="5.0" vgap="5.0"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"
xmlns:fx="http://javafx.com/fxml">
<padding>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0"/>
</padding>

</GridPane>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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.market.spread;

import bisq.desktop.common.view.FxmlView;

import bisq.core.locale.Res;
import bisq.core.util.FormattingUtils;
import bisq.core.util.coin.CoinFormatter;

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

import javafx.scene.control.ToggleButton;

import static bisq.desktop.util.FormBuilder.addSlideToggleButton;

@FxmlView
public class SpreadViewPaymentMethod extends SpreadView {
private ToggleButton expandedMode;

///////////////////////////////////////////////////////////////////////////////////////////
// Constructor, lifecycle
///////////////////////////////////////////////////////////////////////////////////////////

@Inject
public SpreadViewPaymentMethod(SpreadViewModel model, @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter) {
super(model, formatter);
model.setIncludePaymentMethod(true);
}

@Override
public void initialize() {
super.initialize();
int gridRow = 0;
expandedMode = addSlideToggleButton(root, ++gridRow, Res.get("market.spread.expanded"));
}

@Override
protected void activate() {
super.activate();
expandedMode.setSelected(model.isExpandedView());
expandedMode.setOnAction(e -> model.setExpandedView(expandedMode.isSelected()));
}

@Override
protected void deactivate() {
expandedMode.setOnAction(null);
super.deactivate();
}
}