< Summary

Class:DCL.Helpers.NFT.NFTUtils
Assembly:NFTHelper
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/NFTUtils/NFTUtils.cs
Covered lines:16
Uncovered lines:9
Coverable lines:25
Total lines:93
Line coverage:64% (16 of 25)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FetchNFTsFromOwner()0%8.836057.14%
FetchNFTInfo()0%6.116085.71%
FetchNFTInfoSingleAsset()0%19.126028.57%
GetMarket()0%330100%
GetMarket()0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/NFTUtils/NFTUtils.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using DCL.Helpers.NFT.Markets;
 4
 5namespace DCL.Helpers.NFT
 6{
 7    public static class NFTUtils
 8    {
 9        /// <summary>
 10        /// Fetch NFT from owner
 11        /// </summary>
 12        /// <param name="address">owner address</param>
 13        /// <param name="onSuccess">success callback</param>
 14        /// <param name="onError">error callback</param>
 15        /// <returns>IEnumerator</returns>
 16        public static IEnumerator FetchNFTsFromOwner(string address, Action<NFTOwner> onSuccess, Action<string> onError)
 17        {
 5318            INFTMarket selectedMarket = null;
 10619            yield return GetMarket(address, (mkt) => selectedMarket = mkt);
 20
 421            if (selectedMarket != null)
 22            {
 423                yield return selectedMarket.FetchNFTsFromOwner(address, onSuccess, onError);
 024            }
 25            else
 26            {
 027                onError?.Invoke($"Market not found for asset {address}");
 28            }
 029        }
 30
 31        /// <summary>
 32        /// Fetch NFT. Request is added to a batch of requests to reduce the amount of request to the api.
 33        /// NOTE: for ERC1155 result does not contain the array of owners and sell price for this asset
 34        /// </summary>
 35        /// <param name="assetContractAddress">asset contract address</param>
 36        /// <param name="tokenId">asset token id</param>
 37        /// <param name="onSuccess">success callback</param>
 38        /// <param name="onError">error callback</param>
 39        /// <returns>IEnumerator</returns>
 40        public static IEnumerator FetchNFTInfo(string assetContractAddress, string tokenId, Action<NFTInfo> onSuccess, A
 41        {
 1242            INFTMarket selectedMarket = null;
 2443            yield return GetMarket(assetContractAddress, tokenId, (mkt) => selectedMarket = mkt);
 44
 945            if (selectedMarket != null)
 46            {
 947                yield return selectedMarket.FetchNFTInfo(assetContractAddress, tokenId, onSuccess, onError);
 748            }
 49            else
 50            {
 051                onError?.Invoke($"Market not found for asset {assetContractAddress}/{tokenId}");
 52            }
 753        }
 54
 55        /// <summary>
 56        /// Fetch NFT. Request is fetch directly to the api instead of batched with other requests in a single query.
 57        /// Please try to use `FetchNFTInfo` if ownership info is not relevant for your use case.
 58        /// NOTE: result it does contain the array of owners for ERC1155 NFTs
 59        /// </summary>
 60        /// <param name="assetContractAddress">asset contract address</param>
 61        /// <param name="tokenId">asset token id</param>
 62        /// <param name="onSuccess">success callback</param>
 63        /// <param name="onError">error callback</param>
 64        /// <returns>IEnumerator</returns>
 65        public static IEnumerator FetchNFTInfoSingleAsset(string assetContractAddress, string tokenId, Action<NFTInfoSin
 66        {
 167            INFTMarket selectedMarket = null;
 268            yield return GetMarket(assetContractAddress, tokenId, (mkt) => selectedMarket = mkt);
 69
 070            if (selectedMarket != null)
 71            {
 072                yield return selectedMarket.FetchNFTInfoSingleAsset(assetContractAddress, tokenId, onSuccess, onError);
 073            }
 74            else
 75            {
 076                onError?.Invoke($"Market not found for asset {assetContractAddress}/{tokenId}");
 77            }
 078        }
 79
 80        // NOTE: this method doesn't make sense now, but it will when support for other market is added
 81        public static IEnumerator GetMarket(string assetContractAddress, string tokenId, Action<INFTMarket> onSuccess)
 82        {
 1383            onSuccess?.Invoke(DCL.Environment.i.platform.serviceProviders.openSea);
 1384            yield break;
 85        }
 86
 87        public static IEnumerator GetMarket(string assetContractAddress, Action<INFTMarket> onSuccess)
 88        {
 5389            onSuccess?.Invoke(DCL.Environment.i.platform.serviceProviders.openSea);
 5390            yield break;
 91        }
 92    }
 93}