Skip to content

Commit

Permalink
qml: apply TxInput/TxOutput coloring for swap and billing addresses.
Browse files Browse the repository at this point in the history
  • Loading branch information
accumulator committed Jan 21, 2025
1 parent 08688c3 commit 21baaa4
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
1 change: 1 addition & 0 deletions electrum/gui/qml/components/Constants.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 14 additions & 3 deletions electrum/gui/qml/components/controls/TxInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -55,16 +61,21 @@ TextHighlightPane {
Label {
Layout.fillWidth: true
text: model.address
? model.address
? model.address + (_suffix
? ' <span style="font-size:' + constants.fontSizeXSmall + 'px">(' + _suffix + ')</span>'
: "")
: '&lt;' + qsTr('address unknown') + '&gt;'
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
}
}

Expand Down
24 changes: 16 additions & 8 deletions electrum/gui/qml/components/controls/TxOutput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -57,18 +60,23 @@ TextHighlightPane {
RowLayout {
Layout.fillWidth: true
Label {
text: model.address
text: model.address + (_suffix
? ' <span style="font-size:' + constants.fontSizeXSmall + 'px">(' + _suffix + ')</span>'
: "")
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: {
Expand Down
9 changes: 7 additions & 2 deletions electrum/gui/qml/qetxdetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -277,20 +278,24 @@ 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(),
'value': QEAmount(amount_sat=x.value),
'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)
Expand Down
11 changes: 7 additions & 4 deletions electrum/gui/qml/qetxfinalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = '<address unknown>' 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,
Expand All @@ -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({
Expand All @@ -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

Expand Down

0 comments on commit 21baaa4

Please sign in to comment.