<commit_before>// Send command/response

function calculateFee(n, tx) {
    var estimatedGas = 21000;
    if (tx !== null) {
        try {
            estimatedGas = web3.eth.estimateGas(tx);
        } catch (err) {

        }
    }

    var gasMultiplicator = Math.pow(1.4, n).toFixed(3);
    var gasPrice = 211000000000;
    try {
        gasPrice = web3.eth.gasPrice;
    } catch (err) {

    }
    var weiFee = gasPrice * gasMultiplicator * estimatedGas;
    // force fee in eth to be of BigNumber type
    var ethFee = web3.toBigNumber(web3.fromWei(weiFee, "ether"));
    // always display 7 decimal places
    return ethFee.toFixed(7);
}

function calculateGasPrice(n) {
    var gasMultiplicator = Math.pow(1.4, n).toFixed(3);
    var gasPrice = 211000000000;
    try {
        gasPrice = web3.eth.gasPrice;
    } catch (err) {

    }

    return gasPrice * gasMultiplicator;
}

status.defineSubscription(
    "calculatedFee",
    {value: ["sliderValue"], tx: ["transaction"]},
    function (params) {
        return calculateFee(params.value, params.tx);
    }
);

function getFeeExplanation(n) {
    return I18n.t('send_explanation') + I18n.t('send_explanation_' + (n + 2));
}

status.defineSubscription(
    "feeExplanation",
    {value: ["sliderValue"]},
    function(params) {
        return getFeeExplanation(params.value);
    }
);

function amountParameterBox(groupChat, params, context) {
    if (!params["bot-db"]) {
        params["bot-db"] = {};
    }

    var contactAddress;
    if (groupChat) {
        if (params["bot-db"]["public"] && params["bot-db"]["public"]["recipient"]) {
            contactAddress = params["bot-db"]["public"]["recipient"]["address"];
        } else {
            contactAddress = null;
        }
    } else {
        contactAddress = context.to;
    }
    
    var txData;
    var amount;
    var amountIndex = groupChat ? 1 : 0;
    
    try {
        amount = params.args[amountIndex];
        txData = {
            to: contactAddress,
            value: web3.toWei(amount) || 0
        };
    } catch (err) {
        amount = null;
        txData = {
            to: contactAddress,
            value: 0
        };
    } 

    var sliderValue = params["bot-db"]["sliderValue"] || 0;

    try {

        status.setDefaultDb({
            transaction: txData,
            calculatedFee: calculateFee(sliderValue, txData),
            feeExplanation: getFeeExplanation(sliderValue),
            sliderValue: sliderValue
        });

    } catch (err) {

        status.setDefaultDb({
            transaction: txData,
            calculatedFee: "0",
            feeExplanation: "",
            sliderValue: sliderValue
        });
    }
    
    return {
        title: I18n.t('send_title'),
        showBack: true,
        markup: status.components.scrollView(
            {
                keyboardShouldPersistTaps: "always"
            },
            [status.components.view(
                {
                    flex: 1
                },
                [
                    status.components.text(
                        {
                            style: {
                                fontSize: 14,
                                color: "rgb(147, 155, 161)",
                                paddingTop: 12,<commit_msg>[fixes #2908] 0.00 ETH is shown instead of specified amount (with comma) on Send transaction screen after /send command (#3122)<commit_after>// Send command/response

function calculateFee(n, tx) {
    var estimatedGas = 21000;
    if (tx !== null) {
        try {
            estimatedGas = web3.eth.estimateGas(tx);
        } catch (err) {

        }
    }

    var gasMultiplicator = Math.pow(1.4, n).toFixed(3);
    var gasPrice = 211000000000;
    try {
        gasPrice = web3.eth.gasPrice;
    } catch (err) {

    }
    var weiFee = gasPrice * gasMultiplicator * estimatedGas;
    // force fee in eth to be of BigNumber type
    var ethFee = web3.toBigNumber(web3.fromWei(weiFee, "ether"));
    // always display 7 decimal places
    return ethFee.toFixed(7);
}

function calculateGasPrice(n) {
    var gasMultiplicator = Math.pow(1.4, n).toFixed(3);
    var gasPrice = 211000000000;
    try {
        gasPrice = web3.eth.gasPrice;
    } catch (err) {

    }

    return gasPrice * gasMultiplicator;
}

status.defineSubscription(
    "calculatedFee",
    {value: ["sliderValue"], tx: ["transaction"]},
    function (params) {
        return calculateFee(params.value, params.tx);
    }
);

function getFeeExplanation(n) {
    return I18n.t('send_explanation') + I18n.t('send_explanation_' + (n + 2));
}

status.defineSubscription(
    "feeExplanation",
    {value: ["sliderValue"]},
    function(params) {
        return getFeeExplanation(params.value);
    }
);

function amountParameterBox(groupChat, params, context) {
    if (!params["bot-db"]) {
        params["bot-db"] = {};
    }

    var contactAddress;
    if (groupChat) {
        if (params["bot-db"]["public"] && params["bot-db"]["public"]["recipient"]) {
            contactAddress = params["bot-db"]["public"]["recipient"]["address"];
        } else {
            contactAddress = null;
        }
    } else {
        contactAddress = context.to;
    }
    
    var txData;
    var amount;
    var amountIndex = groupChat ? 1 : 0;
    
    try {
        amount = params.args[amountIndex].replace(",", ".");
        txData = {
            to: contactAddress,
            value: web3.toWei(amount) || 0
        };
    } catch (err) {
        amount = null;
        txData = {
            to: contactAddress,
            value: 0
        };
    } 

    var sliderValue = params["bot-db"]["sliderValue"] || 0;

    try {

        status.setDefaultDb({
            transaction: txData,
            calculatedFee: calculateFee(sliderValue, txData),
            feeExplanation: getFeeExplanation(sliderValue),
            sliderValue: sliderValue
        });

    } catch (err) {
        status.setDefaultDb({
            transaction: txData,
            calculatedFee: "0",
            feeExplanation: "",
            sliderValue: sliderValue
        });
    }
    
    return {
        title: I18n.t('send_title'),
        showBack: true,
        markup: status.components.scrollView(
            {
                keyboardShouldPersistTaps: "always"
            },
            [status.components.view(
                {
                    flex: 1
                },
                [
                    status.components.text(
                        {
                            style: {
                                fontSize: 14,
                                color: "rgb(147, 155, 161)",
                                paddingTop: 12,
{'fraction_non_alphanumeric': 0.12330198537095088, 'fraction_numerical': 0.022540677713091505, 'mean_word_length': 1.732463295269168, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3611409', 'n_tokens_mistral': 2134, 'n_tokens_neox': 1984, 'n_words': 402}