Skip to content

Commit

Permalink
feat(billboard): move getClearableAuctions under clearAuctions step
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Mar 5, 2024
1 parent 477bf53 commit 6f341ac
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions handlers/clear-auction-and-distribute-tax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,21 @@ export const handler = async (
}
}

// get auctions to be cleared
const auctions = await getClearableAuctions({ fromTokenId, toTokenId })

if (!auctions || auctions.length <= 0) {
return {
statusCode: 200,
body: JSON.stringify({ message: 'no auction to clear.' }),
}
}

// Step 1: clear auctions
let clearedAuctions: string[] = []
if (fromStep === 'clearAuctions') {
try {
// get auctions to be cleared
const auctions = await getClearableAuctions({ fromTokenId, toTokenId })

if (!auctions || auctions.length <= 0) {
return {
statusCode: 200,
body: JSON.stringify({ message: 'no auction to clear.' }),
}
}
clearedAuctions = auctions.map(({ tokenId }) => tokenId.toString())

const clearAuctionsResult = await publicClient.simulateContract({
...billboardContract,
functionName: 'clearAuctions',
Expand Down Expand Up @@ -131,7 +133,7 @@ export const handler = async (

// response
const data = {
auctionIds: auctions.map((a) => a.auctionId.toString()),
auctionIds: clearedAuctions,
totalTax: tax.toString(),
merkleRoot,
}
Expand Down

0 comments on commit 6f341ac

Please sign in to comment.