mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
ENS name revalidates on network change.
This commit is contained in:
parent
b7a469681b
commit
5995b6d68d
@ -25,31 +25,33 @@ function EnsInput () {
|
|||||||
Component.call(this)
|
Component.call(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EnsInput.prototype.onChange = function (recipient) {
|
||||||
|
const network = this.props.network
|
||||||
|
const networkHasEnsSupport = getNetworkEnsSupport(network)
|
||||||
|
|
||||||
|
this.props.onChange(recipient)
|
||||||
|
|
||||||
|
if (!networkHasEnsSupport) return
|
||||||
|
|
||||||
|
if (recipient.match(ensRE) === null) {
|
||||||
|
return this.setState({
|
||||||
|
loadingEns: false,
|
||||||
|
ensResolution: null,
|
||||||
|
ensFailure: null,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
loadingEns: true,
|
||||||
|
})
|
||||||
|
this.checkName(recipient)
|
||||||
|
}
|
||||||
|
|
||||||
EnsInput.prototype.render = function () {
|
EnsInput.prototype.render = function () {
|
||||||
const props = this.props
|
const props = this.props
|
||||||
const opts = extend(props, {
|
const opts = extend(props, {
|
||||||
list: 'addresses',
|
list: 'addresses',
|
||||||
onChange: (recipient) => {
|
onChange: this.onChange.bind(this),
|
||||||
const network = this.props.network
|
|
||||||
const networkHasEnsSupport = getNetworkEnsSupport(network)
|
|
||||||
|
|
||||||
props.onChange(recipient)
|
|
||||||
|
|
||||||
if (!networkHasEnsSupport) return
|
|
||||||
|
|
||||||
if (recipient.match(ensRE) === null) {
|
|
||||||
return this.setState({
|
|
||||||
loadingEns: false,
|
|
||||||
ensResolution: null,
|
|
||||||
ensFailure: null,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
loadingEns: true,
|
|
||||||
})
|
|
||||||
this.checkName(recipient)
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
return h('div', {
|
return h('div', {
|
||||||
style: { width: '100%', position: 'relative' },
|
style: { width: '100%', position: 'relative' },
|
||||||
@ -89,10 +91,13 @@ EnsInput.prototype.lookupEnsName = function (recipient) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((reason) => {
|
.catch((reason) => {
|
||||||
log.error(reason)
|
// log.error(reason)
|
||||||
|
if (reason.message !== 'ENS name not defined.') {
|
||||||
|
log.error(reason)
|
||||||
|
}
|
||||||
return this.setState({
|
return this.setState({
|
||||||
loadingEns: false,
|
loadingEns: false,
|
||||||
ensResolution: ZERO_ADDRESS,
|
ensResolution: recipient,
|
||||||
ensFailure: true,
|
ensFailure: true,
|
||||||
hoverText: reason.message,
|
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
|
// 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(ensResolution, nickname)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user