pass back addresses to register component

This commit is contained in:
Barry Gitarts 2018-06-11 15:55:42 -04:00
parent 6b0f196d1f
commit 89f84a4991
2 changed files with 33 additions and 18 deletions

View File

@ -10,8 +10,10 @@ import { CopyToClipboard } from 'react-copy-to-clipboard';
import RegisterSubDomain from '../ens/registerSubDomain';
const { getPrice } = ENSSubdomainRegistry.methods;
const invalidSuffix = '0000000000000000000000000000000000000000'
const nullAddress = '0x0000000000000000000000000000000000000000'
const validAddress = address => address != nullAddress;
const validStatusAddress = address => !address.includes(invalidSuffix);
const formatName = domainName => domainName.includes('.') ? domainName : `${domainName}.stateofus.eth`;
const getDomain = fullDomain => formatName(fullDomain).split('.').slice(1).join('.');
const hashedDomain = domainName => hash(getDomain(domainName));
@ -48,12 +50,18 @@ class Register extends PureComponent {
render() {
const { domainName, setStatus } = this.props;
const { domainPrice } = this.state;
const formattedDomain = formatName(domainName);
const formattedDomainArray = formattedDomain.split('.')
return (
<Fragment>
<Info.Action title="No address is associated with this domain">
{formatName(domainName.toUpperCase())} can be registered for {domainPrice} SNT
{formattedDomain.toUpperCase()} can be registered for {domainPrice} SNT
</Info.Action>
<RegisterSubDomain />
<RegisterSubDomain
subDomain={formattedDomainArray[0]}
domainName={formattedDomainArray.slice(1).join('.')}
domainPrice={domainPrice}
registeredCallbackFn={(address, statusAccount) => this.setState({ registered: { address, statusAccount } })} />
<div style={backButton} onClick={() => setStatus(null)}>&larr;</div>
</Fragment>
)
@ -73,15 +81,15 @@ class DisplayAddress extends PureComponent {
<Fragment>
{validAddress(address) ?
<div style={{ display: 'flex', flexDirection: 'column' }}>
<Info.Action title="Click to copy"><b>{domainName.toUpperCase()}</b> Resolves To:</Info.Action>
<Info.Action title="Click to copy"><b>{formatName(domainName).toUpperCase()}</b> Resolves To:</Info.Action>
{address && <Text style={{ marginTop: '1em' }}>Ethereum Address {renderCopied(address)}</Text>}
<CopyToClipboard text={address} onCopy={markCopied}>
<div style={addressStyle}>{address}</div>
</CopyToClipboard>
{statusAccount && <Text style={{ marginTop: '1em' }}>Status Address {renderCopied(statusAccount)}</Text>}
<CopyToClipboard text={statusAccount} onCopy={markCopied}>
{validStatusAddress(statusAccount) && <Text style={{ marginTop: '1em' }}>Status Address {renderCopied(statusAccount)}</Text>}
{validStatusAddress(statusAccount) && <CopyToClipboard text={statusAccount} onCopy={markCopied}>
<div style={{ ...addressStyle, color: isCopied ? theme.primary : null }}>{statusAccount}</div>
</CopyToClipboard>
</CopyToClipboard>}
</div>
:
<Info.Action title="No address is associated with this domain">

View File

@ -19,9 +19,12 @@ const InnerForm = ({
handleSubmit,
isSubmitting,
setFieldValue,
subDomain,
domainName,
domainPrice,
}) => (
<form onSubmit={handleSubmit}>
<FieldGroup
{!subDomain && <FieldGroup
id="subDomain"
name="subDomain"
type="text"
@ -30,8 +33,8 @@ const InnerForm = ({
onBlur={handleBlur}
value={values.subDomain}
error={errors.subDomain}
/>
<FieldGroup
/>}
{!domainName && <FieldGroup
id="domainName"
name="domainName"
type="text"
@ -51,13 +54,13 @@ const InnerForm = ({
Get Price
</Button>
}
/>
<FieldGroup
/>}
{!domainPrice && <FieldGroup
id="price"
name="price"
label="Domain Price"
disabled
value={values.price ? `${Number(values.price).toLocaleString()} SNT` : ''} />
value={values.price ? `${Number(values.price).toLocaleString()} SNT` : ''} />}
<FieldGroup
id="statusAddress"
name="statusAddress"
@ -67,7 +70,7 @@ const InnerForm = ({
onBlur={handleBlur}
value={values.statusAddress}
error={errors.statusAddress}
wide='true'
wide="true"
/>
<FieldGroup
id="address"
@ -86,19 +89,22 @@ const InnerForm = ({
const RegisterSubDomain = withFormik({
mapPropsToValues: props => ({ subDomain: '', domainName: '', price: '' }),
validate(values) {
validate(values, props) {
const errors = {};
const { address, subDomain } = values;
const { address } = values;
const { subDomain } = props || values;
if (address && !web3.utils.isAddress(address)) errors.address = 'Not a valid address';
if (!subDomain) errors.subDomain = 'Required';
return errors;
},
handleSubmit(values, { setSubmitting }) {
const { subDomain, domainName, address, statusAddress } = values;
handleSubmit(values, { setSubmitting, props }) {
const { address, statusAddress } = values;
const { subDomain, domainName, registeredCallbackFn } = props || values;
const { methods: { register } } = ENSSubdomainRegistry;
const subdomainHash = soliditySha3(subDomain);
const domainNameHash = hash(domainName);
const resolveToAddr = address || zeroAddress;
const resolveToStatusAddr = statusAddress || zeroBytes32;
const toSend = register(
subdomainHash,
@ -106,7 +112,7 @@ const RegisterSubDomain = withFormik({
resolveToAddr,
zeroBytes32,
zeroBytes32,
statusAddress || zeroBytes32
resolveToStatusAddr,
);
toSend.estimateGas().then(gasEstimated => {
console.log("Register would work. :D Gas estimated: "+gasEstimated)
@ -122,6 +128,7 @@ const RegisterSubDomain = withFormik({
console.log("Register send errored. :( Out of gas?")
console.dir(err)
}).finally(() => {
registeredCallbackFn(resolveToAddr, resolveToStatusAddr);
setSubmitting(false);
});
}).catch(err => {