Fix typo and improved code readability

This commit is contained in:
Javi Esses 2020-05-28 11:23:07 -03:00
parent e39f001e71
commit 6672378ae2
2 changed files with 10 additions and 5 deletions

View File

@ -86,7 +86,7 @@ EnsInput.prototype.render = function () {
EnsInput.prototype.componentDidMount = function () { EnsInput.prototype.componentDidMount = function () {
const network = this.props.network const network = this.props.network
const networkHasEnsSupport = getNetworkEnsSupport(network) const networkHasEnsSupport = getNetworkEnsSupport(network)
const rnsRegistry = getNetworkRnsSupport(network) const networkHasRnsSupport = getNetworkRnsSupport(network)
this.setState({ ensResolution: ZERO_ADDRESS }) this.setState({ ensResolution: ZERO_ADDRESS })
@ -94,9 +94,10 @@ EnsInput.prototype.componentDidMount = function () {
const provider = global.ethereumProvider const provider = global.ethereumProvider
this.ens = new ENS({ provider, network }) this.ens = new ENS({ provider, network })
this.checkName = debounce(this.lookupEnsName.bind(this, 'ENS'), 200) this.checkName = debounce(this.lookupEnsName.bind(this, 'ENS'), 200)
} else if (rnsRegistry) { } else if (networkHasRnsSupport) {
const registryAddress = getRnsRegistryAddress(network);
const provider = global.ethereumProvider const provider = global.ethereumProvider
this.ens = new ENS({ provider, network, registryAddress: rnsRegistry }) this.ens = new ENS({ provider, network, registryAddress })
this.checkName = debounce(this.lookupEnsName.bind(this, 'RNS'), 200) this.checkName = debounce(this.lookupEnsName.bind(this, 'RNS'), 200)
} }
} }
@ -132,7 +133,7 @@ EnsInput.prototype.lookupEnsName = function (nameService) {
&& reason.message === 'ENS name not defined.' && reason.message === 'ENS name not defined.'
) { ) {
setStateObj.hoverText = `${nameService} name not found` setStateObj.hoverText = `${nameService} name not found`
setStateObj.toError = `${nameService.toLowerCase}NameNotFound` setStateObj.toError = `${nameService.toLowerCase()}NameNotFound`
setStateObj.ensFailure = false setStateObj.ensFailure = false
} else { } else {
log.error(reason) log.error(reason)
@ -214,6 +215,10 @@ function getNetworkEnsSupport (network) {
} }
function getNetworkRnsSupport (network) { function getNetworkRnsSupport (network) {
return (network == RSK_CODE || network == RSK_TESTNET_CODE);
}
function getRnsRegistryAddress (network) {
if (network == RSK_CODE) { if (network == RSK_CODE) {
return RNSRegistryData.address.rskMainnet; return RNSRegistryData.address.rskMainnet;
} }

View File

@ -141,7 +141,7 @@ function isValidENSAddress (address) {
} }
function isValidRNSAddress (address) { function isValidRNSAddress (address) {
return address.match(/([a-z0-9])+\.(rsk)/) return address.match(/^[a-z0-9]+\.rsk$/)
} }
function isInvalidChecksumAddress (address, network) { function isInvalidChecksumAddress (address, network) {