From 8c1fe10f54a3982faf13e7503d8abdb977b993ed Mon Sep 17 00:00:00 2001 From: SomberNight Date: Thu, 23 Mar 2023 16:57:16 +0000 Subject: [PATCH] qml TxDetails: show short_id instead of block height and txpos The "TX index" (txpos) item I think was confusing. --- electrum/gui/qml/components/TxDetails.qml | 15 ++------------- electrum/gui/qml/qetxdetails.py | 20 +++++++------------- electrum/util.py | 6 ++++++ 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/electrum/gui/qml/components/TxDetails.qml b/electrum/gui/qml/components/TxDetails.qml index 68e6894e4..68000b298 100644 --- a/electrum/gui/qml/components/TxDetails.qml +++ b/electrum/gui/qml/components/TxDetails.qml @@ -207,24 +207,13 @@ Pane { Label { visible: txdetails.isMined - text: qsTr('Height') + text: qsTr('Mined at') color: Material.accentColor } Label { visible: txdetails.isMined - text: txdetails.height - } - - Label { - visible: txdetails.isMined - text: qsTr('TX index') - color: Material.accentColor - } - - Label { - visible: txdetails.isMined - text: txdetails.txpos + text: txdetails.shortId } Label { diff --git a/electrum/gui/qml/qetxdetails.py b/electrum/gui/qml/qetxdetails.py index 54e3cab05..40e8176b2 100644 --- a/electrum/gui/qml/qetxdetails.py +++ b/electrum/gui/qml/qetxdetails.py @@ -4,7 +4,7 @@ from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject from electrum.i18n import _ from electrum.logging import get_logger -from electrum.util import format_time, AddTransactionException +from electrum.util import format_time, AddTransactionException, TxMinedInfo from electrum.transaction import tx_from_any from electrum.network import Network @@ -56,10 +56,9 @@ class QETxDetails(QObject, QtEventListener): self._mempool_depth = '' self._date = '' - self._height = 0 self._confirmations = 0 - self._txpos = -1 self._header_hash = '' + self._short_id = "" def on_destroy(self): self.unregister_callbacks() @@ -166,17 +165,13 @@ class QETxDetails(QObject, QtEventListener): def date(self): return self._date - @pyqtProperty(int, notify=detailsChanged) - def height(self): - return self._height - @pyqtProperty(int, notify=detailsChanged) def confirmations(self): return self._confirmations - @pyqtProperty(int, notify=detailsChanged) - def txpos(self): - return self._txpos + @pyqtProperty(str, notify=detailsChanged) + def shortId(self): + return self._short_id @pyqtProperty(str, notify=detailsChanged) def headerHash(self): @@ -296,13 +291,12 @@ class QETxDetails(QObject, QtEventListener): self._label = txinfo.label self.labelChanged.emit() - def update_mined_status(self, tx_mined_info): + def update_mined_status(self, tx_mined_info: TxMinedInfo): self._mempool_depth = '' self._date = format_time(tx_mined_info.timestamp) - self._height = tx_mined_info.height self._confirmations = tx_mined_info.conf - self._txpos = tx_mined_info.txpos self._header_hash = tx_mined_info.header_hash + self._short_id = tx_mined_info.short_id() or "" @pyqtSlot() @pyqtSlot(bool) diff --git a/electrum/util.py b/electrum/util.py index edd0ff6c8..9ad8fbb0f 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -1299,6 +1299,12 @@ class TxMinedInfo(NamedTuple): header_hash: Optional[str] = None # hash of block that mined tx wanted_height: Optional[int] = None # in case of timelock, min abs block height + def short_id(self) -> Optional[str]: + if self.txpos is not None and self.txpos >= 0: + assert self.height > 0 + return f"{self.height}x{self.txpos}" + return None + class ShortID(bytes):