/*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: '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 }); } checkEnter(e, func) { if (e.key !== 'Enter') { return; } e.preventDefault(); func.apply(this, [e]); } 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.checkEnter(e, this.resolveName)}> {this.state.responseResolve && Resolved address: {this.state.responseResolve} } this.handleChange('valueResolve', e)}/>

Lookup an address

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

Register subdomain for embark

this.checkEnter(e, this.registerSubDomain)}> {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;