/*global web3*/ import EmbarkJS from 'Embark/EmbarkJS'; import React from 'react'; import { Alert, Form, FormGroup, FormControl, Button } from 'react-bootstrap'; window.EmbarkJS = EmbarkJS; class ENS extends React.Component { constructor(props) { super(props); this.state = { valueResolve: 'embark.eth', responseResolve: null, isResolveError: false, valueLookup: '', responseLookup: null, isLookupError: false, valueRegister: '', addressRegister: '', responseRegister: null, isRegisterError: false, embarkLogs: [] }; } componentDidMount() { EmbarkJS.onReady(() => { if (!web3.eth.defaultAccount) { this.setState({ globalError: 'There is currently no default account. If Metamask is active, please sign in or deactivate it.' }); } this.setState({ addressRegister: web3.eth.defaultAccount, valueLookup: web3.eth.defaultAccount }) }); } handleChange(stateName, e) { this.setState({ [stateName]: e.target.value }); } registerSubDomain(e) { e.preventDefault(); const self = this; const embarkLogs = this.state.embarkLogs; embarkLogs.push(`EmbarkJS.Names.registerSubDomain('${this.state.valueRegister}', '${this.state.addressRegister}', console.log)`); this.setState({ embarkLogs: embarkLogs }); EmbarkJS.Names.registerSubDomain(this.state.valueRegister, this.state.addressRegister, (err, transaction) => { const message = err ? err : `Successfully registered "${this.state.valueRegister}" with ${transaction.gasUsed} gas`; self.setState({ responseRegister: message, isRegisterError: !!err }); }); } resolveName(e) { e.preventDefault(); const embarkLogs = this.state.embarkLogs; embarkLogs.push(`EmbarkJS.Names.resolve('${this.state.valueResolve}', console.log)`); this.setState({ embarkLogs: embarkLogs }); EmbarkJS.Names.resolve(this.state.valueResolve, (err, result) => { if (err) { return this.setState({ responseResolve: err.message || err, isResolveError: true }); } this.setState({ responseResolve: result, isResolveError: false }); }); } lookupAddress(e) { e.preventDefault(); const embarkLogs = this.state.embarkLogs; embarkLogs.push(`EmbarkJS.Names.resolve('${this.state.valueLookup}', console.log)`); this.setState({ embarkLogs: embarkLogs }); EmbarkJS.Names.lookup(this.state.valueLookup, (err, result) => { if (err) { return this.setState({ responseLookup: err.message || err, isLookupError: true }); } this.setState({ responseLookup: result, isLookupError: false }); }); } render() { return ( {this.state.globalError && {this.state.globalError}}

Resolve a name

{this.state.responseResolve && Resolved address: {this.state.responseResolve} } this.handleChange('valueResolve', e)}/>

Lookup an address

{this.state.responseLookup && Looked up domain: {this.state.responseLookup} } this.handleChange('valueLookup', e)}/>

Register subdomain for embark

{this.state.responseRegister && {this.state.responseRegister} } this.handleChange('valueRegister', e)}/> this.handleChange('addressRegister', e)}/>

Embark Calls

Javascript calls being made:

{ this.state.embarkLogs.map((item, i) =>

{item}

) }
); } } export default ENS;