From df44a5c3612d2ff13226be3ee91af3159d95fabd Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Fri, 31 Mar 2023 10:49:36 +0200 Subject: [PATCH] qml: port over 'show_qr to warn if QR code is missing data' --- electrum/gui/qml/components/ExportTxDialog.qml | 12 ++++++++++++ electrum/gui/qml/components/TxDetails.qml | 9 +++++---- electrum/gui/qml/components/WalletMainView.qml | 13 ++++++++----- electrum/gui/qml/qetxdetails.py | 12 ++++-------- electrum/gui/qml/qewallet.py | 11 ++++------- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/electrum/gui/qml/components/ExportTxDialog.qml b/electrum/gui/qml/components/ExportTxDialog.qml index 8a555727f..63c362e92 100644 --- a/electrum/gui/qml/components/ExportTxDialog.qml +++ b/electrum/gui/qml/components/ExportTxDialog.qml @@ -12,6 +12,7 @@ ElDialog { property string text_qr // if text_qr is undefined text will be used property string text_help + property string text_warn title: qsTr('Share Transaction') @@ -55,6 +56,17 @@ ElDialog { visible: dialog.text_help text: dialog.text_help } + + InfoTextArea { + Layout.fillWidth: true + Layout.margins: constants.paddingLarge + Layout.topMargin: dialog.text_help + ? 0 + : constants.paddingLarge + visible: dialog.text_warn + text: dialog.text_warn + iconStyle: InfoTextArea.IconStyle.Warn + } } } diff --git a/electrum/gui/qml/components/TxDetails.qml b/electrum/gui/qml/components/TxDetails.qml index 8f61e901a..3e050f24c 100644 --- a/electrum/gui/qml/components/TxDetails.qml +++ b/electrum/gui/qml/components/TxDetails.qml @@ -374,9 +374,10 @@ Pane { onClicked: { var msg = '' if (txdetails.isComplete) { - // TODO: iff offline wallet? - // TODO: or also if just temporarily offline? - msg = qsTr('This transaction is complete. Please share it with an online device') + if (!txdetails.isMined && !txdetails.mempoolDepth) // local + // TODO: iff offline wallet? + // TODO: or also if just temporarily offline? + msg = qsTr('This transaction is complete. Please share it with an online device') } else if (txdetails.wallet.isWatchOnly) { msg = qsTr('This transaction should be signed. Present this QR code to the signing device') } else if (txdetails.wallet.isMultisig && txdetails.wallet.walletType != '2fa') { @@ -387,7 +388,7 @@ Pane { } } - app.stack.getRoot().showExport(txdetails.getSerializedTx(false), txdetails.getSerializedTx(true), msg) + app.stack.getRoot().showExport(txdetails.getSerializedTx(), msg) } } diff --git a/electrum/gui/qml/components/WalletMainView.qml b/electrum/gui/qml/components/WalletMainView.qml index 147056ca0..34c487b14 100644 --- a/electrum/gui/qml/components/WalletMainView.qml +++ b/electrum/gui/qml/components/WalletMainView.qml @@ -51,14 +51,17 @@ Item { } function showExportByTxid(txid, helptext) { - showExport(Daemon.currentWallet.getSerializedTx(txid, false), Daemon.currentWallet.getSerializedTx(txid, true), helptext) + showExport(Daemon.currentWallet.getSerializedTx(txid), helptext) } - function showExport(data, data_qr, helptext) { + function showExport(data, helptext) { var dialog = exportTxDialog.createObject(app, { - text: data, - text_qr: data_qr, - text_help: helptext + text: data[0], + text_qr: data[1], + text_help: helptext, + text_warn: data[2] + ? '' + : qsTr('Warning: Some data (prev txs / "full utxos") was left out of the QR code as it would not fit. This might cause issues if signing offline. As a workaround, try exporting the tx as file or text instead.') }) dialog.open() } diff --git a/electrum/gui/qml/qetxdetails.py b/electrum/gui/qml/qetxdetails.py index 69587c63d..44bfca552 100644 --- a/electrum/gui/qml/qetxdetails.py +++ b/electrum/gui/qml/qetxdetails.py @@ -391,11 +391,7 @@ class QETxDetails(QObject, QtEventListener): self._can_remove = True self.detailsChanged.emit() - @pyqtSlot(result=str) - @pyqtSlot(bool, result=str) - def getSerializedTx(self, for_qr=False): - tx = self._tx - if for_qr: - return tx.to_qr_data()[0] - else: - return str(tx) + @pyqtSlot(result='QVariantList') + def getSerializedTx(self): + txqr = self._tx.to_qr_data() + return [str(self._tx), txqr[0], txqr[1]] diff --git a/electrum/gui/qml/qewallet.py b/electrum/gui/qml/qewallet.py index c314a6974..466eec50f 100644 --- a/electrum/gui/qml/qewallet.py +++ b/electrum/gui/qml/qewallet.py @@ -728,11 +728,8 @@ class QEWallet(AuthMixin, QObject, QtEventListener): self.dataChanged.emit() - @pyqtSlot(str, result=str) - @pyqtSlot(str, bool, result=str) - def getSerializedTx(self, txid, for_qr=False): + @pyqtSlot(str, result='QVariantList') + def getSerializedTx(self, txid): tx = self.wallet.db.get_transaction(txid) - if for_qr: - return tx.to_qr_data()[0] - else: - return str(tx) + txqr = tx.to_qr_data() + return [str(tx), txqr[0], txqr[1]]