diff --git a/src/adapters/third-party-wearables-fetcher.ts b/src/adapters/third-party-wearables-fetcher.ts index fb5ea05f..7082aac7 100644 --- a/src/adapters/third-party-wearables-fetcher.ts +++ b/src/adapters/third-party-wearables-fetcher.ts @@ -1,7 +1,7 @@ import LRU from 'lru-cache' import { IBaseComponent } from '@well-known-components/interfaces' import { AppComponents, Limits, ThirdPartyAsset, ThirdPartyWearable } from '../types' -import { BlockchainCollectionThirdPartyCollection } from '@dcl/urn-resolver' +import { BlockchainCollectionThirdPartyName } from '@dcl/urn-resolver' import { findAsync, parseUrn } from '../logic/utils' // TODO cache metrics @@ -38,7 +38,7 @@ export type ThirdPartyWearablesFetcher = IBaseComponent & { fetchByOwner(address: string, limits: Limits): Promise fetchCollectionByOwner( address: string, - collectionUrn: BlockchainCollectionThirdPartyCollection, + thirdPartyNameUrn: BlockchainCollectionThirdPartyName, limits: Limits ): Promise } @@ -202,7 +202,7 @@ export async function createThirdPartyWearablesFetcherComponent({ async function fetchCollectionByOwner( address: string, - collectionUrn: BlockchainCollectionThirdPartyCollection, + thirdPartyNameUrn: BlockchainCollectionThirdPartyName, { offset, limit }: Limits ): Promise { let results: ThirdPartyWearable[] = [] @@ -215,8 +215,7 @@ export async function createThirdPartyWearablesFetcherComponent({ if ( wearableUrn && wearableUrn.type === URN_THIRD_PARTY_ASSET_TYPE && - wearableUrn.collectionId === collectionUrn.collectionId && - wearableUrn.thirdPartyName === collectionUrn.thirdPartyName + wearableUrn.thirdPartyName === thirdPartyNameUrn.thirdPartyName ) { results.push(wearable) } @@ -226,7 +225,9 @@ export async function createThirdPartyWearablesFetcherComponent({ (await thirdPartiesCache.fetch(0))!, async (thirdParty: ThirdParty): Promise => { const urn = await parseUrn(thirdParty.id) - return !!urn && urn.type === URN_THIRD_PARTY_NAME_TYPE && urn.thirdPartyName === collectionUrn.thirdPartyName + return ( + !!urn && urn.type === URN_THIRD_PARTY_NAME_TYPE && urn.thirdPartyName === thirdPartyNameUrn.thirdPartyName + ) } ) @@ -234,17 +235,12 @@ export async function createThirdPartyWearablesFetcherComponent({ // NOTE: currently lambdas return an empty array with status code 200 for this case throw new ThirdPartyFetcherError( ThirdPartyFetcherErrorCode.THIRD_PARTY_NOT_FOUND, - `Third Party not found ${collectionUrn.thirdPartyName}` + `Third Party not found ${thirdPartyNameUrn.thirdPartyName}` ) } const assets = await fetchAssets(address, thirdParty) - results = groupThirdPartyWearablesByURN( - assets.filter((asset: ThirdPartyAsset) => { - const [collectionId, _] = asset.id.split(':') - return collectionId === collectionUrn.collectionId - }) - ) + results = groupThirdPartyWearablesByURN(assets) const totalAmount = results.length return { diff --git a/src/controllers/handlers/wearables-handler.ts b/src/controllers/handlers/wearables-handler.ts index a0b8c4c4..66851d8e 100644 --- a/src/controllers/handlers/wearables-handler.ts +++ b/src/controllers/handlers/wearables-handler.ts @@ -163,7 +163,10 @@ export async function thirdPartyCollectionWearablesHandler( const logger = logs.getLogger('third-party-collections-handler') const { address, collectionId } = context.params - const urn = await parseUrn(collectionId) + // Strip the last part (the 6th part) if a collection contract id is specified + const collectionIdCleaned = collectionId.split(':').slice(0, 5).join(':') + + const urn = await parseUrn(collectionIdCleaned) if (!urn) { return { status: 400, @@ -173,11 +176,12 @@ export async function thirdPartyCollectionWearablesHandler( } } - if (urn.type !== 'blockchain-collection-third-party-collection') { + if (urn.type !== 'blockchain-collection-third-party-name') { return { status: 400, body: { - error: 'Invalid collection id: not a blockchain-collection-third-party-collection URN' + error: + 'Invalid collection id: not a blockchain-collection-third-party-name nor blockchain-collection-third-party-collection URN' } } } @@ -227,7 +231,7 @@ export async function thirdPartyCollectionWearablesHandler( return { status: 502, body: { - error: 'Cannot fetch third parties right now' + error: 'Cannot fetch third parties right now. Third party not found' } } }