Repository: rotki/rotki

Issue:
New endpoint that return all `evm chains`
We need new endpoint that return all `evm chains` so we don't hardcode anything in frontend.
I guess an endpoint that return the data from the `ChainId` struct:
```
[
  {"chain_id": "1", "name": "ethereum"},
  {"chain_id": "10", "name": "optimism"},
  {"chain_id": "56", "name": "binance"},
  {"chain_id": "100", "name": "gnosis"},
  {"chain_id": "137", "name": "matic"},
  {"chain_id": "250", "name": "fantom"},
  {"chain_id": "42161", "name": "arbitrum"},
  {"chain_id": "43114", "name": "avalanche"},
  {"chain_id": "42220", "name": "celo"},
]
```


Discussion:
Any reason why we can't keep the chain id unquoted?

Are we gonna hit the [MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)?

Resolving patch:
diff --git a/rotkehlchen/api/rest.py b/rotkehlchen/api/rest.py
--- a/rotkehlchen/api/rest.py
+++ b/rotkehlchen/api/rest.py
@@ -5014,3 +5014,12 @@ def get_event_details(self, identifier: int) -> Response:
             return api_response(wrap_in_fail_result('No details found'), status_code=HTTPStatus.NOT_FOUND)  # noqa: E501
 
         return api_response(_wrap_in_ok_result(details), status_code=HTTPStatus.OK)
+
+    def get_all_evm_chains(self) -> Response:
+        """Returns a list of all EVM chain ids."""
+        return api_response(
+            result=_wrap_in_ok_result(result=[
+                {'id': chain.value, 'name': chain.to_name()}
+                for chain in ChainID
+            ]),
+        )
diff --git a/rotkehlchen/api/server.py b/rotkehlchen/api/server.py
--- a/rotkehlchen/api/server.py
+++ b/rotkehlchen/api/server.py
@@ -26,6 +26,7 @@
     AddressbookResource,
     AllAssetsResource,
     AllBalancesResource,
+    AllEvmChainsResource,
     AllLatestAssetsPriceResource,
     AllNamesResource,
     AssetIconFileResource,
@@ -221,6 +222,7 @@
     ),
     ('/queried_addresses', QueriedAddressesResource),
     ('/blockchains/supported', SupportedChainsResource),
+    ('blockchains/evm/all', AllEvmChainsResource),
     ('/blockchains/evm/transactions', EvmTransactionsResource),
     ('/blockchains/evm/transactions/decode', EvmPendingTransactionsDecodingResource),
     ('/blockchains/ETH2/validators', Eth2ValidatorsResource),
diff --git a/rotkehlchen/api/v1/resources.py b/rotkehlchen/api/v1/resources.py
--- a/rotkehlchen/api/v1/resources.py
+++ b/rotkehlchen/api/v1/resources.py
@@ -2797,3 +2797,9 @@ class EventDetailsResource(BaseMethodView):
     @use_kwargs(get_schema, location='json_and_query')
     def get(self, identifier: int) -> Response:
         return self.rest_api.get_event_details(identifier=identifier)
+
+
+class AllEvmChainsResource(BaseMethodView):
+
+    def get(self) -> Response:
+        return self.rest_api.get_all_evm_chains()


Test patch:
diff --git a/rotkehlchen/tests/api/test_misc.py b/rotkehlchen/tests/api/test_misc.py
--- a/rotkehlchen/tests/api/test_misc.py
+++ b/rotkehlchen/tests/api/test_misc.py
@@ -17,7 +17,7 @@
     assert_proper_response,
     assert_proper_response_with_result,
 )
-from rotkehlchen.types import SupportedBlockchain
+from rotkehlchen.types import ChainID, SupportedBlockchain
 from rotkehlchen.utils.misc import get_system_spec
 
 
@@ -403,3 +403,9 @@ def test_query_supported_chains(rotkehlchen_api_server):
                 break  # found
         else:  # internal for loop found nothing
             raise AssertionError(f'Did not find {entry} in the supported chains result')
+
+
+def test_query_all_chain_ids(rotkehlchen_api_server):
+    response = requests.get(api_url_for(rotkehlchen_api_server, 'allevmchainsresource'))
+    result = assert_proper_response_with_result(response)
+    assert result == [{'id': chain.value, 'name': chain.to_name()} for chain in ChainID]