Skip to content

Commit

Permalink
Merge pull request #435 from ensdomains/dev
Browse files Browse the repository at this point in the history
Single name speed improvements and refactoring (#434)
  • Loading branch information
jefflau authored Aug 26, 2019
2 parents c8643c4 + 1718a69 commit 295f2d3
Show file tree
Hide file tree
Showing 8 changed files with 1,185 additions and 1,232 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@ensdomains/ethregistrar": "^1.2.2",
"@ensdomains/react-ens-address": "^0.0.11",
"@ensdomains/resolver": "^0.1.6",
"@ensdomains/ui": "^1.1.6",
"@ensdomains/ui": "^1.1.7",
"apollo-cache-inmemory": "^1.2.9",
"apollo-client": "^2.4.5",
"apollo-link": "^1.2.2",
Expand Down
207 changes: 121 additions & 86 deletions src/api/manager/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,112 @@ async function getParent(name) {
return [parent, parentOwner]
}

async function getRegistrarEntry(name) {
const nameArray = name.split('.')
if (nameArray.length > 3 && nameArray[1] !== 'eth') {
return {}
}
const entry = await getEntry(nameArray[0])
const {
registrant,
deedOwner,
state,
registrationDate,
migrationStartDate,
currentBlockDate,
transferEndDate,
gracePeriodEndDate,
revealDate,
value,
highestBid,
expiryTime,
isNewRegistrar,
available
} = entry

const node = {
name: `${name}`,
state: modeNames[state],
registrationDate,
gracePeriodEndDate: gracePeriodEndDate || null,
migrationStartDate: migrationStartDate || null,
currentBlockDate: currentBlockDate || null,
transferEndDate: transferEndDate || null,
revealDate,
value,
highestBid,
registrant,
deedOwner,
isNewRegistrar: !!isNewRegistrar,
available,
expiryTime: expiryTime || null
}

return node
}

async function getDNSEntryDetails(name) {
const nameArray = name.split('.')
if (nameArray.length > 3) return {}

let tld = nameArray[1]
let owner
let tldowner = (await getOwner(tld)).toLocaleLowerCase()
try {
owner = (await getOwner(name)).toLocaleLowerCase()
} catch {
return {}
}

let isDNSRegistrarSupported = await isDNSRegistrar(tld)
if (isDNSRegistrarSupported && tldowner !== emptyAddress) {
const dnsEntry = await getDNSEntry(name, tldowner, owner)
const node = {
isDNSRegistrar: true,
dnsOwner: dnsEntry.dnsOwner || emptyAddress,
state: dnsEntry.state
}

return node
}
}

async function getTestEntry(name) {
const nameArray = name.split('.')
if (nameArray.length < 3 && nameArray[1] === 'test') {
const expiryTime = await expiryTimes(nameArray[0])
if (expiryTime) return { expiryTime }
}
return {}
}

async function getSubDomainSaleEntry(name) {
const nameArray = name.split('.')
const networkId = await getNetworkId()
if (nameArray.length < 3) return {}

if (networkId === 1) {
const domain = domains.find(domain => domain.name === nameArray[1]) || {}
const subdomain = await query(nameArray[1], nameArray[0], domain.registrar)
const node = {
name: `${name}`,
...subdomain,
state: subdomain.available ? 'Open' : 'Owned'
}
return node
}
}

const resolvers = {
Query: {
getOwner: async (_, { name }, { cache }) => {
const owner = await getOwner(name)
return owner
},

singleName: async (_, { name }, { cache }) => {
try {
const nameArray = name.split('.')
const decrypted = isDecrypted(name)
const networkId = await getNetworkId()
let node = {
name: null,
revealDate: null,
Expand All @@ -78,7 +173,6 @@ const resolvers = {
state: null,
label: null,
decrypted,
domain: null,
price: null,
rent: null,
referralFeePPM: null,
Expand All @@ -91,99 +185,40 @@ const resolvers = {
deedOwner: null,
registrant: null
}
let data
if (nameArray.length < 3 && nameArray[1] === 'eth') {
const entry = await getEntry(nameArray[0])
const {
registrant,
deedOwner,
state,
registrationDate,
migrationStartDate,
currentBlockDate,
transferEndDate,
gracePeriodEndDate,
revealDate,
value,
highestBid,
expiryTime,
isNewRegistrar,
available
} = entry
const owner = await getOwner(name)
node = {
...node,
name: `${name}`,
state: modeNames[state],
registrationDate,
gracePeriodEndDate: gracePeriodEndDate || null,
migrationStartDate: migrationStartDate || null,
currentBlockDate: currentBlockDate || null,
transferEndDate: transferEndDate || null,
revealDate,
value,
highestBid,
owner,
registrant,
deedOwner,
isNewRegistrar: !!isNewRegistrar,
available,
expiryTime: expiryTime || null,
__typename: 'Node'
}
} else if (nameArray.length < 3 && nameArray[1] === 'test') {
const expiryTime = await expiryTimes(nameArray[0])
if (expiryTime) {
node.expiryTime = expiryTime
}
} else if (nameArray.length > 2) {
if (networkId === 1) {
const domain =
domains.find(domain => domain.name === nameArray[1]) || {}
const subdomain = await query(
nameArray[1],
nameArray[0],
domain.registrar
)
node = {
name: `${name}`,
...node,
...subdomain,
state: subdomain.available ? 'Open' : 'Owned'
}
}
} else {
// either dnssect domain or non existing domain
let tld = nameArray[1]
let owner
let tldowner = (await getOwner(tld)).toLocaleLowerCase()
try {
owner = (await getOwner(name)).toLocaleLowerCase()
} catch {}

let isDNSRegistrarSupported = await isDNSRegistrar(tld)
if (isDNSRegistrarSupported && tldowner !== emptyAddress) {
const dnsEntry = await getDNSEntry(name, tldowner, owner)
node.isDNSRegistrar = true
node.dnsOwner = dnsEntry.dnsOwner || emptyAddress
node.state = dnsEntry.state
}
}

console.log(node)
const dataSources = [
getRegistrarEntry(name),
getDomainDetails(name),
getParent(name),
getDNSEntryDetails(name),
getTestEntry(name),
getSubDomainSaleEntry(name)
]

const [
registrarEntry,
domainDetails,
[parent, parentOwner],
dnsEntry,
testEntry,
subDomainSaleEntry
] = await Promise.all(dataSources)

const { names } = cache.readQuery({ query: GET_ALL_NODES })
const nodeDetails = await getDomainDetails(name)
const [parent, parentOwner] = await getParent(name)

var detailedNode = {
...node,
...nodeDetails,
...registrarEntry,
...domainDetails,
...dnsEntry,
...testEntry,
...subDomainSaleEntry,
parent,
parentOwner,
__typename: 'Node'
}

data = {
const data = {
names: [...names, detailedNode]
}

Expand Down
13 changes: 12 additions & 1 deletion src/components/QueryAccount.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react'
import { Query } from 'react-apollo'
import { Query, useQuery } from 'react-apollo'
import gql from 'graphql-tag'

const GET_ACCOUNTS = gql`
Expand Down Expand Up @@ -30,4 +30,15 @@ class GetAccount extends Component {
}
}

export function useAccount() {
const { loading, error, data } = useQuery(GET_ACCOUNTS)
const {
web3: { accounts }
} = data
if (error || loading || !accounts[0]) {
return '0x0000000000000000000000000000000000000000'
}
return accounts[0]
}

export default GetAccount
Loading

0 comments on commit 295f2d3

Please sign in to comment.