Skip to content

Commit

Permalink
Merge pull request #132 from daiagi/ahk-royalties
Browse files Browse the repository at this point in the history
royalties
  • Loading branch information
vikiival authored Oct 25, 2023
2 parents d4ade22 + 9fbf4f3 commit 74fda95
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/mappings/nfts/setAttribute.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getOrFail as get } from '@kodadot1/metasquid/entity'
import { CollectionEntity, NFTEntity } from '../../model'
import { unwrap } from '../utils/extract'
import { addressOf } from '../utils/helper'
import { Context, isNFT } from '../utils/types'
import { getAttributeEvent } from './getters'
import { attributeFrom, tokenIdOf } from './types'
Expand All @@ -13,13 +12,12 @@ export async function handleAttributeSet(context: Context): Promise<void> {
isNFT(event)
? await get(context.store, NFTEntity, tokenIdOf(event as any))
: await get(context.store, CollectionEntity, event.collectionId)

if (!final.attributes) {
final.attributes = []
}

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

if ('recipient' in final && event.trait === 'recipient') {
Expand All @@ -32,7 +30,7 @@ export async function handleAttributeSet(context: Context): Promise<void> {
const attribute = final.attributes?.find((attr) => attr.trait === event.trait)
if (attribute) {
attribute.value = String(event.value)
} else {
} else if (event.trait !== 'royalty' && event.trait !== 'recipient') {
const newAttribute = attributeFrom({ trait_type: event.trait, value: String(event.value) })
final.attributes?.push(newAttribute)
}
Expand Down

0 comments on commit 74fda95

Please sign in to comment.