Skip to content

Commit

Permalink
Update token_created.ts (#755)
Browse files Browse the repository at this point in the history
Co-authored-by: Raman Shekhawat <[email protected]>
  • Loading branch information
leonardocustodio and justraman authored Dec 13, 2023
1 parent 05fb2ab commit 6973546
Showing 1 changed file with 1 addition and 30 deletions.
31 changes: 1 addition & 30 deletions src/mappings/multiTokens/events/token_created.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { SubstrateBlock } from '@subsquid/substrate-processor'
import { EventItem } from '@subsquid/substrate-processor/lib/interfaces/dataSelection'
import { u8aToHex } from '@polkadot/util'
import { IsNull } from 'typeorm'
import { UnknownVersionError } from '../../../common/errors'
import { MultiTokensTokenCreatedEvent } from '../../../types/generated/events'
import {
Attribute,
CapType,
Collection,
Event as EventModel,
Extrinsic,
FreezeState,
Metadata,
MultiTokensTokenCreated,
Royalty,
Token,
Expand Down Expand Up @@ -781,41 +778,15 @@ export async function tokenCreated(
}

if (item.event.call) {
const [callData, collection, collectionUri] = await Promise.all([
const [callData, collection] = await Promise.all([
getCallData(ctx, item.event.call, eventData),
ctx.store.findOneOrFail(Collection, {
where: { id: eventData.collectionId.toString() },
}),
ctx.store.findOne(Attribute, {
where: { key: 'uri', token: IsNull(), collection: { id: eventData.collectionId.toString() } },
}),
])

if (!eventData || !callData) return undefined

// TODO: Far from ideal but we will do this only until we don't have the metadata processor
let metadata: Metadata | null | undefined = null
if (collectionUri && (collectionUri.value.includes('{id}.json') || collectionUri.value.includes('%7Bid%7D.json'))) {
metadata = await new Metadata()
if (metadata) {
const collectionWithTokens = await ctx.store.findOneOrFail<Collection>(Collection, {
where: { id: eventData.collectionId.toString() },
relations: {
tokens: true,
},
})

const otherTokens: Token[] = collectionWithTokens.tokens.map((e) => {
e.metadata = metadata
return e
})

if (otherTokens.length > 0) {
ctx.store.save(otherTokens)
}
}
}

const token = new Token({
id: `${eventData.collectionId}-${eventData.tokenId}`,
tokenId: eventData.tokenId,
Expand Down

0 comments on commit 6973546

Please sign in to comment.