Search in sources :

Example 1 with PaymentMethod

use of io.bitsquare.payment.PaymentMethod in project bitsquare by bitsquare.

the class OfferDetailsWindow method addContent.

private void addContent() {
    int rows = 5;
    List<String> acceptedBanks = offer.getAcceptedBankIds();
    boolean showAcceptedBanks = acceptedBanks != null && !acceptedBanks.isEmpty();
    List<String> acceptedCountryCodes = offer.getAcceptedCountryCodes();
    boolean showAcceptedCountryCodes = acceptedCountryCodes != null && !acceptedCountryCodes.isEmpty();
    if (!takeOfferHandlerOptional.isPresent())
        rows++;
    if (showAcceptedBanks)
        rows++;
    if (showAcceptedCountryCodes)
        rows++;
    addTitledGroupBg(gridPane, ++rowIndex, rows, "Offer");
    String fiatDirectionInfo = ":";
    String btcDirectionInfo = ":";
    Offer.Direction direction = offer.getDirection();
    String currencyCode = offer.getCurrencyCode();
    if (takeOfferHandlerOptional.isPresent()) {
        addLabelTextField(gridPane, rowIndex, "Offer type:", formatter.getDirectionForTakeOffer(direction, currencyCode), Layout.FIRST_ROW_DISTANCE);
        fiatDirectionInfo = direction == Offer.Direction.BUY ? " to receive:" : " to spend:";
        btcDirectionInfo = direction == Offer.Direction.SELL ? " to receive:" : " to spend:";
    } else if (placeOfferHandlerOptional.isPresent()) {
        addLabelTextField(gridPane, rowIndex, "Offer type:", formatter.getOfferDirectionForCreateOffer(direction, currencyCode), Layout.FIRST_ROW_DISTANCE);
        fiatDirectionInfo = direction == Offer.Direction.SELL ? " to receive:" : " to spend:";
        btcDirectionInfo = direction == Offer.Direction.BUY ? " to receive:" : " to spend:";
    } else {
        addLabelTextField(gridPane, rowIndex, "Offer type:", formatter.getDirectionBothSides(direction, currencyCode), Layout.FIRST_ROW_DISTANCE);
    }
    if (takeOfferHandlerOptional.isPresent()) {
        addLabelTextField(gridPane, ++rowIndex, "Bitcoin amount" + btcDirectionInfo, formatter.formatCoinWithCode(tradeAmount));
        addLabelTextField(gridPane, ++rowIndex, formatter.formatVolumeLabel(currencyCode) + fiatDirectionInfo, formatter.formatVolumeWithCode(offer.getVolumeByAmount(tradeAmount)));
    } else {
        addLabelTextField(gridPane, ++rowIndex, "Bitcoin amount" + btcDirectionInfo, formatter.formatCoinWithCode(offer.getAmount()));
        addLabelTextField(gridPane, ++rowIndex, "Min. bitcoin amount:", formatter.formatCoinWithCode(offer.getMinAmount()));
        String volume = formatter.formatVolumeWithCode(offer.getOfferVolume());
        String minVolume = "";
        if (!offer.getAmount().equals(offer.getMinAmount()))
            minVolume = " (min. " + formatter.formatVolumeWithCode(offer.getMinOfferVolume()) + ")";
        addLabelTextField(gridPane, ++rowIndex, formatter.formatVolumeLabel(currencyCode) + fiatDirectionInfo, volume + minVolume);
    }
    if (takeOfferHandlerOptional.isPresent()) {
        addLabelTextField(gridPane, ++rowIndex, "Price:", formatter.formatPrice(tradePrice));
    } else {
        Fiat price = offer.getPrice();
        if (offer.getUseMarketBasedPrice()) {
            addLabelTextField(gridPane, ++rowIndex, "Price:", formatter.formatPrice(price) + " (distance from market price: " + formatter.formatPercentagePrice(offer.getMarketPriceMargin()) + ")");
        } else {
            addLabelTextField(gridPane, ++rowIndex, "Price:", formatter.formatPrice(price));
        }
    }
    final PaymentMethod paymentMethod = offer.getPaymentMethod();
    final String offererPaymentAccountId = offer.getOffererPaymentAccountId();
    final PaymentAccount paymentAccount = user.getPaymentAccount(offererPaymentAccountId);
    String bankId = offer.getBankId();
    if (bankId == null || bankId.equals("null"))
        bankId = "";
    else
        bankId = " (" + bankId + ")";
    final boolean isSpecificBanks = paymentMethod.equals(PaymentMethod.SPECIFIC_BANKS);
    final boolean isNationalBanks = paymentMethod.equals(PaymentMethod.NATIONAL_BANK);
    final boolean isSepa = paymentMethod.equals(PaymentMethod.SEPA);
    if (offer.isMyOffer(keyRing) && offererPaymentAccountId != null && paymentAccount != null) {
        addLabelTextField(gridPane, ++rowIndex, "My trading account:", paymentAccount.getAccountName());
    } else {
        final String method = BSResources.get(paymentMethod.getId());
        if (isNationalBanks || isSpecificBanks || isSepa) {
            if (BankUtil.isBankIdRequired(offer.getCountryCode()))
                addLabelTextField(gridPane, ++rowIndex, "Payment method (offerer's bank ID):", method + bankId);
            else if (BankUtil.isBankNameRequired(offer.getCountryCode()))
                addLabelTextField(gridPane, ++rowIndex, "Payment method (offerer's bank name):", method + bankId);
        } else {
            addLabelTextField(gridPane, ++rowIndex, "Payment method:", method);
        }
    }
    if (showAcceptedBanks) {
        if (paymentMethod.equals(PaymentMethod.SAME_BANK)) {
            addLabelTextField(gridPane, ++rowIndex, "Bank ID (e.g. BIC or SWIFT):", acceptedBanks.get(0));
        } else if (isSpecificBanks) {
            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);
        }
    }
    if (showAcceptedCountryCodes) {
        String countries;
        Tooltip tooltip = null;
        if (CountryUtil.containsAllSepaEuroCountries(acceptedCountryCodes)) {
            countries = "All Euro countries";
        } else {
            if (acceptedCountryCodes.size() == 1) {
                countries = CountryUtil.getNameAndCode(acceptedCountryCodes.get(0));
                tooltip = new Tooltip(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.setMouseTransparent(false);
            acceptedCountries.setTooltip(tooltip);
        }
    }
    rows = 5;
    String paymentMethodCountryCode = offer.getCountryCode();
    if (paymentMethodCountryCode != null)
        rows++;
    if (offer.getOfferFeePaymentTxID() != null)
        rows++;
    addTitledGroupBg(gridPane, ++rowIndex, rows, "Details", Layout.GROUP_DISTANCE);
    addLabelTextFieldWithCopyIcon(gridPane, rowIndex, "Offer ID:", offer.getId(), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Offerer's onion address:", offer.getOffererNodeAddress().getFullAddress());
    addLabelTextField(gridPane, ++rowIndex, "Creation date:", formatter.formatDateTime(offer.getDate()));
    addLabelTextField(gridPane, ++rowIndex, "Security deposit:", formatter.formatCoinWithCode(FeePolicy.getSecurityDeposit(offer)));
    if (paymentMethodCountryCode != null)
        addLabelTextField(gridPane, ++rowIndex, "Offerer's country of bank:", CountryUtil.getNameAndCode(paymentMethodCountryCode));
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Accepted arbitrators:", formatter.arbitratorAddressesToString(offer.getArbitratorNodeAddresses()));
    if (offer.getOfferFeePaymentTxID() != null)
        addLabelTxIdTextField(gridPane, ++rowIndex, "Offer fee transaction ID:", offer.getOfferFeePaymentTxID());
    if (placeOfferHandlerOptional.isPresent()) {
        addTitledGroupBg(gridPane, ++rowIndex, 1, "Commitment", Layout.GROUP_DISTANCE);
        addLabelTextField(gridPane, rowIndex, "I agree:", Offer.TAC_OFFERER, Layout.FIRST_ROW_AND_GROUP_DISTANCE);
        addConfirmAndCancelButtons(true);
    } else if (takeOfferHandlerOptional.isPresent()) {
        addTitledGroupBg(gridPane, ++rowIndex, 1, "Contract", Layout.GROUP_DISTANCE);
        addLabelTextField(gridPane, rowIndex, "Terms and conditions:", Offer.TAC_TAKER, Layout.FIRST_ROW_AND_GROUP_DISTANCE);
        addConfirmAndCancelButtons(false);
    } else {
        Button cancelButton = addButtonAfterGroup(gridPane, ++rowIndex, "Close");
        cancelButton.setOnAction(e -> {
            closeHandlerOptional.ifPresent(Runnable::run);
            hide();
        });
    }
}
Also used : Button(javafx.scene.control.Button) Overlay(io.bitsquare.gui.main.overlays.Overlay) PaymentMethod(io.bitsquare.payment.PaymentMethod) Popup(io.bitsquare.gui.main.overlays.popups.Popup) MainView(io.bitsquare.gui.main.MainView) AccountSettingsView(io.bitsquare.gui.main.account.settings.AccountSettingsView) CountryUtil(io.bitsquare.locale.CountryUtil) Coin(org.bitcoinj.core.Coin) LoggerFactory(org.slf4j.LoggerFactory) ArbitratorSelectionView(io.bitsquare.gui.main.account.content.arbitratorselection.ArbitratorSelectionView) Inject(javax.inject.Inject) PaymentAccount(io.bitsquare.payment.PaymentAccount) User(io.bitsquare.user.User) Insets(javafx.geometry.Insets) Navigation(io.bitsquare.gui.Navigation) Layout(io.bitsquare.gui.util.Layout) KeyRing(io.bitsquare.common.crypto.KeyRing) FeePolicy(io.bitsquare.btc.FeePolicy) BankUtil(io.bitsquare.locale.BankUtil) Tooltip(javafx.scene.control.Tooltip) BSFormatter(io.bitsquare.gui.util.BSFormatter) TextField(javafx.scene.control.TextField) Label(javafx.scene.control.Label) Logger(org.slf4j.Logger) Fiat(org.bitcoinj.utils.Fiat) Preferences(io.bitsquare.user.Preferences) Offer(io.bitsquare.trade.offer.Offer) List(java.util.List) FormBuilder(io.bitsquare.gui.util.FormBuilder) Tuple3(io.bitsquare.common.util.Tuple3) ImageView(javafx.scene.image.ImageView) BusyAnimation(io.bitsquare.gui.components.BusyAnimation) Optional(java.util.Optional) BSResources(io.bitsquare.locale.BSResources) Joiner(com.google.common.base.Joiner) AccountView(io.bitsquare.gui.main.account.AccountView) PaymentAccount(io.bitsquare.payment.PaymentAccount) Tooltip(javafx.scene.control.Tooltip) Offer(io.bitsquare.trade.offer.Offer) Button(javafx.scene.control.Button) Fiat(org.bitcoinj.utils.Fiat) PaymentMethod(io.bitsquare.payment.PaymentMethod) TextField(javafx.scene.control.TextField)

Example 2 with PaymentMethod

use of io.bitsquare.payment.PaymentMethod in project bitsquare by bitsquare.

the class OfferBookView method initialize.

@Override
public void initialize() {
    root.setPadding(new Insets(20, 25, 5, 25));
    offerBookTitle = addTitledGroupBg(root, gridRow, 3, "Available offers");
    currencyComboBox = addLabelComboBox(root, gridRow, "Filter by currency:", Layout.FIRST_ROW_DISTANCE).second;
    currencyComboBox.setPromptText("Select currency");
    currencyComboBox.setConverter(GUIUtil.getTradeCurrencyConverter());
    paymentMethodComboBox = addLabelComboBox(root, ++gridRow, "Filter by payment method:").second;
    paymentMethodComboBox.setPromptText("Select payment method");
    paymentMethodComboBox.setVisibleRowCount(20);
    paymentMethodComboBox.setConverter(new StringConverter<PaymentMethod>() {

        @Override
        public String toString(PaymentMethod paymentMethod) {
            String id = paymentMethod.getId();
            if (id.equals(GUIUtil.SHOW_ALL_FLAG))
                return "▶ Show all";
            else if (paymentMethod.equals(PaymentMethod.BLOCK_CHAINS))
                return "✦ " + BSResources.get(id);
            else
                return "★ " + BSResources.get(id);
        }

        @Override
        public PaymentMethod fromString(String s) {
            return null;
        }
    });
    tableView = new TableView<>();
    GridPane.setRowIndex(tableView, ++gridRow);
    GridPane.setColumnIndex(tableView, 0);
    GridPane.setColumnSpan(tableView, 2);
    GridPane.setMargin(tableView, new Insets(10, -10, -10, -10));
    GridPane.setVgrow(tableView, Priority.ALWAYS);
    root.getChildren().add(tableView);
    marketColumn = getMarketColumn();
    priceColumn = getPriceColumn();
    tableView.getColumns().add(priceColumn);
    amountColumn = getAmountColumn();
    tableView.getColumns().add(amountColumn);
    volumeColumn = getVolumeColumn();
    tableView.getColumns().add(volumeColumn);
    paymentMethodColumn = getPaymentMethodColumn();
    tableView.getColumns().add(paymentMethodColumn);
    tableView.getColumns().add(getActionColumn());
    avatarColumn = getAvatarColumn();
    tableView.getColumns().add(avatarColumn);
    tableView.getSortOrder().add(priceColumn);
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    Label placeholder = new Label("Currently there are no offers available");
    placeholder.setWrapText(true);
    tableView.setPlaceholder(placeholder);
    priceColumn.setComparator((o1, o2) -> {
        Fiat price1 = o1.getOffer().getPrice();
        Fiat price2 = o2.getOffer().getPrice();
        return price1 != null && price2 != null ? price1.compareTo(price2) : 0;
    });
    amountColumn.setComparator((o1, o2) -> o1.getOffer().getAmount().compareTo(o2.getOffer().getAmount()));
    volumeColumn.setComparator((o1, o2) -> {
        Fiat offerVolume1 = o1.getOffer().getOfferVolume();
        Fiat offerVolume2 = o2.getOffer().getOfferVolume();
        return offerVolume1 != null && offerVolume2 != null ? offerVolume1.compareTo(offerVolume2) : 0;
    });
    paymentMethodColumn.setComparator((o1, o2) -> o1.getOffer().getPaymentMethod().compareTo(o2.getOffer().getPaymentMethod()));
    avatarColumn.setComparator((o1, o2) -> o1.getOffer().getOwnerNodeAddress().hostName.compareTo(o2.getOffer().getOwnerNodeAddress().hostName));
    nrOfOffersLabel = new Label("");
    nrOfOffersLabel.setId("num-offers");
    GridPane.setHalignment(nrOfOffersLabel, HPos.LEFT);
    GridPane.setVgrow(nrOfOffersLabel, Priority.NEVER);
    GridPane.setValignment(nrOfOffersLabel, VPos.TOP);
    GridPane.setRowIndex(nrOfOffersLabel, ++gridRow);
    GridPane.setColumnIndex(nrOfOffersLabel, 0);
    GridPane.setMargin(nrOfOffersLabel, new Insets(10, 0, 0, -5));
    root.getChildren().add(nrOfOffersLabel);
    createOfferButton = addButton(root, gridRow, "");
    createOfferButton.setMinHeight(40);
    createOfferButton.setPadding(new Insets(0, 20, 0, 20));
    createOfferButton.setGraphicTextGap(10);
    GridPane.setMargin(createOfferButton, new Insets(15, 0, 0, 0));
    GridPane.setHalignment(createOfferButton, HPos.RIGHT);
    GridPane.setVgrow(createOfferButton, Priority.NEVER);
    GridPane.setValignment(createOfferButton, VPos.TOP);
    offerListListener = c -> nrOfOffersLabel.setText("No. of offers: " + model.getOfferList().size());
}
Also used : Insets(javafx.geometry.Insets) Fiat(org.bitcoinj.utils.Fiat) PaymentMethod(io.bitsquare.payment.PaymentMethod)

Example 3 with PaymentMethod

use of io.bitsquare.payment.PaymentMethod in project bitsquare by bitsquare.

the class OfferBookViewModel method getPaymentMethods.

ObservableList<PaymentMethod> getPaymentMethods() {
    ObservableList<PaymentMethod> list = FXCollections.observableArrayList(PaymentMethod.ALL_VALUES);
    list.add(0, new PaymentMethod(GUIUtil.SHOW_ALL_FLAG, 0, 0, null));
    return list;
}
Also used : PaymentMethod(io.bitsquare.payment.PaymentMethod)

Aggregations

PaymentMethod (io.bitsquare.payment.PaymentMethod)3 Insets (javafx.geometry.Insets)2 Fiat (org.bitcoinj.utils.Fiat)2 Joiner (com.google.common.base.Joiner)1 FeePolicy (io.bitsquare.btc.FeePolicy)1 KeyRing (io.bitsquare.common.crypto.KeyRing)1 Tuple3 (io.bitsquare.common.util.Tuple3)1 Navigation (io.bitsquare.gui.Navigation)1 BusyAnimation (io.bitsquare.gui.components.BusyAnimation)1 MainView (io.bitsquare.gui.main.MainView)1 AccountView (io.bitsquare.gui.main.account.AccountView)1 ArbitratorSelectionView (io.bitsquare.gui.main.account.content.arbitratorselection.ArbitratorSelectionView)1 AccountSettingsView (io.bitsquare.gui.main.account.settings.AccountSettingsView)1 Overlay (io.bitsquare.gui.main.overlays.Overlay)1 Popup (io.bitsquare.gui.main.overlays.popups.Popup)1 BSFormatter (io.bitsquare.gui.util.BSFormatter)1 FormBuilder (io.bitsquare.gui.util.FormBuilder)1 Layout (io.bitsquare.gui.util.Layout)1 BSResources (io.bitsquare.locale.BSResources)1 BankUtil (io.bitsquare.locale.BankUtil)1