From 5995b6d68dccb8d45a14b0665664717b21be5b8b Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 13 Jun 2018 09:26:21 -0230 Subject: ENS name revalidates on network change. --- ui/app/components/ens-input.js | 56 +++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 23 deletions(-) (limited to 'ui/app/components/ens-input.js') diff --git a/ui/app/components/ens-input.js b/ui/app/components/ens-input.js index aff4b6ef6..1be6d798a 100644 --- a/ui/app/components/ens-input.js +++ b/ui/app/components/ens-input.js @@ -25,31 +25,33 @@ function EnsInput () { Component.call(this) } -EnsInput.prototype.render = function () { - const props = this.props - const opts = extend(props, { - list: 'addresses', - onChange: (recipient) => { - const network = this.props.network - const networkHasEnsSupport = getNetworkEnsSupport(network) +EnsInput.prototype.onChange = function (recipient) { + const network = this.props.network + const networkHasEnsSupport = getNetworkEnsSupport(network) - props.onChange(recipient) + this.props.onChange(recipient) - if (!networkHasEnsSupport) return + if (!networkHasEnsSupport) return - if (recipient.match(ensRE) === null) { - return this.setState({ - loadingEns: false, - ensResolution: null, - ensFailure: null, - }) - } + if (recipient.match(ensRE) === null) { + return this.setState({ + loadingEns: false, + ensResolution: null, + ensFailure: null, + }) + } - this.setState({ - loadingEns: true, - }) - this.checkName(recipient) - }, + this.setState({ + loadingEns: true, + }) + this.checkName(recipient) +} + +EnsInput.prototype.render = function () { + const props = this.props + const opts = extend(props, { + list: 'addresses', + onChange: this.onChange.bind(this), }) return h('div', { style: { width: '100%', position: 'relative' }, @@ -89,10 +91,13 @@ EnsInput.prototype.lookupEnsName = function (recipient) { } }) .catch((reason) => { - log.error(reason) + // log.error(reason) + if (reason.message !== 'ENS name not defined.') { + log.error(reason) + } return this.setState({ loadingEns: false, - ensResolution: ZERO_ADDRESS, + ensResolution: recipient, ensFailure: true, hoverText: reason.message, }) @@ -105,6 +110,11 @@ EnsInput.prototype.componentDidUpdate = function (prevProps, prevState) { // If an address is sent without a nickname, meaning not from ENS or from // the user's own accounts, a default of a one-space string is used. const nickname = state.nickname || ' ' + if (prevProps.network !== this.props.network) { + const provider = global.ethereumProvider + this.ens = new ENS({ provider, network: this.props.network }) + this.onChange(ensResolution) + } if (prevState && ensResolution && this.props.onChange && ensResolution !== prevState.ensResolution) { this.props.onChange(ensResolution, nickname) -- cgit From bb855707efbcb754f5e4ee4e124f69308bca037d Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 14 Jun 2018 11:25:55 -0230 Subject: ENS input in send form shows distinct errors for invalid addresses and non-existent addresses. --- ui/app/components/ens-input.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'ui/app/components/ens-input.js') diff --git a/ui/app/components/ens-input.js b/ui/app/components/ens-input.js index 1be6d798a..7873e81e0 100644 --- a/ui/app/components/ens-input.js +++ b/ui/app/components/ens-input.js @@ -12,6 +12,7 @@ const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' const connect = require('react-redux').connect const ToAutoComplete = require('./send/to-autocomplete') const log = require('loglevel') +const { isValidENSAddress } = require('../util') EnsInput.contextTypes = { t: PropTypes.func, @@ -29,7 +30,7 @@ EnsInput.prototype.onChange = function (recipient) { const network = this.props.network const networkHasEnsSupport = getNetworkEnsSupport(network) - this.props.onChange(recipient) + this.props.onChange({ toAddress: recipient }) if (!networkHasEnsSupport) return @@ -38,6 +39,7 @@ EnsInput.prototype.onChange = function (recipient) { loadingEns: false, ensResolution: null, ensFailure: null, + toError: null, }) } @@ -87,20 +89,28 @@ EnsInput.prototype.lookupEnsName = function (recipient) { nickname: recipient.trim(), hoverText: address + '\n' + this.context.t('clickCopy'), ensFailure: false, + toError: null, }) } }) .catch((reason) => { // log.error(reason) - if (reason.message !== 'ENS name not defined.') { - log.error(reason) - } - return this.setState({ + const setStateObj = { loadingEns: false, ensResolution: recipient, ensFailure: true, - hoverText: reason.message, - }) + toError: null, + } + if (isValidENSAddress(recipient) && reason.message === 'ENS name not defined.') { + setStateObj.hoverText = this.context.t('ensNameNotFound') + setStateObj.toError = 'ensNameNotFound' + setStateObj.ensFailure = false + } else { + log.error(reason) + setStateObj.hoverText = reason.message + } + + return this.setState(setStateObj) }) } @@ -117,7 +127,7 @@ EnsInput.prototype.componentDidUpdate = function (prevProps, prevState) { } if (prevState && ensResolution && this.props.onChange && ensResolution !== prevState.ensResolution) { - this.props.onChange(ensResolution, nickname) + this.props.onChange({ toAddress: ensResolution, nickname, toError: state.toError }) } } @@ -134,7 +144,9 @@ EnsInput.prototype.ensIcon = function (recipient) { } EnsInput.prototype.ensIconContents = function (recipient) { - const { loadingEns, ensFailure, ensResolution } = this.state || { ensResolution: ZERO_ADDRESS} + const { loadingEns, ensFailure, ensResolution, toError } = this.state || { ensResolution: ZERO_ADDRESS } + + if (toError) return if (loadingEns) { return h('img', { -- cgit From 97a7bc48947000163990be081058c6a6a3cddcad Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 21 Jun 2018 15:01:13 -0230 Subject: Remove commented out code in ens-input. --- ui/app/components/ens-input.js | 1 - 1 file changed, 1 deletion(-) (limited to 'ui/app/components/ens-input.js') diff --git a/ui/app/components/ens-input.js b/ui/app/components/ens-input.js index 7873e81e0..292dcdde6 100644 --- a/ui/app/components/ens-input.js +++ b/ui/app/components/ens-input.js @@ -94,7 +94,6 @@ EnsInput.prototype.lookupEnsName = function (recipient) { } }) .catch((reason) => { - // log.error(reason) const setStateObj = { loadingEns: false, ensResolution: recipient, -- cgit