-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d16ac8c
commit 535d3fd
Showing
3 changed files
with
194 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const ensSubgraphUrl = 'https://api.thegraph.com/subgraphs/name/ensdomains/ens' | ||
|
||
const query = ` | ||
query DomainsQuery($names: [String!]!) { | ||
domains(where: { name_in: $names }) { | ||
resolvedAddress { | ||
id | ||
} | ||
name | ||
} | ||
} | ||
` | ||
|
||
const resolveEnsDomainsBatch = async ( | ||
ensNames: string[], | ||
): Promise<{ [name: string]: string }> => { | ||
const variables = { | ||
names: ensNames, | ||
} | ||
const response = await fetch(ensSubgraphUrl, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ query, variables }), | ||
}) | ||
const { | ||
data, | ||
}: { | ||
data?: { | ||
domains: { resolvedAddress: { id: string } | null; name: string }[] | ||
} | ||
} = await response.json() | ||
if (!data) { | ||
throw new Error('No data returned from subgraph') | ||
} | ||
|
||
return data.domains.reduce((acc, domain) => { | ||
if (domain.resolvedAddress !== null) { | ||
acc[domain.name] = domain.resolvedAddress.id | ||
} | ||
return acc | ||
}, {} as { [name: string]: string }) | ||
} | ||
|
||
export const resolveEnsDomains = async ( | ||
ensNames: string[], | ||
): Promise<{ [name: string]: string }> => { | ||
const batches = chunk(ensNames, 100) | ||
const results = await Promise.all(batches.map(resolveEnsDomainsBatch)) | ||
return results.reduce((acc, batch) => { | ||
return { ...acc, ...batch } | ||
}, {} as { [name: string]: string }) | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const chunk = (arr: any[], size: number): any[][] => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const chunks: any[][] = [] | ||
let i = 0 | ||
while (i < arr.length) { | ||
chunks.push(arr.slice(i, i + size)) | ||
i += size | ||
} | ||
return chunks | ||
} |
535d3fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
lanyard – ./
lanyard-git-main.context.wtf
allowlist.context.wtf
lanyard.context.wtf