feat(wallet) add API to cancel current activity filter

Closes status-desktop #11036
This commit is contained in:
Stefan 2023-09-19 22:58:13 +02:00 committed by Stefan Dunca
parent 579f7e4a52
commit 5c7748dbf7
4 changed files with 43 additions and 25 deletions

View File

@ -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)) 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 { func tokenIDToWalletBigInt(tokenID *hexutil.Big) *bigint.BigInt {
if tokenID == nil { if tokenID == nil {
return nil return nil

View File

@ -161,15 +161,14 @@ SELECT
transfers.timestamp AS timestamp, transfers.timestamp AS timestamp,
NULL AS mt_type, NULL AS mt_type,
CASE CASE
WHEN from_join.address IS NOT NULL WHEN from_join.address IS NOT NULL AND to_join.address IS NULL THEN fromTrType
AND to_join.address IS NULL THEN fromTrType WHEN to_join.address IS NOT NULL AND from_join.address IS NULL THEN toTrType
WHEN to_join.address IS NOT NULL WHEN from_join.address IS NOT NULL AND to_join.address IS NOT NULL THEN
AND from_join.address IS NULL THEN toTrType CASE
WHEN from_join.address IS NOT NULL WHEN transfers.address = transfers.tx_from_address THEN fromTrType
AND to_join.address IS NOT NULL THEN CASE WHEN transfers.address = transfers.tx_to_address THEN toTrType
WHEN transfers.address = transfers.tx_from_address THEN fromTrType ELSE NULL
ELSE toTrType END
END
ELSE NULL ELSE NULL
END as tr_type, END as tr_type,
transfers.tx_from_address AS from_address, transfers.tx_from_address AS from_address,
@ -204,8 +203,6 @@ SELECT
FROM FROM
transfers transfers
CROSS JOIN filter_conditions 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 from_join ON transfers.tx_from_address = from_join.address
LEFT JOIN filter_addresses to_join ON transfers.tx_to_address = to_join.address LEFT JOIN filter_addresses to_join ON transfers.tx_to_address = to_join.address
WHERE WHERE
@ -267,6 +264,10 @@ WHERE
filterAllAddresses -- Every account address has an "owned" entry either as to or from filterAllAddresses -- Every account address has an "owned" entry either as to or from
OR (owner_address IN filter_addresses) OR (owner_address IN filter_addresses)
) )
AND (
filterAllToAddresses
OR (transfers.tx_to_address IN filter_to_addresses)
)
AND ( AND (
includeAllTokenTypeAssets includeAllTokenTypeAssets
OR ( OR (
@ -325,15 +326,13 @@ SELECT
pending_transactions.timestamp AS timestamp, pending_transactions.timestamp AS timestamp,
NULL AS mt_type, NULL AS mt_type,
CASE CASE
WHEN from_join.address IS NOT NULL WHEN from_join.address IS NOT NULL AND to_join.address IS NULL THEN fromTrType
AND to_join.address IS NULL THEN fromTrType WHEN to_join.address IS NOT NULL AND from_join.address IS NULL THEN toTrType
WHEN to_join.address IS NOT NULL WHEN from_join.address IS NOT NULL AND to_join.address IS NOT NULL THEN
AND from_join.address IS NULL THEN toTrType CASE
WHEN from_join.address IS NOT NULL WHEN from_join.address < to_join.address THEN fromTrType
AND to_join.address IS NOT NULL THEN CASE ELSE toTrType
WHEN from_join.address < to_join.address THEN fromTrType END
ELSE toTrType
END
ELSE NULL ELSE NULL
END as tr_type, END as tr_type,
pending_transactions.from_address AS from_address, pending_transactions.from_address AS from_address,
@ -356,8 +355,6 @@ SELECT
FROM FROM
pending_transactions pending_transactions
CROSS JOIN filter_conditions 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 from_join ON pending_transactions.from_address = from_join.address
LEFT JOIN filter_addresses to_join ON pending_transactions.to_address = to_join.address LEFT JOIN filter_addresses to_join ON pending_transactions.to_address = to_join.address
WHERE WHERE
@ -386,6 +383,10 @@ WHERE
filterAllAddresses filterAllAddresses
OR tr_type NOT NULL OR tr_type NOT NULL
) )
AND (
filterAllToAddresses
OR (pending_transactions.to_address IN filter_to_addresses)
)
AND ( AND (
includeAllTokenTypeAssets includeAllTokenTypeAssets
OR ( OR (
@ -443,8 +444,6 @@ SELECT
FROM FROM
multi_transactions multi_transactions
CROSS JOIN filter_conditions 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 tr_status ON multi_transactions.ROWID = tr_status.multi_transaction_id
LEFT JOIN pending_status ON multi_transactions.ROWID = pending_status.multi_transaction_id LEFT JOIN pending_status ON multi_transactions.ROWID = pending_status.multi_transaction_id
WHERE WHERE
@ -478,6 +477,10 @@ WHERE
) )
) )
) )
AND (
filterAllToAddresses
OR (multi_transactions.to_address IN filter_to_addresses)
)
AND ( AND (
includeAllTokenTypeAssets includeAllTokenTypeAssets
OR ( OR (

View File

@ -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() { func (s *Service) Stop() {
s.scheduler.Stop() s.scheduler.Stop()
} }

View File

@ -577,6 +577,13 @@ func (api *API) FilterActivityAsync(requestID int32, addresses []common.Address,
return nil 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) { func (api *API) GetMultiTxDetails(ctx context.Context, multiTxID int) (*activity.EntryDetails, error) {
log.Debug("wallet.api.GetMultiTxDetails", "multiTxID", multiTxID) log.Debug("wallet.api.GetMultiTxDetails", "multiTxID", multiTxID)