Repository: rotki/rotki

Issue:
Uncheck selected trades
## Problem Definition

When you click on the button to select all the trades  you can't unselect them all at once by clicking the same button (not other that I've seen)

![image](https://user-images.githubusercontent.com/5068010/128060501-2770aa90-2358-495f-b4e5-5daeae235301.png)

Operating system: Docker
Rotki version: 1.19.1



Discussion:
So this is for @kelsos to look at I guess
What was the state of the application when that happened. If I remember correctly, the way I implemented the select functionality, it only selects items based on the visible dataset. If you select all while it is loading for example and then more entries appear then the checkbox would be unchecked because the newly added items are not selected.

The same would happen if you select a location filter and then remove the filter.
@kelsos There was nothing selected, everything loaded already and no filter was applied 
So I managed to reproduce it and then with the help of @kelsos figured out the problem is actually the backend generating the same identifier for two different trades.

This, at least in my case, happened for different swaps from different AMMs but in the same transaction. So using an aggregator like paraswap or 1inch and having same transaction hash for a balancer swap and a uniswap swap.

I can easily fix by using the log index in the trade id too. But we probably need a nice way to log this in the frontend in case this happens again, so we know what is the root cause and fix it.

Resolving patch:
diff --git a/rotkehlchen/chain/ethereum/trades.py b/rotkehlchen/chain/ethereum/trades.py
--- a/rotkehlchen/chain/ethereum/trades.py
+++ b/rotkehlchen/chain/ethereum/trades.py
@@ -184,8 +184,13 @@ def address(self) -> ChecksumEthAddress:
 
     @property
     def identifier(self) -> str:
-        """Since these trades are made up, uniqueness needs an extra id"""
-        return f'{self.tx_hash}-{self.trade_index}'
+        """Since these trades are made up, uniqueness needs an extra id
+
+        Also look at https://github.com/rotki/rotki/issues/3287. Turns out this
+        identifier mechanism is not unique for multiple swaps in same transaction
+        from different locations. So also adding log index in there to make up for it.
+        """
+        return f'{self.tx_hash}-{self.trade_index}-{self.swaps[0].log_index}'
 
     @property
     def trade_id(self) -> str:


Test patch:
diff --git a/rotkehlchen/tests/api/test_sushiswap.py b/rotkehlchen/tests/api/test_sushiswap.py
--- a/rotkehlchen/tests/api/test_sushiswap.py
+++ b/rotkehlchen/tests/api/test_sushiswap.py
@@ -7,12 +7,12 @@
 import requests
 
 from rotkehlchen.assets.asset import EthereumToken
+from rotkehlchen.chain.ethereum.interfaces.ammswap.typing import EventType
 from rotkehlchen.chain.ethereum.modules.sushiswap import (
+    SUSHISWAP_EVENTS_PREFIX,
     SushiswapPoolEvent,
     SushiswapPoolEventsBalance,
-    SUSHISWAP_EVENTS_PREFIX,
 )
-from rotkehlchen.chain.ethereum.interfaces.ammswap.typing import EventType
 from rotkehlchen.chain.ethereum.trades import AMMSwap, AMMTrade
 from rotkehlchen.chain.ethereum.typing import string_to_ethereum_address
 from rotkehlchen.constants.misc import ZERO
@@ -30,7 +30,6 @@
 from rotkehlchen.tests.utils.rotkehlchen import setup_balances
 from rotkehlchen.typing import AssetAmount, Location, Price, Timestamp, TradeType
 
-
 SWAP_ADDRESS = string_to_ethereum_address('0x63BC843b9640c4D79d6aE0105bc39F773172d121')
 
 
@@ -423,6 +422,7 @@ def test_get_sushiswap_trades_history(
 ]
 
 
+@pytest.mark.skip('Fails with no event found anymore in the given time range')
 @pytest.mark.parametrize('ethereum_accounts', [[TEST_EVENTS_ADDRESS_1]])
 @pytest.mark.parametrize('ethereum_modules', [['sushiswap']])
 @pytest.mark.parametrize('start_with_valid_premium', [True])