2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-12-06 09:37:59 +01:00
|
|
|
// 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import React, { Component, PropTypes } from 'react';
|
2017-03-02 12:24:54 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2016-12-06 09:37:59 +01:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { bindActionCreators } from 'redux';
|
2016-12-07 12:47:44 +01:00
|
|
|
import moment from 'moment';
|
|
|
|
|
2017-05-09 12:01:44 +02:00
|
|
|
import HistoryStore from '@parity/shared/mobx/historyStore';
|
|
|
|
import { setVisibleAccounts } from '@parity/shared/redux/providers/personalActions';
|
|
|
|
import { nullableProptype } from '@parity/shared/util/proptypes';
|
2017-05-12 12:06:16 +02:00
|
|
|
import { Actionbar, Button, Page, Loading } from '@parity/ui';
|
|
|
|
import { DeleteIcon, EditIcon, SendIcon, SettingsIcon } from '@parity/ui/Icons';
|
2016-12-06 09:37:59 +01:00
|
|
|
|
2017-04-28 11:21:05 +02:00
|
|
|
import EditMeta from '../Account/EditMeta';
|
|
|
|
import Transfer from '../Account/Transfer';
|
2016-12-07 12:47:44 +01:00
|
|
|
import Delete from '../Address/Delete';
|
2016-12-06 09:37:59 +01:00
|
|
|
import Header from '../Account/Header';
|
|
|
|
import WalletDetails from './Details';
|
|
|
|
import WalletConfirmations from './Confirmations';
|
|
|
|
import WalletTransactions from './Transactions';
|
2017-04-28 11:21:05 +02:00
|
|
|
import WalletSettings from './WalletSettings';
|
2016-12-06 09:37:59 +01:00
|
|
|
|
|
|
|
import styles from './wallet.css';
|
|
|
|
|
2017-04-25 11:07:11 +02:00
|
|
|
const accountsHistory = HistoryStore.get('accounts');
|
|
|
|
|
2016-12-06 09:37:59 +01:00
|
|
|
class WalletContainer extends Component {
|
|
|
|
static propTypes = {
|
2017-03-06 08:54:59 +01:00
|
|
|
netVersion: PropTypes.string.isRequired
|
2016-12-06 09:37:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
render () {
|
2017-03-06 08:54:59 +01:00
|
|
|
const { netVersion, ...others } = this.props;
|
2016-12-06 09:37:59 +01:00
|
|
|
|
2017-03-06 08:54:59 +01:00
|
|
|
if (netVersion === '0') {
|
2016-12-06 09:37:59 +01:00
|
|
|
return (
|
|
|
|
<Loading size={ 4 } />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2017-03-02 12:24:54 +01:00
|
|
|
<Wallet
|
2017-03-06 08:54:59 +01:00
|
|
|
netVersion={ netVersion }
|
2017-03-02 12:24:54 +01:00
|
|
|
{ ...others }
|
|
|
|
/>
|
2016-12-06 09:37:59 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Wallet extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
api: PropTypes.object.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
2016-12-30 12:28:12 +01:00
|
|
|
address: PropTypes.string.isRequired,
|
2017-03-06 08:54:59 +01:00
|
|
|
netVersion: PropTypes.string.isRequired,
|
2016-12-30 12:28:12 +01:00
|
|
|
owned: PropTypes.bool.isRequired,
|
|
|
|
setVisibleAccounts: PropTypes.func.isRequired,
|
2016-12-06 09:37:59 +01:00
|
|
|
wallet: PropTypes.object.isRequired,
|
2017-01-04 15:14:37 +01:00
|
|
|
walletAccount: nullableProptype(PropTypes.object.isRequired)
|
2016-12-06 09:37:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
showEditDialog: false,
|
2016-12-08 15:53:29 +01:00
|
|
|
showSettingsDialog: false,
|
2016-12-07 12:47:44 +01:00
|
|
|
showTransferDialog: false,
|
|
|
|
showDeleteDialog: false
|
2016-12-06 09:37:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount () {
|
2017-04-25 11:07:11 +02:00
|
|
|
const { address } = this.props;
|
|
|
|
|
|
|
|
accountsHistory.add(address, 'wallet');
|
|
|
|
|
2016-12-06 09:37:59 +01:00
|
|
|
this.setVisibleAccounts();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps (nextProps) {
|
|
|
|
const prevAddress = this.props.address;
|
|
|
|
const nextAddress = nextProps.address;
|
|
|
|
|
|
|
|
if (prevAddress !== nextAddress) {
|
|
|
|
this.setVisibleAccounts(nextProps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
this.props.setVisibleAccounts([]);
|
|
|
|
}
|
|
|
|
|
|
|
|
setVisibleAccounts (props = this.props) {
|
|
|
|
const { address, setVisibleAccounts } = props;
|
|
|
|
const addresses = [ address ];
|
2017-01-23 13:39:52 +01:00
|
|
|
|
2016-12-06 09:37:59 +01:00
|
|
|
setVisibleAccounts(addresses);
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2017-04-19 18:00:05 +02:00
|
|
|
const { walletAccount, wallet } = this.props;
|
2016-12-06 09:37:59 +01:00
|
|
|
|
2016-12-30 12:28:12 +01:00
|
|
|
if (!walletAccount) {
|
2016-12-06 09:37:59 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-12-30 12:28:12 +01:00
|
|
|
const { owners, require, dailylimit } = wallet;
|
2016-12-07 12:47:44 +01:00
|
|
|
|
2016-12-06 09:37:59 +01:00
|
|
|
return (
|
|
|
|
<div className={ styles.wallet }>
|
2016-12-30 12:28:12 +01:00
|
|
|
{ this.renderEditDialog(walletAccount) }
|
2016-12-08 15:53:29 +01:00
|
|
|
{ this.renderSettingsDialog() }
|
2016-12-06 09:37:59 +01:00
|
|
|
{ this.renderTransferDialog() }
|
2016-12-30 12:28:12 +01:00
|
|
|
{ this.renderDeleteDialog(walletAccount) }
|
2016-12-06 09:37:59 +01:00
|
|
|
{ this.renderActionbar() }
|
2017-02-24 15:21:36 +01:00
|
|
|
<Page padded>
|
2016-12-07 12:47:44 +01:00
|
|
|
<div className={ styles.info }>
|
|
|
|
<Header
|
|
|
|
className={ styles.header }
|
2016-12-30 12:28:12 +01:00
|
|
|
account={ walletAccount }
|
2016-12-10 01:26:47 +01:00
|
|
|
isContract
|
2016-12-07 12:47:44 +01:00
|
|
|
>
|
|
|
|
{ this.renderInfos() }
|
|
|
|
</Header>
|
|
|
|
|
|
|
|
<WalletDetails
|
|
|
|
className={ styles.details }
|
|
|
|
owners={ owners }
|
|
|
|
require={ require }
|
|
|
|
dailylimit={ dailylimit }
|
|
|
|
/>
|
|
|
|
</div>
|
2016-12-06 09:37:59 +01:00
|
|
|
{ this.renderDetails() }
|
|
|
|
</Page>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-07 12:47:44 +01:00
|
|
|
renderInfos () {
|
|
|
|
const { dailylimit } = this.props.wallet;
|
|
|
|
const { api } = this.context;
|
|
|
|
|
|
|
|
if (!dailylimit || !dailylimit.limit) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-12-10 01:26:47 +01:00
|
|
|
const _limit = api.util.fromWei(dailylimit.limit);
|
|
|
|
|
|
|
|
if (_limit.equals(0)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const limit = _limit.toFormat(3);
|
2016-12-07 12:47:44 +01:00
|
|
|
const spent = api.util.fromWei(dailylimit.spent).toFormat(3);
|
|
|
|
const date = moment(dailylimit.last.toNumber() * 24 * 3600 * 1000);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<br />
|
|
|
|
<p>
|
2017-03-02 12:24:54 +01:00
|
|
|
<FormattedMessage
|
|
|
|
id='wallet.details.spent'
|
|
|
|
defaultMessage='{spent} has been spent today, out of {limit} set as the daily limit, which has been reset on {date}'
|
|
|
|
values={ {
|
|
|
|
date: <span className={ styles.detail }>{ date.format('LL') }</span>,
|
|
|
|
limit: <span className={ styles.detail }>{ limit }<span className={ styles.eth } /></span>,
|
|
|
|
spent: <span className={ styles.detail }>{ spent }<span className={ styles.eth } /></span>
|
|
|
|
} }
|
|
|
|
/>
|
2016-12-07 12:47:44 +01:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-06 09:37:59 +01:00
|
|
|
renderDetails () {
|
2017-03-06 08:54:59 +01:00
|
|
|
const { address, netVersion, wallet } = this.props;
|
2016-12-07 12:47:44 +01:00
|
|
|
const { owners, require, confirmations, transactions } = wallet;
|
2016-12-06 09:37:59 +01:00
|
|
|
|
2017-01-04 16:25:39 +01:00
|
|
|
if (!owners || !require) {
|
2016-12-06 09:37:59 +01:00
|
|
|
return (
|
|
|
|
<div style={ { marginTop: '4em' } }>
|
|
|
|
<Loading size={ 4 } />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
<WalletConfirmations
|
2017-03-02 12:24:54 +01:00
|
|
|
address={ address }
|
|
|
|
confirmations={ confirmations }
|
2017-03-06 08:54:59 +01:00
|
|
|
netVersion={ netVersion }
|
2016-12-06 09:37:59 +01:00
|
|
|
key='confirmations'
|
|
|
|
owners={ owners }
|
|
|
|
require={ require }
|
|
|
|
/>,
|
|
|
|
|
|
|
|
<WalletTransactions
|
|
|
|
address={ address }
|
2017-03-06 08:54:59 +01:00
|
|
|
netVersion={ netVersion }
|
2017-03-02 12:24:54 +01:00
|
|
|
key='transactions'
|
|
|
|
transactions={ transactions }
|
2016-12-06 09:37:59 +01:00
|
|
|
/>
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
renderActionbar () {
|
2017-04-19 18:00:05 +02:00
|
|
|
const { owned } = this.props;
|
2016-12-06 09:37:59 +01:00
|
|
|
|
2016-12-30 12:28:12 +01:00
|
|
|
const buttons = [];
|
|
|
|
|
|
|
|
if (owned) {
|
|
|
|
buttons.push(
|
|
|
|
<Button
|
2017-03-02 12:24:54 +01:00
|
|
|
icon={ <SendIcon /> }
|
|
|
|
key='transferFunds'
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='wallet.buttons.transfer'
|
|
|
|
defaultMessage='transfer'
|
|
|
|
/>
|
|
|
|
}
|
2017-01-18 13:05:01 +01:00
|
|
|
onClick={ this.onTransferClick }
|
|
|
|
/>
|
2016-12-30 12:28:12 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buttons.push(
|
2016-12-07 12:47:44 +01:00
|
|
|
<Button
|
2017-03-02 12:24:54 +01:00
|
|
|
icon={ <DeleteIcon /> }
|
2016-12-07 12:47:44 +01:00
|
|
|
key='delete'
|
2017-03-02 12:24:54 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
2017-03-02 21:40:29 +01:00
|
|
|
id='wallet.buttons.forget'
|
|
|
|
defaultMessage='forget'
|
2017-03-02 12:24:54 +01:00
|
|
|
/>
|
|
|
|
}
|
2017-01-18 13:05:01 +01:00
|
|
|
onClick={ this.showDeleteDialog }
|
|
|
|
/>
|
2016-12-30 12:28:12 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
buttons.push(
|
2016-12-06 09:37:59 +01:00
|
|
|
<Button
|
2017-03-02 12:24:54 +01:00
|
|
|
icon={ <EditIcon /> }
|
2016-12-06 09:37:59 +01:00
|
|
|
key='editmeta'
|
2017-03-02 12:24:54 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='wallet.buttons.edit'
|
|
|
|
defaultMessage='edit'
|
|
|
|
/>
|
|
|
|
}
|
2017-01-18 13:05:01 +01:00
|
|
|
onClick={ this.onEditClick }
|
|
|
|
/>
|
2016-12-30 12:28:12 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (owned) {
|
|
|
|
buttons.push(
|
|
|
|
<Button
|
|
|
|
icon={ <SettingsIcon /> }
|
2017-03-02 12:24:54 +01:00
|
|
|
key='settings'
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='wallet.buttons.settings'
|
|
|
|
defaultMessage='settings'
|
|
|
|
/>
|
|
|
|
}
|
2017-01-18 13:05:01 +01:00
|
|
|
onClick={ this.onSettingsClick }
|
|
|
|
/>
|
2016-12-30 12:28:12 +01:00
|
|
|
);
|
|
|
|
}
|
2016-12-06 09:37:59 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Actionbar
|
2017-01-18 13:05:01 +01:00
|
|
|
buttons={ buttons }
|
2017-03-02 12:24:54 +01:00
|
|
|
title={
|
|
|
|
<FormattedMessage
|
|
|
|
id='wallet.title'
|
|
|
|
defaultMessage='Wallet Management'
|
|
|
|
/>
|
|
|
|
}
|
2017-01-18 13:05:01 +01:00
|
|
|
/>
|
2016-12-06 09:37:59 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-07 12:47:44 +01:00
|
|
|
renderDeleteDialog (account) {
|
|
|
|
const { showDeleteDialog } = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Delete
|
|
|
|
account={ account }
|
|
|
|
visible={ showDeleteDialog }
|
|
|
|
route='/accounts'
|
2017-01-18 13:05:01 +01:00
|
|
|
onClose={ this.closeDeleteDialog }
|
|
|
|
/>
|
2016-12-07 12:47:44 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-06 09:37:59 +01:00
|
|
|
renderEditDialog (wallet) {
|
|
|
|
const { showEditDialog } = this.state;
|
|
|
|
|
|
|
|
if (!showEditDialog) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<EditMeta
|
|
|
|
account={ wallet }
|
2016-12-08 15:53:29 +01:00
|
|
|
keys={ ['description'] }
|
2017-01-18 13:05:01 +01:00
|
|
|
onClose={ this.onEditClick }
|
|
|
|
/>
|
2016-12-06 09:37:59 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-08 15:53:29 +01:00
|
|
|
renderSettingsDialog () {
|
|
|
|
const { wallet } = this.props;
|
|
|
|
const { showSettingsDialog } = this.state;
|
|
|
|
|
|
|
|
if (!showSettingsDialog) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<WalletSettings
|
|
|
|
wallet={ wallet }
|
|
|
|
onClose={ this.onSettingsClick }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-06 09:37:59 +01:00
|
|
|
renderTransferDialog () {
|
|
|
|
const { showTransferDialog } = this.state;
|
|
|
|
|
|
|
|
if (!showTransferDialog) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-04-19 18:00:05 +02:00
|
|
|
const { walletAccount } = this.props;
|
2016-12-06 09:37:59 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Transfer
|
2016-12-30 12:28:12 +01:00
|
|
|
account={ walletAccount }
|
2016-12-06 09:37:59 +01:00
|
|
|
onClose={ this.onTransferClose }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
onEditClick = () => {
|
|
|
|
this.setState({
|
|
|
|
showEditDialog: !this.state.showEditDialog
|
|
|
|
});
|
2016-12-08 15:53:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onSettingsClick = () => {
|
|
|
|
this.setState({
|
|
|
|
showSettingsDialog: !this.state.showSettingsDialog
|
|
|
|
});
|
2016-12-06 09:37:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onTransferClick = () => {
|
|
|
|
this.setState({
|
|
|
|
showTransferDialog: !this.state.showTransferDialog
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onTransferClose = () => {
|
|
|
|
this.onTransferClick();
|
|
|
|
}
|
2016-12-07 12:47:44 +01:00
|
|
|
|
|
|
|
closeDeleteDialog = () => {
|
|
|
|
this.setState({ showDeleteDialog: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
showDeleteDialog = () => {
|
|
|
|
this.setState({ showDeleteDialog: true });
|
|
|
|
}
|
2016-12-06 09:37:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps (_, initProps) {
|
|
|
|
const { address } = initProps.params;
|
|
|
|
|
|
|
|
return (state) => {
|
2017-03-06 08:54:59 +01:00
|
|
|
const { netVersion } = state.nodeStatus;
|
2016-12-30 12:28:12 +01:00
|
|
|
const { accountsInfo = {}, accounts = {} } = state.personal;
|
|
|
|
const walletAccount = accounts[address] || accountsInfo[address] || null;
|
|
|
|
|
|
|
|
if (walletAccount) {
|
|
|
|
walletAccount.address = address;
|
|
|
|
}
|
2016-12-07 12:47:44 +01:00
|
|
|
|
2016-12-06 09:37:59 +01:00
|
|
|
const wallet = state.wallet.wallets[address] || {};
|
2016-12-30 12:28:12 +01:00
|
|
|
const owned = !!accounts[address];
|
2016-12-06 09:37:59 +01:00
|
|
|
|
|
|
|
return {
|
2016-12-30 12:28:12 +01:00
|
|
|
address,
|
2017-03-06 08:54:59 +01:00
|
|
|
netVersion,
|
2016-12-30 12:28:12 +01:00
|
|
|
owned,
|
|
|
|
wallet,
|
|
|
|
walletAccount
|
2016-12-06 09:37:59 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return bindActionCreators({
|
|
|
|
setVisibleAccounts
|
|
|
|
}, dispatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(WalletContainer);
|