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