Skip to content

Commit

Permalink
feat: use display_name if available for traits
Browse files Browse the repository at this point in the history
  • Loading branch information
justraman committed Dec 13, 2024
1 parent 6a59d3f commit b7e7f19
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/job-handlers/compute-traits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ export default async (job: Queue.Job<JobData>, done: Queue.DoneCallback) => {

tokens.forEach((token) => {
if (!token.metadata || !token.metadata.attributes || !isPlainObject(token.metadata.attributes)) return
const attributes = token.metadata.attributes as Record<string, { value: string } | string>
const attributes = token.metadata.attributes as Record<string, { value: string; display_name?: string } | string>
Object.entries(attributes).forEach(([traitType, data]) => {
let value = data as string
if (typeof data === 'object') {
value = data.value
if (data.display_name) {
traitType = data.display_name
}
}

if (!value) return
Expand All @@ -70,7 +73,10 @@ export default async (job: Queue.Job<JobData>, done: Queue.DoneCallback) => {
tType.set(value, token.supply)
}

tokenTraitMap.set(token.id, [...(tokenTraitMap.get(token.id) || []), `${collectionId}-${traitType}-${value}`])
tokenTraitMap.set(token.id, [
...(tokenTraitMap.get(token.id) || []),
hash(`${collectionId}-${traitType}-${value}`),
])
})
})

Expand Down Expand Up @@ -108,7 +114,7 @@ export default async (job: Queue.Job<JobData>, done: Queue.DoneCallback) => {
traitTokensToSave.push(
new TraitToken({
id: hash(`${trait}-${tokenId}`),
trait: new Trait({ id: hash(trait) }),
trait: new Trait({ id: trait }),
token: new Token({ id: tokenId }),
})
)
Expand Down
4 changes: 4 additions & 0 deletions src/mappings/util/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export function metadataParser(
image: string | null | undefined
fallback_image: string | null | undefined
media: Media[]
keywords: string[] | undefined
properties: unknown
attributes: unknown
} | null
Expand All @@ -171,6 +172,9 @@ export function metadataParser(
if (externalMetadata?.external_url) {
metadata.externalUrl = safeString(externalMetadata.external_url)
}
if (externalMetadata?.keywords && Array.isArray(externalMetadata.keywords)) {
metadata.keywords = externalMetadata.keywords
}
if (externalMetadata?.image) {
metadata.fallbackImage = safeString(externalMetadata.image)
metadata.media = imageToMedia(externalMetadata.image)
Expand Down

0 comments on commit b7e7f19

Please sign in to comment.