Skip to content

Commit

Permalink
fix: do not fetch with extended urns (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
Melisa Anabella Rossi authored Dec 1, 2023
1 parent 85b3326 commit 844aabe
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ import {
import { computeZoom, getZoom } from './zoom'

const DEFAULT_PROFILE = 'default'
const QUANTITY_OF_PARTS_ON_SHORTENED_ITEMS_URN = 6

function getTokenIdAndAssetUrn(completeUrn: string): { assetUrn: string; tokenId: string | undefined } {
const lastIndex = completeUrn.lastIndexOf(':')

return lastIndex !== -1 && completeUrn.split(':').length > QUANTITY_OF_PARTS_ON_SHORTENED_ITEMS_URN
? { assetUrn: completeUrn.substring(0, lastIndex), tokenId: completeUrn.substring(lastIndex + 1) }
: { assetUrn: completeUrn, tokenId: undefined }
}

async function fetchItem(urn: string, peerUrl: string) {
const [wearables, emotes] = await fetchURNs([urn], peerUrl)
Expand Down Expand Up @@ -86,7 +95,10 @@ async function fetchURNs(urns: string[], peerUrl: string): Promise<[WearableDefi
if (urns.length === 0) {
return [[], []]
}
return peerApi.fetchItems(urns, peerUrl)

const sanitizedAssetUrns = urns.map((urn: string) => getTokenIdAndAssetUrn(urn).assetUrn)

return peerApi.fetchItems(sanitizedAssetUrns, peerUrl)
}

async function fetchURLs(urls: string[]): Promise<[WearableDefinition[], EmoteDefinition[]]> {
Expand Down

1 comment on commit 844aabe

@vercel
Copy link

@vercel vercel bot commented on 844aabe Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.