Skip to content

Commit

Permalink
feat: flag orders as transferred
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed Jan 29, 2025
1 parent 72deac2 commit 79bb2a9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
5 changes: 2 additions & 3 deletions indexer/src/handlers/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getTokenURI,
cancelActiveOrder,
clearNFTOrderProperties,
handleTransferOrder,
} from '../modules/nft'
import { getCategory } from '../modules/category'
import { buildEstateFromNFT, getEstateImage } from '../modules/estate'
Expand Down Expand Up @@ -80,9 +81,7 @@ export function handleTransfer(event: Transfer): void {
metric.save()
} else {
let oldNFT = NFT.load(id)
if (cancelActiveOrder(oldNFT!, event.block.timestamp)) {
nft = clearNFTOrderProperties(nft!)
}
handleTransferOrder(oldNFT, event.params.to)
}

if (category == categories.PARCEL) {
Expand Down
23 changes: 22 additions & 1 deletion indexer/src/modules/nft/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { log, BigInt } from '@graphprotocol/graph-ts'
import { log, BigInt, Bytes } from '@graphprotocol/graph-ts'
import { NFT, Order, Bid } from '../../entities/schema'
import { ERC721, Transfer } from '../../entities/templates/ERC721/ERC721'
import * as status from '../order/status'
Expand Down Expand Up @@ -76,3 +76,24 @@ export function cancelActiveOrder(nft: NFT, now: BigInt): boolean {
}
return false
}


export function handleTransferOrder(nft: NFT | null, to: Bytes): void {
if (nft != null && nft.activeOrder != null) {
let oldOrder = Order.load(nft.activeOrder!)
if (oldOrder != null && oldOrder.status == status.OPEN) {
oldOrder.status = status.TRANSFERRED
oldOrder.save()
nft.searchOrderStatus = status.TRANSFERRED
} else if (oldOrder != null && oldOrder.status == status.TRANSFERRED) {
let isComingBackToOrderOwner = oldOrder.owner == to
if (isComingBackToOrderOwner) {
oldOrder.status = status.OPEN
oldOrder.save()
nft.searchOrderStatus = status.OPEN
} else {
nft.searchOrderStatus = status.TRANSFERRED
}
}
}
}
1 change: 1 addition & 0 deletions indexer/src/modules/order/status.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const OPEN = 'open'
export const SOLD = 'sold'
export const CANCELLED = 'cancelled'
export const TRANSFERRED = 'transferred'

0 comments on commit 79bb2a9

Please sign in to comment.