Added RNS integration

This commit is contained in:
Javi Esses 2020-05-21 23:49:16 -03:00
parent eb14ba7bce
commit 21d58f5a5f
10 changed files with 67 additions and 9 deletions

View File

@ -355,6 +355,9 @@
"ensNameNotFound": { "ensNameNotFound": {
"message": "ENS name not found" "message": "ENS name not found"
}, },
"rnsNameNotFound": {
"message": "RNS name not found"
},
"enterPassword": { "enterPassword": {
"message": "Enter password" "message": "Enter password"
}, },

View File

@ -349,6 +349,9 @@
"ensNameNotFound": { "ensNameNotFound": {
"message": "Nom ENS inconnu" "message": "Nom ENS inconnu"
}, },
"rnsNameNotFound": {
"message": "Nom RNS inconnu"
},
"enterPassword": { "enterPassword": {
"message": "Entrez votre mot de passe" "message": "Entrez votre mot de passe"
}, },

View File

@ -313,6 +313,9 @@
"ensNameNotFound": { "ensNameNotFound": {
"message": "Nou pa jwenn non ENS ou a" "message": "Nou pa jwenn non ENS ou a"
}, },
"rnsNameNotFound": {
"message": "Nou pa jwenn non RNS ou a"
},
"enterPassword": { "enterPassword": {
"message": "Mete modpas" "message": "Mete modpas"
}, },

View File

@ -352,6 +352,9 @@
"ensNameNotFound": { "ensNameNotFound": {
"message": "Nome ENS non trovato" "message": "Nome ENS non trovato"
}, },
"rnsNameNotFound": {
"message": "Nome RNS non trovato"
},
"enterPassword": { "enterPassword": {
"message": "Inserisci password" "message": "Inserisci password"
}, },

View File

@ -349,6 +349,9 @@
"ensNameNotFound": { "ensNameNotFound": {
"message": "ENS 이름을 찾을 수 없습니다" "message": "ENS 이름을 찾을 수 없습니다"
}, },
"rnsNameNotFound": {
"message": "RNS 이름을 찾을 수 없습니다"
},
"enterPassword": { "enterPassword": {
"message": "비밀번호를 입력해주세요" "message": "비밀번호를 입력해주세요"
}, },

View File

@ -313,6 +313,9 @@
"ensNameNotFound": { "ensNameNotFound": {
"message": "Nie znaleziono nazwy ENS" "message": "Nie znaleziono nazwy ENS"
}, },
"rnsNameNotFound": {
"message": "Nie znaleziono nazwy RNS"
},
"enterPassword": { "enterPassword": {
"message": "Wpisz hasło" "message": "Wpisz hasło"
}, },

View File

@ -5,11 +5,15 @@ const debounce = require('debounce')
const copyToClipboard = require('copy-to-clipboard') const copyToClipboard = require('copy-to-clipboard')
const ENS = require('ethjs-ens') const ENS = require('ethjs-ens')
const networkMap = require('ethjs-ens/lib/network-map.json') const networkMap = require('ethjs-ens/lib/network-map.json')
const RNSRegistryData = require('@rsksmart/rns-registry/RNSRegistryData.json');
const ensRE = /.+\..+$/ const ensRE = /.+\..+$/
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
const log = require('loglevel') const log = require('loglevel')
const { isValidENSAddress } = require('../util') const { isValidENSAddress, isValidRNSAddress } = require('../util')
const {
RSK_CODE,
RSK_TESTNET_CODE,
} = require('../../../app/scripts/controllers/network/enums')
module.exports = EnsInput module.exports = EnsInput
@ -24,7 +28,8 @@ EnsInput.prototype.render = function () {
function onInputChange () { function onInputChange () {
const network = this.props.network const network = this.props.network
const networkHasEnsSupport = getNetworkEnsSupport(network) const networkHasEnsSupport = getNetworkEnsSupport(network)
if (!networkHasEnsSupport) return const networkHasRnsSupport = getNetworkRnsSupport(network)
if (!networkHasEnsSupport && !networkHasRnsSupport) return
const recipient = document.querySelector('input[name="address"]').value const recipient = document.querySelector('input[name="address"]').value
if (recipient.match(ensRE) === null) { if (recipient.match(ensRE) === null) {
@ -81,20 +86,26 @@ 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)
this.setState({ ensResolution: ZERO_ADDRESS }) this.setState({ ensResolution: ZERO_ADDRESS })
if (networkHasEnsSupport) { if (networkHasEnsSupport) {
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), 200) this.checkName = debounce(this.lookupEnsName.bind(this, 'ENS'), 200)
} else if (rnsRegistry) {
const provider = global.ethereumProvider
this.ens = new ENS({ provider, network, registryAddress: rnsRegistry })
this.checkName = debounce(this.lookupEnsName.bind(this, 'RNS'), 200)
} }
} }
EnsInput.prototype.lookupEnsName = function () { EnsInput.prototype.lookupEnsName = function (nameService) {
const recipient = document.querySelector('input[name="address"]').value const recipient = document.querySelector('input[name="address"]').value
const { ensResolution } = this.state const { ensResolution } = this.state
log.info(`ENS attempting to resolve name: ${recipient}`) log.info(`${nameService} attempting to resolve name: ${recipient}`)
this.ens.lookup(recipient.trim()) this.ens.lookup(recipient.trim())
.then((address) => { .then((address) => {
if (address === ZERO_ADDRESS) throw new Error('No address has been set for this name.') if (address === ZERO_ADDRESS) throw new Error('No address has been set for this name.')
@ -116,9 +127,12 @@ EnsInput.prototype.lookupEnsName = function () {
ensFailure: true, ensFailure: true,
toError: null, toError: null,
} }
if (isValidENSAddress(recipient) && reason.message === 'ENS name not defined.') { if (
setStateObj.hoverText = 'ENS name not found' (isValidENSAddress(recipient) || isValidRNSAddress(recipient))
setStateObj.toError = 'ensNameNotFound' && reason.message === 'ENS name not defined.'
) {
setStateObj.hoverText = `${nameService} name not found`
setStateObj.toError = `${nameService.toLowerCase}NameNotFound`
setStateObj.ensFailure = false setStateObj.ensFailure = false
} else { } else {
log.error(reason) log.error(reason)
@ -198,3 +212,15 @@ EnsInput.prototype.ensIconContents = function (recipient) {
function getNetworkEnsSupport (network) { function getNetworkEnsSupport (network) {
return Boolean(networkMap[network]) return Boolean(networkMap[network])
} }
function getNetworkRnsSupport (network) {
if (network == RSK_CODE) {
return RNSRegistryData.address.rskMainnet;
}
if (network == RSK_TESTNET_CODE) {
return RNSRegistryData.address.rskTestnet;
};
return;
}

View File

@ -67,6 +67,7 @@ module.exports = {
isAllOneCase, isAllOneCase,
isValidAddress, isValidAddress,
isValidENSAddress, isValidENSAddress,
isValidRNSAddress,
numericBalance, numericBalance,
parseBalance, parseBalance,
formatBalance, formatBalance,
@ -139,6 +140,10 @@ function isValidENSAddress (address) {
return address.match(/^.{7,}\.(eth|test)$/) return address.match(/^.{7,}\.(eth|test)$/)
} }
function isValidRNSAddress (address) {
return address.match(/([a-z0-9])+\.(rsk)/)
}
function isInvalidChecksumAddress (address, network) { function isInvalidChecksumAddress (address, network) {
const prefixed = ethUtil.addHexPrefix(address) const prefixed = ethUtil.addHexPrefix(address)
if (address === '0x0000000000000000000000000000000000000000') return false if (address === '0x0000000000000000000000000000000000000000') return false

8
package-lock.json generated
View File

@ -1966,6 +1966,14 @@
"react-lifecycles-compat": "^3.0.4" "react-lifecycles-compat": "^3.0.4"
} }
}, },
"@rsksmart/rns-registry": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@rsksmart/rns-registry/-/rns-registry-1.0.4.tgz",
"integrity": "sha512-phhzFT2URDi+buxychLvaKPtSytGvXh+HVJUUwvyAHDjvBPXiBSLr7OTnaciVYjVnTns++lwcMoVdgqQMVt3xQ==",
"requires": {
"minimist": "^1.2.3"
}
},
"@rsksmart/rsk-contract-metadata": { "@rsksmart/rsk-contract-metadata": {
"version": "github:rsksmart/rsk-contract-metadata#d7913739e5ee93dac8667043e2c17b0ef339c206", "version": "github:rsksmart/rsk-contract-metadata#d7913739e5ee93dac8667043e2c17b0ef339c206",
"from": "github:rsksmart/rsk-contract-metadata#master" "from": "github:rsksmart/rsk-contract-metadata#master"

View File

@ -85,6 +85,7 @@
"dependencies": { "dependencies": {
"@babel/runtime": "^7.5.5", "@babel/runtime": "^7.5.5",
"@material-ui/core": "^4.1.1", "@material-ui/core": "^4.1.1",
"@rsksmart/rns-registry": "^1.0.4",
"@rsksmart/rsk-contract-metadata": "github:rsksmart/rsk-contract-metadata#master", "@rsksmart/rsk-contract-metadata": "github:rsksmart/rsk-contract-metadata#master",
"@rsksmart/rsk-testnet-contract-metadata": "github:rsksmart/rsk-testnet-contract-metadata#master", "@rsksmart/rsk-testnet-contract-metadata": "github:rsksmart/rsk-testnet-contract-metadata#master",
"@zxing/library": "^0.8.0", "@zxing/library": "^0.8.0",