// 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 { observe } from 'mobx';
import { observer } from 'mobx-react';
import { uniq, isEqual, pickBy } from 'lodash';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import HardwareStore from '@parity/shared/mobx/hardwareStore';
import { setVisibleAccounts } from '@parity/shared/redux/providers/personalActions';
import { Actionbar, ActionbarSearch, ActionbarSort, Button, DappLink, Page } from '@parity/ui';
import { AddIcon, KeyIcon, FileDownloadIcon } from '@parity/ui/Icons';
import CreateWallet from './CreateWallet';
import CreateAccount from './CreateAccount';
import ExportAccount from './ExportAccount';
import List from './List';
import styles from './accounts.css';
@observer
class Accounts extends Component {
static contextTypes = {
api: PropTypes.object
}
static propTypes = {
accounts: PropTypes.object.isRequired,
accountsInfo: PropTypes.object.isRequired,
availability: PropTypes.string.isRequired,
hasAccounts: PropTypes.bool.isRequired,
health: PropTypes.object.isRequired,
setVisibleAccounts: PropTypes.func.isRequired
}
hwstore = HardwareStore.get(this.context.api);
state = {
_observeCancel: null,
addressBook: false,
newDialog: false,
newWalletDialog: false,
newExportDialog: false,
restoreDialog: false,
sortOrder: '',
searchValues: [],
searchTokens: [],
show: false
}
componentWillMount () {
// FIXME: Messy, figure out what it fixes and do it elegantly
window.setTimeout(() => {
this.setState({ show: true });
}, 100);
this.setVisibleAccounts();
this.setState({
_observeCancel: observe(this.hwstore, 'wallets', this.onHardwareChange, true)
});
}
componentWillReceiveProps (nextProps) {
const prevAddresses = Object.keys(this.props.accounts);
const nextAddresses = Object.keys(nextProps.accounts);
if (prevAddresses.length !== nextAddresses.length || !isEqual(prevAddresses.sort(), nextAddresses.sort())) {
this.setVisibleAccounts(nextProps);
}
}
componentWillUnmount () {
this.props.setVisibleAccounts([]);
this.state._observeCancel();
}
setVisibleAccounts (props = this.props) {
const { accounts, setVisibleAccounts } = props;
setVisibleAccounts(Object.keys(accounts));
}
render () {
return (