2018-08-14 10:23:48 +01:00
|
|
|
import React, {Component} from 'react';
|
|
|
|
import {
|
2018-08-14 10:51:28 +01:00
|
|
|
Alert,
|
2018-08-14 10:23:48 +01:00
|
|
|
Button,
|
2018-10-12 12:23:02 +02:00
|
|
|
FormGroup,
|
|
|
|
Input,
|
|
|
|
Card,
|
|
|
|
CardHeader,
|
|
|
|
CardBody
|
|
|
|
} from "reactstrap";
|
2018-08-14 10:23:48 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
class EnsResolve extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2018-08-14 16:22:15 +01:00
|
|
|
name: '',
|
2018-08-14 10:51:28 +01:00
|
|
|
showResult: false
|
2018-08-14 10:23:48 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
handleChange(e) {
|
2018-08-14 16:22:15 +01:00
|
|
|
this.setState({name: e.target.value, showResult: false});
|
2018-08-14 10:23:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handleResolve() {
|
2018-08-14 10:51:28 +01:00
|
|
|
this.setState({showResult: true});
|
2018-08-14 16:22:15 +01:00
|
|
|
this.props.resolve(this.state.name);
|
2018-08-14 10:23:48 +01:00
|
|
|
}
|
|
|
|
|
2018-08-14 10:51:28 +01:00
|
|
|
showResult() {
|
2018-08-14 16:22:15 +01:00
|
|
|
let ensRecord = this.props.ensRecords.find((record) => record.name === this.state.name);
|
2018-08-14 10:51:28 +01:00
|
|
|
if (ensRecord) {
|
2018-10-12 12:23:02 +02:00
|
|
|
return <Alert className="mt-3" color="success">The address is: {ensRecord.address}</Alert>;
|
2018-08-14 10:51:28 +01:00
|
|
|
} else {
|
2018-10-12 12:23:02 +02:00
|
|
|
return <Alert className="mt-3" color="danger">We could not find an address for this name</Alert>;
|
2018-08-14 10:51:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:23:48 +01:00
|
|
|
render(){
|
|
|
|
return (
|
2018-10-12 12:23:02 +02:00
|
|
|
<Card>
|
|
|
|
<CardHeader>
|
|
|
|
<strong>ENS Resolver</strong>
|
|
|
|
</CardHeader>
|
|
|
|
<CardBody>
|
|
|
|
<FormGroup>
|
|
|
|
<Input placeholder="Enter a name" onChange={e => this.handleChange(e)}/>
|
|
|
|
</FormGroup>
|
2018-08-14 10:23:48 +01:00
|
|
|
<Button color="primary" onClick={() => this.handleResolve()}>Resolve</Button>
|
2018-08-14 10:51:28 +01:00
|
|
|
{this.state.showResult && this.showResult()}
|
2018-10-12 12:23:02 +02:00
|
|
|
</CardBody>
|
|
|
|
</Card>
|
2018-08-14 10:23:48 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EnsResolve.propTypes = {
|
2018-08-14 10:51:28 +01:00
|
|
|
resolve: PropTypes.func,
|
|
|
|
ensRecords: PropTypes.arrayOf(PropTypes.object)
|
2018-08-14 10:23:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default EnsResolve;
|