1
0

qml: apply TxInput/TxOutput coloring for swap and billing addresses.

This commit is contained in:
Sander van Grieken
2024-11-15 13:23:50 +01:00
parent 08688c3523
commit bb66b567e0
5 changed files with 44 additions and 11 deletions

View File

@@ -68,6 +68,7 @@ Item {
property color colorAddressUsedWithBalance: Qt.rgba(0.75,0.75,0.75,1) 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 colorAddressFrozen: Qt.rgba(0.5,0.5,1,1)
property color colorAddressBilling: "#8cb3f2" property color colorAddressBilling: "#8cb3f2"
property color colorAddressSwap: colorAddressBilling
function colorAlpha(baseColor, alpha) { function colorAlpha(baseColor, alpha) {
return Qt.rgba(baseColor.r, baseColor.g, baseColor.b, alpha) return Qt.rgba(baseColor.r, baseColor.g, baseColor.b, alpha)

View File

@@ -11,6 +11,12 @@ TextHighlightPane {
property variant model property variant model
property int idx: -1 property int idx: -1
property string _suffix: model.is_mine || model.is_change
? qsTr('mine')
: model.is_swap
? qsTr('swap')
: ""
ColumnLayout { ColumnLayout {
width: parent.width width: parent.width
@@ -55,16 +61,21 @@ TextHighlightPane {
Label { Label {
Layout.fillWidth: true Layout.fillWidth: true
text: model.address text: model.address
? model.address ? model.address + (_suffix
? ' <span style="font-size:' + constants.fontSizeXSmall + 'px">(' + _suffix + ')</span>'
: "")
: '&lt;' + qsTr('address unknown') + '&gt;' : '&lt;' + qsTr('address unknown') + '&gt;'
font.family: FixedFont font.family: FixedFont
font.pixelSize: constants.fontSizeMedium font.pixelSize: constants.fontSizeMedium
textFormat: Text.RichText
color: model.is_mine color: model.is_mine
? model.is_change ? model.is_change
? constants.colorAddressInternal ? constants.colorAddressInternal
: constants.colorAddressExternal : constants.colorAddressExternal
: Material.foreground : model.is_swap
elide: Text.ElideMiddle ? constants.colorAddressSwap
: Material.foreground
wrapMode: Text.WrapAnywhere
} }
} }

View File

@@ -13,6 +13,14 @@ TextHighlightPane {
property bool allowClickAddress: true property bool allowClickAddress: true
property int idx: -1 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 { RowLayout {
width: parent.width width: parent.width
@@ -57,18 +65,23 @@ TextHighlightPane {
RowLayout { RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
Label { Label {
text: model.address text: model.address + (_suffix
? ' <span style="font-size:' + constants.fontSizeXSmall + 'px">(' + _suffix + ')</span>'
: "")
Layout.fillWidth: true Layout.fillWidth: true
wrapMode: Text.Wrap wrapMode: Text.Wrap
font.pixelSize: constants.fontSizeMedium font.pixelSize: constants.fontSizeMedium
font.family: FixedFont font.family: FixedFont
textFormat: Text.RichText
color: model.is_mine color: model.is_mine
? model.is_change ? model.is_change
? constants.colorAddressInternal ? constants.colorAddressInternal
: constants.colorAddressExternal : constants.colorAddressExternal
: model.is_billing : model.is_billing
? constants.colorAddressBilling ? constants.colorAddressBilling
: Material.foreground : model.is_swap
? constants.colorAddressSwap
: Material.foreground
TapHandler { TapHandler {
enabled: allowClickAddress && model.is_mine enabled: allowClickAddress && model.is_mine
onTapped: { onTapped: {

View File

@@ -4,6 +4,7 @@ from PyQt6.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject
from electrum.i18n import _ from electrum.i18n import _
from electrum.logging import get_logger from electrum.logging import get_logger
from electrum.bitcoin import DummyAddress
from electrum.util import format_time, TxMinedInfo from electrum.util import format_time, TxMinedInfo
from electrum.transaction import tx_from_any, Transaction, PartialTxInput, Sighash, PartialTransaction, TxOutpoint from electrum.transaction import tx_from_any, Transaction, PartialTxInput, Sighash, PartialTransaction, TxOutpoint
from electrum.network import Network from electrum.network import Network
@@ -277,12 +278,15 @@ class QETxDetails(QObject, QtEventListener):
Network.run_from_another_thread( Network.run_from_another_thread(
self._tx.add_info_from_network(self._wallet.wallet.network, timeout=10)) # FIXME is this needed?... 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: { self._inputs = list(map(lambda x: {
'short_id': x.prevout.short_name(), 'short_id': x.prevout.short_name(),
'value': x.value_sats(), 'value': x.value_sats(),
'address': x.address, 'address': x.address,
'is_mine': self._wallet.wallet.is_mine(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._tx.inputs()))
self._outputs = list(map(lambda x: { self._outputs = list(map(lambda x: {
'address': x.get_ui_address_str(), 'address': x.get_ui_address_str(),
@@ -290,7 +294,8 @@ class QETxDetails(QObject, QtEventListener):
'short_id': '', # TODO 'short_id': '', # TODO
'is_mine': self._wallet.wallet.is_mine(x.get_ui_address_str()), '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_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())) }, self._tx.outputs()))
txinfo = self._wallet.wallet.get_tx_info(self._tx) txinfo = self._wallet.wallet.get_tx_info(self._tx)

View File

@@ -8,6 +8,7 @@ from PyQt6.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject
from electrum.logging import get_logger from electrum.logging import get_logger
from electrum.i18n import _ from electrum.i18n import _
from electrum.bitcoin import DummyAddress
from electrum.transaction import PartialTxOutput, PartialTransaction, Transaction, TxOutpoint from electrum.transaction import PartialTxOutput, PartialTransaction, Transaction, TxOutpoint
from electrum.util import NotEnoughFunds, profiler, quantize_feerate, UserFacingException from electrum.util import NotEnoughFunds, profiler, quantize_feerate, UserFacingException
from electrum.wallet import CannotBumpFee, CannotDoubleSpendTx, CannotCPFP, BumpFeeStrategy, sweep_preparations from electrum.wallet import CannotBumpFee, CannotDoubleSpendTx, CannotCPFP, BumpFeeStrategy, sweep_preparations
@@ -235,13 +236,11 @@ class TxFeeSlider(FeeSlider):
def update_inputs_from_tx(self, tx): def update_inputs_from_tx(self, tx):
inputs = [] inputs = []
for inp in tx.inputs(): for inp in tx.inputs():
# addr
# addr = self.wallet.adb.get_txin_address(txin) # addr = self.wallet.adb.get_txin_address(txin)
addr = inp.address addr = inp.address
address_str = '<address unknown>' if addr is None else addr address_str = '<address unknown>' if addr is None else addr
txin_value = inp.value_sats() if inp.value_sats() else 0 txin_value = inp.value_sats() if inp.value_sats() else 0
#self.wallet.adb.get_txin_value(txin)
inputs.append({ inputs.append({
'address': address_str, 'address': address_str,
@@ -250,11 +249,14 @@ class TxFeeSlider(FeeSlider):
'is_coinbase': inp.is_coinbase_input(), 'is_coinbase': inp.is_coinbase_input(),
'is_mine': self._wallet.wallet.is_mine(addr), 'is_mine': self._wallet.wallet.is_mine(addr),
'is_change': self._wallet.wallet.is_change(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 self.inputs = inputs
def update_outputs_from_tx(self, tx): def update_outputs_from_tx(self, tx):
sm = self._wallet.wallet.lnworker.swap_manager if self._wallet.wallet.lnworker else None
outputs = [] outputs = []
for idx, o in enumerate(tx.outputs()): for idx, o in enumerate(tx.outputs()):
outputs.append({ outputs.append({
@@ -263,7 +265,8 @@ class TxFeeSlider(FeeSlider):
'short_id': str(TxOutpoint(bytes.fromhex(tx.txid()), idx).short_name()) if tx.txid() else '', '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_mine': self._wallet.wallet.is_mine(o.get_ui_address_str()),
'is_change': self._wallet.wallet.is_change(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 self.outputs = outputs