// Copyright 2015, 2016 Ethcore (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 Paper from 'material-ui/Paper'; import { RaisedButton, SelectField, MenuItem } from 'material-ui'; import FindIcon from 'material-ui/svg-icons/action/find-in-page'; import DeleteIcon from 'material-ui/svg-icons/action/delete'; import Loading from '../../Loading'; import Chip from '../../Chip'; import AddMeta from './add-meta'; import styles from './token.css'; import { metaDataKeys } from '../../constants'; import { api } from '../../parity'; import { parityNode } from '../../../../environment'; export default class Token extends Component { static propTypes = { handleMetaLookup: PropTypes.func.isRequired, address: PropTypes.string.isRequired, name: PropTypes.string.isRequired, index: PropTypes.number.isRequired, owner: PropTypes.string.isRequired, handleAddMeta: PropTypes.func, handleUnregister: PropTypes.func, tla: PropTypes.string, base: PropTypes.number, totalSupply: PropTypes.number, meta: PropTypes.object, isMetaLoading: PropTypes.bool, ownerAccountInfo: PropTypes.shape({ name: PropTypes.string, meta: PropTypes.object }), metaPending: PropTypes.bool, metaMined: PropTypes.bool, isLoading: PropTypes.bool, isPending: PropTypes.bool, isTokenOwner: PropTypes.bool.isRequired, fullWidth: PropTypes.bool }; state = { metaKeyIndex: 0 }; render () { const { isLoading, fullWidth } = this.props; if (isLoading) { return (
); } if (fullWidth) { return (
{ this.renderContent() }
); } return (
{ this.renderContent() }
); } renderContent () { const { address, tla, base, name, meta, owner, totalSupply } = this.props; return (
{ this.renderIsPending() }
{ tla }
"{ name }"
{ this.renderBase(base) } { this.renderTotalSupply(totalSupply, base, tla) } { this.renderAddress(address) } { this.renderOwner(owner) }
{ this.renderMetaKeyItems() } } primary fullWidth onTouchTap={ this.onMetaLookup } />
{ this.renderMeta(meta) } { this.renderAddMeta() } { this.renderUnregister() }
{ this.renderMetaPending() } { this.renderMetaMined() }
); } renderMetaKeyItems () { return metaDataKeys.map((key, index) => ( )); } renderBase (base) { if (!base || base < 0) return null; return ( ); } renderAddress (address) { if (!address) return null; return ( ); } renderTotalSupply (totalSupply, base, tla) { const balance = Math.round((totalSupply / base) * 100) / 100; return ( ); } renderOwner (owner) { if (!owner) return null; const ownerInfo = this.props.ownerAccountInfo; const displayValue = (ownerInfo && ownerInfo.name) ? ownerInfo.name : owner; return ( ); } renderIsPending () { const { isPending } = this.props; if (!isPending) { return null; } return (
); } renderAddMeta () { if (!this.props.isTokenOwner) { return null; } return ( ); } renderUnregister () { if (!this.props.isTokenOwner) { return null; } return ( } secondary fullWidth onTouchTap={ this.onUnregister } /> ); } renderMeta (meta) { const isMetaLoading = this.props.isMetaLoading; if (isMetaLoading) { return (
); } if (!meta) return; const metaData = metaDataKeys.find(m => m.value === meta.query); if (!meta.value) { return (

No { metaData.label.toLowerCase() } meta-data...

); } if (meta.query === 'IMG') { const imageHash = meta.value.replace(/^0x/, ''); return (

{ metaData.label } meta-data:

); } if (meta.query === 'A') { const address = meta.value.slice(0, 42); return (

{ metaData.label } meta-data:

{ api.util.toChecksumAddress(address) }

); } return (

{ metaData.label } meta-data:

{ meta.value }

); } renderMetaPending () { const isMetaPending = this.props.metaPending; if (!isMetaPending) return; return (

Meta-Data pending...

); } renderMetaMined () { const isMetaMined = this.props.metaMined; if (!isMetaMined) return; return (

Meta-Data saved on the blockchain!

); } onUnregister = () => { const index = this.props.index; this.props.handleUnregister(index); } onMetaLookup = () => { const keyIndex = this.state.metaKeyIndex; const key = metaDataKeys[keyIndex].value; const index = this.props.index; this.props.handleMetaLookup(index, key); } onMetaKeyChange = (event, metaKeyIndex) => { this.setState({ metaKeyIndex }); } }