Skip to content

Commit

Permalink
modify: swap elephant image.
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-zhaolei committed Dec 20, 2024
1 parent 3567e3b commit 26daf0d
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/CAServer.Application/Tokens/TokenNftAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TokenDisplayAppService> logger, IUserAssetsProvider userAssetsProvider,
Expand All @@ -74,7 +75,8 @@ public TokenNftAppService(
ISearchAppService searchAppService, IOptionsSnapshot<IpfsOptions> ipfsOption,
IOptionsSnapshot<TokenListOptions> tokenListOptions, IOptionsSnapshot<NftToFtOptions> nftToFtOptions,
IZeroHoldingsConfigAppService zeroHoldingsConfigAppService, IHttpClientService httpClientService,
IOptionsSnapshot<HostInfoOptions> hostInfoOptions, IOptionsSnapshot<AwakenOptions> awakenOptions)
IOptionsSnapshot<HostInfoOptions> hostInfoOptions, IOptionsSnapshot<AwakenOptions> awakenOptions,
IOptionsSnapshot<TokenInfoOptions> tokenInfoOptions)
{
_logger = logger;
_userAssetsProvider = userAssetsProvider;
Expand All @@ -97,6 +99,7 @@ public TokenNftAppService(
_httpClientService = httpClientService;
_hostInfoOptions = hostInfoOptions.Value;
_awakenOptions = awakenOptions.Value;
_tokenInfoOptions = tokenInfoOptions.Value;
}

public async Task<GetTokenDto> GetTokenAsync(GetTokenRequestDto requestDto)
Expand Down Expand Up @@ -225,7 +228,7 @@ private async Task<GetTokenDto> DoGetTokenDtos(GetTokenRequestDto requestDto)
});

// await filterZeroByConfig(dto);

return dto;
}
catch (Exception e)
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -1003,7 +1007,8 @@ private List<Token> SortTokens(List<Token> 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;
}
}
Expand Down Expand Up @@ -1061,16 +1066,19 @@ private List<GetTokenListDto> GetTokenInfoList(List<UserTokenIndex> userTokenInf

return result;
}

public async Task<AwakenSupportedTokenResponse> ListAwakenSupportedTokensAsync(int skipCount, int maxResultCount, int page, string chainId, string caAddress)

public async Task<AwakenSupportedTokenResponse> ListAwakenSupportedTokensAsync(int skipCount, int maxResultCount,
int page, string chainId, string caAddress)
{
if (chainId.IsNullOrEmpty())
{
chainId = _hostInfoOptions.Environment == Options.Environment.Development
? 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<CommonResponseDto<TradePairsDto>>(awakenUrl);
if (!response.Success || response.Data == null || response.Data.Items.IsNullOrEmpty())
{
Expand All @@ -1087,13 +1095,16 @@ public async Task<AwakenSupportedTokenResponse> ListAwakenSupportedTokensAsync(i
var tokens = tokens0.Distinct(new TokenComparer()).ToList();
var result = ObjectMapper.Map<List<TradePairsItemToken>, List<CAServer.UserAssets.Dtos.Token>>(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);
if (!symbolToToken.TryGetValue(token.Symbol, out var userToken))
{
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;
}

Expand All @@ -1106,6 +1117,7 @@ public async Task<AwakenSupportedTokenResponse> ListAwakenSupportedTokensAsync(i
token.Price = userToken.Price;
token.Label = userToken.Label;
}

result = SortTokens(result);
result = result.Skip(skipCount).Take(maxResultCount).ToList();
return new AwakenSupportedTokenResponse()
Expand All @@ -1114,8 +1126,9 @@ public async Task<AwakenSupportedTokenResponse> ListAwakenSupportedTokensAsync(i
Data = result
};
}

private async Task<Dictionary<string, Token>> ListSideChainUserTokens(string chainId, string caAddress, List<TradePairsItemToken> tokens)

private async Task<Dictionary<string, Token>> ListSideChainUserTokens(string chainId, string caAddress,
List<TradePairsItemToken> tokens)
{
var userTokens = await DoGetTokenDtos(new GetTokenRequestDto()
{
Expand All @@ -1131,7 +1144,8 @@ private async Task<Dictionary<string, Token>> 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);
Expand Down

0 comments on commit 26daf0d

Please sign in to comment.