< Summary

Class:NFTInfoFetcher
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/LoadableShapes/NFTShape/NFTInfoFetcher.cs
Covered lines:8
Uncovered lines:7
Coverable lines:15
Total lines:50
Line coverage:53.3% (8 of 15)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Dispose()0%220100%
FetchNFTImage(...)0%2.062075%
FetchNFTImageCoroutine()0%4.123050%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/LoadableShapes/NFTShape/NFTInfoFetcher.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.IO;
 5using DCL;
 6using DCL.Helpers.NFT;
 7using Newtonsoft.Json;
 8using NFTShape_Internal;
 9using UnityEngine;
 10using UnityGLTF.Loader;
 11
 12public interface INFTInfoFetcher
 13{
 14    void FetchNFTImage(string address, string id, Action<NFTInfo> OnSuccess, Action OnFail);
 15    void Dispose();
 16}
 17
 18public class NFTInfoFetcher : INFTInfoFetcher
 19{
 20    internal Coroutine fetchCoroutine;
 21
 22    public void Dispose()
 23    {
 1024        if (fetchCoroutine != null)
 525            CoroutineStarter.Stop(fetchCoroutine);
 1026        fetchCoroutine = null;
 1027    }
 28
 29    public void FetchNFTImage(string address, string id, Action<NFTInfo> OnSuccess, Action OnFail)
 30    {
 1131        if (fetchCoroutine != null)
 032            CoroutineStarter.Stop(fetchCoroutine);
 33
 1134        fetchCoroutine = CoroutineStarter.Start(FetchNFTImageCoroutine(address, id, OnSuccess, OnFail));
 1135    }
 36
 37    private IEnumerator FetchNFTImageCoroutine(string address, string id, Action<NFTInfo> OnSuccess, Action OnFail)
 38    {
 1139        yield return NFTHelper.FetchNFTInfo(address, id,
 40            (info) =>
 41            {
 042                OnSuccess?.Invoke(info);
 043            },
 44            (error) =>
 45            {
 046                Debug.LogError($"Couldn't fetch NFT: '{address}/{id}' {error}");
 047                OnFail?.Invoke();
 048            });
 049    }
 50}