Skip to content

Commit bd707ba

Browse files
authored
fix: request owned wearables in local preview (#5664)
1 parent 0ec56dd commit bd707ba

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

unity-renderer/Assets/DCLServices/WearablesCatalogService/LambdasWearablesCatalogService.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Collections.Generic;
88
using System.Linq;
99
using System.Threading;
10-
using System.Threading.Tasks;
1110
using UnityEngine;
1211
using UnityEngine.Pool;
1312
using static DCLServices.WearablesCatalogService.WearableWithEntityResponseDto.ElementDto;
@@ -56,26 +55,29 @@ public WearableCollectionResponse(EntityDto[] entities)
5655
private readonly Dictionary<(string userId, string collectionId, int pageSize), LambdaResponsePagePointer<WearableWithDefinitionResponse>> thirdPartyCollectionPagePointers = new ();
5756
private readonly List<string> pendingWearablesToRequest = new ();
5857
private readonly BaseVariable<FeatureFlag> featureFlags;
58+
private readonly DataStore dataStore;
59+
private readonly ICatalyst catalyst;
5960
private string assetBundlesUrl => featureFlags.Get().IsFeatureEnabled("ab-new-cdn") ? "https://ab-cdn.decentraland.org/" : "https://content-assets-as-bundle.decentraland.org/";
6061

6162
private CancellationTokenSource serviceCts;
6263
private UniTaskCompletionSource<IReadOnlyList<WearableItem>> lastRequestSource;
63-
private ICatalyst catalyst;
6464

6565
#if UNITY_EDITOR
6666
private readonly DebugConfig debugConfig = DataStore.i.debugConfig;
6767
#endif
68+
6869
public LambdasWearablesCatalogService(BaseDictionary<string, WearableItem> wearablesCatalog,
6970
ILambdasService lambdasService,
7071
IServiceProviders serviceProviders,
71-
BaseVariable<FeatureFlag> featureFlags)
72+
BaseVariable<FeatureFlag> featureFlags,
73+
DataStore dataStore)
7274
{
7375
this.featureFlags = featureFlags;
76+
this.dataStore = dataStore;
7477
this.lambdasService = lambdasService;
7578
this.serviceProviders = serviceProviders;
7679
WearablesCatalog = wearablesCatalog;
7780
catalyst = serviceProviders.catalyst;
78-
7981
}
8082

8183
public void Initialize()
@@ -143,8 +145,20 @@ public void Dispose()
143145
foreach (string collectionId in thirdPartyCollectionIds)
144146
queryParams.Add(("thirdPartyCollectionId", collectionId));
145147

146-
string lambdasUrl = await catalyst.GetLambdaUrl(cancellationToken);
147-
string explorerUrl = lambdasUrl.Replace("/lambdas", "/explorer");
148+
string explorerUrl;
149+
string contentUrl;
150+
151+
if (IsLocalPreview())
152+
{
153+
explorerUrl = "https://peer.decentraland.org/explorer/";
154+
contentUrl = "https://peer.decentraland.org/content/contents/";
155+
}
156+
else
157+
{
158+
string lambdasUrl = await catalyst.GetLambdaUrl(cancellationToken);
159+
explorerUrl = lambdasUrl.Replace("/lambdas", "/explorer");
160+
contentUrl = $"{catalyst.contentUrl}/contents/";
161+
}
148162

149163
(WearableWithEntityResponseDto response, bool success) = await lambdasService.GetFromSpecificUrl<WearableWithEntityResponseDto>(
150164
$"{explorerUrl}/:userId/wearables",
@@ -156,7 +170,7 @@ public void Dispose()
156170
throw new Exception($"The request of wearables for '{userId}' failed!");
157171

158172
List<WearableItem> wearables = ValidateWearables(response.elements,
159-
$"{catalyst.contentUrl}/contents/",
173+
contentUrl,
160174
assetBundlesUrl);
161175

162176
AddWearablesToCatalog(wearables);
@@ -582,5 +596,8 @@ private bool IsInvalidWearable(EntityDto.MetadataDto metadata)
582596

583597
return false;
584598
}
599+
600+
private bool IsLocalPreview() =>
601+
dataStore.realm.playerRealm.Get()?.serverName?.Equals("LocalPreview", StringComparison.OrdinalIgnoreCase) ?? false;
585602
}
586603
}

unity-renderer/Assets/DCLServices/WearablesCatalogService/Tests/LambdasWearablesCatalogServiceShould.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void SetUp()
7070

7171
BaseVariable<FeatureFlag> featureFlags = new BaseVariable<FeatureFlag>();
7272
featureFlags.Set(new FeatureFlag());
73-
service = new LambdasWearablesCatalogService(initialCatalog, lambdasService, serviceProviders, featureFlags);
73+
service = new LambdasWearablesCatalogService(initialCatalog, lambdasService, serviceProviders, featureFlags, new DataStore());
7474
service.Initialize();
7575
}
7676

unity-renderer/Assets/DCLServices/WearablesCatalogService/Tests/WarablesCatalogServiceTests.asmdef

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"ServiceProvidersInterfaces",
1414
"CatalystInterfaces",
1515
"FeatureFlagData",
16-
"Utils"
16+
"Utils",
17+
"DataStore"
1718
],
1819
"includePlatforms": [],
1920
"excludePlatforms": [],

unity-renderer/Assets/Scripts/MainScripts/DCL/Environment/Factories/ServiceLocatorFactory/ServiceLocatorFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ public static ServiceLocator CreateDefault()
145145
new LambdasWearablesCatalogService(DataStore.i.common.wearables,
146146
result.Get<ILambdasService>(),
147147
result.Get<IServiceProviders>(),
148-
featureFlagsDataStore),
148+
featureFlagsDataStore,
149+
DataStore.i),
149150
WebInterfaceWearablesCatalogService.Instance,
150151
DataStore.i.common.wearables,
151152
KernelConfig.i,

0 commit comments

Comments
 (0)