// 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 React, { Component, PropTypes } from 'react';
import { FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { uniq, isEqual } from 'lodash';
import { AddContract, DeployContract } from '~/modals';
import { setVisibleAccounts } from '~/redux/providers/personalActions';
import { Actionbar, ActionbarSearch, ActionbarSort, Button, Page } from '~/ui';
import { AddIcon } from '~/ui/Icons';
import List from '../Accounts/List';
const META_SORT = [
{
key: 'timestamp',
label: (
)
},
{
key: 'blockNumber:-1',
label: (
)
}
];
class Contracts extends Component {
static contextTypes = {
api: PropTypes.object.isRequired
}
static propTypes = {
setVisibleAccounts: PropTypes.func.isRequired,
accounts: PropTypes.object,
contracts: PropTypes.object,
hasContracts: PropTypes.bool
}
state = {
addContract: false,
deployContract: false,
sortOrder: 'blockNumber:-1',
searchValues: [],
searchTokens: []
}
componentWillMount () {
this.setVisibleAccounts();
}
componentWillReceiveProps (nextProps) {
const prevAddresses = Object.keys(this.props.contracts);
const nextAddresses = Object.keys(nextProps.contracts);
if (prevAddresses.length !== nextAddresses.length || !isEqual(prevAddresses.sort(), nextAddresses.sort())) {
this.setVisibleAccounts(nextProps);
}
}
componentWillUnmount () {
this.props.setVisibleAccounts([]);
}
setVisibleAccounts (props = this.props) {
const { contracts, setVisibleAccounts } = props;
const addresses = Object.keys(contracts);
setVisibleAccounts(addresses);
}
render () {
const { contracts, hasContracts } = this.props;
const { searchValues, sortOrder } = this.state;
return (