From adcace22a37ad561ed703a4885e39b02535b05b3 Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Fri, 19 Dec 2014 08:37:34 +0100 Subject: [PATCH] Errors-ready dialog --- src/cutecoin/core/wallet.py | 15 ++++++++++----- src/cutecoin/gui/transferMoneyDialog.py | 23 ++++++++++++++++++++--- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py index e94bb7a7..6c2e53f6 100644 --- a/src/cutecoin/core/wallet.py +++ b/src/cutecoin/core/wallet.py @@ -46,6 +46,14 @@ class Wallet(object): def __eq__(self, other): return (self.keyid == other.keyid) + def check_password(self, salt, password): + key = None + if self.walletid == 0: + key = SigningKey(salt, password) + else: + key = SigningKey("{0}{1}".format(salt, self.walletid), password) + return (key.pubkey == self.pubkey) + def relative_value(self, community): value = self.value(community) ud = community.dividend() @@ -106,11 +114,8 @@ class Wallet(object): logging.debug("Signature : {0}".format(str(signing.signature))) tx.signatures = [str(signing.signature, 'ascii')] logging.debug("Transaction : {0}".format(tx.signed_raw())) - try: - community.post(bma.tx.Process, - post_args={'transaction': tx.signed_raw()}) - except ValueError as e: - logging.debug("Error : {0}".format(e)) + community.post(bma.tx.Process, + post_args={'transaction': tx.signed_raw()}) def sources(self, community): data = community.request(bma.tx.Sources, req_args={'pubkey': self.pubkey}) diff --git a/src/cutecoin/gui/transferMoneyDialog.py b/src/cutecoin/gui/transferMoneyDialog.py index 7af71709..8f5c9a01 100644 --- a/src/cutecoin/gui/transferMoneyDialog.py +++ b/src/cutecoin/gui/transferMoneyDialog.py @@ -3,7 +3,7 @@ Created on 2 févr. 2014 @author: inso ''' -from PyQt5.QtWidgets import QDialog, QErrorMessage, QInputDialog, QLineEdit +from PyQt5.QtWidgets import QDialog, QErrorMessage, QInputDialog, QLineEdit, QMessageBox from cutecoin.core.person import Person @@ -50,15 +50,32 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): else: return - error = self.wallet.send_money(self.sender.salt, password, self.community, + while not self.wallet.check_password(self.sender.salt, password): + password = QInputDialog.getText(self, "Wallet password", + "Wrong password.\nPlease enter your password", + QLineEdit.Password) + if password[1] is True: + password = password[0] + else: + return + + try: + self.wallet.send_money(self.sender.salt, password, self.community, recipient, amount, message) + QMessageBox.information(self, "Money transfer", + "Success transfering {0} {1} to {2}".format(amount, + self.community.currency, + recipient)) + except ValueError as e: + QMessageBox.critical(self, "Money transfer", + "Something wrong happened : {0}".format(e), + QMessageBox.Ok) self.accepted.emit() self.close() def amount_changed(self): amount = self.spinbox_amount.value() - dividend = self.community.dividend() relative = amount / self.dividend self.spinbox_relative.blockSignals(True) self.spinbox_relative.setValue(relative) -- GitLab