diff --git a/templates/demo/app/components/ens.js b/templates/demo/app/components/ens.js index 73260272e..5b87e3464 100644 --- a/templates/demo/app/components/ens.js +++ b/templates/demo/app/components/ens.js @@ -1,6 +1,7 @@ +/*global web3*/ import EmbarkJS from 'Embark/EmbarkJS'; import React from 'react'; -import {Alert, Form, FormGroup, FormControl, Button} from 'react-bootstrap'; +import { Alert, Form, FormGroup, FormControl, Button } from 'react-bootstrap'; window.EmbarkJS = EmbarkJS; @@ -10,18 +11,49 @@ class ENS extends React.Component { super(props); this.state = { - valueResolve: 'ethereumfoundation.eth', + valueResolve: 'embark.eth', responseResolve: null, isResolveError: false, - valueLookup: '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359', + valueLookup: '', responseLookup: null, isLookupError: false, + valueRegister: '', + addressRegister: '', + responseRegister: null, + isRegisterError: false, embarkLogs: [] }; } + componentWillMount() { + EmbarkJS.onReady(() => { + this.setState({ + addressRegister: web3.eth.defaultAccount, + valueLookup: web3.eth.defaultAccount + }) + }); + } + handleChange(stateName, e) { - this.setState({[stateName]: e.target.value}); + 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) { @@ -35,7 +67,7 @@ class ENS extends React.Component { EmbarkJS.Names.resolve(this.state.valueResolve, (err, result) => { if (err) { return this.setState({ - responseResolve: err, + responseResolve: err.message || err, isResolveError: true }); } @@ -57,7 +89,7 @@ class ENS extends React.Component { EmbarkJS.Names.lookup(this.state.valueLookup, (err, result) => { if (err) { return this.setState({ - responseLookup: err, + responseLookup: err.message || err, isLookupError: true }); } @@ -70,12 +102,6 @@ class ENS extends React.Component { render() { return ( - { - !this.props.enabled ? - - ENS provider might not be set - : '' - }

Resolve a name

@@ -106,6 +132,25 @@ class ENS extends React.Component {
+

Register subdomain for embark

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

Embark Calls

Javascript calls being made:

diff --git a/templates/demo/config/namesystem.js b/templates/demo/config/namesystem.js index 10e20d6b3..1b2958434 100644 --- a/templates/demo/config/namesystem.js +++ b/templates/demo/config/namesystem.js @@ -1,6 +1,12 @@ module.exports = { default: { available_providers: ["ens"], - provider: "ens" + provider: "ens", + register: { + rootDomain: "embark.eth", + domains: { + 'status': '0x1a2f3b98e434c02363f3dac3174af93c1d690914' + } + } } };