<commit_before>import EmbarkJS from 'Embark/EmbarkJS';
import {{contractName}} from 'Embark/contracts/{{contractName}}';

import React, { Component, Fragment } from 'react';
import ReactDOM from 'react-dom';
import { FormGroup, ControlLabel, FormControl, Checkbox, Button, Alert, InputGroup } from 'react-bootstrap';


{{#each functions}}
class {{capitalize name}}Form{{@index}} extends Component {
    constructor(props){
        super(props);
        this.state = {
            {{#if inputs.length}}
            input: {
                {{#each inputs}}
                {{#ifeq name ''}}field{{else}}{{trim name}}{{/ifeq}}: {{#ifeq type 'bool'}}false{{else}}''{{/ifeq}}{{#unless @last}},{{/unless}}
                {{/each}}
            },
            {{/if}}
            {{#if payable}}
            value: 0,
            {{/if}}
            {{#ifview stateMutability}}
            output: null,
            {{/ifview}}
            error: null,
            mined: null
        };
    }

    handleChange(e, name){
        const {input} = this.state;
        input[name] = e.target.value;
        this.setState({input});
    }

    handleCheckbox(e, name){
        const {input} = this.state;
        input[name] = e.target.checked;
        this.setState({input});
    }

    async handleClick(e){
        e.preventDefault();

        const {input, value} = this.state;

        this.setState({output: null, error: null, receipt: null});

        try {
        {{#ifview stateMutability}}
            const result = await {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}input.{{#ifeq name ''}}field{{else}}{{trim name}}{{/ifeq}}{{#unless @last}}, {{/unless}}{{/each}}).call()
            {{#iflengthgt outputs 1}}
            this.setState({output: {
            {{#each outputs}}
                {{emptyname name @index}}: result[{{@index}}]{{#unless @last}},{{/unless}}
            {{/each}}
            }}); 
            {{else}}
            this.setState({output: result});  
            {{/iflengthgt}}           
        {{else}}
            {{#each inputs}}
            {{#ifarr type}}
            input.{{trim name}} = input.{{trim name}}.split(',').map(x => x.toString().trim());
            {{/ifarr}}
            {{/each}}

            const toSend = {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}input.{{#ifeq name ''}}field{{else}}{{trim name}}{{/ifeq}}{{#unless @last}}, {{/unless}}{{/each}});

            const estimatedGas = await toSend.estimateGas({from: web3.eth.defaultAccount});
            
            const receipt = await toSend.send({
                {{#if payable}}
                value: value,
                {{/if}}
                from: web3.eth.defaultAccount,
                gasLimit: estimatedGas
            });

            console.log(receipt);

            this.setState({receipt});
        {{/ifview}}
        } catch(err) {
            console.error(err);
            this.setState({error: err.message});
        }
    }

    render(){
        const {input, value, error, output, receipt} = this.state;

        return <div className="formSection">
            <h3>{{name}}</h3>
            <form>
            {{#if inputs.length}}
                {{#each inputs}}
                <FormGroup>
                    <ControlLabel>{{#ifeq name ''}}field{{else}}{{name}}{{/ifeq}}</ControlLabel>
                    {{#ifeq type 'bool'}}
                    <Checkbox
                        onClick={(e) => this.handleCheckbox(e, '{{#ifeq name ''}}field{{else}}{{trim name}}{{/ifeq}}')}
                    />
                    {{else}}
                    <FormControl
                        type="text"
                        defaultValue={ input.{{#ifeq name ''}}field{{else}}{{trim name}}{{/ifeq}} }
                        placeholder="{{type}}"
                        onChange={(e) => this.handleChange(e, '{{#ifeq name ''}}field{{else}}{{trim name}}{{/ifeq}}')}
                    />
                    {{/ifeq}}
                </FormGroup>
                {{/each}}      
            {{/if}}
            {{#if payable}}
                <FormGroup>
                    <ControlLabel>Value</ControlLabel>
                    <InputGroup>
                        <InputGroup.Addon>Ξ</InputGroup.Addon>
                        <FormControl 
                            type="text"
                            defaultValue={ value }
                            placeholder="{{type}}"
                            onChange={(e) => { this.setState({value: e.target.value}); }}
                        />
                        <InputGroup.Addon>wei</InputGroup.Addon>
                    </InputGroup>
                </FormGroup>
            {{/if}}

                { error != null && <Alert bsStyle="danger">{error}</Alert> }

            {{#ifview stateMutability}}
                <Button type="submit" bsStyle="primary" onClick={(e) => this.handleClick(e)}>Call</Button>
                {
                    output &&
                    <Fragment>
                        <h4>Results</h4>
                        {{#iflengthgt outputs 1}}
                        <ul>
                        {{#each outputs}}
                            <li>{{emptyname name @index}}: { output.{{emptyname name @index}} }</li>
                        {{/each}}
                        </ul>
                        {{else}}
                        {output.toString()}
                        {{/iflengthgt}}
                    </Fragment>
                }
            {{else}}
                <Button type="submit" bsStyle="primary" onClick={(e) => this.handleClick(e)}>Send</Button>
                {
                receipt &&
                <Fragment>
                    <Alert bsStyle={receipt.status === "0x1" ? 'success' : 'danger'}>{receipt.status === "0x1" ? 'Success' : 'Failure / Revert'} - Transaction Hash: {receipt.transactionHash}</Alert>
                </Fragment>
                
                }
            {{/ifview}}
            </form>
        </div>;
    }
}

{{/each}}

function {{contractName}}UI(props) {
    return (<div>
            <h1>{{title}}</h1>
            {{#each functions}}
            <{{capitalize name}}Form{{@index}} />
            {{/each}}
        </div>);
}


ReactDOM.render(<{{contractName}}UI />, document.getElementById('app'));
<commit_msg>fix array display and setting<commit_after>import EmbarkJS from 'Embark/EmbarkJS';
import {{contractName}} from 'Embark/contracts/{{contractName}}';

import React, { Component, Fragment } from 'react';
import ReactDOM from 'react-dom';
import { FormGroup, ControlLabel, FormControl, Checkbox, Button, Alert, InputGroup } from 'react-bootstrap';

function isSuccess(status) {
    return status === "0x1" || status === true;
}

{{#each functions}}
class {{capitalize name}}Form{{@index}} extends Component {
    constructor(props){
        super(props);
        this.state = {
            {{#if inputs.length}}
            input: {
                {{#each inputs}}
                {{#ifeq name ''}}field{{else}}{{trim name}}{{/ifeq}}: {{#ifeq type 'bool'}}false{{else}}''{{/ifeq}}{{#unless @last}},{{/unless}}
                {{/each}}
            },
            {{/if}}
            {{#if payable}}
            value: 0,
            {{/if}}
            {{#ifview stateMutability}}
            output: null,
            {{/ifview}}
            error: null,
            mined: null
        };
    }

    handleChange(e, name){
        const {input} = this.state;
        input[name] = e.target.value;
        this.setState({input});
    }

    handleCheckbox(e, name){
        const {input} = this.state;
        input[name] = e.target.checked;
        this.setState({input});
    }

    async handleClick(e){
        e.preventDefault();

        const {input, value} = this.state;

        this.setState({output: null, error: null, receipt: null});

        try {
        {{#ifview stateMutability}}
            const result = await {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}input.{{#ifeq name ''}}field{{else}}{{trim name}}{{/ifeq}}{{#unless @last}}, {{/unless}}{{/each}}).call();
            {{#iflengthgt outputs 1}}
            this.setState({output: {
            {{#each outputs}}
                {{emptyname name @index}}: result[{{@index}}]{{#unless @last}},{{/unless}}
            {{/each}}
            }}); 
            {{else}}
            this.setState({output: result});  
            {{/iflengthgt}}           
        {{else}}
            {{#each inputs}}
            {{#ifarr type}}
            input.{{trim name}} = input.{{trim name}}.split(',').map(x => x.toString().trim());
            {{/ifarr}}
            {{/each}}

            const toSend = {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}input.{{#ifeq name ''}}field{{else}}{{trim name}}{{/ifeq}}{{#unless @last}}, {{/unless}}{{/each}});

            const estimatedGas = await toSend.estimateGas({from: web3.eth.defaultAccount});
            
            const receipt = await toSend.send({
                {{#if payable}}
                value: value,
                {{/if}}
                from: web3.eth.defaultAccount,
                gasLimit: estimatedGas
            });

            console.log(receipt);

            this.setState({receipt});
        {{/ifview}}
        } catch(err) {
            console.error(err);
            this.setState({error: err.message});
        }
    }

    render(){
        const {input, value, error, output, receipt} = this.state;

        return <div className="formSection">
            <h3>{{name}}</h3>
            <form>
            {{#if inputs.length}}
                {{#each inputs}}
                <FormGroup>
                    <ControlLabel>{{#ifeq name ''}}field{{else}}{{name}}{{/ifeq}}</ControlLabel>
                    {{#ifeq type 'bool'}}
                    <Checkbox
                        onClick={(e) => this.handleCheckbox(e, '{{#ifeq name ''}}field{{else}}{{trim name}}{{/ifeq}}')}
                    />
                    {{else}}
                    <FormControl
                        type="text"
                        defaultValue={ input.{{#ifeq name ''}}field{{else}}{{trim name}}{{/ifeq}} }
                        placeholder="{{type}}"
                        onChange={(e) => this.handleChange(e, '{{#ifeq name ''}}field{{else}}{{trim name}}{{/ifeq}}')}
                    />
                    {{/ifeq}}
                </FormGroup>
                {{/each}}      
            {{/if}}
            {{#if payable}}
                <FormGroup>
                    <ControlLabel>Value</ControlLabel>
                    <InputGroup>
                        <InputGroup.Addon>Ξ</InputGroup.Addon>
                        <FormControl 
                            type="text"
                            defaultValue={ value }
                            placeholder="{{type}}"
                            onChange={(e) => { this.setState({value: e.target.value}); }}
                        />
                        <InputGroup.Addon>wei</InputGroup.Addon>
                    </InputGroup>
                </FormGroup>
            {{/if}}

                { error != null && <Alert bsStyle="danger">{error}</Alert> }

            {{#ifview stateMutability}}
                <Button type="submit" bsStyle="primary" onClick={(e) => this.handleClick(e)}>Call</Button>
                {
                    output &&
                    <Fragment>
                        <h4>Results</h4>
                        {{#iflengthgt outputs 1}}
                        <ul>
                        {{#each outputs}}
                            <li>{{emptyname name @index}}: { JSON.stringify(output.{{emptyname name @index}}) }</li>
                        {{/each}}
                        </ul>
                        {{else}}
                        {output.toString()}
                        {{/iflengthgt}}
                    </Fragment>
                }
            {{else}}
                <Button type="submit" bsStyle="primary" onClick={(e) => this.handleClick(e)}>Send</Button>
                {
                receipt &&
                <Fragment>
                    <Alert bsStyle={isSuccess(receipt.status) ? 'success' : 'danger'}>{isSuccess(receipt.status) ? 'Success' : 'Failure / Revert'} - Transaction Hash: {receipt.transactionHash}</Alert>
                </Fragment>
                
                }
            {{/ifview}}
            </form>
        </div>;
    }
}

{{/each}}

function {{contractName}}UI(props) {
    return (<div>
            <h1>{{title}}</h1>
            {{#each functions}}
            <{{capitalize name}}Form{{@index}} />
            {{/each}}
        </div>);
}


ReactDOM.render(<{{contractName}}UI />, document.getElementById('app'));

{'fraction_non_alphanumeric': 0.1708430007733952, 'fraction_numerical': 0.002165506573859242, 'mean_word_length': 1.4206289779108947, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '5006574', 'n_tokens_mistral': 3600, 'n_tokens_neox': 3376, 'n_words': 641}