Search in sources :

Example 1 with PaymentAccountFilter

use of bisq.core.filter.PaymentAccountFilter in project bisq-desktop by bisq-network.

the class FilterWindow method addContent.

private void addContent() {
    InputTextField keyInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("shared.unlock"), 10).second;
    if (useDevPrivilegeKeys)
        keyInputTextField.setText(DevEnv.DEV_PRIVILEGE_PRIV_KEY);
    InputTextField offerIdsInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.offers")).second;
    InputTextField nodesInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.onions")).second;
    // Do not translate
    nodesInputTextField.setPromptText("E.g. zqnzx6o3nifef5df.onion:9999");
    InputTextField paymentAccountFilterInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.accounts")).second;
    GridPane.setHalignment(paymentAccountFilterInputTextField, HPos.RIGHT);
    // Do not translate
    paymentAccountFilterInputTextField.setPromptText("E.g. PERFECT_MONEY|getAccountNr|12345");
    InputTextField bannedCurrenciesInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.bannedCurrencies")).second;
    InputTextField bannedPaymentMethodsInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.bannedPaymentMethods")).second;
    // Do not translate
    bannedPaymentMethodsInputTextField.setPromptText("E.g. PERFECT_MONEY");
    InputTextField arbitratorsInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.arbitrators")).second;
    InputTextField seedNodesInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.seedNode")).second;
    InputTextField priceRelayNodesInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.priceRelayNode")).second;
    InputTextField btcNodesInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.btcNode")).second;
    CheckBox preventPublicBtcNetworkCheckBox = addLabelCheckBox(gridPane, ++rowIndex, Res.get("filterWindow.preventPublicBtcNetwork")).second;
    final Filter filter = filterManager.getDevelopersFilter();
    if (filter != null) {
        offerIdsInputTextField.setText(filter.getBannedOfferIds().stream().collect(Collectors.joining(", ")));
        nodesInputTextField.setText(filter.getBannedNodeAddress().stream().collect(Collectors.joining(", ")));
        if (filter.getBannedPaymentAccounts() != null) {
            StringBuilder sb = new StringBuilder();
            filter.getBannedPaymentAccounts().stream().forEach(e -> {
                if (e != null && e.getPaymentMethodId() != null) {
                    sb.append(e.getPaymentMethodId()).append("|").append(e.getGetMethodName()).append("|").append(e.getValue()).append(", ");
                }
            });
            paymentAccountFilterInputTextField.setText(sb.toString());
        }
        if (filter.getBannedCurrencies() != null)
            bannedCurrenciesInputTextField.setText(filter.getBannedCurrencies().stream().collect(Collectors.joining(", ")));
        if (filter.getBannedPaymentMethods() != null)
            bannedPaymentMethodsInputTextField.setText(filter.getBannedPaymentMethods().stream().collect(Collectors.joining(", ")));
        if (filter.getArbitrators() != null)
            arbitratorsInputTextField.setText(filter.getArbitrators().stream().collect(Collectors.joining(", ")));
        if (filter.getSeedNodes() != null)
            seedNodesInputTextField.setText(filter.getSeedNodes().stream().collect(Collectors.joining(", ")));
        if (filter.getPriceRelayNodes() != null)
            priceRelayNodesInputTextField.setText(filter.getPriceRelayNodes().stream().collect(Collectors.joining(", ")));
        if (filter.getBtcNodes() != null)
            btcNodesInputTextField.setText(filter.getBtcNodes().stream().collect(Collectors.joining(", ")));
        preventPublicBtcNetworkCheckBox.setSelected(filter.isPreventPublicBtcNetwork());
    }
    Button sendButton = new AutoTooltipButton(Res.get("filterWindow.add"));
    sendButton.setOnAction(e -> {
        List<String> offerIds = new ArrayList<>();
        List<String> nodes = new ArrayList<>();
        List<PaymentAccountFilter> paymentAccountFilters = new ArrayList<>();
        List<String> bannedCurrencies = new ArrayList<>();
        List<String> bannedPaymentMethods = new ArrayList<>();
        List<String> arbitrators = new ArrayList<>();
        List<String> seedNodes = new ArrayList<>();
        List<String> priceRelayNodes = new ArrayList<>();
        List<String> btcNodes = new ArrayList<>();
        if (!offerIdsInputTextField.getText().isEmpty()) {
            offerIds = new ArrayList<>(Arrays.asList(StringUtils.deleteWhitespace(offerIdsInputTextField.getText()).split(",")));
        }
        if (!nodesInputTextField.getText().isEmpty()) {
            nodes = new ArrayList<>(Arrays.asList(StringUtils.deleteWhitespace(nodesInputTextField.getText()).replace(":9999", "").replace(".onion", "").split(",")));
        }
        if (!paymentAccountFilterInputTextField.getText().isEmpty()) {
            paymentAccountFilters = new ArrayList<>(Arrays.asList(paymentAccountFilterInputTextField.getText().replace(", ", ",").split(",")).stream().map(item -> {
                String[] list = item.split("\\|");
                if (list.length == 3)
                    return new PaymentAccountFilter(list[0], list[1], list[2]);
                else
                    return new PaymentAccountFilter("", "", "");
            }).collect(Collectors.toList()));
        }
        if (!bannedCurrenciesInputTextField.getText().isEmpty()) {
            bannedCurrencies = new ArrayList<>(Arrays.asList(StringUtils.deleteWhitespace(bannedCurrenciesInputTextField.getText()).split(",")));
        }
        if (!bannedPaymentMethodsInputTextField.getText().isEmpty()) {
            bannedPaymentMethods = new ArrayList<>(Arrays.asList(StringUtils.deleteWhitespace(bannedPaymentMethodsInputTextField.getText()).split(",")));
        }
        if (!arbitratorsInputTextField.getText().isEmpty()) {
            arbitrators = new ArrayList<>(Arrays.asList(StringUtils.deleteWhitespace(arbitratorsInputTextField.getText()).replace(":9999", "").replace(".onion", "").split(",")));
        }
        if (!seedNodesInputTextField.getText().isEmpty()) {
            seedNodes = new ArrayList<>(Arrays.asList(StringUtils.deleteWhitespace(seedNodesInputTextField.getText()).replace(":9999", "").replace(".onion", "").split(",")));
        }
        if (!priceRelayNodesInputTextField.getText().isEmpty()) {
            priceRelayNodes = new ArrayList<>(Arrays.asList(StringUtils.deleteWhitespace(priceRelayNodesInputTextField.getText()).replace(":9999", "").replace(".onion", "").split(",")));
        }
        if (!btcNodesInputTextField.getText().isEmpty()) {
            btcNodes = new ArrayList<>(Arrays.asList(StringUtils.deleteWhitespace(btcNodesInputTextField.getText()).split(",")));
        }
        if (sendFilterMessageHandler.handle(new Filter(offerIds, nodes, paymentAccountFilters, bannedCurrencies, bannedPaymentMethods, arbitrators, seedNodes, priceRelayNodes, preventPublicBtcNetworkCheckBox.isSelected(), btcNodes), keyInputTextField.getText()))
            hide();
        else
            new Popup<>().warning(Res.get("shared.invalidKey")).width(300).onClose(this::blurAgain).show();
    });
    Button removeFilterMessageButton = new AutoTooltipButton(Res.get("filterWindow.remove"));
    removeFilterMessageButton.setOnAction(e -> {
        if (keyInputTextField.getText().length() > 0) {
            if (removeFilterMessageHandler.handle(keyInputTextField.getText()))
                hide();
            else
                new Popup<>().warning(Res.get("shared.invalidKey")).width(300).onClose(this::blurAgain).show();
        }
    });
    closeButton = new AutoTooltipButton(Res.get("shared.close"));
    closeButton.setOnAction(e -> {
        hide();
        closeHandlerOptional.ifPresent(Runnable::run);
    });
    HBox hBox = new HBox();
    hBox.setSpacing(10);
    GridPane.setRowIndex(hBox, ++rowIndex);
    GridPane.setColumnIndex(hBox, 1);
    hBox.getChildren().addAll(sendButton, removeFilterMessageButton, closeButton);
    gridPane.getChildren().add(hBox);
    GridPane.setMargin(hBox, new Insets(10, 0, 0, 0));
}
Also used : Button(javafx.scene.control.Button) Scene(javafx.scene.Scene) KeyCode(javafx.scene.input.KeyCode) HBox(javafx.scene.layout.HBox) HPos(javafx.geometry.HPos) Popup(bisq.desktop.main.overlays.popups.Popup) Arrays(java.util.Arrays) PaymentAccountFilter(bisq.core.filter.PaymentAccountFilter) FilterManager(bisq.core.filter.FilterManager) CheckBox(javafx.scene.control.CheckBox) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) FormBuilder.addLabelInputTextField(bisq.desktop.util.FormBuilder.addLabelInputTextField) ArrayList(java.util.ArrayList) List(java.util.List) Insets(javafx.geometry.Insets) InputTextField(bisq.desktop.components.InputTextField) DevEnv(bisq.common.app.DevEnv) Res(bisq.core.locale.Res) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) Overlay(bisq.desktop.main.overlays.Overlay) Filter(bisq.core.filter.Filter) FormBuilder.addLabelCheckBox(bisq.desktop.util.FormBuilder.addLabelCheckBox) GridPane(javafx.scene.layout.GridPane) HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) FormBuilder.addLabelInputTextField(bisq.desktop.util.FormBuilder.addLabelInputTextField) InputTextField(bisq.desktop.components.InputTextField) ArrayList(java.util.ArrayList) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) PaymentAccountFilter(bisq.core.filter.PaymentAccountFilter) Filter(bisq.core.filter.Filter) Button(javafx.scene.control.Button) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) CheckBox(javafx.scene.control.CheckBox) FormBuilder.addLabelCheckBox(bisq.desktop.util.FormBuilder.addLabelCheckBox) PaymentAccountFilter(bisq.core.filter.PaymentAccountFilter)

Example 2 with PaymentAccountFilter

use of bisq.core.filter.PaymentAccountFilter in project bisq-core by bisq-network.

the class CheckIfPeerIsBanned method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        final NodeAddress nodeAddress = processModel.getTempTradingPeerNodeAddress();
        PaymentAccountPayload paymentAccountPayload = checkNotNull(processModel.getTradingPeer().getPaymentAccountPayload());
        final PaymentAccountFilter[] appliedPaymentAccountFilter = new PaymentAccountFilter[1];
        if (nodeAddress != null && processModel.getFilterManager().isNodeAddressBanned(nodeAddress)) {
            failed("Other trader is banned by his node address.\n" + "tradingPeerNodeAddress=" + nodeAddress);
        } else if (processModel.getFilterManager().isOfferIdBanned(trade.getId())) {
            failed("Offer ID is banned.\n" + "Offer ID=" + trade.getId());
        } else if (processModel.getFilterManager().isCurrencyBanned(trade.getOffer().getCurrencyCode())) {
            failed("Currency is banned.\n" + "Currency code=" + trade.getOffer().getCurrencyCode());
        } else if (processModel.getFilterManager().isPaymentMethodBanned(trade.getOffer().getPaymentMethod())) {
            failed("Payment method is banned.\n" + "Payment method=" + trade.getOffer().getPaymentMethod().getId());
        } else if (processModel.getFilterManager().isPeersPaymentAccountDataAreBanned(paymentAccountPayload, appliedPaymentAccountFilter)) {
            failed("Other trader is banned by his trading account data.\n" + "paymentAccountPayload=" + paymentAccountPayload.getPaymentDetails() + "\n" + "banFilter=" + appliedPaymentAccountFilter[0].toString());
        } else {
            complete();
        }
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : PaymentAccountPayload(bisq.core.payment.payload.PaymentAccountPayload) PaymentAccountFilter(bisq.core.filter.PaymentAccountFilter) NodeAddress(bisq.network.p2p.NodeAddress)

Aggregations

PaymentAccountFilter (bisq.core.filter.PaymentAccountFilter)2 DevEnv (bisq.common.app.DevEnv)1 Filter (bisq.core.filter.Filter)1 FilterManager (bisq.core.filter.FilterManager)1 Res (bisq.core.locale.Res)1 PaymentAccountPayload (bisq.core.payment.payload.PaymentAccountPayload)1 AutoTooltipButton (bisq.desktop.components.AutoTooltipButton)1 InputTextField (bisq.desktop.components.InputTextField)1 Overlay (bisq.desktop.main.overlays.Overlay)1 Popup (bisq.desktop.main.overlays.popups.Popup)1 FormBuilder.addLabelCheckBox (bisq.desktop.util.FormBuilder.addLabelCheckBox)1 FormBuilder.addLabelInputTextField (bisq.desktop.util.FormBuilder.addLabelInputTextField)1 NodeAddress (bisq.network.p2p.NodeAddress)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 HPos (javafx.geometry.HPos)1 Insets (javafx.geometry.Insets)1 Scene (javafx.scene.Scene)1