diff --git a/src/CAServer.Application/Tokens/TokenNftAppService.cs b/src/CAServer.Application/Tokens/TokenNftAppService.cs index 4c4e50544..964b3ae7c 100644 --- a/src/CAServer.Application/Tokens/TokenNftAppService.cs +++ b/src/CAServer.Application/Tokens/TokenNftAppService.cs @@ -61,6 +61,7 @@ public class TokenNftAppService : CAServerAppService, ITokenNftAppService private readonly IHttpClientService _httpClientService; private readonly HostInfoOptions _hostInfoOptions; private readonly AwakenOptions _awakenOptions; + private readonly TokenInfoOptions _tokenInfoOptions; public TokenNftAppService( ILogger logger, IUserAssetsProvider userAssetsProvider, @@ -74,7 +75,8 @@ public TokenNftAppService( ISearchAppService searchAppService, IOptionsSnapshot ipfsOption, IOptionsSnapshot tokenListOptions, IOptionsSnapshot nftToFtOptions, IZeroHoldingsConfigAppService zeroHoldingsConfigAppService, IHttpClientService httpClientService, - IOptionsSnapshot hostInfoOptions, IOptionsSnapshot awakenOptions) + IOptionsSnapshot hostInfoOptions, IOptionsSnapshot awakenOptions, + IOptionsSnapshot tokenInfoOptions) { _logger = logger; _userAssetsProvider = userAssetsProvider; @@ -97,6 +99,7 @@ public TokenNftAppService( _httpClientService = httpClientService; _hostInfoOptions = hostInfoOptions.Value; _awakenOptions = awakenOptions.Value; + _tokenInfoOptions = tokenInfoOptions.Value; } public async Task GetTokenAsync(GetTokenRequestDto requestDto) @@ -225,7 +228,7 @@ private async Task DoGetTokenDtos(GetTokenRequestDto requestDto) }); // await filterZeroByConfig(dto); - + return dto; } catch (Exception e) @@ -779,8 +782,9 @@ await _imageProcessProvider.GetResizeImageAsync(searchItem.NftInfo.ImageUrl, req .ThenBy(t => !defaultSymbols.Contains(t.Symbol)) .ThenBy(t => Array.IndexOf(defaultSymbols.ToArray(), t.Symbol)) .ThenBy(t => t.Symbol).ThenByDescending(t => t.ChainId) - .Union(dto.Data.Where(f => f.NftInfo != null).OrderBy(e => e.Symbol).ThenByDescending(t => t.ChainId)).ToList(); - + .Union(dto.Data.Where(f => f.NftInfo != null).OrderBy(e => e.Symbol).ThenByDescending(t => t.ChainId)) + .ToList(); + dto.Data = dto.Data.Skip(requestDto.SkipCount).Take(requestDto.MaxResultCount).ToList(); SetSeedStatusAndTypeForUserAssets(dto.Data); @@ -1003,7 +1007,8 @@ private List SortTokens(List tokens) } catch (Exception e) { - _logger.LogError(e, "illegal tokens:{0}", JsonConvert.SerializeObject(tokens.Where(t => t.Balance.IsNullOrEmpty()).ToList())); + _logger.LogError(e, "illegal tokens:{0}", + JsonConvert.SerializeObject(tokens.Where(t => t.Balance.IsNullOrEmpty()).ToList())); return tokens; } } @@ -1061,8 +1066,9 @@ private List GetTokenInfoList(List userTokenInf return result; } - - public async Task ListAwakenSupportedTokensAsync(int skipCount, int maxResultCount, int page, string chainId, string caAddress) + + public async Task ListAwakenSupportedTokensAsync(int skipCount, int maxResultCount, + int page, string chainId, string caAddress) { if (chainId.IsNullOrEmpty()) { @@ -1070,7 +1076,9 @@ public async Task ListAwakenSupportedTokensAsync(i ? CommonConstant.TDVWChainId : CommonConstant.TDVVChainId; } - var awakenUrl = _awakenOptions.Domain + $"/api/app/trade-pairs?skipCount={skipCount}&maxResultCount={maxResultCount}&page={page}&chainId={chainId}"; + + var awakenUrl = _awakenOptions.Domain + + $"/api/app/trade-pairs?skipCount={skipCount}&maxResultCount={maxResultCount}&page={page}&chainId={chainId}"; var response = await _httpClientService.GetAsync>(awakenUrl); if (!response.Success || response.Data == null || response.Data.Items.IsNullOrEmpty()) { @@ -1087,6 +1095,7 @@ public async Task ListAwakenSupportedTokensAsync(i var tokens = tokens0.Distinct(new TokenComparer()).ToList(); var result = ObjectMapper.Map, List>(tokens); var symbolToToken = await ListSideChainUserTokens(chainId, caAddress, tokens); + var tokenImageDic = _tokenInfoOptions.TokenInfos.ToDictionary(k => k.Key, v => v.Value.ImageUrl); foreach (var token in result) { ChainDisplayNameHelper.SetDisplayName(token); @@ -1094,6 +1103,8 @@ public async Task ListAwakenSupportedTokensAsync(i { token.Balance = token.Balance.IsNullOrEmpty() ? "0" : token.Balance; token.BalanceInUsd = token.BalanceInUsd.IsNullOrEmpty() ? "0" : token.BalanceInUsd; + token.ImageUrl = !token.ImageUrl.IsNullOrEmpty() ? token.ImageUrl : + tokenImageDic.TryGetValue(token.Symbol, out var imageUrl) ? imageUrl : ""; continue; } @@ -1106,6 +1117,7 @@ public async Task ListAwakenSupportedTokensAsync(i token.Price = userToken.Price; token.Label = userToken.Label; } + result = SortTokens(result); result = result.Skip(skipCount).Take(maxResultCount).ToList(); return new AwakenSupportedTokenResponse() @@ -1114,8 +1126,9 @@ public async Task ListAwakenSupportedTokensAsync(i Data = result }; } - - private async Task> ListSideChainUserTokens(string chainId, string caAddress, List tokens) + + private async Task> ListSideChainUserTokens(string chainId, string caAddress, + List tokens) { var userTokens = await DoGetTokenDtos(new GetTokenRequestDto() { @@ -1131,7 +1144,8 @@ private async Task> ListSideChainUserTokens(string cha MaxResultCount = 200 }); var symbols = tokens.Select(t => t.Symbol).Distinct().ToList(); - var sideChainUserTokens = userTokens.Data.Where(t => chainId.Equals(t.ChainId) && symbols.Contains(t.Symbol)).ToList(); + var sideChainUserTokens = + userTokens.Data.Where(t => chainId.Equals(t.ChainId) && symbols.Contains(t.Symbol)).ToList(); try { return sideChainUserTokens.ToDictionary(token => token.Symbol, token => token);