mirror of
https://github.com/status-im/status-go.git
synced 2025-01-18 10:42:07 +00:00
fix(activity)_: Remove duplicated ids for nft fetching
This commit is contained in:
parent
89f1feade0
commit
eac07af5d7
@ -217,7 +217,7 @@ func (s *Service) getActivityDetails(ctx context.Context, entries []Entry) ([]*E
|
|||||||
res := make([]*EntryData, 0)
|
res := make([]*EntryData, 0)
|
||||||
var err error
|
var err error
|
||||||
ids := make([]thirdparty.CollectibleUniqueID, 0)
|
ids := make([]thirdparty.CollectibleUniqueID, 0)
|
||||||
entriesForIds := make([]*Entry, 0)
|
entriesForIds := make(map[string][]*Entry)
|
||||||
|
|
||||||
idExists := func(ids []thirdparty.CollectibleUniqueID, id *thirdparty.CollectibleUniqueID) bool {
|
idExists := func(ids []thirdparty.CollectibleUniqueID, id *thirdparty.CollectibleUniqueID) bool {
|
||||||
for _, existingID := range ids {
|
for _, existingID := range ids {
|
||||||
@ -234,12 +234,14 @@ func (s *Service) getActivityDetails(ctx context.Context, entries []Entry) ([]*E
|
|||||||
}
|
}
|
||||||
|
|
||||||
id := entries[i].anyIdentity()
|
id := entries[i].anyIdentity()
|
||||||
if id == nil || idExists(ids, id) {
|
if id == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ids = append(ids, *id)
|
entriesForIds[id.HashKey()] = append(entriesForIds[id.HashKey()], &entries[i])
|
||||||
entriesForIds = append(entriesForIds, &entries[i])
|
if !idExists(ids, id) {
|
||||||
|
ids = append(ids, *id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ids) == 0 {
|
if len(ids) == 0 {
|
||||||
@ -255,25 +257,33 @@ func (s *Service) getActivityDetails(ctx context.Context, entries []Entry) ([]*E
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, col := range colData {
|
for _, col := range colData {
|
||||||
data := &EntryData{
|
nftName := w_common.NewAndSet(col.CollectibleData.Name)
|
||||||
NftName: w_common.NewAndSet(col.CollectibleData.Name),
|
nftURL := w_common.NewAndSet(col.CollectibleData.ImageURL)
|
||||||
NftURL: w_common.NewAndSet(col.CollectibleData.ImageURL),
|
|
||||||
}
|
|
||||||
for i := range ids {
|
for i := range ids {
|
||||||
if col.CollectibleData.ID.Same(&ids[i]) {
|
if !col.CollectibleData.ID.Same(&ids[i]) {
|
||||||
if entriesForIds[i].payloadType == MultiTransactionPT {
|
continue
|
||||||
data.ID = w_common.NewAndSet(entriesForIds[i].id)
|
}
|
||||||
|
|
||||||
|
entryList, ok := entriesForIds[ids[i].HashKey()]
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, e := range entryList {
|
||||||
|
data := &EntryData{
|
||||||
|
NftName: nftName,
|
||||||
|
NftURL: nftURL,
|
||||||
|
}
|
||||||
|
if e.payloadType == MultiTransactionPT {
|
||||||
|
data.ID = w_common.NewAndSet(e.id)
|
||||||
} else {
|
} else {
|
||||||
data.Transaction = entriesForIds[i].transaction
|
data.Transaction = e.transaction
|
||||||
}
|
}
|
||||||
|
|
||||||
data.PayloadType = entriesForIds[i].payloadType
|
data.PayloadType = e.payloadType
|
||||||
|
res = append(res, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res = append(res, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,17 +175,35 @@ func TestService_UpdateCollectibleInfo(t *testing.T) {
|
|||||||
}).Return([]thirdparty.FullCollectibleData{
|
}).Return([]thirdparty.FullCollectibleData{
|
||||||
{
|
{
|
||||||
CollectibleData: thirdparty.CollectibleData{
|
CollectibleData: thirdparty.CollectibleData{
|
||||||
|
ID: thirdparty.CollectibleUniqueID{
|
||||||
|
ContractID: thirdparty.ContractID{
|
||||||
|
ChainID: args[4].chainID,
|
||||||
|
Address: *args[4].tokenAddress},
|
||||||
|
TokenID: &bigint.BigInt{Int: args[4].tokenID},
|
||||||
|
},
|
||||||
Name: "Test 4",
|
Name: "Test 4",
|
||||||
ImageURL: "test://url/4"},
|
ImageURL: "test://url/4"},
|
||||||
CollectionData: nil,
|
CollectionData: nil,
|
||||||
}, {
|
}, {
|
||||||
CollectibleData: thirdparty.CollectibleData{
|
CollectibleData: thirdparty.CollectibleData{
|
||||||
|
ID: thirdparty.CollectibleUniqueID{
|
||||||
|
ContractID: thirdparty.ContractID{
|
||||||
|
ChainID: args[1].chainID,
|
||||||
|
Address: *args[1].tokenAddress},
|
||||||
|
TokenID: &bigint.BigInt{Int: args[1].tokenID},
|
||||||
|
},
|
||||||
Name: "Test 1",
|
Name: "Test 1",
|
||||||
ImageURL: "test://url/1"},
|
ImageURL: "test://url/1"},
|
||||||
CollectionData: nil,
|
CollectionData: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
CollectibleData: thirdparty.CollectibleData{
|
CollectibleData: thirdparty.CollectibleData{
|
||||||
|
ID: thirdparty.CollectibleUniqueID{
|
||||||
|
ContractID: thirdparty.ContractID{
|
||||||
|
ChainID: args[0].chainID,
|
||||||
|
Address: *args[0].tokenAddress},
|
||||||
|
TokenID: &bigint.BigInt{Int: args[0].tokenID},
|
||||||
|
},
|
||||||
Name: "Test 0",
|
Name: "Test 0",
|
||||||
ImageURL: "test://url/0"},
|
ImageURL: "test://url/0"},
|
||||||
CollectionData: nil,
|
CollectionData: nil,
|
||||||
@ -216,14 +234,17 @@ func TestService_UpdateCollectibleInfo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FetchAssetsByCollectibleUniqueID will receive only unique ids, while number of entries can be bigger
|
||||||
require.Equal(t, 1, filterResponseCount)
|
require.Equal(t, 1, filterResponseCount)
|
||||||
require.Equal(t, 3, len(updates))
|
require.Equal(t, 4, len(updates))
|
||||||
require.Equal(t, "Test 4", *updates[0].NftName)
|
require.Equal(t, "Test 4", *updates[0].NftName)
|
||||||
require.Equal(t, "test://url/4", *updates[0].NftURL)
|
require.Equal(t, "test://url/4", *updates[0].NftURL)
|
||||||
require.Equal(t, "Test 1", *updates[1].NftName)
|
require.Equal(t, "Test 1", *updates[1].NftName)
|
||||||
require.Equal(t, "test://url/1", *updates[1].NftURL)
|
require.Equal(t, "test://url/1", *updates[1].NftURL)
|
||||||
require.Equal(t, "Test 0", *updates[2].NftName)
|
require.Equal(t, "Test 1", *updates[2].NftName)
|
||||||
require.Equal(t, "test://url/0", *updates[2].NftURL)
|
require.Equal(t, "test://url/1", *updates[2].NftURL)
|
||||||
|
require.Equal(t, "Test 0", *updates[3].NftName)
|
||||||
|
require.Equal(t, "test://url/0", *updates[3].NftURL)
|
||||||
|
|
||||||
sub.Unsubscribe()
|
sub.Unsubscribe()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user