From 083bafcd6ff9cdf7cb3f0f46f579e3f5d44c956e Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Fri, 10 Aug 2018 19:49:26 -0400 Subject: [PATCH] add updateController and moveDomain to admin utils --- app/components/ens/moveDomain.js | 74 ++++++++++++++++++++++++++ app/components/ens/updateController.js | 56 +++++++++++++++++++ app/components/ensSubManagement.js | 3 ++ 3 files changed, 133 insertions(+) create mode 100644 app/components/ens/moveDomain.js create mode 100644 app/components/ens/updateController.js diff --git a/app/components/ens/moveDomain.js b/app/components/ens/moveDomain.js new file mode 100644 index 0000000..0d35cf4 --- /dev/null +++ b/app/components/ens/moveDomain.js @@ -0,0 +1,74 @@ +import ENSSubdomainRegistry from 'Embark/contracts/ENSSubdomainRegistry'; +import web3 from 'web3'; +import React from 'react'; +import { hash } from 'eth-ens-namehash'; +import { Button } from 'react-bootstrap'; +import FieldGroup from '../standard/FieldGroup'; +import { withFormik } from 'formik'; + +const InnerForm = ({ + values, + errors, + handleChange, + handleBlur, + handleSubmit, + isSubmitting, +}) => ( +
+ + + + +) + +const MoveDomain = withFormik({ + mapPropsToValues: props => ({ newAddress: '' }), + async validate(values) { + const { utils: { isAddress } } = web3; + const { newAddress } = values; + const errors = {}; + if (!isAddress(newAddress)) errors.newAddress = 'Please enter a valid address' + if (Object.keys(errors).length) throw errors; + }, + async handleSubmit(values, { setSubmitting }) { + const { newAddress, domainName } = values; + const { methods: { moveDomain } } = ENSSubdomainRegistry; + const hashedDomain = hash(domainName); + console.log( + `inputs for moveDomain of domain name: ${domainName}`, + newAddress, + hashedDomain, + ); + + moveDomain(newAddress, hashedDomain) + .send() + .then((res) => { + setSubmitting(false); + console.log(res); + }) + .catch((err) => { + setSubmitting(false); + console.log(err); + }) + } +})(InnerForm); + +export default MoveDomain; diff --git a/app/components/ens/updateController.js b/app/components/ens/updateController.js new file mode 100644 index 0000000..3212d79 --- /dev/null +++ b/app/components/ens/updateController.js @@ -0,0 +1,56 @@ +import ENSSubdomainRegistry from 'Embark/contracts/ENSSubdomainRegistry'; +import web3 from 'web3'; +import React from 'react'; +import { Button } from 'react-bootstrap'; +import FieldGroup from '../standard/FieldGroup'; +import { withFormik } from 'formik'; + +const InnerForm = ({ + values, + errors, + handleChange, + handleBlur, + handleSubmit, + isSubmitting, +}) => ( +
+ + + +) + +const UpdateController = withFormik({ + mapPropsToValues: props => ({ newAddress: '' }), + async validate(values) { + const { utils: { isAddress } } = web3; + const { newAddress } = values; + const errors = {}; + if (!isAddress(newAddress)) errors.newAddress = 'Please enter a valid address' + if (Object.keys(errors).length) throw errors; + }, + async handleSubmit(values, { setSubmitting }) { + const { newAddress } = values; + const { methods: { changeController } } = ENSSubdomainRegistry; + changeController(newAddress) + .send() + .then((res) => { + setSubmitting(false); + console.log(res); + }) + .catch((err) => { + setSubmitting(false); + console.log(err); + }) + } +})(InnerForm); + +export default UpdateController; diff --git a/app/components/ensSubManagement.js b/app/components/ensSubManagement.js index b08e784..ef6c3cf 100644 --- a/app/components/ensSubManagement.js +++ b/app/components/ensSubManagement.js @@ -5,6 +5,7 @@ import TestToken from 'Embark/contracts/TestToken'; import React, { Fragment } from 'react'; import { Form, FormGroup, FormControl, HelpBlock, Button, ControlLabel } from 'react-bootstrap'; import AddDomain from './ens/addDomain'; +import MoveDomain from './ens/moveDomain'; import RegisterSubDomain from './ens/registerSubDomain'; import TokenPermissions from './standard/TokenPermission'; import SetupENS from './ens/setupENS'; @@ -25,6 +26,8 @@ const ENSSubManagement = props => (

Add/Update Domain Price

+

Move Domain To Another Registry

+

Register Sub-Domain