From ab19ece4e08b513bee09937ab71fb976f8026615 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Mon, 8 May 2023 15:24:17 +0200 Subject: [PATCH] qml: refactor TxOutput into reusable component --- .../gui/qml/components/ConfirmTxDialog.qml | 31 ++--------- .../gui/qml/components/CpfpBumpFeeDialog.qml | 31 ++--------- .../gui/qml/components/RbfBumpFeeDialog.qml | 31 ++--------- .../gui/qml/components/RbfCancelDialog.qml | 31 ++--------- electrum/gui/qml/components/TxDetails.qml | 41 +------------- .../gui/qml/components/controls/TxOutput.qml | 54 +++++++++++++++++++ electrum/gui/qml/qetxfinalizer.py | 2 +- 7 files changed, 69 insertions(+), 152 deletions(-) create mode 100644 electrum/gui/qml/components/controls/TxOutput.qml diff --git a/electrum/gui/qml/components/ConfirmTxDialog.qml b/electrum/gui/qml/components/ConfirmTxDialog.qml index 48d1e13a0..8fd8e0075 100644 --- a/electrum/gui/qml/components/ConfirmTxDialog.qml +++ b/electrum/gui/qml/components/ConfirmTxDialog.qml @@ -182,37 +182,12 @@ ElDialog { Repeater { model: finalizer.outputs - delegate: TextHighlightPane { + delegate: TxOutput { Layout.columnSpan: 2 Layout.fillWidth: true - RowLayout { - width: parent.width - Label { - text: modelData.address - Layout.fillWidth: true - wrapMode: Text.Wrap - font.pixelSize: constants.fontSizeLarge - font.family: FixedFont - color: modelData.is_mine - ? modelData.is_change - ? constants.colorAddressInternal - : constants.colorAddressExternal - : modelData.is_billing - ? constants.colorAddressBilling - : Material.foreground - } - Label { - text: Config.formatSats(modelData.value_sats) - font.pixelSize: constants.fontSizeMedium - font.family: FixedFont - } - Label { - text: Config.baseUnit - font.pixelSize: constants.fontSizeMedium - color: Material.accentColor - } - } + allowShare: false + model: modelData } } } diff --git a/electrum/gui/qml/components/CpfpBumpFeeDialog.qml b/electrum/gui/qml/components/CpfpBumpFeeDialog.qml index 14fb8ad60..a7a8a34a0 100644 --- a/electrum/gui/qml/components/CpfpBumpFeeDialog.qml +++ b/electrum/gui/qml/components/CpfpBumpFeeDialog.qml @@ -185,37 +185,12 @@ ElDialog { Repeater { model: cpfpfeebumper.valid ? cpfpfeebumper.outputs : [] - delegate: TextHighlightPane { + delegate: TxOutput { Layout.columnSpan: 2 Layout.fillWidth: true - RowLayout { - width: parent.width - Label { - text: modelData.address - Layout.fillWidth: true - wrapMode: Text.Wrap - font.pixelSize: constants.fontSizeLarge - font.family: FixedFont - color: modelData.is_mine - ? modelData.is_change - ? constants.colorAddressInternal - : constants.colorAddressExternal - : modelData.is_billing - ? constants.colorAddressBilling - : Material.foreground - } - Label { - text: Config.formatSats(modelData.value_sats) - font.pixelSize: constants.fontSizeMedium - font.family: FixedFont - } - Label { - text: Config.baseUnit - font.pixelSize: constants.fontSizeMedium - color: Material.accentColor - } - } + allowShare: false + model: modelData } } } diff --git a/electrum/gui/qml/components/RbfBumpFeeDialog.qml b/electrum/gui/qml/components/RbfBumpFeeDialog.qml index 5939e5e36..dc0dedc3d 100644 --- a/electrum/gui/qml/components/RbfBumpFeeDialog.qml +++ b/electrum/gui/qml/components/RbfBumpFeeDialog.qml @@ -198,37 +198,12 @@ ElDialog { Repeater { model: rbffeebumper.valid ? rbffeebumper.outputs : [] - delegate: TextHighlightPane { + delegate: TxOutput { Layout.columnSpan: 2 Layout.fillWidth: true - RowLayout { - width: parent.width - Label { - text: modelData.address - Layout.fillWidth: true - wrapMode: Text.Wrap - font.pixelSize: constants.fontSizeLarge - font.family: FixedFont - color: modelData.is_mine - ? modelData.is_change - ? constants.colorAddressInternal - : constants.colorAddressExternal - : modelData.is_billing - ? constants.colorAddressBilling - : Material.foreground - } - Label { - text: Config.formatSats(modelData.value_sats) - font.pixelSize: constants.fontSizeMedium - font.family: FixedFont - } - Label { - text: Config.baseUnit - font.pixelSize: constants.fontSizeMedium - color: Material.accentColor - } - } + allowShare: false + model: modelData } } } diff --git a/electrum/gui/qml/components/RbfCancelDialog.qml b/electrum/gui/qml/components/RbfCancelDialog.qml index aa8b84227..315a36362 100644 --- a/electrum/gui/qml/components/RbfCancelDialog.qml +++ b/electrum/gui/qml/components/RbfCancelDialog.qml @@ -157,37 +157,12 @@ ElDialog { Repeater { model: txcanceller.valid ? txcanceller.outputs : [] - delegate: TextHighlightPane { + delegate: TxOutput { Layout.columnSpan: 2 Layout.fillWidth: true - RowLayout { - width: parent.width - Label { - text: modelData.address - Layout.fillWidth: true - wrapMode: Text.Wrap - font.pixelSize: constants.fontSizeLarge - font.family: FixedFont - color: modelData.is_mine - ? modelData.is_change - ? constants.colorAddressInternal - : constants.colorAddressExternal - : modelData.is_billing - ? constants.colorAddressBilling - : Material.foreground - } - Label { - text: Config.formatSats(modelData.value_sats) - font.pixelSize: constants.fontSizeMedium - font.family: FixedFont - } - Label { - text: Config.baseUnit - font.pixelSize: constants.fontSizeMedium - color: Material.accentColor - } - } + allowShare: false + model: modelData } } } diff --git a/electrum/gui/qml/components/TxDetails.qml b/electrum/gui/qml/components/TxDetails.qml index 8cc1d98fb..99409e392 100644 --- a/electrum/gui/qml/components/TxDetails.qml +++ b/electrum/gui/qml/components/TxDetails.qml @@ -272,48 +272,11 @@ Pane { Repeater { model: txdetails.outputs - delegate: TextHighlightPane { + delegate: TxOutput { Layout.columnSpan: 2 Layout.fillWidth: true - RowLayout { - width: parent.width - Label { - text: modelData.address - Layout.fillWidth: true - wrapMode: Text.Wrap - font.pixelSize: constants.fontSizeLarge - font.family: FixedFont - color: modelData.is_mine - ? modelData.is_change - ? constants.colorAddressInternal - : constants.colorAddressExternal - : modelData.is_billing - ? constants.colorAddressBilling - : Material.foreground - } - Label { - text: Config.formatSats(modelData.value) - font.pixelSize: constants.fontSizeMedium - font.family: FixedFont - } - Label { - text: Config.baseUnit - font.pixelSize: constants.fontSizeMedium - color: Material.accentColor - } - ToolButton { - icon.source: '../../icons/share.png' - icon.color: 'transparent' - onClicked: { - var dialog = app.genericShareDialog.createObject(root, { - title: qsTr('Tx Output'), - text: modelData.address - }) - dialog.open() - } - } - } + model: modelData } } } diff --git a/electrum/gui/qml/components/controls/TxOutput.qml b/electrum/gui/qml/components/controls/TxOutput.qml new file mode 100644 index 000000000..fcfd5d670 --- /dev/null +++ b/electrum/gui/qml/components/controls/TxOutput.qml @@ -0,0 +1,54 @@ +import QtQuick 2.6 +import QtQuick.Layouts 1.0 +import QtQuick.Controls 2.0 +import QtQuick.Controls.Material 2.0 + +import org.electrum 1.0 + +TextHighlightPane { + id: root + + property variant model + property bool allowShare: true + + RowLayout { + width: parent.width + Label { + text: model.address + Layout.fillWidth: true + wrapMode: Text.Wrap + font.pixelSize: constants.fontSizeLarge + font.family: FixedFont + color: model.is_mine + ? model.is_change + ? constants.colorAddressInternal + : constants.colorAddressExternal + : model.is_billing + ? constants.colorAddressBilling + : Material.foreground + } + Label { + text: Config.formatSats(model.value) + font.pixelSize: constants.fontSizeMedium + font.family: FixedFont + } + Label { + text: Config.baseUnit + font.pixelSize: constants.fontSizeMedium + color: Material.accentColor + } + ToolButton { + visible: allowShare + icon.source: Qt.resolvedUrl('../../../icons/share.png') + icon.color: 'transparent' + onClicked: { + var dialog = app.genericShareDialog.createObject(app, { + title: qsTr('Tx Output'), + text: model.address + }) + dialog.open() + } + } + } +} + diff --git a/electrum/gui/qml/qetxfinalizer.py b/electrum/gui/qml/qetxfinalizer.py index d0dba05f7..1af467533 100644 --- a/electrum/gui/qml/qetxfinalizer.py +++ b/electrum/gui/qml/qetxfinalizer.py @@ -213,7 +213,7 @@ class TxFeeSlider(FeeSlider): for o in tx.outputs(): outputs.append({ 'address': o.get_ui_address_str(), - 'value_sats': o.value, + 'value': o.value, '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())