Search in sources :

Example 1 with Tuple4

use of bisq.common.util.Tuple4 in project bisq-desktop by bisq-network.

the class TransactionsView method showStatisticsPopup.

// This method is not intended for the public so we don't translate here
private void showStatisticsPopup() {
    Map<Long, List<Coin>> map = new HashMap<>();
    Map<String, Tuple4<Date, Integer, Integer, Integer>> dataByDayMap = new HashMap<>();
    displayedTransactions.forEach(item -> {
        Coin amountAsCoin = item.getAmountAsCoin();
        List<Coin> amounts;
        long key = amountAsCoin.getValue();
        if (!map.containsKey(key)) {
            amounts = new ArrayList<>();
            map.put(key, amounts);
        } else {
            amounts = map.get(key);
        }
        amounts.add(amountAsCoin);
        DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.US);
        String day = dateFormatter.format(item.getDate());
        // TODO fee is dynamic now
        Coin txFee = Coin.valueOf(20_000);
        Coin createOfferFee = Coin.valueOf(50_000);
        Coin takeOfferFee = Coin.valueOf(100_000);
        if (!dataByDayMap.containsKey(day)) {
            int numOffers = 0;
            int numTrades = 0;
            if (amountAsCoin.compareTo(createOfferFee.subtract(txFee)) == 0)
                numOffers++;
            else if (amountAsCoin.compareTo(takeOfferFee.subtract(txFee)) == 0)
                numTrades++;
            dataByDayMap.put(day, new Tuple4<>(item.getDate(), 1, numOffers, numTrades));
        } else {
            Tuple4<Date, Integer, Integer, Integer> tuple = dataByDayMap.get(day);
            int prev = tuple.second;
            int numOffers = tuple.third;
            int numTrades = tuple.forth;
            if (amountAsCoin.compareTo(createOfferFee.subtract(txFee)) == 0)
                numOffers++;
            else if (amountAsCoin.compareTo(takeOfferFee.subtract(txFee)) == 0)
                numTrades++;
            dataByDayMap.put(day, new Tuple4<>(tuple.first, ++prev, numOffers, numTrades));
        }
    });
    StringBuilder stringBuilder = new StringBuilder();
    map.forEach((key, value) -> {
        // This is not intended for the public so we don't translate here
        stringBuilder.append("No. of transactions for amount ").append(formatter.formatCoinWithCode(Coin.valueOf(key))).append(": ").append(value.size()).append("\n");
    });
    List<Tuple4<String, Date, Integer, Tuple2<Integer, Integer>>> sortedDataByDayList = dataByDayMap.entrySet().stream().map(e -> {
        Tuple4<Date, Integer, Integer, Integer> data = e.getValue();
        return new Tuple4<>(e.getKey(), data.first, data.second, new Tuple2<>(data.third, data.forth));
    }).sorted((o1, o2) -> o2.second.compareTo(o1.second)).collect(Collectors.toList());
    StringBuilder transactionsByDayStringBuilder = new StringBuilder();
    StringBuilder offersStringBuilder = new StringBuilder();
    StringBuilder tradesStringBuilder = new StringBuilder();
    StringBuilder allStringBuilder = new StringBuilder();
    // This is not intended for the public so we don't translate here
    allStringBuilder.append(Res.get("shared.date")).append(";").append("Offers").append(";").append("Trades").append("\n");
    sortedDataByDayList.forEach(tuple4 -> {
        offersStringBuilder.append(tuple4.forth.first).append(",");
        tradesStringBuilder.append(tuple4.forth.second).append(",");
        allStringBuilder.append(tuple4.first).append(";").append(tuple4.forth.first).append(";").append(tuple4.forth.second).append("\n");
        transactionsByDayStringBuilder.append("\n").append(tuple4.first).append(": ").append(tuple4.third).append(" (Offers: ").append(tuple4.forth.first).append(" / Trades: ").append(tuple4.forth.second).append(")");
    });
    // This is not intended for the public so we don't translate here
    String message = stringBuilder.toString() + "\nNo. of transactions by day:" + transactionsByDayStringBuilder.toString();
    new Popup<>().headLine("Statistical info").information(message).actionButtonText("Copy").onAction(() -> Utilities.copyToClipboard(message + "\n\nCSV (Offers):\n" + offersStringBuilder.toString() + "\n\nCSV (Trades):\n" + tradesStringBuilder.toString() + "\n\nCSV (all):\n" + allStringBuilder.toString())).show();
}
Also used : Button(javafx.scene.control.Button) EventHandler(javafx.event.EventHandler) Transaction(org.bitcoinj.core.Transaction) OpenOffer(bisq.core.offer.OpenOffer) Utilities(bisq.common.util.Utilities) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) Coin(org.bitcoinj.core.Coin) Date(java.util.Date) CSVEntryConverter(com.googlecode.jcsv.writer.CSVEntryConverter) VBox(javafx.scene.layout.VBox) BSFormatter(bisq.desktop.util.BSFormatter) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) Res(bisq.core.locale.Res) Locale(java.util.Locale) Map(java.util.Map) TableView(javafx.scene.control.TableView) DateFormat(java.text.DateFormat) SortedList(javafx.collections.transformation.SortedList) Popup(bisq.desktop.main.overlays.popups.Popup) P2PService(bisq.network.p2p.P2PService) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) KeyEvent(javafx.scene.input.KeyEvent) Collectors(java.util.stream.Collectors) ECKey(org.bitcoinj.core.ECKey) FXML(javafx.fxml.FXML) List(java.util.List) Script(org.bitcoinj.script.Script) WalletsSetup(bisq.core.btc.wallet.WalletsSetup) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) Preferences(bisq.core.user.Preferences) ObservableList(javafx.collections.ObservableList) AwesomeIcon(de.jensd.fx.fontawesome.AwesomeIcon) GUIUtil(bisq.desktop.util.GUIUtil) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) Scene(javafx.scene.Scene) WalletEventListener(org.bitcoinj.wallet.listeners.WalletEventListener) ActivatableView(bisq.desktop.common.view.ActivatableView) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) OfferDetailsWindow(bisq.desktop.main.overlays.windows.OfferDetailsWindow) Wallet(org.bitcoinj.wallet.Wallet) HashMap(java.util.HashMap) Tradable(bisq.core.trade.Tradable) FxmlView(bisq.desktop.common.view.FxmlView) TableColumn(javafx.scene.control.TableColumn) ArrayList(java.util.ArrayList) Tuple4(bisq.common.util.Tuple4) Inject(javax.inject.Inject) Tuple2(bisq.common.util.Tuple2) TableCell(javafx.scene.control.TableCell) AddressWithIconAndDirection(bisq.desktop.components.AddressWithIconAndDirection) Callback(javafx.util.Callback) Tooltip(javafx.scene.control.Tooltip) Nullable(javax.annotation.Nullable) KeyCode(javafx.scene.input.KeyCode) TradeDetailsWindow(bisq.desktop.main.overlays.windows.TradeDetailsWindow) Trade(bisq.core.trade.Trade) Stage(javafx.stage.Stage) Comparator(java.util.Comparator) HashMap(java.util.HashMap) Date(java.util.Date) Tuple4(bisq.common.util.Tuple4) Coin(org.bitcoinj.core.Coin) DateFormat(java.text.DateFormat) SortedList(javafx.collections.transformation.SortedList) List(java.util.List) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList)

Example 2 with Tuple4

use of bisq.common.util.Tuple4 in project bisq-desktop by bisq-network.

the class OfferBookChartView method getOfferTable.

private Tuple4<TableView<OfferListItem>, VBox, Button, Label> getOfferTable(OfferPayload.Direction direction) {
    TableView<OfferListItem> tableView = new TableView<>();
    tableView.setMinHeight(initialOfferTableViewHeight);
    tableView.setPrefHeight(121);
    tableView.setMinWidth(480);
    tableView.getStyleClass().add("offer-table");
    // price
    TableColumn<OfferListItem, OfferListItem> priceColumn = new TableColumn<>();
    priceColumn.textProperty().bind(priceColumnLabel);
    priceColumn.setMinWidth(115);
    priceColumn.setMaxWidth(115);
    priceColumn.setSortable(false);
    priceColumn.getStyleClass().add("number-column");
    priceColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    priceColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {

        @Override
        public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
            return new TableCell<OfferListItem, OfferListItem>() {

                private Offer offer;

                final ChangeListener<Number> listener = new ChangeListener<Number>() {

                    @Override
                    public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                        if (offer != null && offer.getPrice() != null) {
                            setText("");
                            setGraphic(new ColoredDecimalPlacesWithZerosText(model.getPrice(offer), model.getZeroDecimalsForPrice(offer)));
                            model.priceFeedService.updateCounterProperty().removeListener(listener);
                        }
                    }
                };

                @Override
                public void updateItem(final OfferListItem offerListItem, boolean empty) {
                    super.updateItem(offerListItem, empty);
                    if (offerListItem != null && !empty) {
                        final Offer offer = offerListItem.offer;
                        if (offer.getPrice() == null) {
                            this.offer = offer;
                            model.priceFeedService.updateCounterProperty().addListener(listener);
                            setText(Res.get("shared.na"));
                        } else {
                            setGraphic(new ColoredDecimalPlacesWithZerosText(model.getPrice(offer), model.getZeroDecimalsForPrice(offer)));
                        }
                    } else {
                        if (listener != null)
                            model.priceFeedService.updateCounterProperty().removeListener(listener);
                        this.offer = null;
                        setText("");
                        setGraphic(null);
                    }
                }
            };
        }
    });
    // volume
    TableColumn<OfferListItem, OfferListItem> volumeColumn = new TableColumn<>();
    volumeColumn.setMinWidth(115);
    volumeColumn.setSortable(false);
    volumeColumn.textProperty().bind(volumeColumnLabel);
    volumeColumn.getStyleClass().add("number-column");
    volumeColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    volumeColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {

        @Override
        public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
            return new TableCell<OfferListItem, OfferListItem>() {

                private Offer offer;

                final ChangeListener<Number> listener = new ChangeListener<Number>() {

                    @Override
                    public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                        if (offer != null && offer.getPrice() != null) {
                            setText("");
                            setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(offer), model.getMaxNumberOfPriceZeroDecimalsToColorize(offer)));
                            model.priceFeedService.updateCounterProperty().removeListener(listener);
                        }
                    }
                };

                @Override
                public void updateItem(final OfferListItem offerListItem, boolean empty) {
                    super.updateItem(offerListItem, empty);
                    if (offerListItem != null && !empty) {
                        this.offer = offerListItem.offer;
                        if (offer.getPrice() == null) {
                            this.offer = offerListItem.offer;
                            model.priceFeedService.updateCounterProperty().addListener(listener);
                            setText(Res.get("shared.na"));
                        } else {
                            setText("");
                            setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(offer), model.getMaxNumberOfPriceZeroDecimalsToColorize(offer)));
                        }
                    } else {
                        if (listener != null)
                            model.priceFeedService.updateCounterProperty().removeListener(listener);
                        this.offer = null;
                        setText("");
                        setGraphic(null);
                    }
                }
            };
        }
    });
    // amount
    TableColumn<OfferListItem, OfferListItem> amountColumn = new AutoTooltipTableColumn<>(Res.get("shared.amountWithCur", Res.getBaseCurrencyCode()));
    amountColumn.setMinWidth(115);
    amountColumn.setSortable(false);
    amountColumn.getStyleClass().add("number-column");
    amountColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    amountColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {

        @Override
        public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
            return new TableCell<OfferListItem, OfferListItem>() {

                @Override
                public void updateItem(final OfferListItem offerListItem, boolean empty) {
                    super.updateItem(offerListItem, empty);
                    if (offerListItem != null && !empty) {
                        setGraphic(new ColoredDecimalPlacesWithZerosText(formatter.formatCoin(offerListItem.offer.getAmount(), 4), GUIUtil.AMOUNT_DECIMALS_WITH_ZEROS));
                    } else {
                        setGraphic(null);
                    }
                }
            };
        }
    });
    tableView.getColumns().add(volumeColumn);
    tableView.getColumns().add(amountColumn);
    tableView.getColumns().add(priceColumn);
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    Label placeholder = new AutoTooltipLabel(Res.get("table.placeholder.noItems", Res.get("shared.multipleOffers")));
    placeholder.setWrapText(true);
    tableView.setPlaceholder(placeholder);
    Label titleLabel = new AutoTooltipLabel();
    titleLabel.getStyleClass().add("table-title");
    UserThread.execute(() -> titleLabel.prefWidthProperty().bind(tableView.widthProperty()));
    boolean isSellOffer = direction == OfferPayload.Direction.SELL;
    Button button = new AutoTooltipButton();
    ImageView iconView = new ImageView();
    iconView.setId(isSellOffer ? "image-buy-white" : "image-sell-white");
    button.setGraphic(iconView);
    button.setGraphicTextGap(10);
    button.setText(isSellOffer ? Res.get("market.offerBook.buy") : Res.get("market.offerBook.sell"));
    button.setMinHeight(40);
    button.setId(isSellOffer ? "buy-button-big" : "sell-button-big");
    button.setOnAction(e -> {
        if (isSellOffer) {
            model.preferences.setBuyScreenCurrencyCode(model.getCurrencyCode());
            // noinspection unchecked
            navigation.navigateTo(MainView.class, BuyOfferView.class);
        } else {
            model.preferences.setSellScreenCurrencyCode(model.getCurrencyCode());
            // noinspection unchecked
            navigation.navigateTo(MainView.class, SellOfferView.class);
        }
    });
    VBox vBox = new VBox();
    vBox.setSpacing(10);
    vBox.setFillWidth(true);
    vBox.setMinHeight(190);
    vBox.setVgrow(tableView, Priority.ALWAYS);
    vBox.getChildren().addAll(titleLabel, tableView, button);
    button.prefWidthProperty().bind(vBox.widthProperty());
    return new Tuple4<>(tableView, vBox, button, titleLabel);
}
Also used : ObservableValue(javafx.beans.value.ObservableValue) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Label(javafx.scene.control.Label) TableCell(javafx.scene.control.TableCell) Button(javafx.scene.control.Button) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) ListChangeListener(javafx.collections.ListChangeListener) ChangeListener(javafx.beans.value.ChangeListener) ImageView(javafx.scene.image.ImageView) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) TableView(javafx.scene.control.TableView) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) TableColumn(javafx.scene.control.TableColumn) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) Tuple4(bisq.common.util.Tuple4) Offer(bisq.core.offer.Offer) ColoredDecimalPlacesWithZerosText(bisq.desktop.components.ColoredDecimalPlacesWithZerosText) VBox(javafx.scene.layout.VBox)

Example 3 with Tuple4

use of bisq.common.util.Tuple4 in project bisq-desktop by bisq-network.

the class FormBuilder method addLabelInputTextFieldLabelInputTextField.

// /////////////////////////////////////////////////////////////////////////////////////////
// Label  + InputTextField + Label  + InputTextField
// /////////////////////////////////////////////////////////////////////////////////////////
public static Tuple4<Label, InputTextField, Label, InputTextField> addLabelInputTextFieldLabelInputTextField(GridPane gridPane, int rowIndex, String title1, String title2) {
    Label label1 = addLabel(gridPane, rowIndex, title1, 0);
    InputTextField inputTextField1 = new InputTextField();
    Label label2 = new AutoTooltipLabel(title2);
    HBox.setMargin(label2, new Insets(5, 0, 0, 0));
    InputTextField inputTextField2 = new InputTextField();
    HBox hBox = new HBox();
    hBox.setSpacing(10);
    hBox.getChildren().addAll(inputTextField1, label2, inputTextField2);
    GridPane.setRowIndex(hBox, rowIndex);
    GridPane.setColumnIndex(hBox, 1);
    gridPane.getChildren().add(hBox);
    return new Tuple4<>(label1, inputTextField1, label2, inputTextField2);
}
Also used : Tuple4(bisq.common.util.Tuple4) HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) InputTextField(bisq.desktop.components.InputTextField) InfoInputTextField(bisq.desktop.components.InfoInputTextField) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Label(javafx.scene.control.Label) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel)

Example 4 with Tuple4

use of bisq.common.util.Tuple4 in project bisq-desktop by bisq-network.

the class FormBuilder method addLabelTextFieldLabelTextField.

// /////////////////////////////////////////////////////////////////////////////////////////
// Label  + TextField + Label  + TextField
// /////////////////////////////////////////////////////////////////////////////////////////
public static Tuple4<Label, TextField, Label, TextField> addLabelTextFieldLabelTextField(GridPane gridPane, int rowIndex, String title1, String title2) {
    Label label1 = addLabel(gridPane, rowIndex, title1, 0);
    TextField textField1 = new TextField();
    textField1.setEditable(false);
    textField1.setMouseTransparent(true);
    textField1.setFocusTraversable(false);
    Label label2 = new AutoTooltipLabel(title2);
    HBox.setMargin(label2, new Insets(5, 0, 0, 0));
    TextField textField2 = new TextField();
    textField2.setEditable(false);
    textField2.setMouseTransparent(true);
    textField2.setFocusTraversable(false);
    HBox hBox = new HBox();
    hBox.setSpacing(10);
    hBox.getChildren().addAll(textField1, label2, textField2);
    GridPane.setRowIndex(hBox, rowIndex);
    GridPane.setColumnIndex(hBox, 1);
    gridPane.getChildren().add(hBox);
    return new Tuple4<>(label1, textField1, label2, textField2);
}
Also used : Tuple4(bisq.common.util.Tuple4) HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Label(javafx.scene.control.Label) BalanceTextField(bisq.desktop.components.BalanceTextField) InputTextField(bisq.desktop.components.InputTextField) InfoInputTextField(bisq.desktop.components.InfoInputTextField) PasswordTextField(bisq.desktop.components.PasswordTextField) InfoTextField(bisq.desktop.components.InfoTextField) TextField(javafx.scene.control.TextField) TxIdTextField(bisq.desktop.components.TxIdTextField) BsqAddressTextField(bisq.desktop.components.BsqAddressTextField) FundsTextField(bisq.desktop.components.FundsTextField) AddressTextField(bisq.desktop.components.AddressTextField) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel)

Aggregations

Tuple4 (bisq.common.util.Tuple4)4 AutoTooltipLabel (bisq.desktop.components.AutoTooltipLabel)4 Label (javafx.scene.control.Label)3 AutoTooltipButton (bisq.desktop.components.AutoTooltipButton)2 InfoInputTextField (bisq.desktop.components.InfoInputTextField)2 InputTextField (bisq.desktop.components.InputTextField)2 Button (javafx.scene.control.Button)2 TableCell (javafx.scene.control.TableCell)2 TableColumn (javafx.scene.control.TableColumn)2 TableView (javafx.scene.control.TableView)2 VBox (javafx.scene.layout.VBox)2 Tuple2 (bisq.common.util.Tuple2)1 Utilities (bisq.common.util.Utilities)1 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)1 WalletsSetup (bisq.core.btc.wallet.WalletsSetup)1 Res (bisq.core.locale.Res)1 Offer (bisq.core.offer.Offer)1 OpenOffer (bisq.core.offer.OpenOffer)1 Tradable (bisq.core.trade.Tradable)1 Trade (bisq.core.trade.Trade)1