Skip to content

Commit

Permalink
Merge pull request #115 from decentraland/fix/allow-new-third-party-urns
Browse files Browse the repository at this point in the history
fix: Allow new third parties URN
  • Loading branch information
LautaroPetaccio authored Aug 16, 2024
2 parents 4b93c3f + 153fa62 commit 8a0c65c
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,40 @@ import { computeZoom, getZoom } from './zoom'

const DEFAULT_PROFILE = 'default'
const QUANTITY_OF_PARTS_ON_SHORTENED_ITEMS_URN = 6
const THIRD_PARTY_URN_ID = "collections-thirdparty"
const THIRD_PARTY_URN_ID = 'collections-thirdparty'
const MAPPED_THIRD_PARTY_ITEM_FULL_URN_PROPERTIES_LENGTH = 10

type URNData = {
assetUrn: string
tokenId?: string
network?: string
contractAddress?: string
}

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

let result: URNData | undefined

if (
completeUrn.includes(THIRD_PARTY_URN_ID) &&
urnPropertiesLength === MAPPED_THIRD_PARTY_ITEM_FULL_URN_PROPERTIES_LENGTH
) {
result = {
assetUrn: urnProperties.slice(0, 7).join(':'),
tokenId: urnProperties[9],
contractAddress: urnProperties[8],
network: urnProperties[7],
}
} else if (
!completeUrn.includes(THIRD_PARTY_URN_ID) &&
urnPropertiesLength > QUANTITY_OF_PARTS_ON_SHORTENED_ITEMS_URN
) {
result = { assetUrn: urnProperties.slice(0, -1).join(':'), tokenId: urnProperties[urnPropertiesLength - 1] }
}

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

async function fetchItem(urn: string, peerUrl: string) {
Expand Down

0 comments on commit 8a0c65c

Please sign in to comment.