import React, { Component } from 'react'; import { connect } from 'react-redux'; import { AppState } from 'reducers'; import { resolveDomainRequested, TResolveDomainRequested } from 'actions/ens'; import { isValidENSName } from 'libs/validators'; import './NameInput.scss'; import { Input } from 'components/ui'; import translate from 'translations'; interface State { domainToCheck: string; isValidDomain: boolean; isFocused: boolean; } interface Props { domainRequests: AppState['ens']['domainRequests']; resolveDomainRequested: TResolveDomainRequested; } class NameInput extends Component { public state = { isFocused: false, isValidDomain: false, domainToCheck: '' }; public render() { const { domainRequests } = this.props; const { isValidDomain, domainToCheck } = this.state; const req = domainRequests[domainToCheck]; const isLoading = req && !req.data && !req.error; return (
{domainToCheck && !isValidDomain && (

{translate('ENS_INVALID_INPUT')}

)}
); } // add delay to namehash computation / getting the availability private onChange = (event: React.FormEvent) => { const domainToCheck = event.currentTarget.value.toLowerCase().trim(); const isValidDomain = isValidENSName(domainToCheck); this.setState({ domainToCheck, isValidDomain }); }; private onSubmit = (ev: React.FormEvent) => { ev.preventDefault(); const { isValidDomain, domainToCheck } = this.state; return isValidDomain && this.props.resolveDomainRequested(domainToCheck); }; private onFocus = () => this.setState({ isFocused: true }); private onBlur = () => this.setState({ isFocused: false }); } function mapStateToProps(state: AppState) { return { domainRequests: state.ens.domainRequests }; } export default connect(mapStateToProps, { resolveDomainRequested })(NameInput);