Repository: rotki/rotki

Issue:
Changing fiat currency does not change manually tracked balances value column title
## Problem Definition

Seen in v1.4.0 by @cryptomole1

Changing the FIAT currency via the drop-down menu if the user has manually tracked balances changes the value but not the title of the column. The title of the column is stuck to being `USD Value`.

I can confirm the problem, just tested it.

## Task

- Fix it
- Write a unit test


Discussion:

Resolving patch:
diff --git a/rotkehlchen/balances/manual.py b/rotkehlchen/balances/manual.py
--- a/rotkehlchen/balances/manual.py
+++ b/rotkehlchen/balances/manual.py
@@ -1,10 +1,11 @@
 from typing import TYPE_CHECKING, Any, Dict, List, NamedTuple, Optional
 
 from rotkehlchen.assets.asset import Asset
-from rotkehlchen.errors import InputError
+from rotkehlchen.constants.misc import ZERO
+from rotkehlchen.errors import InputError, RemoteError
 from rotkehlchen.fval import FVal
 from rotkehlchen.inquirer import Inquirer
-from rotkehlchen.typing import Location
+from rotkehlchen.typing import Location, Price
 
 if TYPE_CHECKING:
     from rotkehlchen.db.dbhandler import DBHandler
@@ -30,15 +31,18 @@ class ManuallyTrackedBalanceWithValue(NamedTuple):
 
 
 def get_manually_tracked_balances(db: 'DBHandler') -> List[ManuallyTrackedBalanceWithValue]:
-    """Gets the manually tracked balances
-
-    May raise:
-    - RemoteError if there is a problem querying for the current price of an asset
-    """
+    """Gets the manually tracked balances"""
     balances = db.get_manually_tracked_balances()
     balances_with_value = []
     for entry in balances:
-        price = Inquirer().find_usd_price(entry.asset)
+        try:
+            price = Inquirer().find_usd_price(entry.asset)
+        except RemoteError as e:
+            db.msg_aggregator.add_warning(
+                f'Could not find price for {entry.asset.identifier} during '
+                f'manually tracked balance querying due to {str(e)}',
+            )
+            price = Price(ZERO)
         # https://github.com/python/mypy/issues/2582 --> for the type ignore below
         balances_with_value.append(ManuallyTrackedBalanceWithValue(  # type: ignore
             **entry._asdict(),


Test patch:
diff --git a/rotkehlchen/tests/api/test_manually_tracked_balances.py b/rotkehlchen/tests/api/test_manually_tracked_balances.py
--- a/rotkehlchen/tests/api/test_manually_tracked_balances.py
+++ b/rotkehlchen/tests/api/test_manually_tracked_balances.py
@@ -60,12 +60,16 @@ def _populate_tags(api_server):
 def assert_balances_match(
         expected_balances: List[Dict[str, Any]],
         returned_balances: List[Dict[str, Any]],
+        expect_found_price: bool = True,
 ) -> None:
     assert len(returned_balances) == len(expected_balances)
     for idx, entry in enumerate(reversed(returned_balances)):
         for key, val in entry.items():
             if key == 'usd_value':
-                assert FVal(val) > ZERO
+                if expect_found_price:
+                    assert FVal(val) > ZERO
+                else:
+                    assert FVal(val) == ZERO
                 continue
             if key == 'tags':
                 if val is None:
@@ -139,6 +143,45 @@ def test_add_and_query_manually_tracked_balances(
     assert_balances_match(expected_balances=balances, returned_balances=result['balances'])
 
 
+def test_add_manually_tracked_balances_no_price(rotkehlchen_api_server):
+    """Test that adding a manually tracked balance of an asset for which we cant
+    query a price is handled properly both in the adding and querying part
+
+    Regression test for https://github.com/rotki/rotki/issues/896"""
+    _populate_tags(rotkehlchen_api_server)
+    balances: List[Dict[str, Any]] = [{
+        "asset": "CYFM",
+        "label": "CUFM account",
+        "amount": "50.315",
+        "tags": ["public"],
+        "location": "blockchain",
+    }]
+    response = requests.put(
+        api_url_for(
+            rotkehlchen_api_server,
+            "manuallytrackedbalancesresource",
+        ), json={'balances': balances},
+    )
+    result = assert_proper_response_with_result(response)
+    assert_balances_match(
+        expected_balances=balances,
+        returned_balances=result['balances'],
+        expect_found_price=False,
+    )
+    response = requests.get(
+        api_url_for(
+            rotkehlchen_api_server,
+            "manuallytrackedbalancesresource",
+        ),
+    )
+    result = assert_proper_response_with_result(response)
+    assert_balances_match(
+        expected_balances=balances,
+        returned_balances=result['balances'],
+        expect_found_price=False,
+    )
+
+
 def test_edit_manually_tracked_balances(
         rotkehlchen_api_server,
 ):