From 83a04516126645c1f68240a98ff6c065353b304f Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Tue, 20 Jan 2015 19:28:45 +0100
Subject: [PATCH] Multiple bug fixes with new accounts

---
 src/cutecoin/core/account.py            | 15 +++++++++++----
 src/cutecoin/core/community.py          |  5 ++---
 src/cutecoin/core/wallet.py             |  4 +++-
 src/cutecoin/gui/community_tab.py       |  2 +-
 src/cutecoin/gui/process_cfg_account.py |  2 +-
 src/cutecoin/gui/transfer.py            | 17 ++++++++++++++---
 6 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py
index eb6ae822..25d89b89 100644
--- a/src/cutecoin/core/account.py
+++ b/src/cutecoin/core/account.py
@@ -113,12 +113,18 @@ class Account(object):
 
     def certify(self, password, community, pubkey):
         certified = Person.lookup(pubkey, community)
-        block = community.get_block()
-        block_hash = hashlib.sha1(block.signed_raw().encode("ascii")).hexdigest().upper()
+
+        try:
+            block = community.get_block()
+            block_number = block.number
+            block_hash = hashlib.sha1(block.signed_raw().encode("ascii")).hexdigest().upper()
+        except ValueError as e:
+            block_number = 0
+            block_hash = "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709"
 
         certification = Certification(PROTOCOL_VERSION, community.currency,
                                       self.pubkey, certified.pubkey,
-                                      block_hash, block.number, None)
+                                      block_hash, block_number, None)
 
         selfcert = certified.selfcert(community)
         logging.debug("SelfCertification : {0}".format(selfcert.raw()))
@@ -202,10 +208,11 @@ class Account(object):
         try:
             block = community.get_block()
             block_hash = hashlib.sha1(block.signed_raw().encode("ascii")).hexdigest().upper()
-            block_number = block['number']
+            block_number = block.number
         except ValueError as e:
             block_number = 0
             block_hash = "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709"
+
         membership = Membership(PROTOCOL_VERSION, community.currency,
                           selfcert.pubkey, block_number,
                           block_hash, type, selfcert.uid,
diff --git a/src/cutecoin/core/community.py b/src/cutecoin/core/community.py
index 7f38061c..b1fce9fd 100644
--- a/src/cutecoin/core/community.py
+++ b/src/cutecoin/core/community.py
@@ -126,12 +126,11 @@ class Community(object):
     def request(self, request, req_args={}, get_args={}, cached=True):
         for peer in self.peers:
             e = next(e for e in peer.endpoints if type(e) is BMAEndpoint)
-            if cached:
+            self.check_current_block(e)
+            if cached and self.last_block["number"] != 0:
                 try:
                     # We request the current block every five minutes
                     # If a new block is mined we reset the cache
-
-                    self.check_current_block(e)
                     cache_key = (hash(request),
                                  hash(tuple(frozenset(sorted(req_args.keys())))),
                                  hash(tuple(frozenset(sorted(req_args.items())))),
diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py
index 27afe437..3c48bf67 100644
--- a/src/cutecoin/core/wallet.py
+++ b/src/cutecoin/core/wallet.py
@@ -167,8 +167,10 @@ class Wallet(object):
             self.caches[currency].load_from_json(json_data[currency])
 
     def jsonify_caches(self):
+        data = {}
         for currency in self.caches:
-            return {currency: self.caches[currency].jsonify()}
+            data[currency] = self.caches[currency].jsonify()
+        return data
 
     def refresh_cache(self, community):
         if community.currency not in self.caches:
diff --git a/src/cutecoin/gui/community_tab.py b/src/cutecoin/gui/community_tab.py
index 09ebb8ad..153d0584 100644
--- a/src/cutecoin/gui/community_tab.py
+++ b/src/cutecoin/gui/community_tab.py
@@ -104,7 +104,7 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget):
             self.account.send_membership(password, self.community, 'IN')
         except ValueError as e:
             QMessageBox.critical(self, "Join demand error",
-                              e.message)
+                              str(e))
         except PersonNotFoundError as e:
             QMessageBox.critical(self, "Key not sent to community",
                               "Your key wasn't sent in the community. \
diff --git a/src/cutecoin/gui/process_cfg_account.py b/src/cutecoin/gui/process_cfg_account.py
index e5b02108..8843f1c8 100644
--- a/src/cutecoin/gui/process_cfg_account.py
+++ b/src/cutecoin/gui/process_cfg_account.py
@@ -200,7 +200,7 @@ class ProcessConfigureAccount(QDialog, Ui_AccountConfigurationDialog):
 
     def open_process_edit_community(self, index):
         community = self.account.communities[index.row()]
-        dialog = ProcessConfigureCommunity(self.account, community)
+        dialog = ProcessConfigureCommunity(self.account, community, self.password_asker)
         dialog.accepted.connect(self.action_edit_community)
         dialog.exec_()
 
diff --git a/src/cutecoin/gui/transfer.py b/src/cutecoin/gui/transfer.py
index 9e249701..c903e5ed 100644
--- a/src/cutecoin/gui/transfer.py
+++ b/src/cutecoin/gui/transfer.py
@@ -3,7 +3,7 @@ Created on 2 févr. 2014
 
 @author: inso
 '''
-from PyQt5.QtWidgets import QDialog, QErrorMessage, QInputDialog, QLineEdit, QMessageBox
+from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QMessageBox
 
 from ..tools.exceptions import NotEnoughMoneyError
 from ..core.person import Person
@@ -41,6 +41,11 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
         for contact in sender.contacts:
             self.combo_contact.addItem(contact.name)
 
+        if len(self.sender.contacts) == 0:
+            self.combo_contact.setEnabled(False)
+            self.radio_contact.setEnabled(False)
+            self.radio_pubkey.setChecked(True)
+
     def accept(self):
         comment = self.edit_message.text()
 
@@ -94,13 +99,19 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
         self.label_total.setText(self.wallet.get_text(self.community))
         self.spinbox_amount.setSuffix(" " + self.community.currency)
         self.spinbox_amount.setValue(0)
-        self.spinbox_amount.setMaximum(self.wallet.value(self.community))
+        amount = self.wallet.value(self.community)
+        relative = amount / self.dividend
+        self.spinbox_amount.setMaximum(amount)
+        self.spinbox_relative.setMaximum(relative)
 
     def change_displayed_wallet(self, index):
         self.wallet = self.sender.wallets[index]
         self.label_total.setText(self.wallet.get_text(self.community))
         self.spinbox_amount.setValue(0)
-        self.spinbox_amount.setMaximum(self.wallet.value(self.community))
+        amount = self.wallet.value(self.community)
+        relative = amount / self.dividend
+        self.spinbox_amount.setMaximum(amount)
+        self.spinbox_relative.setMaximum(relative)
 
     def recipient_mode_changed(self, pubkey_toggled):
         self.edit_pubkey.setEnabled(pubkey_toggled)
-- 
GitLab