import ENSSubdomainRegistry from 'Embark/contracts/ENSSubdomainRegistry';
import React, { Fragment } from 'react';
import { Form, FormGroup, FormControl, HelpBlock, Button, ControlLabel } from 'react-bootstrap';
import { withFormik } from 'formik';
import { hash } from 'eth-ens-namehash'
const FieldGroup = ({ id, label, error, ...props }) => (
{label}
{error && {error}}
)
const InnerForm = ({
values,
errors,
touched,
handleChange,
handleBlur,
handleSubmit,
isSubmitting,
}) => (
)
const AddDomain = withFormik({
mapPropsToValues: props => ({ domainName: '', domainPrice: '' }),
validate(values, props) {
const errors = {};
if (!values.domainName) errors.domainName = 'Required';
return errors;
},
handleSubmit(values, { setSubmitting }) {
const { domainName, domainPrice } = values
const { methods: { addDomain } } = ENSSubdomainRegistry
addDomain(hash(domainName), domainPrice || 0)
.send()
.then(res => {
setSubmitting(false);
console.log(res);
})
.catch(err => {
setSubmitting(false);
console.log(err);
})
}
})(InnerForm)
export default AddDomain;