<commit_before>import React from "react";

import counterpart from "counterpart";
import Translate from "react-translate-component";
import {connect} from "alt-react";
import {
    Table,
    Button,
    Radio,
    Modal,
    Checkbox,
    Collapse,
    Tooltip,
    Icon
} from "bitshares-ui-style-guide";
import SettingsStore from "stores/SettingsStore";
import {availableGateways, availableBridges} from "common/gateways";
import {getFaucet, allowedGateway} from "../../branding";
import SettingsActions from "../../actions/SettingsActions";
import {updateGatewayBackers} from "common/gatewayUtils";
import ServiceProviderExplanation from "./ServiceProviderExplanation";

class GatewaySelectorModal extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            showIntroduction: true,
            onChainDisabled: {}
        };
    }

    onSubmit() {
        this.onClose();
    }

    onNone() {
        SettingsActions.changeSetting({
            setting: "filteredServiceProviders",
            value: []
        });
        this.onClose();
    }

    next() {
        this.setState({showIntroduction: false});
    }

    onClose() {
        if (!this.props.hasSeenExternalServices) {
            SettingsActions.changeViewSetting({
                hasSeenExternalServices: true
            });
        }
        updateGatewayBackers();
        this.props.hideModal();
    }

    _getRowHeaders() {
        const columns = [
            {
                key: "name",
                title: counterpart.translate(
                    "external_service_provider.selector.name"
                ),
                render: row => {
                    if (!!this.state.onChainDisabled[row.key]) {
                        return (
                            <Tooltip
                                title={
                                    "This gateway has been deactivated. This can be due to several reasons. If you are the operator of this gateway, please contact us."
                                }
                            >
                                <span style={{whiteSpace: "nowrap"}}>
                                    {row.name}
                                    <Icon
                                        style={{
                                            marginLeft: "0.5rem"
                                        }}
                                        type="question-circle"
                                    />
                                </span>
                            </Tooltip>
                        );
                    }
                    return row.name;
                }
            },
            {
                key: "type",
                title: counterpart.translate(
                    "external_service_provider.selector.type"
                ),
                align: "left",
                render: row => {
                    if (row.type == "bridge") {
                        return counterpart.translate(
                            "external_service_provider.bridge.short"
                        );
                    } else {
                        return (
                            <div>
                                <span>
                                    {counterpart.translate(
                                        "external_service_provider.gateway.short"
                                    )}
                                </span>
                                <br />
                                <span>
                                    {counterpart.translate(
                                        "external_service_provider.gateway.prefix"
                                    )}
                                    {": " + row.prefix}
                                </span>
                            </div>
                        );
                    }

                    return (
                        <div>
                            <span>
                                {counterpart.translate(
                                    "external_service_provider." +
                                        row.type +
                                        ".short"
                                )}
                            </span>
                            <br />
                            <span>{row.prefix}</span>
                        </div>
                    );
                }
            },
            {
                key: "landing",
                title: counterpart.translate(
                    "external_service_provider.selector.landing"
                ),
                align: "left",
                render: row => {
                    if (!row.landing) return "-";
                    return (
                        <a
                            target="_blank"
                            className="external-link"
                            rel="noopener noreferrer"
                            href={row.landing}
                        >
                            External Link
                        </a>
                    );
                }
            },
            {
                key: "wallet",
                title: counterpart.translate(
                    "external_service_provider.selector.wallet"
                ),
                align: "left",
                render: row => {
                    if (!row.wallet) return "-";
                    return (
                        <a
                            target="_blank"
                            className="external-link"
                            rel="noopener noreferrer"
                            href={row.wallet}
                        >
                            External Link
                        </a>
                    );
                }
            }
        ];
        return columns;
    }

    _getReferrerLink() {
        return !!getFaucet().referrer ? "r=" + getFaucet().referrer : "";
    }

    async _checkOnChainConfig() {
        const all = this._getRows();
        let onChainDisabled = {};
        for (let i = 0; i < all.length; i++) {
            if (!(await all[i].isEnabled({onlyOnChainConfig: true})))
                onChainDisabled[all[i].key] = true;
        }
        this.setState({onChainDisabled});
    }

    _getEnabledRowKeys() {
        return this._getRows().map(
            item =>
                this.state.onChainDisabled[item.key] ? undefined : item.key
        );
    }

    _getRows() {
        const gateways = Object.values(availableGateways).map(item => {
            return {
                key: item.id,
                type: "gateway",
                name: item.name,
                prefix: item.id,
                landing: !!item.landing ? item.landing : undefined,
                wallet: !!item.wallet
                    ? item.wallet + this._getReferrerLink()
                    : undefined,
                isEnabled: item.isEnabled<commit_msg>add ?<commit_after>import React from "react";

import counterpart from "counterpart";
import Translate from "react-translate-component";
import {connect} from "alt-react";
import {
    Table,
    Button,
    Radio,
    Modal,
    Checkbox,
    Collapse,
    Tooltip,
    Icon
} from "bitshares-ui-style-guide";
import SettingsStore from "stores/SettingsStore";
import {availableGateways, availableBridges} from "common/gateways";
import {getFaucet, allowedGateway} from "../../branding";
import SettingsActions from "../../actions/SettingsActions";
import {updateGatewayBackers} from "common/gatewayUtils";
import ServiceProviderExplanation from "./ServiceProviderExplanation";

class GatewaySelectorModal extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            showIntroduction: true,
            onChainDisabled: {}
        };
    }

    onSubmit() {
        this.onClose();
    }

    onNone() {
        SettingsActions.changeSetting({
            setting: "filteredServiceProviders",
            value: []
        });
        this.onClose();
    }

    next() {
        this.setState({showIntroduction: false});
    }

    onClose() {
        if (!this.props.hasSeenExternalServices) {
            SettingsActions.changeViewSetting({
                hasSeenExternalServices: true
            });
        }
        updateGatewayBackers();
        this.props.hideModal();
    }

    _getRowHeaders() {
        const columns = [
            {
                key: "name",
                title: counterpart.translate(
                    "external_service_provider.selector.name"
                ),
                render: row => {
                    if (!!this.state.onChainDisabled[row.key]) {
                        return (
                            <Tooltip
                                title={
                                    "This gateway has been deactivated. This can be due to several reasons. If you are the operator of this gateway, please contact us."
                                }
                            >
                                <span style={{whiteSpace: "nowrap"}}>
                                    {row.name}
                                    <Icon
                                        style={{
                                            marginLeft: "0.5rem"
                                        }}
                                        type="question-circle"
                                    />
                                </span>
                            </Tooltip>
                        );
                    }
                    return row.name;
                }
            },
            {
                key: "type",
                title: counterpart.translate(
                    "external_service_provider.selector.type"
                ),
                align: "left",
                render: row => {
                    if (row.type == "bridge") {
                        return counterpart.translate(
                            "external_service_provider.bridge.short"
                        );
                    } else {
                        return (
                            <div>
                                <span>
                                    {counterpart.translate(
                                        "external_service_provider.gateway.short"
                                    )}
                                </span>
                                <br />
                                <span>
                                    {counterpart.translate(
                                        "external_service_provider.gateway.prefix"
                                    )}
                                    {": " + row.prefix}
                                </span>
                            </div>
                        );
                    }

                    return (
                        <div>
                            <span>
                                {counterpart.translate(
                                    "external_service_provider." +
                                        row.type +
                                        ".short"
                                )}
                            </span>
                            <br />
                            <span>{row.prefix}</span>
                        </div>
                    );
                }
            },
            {
                key: "landing",
                title: counterpart.translate(
                    "external_service_provider.selector.landing"
                ),
                align: "left",
                render: row => {
                    if (!row.landing) return "-";
                    return (
                        <a
                            target="_blank"
                            className="external-link"
                            rel="noopener noreferrer"
                            href={row.landing}
                        >
                            External Link
                        </a>
                    );
                }
            },
            {
                key: "wallet",
                title: counterpart.translate(
                    "external_service_provider.selector.wallet"
                ),
                align: "left",
                render: row => {
                    if (!row.wallet) return "-";
                    return (
                        <a
                            target="_blank"
                            className="external-link"
                            rel="noopener noreferrer"
                            href={row.wallet}
                        >
                            External Link
                        </a>
                    );
                }
            }
        ];
        return columns;
    }

    _getReferrerLink() {
        return !!getFaucet().referrer ? "?r=" + getFaucet().referrer : "";
    }

    async _checkOnChainConfig() {
        const all = this._getRows();
        let onChainDisabled = {};
        for (let i = 0; i < all.length; i++) {
            if (!(await all[i].isEnabled({onlyOnChainConfig: true})))
                onChainDisabled[all[i].key] = true;
        }
        this.setState({onChainDisabled});
    }

    _getEnabledRowKeys() {
        return this._getRows().map(
            item =>
                this.state.onChainDisabled[item.key] ? undefined : item.key
        );
    }

    _getRows() {
        const gateways = Object.values(availableGateways).map(item => {
            return {
                key: item.id,
                type: "gateway",
                name: item.name,
                prefix: item.id,
                landing: !!item.landing ? item.landing : undefined,
                wallet: !!item.wallet
                    ? item.wallet + this._getReferrerLink()
                    : undefined,
                isEnabled: item.isEnabled
{'fraction_non_alphanumeric': 0.09012723008031844, 'fraction_numerical': 0.00042646954296680646, 'mean_word_length': 0.8089483157624068, 'pattern_counts': {'":': 2, '<': 51, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6264079', 'n_tokens_mistral': 3137, 'n_tokens_neox': 2936, 'n_words': 552}