add register in demo

This commit is contained in:
Jonathan Rainville 2018-07-23 17:11:41 -04:00 committed by Iuri Matias
parent 297128290a
commit 89421771ef
2 changed files with 64 additions and 13 deletions

View File

@ -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 (<React.Fragment>
{
!this.props.enabled ?
<React.Fragment>
<Alert bsStyle="warning">ENS provider might not be set</Alert>
</React.Fragment> : ''
}
<h3>Resolve a name</h3>
<Form inline>
<FormGroup>
@ -106,6 +132,25 @@ class ENS extends React.Component {
</FormGroup>
</Form>
<h3>Register subdomain for embark</h3>
<Form inline>
<FormGroup>
{this.state.responseRegister &&
<Alert className="alert-result" bsStyle={this.state.isRegisterError ? 'danger' : 'success'}>
<span className="value">{this.state.responseRegister}</span>
</Alert>}
<FormControl
type="text"
defaultValue={this.state.valueRegister}
onChange={(e) => this.handleChange('valueRegister', e)}/>
<FormControl
type="text"
defaultValue={this.state.addressRegister}
onChange={(e) => this.handleChange('addressRegister', e)}/>
<Button bsStyle="primary" onClick={(e) => this.registerSubDomain(e)}>Register subdomain</Button>
</FormGroup>
</Form>
<h3>Embark Calls </h3>
<p>Javascript calls being made: </p>
<div className="logs">

View File

@ -1,6 +1,12 @@
module.exports = {
default: {
available_providers: ["ens"],
provider: "ens"
provider: "ens",
register: {
rootDomain: "embark.eth",
domains: {
'status': '0x1a2f3b98e434c02363f3dac3174af93c1d690914'
}
}
}
};