Skip to content

Commit

Permalink
feat: add searchUserAssets & search activity by tokenName
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoxkang committed Feb 20, 2025
1 parent a57acdb commit 3ea1d5e
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/mainnet-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
servicename:
[EoaServer.Silo,EoaServer.HttpApi.Host,EoaServer.EntityEventHandler,EoaServer.AuthServer,EoaServer.DbMigrator]
[EoaServer.HttpApi.Host,EoaServer.DbMigrator]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
Expand All @@ -30,7 +30,7 @@ jobs:
strategy:
matrix:
servicename:
[EoaServer.Silo,EoaServer.HttpApi.Host,EoaServer.EntityEventHandler,EoaServer.AuthServer,EoaServer.DbMigrator]
[EoaServer.HttpApi.Host,EoaServer.DbMigrator]
permissions:
contents: read
steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Collections.Generic;
using EoaServer.Commons;

namespace EoaServer.UserAssets.Dto;

public class SearchUserAssetsV2Dto
{
public List<TokenInfoV2Dto> TokenInfos { get; set; } = new();
public List<NftCollectionDto> NftInfos { get; set; } = new();
public long TotalRecordCount { get; set; }
}

public class NftInfoDto : ChainDisplayNameDto
{
public string ImageUrl { get; set; }
public string Alias { get; set; }
public string TokenId { get; set; }
public string CollectionName { get; set; } // nftItem collectionSymbol
public string Balance { get; set; }
public string TokenContractAddress { get; set; }
public string Decimals { get; set; }
public string TokenName { get; set; }
public bool IsSeed { get; set; }
public int SeedType { get; set; }
public string Label { get; set; } // new nftItem
public string Symbol { get; set; }
}

public class TokenInfoV2Dto : ChainDisplayNameDto
{
public string Symbol { get; set; }
public string Address { get; set; } // user address
public string Label { get; set; }

public string Balance { get; set; }
public string Decimals { get; set; }
public string BalanceInUsd { get; set; }
public string TokenContractAddress { get; set; }
public string ImageUrl { get; set; }
}

public class NftCollectionDto
{
public string CollectionName { get; set; }
public string ImageUrl { get; set; }
public List<NftInfoDto> Items { get; set; } = new();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using EoaServer.Awaken;
using EoaServer.UserAssets;
using EoaServer.UserAssets.Dto;
using EoaServer.UserAssets.Dtos;

namespace EoaServer.UserAssets;
Expand All @@ -12,4 +13,5 @@ public interface IUserAssetsAppService
Task<GetNftItemsDto> GetNFTItemsAsync(GetNftItemsRequestDto requestDto);
Task<AwakenSupportedTokenResponse> ListAwakenSupportedTokensAsync(int skipCount, int maxResultCount,
int page, string chainId, string caAddress);
Task<SearchUserAssetsV2Dto> SearchUserAssetsAsync(SearchUserAssetsRequestDto requestDto);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using EoaServer.UserAssets;

namespace EoaServer.UserAssets;

public class GetTokenRequestDto : GetAssetsBase
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations;

namespace EoaServer.UserAssets;

public class SearchUserAssetsRequestDto : GetAssetsBase
{
[MaxLength(100)] public string Keyword { get; set; }

public int Width { get; set; }

public int Height { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using EoaServer.Search.Dto;
using EoaServer.Token.Eto;
using EoaServer.Transfer.Dtos;
using EoaServer.UserAssets.Dto;
using EoaServer.UserAssets.Dtos;

namespace EoaServer;

Expand All @@ -21,6 +23,8 @@ public EoaServerApplicationAutoMapperProfile()
CreateMap<ChainsInfoIndex, ChainsInfoDto>();
CreateMap<DefaultTokenInfo, DefaultTokenInfoDto>();
CreateMap<TradePairsItemToken, UserAssets.Dtos.Token>();
CreateMap<UserAssets.Dtos.Token, TokenInfoV2Dto>();
CreateMap<NftItem, NftInfoDto>();
CreateMap<AuthTokenRequestDto, ETransferAuthTokenRequestDto>().ForMember(des => des.ClientId,
opt => opt.MapFrom(f => ETransferConstant.ClientId))
.ForMember(des => des.GrantType,
Expand Down
28 changes: 18 additions & 10 deletions src/EoaServer.Application/UserActivity/UserActivityAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,6 @@ public async Task<GetActivitiesDto> GetActivitiesAsync(GetActivitiesRequestDto r
var txns = new IndexerTransactionListResultDto();
var tokenTransfers = new IndexerTokenTransferListDto();

var txnsTask = _graphqlProvider.GetTransactionsAsync(new TransactionsRequestDto()
{
ChainId = chainId,
Address = address,
SkipCount = 0,
MaxResultCount = request.SkipCount + request.MaxResultCount
});
var tokenTransfersTask = _graphqlProvider.GetTokenTransferInfoAsync(new GetTokenTransferRequestDto()
{
Address = address,
Expand All @@ -135,10 +128,25 @@ public async Task<GetActivitiesDto> GetActivitiesAsync(GetActivitiesRequestDto r
Symbol = request.Symbol
});

await Task.WhenAll(txnsTask, tokenTransfersTask);
if (!request.Symbol.IsNullOrWhiteSpace())
{
tokenTransfers = await tokenTransfersTask;
}
else
{
var txnsTask = _graphqlProvider.GetTransactionsAsync(new TransactionsRequestDto()
{
ChainId = chainId,
Address = address,
SkipCount = 0,
MaxResultCount = request.SkipCount + request.MaxResultCount
});
await Task.WhenAll(txnsTask, tokenTransfersTask);

txns = await txnsTask;
tokenTransfers = await tokenTransfersTask;
}

txns = await txnsTask;
tokenTransfers = await tokenTransfersTask;
var transactions = MergeTxns(txns, tokenTransfers);

transactions = transactions.OrderByDescending(item => item.Timestamp)
Expand Down
86 changes: 83 additions & 3 deletions src/EoaServer.Application/UserAssets/UserAssetsAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using EoaServer.Token;
using EoaServer.Token.Dto;
using EoaServer.UserAssets;
using EoaServer.UserAssets.Dto;
using EoaServer.UserAssets.Dtos;
using EoaServer.UserAssets.Provider;
using EoaServer.UserToken;
Expand Down Expand Up @@ -75,8 +76,13 @@ public UserAssetsAppService(
_tokenInfoOptions = tokenInfoOptions.Value;
_nftToFtOptions = nftToFtOptions.Value;
}

public async Task<GetTokenDto> GetTokenAsync(GetTokenRequestDto requestDto)
{
return await GetTokenAsync(requestDto, true);
}

public async Task<GetTokenDto> GetTokenAsync(GetAssetsBase requestDto, bool addDefaultToken)
{
var tokenList = new GetAddressTokenListResultDto();
foreach (var addressInfo in requestDto.AddressInfos)
Expand All @@ -101,7 +107,10 @@ public async Task<GetTokenDto> GetTokenAsync(GetTokenRequestDto requestDto)
chainToken.Quantity = (long) ((double) chainToken.Quantity * Math.Pow(10, tokenInfoDto.Decimals));
}

AddDefaultTokens(tokenList);
if (addDefaultToken)
{
AddDefaultTokens(tokenList);
}
var result = await ConvertDtoAsync(tokenList, requestDto);

result.Data = SortTokens(result.Data);
Expand Down Expand Up @@ -475,7 +484,7 @@ private static void DealWithDisplayChainImage(GetNftCollectionsDto dto)
}
}

private async Task<GetTokenDto> ConvertDtoAsync(GetAddressTokenListResultDto fromDto, GetTokenRequestDto requestDto)
private async Task<GetTokenDto> ConvertDtoAsync(GetAddressTokenListResultDto fromDto, GetAssetsBase requestDto)
{
var result = new GetTokenDto()
{
Expand Down Expand Up @@ -742,4 +751,75 @@ public async Task<AwakenSupportedTokenResponse> ListAwakenSupportedTokensAsync(i
return tokens;
}
}

public async Task<SearchUserAssetsV2Dto> SearchUserAssetsAsync(SearchUserAssetsRequestDto requestDto)
{
var result = new SearchUserAssetsV2Dto();
var getTokenDto = await GetTokenAsync(requestDto, false);
foreach (var tokenInfo in getTokenDto.Data)
{
if (!requestDto.Keyword.IsNullOrWhiteSpace() && !tokenInfo.Symbol.Contains(requestDto.Keyword))
{
continue;
}
var tokenInfoDtoList = ObjectMapper.Map<List<Dtos.Token>, List<TokenInfoV2Dto>>(tokenInfo.Tokens);
result.TokenInfos.AddRange(tokenInfoDtoList);
}
result.TokenInfos.ForEach(t => t.Address = requestDto.AddressInfos[0].Address);


var collectionDto = await GetNFTCollectionsAsync(new GetNftCollectionsRequestDto()
{
SkipCount = requestDto.SkipCount,
MaxResultCount = requestDto.MaxResultCount,
AddressInfos = requestDto.AddressInfos,
Height = requestDto.Height,
Width = requestDto.Width
});
var nftItemsTask = collectionDto.Data.Select(t => GetNFTItemsAsync(new GetNftItemsRequestDto()
{
SkipCount = requestDto.SkipCount,
MaxResultCount = requestDto.MaxResultCount,
AddressInfos = requestDto.AddressInfos,
Height = requestDto.Height,
Width = requestDto.Width,
Symbol = t.Symbol
}));
var nftItemsDtoList = await Task.WhenAll(nftItemsTask);
var nftItemsMap = nftItemsDtoList.ToDictionary(t => t.Data[0].CollectionSymbol, t => t);
foreach (var collection in collectionDto.Data)
{
var collectionInfo = new NftCollectionDto();
collectionInfo.CollectionName = collection.CollectionName;
collectionInfo.ImageUrl = collection.ImageUrl;
if (!nftItemsMap.TryGetValue(collection.Symbol, out var nftItems) || nftItems.Data.IsNullOrEmpty())
{
continue;
}
foreach (var nftItem in nftItems.Data)
{
if (!requestDto.Keyword.IsNullOrWhiteSpace() && !nftItem.Symbol.Contains(requestDto.Keyword))
{
continue;
}
var nftItemInfo = ObjectMapper.Map<NftItem, NftInfoDto>(nftItem);
nftItemInfo.CollectionName = collection.CollectionName;
var nftToFtInfo = _nftToFtOptions.NftToFtInfos.GetOrDefault(nftItem.Symbol);
if (nftToFtInfo != null)
{
nftItemInfo.Label = nftToFtInfo.Label;
nftItemInfo.ImageUrl = nftToFtInfo.ImageUrl;
}
collectionInfo.Items.Add(nftItemInfo);
}

if (collectionInfo.Items.Count > 0)
{
result.NftInfos.Add(collectionInfo);
}
}

result.TotalRecordCount = result.TokenInfos.Count + result.NftInfos.Sum(t => t.Items.Count);
return result;
}
}
9 changes: 8 additions & 1 deletion src/EoaServer.HttpApi/Controllers/UserAssetsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
using System.Threading.Tasks;
using Asp.Versioning;
using EoaServer.Awaken;
using EoaServer.Commons;
using EoaServer.UserAssets;
using EoaServer.UserAssets.Dto;
using EoaServer.UserAssets.Dtos;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
Expand Down Expand Up @@ -54,4 +55,10 @@ public async Task<AwakenSupportedTokenResponse> ListAwakenSupportedTokensAsync(i
page = page <= 1 ? 1 : page;
return await _userAssetsAppService.ListAwakenSupportedTokensAsync(skipCount, maxResultCount, page, chainId, address);
}

[HttpPost("searchUserAssets")]
public async Task<SearchUserAssetsV2Dto> SearchUserAssetsAsync(SearchUserAssetsRequestDto requestDto)
{
return await _userAssetsAppService.SearchUserAssetsAsync(requestDto);
}
}

0 comments on commit 3ea1d5e

Please sign in to comment.