From 5c7748dbf761af7f90c06537baf92f11c182a59f Mon Sep 17 00:00:00 2001 From: Stefan Date: Tue, 19 Sep 2023 22:58:13 +0200 Subject: [PATCH] feat(wallet) add API to cancel current activity filter Closes status-desktop #11036 --- services/wallet/activity/activity.go | 1 - services/wallet/activity/filter.sql | 51 +++++++++++++++------------- services/wallet/activity/service.go | 9 +++++ services/wallet/api.go | 7 ++++ 4 files changed, 43 insertions(+), 25 deletions(-) diff --git a/services/wallet/activity/activity.go b/services/wallet/activity/activity.go index 0878ef075..f6a05059b 100644 --- a/services/wallet/activity/activity.go +++ b/services/wallet/activity/activity.go @@ -200,7 +200,6 @@ func (e *Entry) isNFT() bool { return tt != nil && (*tt == TransferTypeErc721 || *tt == TransferTypeErc1155) && ((e.tokenIn != nil && e.tokenIn.TokenID != nil) || (e.tokenOut != nil && e.tokenOut.TokenID != nil)) } -// TODO - #11952: use only one of (big.Int, bigint.BigInt and hexutil.Big) func tokenIDToWalletBigInt(tokenID *hexutil.Big) *bigint.BigInt { if tokenID == nil { return nil diff --git a/services/wallet/activity/filter.sql b/services/wallet/activity/filter.sql index 141467f47..f93f02014 100644 --- a/services/wallet/activity/filter.sql +++ b/services/wallet/activity/filter.sql @@ -161,15 +161,14 @@ SELECT transfers.timestamp AS timestamp, NULL AS mt_type, CASE - WHEN from_join.address IS NOT NULL - AND to_join.address IS NULL THEN fromTrType - WHEN to_join.address IS NOT NULL - AND from_join.address IS NULL THEN toTrType - WHEN from_join.address IS NOT NULL - AND to_join.address IS NOT NULL THEN CASE - WHEN transfers.address = transfers.tx_from_address THEN fromTrType - ELSE toTrType - END + WHEN from_join.address IS NOT NULL AND to_join.address IS NULL THEN fromTrType + WHEN to_join.address IS NOT NULL AND from_join.address IS NULL THEN toTrType + WHEN from_join.address IS NOT NULL AND to_join.address IS NOT NULL THEN + CASE + WHEN transfers.address = transfers.tx_from_address THEN fromTrType + WHEN transfers.address = transfers.tx_to_address THEN toTrType + ELSE NULL + END ELSE NULL END as tr_type, transfers.tx_from_address AS from_address, @@ -204,8 +203,6 @@ SELECT FROM transfers CROSS JOIN filter_conditions - INNER JOIN filter_to_addresses receiver_join ON filterAllToAddresses != 0 - OR transfers.tx_to_address = receiver_join.address LEFT JOIN filter_addresses from_join ON transfers.tx_from_address = from_join.address LEFT JOIN filter_addresses to_join ON transfers.tx_to_address = to_join.address WHERE @@ -267,6 +264,10 @@ WHERE filterAllAddresses -- Every account address has an "owned" entry either as to or from OR (owner_address IN filter_addresses) ) + AND ( + filterAllToAddresses + OR (transfers.tx_to_address IN filter_to_addresses) + ) AND ( includeAllTokenTypeAssets OR ( @@ -325,15 +326,13 @@ SELECT pending_transactions.timestamp AS timestamp, NULL AS mt_type, CASE - WHEN from_join.address IS NOT NULL - AND to_join.address IS NULL THEN fromTrType - WHEN to_join.address IS NOT NULL - AND from_join.address IS NULL THEN toTrType - WHEN from_join.address IS NOT NULL - AND to_join.address IS NOT NULL THEN CASE - WHEN from_join.address < to_join.address THEN fromTrType - ELSE toTrType - END + WHEN from_join.address IS NOT NULL AND to_join.address IS NULL THEN fromTrType + WHEN to_join.address IS NOT NULL AND from_join.address IS NULL THEN toTrType + WHEN from_join.address IS NOT NULL AND to_join.address IS NOT NULL THEN + CASE + WHEN from_join.address < to_join.address THEN fromTrType + ELSE toTrType + END ELSE NULL END as tr_type, pending_transactions.from_address AS from_address, @@ -356,8 +355,6 @@ SELECT FROM pending_transactions CROSS JOIN filter_conditions - INNER JOIN filter_to_addresses receiver_join ON filterAllToAddresses != 0 - OR pending_transactions.to_address = receiver_join.address LEFT JOIN filter_addresses from_join ON pending_transactions.from_address = from_join.address LEFT JOIN filter_addresses to_join ON pending_transactions.to_address = to_join.address WHERE @@ -386,6 +383,10 @@ WHERE filterAllAddresses OR tr_type NOT NULL ) + AND ( + filterAllToAddresses + OR (pending_transactions.to_address IN filter_to_addresses) + ) AND ( includeAllTokenTypeAssets OR ( @@ -443,8 +444,6 @@ SELECT FROM multi_transactions CROSS JOIN filter_conditions - INNER JOIN filter_to_addresses receiver_join ON filterAllToAddresses != 0 - OR multi_transactions.to_address = receiver_join.address LEFT JOIN tr_status ON multi_transactions.ROWID = tr_status.multi_transaction_id LEFT JOIN pending_status ON multi_transactions.ROWID = pending_status.multi_transaction_id WHERE @@ -478,6 +477,10 @@ WHERE ) ) ) + AND ( + filterAllToAddresses + OR (multi_transactions.to_address IN filter_to_addresses) + ) AND ( includeAllTokenTypeAssets OR ( diff --git a/services/wallet/activity/service.go b/services/wallet/activity/service.go index 52cc5561b..53749997b 100644 --- a/services/wallet/activity/service.go +++ b/services/wallet/activity/service.go @@ -236,6 +236,15 @@ func (s *Service) GetOldestTimestampAsync(requestID int32, addresses []common.Ad }) } +func (s *Service) CancelFilterTask(requestID int32) { + s.scheduler.Enqueue(requestID, filterTask, func(ctx context.Context) (interface{}, error) { + // No-op + return nil, nil + }, func(result interface{}, taskType async.TaskType, err error) { + // Ignore result + }) +} + func (s *Service) Stop() { s.scheduler.Stop() } diff --git a/services/wallet/api.go b/services/wallet/api.go index 5fd802de1..4f2b4705d 100644 --- a/services/wallet/api.go +++ b/services/wallet/api.go @@ -577,6 +577,13 @@ func (api *API) FilterActivityAsync(requestID int32, addresses []common.Address, return nil } +func (api *API) CancelActivityFilterTask(requestID int32) error { + log.Debug("wallet.api.CancelActivityFilterTask", "requestID", requestID) + + api.s.activity.CancelFilterTask(requestID) + return nil +} + func (api *API) GetMultiTxDetails(ctx context.Context, multiTxID int) (*activity.EntryDetails, error) { log.Debug("wallet.api.GetMultiTxDetails", "multiTxID", multiTxID)