// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.
// Parity 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.
// Parity 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 Parity. If not, see .
import BigNumber from 'bignumber.js';
import moment from 'moment';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
import IdentityIcon from '../IdentityIcon';
import { TypedInput, Label } from '../Form';
import Loading from '../Loading';
import MethodDecodingStore from './methodDecodingStore';
import styles from './methodDecoding.css';
const ASCII_INPUT = /^[a-z0-9\s,?;.:/!()-_@'"#]+$/i;
const TOKEN_METHODS = {
'0xa9059cbb': 'transfer(to,value)'
};
class MethodDecoding extends Component {
static contextTypes = {
api: PropTypes.object.isRequired
};
static propTypes = {
address: PropTypes.string,
compact: PropTypes.bool,
token: PropTypes.object,
transaction: PropTypes.object,
historic: PropTypes.bool
};
static defaultProps = {
address: '',
compact: false,
historic: false
};
state = {
contractAddress: null,
methodName: null,
methodInputs: null,
methodParams: null,
methodSignature: null,
isContract: false,
isDeploy: false,
isReceived: false,
isLoading: true,
expandInput: false,
inputType: 'auto'
};
methodDecodingStore = MethodDecodingStore.get(this.context.api);
componentWillMount () {
const { address, transaction } = this.props;
this
.methodDecodingStore
.lookup(address, transaction)
.then((lookup) => {
const newState = {
methodName: lookup.name,
methodInputs: lookup.inputs,
methodParams: lookup.params,
methodSignature: lookup.signature,
isContract: lookup.contract,
isDeploy: lookup.deploy,
isLoading: false,
isReceived: lookup.received
};
this.setState(newState);
});
}
render () {
const { transaction } = this.props;
const { isLoading } = this.state;
if (!transaction) {
return null;
}
if (isLoading) {
return (