Skip to content

Commit

Permalink
Merge pull request #183 from kodadot/revert-162-fix/comment/royalty
Browse files Browse the repository at this point in the history
Revert "🔧 comment royalty"
  • Loading branch information
vikiival authored Jan 10, 2024
2 parents e351120 + 472103f commit 027d964
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/mappings/nfts/setAttribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { getOrFail as get } from '@kodadot1/metasquid/entity'
import { CollectionEntity, NFTEntity } from '../../model'
import { unwrap } from '../utils/extract'
import { Context, isNFT } from '../utils/types'
// import { addressOf } from '../utils/helper'
import { addressOf } from '../utils/helper'
import { getAttributeEvent } from './getters'
import { tokenIdOf } from './types'
import { attributeFrom, tokenIdOf } from './types'

export async function handleAttributeSet(context: Context): Promise<void> {
const event = unwrap(context, getAttributeEvent)
Expand All @@ -17,30 +17,29 @@ export async function handleAttributeSet(context: Context): Promise<void> {
final.attributes = []
}

// if ('royalty' in final && event.trait === 'royalty') {
// final.royalty = final.royalty ?? Number.parseFloat(event.value as string)
// }
if ('royalty' in final && event.trait === 'royalty') {
final.royalty = final.royalty ?? Number.parseFloat(event.value as string)
}

// if ('recipient' in final && event.trait === 'recipient') {
// try {
// final.recipient = final.recipient ?? addressOf(event.value as string)
// } catch (error) {
// console.log(error)
// final.recipient = final.recipient ?? (event.value as string)
// }
// }
if ('recipient' in final && event.trait === 'recipient') {
try {
final.recipient = final.recipient ?? addressOf(event.value as string)
} catch (error) {
console.log(error)
final.recipient = final.recipient ?? (event.value as string)
}
}

if (event.value === null) {
final.attributes = final.attributes?.filter((attr) => attr.trait !== event.trait)
} else {
const attribute = final.attributes?.find((attr) => attr.trait === event.trait)
if (attribute) {
attribute.value = String(event.value)
}
// else if (event.trait !== 'royalty' && event.trait !== 'recipient') {
// const newAttribute = attributeFrom({ trait_type: event.trait, value: String(event.value) })
// final.attributes?.push(newAttribute)
// }
} else if (event.trait !== 'royalty' && event.trait !== 'recipient') {
const newAttribute = attributeFrom({ trait_type: event.trait, value: String(event.value) })
final.attributes?.push(newAttribute)
}
}

await context.store.save(final)
Expand Down

0 comments on commit 027d964

Please sign in to comment.