< Summary

Class:DCLServices.CustomNftCollection.WebInterfaceCustomNftCatalogBridge
Assembly:CustomNftCollection
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/CustomNftCollection/WebInterfaceCustomNftCollectionBridge.cs
Covered lines:4
Uncovered lines:20
Coverable lines:24
Total lines:92
Line coverage:16.6% (4 of 24)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:7
Method coverage:42.8% (3 of 7)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetOrCreate()0%660100%
Dispose()0%110100%
Initialize()0%110100%
GetConfiguredCustomNftCollectionAsync()0%20400%
GetConfiguredCustomNftItemsAsync()0%20400%
SetWithCollectionsParam(...)0%6200%
SetWithItemsParam(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/CustomNftCollection/WebInterfaceCustomNftCollectionBridge.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL;
 3using DCL.Helpers;
 4using DCL.Interface;
 5using JetBrains.Annotations;
 6using Newtonsoft.Json;
 7using System;
 8using System.Collections.Generic;
 9using System.Linq;
 10using System.Threading;
 11using UnityEngine;
 12
 13namespace DCLServices.CustomNftCollection
 14{
 15    public class WebInterfaceCustomNftCatalogBridge : MonoBehaviour, ICustomNftCollectionService
 16    {
 17        private string[] items;
 18        private string[] collections;
 19
 20        public static WebInterfaceCustomNftCatalogBridge GetOrCreate()
 21        {
 42522            var bridgeObj = SceneReferences.i?.bridgeGameObject;
 23
 42524            return SceneReferences.i?.bridgeGameObject == null
 25                ? new GameObject("Bridge").AddComponent<WebInterfaceCustomNftCatalogBridge>()
 26                : bridgeObj.GetOrCreateComponent<WebInterfaceCustomNftCatalogBridge>();
 27        }
 28
 42529        public void Dispose() { }
 30
 42531        public void Initialize() { }
 32
 33        public async UniTask<IReadOnlyList<string>> GetConfiguredCustomNftCollectionAsync(CancellationToken cancellation
 34        {
 035            if (collections != null)
 036                return collections;
 37
 038            WebInterface.GetWithCollectionsUrlParam();
 39
 40            // Reworked into this approach. Using a UniTaskCompletionSource<IReadOnlyList<string>> emits an invalid stri
 41            // on WebGL. Seems like a IL2CPP issue, not sure. This workaround is the only one i found to make it work on
 042            await UniTask.WaitUntil(() => collections != null, cancellationToken: cancellationToken)
 43                         .Timeout(TimeSpan.FromSeconds(30));
 44
 045            return collections;
 046        }
 47
 48        public async UniTask<IReadOnlyList<string>> GetConfiguredCustomNftItemsAsync(CancellationToken cancellationToken
 49        {
 050            if (items != null)
 051                return items;
 52
 053            WebInterface.GetWithItemsUrlParam();
 54
 55            // Reworked into this approach. Using a UniTaskCompletionSource<IReadOnlyList<string>> emits an invalid stri
 56            // on WebGL. Seems like a IL2CPP issue, not sure. This workaround is the only one i found to make it work on
 057            await UniTask.WaitUntil(() => items != null, cancellationToken: cancellationToken)
 58                         .Timeout(TimeSpan.FromSeconds(30));
 59
 060            return items;
 061        }
 62
 63        [PublicAPI("Kernel response for GetParametrizedCustomNftCollectionAsync")]
 64        public void SetWithCollectionsParam(string json)
 65        {
 066            CollectionIdsPayload payload = JsonConvert.DeserializeObject<CollectionIdsPayload>(json);
 067            string[] collectionIds = payload.collectionIds.Where(s => !string.IsNullOrEmpty(s)).ToArray();
 068            collections = collectionIds;
 069        }
 70
 71        [PublicAPI("Kernel response for GetConfiguredCustomNftItemsAsync")]
 72        public void SetWithItemsParam(string json)
 73        {
 074            ItemIdsPayload payload = JsonConvert.DeserializeObject<ItemIdsPayload>(json);
 75
 076            string[] itemIds = payload.itemIds.Where(s => !string.IsNullOrEmpty(s)).ToArray();
 077            items = itemIds;
 078        }
 79
 80        [Serializable]
 81        private struct CollectionIdsPayload
 82        {
 83            public string[] collectionIds;
 84        }
 85
 86        [Serializable]
 87        private struct ItemIdsPayload
 88        {
 89            public string[] itemIds;
 90        }
 91    }
 92}