Skip to content

Commit

Permalink
feat: NFTIO-2880 Add to address for offers on fungible tokens (#1496)
Browse files Browse the repository at this point in the history
* fix

* NFTIO-2880
  • Loading branch information
justraman authored Jan 14, 2025
1 parent ff3b49f commit 6da40f0
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/mappings/marketplace/events/listing_created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
OfferData,
OfferState,
Token,
TokenAccount,
} from '../../../model'
import { CommonContext, BlockHeader, EventItem } from '../../types/contexts'
import { getOrCreateAccount } from '../../util/entities'
Expand All @@ -45,7 +46,12 @@ function getEventData(ctx: CommonContext, event: EventItem) {
throw new UnknownVersionError(events.marketplace.listingCreated.name)
}

function getEvent(item: EventItem, data: ReturnType<typeof getEventData>): [EventModel, AccountTokenEvent] | undefined {
async function getEvent(
ctx: CommonContext,
item: EventItem,
data: ReturnType<typeof getEventData>,
listing: Listing
): Promise<[EventModel, AccountTokenEvent] | undefined> {
let event: EventModel

event = new EventModel({
Expand All @@ -72,12 +78,21 @@ function getEvent(item: EventItem, data: ReturnType<typeof getEventData>): [Even
})
}

let to = null
if (data.listing.data.__kind === 'Offer' && listing.takeAssetId.nonFungible) {
const tokenOwner = await ctx.store.findOne(TokenAccount, { where: { token: { id: listing.takeAssetId.id } } })
if (tokenOwner) {
to = tokenOwner.account
}
}

return [
event,
new AccountTokenEvent({
id: item.id,
token: new Token({ id: event.tokenId! }),
from: new Account({ id: 'creator' in data.listing ? data.listing.creator : data.listing.seller }),
to,
event,
}),
]
Expand Down Expand Up @@ -210,5 +225,5 @@ export async function listingCreated(
})
}

return getEvent(item, data)
return await getEvent(ctx, item, data, listing)
}

0 comments on commit 6da40f0

Please sign in to comment.