< Summary

Class:DCL.Backpack.VRMDetailsController
Assembly:BackpackEditorHUDV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BackpackEditorHUDV2/VRMExport/VRMDetailsController.cs
Covered lines:9
Uncovered lines:37
Coverable lines:46
Total lines:114
Line coverage:19.5% (9 of 46)
Covered branches:0
Total branches:0
Covered methods:1
Total methods:6
Method coverage:16.6% (1 of 6)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
VRMDetailsController(...)0%110100%
Dispose()0%2100%
HandleWearableEquipped(...)0%6200%
HandleWearableUnequipped(...)0%6200%
Initialize(...)0%2100%
PopulateDetails()0%1821300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BackpackEditorHUDV2/VRMExport/VRMDetailsController.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCLServices.EnvironmentProvider;
 3using System;
 4using System.Collections.Generic;
 5using UnityEngine;
 6
 7namespace DCL.Backpack
 8{
 9    public class VRMDetailsController : IDisposable
 10    {
 11        private readonly IUserProfileBridge userProfileBridge;
 12        private readonly IVRMDetailsComponentView view;
 2513        private readonly Dictionary<string, NFTDataDTO> nftDataCache = new ();
 14        private readonly INFTFetchHelper nftFetchHelper;
 15        private IEnvironmentProviderService environmentProviderService;
 16
 17        public event Action<string, UnequipWearableSource> OnWearableUnequipped;
 18        public event Action<string, EquipWearableSource> OnWearableEquipped;
 19
 2520        public VRMDetailsController(
 21            IVRMDetailsComponentView view,
 22            IUserProfileBridge userProfileBridge,
 23            INFTFetchHelper nftFetchHelper,
 24            IEnvironmentProviderService environmentProviderService)
 25        {
 2526            this.view = view;
 2527            this.userProfileBridge = userProfileBridge;
 2528            this.nftFetchHelper = nftFetchHelper;
 2529            this.environmentProviderService = environmentProviderService;
 30
 2531            view.OnWearableUnequipped += HandleWearableUnequipped;
 2532            view.OnWearableEquipped += HandleWearableEquipped;
 2533        }
 34
 35        public void Dispose()
 36        {
 037            view.OnWearableUnequipped -= HandleWearableUnequipped;
 038            view.OnWearableEquipped -= HandleWearableEquipped;
 039        }
 40
 41        private void HandleWearableEquipped(VRMItemModel vrmItemModel, EquipWearableSource equipWearableSource)
 42        {
 043            OnWearableEquipped?.Invoke(vrmItemModel.wearableUrn, equipWearableSource);
 044        }
 45
 46        private void HandleWearableUnequipped(VRMItemModel vrmItemModel, UnequipWearableSource unEquipWearableSource)
 47        {
 048            OnWearableUnequipped?.Invoke(vrmItemModel.wearableUrn, unEquipWearableSource);
 049        }
 50
 51        /// <summary>
 52        /// Initializes the controller.
 53        /// </summary>
 54        /// <param name="vrmBlockingWearables"> A dictionary where the Key is the wearable urn and the Value is whether 
 55        public void Initialize(Dictionary<string, bool> vrmBlockingWearables)
 56        {
 057            PopulateDetails(vrmBlockingWearables).Forget();
 058        }
 59
 60        private async UniTask PopulateDetails(Dictionary<string, bool> vrmBlockingWearables)
 61        {
 062            List<NFTDataDTO> itemsToDisplay = new ();
 63
 64            // Copy the list from params since it's used for other checks elsewhere
 065            Dictionary<string, bool> itemsToProcess = new (vrmBlockingWearables);
 66
 67            // Get cached items first, to reduce api calls.
 068            foreach ((string id, NFTDataDTO data) in nftDataCache)
 069                if (itemsToProcess.ContainsKey(id))
 70                {
 071                    itemsToDisplay.Add(data);
 072                    itemsToProcess.Remove(id);
 73                }
 74
 75            // If we're still missing items, fetch them.
 076            if (itemsToProcess.Count > 0)
 77            {
 078                string nftItemRawData = await nftFetchHelper.GetNFTItems(new List<string>(itemsToProcess.Keys), environm
 079                var nftItemsData = JsonUtility.FromJson<NFTItemsDTO>(nftItemRawData);
 80
 081                for (var i = 0; i < nftItemsData.data.Length; i++)
 82                {
 083                    NFTDataDTO nftDataDto = nftItemsData.data[i];
 084                    var creatorProfile = userProfileBridge.Get(nftDataDto.creator);
 85
 086                    if (creatorProfile == null)
 87                    {
 088                        creatorProfile = await userProfileBridge.RequestFullUserProfileAsync(nftDataDto.creator);
 89
 090                        if (creatorProfile == null)
 91                        {
 092                            Debug.LogError($"Creator {nftDataDto.creator} profile could not be retrieved!");
 093                            nftDataDto.creatorName = "User not found";
 094                            nftDataDto.creatorImageUrl = string.Empty;
 95                        }
 96                    }
 97
 098                    if (creatorProfile != null)
 99                    {
 0100                        nftDataDto.creatorName = creatorProfile.userName;
 0101                        nftDataDto.creatorImageUrl = creatorProfile.face256SnapshotURL;
 102                    }
 103
 0104                    nftDataDto.canBeUnEquipped = itemsToProcess[nftDataDto.urn];
 105
 0106                    nftDataCache.Add(nftDataDto.urn, nftDataDto);
 0107                    itemsToDisplay.Add(nftDataDto);
 0108                }
 0109            }
 110
 0111            view.FillVRMBlockingWearablesList(itemsToDisplay);
 0112        }
 113    }
 114}