Skip to content

Commit

Permalink
fix(getStatNFT): useless marketplaceId/owner parameters removed
Browse files Browse the repository at this point in the history
  • Loading branch information
ipapandinas committed Feb 21, 2022
1 parent 9e8cb2f commit 396a567
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/api/helpers/nftHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ export async function populateStat(
smallestPrice: string
}> {
try {
const marketplaceId = query.filter?.marketplaceId;
const owner = query.filter?.owner;
const stat = await NFTService.getStatNFT(NFT.serieId, marketplaceId, owner, query)
const stat = await NFTService.getStatNFT(NFT.serieId, query)
return stat
} catch (err) {
L.error({ err }, "NFTs stats could not have been fetched");
Expand Down
15 changes: 9 additions & 6 deletions src/api/services/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class NFTService {
* @param filterOptionsQuery - filter options (optional)
* @throws Will throw an error if can't request indexer
*/
async getStatNFT(seriesId:string, marketplaceId:number=null, owner:string=null, filterOptionsQuery:getTotalFilteredNFTsQuery=null): Promise<{
async getStatNFT(seriesId:string, query:NFTsQuery=null): Promise<{
totalNft: number,
totalListedNft: number,
totalFiltered: number | null,
Expand All @@ -160,15 +160,18 @@ export class NFTService {
totalOwnedListedInMarketplaceByRequestingUser: number,
smallestPrice: string
}> {
const marketplaceId = query.filter.marketplaceId ?? null;
const owner = query.filter.owner ?? null;

try {
const [totalRequest, totalListedRequest, totalFilteredRequest, totalListedInMarketplaceRequest, totalOwnedByRequestingUserRequest, totalOwnedListedByRequestingUserRequest, totalOwnedListedInMarketplaceByRequestingUserRequest, smallestPriceRequest] = await Promise.all([
request(indexerUrl, QueriesBuilder.countTotal(seriesId)),
request(indexerUrl, QueriesBuilder.countTotalListed(seriesId)),
filterOptionsQuery ? request(indexerUrl, QueriesBuilder.countTotalFilteredNFTs(filterOptionsQuery, seriesId)) : null,
marketplaceId!==null ? request(indexerUrl, QueriesBuilder.countTotalListedInMarketplace(seriesId, marketplaceId)) : 0,
owner ? request(indexerUrl, QueriesBuilder.countTotalOwned(seriesId, owner)) : null,
owner ? request(indexerUrl, QueriesBuilder.countTotalOwnedListed(seriesId, owner)) : null,
owner && marketplaceId!==null ? request(indexerUrl, QueriesBuilder.countTotalOwnedListedInMarketplace(seriesId, owner, marketplaceId)) : null,
query ? request(indexerUrl, QueriesBuilder.countTotalFilteredNFTs(query, seriesId)) : null,
marketplaceId !== null ? request(indexerUrl, QueriesBuilder.countTotalListedInMarketplace(seriesId, marketplaceId)) : 0,
owner !== null ? request(indexerUrl, QueriesBuilder.countTotalOwned(seriesId, owner)) : null,
owner !== null ? request(indexerUrl, QueriesBuilder.countTotalOwnedListed(seriesId, owner)) : null,
owner !== null && marketplaceId !== null ? request(indexerUrl, QueriesBuilder.countTotalOwnedListedInMarketplace(seriesId, owner, marketplaceId)) : null,
request(indexerUrl, QueriesBuilder.countSmallestPrice(seriesId, marketplaceId)),
])
const totalNft: number = totalRequest.nftEntities.totalCount;
Expand Down

0 comments on commit 396a567

Please sign in to comment.