From 7be222a1d20913515c9ec9a2b5010816aa9b8dba Mon Sep 17 00:00:00 2001 From: Dario Gabriel Lipicar Date: Fri, 29 Nov 2024 11:37:56 -0300 Subject: [PATCH] feat_: add unique key to each activity entry --- services/wallet/activity/activity.go | 13 +++++++++++++ services/wallet/activity/service.go | 1 + services/wallet/activity/session_service.go | 1 + services/wallet/transfer/transaction_manager.go | 4 ++++ 4 files changed, 19 insertions(+) diff --git a/services/wallet/activity/activity.go b/services/wallet/activity/activity.go index 6048aa50c..851e0e9b9 100644 --- a/services/wallet/activity/activity.go +++ b/services/wallet/activity/activity.go @@ -85,9 +85,21 @@ type Entry struct { isNew bool // isNew is used to indicate if the entry is newer than session start (changed state also) } +func (e *Entry) Key() string { + if e.payloadType == MultiTransactionPT { + key := fmt.Sprintf("%d", e.id) + for _, t := range e.transactions { + key += fmt.Sprintf("-%s", t.Key()) + } + return key + } + return e.transaction.Key() +} + // Only used for JSON marshalling type EntryData struct { PayloadType PayloadType `json:"payloadType"` + Key string `json:"key"` Transaction *transfer.TransactionIdentity `json:"transaction,omitempty"` ID *common.MultiTransactionIDType `json:"id,omitempty"` Transactions []*transfer.TransactionIdentity `json:"transactions,omitempty"` @@ -118,6 +130,7 @@ type EntryData struct { func (e *Entry) MarshalJSON() ([]byte, error) { data := EntryData{ + Key: e.Key(), Timestamp: &e.timestamp, ActivityType: &e.activityType, ActivityStatus: &e.activityStatus, diff --git a/services/wallet/activity/service.go b/services/wallet/activity/service.go index ea73d7886..4148a5bdc 100644 --- a/services/wallet/activity/service.go +++ b/services/wallet/activity/service.go @@ -276,6 +276,7 @@ func (s *Service) getActivityDetails(ctx context.Context, entries []Entry) ([]*E } for _, e := range entryList { data := &EntryData{ + Key: e.Key(), NftName: nftName, NftURL: nftURL, } diff --git a/services/wallet/activity/session_service.go b/services/wallet/activity/session_service.go index 775b3bcf8..2d61dcf96 100644 --- a/services/wallet/activity/session_service.go +++ b/services/wallet/activity/session_service.go @@ -456,6 +456,7 @@ func (s *Service) processEntryDataUpdates(sessionID SessionID, entries []Entry, } data := &EntryData{ + Key: e.Key(), ActivityStatus: &e.activityStatus, } if e.payloadType == MultiTransactionPT { diff --git a/services/wallet/transfer/transaction_manager.go b/services/wallet/transfer/transaction_manager.go index ebe9583b3..30fa2e54b 100644 --- a/services/wallet/transfer/transaction_manager.go +++ b/services/wallet/transfer/transaction_manager.go @@ -126,6 +126,10 @@ type TransactionIdentity struct { Address common.Address `json:"address"` } +func (tid *TransactionIdentity) Key() string { + return fmt.Sprintf("%d-%s-%s", tid.ChainID, tid.Hash.Hex(), tid.Address.Hex()) +} + type TxResponse struct { KeyUID string `json:"keyUid,omitempty"` Address types.Address `json:"address,omitempty"`