add updateController and moveDomain to admin utils

This commit is contained in:
Barry Gitarts 2018-08-10 19:49:26 -04:00
parent 0fde3e1c1c
commit 083bafcd6f
3 changed files with 133 additions and 0 deletions

View File

@ -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,
}) => (
<form onSubmit={handleSubmit}>
<FieldGroup
id="newAddress"
name="newAddress"
type="text"
label="New Controller Address"
onChange={handleChange}
onBlur={handleBlur}
value={values.newAddress}
error={errors.newAddress}
/>
<FieldGroup
id="domainName"
name="domainName"
type="text"
label="Domain Name"
onChange={handleChange}
onBlur={handleBlur}
value={values.domainName}
error={errors.domainName}
/>
<Button bsStyle="primary" type="submit" disabled={isSubmitting || !!Object.keys(errors).length}>{!isSubmitting ? 'Submit' : 'Submitting to the Blockchain - (this may take awhile)'}</Button>
</form>
)
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;

View File

@ -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,
}) => (
<form onSubmit={handleSubmit}>
<FieldGroup
id="newAddress"
name="newAddress"
type="text"
label="New Controller Address"
onChange={handleChange}
onBlur={handleBlur}
value={values.newAddress}
error={errors.newAddress}
/>
<Button bsStyle="primary" type="submit" disabled={isSubmitting || !!Object.keys(errors).length}>{!isSubmitting ? 'Submit' : 'Submitting to the Blockchain - (this may take awhile)'}</Button>
</form>
)
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;

View File

@ -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 => (
<UpdateController />
<h3>Add/Update Domain Price</h3>
<AddDomain />
<h3>Move Domain To Another Registry</h3>
<MoveDomain />
<hr/>
<h3>Register Sub-Domain</h3>
<RegisterSubDomain />