Skip to content
Snippets Groups Projects
Commit 5111c4cb authored by inso's avatar inso
Browse files

Better handling of connection failures

parent ea493de2
No related branches found
No related tags found
No related merge requests found
...@@ -63,7 +63,6 @@ class Application(object): ...@@ -63,7 +63,6 @@ class Application(object):
if self.current_account is not None: if self.current_account is not None:
self.save_cache(self.current_account) self.save_cache(self.current_account)
self.current_account = account self.current_account = account
self.load_cache(account)
def load(self): def load(self):
if (os.path.exists(config.parameters['data']) if (os.path.exists(config.parameters['data'])
...@@ -71,7 +70,6 @@ class Application(object): ...@@ -71,7 +70,6 @@ class Application(object):
logging.debug("Loading data...") logging.debug("Loading data...")
with open(config.parameters['data'], 'r') as json_data: with open(config.parameters['data'], 'r') as json_data:
data = json.load(json_data) data = json.load(json_data)
json_data.close()
if 'default_account' in data.keys(): if 'default_account' in data.keys():
self.default_account = data['default_account'] self.default_account = data['default_account']
for account_name in data['local_accounts']: for account_name in data['local_accounts']:
...@@ -83,6 +81,7 @@ class Application(object): ...@@ -83,6 +81,7 @@ class Application(object):
with open(account_path, 'r') as json_data: with open(account_path, 'r') as json_data:
data = json.load(json_data) data = json.load(json_data)
account = Account.load(data) account = Account.load(data)
self.load_cache(account)
self.accounts[account_name] = account self.accounts[account_name] = account
def load_cache(self, account): def load_cache(self, account):
...@@ -92,7 +91,7 @@ class Application(object): ...@@ -92,7 +91,7 @@ class Application(object):
if os.path.exists(wallet_path): if os.path.exists(wallet_path):
with open(wallet_path, 'r') as json_data: with open(wallet_path, 'r') as json_data:
data = json.load(json_data) data = json.load(json_data)
wallet.load_caches(data) wallet.load_caches(data)
for community in account.communities: for community in account.communities:
wallet.refresh_cache(community) wallet.refresh_cache(community)
......
...@@ -49,11 +49,10 @@ class BlockchainWatcher(QObject): ...@@ -49,11 +49,10 @@ class BlockchainWatcher(QObject):
except NoPeerAvailable: except NoPeerAvailable:
return return
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
QMessageBox.critical(self, ":(", self.connection_error.emit(str(e))
str(e),
QMessageBox.Ok)
new_block_mined = pyqtSignal(int) new_block_mined = pyqtSignal(int)
connection_error = pyqtSignal(str)
class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
...@@ -78,6 +77,7 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): ...@@ -78,6 +77,7 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
self.bc_watcher = BlockchainWatcher(self.app.current_account, self.bc_watcher = BlockchainWatcher(self.app.current_account,
community) community)
self.bc_watcher.new_block_mined.connect(self.refresh_block) self.bc_watcher.new_block_mined.connect(self.refresh_block)
self.bc_watcher.connection_error.connect(self.display_error)
self.watcher_thread = QThread() self.watcher_thread = QThread()
self.bc_watcher.moveToThread(self.watcher_thread) self.bc_watcher.moveToThread(self.watcher_thread)
...@@ -107,6 +107,12 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): ...@@ -107,6 +107,12 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
self.status_label.setText("Connected : Block {0}" self.status_label.setText("Connected : Block {0}"
.format(block_number)) .format(block_number))
@pyqtSlot(str)
def display_error(self, error):
QMessageBox.critical(self, ":(",
error,
QMessageBox.Ok)
@pyqtSlot(int) @pyqtSlot(int)
def refresh_block(self, block_number): def refresh_block(self, block_number):
if self.list_wallets.model(): if self.list_wallets.model():
......
...@@ -28,6 +28,7 @@ class Loader(QObject): ...@@ -28,6 +28,7 @@ class Loader(QObject):
self.account_name = "" self.account_name = ""
loaded = pyqtSignal() loaded = pyqtSignal()
connection_error = pyqtSignal(str)
def set_account_name(self, name): def set_account_name(self, name):
self.account_name = name self.account_name = name
...@@ -38,9 +39,9 @@ class Loader(QObject): ...@@ -38,9 +39,9 @@ class Loader(QObject):
try: try:
self.app.change_current_account(self.app.get_account(self.account_name)) self.app.change_current_account(self.app.get_account(self.account_name))
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
QMessageBox.critical(self, ":(", self.connection_error.emit(str(e))
str(e), self.loaded.emit()
QMessageBox.Ok)
self.loaded.emit() self.loaded.emit()
...@@ -75,6 +76,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -75,6 +76,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.loader.moveToThread(self.loader_thread) self.loader.moveToThread(self.loader_thread)
self.loader.loaded.connect(self.loader_finished) self.loader.loaded.connect(self.loader_finished)
self.loader.loaded.connect(self.loader_thread.quit) self.loader.loaded.connect(self.loader_thread.quit)
self.loader.connection_error.connect(self.display_error)
self.loader_thread.started.connect(self.loader.load) self.loader_thread.started.connect(self.loader.load)
self.setWindowTitle("CuteCoin {0}".format(__version__)) self.setWindowTitle("CuteCoin {0}".format(__version__))
self.refresh() self.refresh()
...@@ -89,9 +91,13 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -89,9 +91,13 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.refresh() self.refresh()
self.busybar.hide() self.busybar.hide()
@pyqtSlot(str)
def display_error(self, error):
QMessageBox.critical(self, ":(",
error,
QMessageBox.Ok)
def action_change_account(self, account_name): def action_change_account(self, account_name):
if self.app.current_account:
self.app.save_cache(self.app.current_account)
self.busybar.show() self.busybar.show()
self.status_label.setText("Loading account {0}".format(account_name)) self.status_label.setText("Loading account {0}".format(account_name))
self.loader.set_account_name(account_name) self.loader.set_account_name(account_name)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment