Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: third party wearables v2 #6236

Merged
merged 8 commits into from
Aug 19, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,40 @@
{
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 string COLLECTIONS_THIRD_PARTY = "collections-thirdparty";

public static string GetShortenedUrn(string urnReceived)
{
if (!IsExtendedUrn(urnReceived)) return urnReceived;

int lastIndex = urnReceived.LastIndexOf(':');

return lastIndex != -1 && IsExtendedUrn(urnReceived)
? urnReceived.Substring(0, lastIndex)
return lastIndex != -1
? urnReceived[..lastIndex]
: urnReceived;
}

public static bool IsExtendedUrn(string urn) =>
urn.Split(':').Length > QUANTITY_OF_PARTS_ON_SHORTENED_ITEMS_URN && !urn.Contains(COLLECTIONS_THIRDPARTY);
}
public static bool IsExtendedUrn(string urn)
{
if (urn.Contains(COLLECTIONS_THIRD_PARTY))
return false;

return CountParts(urn) > REGULAR_NFTS_SHORT_PARTS;
}

private static int CountParts(string urn)
{
int count = 1;
int index = urn.IndexOf(':');

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

return count;
}
}
}
Loading