From 2a1e5238c85da0bd4b45c04fb7d8312505a10923 Mon Sep 17 00:00:00 2001 From: Johann Bauer Date: Sun, 28 Jan 2018 23:11:43 +0100 Subject: [PATCH] Allow user to save transaction from dialog --- gui/qt/transaction_dialog.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/gui/qt/transaction_dialog.py b/gui/qt/transaction_dialog.py index c93fee15b..6be77736c 100644 --- a/gui/qt/transaction_dialog.py +++ b/gui/qt/transaction_dialog.py @@ -35,6 +35,8 @@ from electrum.i18n import _ from electrum.plugins import run_hook from electrum.util import bfh +from electrum.wallet import UnrelatedTransactionException + from .util import * dialogs = [] # Otherwise python randomly garbage collects the dialogs... @@ -98,8 +100,13 @@ class TxDialog(QDialog, MessageBoxMixin): self.broadcast_button = b = QPushButton(_("Broadcast")) b.clicked.connect(self.do_broadcast) - self.save_button = b = QPushButton(_("Save")) - b.clicked.connect(self.save) + self.save_button = QPushButton(_("Save")) + self.save_button.setDisabled(True) + self.save_button.setToolTip(_("Please sign this transaction in order to save it")) + self.save_button.clicked.connect(self.save) + + self.export_button = b = QPushButton(_("Export")) + b.clicked.connect(self.export) self.cancel_button = b = QPushButton(_("Close")) b.clicked.connect(self.close) @@ -112,9 +119,9 @@ class TxDialog(QDialog, MessageBoxMixin): self.copy_button = CopyButton(lambda: str(self.tx), parent.app) # Action buttons - self.buttons = [self.sign_button, self.broadcast_button, self.cancel_button] + self.buttons = [self.sign_button, self.broadcast_button, self.save_button, self.cancel_button] # Transaction sharing buttons - self.sharing_buttons = [self.copy_button, self.qr_button, self.save_button] + self.sharing_buttons = [self.copy_button, self.qr_button, self.export_button] run_hook('transaction_dialog', self) @@ -155,6 +162,8 @@ class TxDialog(QDialog, MessageBoxMixin): if success: self.prompt_if_unsaved = True self.saved = False + self.save_button.setDisabled(False) + self.save_button.setToolTip("") self.update() self.main_window.pop_top_level_window(self) @@ -163,12 +172,23 @@ class TxDialog(QDialog, MessageBoxMixin): self.main_window.sign_tx(self.tx, sign_done) def save(self): + self.wallet.add_transaction(self.tx.txid(), self.tx) + self.wallet.save_transactions(write=True) + + self.main_window.history_list.update() + + self.save_button.setDisabled(True) + self.show_message(_("Transaction saved successfully")) + self.saved = True + + + def export(self): name = 'signed_%s.txn' % (self.tx.txid()[0:8]) if self.tx.is_complete() else 'unsigned.txn' fileName = self.main_window.getSaveFileName(_("Select where to save your signed transaction"), name, "*.txn") if fileName: with open(fileName, "w+") as f: f.write(json.dumps(self.tx.as_dict(), indent=4) + '\n') - self.show_message(_("Transaction saved successfully")) + self.show_message(_("Transaction exported successfully")) self.saved = True def update(self):