diff --git a/src/cutecoin/core/person.py b/src/cutecoin/core/person.py index 67c0419b2b46c7b602fd2b5e4fe839c1cbd886a2..7a1a14c66515434f794049062d86879cc0d72968 100644 --- a/src/cutecoin/core/person.py +++ b/src/cutecoin/core/person.py @@ -79,19 +79,23 @@ class Person(object): raise PersonNotFoundError(self.pubkey, community.name()) def membership(self, community): - search = community.request(bma.blockchain.Membership, - {'search': self.pubkey}) - block_number = 0 - for ms in search['memberships']: - if ms['blockNumber'] >= block_number: - if 'type' in ms: - if ms['type'] is 'IN': + try: + search = community.request(bma.blockchain.Membership, + {'search': self.pubkey}) + block_number = 0 + for ms in search['memberships']: + if ms['blockNumber'] >= block_number: + if 'type' in ms: + if ms['type'] is 'IN': + membership_data = ms + else: membership_data = ms - else: - membership_data = ms - if membership_data is None: - raise MembershipNotFoundError(self.pubkey(), community.name()) + if membership_data is None: + raise MembershipNotFoundError(self.pubkey, community.name()) + except ValueError as e: + if '400' in str(e): + raise MembershipNotFoundError(self.pubkey, community.name()) membership = Membership(PROTOCOL_VERSION, community.currency, self.pubkey, membership_data['blockNumber'], diff --git a/src/cutecoin/gui/certification.py b/src/cutecoin/gui/certification.py index 7ff30f863818a942f0826b150a840ad07165f399..1492c6cd4fb2ac1b8b750fbea775852753aaf113 100644 --- a/src/cutecoin/gui/certification.py +++ b/src/cutecoin/gui/certification.py @@ -3,7 +3,7 @@ Created on 24 dec. 2014 @author: inso ''' -from PyQt5.QtWidgets import QDialog, QMessageBox +from PyQt5.QtWidgets import QDialog, QMessageBox, QDialogButtonBox from ..tools.exceptions import NoPeerAvailable from ..gen_resources.certification_uic import Ui_CertificationDialog @@ -20,11 +20,11 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): ''' super().__init__() self.setupUi(self) - self.certifier = certifier + self.account = certifier self.password_asker = password_asker - self.community = self.certifier.communities[0] + self.community = self.account.communities[0] - for community in self.certifier.communities: + for community in self.account.communities: self.combo_community.addItem(community.currency) for contact in certifier.contacts: @@ -33,7 +33,7 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): def accept(self): if self.radio_contact.isChecked(): index = self.combo_contact.currentIndex() - pubkey = self.certifier.contacts[index].pubkey + pubkey = self.account.contacts[index].pubkey else: pubkey = self.edit_pubkey.text() @@ -42,7 +42,7 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): return try: - self.certifier.certify(password, self.community, pubkey) + self.account.certify(password, self.community, pubkey) QMessageBox.information(self, "Certification", "Success certifying {0} from {1}".format(pubkey, self.community.currency)) @@ -65,7 +65,11 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): super().accept() def change_current_community(self, index): - self.community = self.certifier.communities[index] + self.community = self.account.communities[index] + if self.account.pubkey in self.community.members_pubkeys(): + self.button_box.button(QDialogButtonBox.Ok).setEnabled(True) + else: + self.button_box.button(QDialogButtonBox.Ok).setEnabled(False) def recipient_mode_changed(self, pubkey_toggled): self.edit_pubkey.setEnabled(pubkey_toggled) diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index ef3e74bc950eab7b29a2163b60fe36cf00ecc7ba..8b9ffc5fef548056802b77bb21125b9ee9500f83 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -21,7 +21,7 @@ from ..models.txhistory import HistoryTableModel, TxFilterProxyModel from .informations_tab import InformationsTabWidget from ..models.wallets import WalletsListModel from ..models.wallet import WalletListModel -from ..tools.exceptions import NoPeerAvailable +from ..tools.exceptions import NoPeerAvailable, MembershipNotFoundError from ..core.wallet import Wallet from ..core.person import Person from ..core.transfer import Transfer @@ -93,23 +93,26 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.watcher_thread.start() person = Person.lookup(self.app.current_account.pubkey, self.community) - join_block = person.membership(self.community).block_number - join_date = self.community.get_block(join_block).mediantime - parameters = self.community.get_parameters() - expiration_date = join_date + parameters['sigValidity'] - current_time = time.time() - sig_validity = self.community.get_parameters()['sigValidity'] - warning_expiration_time = int(sig_validity / 3) - will_expire_soon = (current_time > expiration_date - warning_expiration_time) - - if will_expire_soon: - days = QDateTime().currentDateTime().daysTo(QDateTime.fromTime_t(expiration_date)) - QMessageBox.warning( - self, - "Membership expiration", - "Warning : Membership expiration in {0} days".format(days), - QMessageBox.Ok - ) + try: + join_block = person.membership(self.community).block_number + join_date = self.community.get_block(join_block).mediantime + parameters = self.community.get_parameters() + expiration_date = join_date + parameters['sigValidity'] + current_time = time.time() + sig_validity = self.community.get_parameters()['sigValidity'] + warning_expiration_time = int(sig_validity / 3) + will_expire_soon = (current_time > expiration_date - warning_expiration_time) + + if will_expire_soon: + days = QDateTime().currentDateTime().daysTo(QDateTime.fromTime_t(expiration_date)) + QMessageBox.warning( + self, + "Membership expiration", + "Warning : Membership expiration in {0} days".format(days), + QMessageBox.Ok + ) + except MembershipNotFoundError as e: + pass def refresh(self): if self.app.current_account is None: diff --git a/src/cutecoin/models/txhistory.py b/src/cutecoin/models/txhistory.py index e91eea080cf5c22d1639a89271a04a17a6dda27e..4e6cbb5f87c9aafd65078652d8059f7e33309460 100644 --- a/src/cutecoin/models/txhistory.py +++ b/src/cutecoin/models/txhistory.py @@ -79,14 +79,13 @@ class TxFilterProxyModel(QSortFilterProxyModel): if source_data is not "": amount_ref = self.account.units_to_diff_ref(source_data, self.community) - ref_name = self.account.diff_ref_name(self.community.short_currency) if type(amount_ref) is int: - formatter = "{0} {1}" + formatter = "{0}" else: - formatter = "{0:.2f} {1}" + formatter = "{0:.2f}" - return formatter.format(amount_ref, ref_name) + return formatter.format(amount_ref) if role == Qt.FontRole: font = QFont()