< 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:26
Uncovered lines:7
Coverable lines:33
Total lines:105
Line coverage:78.7% (26 of 33)
Covered branches:0
Total branches:0

Metrics

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

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        {
 318            INFTMarket selectedMarket = null;
 619            yield return GetMarket(address, (mkt) => selectedMarket = mkt);
 20
 321            if (selectedMarket != null)
 22            {
 323                yield return selectedMarket.FetchNFTsFromOwner(address, onSuccess, onError);
 324            }
 25            else
 26            {
 027                onError?.Invoke($"Market not found for asset {address}");
 28            }
 329        }
 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        {
 542            INFTMarket selectedMarket = null;
 1043            yield return GetMarket(assetContractAddress, tokenId, (mkt) => selectedMarket = mkt);
 44
 345            if (selectedMarket != null)
 46            {
 347                yield return selectedMarket.FetchNFTInfo(assetContractAddress, tokenId, onSuccess, onError);
 348            }
 49            else
 50            {
 051                onError?.Invoke($"Market not found for asset {assetContractAddress}/{tokenId}");
 52            }
 353        }
 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        {
 683            IServiceProviders serviceProviders = Environment.i.platform.serviceProviders;
 684            INFTMarket openSea = null;
 85
 686            if ( serviceProviders != null )
 387                openSea = serviceProviders.openSea;
 88
 689            onSuccess?.Invoke(openSea);
 690            yield break;
 91        }
 92
 93        public static IEnumerator GetMarket(string assetContractAddress, Action<INFTMarket> onSuccess)
 94        {
 395            IServiceProviders serviceProviders = Environment.i.platform.serviceProviders;
 396            INFTMarket openSea = null;
 97
 398            if ( serviceProviders != null )
 399                openSea = serviceProviders.openSea;
 100
 3101            onSuccess?.Invoke(openSea);
 3102            yield break;
 103        }
 104    }
 105}