From 2c853c6b0c4f09497700e83408e6d62b98b8070c Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Tue, 22 May 2018 16:40:56 -0400 Subject: [PATCH] add domain component --- app/components/ens/addDomain.js | 73 ++++++++++++++++++++++++++++++ app/components/ensSubManagement.js | 2 +- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 app/components/ens/addDomain.js diff --git a/app/components/ens/addDomain.js b/app/components/ens/addDomain.js new file mode 100644 index 0000000..c45e12c --- /dev/null +++ b/app/components/ens/addDomain.js @@ -0,0 +1,73 @@ +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) + +setTimeout(() => {ENSSubdomainRegistry.methods.controller().call().then(console.log)}, 2000) +export default AddDomain; diff --git a/app/components/ensSubManagement.js b/app/components/ensSubManagement.js index ab39e2b..189dde7 100644 --- a/app/components/ensSubManagement.js +++ b/app/components/ensSubManagement.js @@ -14,7 +14,7 @@ const FieldGroup = ({ id, label, help, ...props }) => ( const ENSSubManagement = (props) => ( -

Subdomain management

+

Subdomain Management

Add Domain