Skip to content

Commit

Permalink
feat: third party wearables v2 (#6236)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorux0 authored Aug 19, 2024
1 parent 77de5fd commit 5092dfe
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,54 @@
{
public static class ExtendedUrnParser
{
private const int QUANTITY_OF_PARTS_ON_SHORTENED_ITEMS_URN = 6;
private const string COLLECTIONS_THIRDPARTY = "collections-thirdparty";
private const int REGULAR_NFTS_SHORT_PARTS = 6;
private const int THIRD_PARTY_V2_SHORTEN_URN_PARTS = 7;
private const string COLLECTIONS_THIRD_PARTY = "collections-thirdparty";

public static string GetShortenedUrn(string urnReceived)
{
int lastIndex = urnReceived.LastIndexOf(':');
if (string.IsNullOrEmpty(urnReceived)) return urnReceived;
if (CountParts(urnReceived) <= REGULAR_NFTS_SHORT_PARTS) return urnReceived;

return lastIndex != -1 && IsExtendedUrn(urnReceived)
? urnReceived.Substring(0, lastIndex)
: urnReceived;
int index;

if (IsThirdPartyCollection(urnReceived))
{
index = -1;

// Third party v2 contains 10 parts, on which 3 are reserved for the tokenId
// "id": urn:decentraland:amoy:collections-thirdparty:back-to-the-future:amoy-eb54:tuxedo-6751:amoy:0x1d9fb685c257e74f869ba302e260c0b68f5ebb37:12
// "tokenId": amoy:0x1d9fb685c257e74f869ba302e260c0b68f5ebb37:12
for (var i = 0; i < THIRD_PARTY_V2_SHORTEN_URN_PARTS; i++)
{
index = urnReceived.IndexOf(':', index + 1);
if (index == -1) break;
}

return index != -1 ? urnReceived[..index] : urnReceived;
}

// TokenId is always placed in the last part for regular nfts
index = urnReceived.LastIndexOf(':');

return index != -1 ? urnReceived[..index] : urnReceived;
}

public static bool IsExtendedUrn(string urn) =>
urn.Split(':').Length > QUANTITY_OF_PARTS_ON_SHORTENED_ITEMS_URN && !urn.Contains(COLLECTIONS_THIRDPARTY);
}
private static int CountParts(string urn)
{
int count = 1;
int index = urn.IndexOf(':');

while (index != -1)
{
count++;
index = urn.IndexOf(':', index + 1);
}

return count;
}

private static bool IsThirdPartyCollection(string urn) =>
!string.IsNullOrEmpty(urn) && urn.Contains(COLLECTIONS_THIRD_PARTY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,7 @@ private void EquipWearable(
bool resetOverride = true)
{
string shortenWearableId = ExtendedUrnParser.GetShortenedUrn(wearable.id);

if (ExtendedUrnParser.IsExtendedUrn(extendedWearableId))
extendedWearableUrns[shortenWearableId] = extendedWearableId;
extendedWearableUrns[shortenWearableId] = extendedWearableId;

if (wearable.data.category == WearableLiterals.Categories.BODY_SHAPE)
{
Expand Down

0 comments on commit 5092dfe

Please sign in to comment.