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):
if self.current_account is not None:
self.save_cache(self.current_account)
self.current_account = account
self.load_cache(account)
def load(self):
if (os.path.exists(config.parameters['data'])
......@@ -71,7 +70,6 @@ class Application(object):
logging.debug("Loading data...")
with open(config.parameters['data'], 'r') as json_data:
data = json.load(json_data)
json_data.close()
if 'default_account' in data.keys():
self.default_account = data['default_account']
for account_name in data['local_accounts']:
......@@ -83,6 +81,7 @@ class Application(object):
with open(account_path, 'r') as json_data:
data = json.load(json_data)
account = Account.load(data)
self.load_cache(account)
self.accounts[account_name] = account
def load_cache(self, account):
......@@ -92,7 +91,7 @@ class Application(object):
if os.path.exists(wallet_path):
with open(wallet_path, 'r') as json_data:
data = json.load(json_data)
wallet.load_caches(data)
wallet.load_caches(data)
for community in account.communities:
wallet.refresh_cache(community)
......
......@@ -49,11 +49,10 @@ class BlockchainWatcher(QObject):
except NoPeerAvailable:
return
except requests.exceptions.RequestException as e:
QMessageBox.critical(self, ":(",
str(e),
QMessageBox.Ok)
self.connection_error.emit(str(e))
new_block_mined = pyqtSignal(int)
connection_error = pyqtSignal(str)
class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
......@@ -78,6 +77,7 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
self.bc_watcher = BlockchainWatcher(self.app.current_account,
community)
self.bc_watcher.new_block_mined.connect(self.refresh_block)
self.bc_watcher.connection_error.connect(self.display_error)
self.watcher_thread = QThread()
self.bc_watcher.moveToThread(self.watcher_thread)
......@@ -107,6 +107,12 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
self.status_label.setText("Connected : Block {0}"
.format(block_number))
@pyqtSlot(str)
def display_error(self, error):
QMessageBox.critical(self, ":(",
error,
QMessageBox.Ok)
@pyqtSlot(int)
def refresh_block(self, block_number):
if self.list_wallets.model():
......
......@@ -28,6 +28,7 @@ class Loader(QObject):
self.account_name = ""
loaded = pyqtSignal()
connection_error = pyqtSignal(str)
def set_account_name(self, name):
self.account_name = name
......@@ -38,9 +39,9 @@ class Loader(QObject):
try:
self.app.change_current_account(self.app.get_account(self.account_name))
except requests.exceptions.RequestException as e:
QMessageBox.critical(self, ":(",
str(e),
QMessageBox.Ok)
self.connection_error.emit(str(e))
self.loaded.emit()
self.loaded.emit()
......@@ -75,6 +76,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.loader.moveToThread(self.loader_thread)
self.loader.loaded.connect(self.loader_finished)
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.setWindowTitle("CuteCoin {0}".format(__version__))
self.refresh()
......@@ -89,9 +91,13 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.refresh()
self.busybar.hide()
@pyqtSlot(str)
def display_error(self, error):
QMessageBox.critical(self, ":(",
error,
QMessageBox.Ok)
def action_change_account(self, account_name):
if self.app.current_account:
self.app.save_cache(self.app.current_account)
self.busybar.show()
self.status_label.setText("Loading account {0}".format(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