Skip to content

Commit

Permalink
fix: handling of third-party wearable on ExtendedUrnParser class (#6202)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleortega authored Jun 4, 2024
1 parent e8937d1 commit d3f77d6
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 24 deletions.
14 changes: 7 additions & 7 deletions browser-interface/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion browser-interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@dcl/legacy-ecs": "^6.11.11",
"@dcl/protocol": "1.0.0-8789372854.commit-f692c7a",
"@dcl/rpc": "^1.1.1",
"@dcl/scene-runtime": "7.0.6-20240220184109.commit-cf1e4e2",
"@dcl/scene-runtime": "7.0.6-20240515153908.commit-adbf9e7",
"@dcl/schemas": "^9.1.1",
"@dcl/single-sign-on-client": "^0.1.0",
"@dcl/urn-resolver": "^2.2.0",
Expand Down
2 changes: 1 addition & 1 deletion browser-interface/packages/shared/catalogs/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ function fetchOwnedEmotes(ethAddress: string, client: CatalystClient) {

export function urnWithoutToken(urn: string): string {
const value = urn.split(':')
if (value.length === 7) {
if (value.length === 7 && !urn.includes("collections-thirdparty")) {
return value.slice(0, 6).join(':')
}
return urn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PREVIEW } from 'config'
import { SourceMapConsumerConstructor, Sourcemap } from './types'

import('./source-map@0.7.4.js')
Expand Down Expand Up @@ -45,6 +46,11 @@ export async function initSourcemap(code: string, inlineSourcemaps: boolean = tr
* in every error. So we need to fix that in the error code stack.
*/
function adjustStackTrace(stackTrace: string) {
// Don't adjust the stack trace if we are in preview mode
// preview mode uses a plain eval wrapped, so this is not necessary
// see more https://github.com/decentraland/scene-runtime/pull/211
if (PREVIEW) return stackTrace

const lines = stackTrace.split('\n')
const adjustedLines = lines.map((line) => {
// Check if the line contains a line number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public static class ExtendedUrnParser
{
private const int QUANTITY_OF_PARTS_ON_SHORTENED_ITEMS_URN = 6;
private const string COLLECTIONS_THIRDPARTY = "collections-thirdparty";

public static string GetShortenedUrn(string urnReceived)
{
Expand All @@ -14,7 +15,7 @@ public static string GetShortenedUrn(string urnReceived)
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@ private async UniTask<WearableItem> SyncWearablesRequestsAsync(string newWearabl

ct.ThrowIfCancellationRequested();

return result.FirstOrDefault(x => x.id == ExtendedUrnParser.GetShortenedUrn(newWearableId));
return result.FirstOrDefault(x => string.Equals(x.id, ExtendedUrnParser.GetShortenedUrn(newWearableId),
StringComparison.OrdinalIgnoreCase));
}

private List<WearableItem> ValidateWearables(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static IEnumerator GetMarket(string chain, string assetContractAddress, s
IServiceProviders serviceProviders = Environment.i.platform.serviceProviders;
IOpenSea openSea = null;

if ( serviceProviders != null )
if (serviceProviders != null)
openSea = serviceProviders.openSea;

onSuccess?.Invoke(openSea);
Expand All @@ -97,7 +97,7 @@ public static IEnumerator GetMarket(string assetContractAddress, Action<IOpenSea
IServiceProviders serviceProviders = Environment.i.platform.serviceProviders;
IOpenSea openSea = null;

if ( serviceProviders != null )
if (serviceProviders != null)
openSea = serviceProviders.openSea;

onSuccess?.Invoke(openSea);
Expand All @@ -119,6 +119,7 @@ public static bool TryParseUrn(string urn, out string chain, out string contract
{
const char SEPARATOR = ':';
const string DCL_URN_ID = "urn:decentraland";
const string COLLECTIONS_THIRDPARTY = "collections-thirdparty";

contractAddress = string.Empty;
tokenId = string.Empty;
Expand All @@ -133,8 +134,6 @@ public static bool TryParseUrn(string urn, out string chain, out string contract
return false;
urnSpan = urnSpan.Slice(DCL_URN_ID.Length + 1);

// TODO: allow 'matic' chain when Opensea implements its APIv2 "retrieve assets" endpoint
// (https://docs.opensea.io/v2.0/reference/api-overview) in the future
// 2: chain/network
var chainSpan = urnSpan.Slice(0, urnSpan.IndexOf(SEPARATOR));
urnSpan = urnSpan.Slice(chainSpan.Length + 1);
Expand All @@ -143,20 +142,33 @@ public static bool TryParseUrn(string urn, out string chain, out string contract
var contractStandardSpan = urnSpan.Slice(0, urnSpan.IndexOf(SEPARATOR));
urnSpan = urnSpan.Slice(contractStandardSpan.Length + 1);

// 4: contract address
var contractAddressSpan = urnSpan.Slice(0, urnSpan.IndexOf(SEPARATOR));
urnSpan = urnSpan.Slice(contractAddressSpan.Length + 1);
// check if wearables is third-party
if (contractStandardSpan.ToString().Equals(COLLECTIONS_THIRDPARTY, StringComparison.Ordinal))
{
// 4: contract address
var contractAddressSpan = urnSpan;
contractAddress = contractAddressSpan.ToString();

// NOTE: Third Party wearables do not have token id at the moment
}
else
{
// 4: contract address
var contractAddressSpan = urnSpan.Slice(0, urnSpan.IndexOf(SEPARATOR));
urnSpan = urnSpan.Slice(contractAddressSpan.Length + 1);

// 5: token id
var tokenIdSpan = urnSpan;
contractAddress = contractAddressSpan.ToString();
tokenId = tokenIdSpan.ToString();
}

// 5: token id
var tokenIdSpan = urnSpan;
contractAddress = contractAddressSpan.ToString();
tokenId = tokenIdSpan.ToString();
chain = chainSpan.ToString();

return true;
}
catch (Exception e)
{ // ignored
{
// ignored
}

return false;
Expand Down

0 comments on commit d3f77d6

Please sign in to comment.