Skip to content
Snippets Groups Projects
Commit 6f9caa06 authored by inso's avatar inso
Browse files

Better handling of unjoinable communities

parent 019f243a
No related branches found
No related tags found
No related merge requests found
...@@ -69,9 +69,11 @@ class Account(object): ...@@ -69,9 +69,11 @@ class Account(object):
dead_communities = [] dead_communities = []
for data in json_data['communities']: for data in json_data['communities']:
try: try:
communities.append(Community.load(data)) community = Community.load(data)
communities.append(community)
except NoPeerAvailable: except NoPeerAvailable:
dead_communities.append(data['currency']) community = Community.without_network(data)
dead_communities.append(community)
account = cls(salt, pubkey, name, communities, wallets, account = cls(salt, pubkey, name, communities, wallets,
contacts, dead_communities) contacts, dead_communities)
...@@ -210,7 +212,8 @@ class Account(object): ...@@ -210,7 +212,8 @@ class Account(object):
def jsonify(self): def jsonify(self):
data_communities = [] data_communities = []
for c in self.communities: communities = self.communities + self.dead_communities
for c in communities:
data_communities.append(c.jsonify()) data_communities.append(c.jsonify())
data_wallets = [] data_wallets = []
......
...@@ -59,18 +59,16 @@ class Community(object): ...@@ -59,18 +59,16 @@ class Community(object):
self.peers = [p for p in peers if p.currency == currency] self.peers = [p for p in peers if p.currency == currency]
self._cache = Cache(self) self._cache = Cache(self)
# After initializing the community from latest peers,
# we refresh its peers tree
logging.debug("Creating community")
self.peers = self.peering()
logging.debug("{0} peers found".format(len(self.peers)))
logging.debug([peer.pubkey for peer in peers])
self._cache.refresh() self._cache.refresh()
@classmethod @classmethod
def create(cls, currency, peer): def create(cls, currency, peer):
return cls(currency, [peer]) community = cls(currency, [peer])
logging.debug("Creating community")
community.peers = community.peering()
logging.debug("{0} peers found".format(len(community.peers)))
logging.debug([peer.pubkey for peer in community.peers])
return community
@classmethod @classmethod
def load(cls, json_data): def load(cls, json_data):
...@@ -92,6 +90,28 @@ class Community(object): ...@@ -92,6 +90,28 @@ class Community(object):
except: except:
pass pass
community = cls(currency, peers)
logging.debug("Creating community")
community.peers = community.peering()
logging.debug("{0} peers found".format(len(community.peers)))
logging.debug([peer.pubkey for peer in community.peers])
return community
@classmethod
def without_network(cls, json_data):
peers = []
currency = json_data['currency']
for data in json_data['peers']:
endpoints = []
for e in data['endpoints']:
endpoints.append(Endpoint.from_inline(e))
peer = Peer(PROTOCOL_VERSION, currency, data['pubkey'],
"0-DA39A3EE5E6B4B0D3255BFEF95601890AFD80709",
endpoints, None)
peers.append(peer)
community = cls(currency, peers) community = cls(currency, peers)
return community return community
......
...@@ -172,11 +172,6 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -172,11 +172,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.action_configure_parameters.setEnabled(False) self.action_configure_parameters.setEnabled(False)
self.action_set_as_default.setEnabled(False) self.action_set_as_default.setEnabled(False)
else: else:
for dead in self.app.current_account.dead_communities:
QMessageBox.critical(self, ":(",
"No {0} peers could be joined. Connection to its network is lost.".format(dead),
QMessageBox.Ok)
self.action_set_as_default.setEnabled(self.app.current_account.name self.action_set_as_default.setEnabled(self.app.current_account.name
!= self.app.default_account) != self.app.default_account)
self.password_asker = PasswordAskerDialog(self.app.current_account) self.password_asker = PasswordAskerDialog(self.app.current_account)
......
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