71 lines
1.8 KiB
React
Raw Normal View History

2017-06-27 02:27:55 +04:00
// @flow
import React from 'react';
import translate from 'translations';
import UnitDropdown from './UnitDropdown';
type Props = {
2017-07-02 00:49:06 -05:00
value: string,
unit: string,
2017-07-16 03:05:57 +04:00
tokens: string[],
2017-07-02 00:49:06 -05:00
onChange?: (value: string, unit: string) => void
2017-06-27 02:27:55 +04:00
};
export default class AmountField extends React.Component {
2017-07-02 00:49:06 -05:00
props: Props;
2017-06-27 02:27:55 +04:00
2017-07-02 00:49:06 -05:00
render() {
const { value, unit, onChange } = this.props;
const isReadonly = !onChange;
return (
<div>
2017-07-16 03:05:57 +04:00
<label>
{translate('SEND_amount')}
</label>
2017-07-02 00:49:06 -05:00
<div className="input-group col-sm-11">
<input
2017-07-16 03:05:57 +04:00
className={`form-control ${isFinite(Number(value)) && Number(value) > 0
2017-07-02 00:49:06 -05:00
? 'is-valid'
: 'is-invalid'}`}
type="text"
placeholder={translate('SEND_amount_short')}
value={value}
disabled={isReadonly}
onChange={isReadonly ? void 0 : this.onValueChange}
/>
<UnitDropdown
value={unit}
2017-07-16 03:05:57 +04:00
options={['ether'].concat(this.props.tokens)}
2017-07-02 00:49:06 -05:00
onChange={isReadonly ? void 0 : this.onUnitChange}
/>
</div>
{!isReadonly &&
<p>
<a onClick={this.onSendEverything}>
<span className="strong">
{translate('SEND_TransferTotal')}
</span>
</a>
</p>}
</div>
);
}
2017-06-27 02:27:55 +04:00
2017-07-02 00:49:06 -05:00
onUnitChange = (unit: string) => {
if (this.props.onChange) {
this.props.onChange(this.props.value, unit);
}
};
2017-06-27 02:27:55 +04:00
2017-07-02 00:49:06 -05:00
onValueChange = (e: SyntheticInputEvent) => {
if (this.props.onChange) {
this.props.onChange(e.target.value, this.props.unit);
}
};
2017-06-27 02:27:55 +04:00
2017-07-02 00:49:06 -05:00
onSendEverything = () => {
if (this.props.onChange) {
this.props.onChange('everything', this.props.unit);
}
};
2017-06-27 02:27:55 +04:00
}