convert nameLookup to formik with handleSubmit

remove debugTable from addDomain
This commit is contained in:
Barry Gitarts 2018-06-05 16:48:30 -04:00
parent b0439c6ce1
commit ca3669224f
3 changed files with 38 additions and 27 deletions

View File

@ -69,21 +69,6 @@ const AddDomain = withFormik({
const { methods: { domains, setDomainPrice, updateDomainPrice } } = ENSSubdomainRegistry
const { sha3 } = window.web3.utils
const hashedDomain = hash(domainName)
const debugTable = await ['eth', 'stateofus', 'stateofus.eth', 'freedomain', 'freedomain.eth', domainName]
.map(async str => {
const result = {};
result['domainName'] = str;
result['sha3Result'] = await getDomain(sha3(str), domains);
result['sha3State'] = result.sha3Result.state
result['sha3Price'] = result.sha3Result.price
result['nameHashResult'] = await getDomain(hash(str), domains);
result['nameHashState'] = result['nameHashResult'].state
result['nameHashPrice'] = result['nameHashResult'].price
result['sha3String'] = sha3(str);
result['nameHashString'] = hash(str);
return result;
})
Promise.all(debugTable).then(v => { console.table(v) });
const { state } = await getDomain(hashedDomain, domains);
setPrice(
!!Number(state) ? updateDomainPrice : setDomainPrice,

View File

@ -1,21 +1,52 @@
import React, { Fragment } from 'react';
import { Button, Field, TextInput, Card } from '../../ui/components'
import { withFormik } from 'formik';
import PublicResolver from 'Embark/contracts/PublicResolver';
import { hash } from 'eth-ens-namehash';
const formatName = domainName => domainName.includes('.') ? domainName : `${domainName}.stateofus.eth`;
const cardStyle = {
width: '75%',
marginLeft: '15%',
padding: '30px'
}
const NameLookup = () => (
const InnerForm = ({
values,
errors,
touched,
handleChange,
handleBlur,
handleSubmit,
isSubmitting,
}) => (
<Card style={cardStyle}>
<Field label="Enter Domain or Status Name" wide>
<TextInput wide required />
</Field>
<Button mode="strong" type="submit" wide>
Get Address
</Button>
<form onSubmit={handleSubmit}>
<Field label="Enter Domain or Status Name" wide>
<TextInput
value={values.domainName}
name="domainName"
onChange={handleChange}
wide
required />
</Field>
<Button mode="strong" type="submit" wide>
Get Address
</Button>
</form>
</Card>
)
const NameLookup = withFormik({
mapPropsToValues: props => ({ domainName: '' }),
handleSubmit(values, { setSubmitting }) {
const { domainName } = values;
PublicResolver.methods.addr(hash(formatName(domainName)))
.call()
.then(res =>{
console.log('addr', res);
});
}
})(InnerForm)
export default NameLookup;

View File

@ -1,7 +1,6 @@
import EmbarkJS from 'Embark/EmbarkJS';
import ENSRegistry from 'Embark/contracts/ENSRegistry';
import ENSSubdomainRegistry from 'Embark/contracts/ENSSubdomainRegistry';
import PublicResolver from 'Embark/contracts/PublicResolver';
import TestToken from 'Embark/contracts/TestToken';
import React, { Fragment } from 'react';
import { Form, FormGroup, FormControl, HelpBlock, Button, ControlLabel } from 'react-bootstrap';
@ -9,7 +8,6 @@ import AddDomain from './ens/addDomain';
import RegisterSubDomain from './ens/registerSubDomain';
import TokenPermissions from './standard/TokenPermission';
import SetupENS from './ens/setupENS';
import { hash } from 'eth-ens-namehash';
const FieldGroup = ({ id, label, help, ...props }) => (
<FormGroup controlId={id}>
@ -40,9 +38,6 @@ setTimeout(() => ENSRegistry.getPastEvents(
'allEvents',
{},
(err, res) => {
PublicResolver.methods.addr(hash('bobby.stateofus.eth')).call().then(res =>{
console.log('addr', res);
});
console.log(err, res) }), 2000)
export default ENSSubManagement;