From 21baaa4f93e7c46b5842f3efe073dcc3c791e7d1 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Fri, 15 Nov 2024 13:23:50 +0100 Subject: [PATCH] qml: apply TxInput/TxOutput coloring for swap and billing addresses. --- electrum/gui/qml/components/Constants.qml | 1 + .../gui/qml/components/controls/TxInput.qml | 17 ++++++++++--- .../gui/qml/components/controls/TxOutput.qml | 24 ++++++++++++------- electrum/gui/qml/qetxdetails.py | 9 +++++-- electrum/gui/qml/qetxfinalizer.py | 11 +++++---- 5 files changed, 45 insertions(+), 17 deletions(-) diff --git a/electrum/gui/qml/components/Constants.qml b/electrum/gui/qml/components/Constants.qml index ff88c6009547..d1d76f2fde34 100644 --- a/electrum/gui/qml/components/Constants.qml +++ b/electrum/gui/qml/components/Constants.qml @@ -68,6 +68,7 @@ Item { property color colorAddressUsedWithBalance: Qt.rgba(0.75,0.75,0.75,1) property color colorAddressFrozen: Qt.rgba(0.5,0.5,1,1) property color colorAddressBilling: "#8cb3f2" + property color colorAddressSwap: colorAddressBilling function colorAlpha(baseColor, alpha) { return Qt.rgba(baseColor.r, baseColor.g, baseColor.b, alpha) diff --git a/electrum/gui/qml/components/controls/TxInput.qml b/electrum/gui/qml/components/controls/TxInput.qml index 2ce1176ad736..7d53668e9c78 100644 --- a/electrum/gui/qml/components/controls/TxInput.qml +++ b/electrum/gui/qml/components/controls/TxInput.qml @@ -11,6 +11,12 @@ TextHighlightPane { property variant model property int idx: -1 + property string _suffix: model.is_mine || model.is_change + ? qsTr('mine') + : model.is_swap + ? qsTr('swap') + : "" + ColumnLayout { width: parent.width @@ -55,16 +61,21 @@ TextHighlightPane { Label { Layout.fillWidth: true text: model.address - ? model.address + ? model.address + (_suffix + ? ' (' + _suffix + ')' + : "") : '<' + qsTr('address unknown') + '>' font.family: FixedFont font.pixelSize: constants.fontSizeMedium + textFormat: Text.RichText color: model.is_mine ? model.is_change ? constants.colorAddressInternal : constants.colorAddressExternal - : Material.foreground - elide: Text.ElideMiddle + : model.is_swap + ? constants.colorAddressSwap + : Material.foreground + wrapMode: Text.WrapAnywhere } } diff --git a/electrum/gui/qml/components/controls/TxOutput.qml b/electrum/gui/qml/components/controls/TxOutput.qml index e603c5004686..1bbd4712762b 100644 --- a/electrum/gui/qml/components/controls/TxOutput.qml +++ b/electrum/gui/qml/components/controls/TxOutput.qml @@ -13,6 +13,14 @@ TextHighlightPane { property bool allowClickAddress: true property int idx: -1 + property string _suffix: model.is_mine || model.is_change + ? qsTr('mine') + : model.is_swap + ? qsTr('swap') + : model.is_billing + ? qsTr('billing') + : "" + RowLayout { width: parent.width @@ -23,18 +31,13 @@ TextHighlightPane { Layout.fillWidth: true Label { - Layout.rightMargin: constants.paddingLarge + Layout.fillWidth: true text: '#' + idx visible: idx >= 0 font.family: FixedFont font.pixelSize: constants.fontSizeMedium font.bold: true } - Label { - Layout.fillWidth: true - font.family: FixedFont - text: model.short_id - } Label { text: Config.formatSats(model.value) font.pixelSize: constants.fontSizeMedium @@ -57,18 +60,23 @@ TextHighlightPane { RowLayout { Layout.fillWidth: true Label { - text: model.address + text: model.address + (_suffix + ? ' (' + _suffix + ')' + : "") Layout.fillWidth: true wrapMode: Text.Wrap font.pixelSize: constants.fontSizeMedium font.family: FixedFont + textFormat: Text.RichText color: model.is_mine ? model.is_change ? constants.colorAddressInternal : constants.colorAddressExternal : model.is_billing ? constants.colorAddressBilling - : Material.foreground + : model.is_swap + ? constants.colorAddressSwap + : Material.foreground TapHandler { enabled: allowClickAddress && model.is_mine onTapped: { diff --git a/electrum/gui/qml/qetxdetails.py b/electrum/gui/qml/qetxdetails.py index d6a894063254..c36e7aeea3b2 100644 --- a/electrum/gui/qml/qetxdetails.py +++ b/electrum/gui/qml/qetxdetails.py @@ -4,6 +4,7 @@ from electrum.i18n import _ from electrum.logging import get_logger +from electrum.bitcoin import DummyAddress from electrum.util import format_time, TxMinedInfo from electrum.transaction import tx_from_any, Transaction, PartialTxInput, Sighash, PartialTransaction, TxOutpoint from electrum.network import Network @@ -277,12 +278,15 @@ def update(self, from_txid: bool = False): Network.run_from_another_thread( self._tx.add_info_from_network(self._wallet.wallet.network, timeout=10)) # FIXME is this needed?... + sm = self._wallet.wallet.lnworker.swap_manager if self._wallet.wallet.lnworker else None + self._inputs = list(map(lambda x: { 'short_id': x.prevout.short_name(), 'value': x.value_sats(), 'address': x.address, 'is_mine': self._wallet.wallet.is_mine(x.address), - 'is_change': self._wallet.wallet.is_change(x.address) + 'is_change': self._wallet.wallet.is_change(x.address), + 'is_swap': False if not sm else sm.is_lockup_address_for_a_swap(x.address) or x.address == DummyAddress.SWAP }, self._tx.inputs())) self._outputs = list(map(lambda x: { 'address': x.get_ui_address_str(), @@ -290,7 +294,8 @@ def update(self, from_txid: bool = False): 'short_id': '', # TODO 'is_mine': self._wallet.wallet.is_mine(x.get_ui_address_str()), 'is_change': self._wallet.wallet.is_change(x.get_ui_address_str()), - 'is_billing': self._wallet.wallet.is_billing_address(x.get_ui_address_str()) + 'is_billing': self._wallet.wallet.is_billing_address(x.get_ui_address_str()), + 'is_swap': False if not sm else sm.is_lockup_address_for_a_swap(x.get_ui_address_str()) or x.get_ui_address_str() == DummyAddress.SWAP }, self._tx.outputs())) txinfo = self._wallet.wallet.get_tx_info(self._tx) diff --git a/electrum/gui/qml/qetxfinalizer.py b/electrum/gui/qml/qetxfinalizer.py index f1c4bb6d84ca..b3ff2491c024 100644 --- a/electrum/gui/qml/qetxfinalizer.py +++ b/electrum/gui/qml/qetxfinalizer.py @@ -8,6 +8,7 @@ from electrum.logging import get_logger from electrum.i18n import _ +from electrum.bitcoin import DummyAddress from electrum.transaction import PartialTxOutput, PartialTransaction, Transaction, TxOutpoint from electrum.util import NotEnoughFunds, profiler, quantize_feerate, UserFacingException from electrum.wallet import CannotBumpFee, CannotDoubleSpendTx, CannotCPFP, BumpFeeStrategy, sweep_preparations @@ -235,13 +236,11 @@ def update_from_tx(self, tx): def update_inputs_from_tx(self, tx): inputs = [] for inp in tx.inputs(): - # addr # addr = self.wallet.adb.get_txin_address(txin) addr = inp.address address_str = '
' if addr is None else addr txin_value = inp.value_sats() if inp.value_sats() else 0 - #self.wallet.adb.get_txin_value(txin) inputs.append({ 'address': address_str, @@ -250,11 +249,14 @@ def update_inputs_from_tx(self, tx): 'is_coinbase': inp.is_coinbase_input(), 'is_mine': self._wallet.wallet.is_mine(addr), 'is_change': self._wallet.wallet.is_change(addr), - 'prevout_txid': inp.prevout.txid.hex() + 'prevout_txid': inp.prevout.txid.hex(), + 'is_swap': False }) self.inputs = inputs def update_outputs_from_tx(self, tx): + sm = self._wallet.wallet.lnworker.swap_manager if self._wallet.wallet.lnworker else None + outputs = [] for idx, o in enumerate(tx.outputs()): outputs.append({ @@ -263,7 +265,8 @@ def update_outputs_from_tx(self, tx): 'short_id': str(TxOutpoint(bytes.fromhex(tx.txid()), idx).short_name()) if tx.txid() else '', 'is_mine': self._wallet.wallet.is_mine(o.get_ui_address_str()), 'is_change': self._wallet.wallet.is_change(o.get_ui_address_str()), - 'is_billing': self._wallet.wallet.is_billing_address(o.get_ui_address_str()) + 'is_billing': self._wallet.wallet.is_billing_address(o.get_ui_address_str()), + 'is_swap': False if not sm else sm.is_lockup_address_for_a_swap(o.get_ui_address_str()) or o.get_ui_address_str() == DummyAddress.SWAP }) self.outputs = outputs