Skip to content

Commit

Permalink
fetch owners
Browse files Browse the repository at this point in the history
  • Loading branch information
meelrossi committed May 14, 2024
1 parent fae5355 commit 83f77e0
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 12 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"decentraland-ecs": "6.12.4-7784644013.commit-f770b3e",
"decentraland-experiments": "^1.0.2",
"decentraland-transactions": "^2.6.1",
"decentraland-ui": "^5.23.2",
"decentraland-ui": "^5.23.3",
"ethers": "^5.6.8",
"file-saver": "^2.0.1",
"graphql": "^15.8.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { t } from 'decentraland-dapps/dist/modules/translation'
import { Loader, Message, Table, Empty, Button } from 'decentraland-ui'
import { formatNumber } from 'decentraland-dapps/dist/lib'
import { useCallback } from 'react'
import { config } from 'config'
import { locations } from 'routing/locations'
import Profile from 'components/Profile'
import { ENS } from 'modules/ens/types'
import { fromBytesToMegabytes, renderPublishSceneButton, renderWorldUrl } from '../utils'
import { Props } from './WorldContributorTab.types'
import { renderPublishSceneButton, renderWorldUrl } from '../utils'

export default function WorldContributorTab({ items, deploymentsByWorlds, projects, loading, error, onNavigate, onUnpublishWorld }: Props) {
const handlePublishScene = useCallback(() => {
Expand Down Expand Up @@ -75,7 +76,7 @@ export default function WorldContributorTab({ items, deploymentsByWorlds, projec
return (
<Table.Row className="TableRow" key={index}>
<Table.Cell width={1}>{ens.name}</Table.Cell>
<Table.Cell width={1}>{<Profile address={ens.nftOwnerAddress} />}</Table.Cell>
<Table.Cell width={1}>{<Profile address={ens.nftOwnerAddress || ''} />}</Table.Cell>
<Table.Cell width={2}>{renderWorldUrl(deploymentsByWorlds, ens)}</Table.Cell>
<Table.Cell width={1}>
{renderPublishSceneButton({
Expand All @@ -87,7 +88,7 @@ export default function WorldContributorTab({ items, deploymentsByWorlds, projec
onUnpublishScene: canUserDeploy ? handleUnpublishScene : undefined
})}
</Table.Cell>
<Table.Cell width={1}>{ens.size || '-'}</Table.Cell>
<Table.Cell width={1}>{formatNumber(fromBytesToMegabytes(Number(ens.size) || 0))}</Table.Cell>
<Table.Cell width={1}>{userPermissions}</Table.Cell>
</Table.Row>
)
Expand Down
44 changes: 43 additions & 1 deletion src/lib/api/ens.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
type Domain = { name: string }
import { config } from 'config'
import { gql } from 'apollo-boost'
import { createClient } from './graph'

export const ENS_SUBGRAPH_URL = config.get('ENS_SUBGRAPH_URL', '')
const ensGraphClient = createClient(ENS_SUBGRAPH_URL)

type Domain = { name: string }
type DomainsQueryResult = { data: { domains: Domain[] } } | { errors: any }

type OwnerByENSTuple = {
name: string
wrappedOwner: {
id: string
}
}

type OwnerByENSQueryResult = {
domains: OwnerByENSTuple[]
}

const FAIL_TO_FETCH_ENS_LIST_MESSAGE = 'Failed to fetch ENS list'

const getOwnerByENSQuery = () => gql`
query getOwners($domains: [String]) {
domains(where: { name_in: $domains }) {
name
wrappedOwner {
id
}
}
}
`

export class ENSApi {
constructor(private subgraph: string) {}

Expand Down Expand Up @@ -49,4 +77,18 @@ export class ENSApi {

return queryResult.data.domains.map(domain => domain.name)
}

fetchExternalENSOwners = async (domains: string[]): Promise<Record<string, string>> => {
const { data } = await ensGraphClient.query<OwnerByENSQueryResult>({
query: getOwnerByENSQuery(),
variables: { domains }
})

const results: Record<string, string> = {}
data.domains.forEach(({ wrappedOwner, name }) => {
results[name] = wrappedOwner.id
})

return results
}
}
50 changes: 50 additions & 0 deletions src/lib/api/marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ const getSubdomainQuery = () => gql`
}
`

const getOwnerByNameQuery = () => gql`
query getOwners($domains: [String], $offset: Int) {
nfts(first: ${BATCH_SIZE}, skip: $offset, where: { name_in: $domains, category: ens }) {
owner {
address
}
ens {
subdomain
}
}
}
`

type SubdomainTuple = {
ens: {
subdomain: string[]
Expand All @@ -27,7 +40,44 @@ type SubdomainQueryResult = {
nfts: SubdomainTuple[]
}

type OwnerByNameTuple = {
owner: {
address: string
}
ens: {
subdomain: string
}
}
type OwnerByNameQueryResult = {
nfts: OwnerByNameTuple[]
}

export class MarketplaceAPI {
public async fetchENSOwnerByDomain(domains: string[]): Promise<Record<string, string>> {
if (!domains) {
return {}
}

const results: Record<string, string> = {}
let offset = 0
let nextPage = true
while (nextPage) {
const { data } = await marketplaceGraphClient.query<OwnerByNameQueryResult>({
query: getOwnerByNameQuery(),
variables: { domains, offset }
})
data.nfts.forEach(({ ens, owner }) => {
results[ens.subdomain] = owner.address
})
if (data.nfts.length === BATCH_SIZE) {
offset += BATCH_SIZE
} else {
nextPage = false
}
}
return results
}

public async fetchENSList(address: string | undefined): Promise<string[]> {
if (!address) {
return []
Expand Down
2 changes: 1 addition & 1 deletion src/lib/api/worlds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class WorldsAPI extends BaseAPI {
throw new Error('Unauthorized')
}

const path = '/world/contribute'
const path = '/wallet/contribute'
const headers = this.authorization.createAuthHeaders('get', path, {})
const result = await fetch(this.url + path, {
method: 'GET',
Expand Down
16 changes: 14 additions & 2 deletions src/modules/ens/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,23 @@ export function* ensSaga(builderClient: BuilderClient, ensApi: ENSApi, worldsAPI
const bannedNamesSet = new Set(bannedNames.map(x => x.toLowerCase()))

names = names.filter(({ name }) => name.split('.').every(nameSegment => !bannedNamesSet.has(nameSegment)))
const ensDomains: string[] = []
const nameDomains: string[] = []
names.forEach(({ name }) => {
if (name.includes('.dcl.eth')) {
nameDomains.push(name.replace('.dcl.eth', ''))
} else {
ensDomains.push(name)
}
})
const ownerByNameDomain: Record<string, string> = yield call([marketplace, 'fetchENSOwnerByDomain'], nameDomains)
const ownerByEnsDomain: Record<string, string> = yield call([ensApi, 'fetchExternalENSOwners'], ensDomains)

const enss: ENS[] = names.map(({ name, user_permissions, owner, size }) => {
const enss: ENS[] = names.map(({ name, user_permissions, size }) => {
const nameDomain = name.replace('.dcl.eth', '')
return {
subdomain: name,
nftOwnerAddress: owner,
nftOwnerAddress: name.includes('dcl.eth') ? ownerByNameDomain[nameDomain] : ownerByEnsDomain[name],
content: '',
ensOwnerAddress: '',
name,
Expand Down

0 comments on commit 83f77e0

Please sign in to comment.