<commit_before>import Immutable from 'immutable';
import log from 'loglevel';
import { change, formValueSelector, SubmissionError } from 'redux-form';

import { connect } from 'react-redux';
import { sendTransaction, trackTx } from 'store/accountActions';
import { transferTokenTransaction, traceTokenTransaction, traceCall } from 'store/tokenActions';
import { gotoScreen } from 'store/screenActions';
import { mweiToWei, etherToWei, toHex, estimateGasFromTrace } from 'lib/convert';
import { address } from 'lib/validators';

import CreateTxForm from './createTxForm';

const DefaultGas = 21000;
const DefaultTokenGas = 23890;

const traceValidate = (data, dispatch) => {
    const dataObj = {
        from: data.from,
        gasPrice: toHex(mweiToWei(data.gasPrice)),
        gas: toHex(data.gasAmount),
        to: data.to,
        value: toHex(etherToWei(data.value)),
    };
    const resolveValidate = (response, resolve) => {
        let errors = null;
        dataObj.data = (((response.trace || [])[0] || {}).action || {}).input;
        const gas = estimateGasFromTrace(dataObj, response);
        if (!gas) {
            errors = { value: 'Invalid Transaction' };
        } else if (gas.div(dataObj.gasPrice).toString(10) > dataObj.gasAmount) {
            errors = { gasAmount: `Insufficient Gas: Expected ${gas.div(dataObj.gasPrice).toString(10)}` };
        }
        resolve(errors);
    };

    if (data.token.length > 1) {
        return new Promise((resolve, reject) => {
            dispatch(traceTokenTransaction(data.from,
              data.to,
              dataObj.gas,
              dataObj.gasPrice,
              dataObj.value,
              data.token, data.isTransfer
            )).then((response) => resolveValidate(response, resolve))
              .catch((error) => {
                  resolve({ _error: (error.message || JSON.stringify(error)) });
              });
        });
    }
    return new Promise((resolve, reject) => {
        dispatch(traceCall(data.from,
              data.to,
              dataObj.gas,
              dataObj.gasPrice,
              dataObj.value<commit_msg>components/tx/create: accommodate geth trace_call<commit_after>import Immutable from 'immutable';
import log from 'loglevel';
import { change, formValueSelector, SubmissionError } from 'redux-form';

import { connect } from 'react-redux';
import { sendTransaction, trackTx } from 'store/accountActions';
import { transferTokenTransaction, traceTokenTransaction, traceCall } from 'store/tokenActions';
import { gotoScreen } from 'store/screenActions';
import { mweiToWei, etherToWei, toHex, estimateGasFromTrace } from 'lib/convert';
import { address } from 'lib/validators';

import CreateTxForm from './createTxForm';

const DefaultGas = 21000;
const DefaultTokenGas = 23890;

const traceValidate = (data, dispatch) => {
    const dataObj = {
        from: data.from,
        gasPrice: toHex(mweiToWei(data.gasPrice)),
        gas: toHex(data.gasAmount),
        to: data.to,
        value: toHex(etherToWei(data.value)),
    };
    const resolveValidate = (response, resolve) => {
        let errors = null;
        dataObj.data = (((response.trace || [])[0] || {}).action || {}).input;
        let gas; 
        if (response.gas) gas = response.gas;
        else {
            gas = estimateGasFromTrace(dataObj, response);
            gas = (gas && gas.div(dataObj.gasPrice).toString(10));
        }
        if (!gas) {
            errors = { value: 'Invalid Transaction' };
        } else if (gas > dataObj.gasAmount) {
            errors = { gasAmount: `Insufficient Gas: Expected ${gas}` };
        }
        resolve(errors);
    };

    if (data.token.length > 1) {
        return new Promise((resolve, reject) => {
            dispatch(traceTokenTransaction(data.from,
              data.to,
              dataObj.gas,
              dataObj.gasPrice,
              dataObj.value,
              data.token, data.isTransfer
            )).then((response) => resolveValidate(response, resolve))
              .catch((error) => {
                  resolve({ _error: (error.message || JSON.stringify(error)) });
              });
        });
    }
    return new Promise((resolve, reject) => {
        dispatch(traceCall(data.from,
              data.to,
              dataObj.gas,
              dataObj.gasPrice,
              dataObj.value
{'fraction_non_alphanumeric': 0.1297482837528604, 'fraction_numerical': 0.006864988558352402, 'mean_word_length': 2.41484375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '636515', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1224, 'n_words': 279}