<commit_before>'use babel'
// Copyright 2018 Etheratom Authors
// This file is part of Etheratom.

// Etheratom is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Etheratom is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Etheratom.  If not, see <http://www.gnu.org/licenses/>.
import React from 'react';
import { connect } from 'react-redux';
import ReactJson from 'react-json-view';
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs';
import GasInput from '../GasInput';
import InputsForm from '../InputsForm';
import CreateButton from '../CreateButton';
import PropTypes from 'prop-types';
import { addInterface } from '../../actions';
import { saveAs } from 'file-saver';
const Blob = require('blob');

class ContractCompiled extends React.Component {
    constructor(props) {
        super(props);
        this.helpers = props.helpers;
        this.state = {
            estimatedGas: 9000000,
            ContractABI: props.interfaces[props.contractName].interface,
            savePath: `${props.contractName}.abi`
        };
        this._handleGasChange = this._handleGasChange.bind(this);
        this._handleInput = this._handleInput.bind(this);
        this._saveABI = this._saveABI.bind(this);
    }
    async componentDidMount() {
        try {
            const { coinbase, bytecode } = this.props;
            const gas = await this.helpers.getGasEstimate(coinbase, bytecode);
            this.setState({ estimatedGas: gas });
        } catch (e) {
            console.log(e);
            this.helpers.showPanelError(e);
        }
    }
    _handleGasChange(event) {
        this.setState({ estimatedGas: event.target.value });
    }
    _handleInput() {
        const { contractName } = this.props;
        const { ContractABI } = this.state;
        this.props.addInterface({ contractName, ContractABI });
    }
    _saveABI() {
        const { fileName } = this.props;
        const { ContractABI } = this.state;
        const savePath = `${fileName.split('.sol')[0]}.abi`;
        const json = JSON.stringify(ContractABI).replace(new RegExp('"', 'g'), '\'');
        const blob = new Blob([json], {type: 'text/plain;charset=utf-8'});
        saveAs(blob, savePath);
    }

    render() {
        const { contractName, bytecode, index } = this.props;
        const { estimatedGas, ContractABI } = this.state;
        const savePath = `${contractName}.abi`;
        return (
            <div className="contract-content" key={index}>
                <span className="contract-name inline-block highlight-success">{ contractName }</span>
                <div className="byte-code">
                    <pre className="large-code">{ JSON.stringify(bytecode) }</pre>
                </div>
                <div className="abi-definition">
                    <Tabs>
                        <TabList>
                            <div className="tab_btns">
                                <Tab>
                                    <div className="btn">Interface</div>
                                </Tab>
                                <Tab>
                                    <div className="btn">Interface Object</div>
                                </Tab>
                                <button className="btn icon icon-desktop-download inline-block-tight icon-button"
                                    title={"Save "+savePath } onClick={this._saveABI}></button>
                                
                            </div>
                        </TabList>

                        <TabPanel>
                            <pre className="large-code">{ JSON.stringify(ContractABI) }</pre>
                        </TabPanel>
                        <TabPanel>
                            <ReactJson
                                src={ContractABI}
                                theme="chalk"
                                displayDataTypes={false}
                                name={false}
                                collapsed={2}
                                collapseStringsAfterLength={32}
                                iconStyle="triangle"
                            />
                        </TabPanel>
                    </Tabs>
                </div>
                {
                    ContractABI.map((abi, i) => {
                        return <InputsForm key={i} contractName={contractName} abi={abi} onSubmit={this._handleInput}/>;
                    })
                }<commit_msg>fix build error<commit_after>'use babel'
// Copyright 2018 Etheratom Authors
// This file is part of Etheratom.

// Etheratom is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Etheratom is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Etheratom.  If not, see <http://www.gnu.org/licenses/>.
import React from 'react';
import { connect } from 'react-redux';
import ReactJson from 'react-json-view';
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs';
import GasInput from '../GasInput';
import InputsForm from '../InputsForm';
import CreateButton from '../CreateButton';
import PropTypes from 'prop-types';
import { addInterface } from '../../actions';
import { saveAs } from 'file-saver';
const Blob = require('blob');

class ContractCompiled extends React.Component {
    constructor(props) {
        super(props);
        this.helpers = props.helpers;
        this.state = {
            estimatedGas: 9000000,
            ContractABI: props.interfaces[props.contractName].interface,
            savePath: `${props.contractName}.abi`
        };
        this._handleGasChange = this._handleGasChange.bind(this);
        this._handleInput = this._handleInput.bind(this);
        this._saveABI = this._saveABI.bind(this);
    }
    async componentDidMount() {
        try {
            const { coinbase, bytecode } = this.props;
            const gas = await this.helpers.getGasEstimate(coinbase, bytecode);
            this.setState({ estimatedGas: gas });
        } catch (e) {
            console.log(e);
            this.helpers.showPanelError(e);
        }
    }
    _handleGasChange(event) {
        this.setState({ estimatedGas: event.target.value });
    }
    _handleInput() {
        const { contractName } = this.props;
        const { ContractABI } = this.state;
        this.props.addInterface({ contractName, ContractABI });
    }
    _saveABI() {
        const { fileName } = this.props;
        const { ContractABI } = this.state;
        const savePath = `${fileName.split('.sol')[0]}.abi`;
        const json = JSON.stringify(ContractABI).replace(new RegExp('"', 'g'), '\'');
        const blob = new Blob([json], {type: 'text/plain;charset=utf-8'});
        saveAs(blob, savePath);
    }

    render() {
        const { contractName, bytecode, index } = this.props;
        const { estimatedGas, ContractABI } = this.state;
        const savePath = `${contractName}.abi`;
        return (
            <div className="contract-content" key={index}>
                <span className="contract-name inline-block highlight-success">{ contractName }</span>
                <div className="byte-code">
                    <pre className="large-code">{ JSON.stringify(bytecode) }</pre>
                </div>
                <div className="abi-definition">
                    <Tabs>
                        <TabList>
                            <div className="tab_btns">
                                <Tab>
                                    <div className="btn">Interface</div>
                                </Tab>
                                <Tab>
                                    <div className="btn">Interface Object</div>
                                </Tab>
                                <button className="btn icon icon-desktop-download inline-block-tight icon-button"
                                    title={'Save '+savePath } onClick={this._saveABI}></button>
                                
                            </div>
                        </TabList>

                        <TabPanel>
                            <pre className="large-code">{ JSON.stringify(ContractABI) }</pre>
                        </TabPanel>
                        <TabPanel>
                            <ReactJson
                                src={ContractABI}
                                theme="chalk"
                                displayDataTypes={false}
                                name={false}
                                collapsed={2}
                                collapseStringsAfterLength={32}
                                iconStyle="triangle"
                            />
                        </TabPanel>
                    </Tabs>
                </div>
                {
                    ContractABI.map((abi, i) => {
                        return <InputsForm key={i} contractName={contractName} abi={abi} onSubmit={this._handleInput}/>;
                    })
                }
{'fraction_non_alphanumeric': 0.11095276872964169, 'fraction_numerical': 0.0034609120521172636, 'mean_word_length': 1.5446775446775447, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4028819', 'n_tokens_mistral': 2497, 'n_tokens_neox': 2397, 'n_words': 628}