From 6566230bed78608ac348d39a5ee7d8196acd5a06 Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Sat, 12 Sep 2015 10:59:01 +0200
Subject: [PATCH] Fix display in homescreen

---
 src/cutecoin/core/net/api/bma/access.py |  3 --
 src/cutecoin/gui/community_tile.py      |  9 ++++-
 src/cutecoin/gui/community_view.py      |  8 ++++
 src/cutecoin/gui/homescreen.py          | 11 ++++-
 src/cutecoin/gui/mainwindow.py          |  4 +-
 src/cutecoin/gui/transactions_tab.py    | 54 +++++--------------------
 6 files changed, 37 insertions(+), 52 deletions(-)

diff --git a/src/cutecoin/core/net/api/bma/access.py b/src/cutecoin/core/net/api/bma/access.py
index df1c2108..5c64b382 100644
--- a/src/cutecoin/core/net/api/bma/access.py
+++ b/src/cutecoin/core/net/api/bma/access.py
@@ -148,9 +148,6 @@ class BmaAccess(QObject):
         :return: The future data
         :rtype: dict
         """
-        if request == blockchain.UD:
-            pass
-
         def handle_future_reply(reply):
             if reply.error() == QNetworkReply.NoError:
                 strdata = bytes(reply.readAll()).decode('utf-8')
diff --git a/src/cutecoin/gui/community_tile.py b/src/cutecoin/gui/community_tile.py
index cfe1ec27..205b3ec4 100644
--- a/src/cutecoin/gui/community_tile.py
+++ b/src/cutecoin/gui/community_tile.py
@@ -33,6 +33,11 @@ class CommunityTile(QFrame):
     def refresh(self):
         current_block = yield from self.community.get_block(self.community.network.latest_block_number)
         members_pubkeys = yield from self.community.members_pubkeys()
+        amount = yield from self.app.current_account.amount(self.community)
+        localized_amount = yield from self.app.current_account.current_ref(amount,
+                                                    self.community, self.app).localized(units=True)
+        localized_monetary_mass = yield from self.app.current_account.current_ref(current_block['monetaryMass'],
+                                                    self.community, self.app).localized(units=True)
         status = self.tr("Member") if self.app.current_account.pubkey in members_pubkeys \
             else self.tr("Non-Member")
         description = """<html>
@@ -49,11 +54,11 @@ class CommunityTile(QFrame):
                           nb_members=len(members_pubkeys),
                           members_label=self.tr("members"),
                           monetary_mass_label=self.tr("Monetary mass"),
-                          monetary_mass=current_block['monetaryMass'],
+                          monetary_mass=localized_monetary_mass,
                           status_label=self.tr("Status"),
                           status=status,
                           balance_label=self.tr("Balance"),
-                          balance=self.app.current_account.amount(self.community))
+                          balance=localized_amount)
         self.text_label.setText(description)
 
     def mousePressEvent(self, event):
diff --git a/src/cutecoin/gui/community_view.py b/src/cutecoin/gui/community_view.py
index c0e515d5..2d77b6a1 100644
--- a/src/cutecoin/gui/community_view.py
+++ b/src/cutecoin/gui/community_view.py
@@ -324,6 +324,14 @@ Revoking your UID can only success if it is not already validated by the network
         else:
             QMessageBox.error(error, strdata)
 
+    def showEvent(self, QShowEvent):
+        """
+
+        :param QShowEvent:
+        :return:
+        """
+        self.refresh_status()
+
     def changeEvent(self, event):
         """
         Intercepte LanguageChange event to translate UI
diff --git a/src/cutecoin/gui/homescreen.py b/src/cutecoin/gui/homescreen.py
index cc4db8af..d20dff14 100644
--- a/src/cutecoin/gui/homescreen.py
+++ b/src/cutecoin/gui/homescreen.py
@@ -48,7 +48,7 @@ class HomeScreenWidget(QWidget, Ui_HomescreenWidget):
     classdocs
     """
 
-    def __init__(self, app):
+    def __init__(self, app, status_label):
         """
         Constructor
         """
@@ -57,6 +57,7 @@ class HomeScreenWidget(QWidget, Ui_HomescreenWidget):
         self.app = app
         self.frame_communities = FrameCommunities(self)
         self.layout().addWidget(self.frame_communities)
+        self.status_label = status_label
 
     def refresh(self):
         self.frame_communities.refresh(self.app)
@@ -68,6 +69,14 @@ class HomeScreenWidget(QWidget, Ui_HomescreenWidget):
             self.frame_disconnected.show()
             self.frame_connected.hide()
 
+    def showEvent(self, QShowEvent):
+        """
+
+        :param QShowEvent:
+        :return:
+        """
+        self.status_label.setText("")
+
     def changeEvent(self, event):
         """
         Intercepte LanguageChange event to translate UI
diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py
index 37289751..a361f6bc 100644
--- a/src/cutecoin/gui/mainwindow.py
+++ b/src/cutecoin/gui/mainwindow.py
@@ -66,7 +66,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
         self.combo_referential.currentIndexChanged.connect(self.referential_changed)
         self.statusbar.addPermanentWidget(self.combo_referential)
 
-        self.homescreen = HomeScreenWidget(self.app)
+        self.homescreen = HomeScreenWidget(self.app, self.status_label)
         self.homescreen.frame_communities.community_tile_clicked.connect(self.change_community)
         self.homescreen.toolbutton_new_account.addAction(self.action_add_account)
         self.homescreen.toolbutton_new_account.addAction(self.action_import)
@@ -254,8 +254,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
             self.homescreen.hide()
             self.community_view.show()
         else:
-            self.homescreen.show()
             self.community_view.hide()
+            self.homescreen.show()
 
         self.community_view.change_community(community)
 
diff --git a/src/cutecoin/gui/transactions_tab.py b/src/cutecoin/gui/transactions_tab.py
index e0b0f912..534bc085 100644
--- a/src/cutecoin/gui/transactions_tab.py
+++ b/src/cutecoin/gui/transactions_tab.py
@@ -111,51 +111,17 @@ class TransactionsTabWidget(QWidget, Ui_transactionsTabWidget):
     @asyncify
     @asyncio.coroutine
     def refresh_balance(self):
-        if self.app.preferences['expert_mode']:
-            # if referential is "units"
-            if self.app.current_account._current_ref == 0:
-                self.label_balance.show()
-                self.label_deposit.show()
-                self.label_payment.show()
-            else:
-                self.label_balance.hide()
-                self.label_deposit.hide()
-                self.label_payment.hide()
-
-            proxy = self.table_history.model()
-            balance = proxy.deposits - proxy.payments
-            localized_deposits = yield from self.app.current_account.current_ref(proxy.deposits, self.community,
-                                                                                 self.app).diff_localized()
-            localized_payments = yield from self.app.current_account.current_ref(proxy.payments, self.community,
-                                                                                 self.app).diff_localized()
-            localized_balance = yield from self.app.current_account.current_ref(balance, self.community,
-                                                                                self.app).diff_localized()
-
-            self.label_deposit.setText(QCoreApplication.translate("TransactionsTabWidget", "<b>Deposits</b> {:} {:}").format(
-                localized_deposits,
-                self.app.current_account.current_ref.units(self.community.short_currency)
-            ))
-            self.label_payment.setText(QCoreApplication.translate("TransactionsTabWidget", "<b>Payments</b> {:} {:}").format(
-                localized_payments,
-                self.app.current_account.current_ref.units(self.community.short_currency)
-            ))
-            self.label_balance.setText(QCoreApplication.translate("TransactionsTabWidget", "<b>Balance</b> {:} {:}").format(
-                localized_balance,
-                self.app.current_account.current_ref.units(self.community.short_currency)
-            ))
-
-        else:
-            amount = yield from self.app.current_account.amount(self.community)
-            localized_amount = yield from self.app.current_account.current_ref(amount, self.community,
-                                                                               self.app).localized(units=True)
-
-            # set infos in label
-            self.label_balance.setText(
-                self.tr("{:}")
-                .format(
-                    localized_amount
-                )
+        amount = yield from self.app.current_account.amount(self.community)
+        localized_amount = yield from self.app.current_account.current_ref(amount, self.community,
+                                                                           self.app).localized(units=True)
+
+        # set infos in label
+        self.label_balance.setText(
+            self.tr("{:}")
+            .format(
+                localized_amount
             )
+        )
 
     def history_context_menu(self, point):
         index = self.table_history.indexAt(point)
-- 
GitLab