Browse Source

Allow user to save transaction from dialog

3.1
Johann Bauer 7 years ago
parent
commit
2a1e5238c8
  1. 30
      gui/qt/transaction_dialog.py

30
gui/qt/transaction_dialog.py

@ -35,6 +35,8 @@ from electrum.i18n import _
from electrum.plugins import run_hook from electrum.plugins import run_hook
from electrum.util import bfh from electrum.util import bfh
from electrum.wallet import UnrelatedTransactionException
from .util import * from .util import *
dialogs = [] # Otherwise python randomly garbage collects the dialogs... dialogs = [] # Otherwise python randomly garbage collects the dialogs...
@ -98,8 +100,13 @@ class TxDialog(QDialog, MessageBoxMixin):
self.broadcast_button = b = QPushButton(_("Broadcast")) self.broadcast_button = b = QPushButton(_("Broadcast"))
b.clicked.connect(self.do_broadcast) b.clicked.connect(self.do_broadcast)
self.save_button = b = QPushButton(_("Save")) self.save_button = QPushButton(_("Save"))
b.clicked.connect(self.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")) self.cancel_button = b = QPushButton(_("Close"))
b.clicked.connect(self.close) b.clicked.connect(self.close)
@ -112,9 +119,9 @@ class TxDialog(QDialog, MessageBoxMixin):
self.copy_button = CopyButton(lambda: str(self.tx), parent.app) self.copy_button = CopyButton(lambda: str(self.tx), parent.app)
# Action buttons # 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 # 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) run_hook('transaction_dialog', self)
@ -155,6 +162,8 @@ class TxDialog(QDialog, MessageBoxMixin):
if success: if success:
self.prompt_if_unsaved = True self.prompt_if_unsaved = True
self.saved = False self.saved = False
self.save_button.setDisabled(False)
self.save_button.setToolTip("")
self.update() self.update()
self.main_window.pop_top_level_window(self) 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) self.main_window.sign_tx(self.tx, sign_done)
def save(self): 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' 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") fileName = self.main_window.getSaveFileName(_("Select where to save your signed transaction"), name, "*.txn")
if fileName: if fileName:
with open(fileName, "w+") as f: with open(fileName, "w+") as f:
f.write(json.dumps(self.tx.as_dict(), indent=4) + '\n') 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 self.saved = True
def update(self): def update(self):

Loading…
Cancel
Save