2017-09-25 02:06:28 +00:00
|
|
|
import { donationAddressMap } from 'config/data';
|
|
|
|
import { isValidHex } from 'libs/validators';
|
2017-06-26 22:27:55 +00:00
|
|
|
import React from 'react';
|
|
|
|
import translate from 'translations';
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
interface Props {
|
|
|
|
value: string;
|
|
|
|
onChange?(e: string): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
expanded: boolean;
|
|
|
|
}
|
|
|
|
export default class DataField extends React.Component<Props, State> {
|
|
|
|
public state = {
|
2017-07-02 05:49:06 +00:00
|
|
|
expanded: false
|
|
|
|
};
|
2017-09-25 02:06:28 +00:00
|
|
|
public render() {
|
2017-07-02 05:49:06 +00:00
|
|
|
const { value } = this.props;
|
|
|
|
const { expanded } = this.state;
|
|
|
|
const valid = isValidHex(value || '');
|
|
|
|
const readOnly = !this.props.onChange;
|
2017-06-26 22:27:55 +00:00
|
|
|
|
2017-07-02 05:49:06 +00:00
|
|
|
return (
|
|
|
|
<div className="row form-group">
|
|
|
|
<div className="col-sm-11 clearfix">
|
|
|
|
{!expanded &&
|
|
|
|
<a onClick={this.expand}>
|
|
|
|
<p className="strong">
|
|
|
|
{translate('TRANS_advanced')}
|
|
|
|
</p>
|
|
|
|
</a>}
|
|
|
|
{expanded &&
|
|
|
|
<section>
|
|
|
|
<div className="form-group">
|
|
|
|
<label>
|
|
|
|
{translate('TRANS_data')}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
className={`form-control ${valid
|
|
|
|
? 'is-valid'
|
|
|
|
: 'is-invalid'}`}
|
|
|
|
type="text"
|
2017-07-04 00:16:20 +00:00
|
|
|
placeholder={readOnly ? '' : donationAddressMap.ETH}
|
2017-07-02 05:49:06 +00:00
|
|
|
value={value || ''}
|
|
|
|
disabled={readOnly}
|
|
|
|
onChange={this.onChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</section>}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-06-26 22:27:55 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public expand = () => {
|
2017-07-02 05:49:06 +00:00
|
|
|
this.setState({ expanded: true });
|
|
|
|
};
|
2017-06-26 22:27:55 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public onChange = (e: React.SyntheticEvent<HTMLInputElement>) => {
|
2017-07-02 05:49:06 +00:00
|
|
|
if (this.props.onChange) {
|
2017-09-25 02:06:28 +00:00
|
|
|
this.props.onChange((e.target as HTMLInputElement).value);
|
2017-07-02 05:49:06 +00:00
|
|
|
}
|
|
|
|
};
|
2017-06-26 22:27:55 +00:00
|
|
|
}
|