From 8c5c0da41cdab6e5443220c19678b9d6aa53866f Mon Sep 17 00:00:00 2001
From: vtexier <vit@free.fr>
Date: Sat, 21 Mar 2020 10:32:40 +0100
Subject: [PATCH] [enh] tx history update button set to disable until update is
 done

---
 .../gui/navigation/txhistory/controller.py    | 60 +++++++++++--------
 1 file changed, 36 insertions(+), 24 deletions(-)

diff --git a/src/sakia/gui/navigation/txhistory/controller.py b/src/sakia/gui/navigation/txhistory/controller.py
index 12fa8060..f30362b0 100644
--- a/src/sakia/gui/navigation/txhistory/controller.py
+++ b/src/sakia/gui/navigation/txhistory/controller.py
@@ -186,31 +186,43 @@ class TxHistoryController(QObject):
         Update tx history from network for the selected date period
         :return:
         """
-        self._logger.debug("Manually refresh tx history...")
+        self._logger.debug("Manually update tx history...")
 
-        pubkey = self.model.connection.pubkey
-
-        (
-            changed_tx,
-            new_tx,
-        ) = await self.model.transactions_service.update_transactions_history(
-            pubkey,
-            self.view.table_history.model().ts_from,
-            self.view.table_history.model().ts_to,
-        )
-        for tx in changed_tx:
-            self.model.app.transaction_state_changed.emit(tx)
+        # disable update button
+        self.view.button_refresh.setDisabled(True)
 
-        for tx in new_tx:
-            self.model.app.new_transfer.emit(self.model.connection, tx)
+        pubkey = self.model.connection.pubkey
+        try:
+            (
+                changed_tx,
+                new_tx,
+            ) = await self.model.transactions_service.update_transactions_history(
+                pubkey,
+                self.view.table_history.model().ts_from,
+                self.view.table_history.model().ts_to,
+            )
+            for tx in changed_tx:
+                self.model.app.transaction_state_changed.emit(tx)
+
+            for tx in new_tx:
+                self.model.app.new_transfer.emit(self.model.connection, tx)
+        except Exception as e:
+            self._logger.error(str(e))
+
+        try:
+            new_dividends = await self.model.transactions_service.update_dividends_history(
+                pubkey,
+                self.view.table_history.model().ts_from,
+                self.view.table_history.model().ts_to,
+                new_tx,
+            )
+            self._logger.debug("Found {} new dividends".format(len(new_dividends)))
 
-        new_dividends = await self.model.transactions_service.update_dividends_history(
-            pubkey,
-            self.view.table_history.model().ts_from,
-            self.view.table_history.model().ts_to,
-            new_tx,
-        )
-        self._logger.debug("Found {} new dividends".format(len(new_dividends)))
+            for ud in new_dividends:
+                self.model.app.new_dividend.emit(self.model.connection, ud)
+        except Exception as e:
+            self._logger.error(str(e))
 
-        for ud in new_dividends:
-            self.model.app.new_dividend.emit(self.model.connection, ud)
+        # enable update button
+        self.view.button_refresh.setDisabled(False)
+        self._logger.debug("Manually update tx history finished")
-- 
GitLab