catch exception within sign thread, to re-enable send button
[electrum-nvc.git] / gui / qt / main_window.py
index cd288e9..f8b5336 100644 (file)
@@ -35,7 +35,7 @@ from electrum.plugins import run_hook
 
 import icons_rc
 
-from electrum.wallet import format_satoshis
+from electrum.util import format_satoshis
 from electrum import Transaction
 from electrum import mnemonic
 from electrum import util, bitcoin, commands, Interface, Wallet
@@ -134,7 +134,6 @@ class ElectrumWindow(QMainWindow):
 
         set_language(config.get('language'))
 
-        self.funds_error = False
         self.completions = QStringListModel()
 
         self.tabs = tabs = QTabWidget(self)
@@ -557,7 +556,7 @@ class ElectrumWindow(QMainWindow):
 
 
     def edit_label(self, is_recv):
-        l = self.receive_list if is_recv else self.contacts_list
+        l = self.address_list if is_recv else self.contacts_list
         item = l.currentItem()
         item.setFlags(Qt.ItemIsEditable|Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsDragEnabled)
         l.editItem( item, 1 )
@@ -862,7 +861,6 @@ class ElectrumWindow(QMainWindow):
         w.setLayout(grid)
 
         def entry_changed( is_fee ):
-            self.funds_error = False
 
             if self.amount_e.is_shortcut:
                 self.amount_e.is_shortcut = False
@@ -872,6 +870,7 @@ class ElectrumWindow(QMainWindow):
                 fee = self.wallet.estimated_fee(inputs, 1)
                 amount = total - fee
                 self.amount_e.setAmount(amount)
+                self.amount_e.textEdited.emit("")
                 self.fee_e.setAmount(fee)
                 return
 
@@ -880,6 +879,7 @@ class ElectrumWindow(QMainWindow):
 
             if not is_fee: fee = None
             if amount is None:
+                self.fee_e.setAmount(None)
                 return
             # assume that there will be 2 outputs (one for change)
             inputs, total, fee = self.wallet.choose_tx_inputs(amount, fee, 2, coins = self.get_coins())
@@ -892,7 +892,6 @@ class ElectrumWindow(QMainWindow):
             else:
                 palette = QPalette()
                 palette.setColor(self.amount_e.foregroundRole(), QColor('red'))
-                self.funds_error = True
                 text = _( "Not enough funds" )
                 c, u = self.wallet.get_frozen_balance()
                 if c+u: text += ' (' + self.format_amount(c+u).strip() + ' ' + self.base_unit() + ' ' +_("are frozen") + ')'
@@ -1022,13 +1021,15 @@ class ElectrumWindow(QMainWindow):
 
         # sign the tx
         def sign_thread():
-            time.sleep(0.1)
             keypairs = {}
-            self.wallet.add_keypairs_from_wallet(tx, keypairs, password)
-            self.wallet.sign_transaction(tx, keypairs, password)
-            return tx, fee, label
+            try:
+                self.wallet.add_keypairs(tx, keypairs, password)
+                self.wallet.sign_transaction(tx, keypairs, password)
+            except Exception as e:
+                tx.error = str(e)
+            return tx
 
-        def sign_done(tx, fee, label):
+        def sign_done(tx):
             if tx.error:
                 self.show_message(tx.error)
                 self.send_button.setDisabled(False)
@@ -1048,6 +1049,7 @@ class ElectrumWindow(QMainWindow):
 
             self.broadcast_transaction(tx)
 
+        # keep a reference to WaitingDialog or the gui might crash
         self.waiting_dialog = WaitingDialog(self, 'Signing..', sign_thread, sign_done)
         self.waiting_dialog.start()
 
@@ -1814,7 +1816,6 @@ class ElectrumWindow(QMainWindow):
     def show_qrcode(self, data, title = _("QR code")):
         if not data: 
             return
-        print_error("qrcode:", data)
         d = QRDialog(data, self, title)
         d.exec_()
 
@@ -2046,24 +2047,29 @@ class ElectrumWindow(QMainWindow):
         "json or raw hexadecimal"
         try:
             txt.decode('hex')
-            tx = Transaction(txt)
-            return tx
-        except Exception:
-            pass
+            is_hex = True
+        except:
+            is_hex = False
+
+        if is_hex:
+            try:
+                return Transaction(txt)
+            except:
+                traceback.print_exc(file=sys.stdout)
+                QMessageBox.critical(None, _("Unable to parse transaction"), _("Electrum was unable to parse your transaction"))
+                return
 
         try:
             tx_dict = json.loads(str(txt))
             assert "hex" in tx_dict.keys()
             tx = Transaction(tx_dict["hex"])
-            if tx_dict.has_key("input_info"):
-                input_info = json.loads(tx_dict['input_info'])
-                tx.add_input_info(input_info)
+            #if tx_dict.has_key("input_info"):
+            #    input_info = json.loads(tx_dict['input_info'])
+            #    tx.add_input_info(input_info)
             return tx
         except Exception:
             traceback.print_exc(file=sys.stdout)
-            pass
-
-        QMessageBox.critical(None, _("Unable to parse transaction"), _("Electrum was unable to parse your transaction"))
+            QMessageBox.critical(None, _("Unable to parse transaction"), _("Electrum was unable to parse your transaction"))
 
 
 
@@ -2081,10 +2087,11 @@ class ElectrumWindow(QMainWindow):
 
 
     @protected
-    def sign_raw_transaction(self, tx, input_info, password):
+    def sign_raw_transaction(self, tx, password):
         try:
-            self.wallet.signrawtransaction(tx, input_info, [], password)
+            self.wallet.signrawtransaction(tx, [], password)
         except Exception as e:
+            traceback.print_exc(file=sys.stdout)
             QMessageBox.warning(self, _("Error"), str(e))
 
     def do_process_from_text(self):