Gavcoin event display updates (#2956)

* Mapp all known addresses

* Display timestamp in event log

* Shorten addresses

* Display "Pending" timestamps as well

* Pending/Loading with empty timestamp
This commit is contained in:
Jaco Greeff 2016-10-29 13:04:47 +02:00 committed by Gav Wood
parent e1cf6f7dd0
commit 65c985bef3
5 changed files with 55 additions and 24 deletions

View File

@ -53,6 +53,7 @@ export default class Application extends Component {
action: null, action: null,
address: null, address: null,
accounts: [], accounts: [],
accountsInfo: {},
blockNumber: new BigNumber(-1), blockNumber: new BigNumber(-1),
ethBalance: new BigNumber(0), ethBalance: new BigNumber(0),
gavBalance: new BigNumber(0), gavBalance: new BigNumber(0),
@ -68,7 +69,7 @@ export default class Application extends Component {
} }
render () { render () {
const { accounts, address, blockNumber, gavBalance, loading, price, remaining, totalSupply } = this.state; const { accounts, accountsInfo, address, blockNumber, gavBalance, loading, price, remaining, totalSupply } = this.state;
if (loading) { if (loading) {
return ( return (
@ -93,7 +94,7 @@ export default class Application extends Component {
gavBalance={ gavBalance } gavBalance={ gavBalance }
onAction={ this.onAction } /> onAction={ this.onAction } />
<Events <Events
accounts={ accounts } /> accountsInfo={ accountsInfo } />
</div> </div>
); );
} }
@ -216,8 +217,8 @@ export default class Application extends Component {
api.personal.accountsInfo() api.personal.accountsInfo()
]); ]);
}) })
.then(([address, addresses, infos]) => { .then(([address, addresses, accountsInfo]) => {
infos = infos || {}; accountsInfo = accountsInfo || {};
console.log(`gavcoin was found at ${address}`); console.log(`gavcoin was found at ${address}`);
const contract = api.newContract(abis.gavcoin, address); const contract = api.newContract(abis.gavcoin, address);
@ -226,9 +227,10 @@ export default class Application extends Component {
loading: false, loading: false,
address, address,
contract, contract,
accountsInfo,
instance: contract.instance, instance: contract.instance,
accounts: addresses.map((address) => { accounts: addresses.map((address) => {
const info = infos[address] || {}; const info = accountsInfo[address] || {};
return { return {
address, address,

View File

@ -14,10 +14,11 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
import moment from 'moment';
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import IdentityIcon from '../../IdentityIcon'; import IdentityIcon from '../../IdentityIcon';
import { formatBlockNumber, formatCoins, formatEth } from '../../format'; import { formatCoins, formatEth, formatHash } from '../../format';
import styles from '../events.css'; import styles from '../events.css';
@ -27,7 +28,8 @@ const EMPTY_COLUMN = (
export default class Event extends Component { export default class Event extends Component {
static contextTypes = { static contextTypes = {
accounts: PropTypes.array.isRequired accountsInfo: PropTypes.object.isRequired,
api: PropTypes.object.isRequired
} }
static propTypes = { static propTypes = {
@ -38,14 +40,23 @@ export default class Event extends Component {
toAddress: PropTypes.string toAddress: PropTypes.string
} }
state = {
block: null
}
componentDidMount () {
this.loadBlock();
}
render () { render () {
const { event, fromAddress, toAddress, price, value } = this.props; const { event, fromAddress, toAddress, price, value } = this.props;
const { blockNumber, state, type } = event; const { block } = this.state;
const { state, type } = event;
const cls = `${styles.event} ${styles[state]} ${styles[type.toLowerCase()]}`; const cls = `${styles.event} ${styles[state]} ${styles[type.toLowerCase()]}`;
return ( return (
<tr className={ cls }> <tr className={ cls }>
{ this.renderBlockNumber(blockNumber) } { this.renderTimestamp(block) }
{ this.renderType(type) } { this.renderType(type) }
{ this.renderValue(value) } { this.renderValue(value) }
{ this.renderPrice(price) } { this.renderPrice(price) }
@ -55,10 +66,10 @@ export default class Event extends Component {
); );
} }
renderBlockNumber (blockNumber) { renderTimestamp (block) {
return ( return (
<td className={ styles.blocknumber }> <td className={ styles.blocknumber }>
{ formatBlockNumber(blockNumber) } { !block ? ' ' : moment(block.timestamp).fromNow() }
</td> </td>
); );
} }
@ -77,8 +88,8 @@ export default class Event extends Component {
} }
renderAddressName (address) { renderAddressName (address) {
const { accounts } = this.context; const { accountsInfo } = this.context;
const account = accounts.find((_account) => _account.address === address); const account = accountsInfo[address];
if (account && account.name) { if (account && account.name) {
return ( return (
@ -90,7 +101,7 @@ export default class Event extends Component {
return ( return (
<div className={ styles.address }> <div className={ styles.address }>
{ address } { formatHash(address) }
</div> </div>
); );
} }
@ -126,4 +137,19 @@ export default class Event extends Component {
</td> </td>
); );
} }
loadBlock () {
const { api } = this.context;
const { event } = this.props;
if (!event || !event.blockNumber || event.blockNumber.eq(0)) {
return;
}
api.eth
.getBlockByNumber(event.blockNumber)
.then((block) => {
this.setState({ block });
});
}
} }

View File

@ -16,18 +16,20 @@
*/ */
.events { .events {
padding: 4em 2em; padding: 4em 2em;
text-align: center;
} }
.list { .list {
width: 100%; margin: 0 auto;
border: none; border: none;
border-spacing: 0; border-spacing: 0;
text-align: left;
} }
.list td { .list td {
vertical-align: top; vertical-align: top;
padding: 4px 0.5em; padding: 0.25em 1em;
max-height: 32px; max-height: 1.5em;
} }
.event { .event {
@ -38,7 +40,6 @@
.blocknumber, .blocknumber,
.ethvalue, .ethvalue,
.gavvalue { .gavvalue {
font-family: 'Roboto Mono', monospace;
} }
.blocknumber, .blocknumber,

View File

@ -27,7 +27,7 @@ import styles from './events.css';
export default class Events extends Component { export default class Events extends Component {
static childContextTypes = { static childContextTypes = {
accounts: PropTypes.array accountsInfo: PropTypes.object
} }
static contextTypes = { static contextTypes = {
@ -36,7 +36,7 @@ export default class Events extends Component {
} }
static propTypes = { static propTypes = {
accounts: PropTypes.array accountsInfo: PropTypes.object.isRequired
} }
state = { state = {
@ -84,11 +84,9 @@ export default class Events extends Component {
} }
getChildContext () { getChildContext () {
const { accounts } = this.props; const { accountsInfo } = this.props;
return { return { accountsInfo };
accounts
};
} }
setupFilters () { setupFilters () {

View File

@ -50,3 +50,7 @@ export function formatCoins (amount, decimals = 6) {
export function formatEth (eth, decimals = 3) { export function formatEth (eth, decimals = 3) {
return api.util.fromWei(eth).toFormat(decimals); return api.util.fromWei(eth).toFormat(decimals);
} }
export function formatHash (hash) {
return `${hash.substr(0, 10)}...${hash.substr(-8)}`;
}