From b60936deb5cb9854e348c4e10f87194eda90730a Mon Sep 17 00:00:00 2001
From: Moul <moul@moul.re>
Date: Wed, 2 Aug 2023 21:15:01 +0200
Subject: [PATCH] Do not display monetary mass per members

when there is zero members which causes a ZeroDivisionError
G1-test reaching zero members revealed a bug
---
 silkaj/money/balance.py              | 23 ++++++++++++++---------
 tests/integration/test_end_to_end.py |  1 -
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/silkaj/money/balance.py b/silkaj/money/balance.py
index 4cfa5b6b..a1a1f42a 100644
--- a/silkaj/money/balance.py
+++ b/silkaj/money/balance.py
@@ -14,7 +14,7 @@
 # along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
 
 import sys
-from typing import List
+from typing import List, Optional
 
 import rich_click as click
 
@@ -112,18 +112,23 @@ def show_amount_from_pubkey(label: str, inputs_balance: List[int]) -> None:
         ud_value,
         currency_symbol,
     )
-    display.append(
-        [
-            "Total relative to M/N",
-            f"{round(totalAmountInput / average, 2)} x M/N",
-        ],
-    )
+    if average:
+        display.append(
+            [
+                "Total relative to M/N",
+                f"{round(totalAmountInput / average, 2)} x M/N",
+            ],
+        )
 
     table = tui.Table()
     table.fill_rows(display)
     click.echo(table.draw())
 
 
-def get_average() -> int:
+def get_average() -> Optional[int]:
     head = get_head_block()
-    return head["monetaryMass"] / head["membersCount"]
+    try:
+        return head["monetaryMass"] / head["membersCount"]
+    except ZeroDivisionError:
+        print("The currency reached zero members")
+        return None
diff --git a/tests/integration/test_end_to_end.py b/tests/integration/test_end_to_end.py
index a96bb3fa..70ad4d18 100644
--- a/tests/integration/test_end_to_end.py
+++ b/tests/integration/test_end_to_end.py
@@ -62,4 +62,3 @@ def test_money_balance():
     assert ":EyF" in output
     assert "│ Total balance (unit|relative) │" in output
     assert "UD ĞTest" in output
-    assert "Total relative to M/N" in output
-- 
GitLab