| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.IO; |
| | 5 | | using DCL; |
| | 6 | | using DCL.Helpers.NFT; |
| | 7 | | using Newtonsoft.Json; |
| | 8 | | using NFTShape_Internal; |
| | 9 | | using UnityEngine; |
| | 10 | |
|
| | 11 | | public interface INFTInfoLoadHelper : IDisposable |
| | 12 | | { |
| | 13 | | void FetchNFTInfo(string address, string id, Action<NFTInfo> OnSuccess, Action OnFail); |
| | 14 | | } |
| | 15 | |
|
| | 16 | | public class NFTInfoLoadHelper : INFTInfoLoadHelper |
| | 17 | | { |
| | 18 | | internal Coroutine fetchCoroutine; |
| | 19 | |
|
| | 20 | | public void Dispose() |
| | 21 | | { |
| 3 | 22 | | if (fetchCoroutine != null) |
| 2 | 23 | | CoroutineStarter.Stop(fetchCoroutine); |
| | 24 | |
|
| 3 | 25 | | fetchCoroutine = null; |
| 3 | 26 | | } |
| | 27 | |
|
| | 28 | | public void FetchNFTInfo(string address, string id, Action<NFTInfo> OnSuccess, Action OnFail) |
| | 29 | | { |
| 5 | 30 | | if (fetchCoroutine != null) |
| 0 | 31 | | CoroutineStarter.Stop(fetchCoroutine); |
| | 32 | |
|
| 5 | 33 | | fetchCoroutine = CoroutineStarter.Start(FetchNFTInfoCoroutine(address, id, OnSuccess, OnFail)); |
| 5 | 34 | | } |
| | 35 | |
|
| | 36 | | private IEnumerator FetchNFTInfoCoroutine(string address, string id, Action<NFTInfo> OnSuccess, Action OnFail) |
| | 37 | | { |
| 5 | 38 | | yield return NFTUtils.FetchNFTInfo(address, id, |
| 0 | 39 | | (info) => { OnSuccess?.Invoke(info); }, |
| | 40 | | (error) => |
| | 41 | | { |
| 0 | 42 | | Debug.LogError($"Couldn't fetch NFT: '{address}/{id}' {error}"); |
| 0 | 43 | | OnFail?.Invoke(); |
| 0 | 44 | | }); |
| 3 | 45 | | } |
| | 46 | | } |