Search in sources :

Example 21 with Offer

use of io.bitsquare.trade.offer.Offer in project bitsquare by bitsquare.

the class OfferBookView method getActionColumn.

private TableColumn<OfferBookListItem, OfferBookListItem> getActionColumn() {
    TableColumn<OfferBookListItem, OfferBookListItem> column = new TableColumn<OfferBookListItem, OfferBookListItem>("I want to:") {

        {
            setMinWidth(80);
            setSortable(false);
        }
    };
    column.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    column.setCellFactory(new Callback<TableColumn<OfferBookListItem, OfferBookListItem>, TableCell<OfferBookListItem, OfferBookListItem>>() {

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

                final ImageView iconView = new ImageView();

                final Button button = new Button();

                boolean isTradable, isPaymentAccountValidForOffer, hasMatchingArbitrator, hasSameProtocolVersion, isIgnored, isOfferBanned, isNodeBanned;

                {
                    button.setGraphic(iconView);
                    button.setMinWidth(130);
                    button.setMaxWidth(130);
                    button.setGraphicTextGap(10);
                }

                @Override
                public void updateItem(final OfferBookListItem newItem, boolean empty) {
                    super.updateItem(newItem, empty);
                    TableRow tableRow = getTableRow();
                    if (newItem != null && !empty) {
                        final Offer offer = newItem.getOffer();
                        boolean myOffer = model.isMyOffer(offer);
                        if (tableRow != null) {
                            isPaymentAccountValidForOffer = model.isAnyPaymentAccountValidForOffer(offer);
                            hasMatchingArbitrator = model.hasMatchingArbitrator(offer);
                            hasSameProtocolVersion = model.hasSameProtocolVersion(offer);
                            isIgnored = model.isIgnored(offer);
                            isOfferBanned = model.isOfferBanned(offer);
                            isNodeBanned = model.isNodeBanned(offer);
                            isTradable = isPaymentAccountValidForOffer && hasMatchingArbitrator && hasSameProtocolVersion && !isIgnored && !isOfferBanned && !isNodeBanned;
                            tableRow.setOpacity(isTradable || myOffer ? 1 : 0.4);
                            if (isTradable) {
                                // set first row button as default
                                button.setDefaultButton(getIndex() == 0);
                                tableRow.setOnMousePressed(null);
                            } else {
                                button.setDefaultButton(false);
                                tableRow.setOnMousePressed(e -> {
                                    if (!(e.getTarget() instanceof ImageView || e.getTarget() instanceof Canvas))
                                        onShowInfo(isPaymentAccountValidForOffer, hasMatchingArbitrator, hasSameProtocolVersion, isIgnored, isOfferBanned, isNodeBanned);
                                });
                            //TODO
                            //tableRow.setTooltip(new Tooltip(""));
                            }
                        }
                        String title;
                        if (myOffer) {
                            iconView.setId("image-remove");
                            title = "Remove";
                            button.setId("cancel-button");
                            // does not take the font colors sometimes from the style
                            button.setStyle("-fx-text-fill: #444;");
                            button.setOnAction(e -> onRemoveOpenOffer(offer));
                        } else {
                            boolean isSellOffer = offer.getDirection() == Offer.Direction.SELL;
                            iconView.setId(isSellOffer ? "image-buy-white" : "image-sell-white");
                            button.setId(isSellOffer ? "buy-button" : "sell-button");
                            // does not take the font colors sometimes from the style
                            button.setStyle("-fx-text-fill: white;");
                            title = model.getDirectionLabel(offer);
                            button.setTooltip(new Tooltip("Take offer for " + model.getDirectionLabelTooltip(offer)));
                            button.setOnAction(e -> onTakeOffer(offer));
                        }
                        if (!myOffer && !isTradable)
                            button.setOnAction(e -> onShowInfo(isPaymentAccountValidForOffer, hasMatchingArbitrator, hasSameProtocolVersion, isIgnored, isOfferBanned, isNodeBanned));
                        button.setText(title);
                        setGraphic(button);
                    } else {
                        setGraphic(null);
                        if (button != null)
                            button.setOnAction(null);
                        if (tableRow != null) {
                            tableRow.setOpacity(1);
                            tableRow.setOnMousePressed(null);
                        }
                    }
                }
            };
        }
    });
    return column;
}
Also used : PaymentMethod(io.bitsquare.payment.PaymentMethod) HPos(javafx.geometry.HPos) Popup(io.bitsquare.gui.main.overlays.popups.Popup) MainView(io.bitsquare.gui.main.MainView) AccountSettingsView(io.bitsquare.gui.main.account.settings.AccountSettingsView) FiatCurrency(io.bitsquare.locale.FiatCurrency) javafx.scene.control(javafx.scene.control) PeerInfoIcon(io.bitsquare.gui.components.PeerInfoIcon) TradeCurrency(io.bitsquare.locale.TradeCurrency) FundsView(io.bitsquare.gui.main.funds.FundsView) ArbitratorSelectionView(io.bitsquare.gui.main.account.content.arbitratorselection.ArbitratorSelectionView) GUIUtil(io.bitsquare.gui.util.GUIUtil) Inject(javax.inject.Inject) OfferView(io.bitsquare.gui.main.offer.OfferView) Insets(javafx.geometry.Insets) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) Navigation(io.bitsquare.gui.Navigation) Layout(io.bitsquare.gui.util.Layout) VPos(javafx.geometry.VPos) MonadicBinding(org.fxmisc.easybind.monadic.MonadicBinding) FeePolicy(io.bitsquare.btc.FeePolicy) Callback(javafx.util.Callback) GridPane(javafx.scene.layout.GridPane) BSFormatter(io.bitsquare.gui.util.BSFormatter) WithdrawalView(io.bitsquare.gui.main.funds.withdrawal.WithdrawalView) Node(javafx.scene.Node) Canvas(javafx.scene.canvas.Canvas) Fiat(org.bitcoinj.utils.Fiat) OfferDetailsWindow(io.bitsquare.gui.main.overlays.windows.OfferDetailsWindow) StringConverter(javafx.util.StringConverter) Subscription(org.fxmisc.easybind.Subscription) ActivatableViewAndModel(io.bitsquare.gui.common.view.ActivatableViewAndModel) PrivateNotificationManager(io.bitsquare.alert.PrivateNotificationManager) Priority(javafx.scene.layout.Priority) HyperlinkWithIcon(io.bitsquare.gui.components.HyperlinkWithIcon) Offer(io.bitsquare.trade.offer.Offer) FormBuilder(io.bitsquare.gui.util.FormBuilder) FiatAccountsView(io.bitsquare.gui.main.account.content.fiataccounts.FiatAccountsView) EasyBind(org.fxmisc.easybind.EasyBind) ImageView(javafx.scene.image.ImageView) ObservableValue(javafx.beans.value.ObservableValue) FxmlView(io.bitsquare.gui.common.view.FxmlView) ChangeListener(javafx.beans.value.ChangeListener) BSResources(io.bitsquare.locale.BSResources) TitledGroupBg(io.bitsquare.gui.components.TitledGroupBg) AccountView(io.bitsquare.gui.main.account.AccountView) Canvas(javafx.scene.canvas.Canvas) Offer(io.bitsquare.trade.offer.Offer) ImageView(javafx.scene.image.ImageView)

Example 22 with Offer

use of io.bitsquare.trade.offer.Offer in project bitsquare by bitsquare.

the class OfferBookView method getPaymentMethodColumn.

private TableColumn<OfferBookListItem, OfferBookListItem> getPaymentMethodColumn() {
    TableColumn<OfferBookListItem, OfferBookListItem> column = new TableColumn<OfferBookListItem, OfferBookListItem>("Payment method") {

        {
            setMinWidth(125);
        }
    };
    column.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    column.setCellFactory(new Callback<TableColumn<OfferBookListItem, OfferBookListItem>, TableCell<OfferBookListItem, OfferBookListItem>>() {

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

                private HyperlinkWithIcon field;

                @Override
                public void updateItem(final OfferBookListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        field = new HyperlinkWithIcon(model.getPaymentMethod(item), true);
                        field.setOnAction(event -> offerDetailsWindow.show(item.getOffer()));
                        field.setTooltip(new Tooltip(model.getPaymentMethodToolTip(item)));
                        setGraphic(field);
                    } else {
                        setGraphic(null);
                        if (field != null)
                            field.setOnAction(null);
                    }
                }
            };
        }
    });
    return column;
}
Also used : PaymentMethod(io.bitsquare.payment.PaymentMethod) HPos(javafx.geometry.HPos) Popup(io.bitsquare.gui.main.overlays.popups.Popup) MainView(io.bitsquare.gui.main.MainView) AccountSettingsView(io.bitsquare.gui.main.account.settings.AccountSettingsView) FiatCurrency(io.bitsquare.locale.FiatCurrency) javafx.scene.control(javafx.scene.control) PeerInfoIcon(io.bitsquare.gui.components.PeerInfoIcon) TradeCurrency(io.bitsquare.locale.TradeCurrency) FundsView(io.bitsquare.gui.main.funds.FundsView) ArbitratorSelectionView(io.bitsquare.gui.main.account.content.arbitratorselection.ArbitratorSelectionView) GUIUtil(io.bitsquare.gui.util.GUIUtil) Inject(javax.inject.Inject) OfferView(io.bitsquare.gui.main.offer.OfferView) Insets(javafx.geometry.Insets) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) Navigation(io.bitsquare.gui.Navigation) Layout(io.bitsquare.gui.util.Layout) VPos(javafx.geometry.VPos) MonadicBinding(org.fxmisc.easybind.monadic.MonadicBinding) FeePolicy(io.bitsquare.btc.FeePolicy) Callback(javafx.util.Callback) GridPane(javafx.scene.layout.GridPane) BSFormatter(io.bitsquare.gui.util.BSFormatter) WithdrawalView(io.bitsquare.gui.main.funds.withdrawal.WithdrawalView) Node(javafx.scene.Node) Canvas(javafx.scene.canvas.Canvas) Fiat(org.bitcoinj.utils.Fiat) OfferDetailsWindow(io.bitsquare.gui.main.overlays.windows.OfferDetailsWindow) StringConverter(javafx.util.StringConverter) Subscription(org.fxmisc.easybind.Subscription) ActivatableViewAndModel(io.bitsquare.gui.common.view.ActivatableViewAndModel) PrivateNotificationManager(io.bitsquare.alert.PrivateNotificationManager) Priority(javafx.scene.layout.Priority) HyperlinkWithIcon(io.bitsquare.gui.components.HyperlinkWithIcon) Offer(io.bitsquare.trade.offer.Offer) FormBuilder(io.bitsquare.gui.util.FormBuilder) FiatAccountsView(io.bitsquare.gui.main.account.content.fiataccounts.FiatAccountsView) EasyBind(org.fxmisc.easybind.EasyBind) ImageView(javafx.scene.image.ImageView) ObservableValue(javafx.beans.value.ObservableValue) FxmlView(io.bitsquare.gui.common.view.FxmlView) ChangeListener(javafx.beans.value.ChangeListener) BSResources(io.bitsquare.locale.BSResources) TitledGroupBg(io.bitsquare.gui.components.TitledGroupBg) AccountView(io.bitsquare.gui.main.account.AccountView) HyperlinkWithIcon(io.bitsquare.gui.components.HyperlinkWithIcon)

Example 23 with Offer

use of io.bitsquare.trade.offer.Offer in project bitsquare by bitsquare.

the class OfferBookView method setDirectionTitles.

private void setDirectionTitles() {
    TradeCurrency selectedTradeCurrency = model.getSelectedTradeCurrency();
    if (selectedTradeCurrency != null) {
        Offer.Direction direction = model.getDirection();
        String preFix = "Create new offer to ";
        String directionText = direction == Offer.Direction.BUY ? "buy" : "sell";
        String mirroredDirectionText = direction == Offer.Direction.SELL ? "buy" : "sell";
        String code = selectedTradeCurrency.getCode();
        if (model.showAllTradeCurrenciesProperty.get())
            createOfferButton.setText(preFix + directionText + " BTC");
        else if (selectedTradeCurrency instanceof FiatCurrency)
            createOfferButton.setText(preFix + directionText + " BTC" + (direction == Offer.Direction.BUY ? " with " : " for ") + code);
        else
            createOfferButton.setText(preFix + mirroredDirectionText + " " + code + " (" + directionText + " BTC)");
    }
}
Also used : TradeCurrency(io.bitsquare.locale.TradeCurrency) Offer(io.bitsquare.trade.offer.Offer) FiatCurrency(io.bitsquare.locale.FiatCurrency)

Example 24 with Offer

use of io.bitsquare.trade.offer.Offer in project bitsquare by bitsquare.

the class ContractWindow method addContent.

private void addContent() {
    Contract contract = dispute.getContract();
    Offer offer = contract.offer;
    List<String> acceptedBanks = offer.getAcceptedBankIds();
    boolean showAcceptedBanks = acceptedBanks != null && !acceptedBanks.isEmpty();
    List<String> acceptedCountryCodes = offer.getAcceptedCountryCodes();
    boolean showAcceptedCountryCodes = acceptedCountryCodes != null && !acceptedCountryCodes.isEmpty();
    int rows = 16;
    if (dispute.getDepositTxSerialized() != null)
        rows++;
    if (dispute.getPayoutTxSerialized() != null)
        rows++;
    if (showAcceptedCountryCodes)
        rows++;
    if (showAcceptedBanks)
        rows++;
    PaymentAccountContractData sellerPaymentAccountContractData = contract.getSellerPaymentAccountContractData();
    addTitledGroupBg(gridPane, ++rowIndex, rows, "Dispute details");
    addLabelTextFieldWithCopyIcon(gridPane, rowIndex, "Offer ID:", offer.getId(), Layout.FIRST_ROW_DISTANCE).second.setMouseTransparent(false);
    addLabelTextField(gridPane, ++rowIndex, "Offer date / Trade date:", formatter.formatDateTime(offer.getDate()) + " / " + formatter.formatDateTime(dispute.getTradeDate()));
    String currencyCode = offer.getCurrencyCode();
    addLabelTextField(gridPane, ++rowIndex, "Trade type:", formatter.getDirectionBothSides(offer.getDirection(), currencyCode));
    addLabelTextField(gridPane, ++rowIndex, "Trade price:", formatter.formatPrice(contract.getTradePrice()));
    addLabelTextField(gridPane, ++rowIndex, "Trade amount:", formatter.formatCoinWithCode(contract.getTradeAmount()));
    addLabelTextField(gridPane, ++rowIndex, formatter.formatVolumeLabel(currencyCode, ":"), formatter.formatVolumeWithCode(new ExchangeRate(contract.getTradePrice()).coinToFiat(contract.getTradeAmount())));
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Bitcoin address BTC buyer / BTC seller:", contract.getBuyerPayoutAddressString() + " / " + contract.getSellerPayoutAddressString()).second.setMouseTransparent(false);
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Network address BTC buyer / BTC seller:", contract.getBuyerNodeAddress().getFullAddress() + " / " + contract.getSellerNodeAddress().getFullAddress());
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "No. of disputes BTC buyer / BTC seller:", disputeManager.getNrOfDisputes(true, contract) + " / " + disputeManager.getNrOfDisputes(false, contract));
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "BTC buyer payment details:", BSResources.get(contract.getBuyerPaymentAccountContractData().getPaymentDetails())).second.setMouseTransparent(false);
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "BTC seller payment details:", BSResources.get(sellerPaymentAccountContractData.getPaymentDetails())).second.setMouseTransparent(false);
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Selected arbitrator:", contract.arbitratorNodeAddress.getFullAddress());
    if (showAcceptedCountryCodes) {
        String countries;
        Tooltip tooltip = null;
        if (CountryUtil.containsAllSepaEuroCountries(acceptedCountryCodes)) {
            countries = "All Euro countries";
        } else {
            countries = CountryUtil.getCodesString(acceptedCountryCodes);
            tooltip = new Tooltip(CountryUtil.getNamesByCodesString(acceptedCountryCodes));
        }
        TextField acceptedCountries = addLabelTextField(gridPane, ++rowIndex, "Accepted taker countries:", countries).second;
        if (tooltip != null)
            acceptedCountries.setTooltip(new Tooltip());
    }
    if (showAcceptedBanks) {
        if (offer.getPaymentMethod().equals(PaymentMethod.SAME_BANK)) {
            addLabelTextField(gridPane, ++rowIndex, "Bank name:", acceptedBanks.get(0));
        } else if (offer.getPaymentMethod().equals(PaymentMethod.SPECIFIC_BANKS)) {
            String value = Joiner.on(", ").join(acceptedBanks);
            Tooltip tooltip = new Tooltip("Accepted banks: " + value);
            TextField acceptedBanksTextField = addLabelTextField(gridPane, ++rowIndex, "Accepted banks:", value).second;
            acceptedBanksTextField.setMouseTransparent(false);
            acceptedBanksTextField.setTooltip(tooltip);
        }
    }
    addLabelTxIdTextField(gridPane, ++rowIndex, "Offer fee transaction ID:", offer.getOfferFeePaymentTxID());
    addLabelTxIdTextField(gridPane, ++rowIndex, "Trading fee transaction ID:", contract.takeOfferFeeTxID);
    if (dispute.getDepositTxSerialized() != null)
        addLabelTxIdTextField(gridPane, ++rowIndex, "Deposit transaction ID:", dispute.getDepositTxId());
    if (dispute.getPayoutTxSerialized() != null)
        addLabelTxIdTextField(gridPane, ++rowIndex, "Payout transaction ID:", dispute.getPayoutTxId());
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Contract hash:", Utils.HEX.encode(dispute.getContractHash())).second.setMouseTransparent(false);
    if (contract != null) {
        Button viewContractButton = addLabelButton(gridPane, ++rowIndex, "Contract in JSON format:", "View contract in JSON format", 0).second;
        viewContractButton.setDefaultButton(false);
        viewContractButton.setOnAction(e -> {
            TextArea textArea = new TextArea();
            String contractAsJson = dispute.getContractAsJson();
            contractAsJson += "\n\nBuyerMultiSigPubKeyHex: " + Utils.HEX.encode(dispute.getContract().getBuyerMultiSigPubKey());
            contractAsJson += "\nSellerMultiSigPubKeyHex: " + Utils.HEX.encode(dispute.getContract().getSellerMultiSigPubKey());
            textArea.setText(contractAsJson);
            textArea.setPrefHeight(50);
            textArea.setEditable(false);
            textArea.setWrapText(true);
            textArea.setPrefSize(800, 600);
            Scene viewContractScene = new Scene(textArea);
            Stage viewContractStage = new Stage();
            viewContractStage.setTitle("Contract for trade with ID: " + dispute.getShortTradeId());
            viewContractStage.setScene(viewContractScene);
            if (owner == null)
                owner = MainView.getRootContainer();
            Scene rootScene = owner.getScene();
            viewContractStage.initOwner(rootScene.getWindow());
            viewContractStage.initModality(Modality.NONE);
            viewContractStage.initStyle(StageStyle.UTILITY);
            viewContractStage.show();
            Window window = rootScene.getWindow();
            double titleBarHeight = window.getHeight() - rootScene.getHeight();
            viewContractStage.setX(Math.round(window.getX() + (owner.getWidth() - viewContractStage.getWidth()) / 2) + 200);
            viewContractStage.setY(Math.round(window.getY() + titleBarHeight + (owner.getHeight() - viewContractStage.getHeight()) / 2) + 50);
        });
    }
    Button cancelButton = addButtonAfterGroup(gridPane, ++rowIndex, "Close");
    //TODO app wide focus
    //cancelButton.requestFocus();
    cancelButton.setOnAction(e -> {
        closeHandlerOptional.ifPresent(closeHandler -> closeHandler.run());
        hide();
    });
}
Also used : Window(javafx.stage.Window) PaymentAccountContractData(io.bitsquare.payment.PaymentAccountContractData) ExchangeRate(org.bitcoinj.utils.ExchangeRate) TextArea(javafx.scene.control.TextArea) Tooltip(javafx.scene.control.Tooltip) Scene(javafx.scene.Scene) Offer(io.bitsquare.trade.offer.Offer) Button(javafx.scene.control.Button) TextField(javafx.scene.control.TextField) Stage(javafx.stage.Stage) Contract(io.bitsquare.trade.Contract)

Example 25 with Offer

use of io.bitsquare.trade.offer.Offer in project bitsquare by bitsquare.

the class OfferBookViewModel method getAmount.

String getAmount(OfferBookListItem item) {
    Offer offer = item.getOffer();
    Coin amount = offer.getAmount();
    Coin minAmount = offer.getMinAmount();
    if (amount.equals(minAmount))
        return formatter.formatAmount(offer);
    else
        return formatter.formatAmountWithMinAmount(offer);
}
Also used : Coin(org.bitcoinj.core.Coin) Offer(io.bitsquare.trade.offer.Offer)

Aggregations

Offer (io.bitsquare.trade.offer.Offer)27 Fiat (org.bitcoinj.utils.Fiat)8 Coin (org.bitcoinj.core.Coin)7 MainView (io.bitsquare.gui.main.MainView)5 Popup (io.bitsquare.gui.main.overlays.popups.Popup)5 BSFormatter (io.bitsquare.gui.util.BSFormatter)5 ImageView (javafx.scene.image.ImageView)5 AddressEntry (io.bitsquare.btc.AddressEntry)4 WalletService (io.bitsquare.btc.WalletService)4 Navigation (io.bitsquare.gui.Navigation)4 TradeCurrency (io.bitsquare.locale.TradeCurrency)4 ListChangeListener (javafx.collections.ListChangeListener)4 FeePolicy (io.bitsquare.btc.FeePolicy)3 ActivatableViewAndModel (io.bitsquare.gui.common.view.ActivatableViewAndModel)3 FxmlView (io.bitsquare.gui.common.view.FxmlView)3 AccountView (io.bitsquare.gui.main.account.AccountView)3 ArbitratorSelectionView (io.bitsquare.gui.main.account.content.arbitratorselection.ArbitratorSelectionView)3 AccountSettingsView (io.bitsquare.gui.main.account.settings.AccountSettingsView)3 GUIUtil (io.bitsquare.gui.util.GUIUtil)3 FiatCurrency (io.bitsquare.locale.FiatCurrency)3