Search in sources :

Example 16 with PaymentAccount

use of bisq.core.payment.PaymentAccount in project bisq-desktop by bisq-network.

the class GUIUtil method getPaymentAccountsComboBoxStringConverter.

public static StringConverter<PaymentAccount> getPaymentAccountsComboBoxStringConverter() {
    return new StringConverter<PaymentAccount>() {

        @Override
        public String toString(PaymentAccount paymentAccount) {
            if (paymentAccount.hasMultipleCurrencies()) {
                return paymentAccount.getAccountName() + " (" + Res.get(paymentAccount.getPaymentMethod().getId()) + ")";
            } else {
                TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
                String prefix = singleTradeCurrency != null ? singleTradeCurrency.getCode() + ", " : "";
                return paymentAccount.getAccountName() + " (" + prefix + Res.get(paymentAccount.getPaymentMethod().getId()) + ")";
            }
        }

        @Override
        public PaymentAccount fromString(String s) {
            return null;
        }
    };
}
Also used : TradeCurrency(bisq.core.locale.TradeCurrency) PaymentAccount(bisq.core.payment.PaymentAccount) StringConverter(javafx.util.StringConverter)

Example 17 with PaymentAccount

use of bisq.core.payment.PaymentAccount in project bisq-desktop by bisq-network.

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, Res.get("shared.Offer"));
    String fiatDirectionInfo = ":";
    String btcDirectionInfo = ":";
    OfferPayload.Direction direction = offer.getDirection();
    String currencyCode = offer.getCurrencyCode();
    String offerTypeLabel = Res.getWithCol("shared.offerType");
    String toReceive = " " + Res.get("shared.toReceive");
    String toSpend = " " + Res.get("shared.toSpend");
    double firstRowDistance = Layout.FIRST_ROW_DISTANCE;
    if (takeOfferHandlerOptional.isPresent()) {
        addLabelTextField(gridPane, rowIndex, offerTypeLabel, formatter.getDirectionForTakeOffer(direction, currencyCode), firstRowDistance);
        fiatDirectionInfo = direction == OfferPayload.Direction.BUY ? toReceive : toSpend;
        btcDirectionInfo = direction == OfferPayload.Direction.SELL ? toReceive : toSpend;
    } else if (placeOfferHandlerOptional.isPresent()) {
        addLabelTextField(gridPane, rowIndex, offerTypeLabel, formatter.getOfferDirectionForCreateOffer(direction, currencyCode), firstRowDistance);
        fiatDirectionInfo = direction == OfferPayload.Direction.SELL ? toReceive : toSpend;
        btcDirectionInfo = direction == OfferPayload.Direction.BUY ? toReceive : toSpend;
    } else {
        addLabelTextField(gridPane, rowIndex, offerTypeLabel, formatter.getDirectionBothSides(direction, currencyCode), firstRowDistance);
    }
    String btcAmount = Res.get("shared.btcAmount");
    if (takeOfferHandlerOptional.isPresent()) {
        addLabelTextField(gridPane, ++rowIndex, btcAmount + btcDirectionInfo, formatter.formatCoinWithCode(tradeAmount));
        addLabelTextField(gridPane, ++rowIndex, formatter.formatVolumeLabel(currencyCode) + fiatDirectionInfo, formatter.formatVolumeWithCode(offer.getVolumeByAmount(tradeAmount)));
    } else {
        addLabelTextField(gridPane, ++rowIndex, btcAmount + btcDirectionInfo, formatter.formatCoinWithCode(offer.getAmount()));
        addLabelTextField(gridPane, ++rowIndex, Res.get("offerDetailsWindow.minBtcAmount"), formatter.formatCoinWithCode(offer.getMinAmount()));
        String volume = formatter.formatVolumeWithCode(offer.getVolume());
        String minVolume = "";
        if (offer.getVolume() != null && offer.getMinVolume() != null && !offer.getVolume().equals(offer.getMinVolume()))
            minVolume = " " + Res.get("offerDetailsWindow.min", formatter.formatVolumeWithCode(offer.getMinVolume()));
        addLabelTextField(gridPane, ++rowIndex, formatter.formatVolumeLabel(currencyCode) + fiatDirectionInfo, volume + minVolume);
    }
    String priceLabel = Res.getWithCol("shared.price");
    if (takeOfferHandlerOptional.isPresent()) {
        addLabelTextField(gridPane, ++rowIndex, priceLabel, formatter.formatPrice(tradePrice));
    } else {
        Price price = offer.getPrice();
        if (offer.isUseMarketBasedPrice()) {
            addLabelTextField(gridPane, ++rowIndex, priceLabel, formatter.formatPrice(price) + " " + Res.get("offerDetailsWindow.distance", formatter.formatPercentagePrice(offer.getMarketPriceMargin())));
        } else {
            addLabelTextField(gridPane, ++rowIndex, priceLabel, formatter.formatPrice(price));
        }
    }
    final PaymentMethod paymentMethod = offer.getPaymentMethod();
    final String makerPaymentAccountId = offer.getMakerPaymentAccountId();
    final PaymentAccount paymentAccount = user.getPaymentAccount(makerPaymentAccountId);
    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) && makerPaymentAccountId != null && paymentAccount != null) {
        addLabelTextField(gridPane, ++rowIndex, Res.get("offerDetailsWindow.myTradingAccount"), paymentAccount.getAccountName());
    } else {
        final String method = Res.get(paymentMethod.getId());
        String paymentMethodLabel = Res.getWithCol("shared.paymentMethod");
        if (isNationalBanks || isSpecificBanks || isSepa) {
            String methodWithBankId = method + bankId;
            if (BankUtil.isBankIdRequired(offer.getCountryCode()))
                addLabelTextField(gridPane, ++rowIndex, paymentMethodLabel + " " + Res.get("offerDetailsWindow.offererBankId"), methodWithBankId);
            else if (BankUtil.isBankNameRequired(offer.getCountryCode()))
                addLabelTextField(gridPane, ++rowIndex, paymentMethodLabel + " " + Res.get("offerDetailsWindow.offerersBankName"), methodWithBankId);
        } else {
            addLabelTextField(gridPane, ++rowIndex, paymentMethodLabel, method);
        }
    }
    if (showAcceptedBanks) {
        if (paymentMethod.equals(PaymentMethod.SAME_BANK)) {
            addLabelTextField(gridPane, ++rowIndex, Res.get("offerDetailsWindow.bankId"), acceptedBanks.get(0));
        } else if (isSpecificBanks) {
            String value = Joiner.on(", ").join(acceptedBanks);
            String acceptedBanksLabel = Res.getWithCol("shared.acceptedBanks");
            Tooltip tooltip = new Tooltip(acceptedBanksLabel + " " + value);
            TextField acceptedBanksTextField = addLabelTextField(gridPane, ++rowIndex, acceptedBanksLabel, value).second;
            acceptedBanksTextField.setMouseTransparent(false);
            acceptedBanksTextField.setTooltip(tooltip);
        }
    }
    if (showAcceptedCountryCodes) {
        String countries;
        Tooltip tooltip = null;
        if (CountryUtil.containsAllSepaEuroCountries(acceptedCountryCodes)) {
            countries = Res.getWithCol("shared.allEuroCountries");
        } 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, Res.getWithCol("shared.acceptedTakerCountries"), 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, Res.get("shared.details"), Layout.GROUP_DISTANCE);
    addLabelTextFieldWithCopyIcon(gridPane, rowIndex, Res.getWithCol("shared.offerId"), offer.getId(), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("offerDetailsWindow.makersOnion"), offer.getMakerNodeAddress().getFullAddress());
    addLabelTextField(gridPane, ++rowIndex, Res.get("offerDetailsWindow.creationDate"), formatter.formatDateTime(offer.getDate()));
    String value = Res.getWithColAndCap("shared.buyer") + " " + formatter.formatCoinWithCode(offer.getBuyerSecurityDeposit()) + " / " + Res.getWithColAndCap("shared.seller") + " " + formatter.formatCoinWithCode(offer.getSellerSecurityDeposit());
    addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.securityDeposit"), value);
    if (paymentMethodCountryCode != null)
        addLabelTextField(gridPane, ++rowIndex, Res.get("offerDetailsWindow.countryBank"), CountryUtil.getNameAndCode(paymentMethodCountryCode));
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("offerDetailsWindow.acceptedArbitrators"), formatter.arbitratorAddressesToString(offer.getArbitratorNodeAddresses()));
    if (offer.getOfferFeePaymentTxId() != null)
        addLabelTxIdTextField(gridPane, ++rowIndex, Res.get("shared.makerFeeTxId"), offer.getOfferFeePaymentTxId());
    if (placeOfferHandlerOptional.isPresent()) {
        addTitledGroupBg(gridPane, ++rowIndex, 1, Res.get("offerDetailsWindow.commitment"), Layout.GROUP_DISTANCE);
        addLabelTextField(gridPane, rowIndex, Res.get("offerDetailsWindow.agree"), Res.get("createOffer.tac"), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
        addConfirmAndCancelButtons(true);
    } else if (takeOfferHandlerOptional.isPresent()) {
        addTitledGroupBg(gridPane, ++rowIndex, 1, Res.get("shared.contract"), Layout.GROUP_DISTANCE);
        addLabelTextField(gridPane, rowIndex, Res.get("offerDetailsWindow.tac"), Res.get("takeOffer.tac"), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
        addConfirmAndCancelButtons(false);
    } else {
        Button closeButton = addButtonAfterGroup(gridPane, ++rowIndex, Res.get("shared.close"));
        closeButton.setOnAction(e -> {
            closeHandlerOptional.ifPresent(Runnable::run);
            hide();
        });
    }
}
Also used : Button(javafx.scene.control.Button) BusyAnimation(bisq.desktop.components.BusyAnimation) ArbitratorSelectionView(bisq.desktop.main.account.content.arbitratorselection.ArbitratorSelectionView) Coin(org.bitcoinj.core.Coin) LoggerFactory(org.slf4j.LoggerFactory) Layout(bisq.desktop.util.Layout) BSFormatter(bisq.desktop.util.BSFormatter) User(bisq.core.user.User) Inject(javax.inject.Inject) OfferPayload(bisq.core.offer.OfferPayload) Tuple3(bisq.common.util.Tuple3) Insets(javafx.geometry.Insets) Res(bisq.core.locale.Res) Overlay(bisq.desktop.main.overlays.Overlay) Tooltip(javafx.scene.control.Tooltip) AccountView(bisq.desktop.main.account.AccountView) Navigation(bisq.desktop.Navigation) Popup(bisq.desktop.main.overlays.popups.Popup) Offer(bisq.core.offer.Offer) TextField(javafx.scene.control.TextField) Label(javafx.scene.control.Label) Logger(org.slf4j.Logger) FormBuilder(bisq.desktop.util.FormBuilder) PaymentMethod(bisq.core.payment.payload.PaymentMethod) MainView(bisq.desktop.main.MainView) PaymentAccount(bisq.core.payment.PaymentAccount) List(java.util.List) ImageView(javafx.scene.image.ImageView) CountryUtil(bisq.core.locale.CountryUtil) Price(bisq.core.monetary.Price) AccountSettingsView(bisq.desktop.main.account.settings.AccountSettingsView) Optional(java.util.Optional) BankUtil(bisq.core.locale.BankUtil) KeyRing(bisq.common.crypto.KeyRing) Joiner(com.google.common.base.Joiner) PaymentAccount(bisq.core.payment.PaymentAccount) Tooltip(javafx.scene.control.Tooltip) Price(bisq.core.monetary.Price) Button(javafx.scene.control.Button) PaymentMethod(bisq.core.payment.payload.PaymentMethod) TextField(javafx.scene.control.TextField) OfferPayload(bisq.core.offer.OfferPayload)

Aggregations

PaymentAccount (bisq.core.payment.PaymentAccount)17 CryptoCurrency (bisq.core.locale.CryptoCurrency)7 TradeCurrency (bisq.core.locale.TradeCurrency)7 PaymentMethod (bisq.core.payment.payload.PaymentMethod)7 AccountAgeWitnessService (bisq.core.payment.AccountAgeWitnessService)6 Res (bisq.core.locale.Res)5 User (bisq.core.user.User)5 BSFormatter (bisq.desktop.util.BSFormatter)5 UserThread (bisq.common.UserThread)4 Tuple3 (bisq.common.util.Tuple3)4 CryptoCurrencyAccount (bisq.core.payment.CryptoCurrencyAccount)4 InputValidator (bisq.core.util.validation.InputValidator)4 Popup (bisq.desktop.main.overlays.popups.Popup)4 Tuple2 (bisq.common.util.Tuple2)3 FiatCurrency (bisq.core.locale.FiatCurrency)3 CountryBasedPaymentAccount (bisq.core.payment.CountryBasedPaymentAccount)3 PaymentAccountFactory (bisq.core.payment.PaymentAccountFactory)3 ActivatableViewAndModel (bisq.desktop.common.view.ActivatableViewAndModel)3 FxmlView (bisq.desktop.common.view.FxmlView)3 AutoTooltipButton (bisq.desktop.components.AutoTooltipButton)3