|
|
@ -12,6 +12,7 @@ const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' |
|
|
|
const connect = require('react-redux').connect |
|
|
|
const connect = require('react-redux').connect |
|
|
|
const ToAutoComplete = require('./send/to-autocomplete') |
|
|
|
const ToAutoComplete = require('./send/to-autocomplete') |
|
|
|
const log = require('loglevel') |
|
|
|
const log = require('loglevel') |
|
|
|
|
|
|
|
const { isValidENSAddress } = require('../util') |
|
|
|
|
|
|
|
|
|
|
|
EnsInput.contextTypes = { |
|
|
|
EnsInput.contextTypes = { |
|
|
|
t: PropTypes.func, |
|
|
|
t: PropTypes.func, |
|
|
@ -25,15 +26,11 @@ function EnsInput () { |
|
|
|
Component.call(this) |
|
|
|
Component.call(this) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
EnsInput.prototype.render = function () { |
|
|
|
EnsInput.prototype.onChange = function (recipient) { |
|
|
|
const props = this.props |
|
|
|
|
|
|
|
const opts = extend(props, { |
|
|
|
|
|
|
|
list: 'addresses', |
|
|
|
|
|
|
|
onChange: (recipient) => { |
|
|
|
|
|
|
|
const network = this.props.network |
|
|
|
const network = this.props.network |
|
|
|
const networkHasEnsSupport = getNetworkEnsSupport(network) |
|
|
|
const networkHasEnsSupport = getNetworkEnsSupport(network) |
|
|
|
|
|
|
|
|
|
|
|
props.onChange(recipient) |
|
|
|
this.props.onChange({ toAddress: recipient }) |
|
|
|
|
|
|
|
|
|
|
|
if (!networkHasEnsSupport) return |
|
|
|
if (!networkHasEnsSupport) return |
|
|
|
|
|
|
|
|
|
|
@ -42,6 +39,7 @@ EnsInput.prototype.render = function () { |
|
|
|
loadingEns: false, |
|
|
|
loadingEns: false, |
|
|
|
ensResolution: null, |
|
|
|
ensResolution: null, |
|
|
|
ensFailure: null, |
|
|
|
ensFailure: null, |
|
|
|
|
|
|
|
toError: null, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -49,7 +47,13 @@ EnsInput.prototype.render = function () { |
|
|
|
loadingEns: true, |
|
|
|
loadingEns: true, |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.checkName(recipient) |
|
|
|
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', { |
|
|
|
return h('div', { |
|
|
|
style: { width: '100%', position: 'relative' }, |
|
|
|
style: { width: '100%', position: 'relative' }, |
|
|
@ -85,17 +89,27 @@ EnsInput.prototype.lookupEnsName = function (recipient) { |
|
|
|
nickname: recipient.trim(), |
|
|
|
nickname: recipient.trim(), |
|
|
|
hoverText: address + '\n' + this.context.t('clickCopy'), |
|
|
|
hoverText: address + '\n' + this.context.t('clickCopy'), |
|
|
|
ensFailure: false, |
|
|
|
ensFailure: false, |
|
|
|
|
|
|
|
toError: null, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((reason) => { |
|
|
|
.catch((reason) => { |
|
|
|
log.error(reason) |
|
|
|
const setStateObj = { |
|
|
|
return this.setState({ |
|
|
|
|
|
|
|
loadingEns: false, |
|
|
|
loadingEns: false, |
|
|
|
ensResolution: ZERO_ADDRESS, |
|
|
|
ensResolution: recipient, |
|
|
|
ensFailure: true, |
|
|
|
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) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -105,9 +119,14 @@ EnsInput.prototype.componentDidUpdate = function (prevProps, prevState) { |
|
|
|
// If an address is sent without a nickname, meaning not from ENS or from
|
|
|
|
// 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.
|
|
|
|
// the user's own accounts, a default of a one-space string is used.
|
|
|
|
const nickname = state.nickname || ' ' |
|
|
|
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 && |
|
|
|
if (prevState && ensResolution && this.props.onChange && |
|
|
|
ensResolution !== prevState.ensResolution) { |
|
|
|
ensResolution !== prevState.ensResolution) { |
|
|
|
this.props.onChange(ensResolution, nickname) |
|
|
|
this.props.onChange({ toAddress: ensResolution, nickname, toError: state.toError }) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -124,7 +143,9 @@ EnsInput.prototype.ensIcon = function (recipient) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
EnsInput.prototype.ensIconContents = 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) { |
|
|
|
if (loadingEns) { |
|
|
|
return h('img', { |
|
|
|
return h('img', { |
|
|
|