Register and resolve
This commit is contained in:
parent
5edbe10ad3
commit
853a655a84
|
@ -1,5 +1,6 @@
|
||||||
import React, {Component} from 'react';
|
import React, {Component} from 'react';
|
||||||
import {
|
import {
|
||||||
|
Alert,
|
||||||
Button,
|
Button,
|
||||||
Form
|
Form
|
||||||
} from "tabler-react";
|
} from "tabler-react";
|
||||||
|
@ -10,18 +11,29 @@ class EnsLookup extends Component {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
address: ''
|
address: '',
|
||||||
|
showResult: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChange(e) {
|
handleChange(e) {
|
||||||
this.setState({address: e.target.value});
|
this.setState({address: e.target.value, showResult: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleLookup() {
|
handleLookup() {
|
||||||
|
this.setState({showResult: true});
|
||||||
this.props.lookup(this.state.address);
|
this.props.lookup(this.state.address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showResult() {
|
||||||
|
let ensRecord = this.props.ensRecords.find((record) => record.address === this.state.address);
|
||||||
|
if (ensRecord) {
|
||||||
|
return <Alert type="success">The name is: {ensRecord.name}</Alert>;
|
||||||
|
} else {
|
||||||
|
return <Alert type="danger">We could not find a name for this address</Alert>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
@ -31,6 +43,7 @@ class EnsLookup extends Component {
|
||||||
<Form.Input placeholder="Enter an address" onChange={e => this.handleChange(e)}/>
|
<Form.Input placeholder="Enter an address" onChange={e => this.handleChange(e)}/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Button color="primary" onClick={() => this.handleLookup()}>Lookup</Button>
|
<Button color="primary" onClick={() => this.handleLookup()}>Lookup</Button>
|
||||||
|
{this.state.showResult && this.showResult()}
|
||||||
</Form.FieldSet>
|
</Form.FieldSet>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
|
@ -38,7 +51,8 @@ class EnsLookup extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
EnsLookup.propTypes = {
|
EnsLookup.propTypes = {
|
||||||
lookup: PropTypes.func
|
lookup: PropTypes.func,
|
||||||
|
ensRecords: PropTypes.arrayOf(PropTypes.object)
|
||||||
};
|
};
|
||||||
|
|
||||||
export default EnsLookup;
|
export default EnsLookup;
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
import React from 'react';
|
|
||||||
import {
|
|
||||||
Page,
|
|
||||||
Grid,
|
|
||||||
Card,
|
|
||||||
Table
|
|
||||||
} from "tabler-react";
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
|
|
||||||
const EnsRecords = ({ensRecords}) => (
|
|
||||||
<Page.Content title="Records">
|
|
||||||
<Grid.Row>
|
|
||||||
<Grid.Col>
|
|
||||||
<Card>
|
|
||||||
<Table
|
|
||||||
responsive
|
|
||||||
className="card-table table-vcenter text-nowrap"
|
|
||||||
headerItems={[
|
|
||||||
{content: "Name"},
|
|
||||||
{content: "Address"}
|
|
||||||
]}
|
|
||||||
bodyItems={
|
|
||||||
ensRecords.map((ensRecord) => {
|
|
||||||
return ([
|
|
||||||
{content: ensRecord.name},
|
|
||||||
{content: ensRecord.address}
|
|
||||||
]);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</Card>
|
|
||||||
</Grid.Col>
|
|
||||||
</Grid.Row>
|
|
||||||
</Page.Content>
|
|
||||||
);
|
|
||||||
|
|
||||||
EnsRecords.propTypes = {
|
|
||||||
ensRecords: PropTypes.arrayOf(PropTypes.object)
|
|
||||||
};
|
|
||||||
|
|
||||||
export default EnsRecords;
|
|
|
@ -1,5 +1,6 @@
|
||||||
import React, {Component} from 'react';
|
import React, {Component} from 'react';
|
||||||
import {
|
import {
|
||||||
|
Alert,
|
||||||
Button,
|
Button,
|
||||||
Form, Grid
|
Form, Grid
|
||||||
} from "tabler-react";
|
} from "tabler-react";
|
||||||
|
@ -11,18 +12,30 @@ class EnsRegister extends Component {
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
name: '',
|
name: '',
|
||||||
address: ''
|
address: '',
|
||||||
|
showResult: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChange(e, name) {
|
handleChange(e, name) {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
showResult: false,
|
||||||
[name]: e.target.value
|
[name]: e.target.value
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRegister() {
|
handleRegister() {
|
||||||
this.props.register(this.state.name, this.state.address);
|
this.props.register(this.state.name, this.state.address);
|
||||||
|
this.setState({showResult: true});
|
||||||
|
}
|
||||||
|
|
||||||
|
showResult() {
|
||||||
|
let ensRecord = this.props.ensRecords.find((record) => record.address === this.state.address && record.name === this.state.name);
|
||||||
|
if (ensRecord) {
|
||||||
|
return <Alert type="success">Successfully registered</Alert>;
|
||||||
|
} else {
|
||||||
|
return <Alert type="danger">An error happened</Alert>;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
|
@ -44,13 +57,15 @@ class EnsRegister extends Component {
|
||||||
</Grid.Row>
|
</Grid.Row>
|
||||||
<Button color="primary" onClick={() => this.handleRegister()}>Register</Button>
|
<Button color="primary" onClick={() => this.handleRegister()}>Register</Button>
|
||||||
</Form.FieldSet>
|
</Form.FieldSet>
|
||||||
|
{this.state.showResult && this.showResult()}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EnsRegister.propTypes = {
|
EnsRegister.propTypes = {
|
||||||
register: PropTypes.func
|
register: PropTypes.func,
|
||||||
|
ensRecords: PropTypes.arrayOf(PropTypes.object)
|
||||||
};
|
};
|
||||||
|
|
||||||
export default EnsRegister;
|
export default EnsRegister;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import React, {Component} from 'react';
|
import React, {Component} from 'react';
|
||||||
import {
|
import {
|
||||||
|
Alert,
|
||||||
Button,
|
Button,
|
||||||
Form
|
Form
|
||||||
} from "tabler-react";
|
} from "tabler-react";
|
||||||
|
@ -10,18 +11,29 @@ class EnsResolve extends Component {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
name: ''
|
name: '',
|
||||||
|
showResult: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChange(e) {
|
handleChange(e) {
|
||||||
this.setState({name: e.target.value});
|
this.setState({name: e.target.value, showResult: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleResolve() {
|
handleResolve() {
|
||||||
|
this.setState({showResult: true});
|
||||||
this.props.resolve(this.state.name);
|
this.props.resolve(this.state.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showResult() {
|
||||||
|
let ensRecord = this.props.ensRecords.find((record) => record.name === this.state.name);
|
||||||
|
if (ensRecord) {
|
||||||
|
return <Alert type="success">The address is: {ensRecord.address}</Alert>;
|
||||||
|
} else {
|
||||||
|
return <Alert type="danger">We could not find an address for this name</Alert>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
@ -31,6 +43,7 @@ class EnsResolve extends Component {
|
||||||
<Form.Input placeholder="Enter a name" onChange={e => this.handleChange(e)}/>
|
<Form.Input placeholder="Enter a name" onChange={e => this.handleChange(e)}/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Button color="primary" onClick={() => this.handleResolve()}>Resolve</Button>
|
<Button color="primary" onClick={() => this.handleResolve()}>Resolve</Button>
|
||||||
|
{this.state.showResult && this.showResult()}
|
||||||
</Form.FieldSet>
|
</Form.FieldSet>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
|
@ -38,7 +51,8 @@ class EnsResolve extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
EnsResolve.propTypes = {
|
EnsResolve.propTypes = {
|
||||||
resolve: PropTypes.func
|
resolve: PropTypes.func,
|
||||||
|
ensRecords: PropTypes.arrayOf(PropTypes.object)
|
||||||
};
|
};
|
||||||
|
|
||||||
export default EnsResolve;
|
export default EnsResolve;
|
||||||
|
|
|
@ -3,11 +3,9 @@ import React, {Component} from 'react';
|
||||||
import connect from "react-redux/es/connect/connect";
|
import connect from "react-redux/es/connect/connect";
|
||||||
import {Alert, Page} from "tabler-react";
|
import {Alert, Page} from "tabler-react";
|
||||||
import {ensRecord, ensRecords} from "../actions";
|
import {ensRecord, ensRecords} from "../actions";
|
||||||
import DataWrapper from "../components/DataWrapper";
|
|
||||||
import EnsRegister from "../components/EnsRegister";
|
import EnsRegister from "../components/EnsRegister";
|
||||||
import EnsLookup from "../components/EnsLookup";
|
import EnsLookup from "../components/EnsLookup";
|
||||||
import EnsResolve from "../components/EnsResolve";
|
import EnsResolve from "../components/EnsResolve";
|
||||||
import EnsRecords from "../components/EnsRecords";
|
|
||||||
import {getEnsRecords, isEnsEnabled} from "../reducers/selectors";
|
import {getEnsRecords, isEnsEnabled} from "../reducers/selectors";
|
||||||
|
|
||||||
class EnsContainer extends Component {
|
class EnsContainer extends Component {
|
||||||
|
@ -15,12 +13,9 @@ class EnsContainer extends Component {
|
||||||
showEns() {
|
showEns() {
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<EnsLookup lookup={this.props.lookup}/>
|
<EnsLookup lookup={this.props.lookup} ensRecords={this.props.ensRecords}/>
|
||||||
<EnsResolve resolve={this.props.resolve}/>
|
<EnsResolve resolve={this.props.resolve} ensRecords={this.props.ensRecords}/>
|
||||||
<EnsRegister register={this.props.register}/>
|
<EnsRegister register={this.props.register} ensRecords={this.props.ensRecords}/>
|
||||||
<DataWrapper shouldRender={this.props.ensRecords.length > 0} {...this.props} render={({ensRecords}) => (
|
|
||||||
<EnsRecords ensRecords={ensRecords} />
|
|
||||||
)} />
|
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue