fix(activity)_: report other token types than ERC20

This fixes incremental updates for tokens and proper report of
token type for mobile (in desktop we didn't use it)

Closes: #15233
This commit is contained in:
Emil Sawicki 2024-07-04 13:51:43 +02:00 committed by Stefan Dunca
parent 7e4322b45a
commit 89f1feade0
3 changed files with 62 additions and 15 deletions

View File

@ -587,11 +587,15 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
inAmount, outAmount := getTrInAndOutAmounts(activityType, dbTrAmount, dbPTrAmount)
// Extract tokens and chains
var involvedToken *Token
var tokenContractAddress eth.Address
if tokenAddress != nil && *tokenAddress != ZeroAddress {
involvedToken = &Token{TokenType: Erc20, ChainID: common.ChainID(chainID.Int64), TokenID: tokenID, Address: *tokenAddress}
} else {
involvedToken = &Token{TokenType: Native, ChainID: common.ChainID(chainID.Int64), TokenID: tokenID}
tokenContractAddress = *tokenAddress
}
involvedToken := &Token{
TokenType: transferTypeToTokenType(transferType),
ChainID: common.ChainID(chainID.Int64),
Address: tokenContractAddress,
TokenID: tokenID,
}
entry = newActivityEntryWithSimpleTransaction(
@ -784,6 +788,25 @@ func contractTypeFromDBType(dbType string) (transferType *TransferType) {
return transferType
}
func transferTypeToTokenType(transferType *TransferType) TokenType {
if transferType == nil {
return Native
}
switch *transferType {
case TransferTypeEth:
return Native
case TransferTypeErc20:
return Erc20
case TransferTypeErc721:
return Erc721
case TransferTypeErc1155:
return Erc1155
default:
log.Error(fmt.Sprintf("unexpected transfer type %d", transferType))
}
return Native
}
// lookupAndFillInTokens ignores NFTs
func lookupAndFillInTokens(deps FilterDependencies, tokenOut *Token, tokenIn *Token) (symbolOut *string, symbolIn *string) {
if tokenOut != nil && tokenOut.TokenID == nil {

View File

@ -218,13 +218,23 @@ func (s *Service) getActivityDetails(ctx context.Context, entries []Entry) ([]*E
var err error
ids := make([]thirdparty.CollectibleUniqueID, 0)
entriesForIds := make([]*Entry, 0)
idExists := func(ids []thirdparty.CollectibleUniqueID, id *thirdparty.CollectibleUniqueID) bool {
for _, existingID := range ids {
if existingID.Same(id) {
return true
}
}
return false
}
for i := range entries {
if !entries[i].isNFT() {
continue
}
id := entries[i].anyIdentity()
if id == nil {
if id == nil || idExists(ids, id) {
continue
}

View File

@ -138,6 +138,7 @@ func TestService_UpdateCollectibleInfo(t *testing.T) {
args := []arg{
{5, "0xA2838FDA19EB6EED3F8B9EFF411D4CD7D2DE0313", "0x0D", nil, nil},
{5, "0xA2838FDA19EB6EED3F8B9EFF411D4CD7D2DE0313", "0x762AD3E4934E687F8701F24C7274E5209213FD6208FF952ACEB325D028866949", nil, nil},
{5, "0xA2838FDA19EB6EED3F8B9EFF411D4CD7D2DE0313", "0x762AD3E4934E687F8701F24C7274E5209213FD6208FF952ACEB325D028866949", nil, nil},
{5, "0x3d6afaa395c31fcd391fe3d562e75fe9e8ec7e6a", "", nil, nil},
{5, "0xA2838FDA19EB6EED3F8B9EFF411D4CD7D2DE0313", "0x0F", nil, nil},
}
@ -157,20 +158,25 @@ func TestService_UpdateCollectibleInfo(t *testing.T) {
state.collectiblesMock.On("FetchAssetsByCollectibleUniqueID", []thirdparty.CollectibleUniqueID{
{
ContractID: thirdparty.ContractID{
ChainID: args[3].chainID,
Address: *args[3].tokenAddress},
TokenID: &bigint.BigInt{Int: args[3].tokenID},
ChainID: args[4].chainID,
Address: *args[4].tokenAddress},
TokenID: &bigint.BigInt{Int: args[4].tokenID},
}, {
ContractID: thirdparty.ContractID{
ChainID: args[1].chainID,
Address: *args[1].tokenAddress},
TokenID: &bigint.BigInt{Int: args[1].tokenID},
}, {
ContractID: thirdparty.ContractID{
ChainID: args[0].chainID,
Address: *args[0].tokenAddress},
TokenID: &bigint.BigInt{Int: args[0].tokenID},
},
}).Return([]thirdparty.FullCollectibleData{
{
CollectibleData: thirdparty.CollectibleData{
Name: "Test 2",
ImageURL: "test://url/2"},
Name: "Test 4",
ImageURL: "test://url/4"},
CollectionData: nil,
}, {
CollectibleData: thirdparty.CollectibleData{
@ -178,9 +184,15 @@ func TestService_UpdateCollectibleInfo(t *testing.T) {
ImageURL: "test://url/1"},
CollectionData: nil,
},
{
CollectibleData: thirdparty.CollectibleData{
Name: "Test 0",
ImageURL: "test://url/0"},
CollectionData: nil,
},
}, nil).Once()
state.service.FilterActivityAsync(0, append(fromAddresses, toAddresses...), allNetworksFilter(), Filter{}, 0, 3)
state.service.FilterActivityAsync(0, append(fromAddresses, toAddresses...), allNetworksFilter(), Filter{}, 0, 10)
filterResponseCount := 0
var updates []EntryData
@ -193,7 +205,7 @@ func TestService_UpdateCollectibleInfo(t *testing.T) {
payload, err := walletevent.GetPayload[FilterResponse](res)
require.NoError(t, err)
require.Equal(t, ErrorCodeSuccess, payload.ErrorCode)
require.Equal(t, 3, len(payload.Activities))
require.Equal(t, 5, len(payload.Activities))
filterResponseCount++
case EventActivityFilteringUpdate:
err := walletevent.ExtractPayload(res, &updates)
@ -205,11 +217,13 @@ func TestService_UpdateCollectibleInfo(t *testing.T) {
}
require.Equal(t, 1, filterResponseCount)
require.Equal(t, 2, len(updates))
require.Equal(t, "Test 2", *updates[0].NftName)
require.Equal(t, "test://url/2", *updates[0].NftURL)
require.Equal(t, 3, len(updates))
require.Equal(t, "Test 4", *updates[0].NftName)
require.Equal(t, "test://url/4", *updates[0].NftURL)
require.Equal(t, "Test 1", *updates[1].NftName)
require.Equal(t, "test://url/1", *updates[1].NftURL)
require.Equal(t, "Test 0", *updates[2].NftName)
require.Equal(t, "test://url/0", *updates[2].NftURL)
sub.Unsubscribe()
}