// 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 } from 'react'; import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import moment from 'moment'; import HistoryStore from '@parity/shared/mobx/historyStore'; import { setVisibleAccounts } from '@parity/shared/redux/providers/personalActions'; import { nullableProptype } from '@parity/shared/util/proptypes'; import { Actionbar, Button, Page, Loading } from '@parity/ui'; import { DeleteIcon, EditIcon, SendIcon, SettingsIcon } from '@parity/ui/Icons'; import EditMeta from '@parity/dapp-account/EditMeta'; import Transfer from '@parity/dapp-account/Transfer'; import Delete from '@parity/dapp-address/Delete'; import Header from '@parity/dapp-account/Header'; import WalletDetails from './Details'; import WalletConfirmations from './Confirmations'; import WalletTransactions from './Transactions'; import WalletSettings from './WalletSettings'; import styles from './wallet.css'; const accountsHistory = HistoryStore.get('accounts'); class Wallet extends Component { static contextTypes = { api: PropTypes.object.isRequired }; static propTypes = { address: PropTypes.string.isRequired, netVersion: PropTypes.string.isRequired, owned: PropTypes.bool.isRequired, setVisibleAccounts: PropTypes.func.isRequired, wallet: PropTypes.object.isRequired, walletAccount: nullableProptype(PropTypes.object.isRequired) }; state = { showEditDialog: false, showSettingsDialog: false, showTransferDialog: false, showDeleteDialog: false }; componentDidMount () { const { address } = this.props; accountsHistory.add(address, 'wallet'); 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 ]; setVisibleAccounts(addresses); } render () { const { walletAccount, wallet } = this.props; if (!walletAccount) { return null; } const { owners, require, dailylimit } = wallet; return (
{ this.renderEditDialog(walletAccount) } { this.renderSettingsDialog() } { this.renderTransferDialog() } { this.renderDeleteDialog(walletAccount) } { this.renderActionbar() }
{ this.renderInfos() }
{ this.renderDetails() }
); } renderInfos () { const { dailylimit } = this.props.wallet; const { api } = this.context; if (!dailylimit || !dailylimit.limit) { return null; } const _limit = api.util.fromWei(dailylimit.limit); if (_limit.equals(0)) { return null; } const limit = _limit.toFormat(3); const spent = api.util.fromWei(dailylimit.spent).toFormat(3); const date = moment(dailylimit.last.toNumber() * 24 * 3600 * 1000); return (

{ date.format('LL') }, limit: { limit }, spent: { spent } } } />

); } renderDetails () { const { address, netVersion, wallet } = this.props; const { owners, require, confirmations, transactions } = wallet; if (!owners || !require) { return (
); } return [ , ]; } renderActionbar () { const { owned } = this.props; const buttons = []; if (owned) { buttons.push(