Skip to content
Snippets Groups Projects
Commit 7f472be0 authored by inso's avatar inso
Browse files

Multiple issues fixed

- Fixed issue #55
- Fixed display of units in transactions tab
- Fixed an error when an account was not a member of a community
parent fb3fb282
No related branches found
No related tags found
No related merge requests found
...@@ -79,19 +79,23 @@ class Person(object): ...@@ -79,19 +79,23 @@ class Person(object):
raise PersonNotFoundError(self.pubkey, community.name()) raise PersonNotFoundError(self.pubkey, community.name())
def membership(self, community): def membership(self, community):
search = community.request(bma.blockchain.Membership, try:
{'search': self.pubkey}) search = community.request(bma.blockchain.Membership,
block_number = 0 {'search': self.pubkey})
for ms in search['memberships']: block_number = 0
if ms['blockNumber'] >= block_number: for ms in search['memberships']:
if 'type' in ms: if ms['blockNumber'] >= block_number:
if ms['type'] is 'IN': if 'type' in ms:
if ms['type'] is 'IN':
membership_data = ms
else:
membership_data = ms membership_data = ms
else:
membership_data = ms
if membership_data is None: if membership_data is None:
raise MembershipNotFoundError(self.pubkey(), community.name()) 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 = Membership(PROTOCOL_VERSION, community.currency, self.pubkey,
membership_data['blockNumber'], membership_data['blockNumber'],
......
...@@ -3,7 +3,7 @@ Created on 24 dec. 2014 ...@@ -3,7 +3,7 @@ Created on 24 dec. 2014
@author: inso @author: inso
''' '''
from PyQt5.QtWidgets import QDialog, QMessageBox from PyQt5.QtWidgets import QDialog, QMessageBox, QDialogButtonBox
from ..tools.exceptions import NoPeerAvailable from ..tools.exceptions import NoPeerAvailable
from ..gen_resources.certification_uic import Ui_CertificationDialog from ..gen_resources.certification_uic import Ui_CertificationDialog
...@@ -20,11 +20,11 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): ...@@ -20,11 +20,11 @@ class CertificationDialog(QDialog, Ui_CertificationDialog):
''' '''
super().__init__() super().__init__()
self.setupUi(self) self.setupUi(self)
self.certifier = certifier self.account = certifier
self.password_asker = password_asker 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) self.combo_community.addItem(community.currency)
for contact in certifier.contacts: for contact in certifier.contacts:
...@@ -33,7 +33,7 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): ...@@ -33,7 +33,7 @@ class CertificationDialog(QDialog, Ui_CertificationDialog):
def accept(self): def accept(self):
if self.radio_contact.isChecked(): if self.radio_contact.isChecked():
index = self.combo_contact.currentIndex() index = self.combo_contact.currentIndex()
pubkey = self.certifier.contacts[index].pubkey pubkey = self.account.contacts[index].pubkey
else: else:
pubkey = self.edit_pubkey.text() pubkey = self.edit_pubkey.text()
...@@ -42,7 +42,7 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): ...@@ -42,7 +42,7 @@ class CertificationDialog(QDialog, Ui_CertificationDialog):
return return
try: try:
self.certifier.certify(password, self.community, pubkey) self.account.certify(password, self.community, pubkey)
QMessageBox.information(self, "Certification", QMessageBox.information(self, "Certification",
"Success certifying {0} from {1}".format(pubkey, "Success certifying {0} from {1}".format(pubkey,
self.community.currency)) self.community.currency))
...@@ -65,7 +65,11 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): ...@@ -65,7 +65,11 @@ class CertificationDialog(QDialog, Ui_CertificationDialog):
super().accept() super().accept()
def change_current_community(self, index): 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): def recipient_mode_changed(self, pubkey_toggled):
self.edit_pubkey.setEnabled(pubkey_toggled) self.edit_pubkey.setEnabled(pubkey_toggled)
......
...@@ -21,7 +21,7 @@ from ..models.txhistory import HistoryTableModel, TxFilterProxyModel ...@@ -21,7 +21,7 @@ from ..models.txhistory import HistoryTableModel, TxFilterProxyModel
from .informations_tab import InformationsTabWidget from .informations_tab import InformationsTabWidget
from ..models.wallets import WalletsListModel from ..models.wallets import WalletsListModel
from ..models.wallet import WalletListModel from ..models.wallet import WalletListModel
from ..tools.exceptions import NoPeerAvailable from ..tools.exceptions import NoPeerAvailable, MembershipNotFoundError
from ..core.wallet import Wallet from ..core.wallet import Wallet
from ..core.person import Person from ..core.person import Person
from ..core.transfer import Transfer from ..core.transfer import Transfer
...@@ -93,23 +93,26 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): ...@@ -93,23 +93,26 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
self.watcher_thread.start() self.watcher_thread.start()
person = Person.lookup(self.app.current_account.pubkey, self.community) person = Person.lookup(self.app.current_account.pubkey, self.community)
join_block = person.membership(self.community).block_number try:
join_date = self.community.get_block(join_block).mediantime join_block = person.membership(self.community).block_number
parameters = self.community.get_parameters() join_date = self.community.get_block(join_block).mediantime
expiration_date = join_date + parameters['sigValidity'] parameters = self.community.get_parameters()
current_time = time.time() expiration_date = join_date + parameters['sigValidity']
sig_validity = self.community.get_parameters()['sigValidity'] current_time = time.time()
warning_expiration_time = int(sig_validity / 3) sig_validity = self.community.get_parameters()['sigValidity']
will_expire_soon = (current_time > expiration_date - warning_expiration_time) 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)) if will_expire_soon:
QMessageBox.warning( days = QDateTime().currentDateTime().daysTo(QDateTime.fromTime_t(expiration_date))
self, QMessageBox.warning(
"Membership expiration", self,
"Warning : Membership expiration in {0} days".format(days), "Membership expiration",
QMessageBox.Ok "Warning : Membership expiration in {0} days".format(days),
) QMessageBox.Ok
)
except MembershipNotFoundError as e:
pass
def refresh(self): def refresh(self):
if self.app.current_account is None: if self.app.current_account is None:
......
...@@ -79,14 +79,13 @@ class TxFilterProxyModel(QSortFilterProxyModel): ...@@ -79,14 +79,13 @@ class TxFilterProxyModel(QSortFilterProxyModel):
if source_data is not "": if source_data is not "":
amount_ref = self.account.units_to_diff_ref(source_data, amount_ref = self.account.units_to_diff_ref(source_data,
self.community) self.community)
ref_name = self.account.diff_ref_name(self.community.short_currency)
if type(amount_ref) is int: if type(amount_ref) is int:
formatter = "{0} {1}" formatter = "{0}"
else: else:
formatter = "{0:.2f} {1}" formatter = "{0:.2f}"
return formatter.format(amount_ref, ref_name) return formatter.format(amount_ref)
if role == Qt.FontRole: if role == Qt.FontRole:
font = QFont() font = QFont()
......
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