// 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 { Dialog, RaisedButton, FlatButton, SelectField, MenuItem } from 'material-ui';
import AddIcon from 'material-ui/svg-icons/content/add';
import PropTypes from 'prop-types';
import InputText from '../../Inputs/Text';
import { ADDRESS_TYPE, URL_TYPE } from '../../Inputs/validation';
import styles from './token.css';
import { metaDataKeys } from '../../constants';
const initState = {
showDialog: false,
complete: false,
metaKeyIndex: 0,
form: {
valid: false,
value: ''
}
};
export default class AddMeta extends Component {
static propTypes = {
isTokenOwner: PropTypes.bool,
handleAddMeta: PropTypes.func,
index: PropTypes.number
};
state = initState;
render () {
if (!this.props.isTokenOwner) {
return null;
}
return (
}
primary
fullWidth
onTouchTap={ this.onShowDialog }
/>
);
}
renderActions () {
const { complete } = this.state;
if (complete) {
return (
);
}
const isValid = this.state.form.valid;
return ([
,
]);
}
renderContent () {
const { complete } = this.state;
if (complete) {
return this.renderComplete();
}
return this.renderForm();
}
renderComplete () {
if (metaDataKeys[this.state.metaKeyIndex].value === 'IMG') {
return (
Your transactions has been posted.
Two transactions are needed to add an Image.
Please visit the Parity Signer to authenticate the transfer.
);
}
return (
Your transaction has been posted. Please visit the Parity Signer to authenticate the transfer.
);
}
renderForm () {
const selectedMeta = metaDataKeys[this.state.metaKeyIndex];
const metaLabel = selectedMeta.label.toLowerCase();
let metaType;
switch (selectedMeta.validation) {
case ADDRESS_TYPE:
metaType = 'Address';
break;
case URL_TYPE:
metaType = 'URL';
break;
default:
metaType = 'URL Hint';
break;
}
return (
{ this.renderMetaKeyItems() }
);
}
renderMetaKeyItems () {
return metaDataKeys.map((key, index) => (
));
}
onShowDialog = () => {
this.setState({ showDialog: true });
}
onClose = () => {
this.setState(initState);
}
onAdd = () => {
const { index } = this.props;
const { form, metaKeyIndex } = this.state;
const selectedMeta = metaDataKeys[metaKeyIndex];
const keyIndex = this.state.metaKeyIndex;
const key = metaDataKeys[keyIndex].value;
const value = form.value;
const validationType = selectedMeta.validation;
this.props.handleAddMeta(
index,
key,
value,
validationType
);
this.setState({ complete: true });
}
onChange = (valid, value) => {
this.setState({
form: {
valid, value
}
});
}
onMetaKeyChange = (event, metaKeyIndex) => {
this.setState({ metaKeyIndex, form: {
...[this.state.form],
valid: false,
value: ''
} });
}
}