// Copyright 2015, 2016 Ethcore (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 React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import ActionDelete from 'material-ui/svg-icons/action/delete';
import AvPlayArrow from 'material-ui/svg-icons/av/play-arrow';
import ContentCreate from 'material-ui/svg-icons/content/create';
import { newError } from '../../redux/actions';
import { EditMeta, ExecuteContract } from '../../modals';
import { Actionbar, Button, Page } from '../../ui';
import Header from '../Account/Header';
import Delete from '../Address/Delete';
import Events from './Events';
import Queries from './Queries';
import styles from './contract.css';
class Contract extends Component {
static contextTypes = {
api: React.PropTypes.object.isRequired
}
static propTypes = {
accounts: PropTypes.object,
balances: PropTypes.object,
contracts: PropTypes.object,
isTest: PropTypes.bool,
params: PropTypes.object
}
state = {
contract: null,
fromAddress: '',
showDeleteDialog: false,
showEditDialog: false,
showExecuteDialog: false,
subscriptionId: -1,
blockSubscriptionId: -1,
allEvents: [],
minedEvents: [],
pendingEvents: [],
queryValues: {}
}
componentDidMount () {
const { api } = this.context;
this.attachContract(this.props);
this.setBaseAccount(this.props);
api
.subscribe('eth_blockNumber', this.queryContract)
.then(blockSubscriptionId => this.setState({ blockSubscriptionId }));
}
componentWillReceiveProps (newProps) {
const { accounts, contracts } = newProps;
if (Object.keys(contracts).length !== Object.keys(this.props.contracts).length) {
this.attachContract(newProps);
}
if (Object.keys(accounts).length !== Object.keys(this.props.accounts).length) {
this.setBaseAccount(newProps);
}
}
componentWillUnmount () {
const { api } = this.context;
const { subscriptionId, blockSubscriptionId, contract } = this.state;
api.unsubscribe(blockSubscriptionId);
contract.unsubscribe(subscriptionId);
}
render () {
const { balances, contracts, params, isTest } = this.props;
const { allEvents, contract, queryValues } = this.state;
const account = contracts[params.address];
const balance = balances[params.address];
if (!account) {
return null;
}
return (