import React, { Fragment, PureComponent } from 'react'; import { Button, Field, TextInput, Card, Info, Text } from '../../ui/components' import theme from '../../ui/theme' import { withFormik } from 'formik'; import PublicResolver from 'Embark/contracts/PublicResolver'; import { hash } from 'eth-ens-namehash'; import { CopyToClipboard } from 'react-copy-to-clipboard'; const nullAddress = '0x0000000000000000000000000000000000000000' const formatName = domainName => domainName.includes('.') ? domainName : `${domainName}.stateofus.eth`; const copiedText = { color: 'white', textAlign: 'center' } const cardStyle = { width: '75%', marginLeft: '15%', padding: '30px' } const addressStyle = { fontSize: '18px', fontWeight: 400, margin: '3% 0 3% 0', cursor: 'copy', textAlign: 'center', wordWrap: 'break-word' } const backButton = { fontSize: '40px', color: theme.accent, cursor: 'pointer' } class DisplayAddress extends PureComponent { state = { copied: false } render() { const { copied } = this.state const { domainName, address, statusAccount, setStatus } = this.props const markCopied = () => { this.setState({ copied: !copied }) } const validAddress = address != nullAddress; return ( {validAddress ?
{domainName.toUpperCase()} Resolves To:
{address}
{statusAccount}
{copied && COPIED }
: {domainName.toUpperCase()}}
setStatus(null)}>←
) } } const InnerForm = ({ values, errors, touched, handleChange, handleBlur, handleSubmit, isSubmitting, status, setStatus }) => ( {!status ?
: }
) const NameLookup = withFormik({ mapPropsToValues: props => ({ domainName: '' }), async handleSubmit(values, { status, setSubmitting, setStatus }) { const { domainName } = values; const { addr, text } = PublicResolver.methods; const lookupHash = hash(formatName(domainName)); const address = await addr(lookupHash).call(); const statusAccount = await text(lookupHash, 'statusAccount').call(); setStatus({ address, statusAccount }); } })(InnerForm) export default NameLookup;