lbry-desktop/src/renderer/component/walletSend/view.jsx

98 lines
2.9 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import React from 'react';
2018-03-26 23:32:43 +02:00
import Button from 'component/button';
import { Form, FormRow, FormField } from 'component/common/form';
import { Formik } from 'formik';
import { validateSendTx } from 'util/form-validation';
2018-03-26 23:32:43 +02:00
type DraftTransaction = {
address: string,
amount: number | string, // So we can use a placeholder in the input
};
2018-03-26 23:32:43 +02:00
type Props = {
sendToAddress: DraftTransaction => void,
balance: number,
};
class WalletSend extends React.PureComponent<Props> {
constructor() {
super();
(this: any).handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit(values: DraftTransaction) {
const { sendToAddress } = this.props;
sendToAddress(values);
}
render() {
2018-03-26 23:32:43 +02:00
const { balance } = this.props;
return (
2018-03-26 23:32:43 +02:00
<section className="card card--section">
<div className="card__title">{__('Send Credits')}</div>
<div className="card__content">
<Formik
initialValues={{
address: '',
amount: '',
}}
onSubmit={this.handleSubmit}
validate={validateSendTx}
render={({ values, errors, touched, handleChange, handleBlur, handleSubmit }) => (
<Form onSubmit={handleSubmit}>
<FormRow>
<FormField
type="number"
name="amount"
label={__('Amount')}
postfix={__('LBC')}
className="input--price-amount"
min="0"
step="any"
2018-03-26 23:32:43 +02:00
onChange={handleChange}
onBlur={handleBlur}
value={values.amount}
error={
(!!values.amount && touched.amount && errors.amount) ||
(values.amount > balance && __('Not enough'))
}
/>
<FormField
type="text"
name="address"
placeholder="bbFxRyXXXXXXXXXXXZD8nE7XTLUxYnddTs"
className="input--address"
label={__('Recipient address')}
error={!!values.address && touched.address && errors.address}
onChange={handleChange}
onBlur={handleBlur}
value={values.address}
/>
</FormRow>
<div className="card__actions">
<Button
button="primary"
type="submit"
label={__('Send')}
disabled={
!values.address ||
!!Object.keys(errors).length ||
!(parseFloat(values.amount) > 0.0)
}
/>
</div>
</Form>
)}
/>
</div>
</section>
);
}
}
2017-06-06 06:21:55 +02:00
export default WalletSend;