From f82136d07c3f584da987c1029fc27135fdfb7911 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Mon, 16 Jan 2023 13:49:32 +0100 Subject: [PATCH] qml: refactor most amount values to FormattedAmount, use fixed font more consistently --- .../gui/qml/components/AddressDetails.qml | 16 +----- .../gui/qml/components/ChannelDetails.qml | 50 +++--------------- electrum/gui/qml/components/Channels.qml | 33 ++---------- .../gui/qml/components/ConfirmTxDialog.qml | 25 ++------- .../gui/qml/components/CpfpBumpFeeDialog.qml | 52 +++++-------------- .../gui/qml/components/RbfCancelDialog.qml | 28 +++------- electrum/gui/qml/components/ReceiveDialog.qml | 19 +------ 7 files changed, 40 insertions(+), 183 deletions(-) diff --git a/electrum/gui/qml/components/AddressDetails.qml b/electrum/gui/qml/components/AddressDetails.qml index 0ffc17bee..a1abc2ff3 100644 --- a/electrum/gui/qml/components/AddressDetails.qml +++ b/electrum/gui/qml/components/AddressDetails.qml @@ -184,20 +184,8 @@ Pane { color: Material.accentColor } - RowLayout { - Label { - font.family: FixedFont - text: Config.formatSats(addressdetails.balance) - } - Label { - color: Material.accentColor - text: Config.baseUnit - } - Label { - text: Daemon.fx.enabled - ? '(' + Daemon.fx.fiatValue(addressdetails.balance) + ' ' + Daemon.fx.fiatCurrency + ')' - : '' - } + FormattedAmount { + amount: addressdetails.balance } Label { diff --git a/electrum/gui/qml/components/ChannelDetails.qml b/electrum/gui/qml/components/ChannelDetails.qml index 88a6a1df5..cc609bc41 100644 --- a/electrum/gui/qml/components/ChannelDetails.qml +++ b/electrum/gui/qml/components/ChannelDetails.qml @@ -93,20 +93,8 @@ Pane { color: Material.accentColor } - RowLayout { - Label { - font.family: FixedFont - text: Config.formatSats(channeldetails.capacity) - } - Label { - color: Material.accentColor - text: Config.baseUnit - } - Label { - text: Daemon.fx.enabled - ? '(' + Daemon.fx.fiatValue(channeldetails.capacity) + ' ' + Daemon.fx.fiatCurrency + ')' - : '' - } + FormattedAmount { + amount: channeldetails.capacity } Label { @@ -114,22 +102,11 @@ Pane { color: Material.accentColor } - RowLayout { + FormattedAmount { visible: !channeldetails.frozenForSending && channeldetails.isOpen - Label { - font.family: FixedFont - text: Config.formatSats(channeldetails.canSend) - } - Label { - color: Material.accentColor - text: Config.baseUnit - } - Label { - text: Daemon.fx.enabled - ? '(' + Daemon.fx.fiatValue(channeldetails.canSend) + ' ' + Daemon.fx.fiatCurrency + ')' - : '' - } + amount: channeldetails.canSend } + Label { visible: channeldetails.frozenForSending && channeldetails.isOpen text: qsTr('n/a (frozen)') @@ -144,22 +121,11 @@ Pane { color: Material.accentColor } - RowLayout { + FormattedAmount { visible: !channeldetails.frozenForReceiving && channeldetails.isOpen - Label { - font.family: FixedFont - text: Config.formatSats(channeldetails.canReceive) - } - Label { - color: Material.accentColor - text: Config.baseUnit - } - Label { - text: Daemon.fx.enabled - ? '(' + Daemon.fx.fiatValue(channeldetails.canReceive) + ' ' + Daemon.fx.fiatCurrency + ')' - : '' - } + amount: channeldetails.canReceive } + Label { visible: channeldetails.frozenForReceiving && channeldetails.isOpen text: qsTr('n/a (frozen)') diff --git a/electrum/gui/qml/components/Channels.qml b/electrum/gui/qml/components/Channels.qml index 5f8dcee39..59f24a503 100644 --- a/electrum/gui/qml/components/Channels.qml +++ b/electrum/gui/qml/components/Channels.qml @@ -51,20 +51,8 @@ Pane { color: Material.accentColor } - RowLayout { - Layout.fillWidth: true - Label { - text: Config.formatSats(Daemon.currentWallet.lightningCanSend) - } - Label { - text: Config.baseUnit - color: Material.accentColor - } - Label { - text: Daemon.fx.enabled - ? '(' + Daemon.fx.fiatValue(Daemon.currentWallet.lightningCanSend) + ' ' + Daemon.fx.fiatCurrency + ')' - : '' - } + FormattedAmount { + amount: Daemon.currentWallet.lightningCanSend } Label { @@ -72,22 +60,9 @@ Pane { color: Material.accentColor } - RowLayout { - Layout.fillWidth: true - Label { - text: Config.formatSats(Daemon.currentWallet.lightningCanReceive) - } - Label { - text: Config.baseUnit - color: Material.accentColor - } - Label { - text: Daemon.fx.enabled - ? '(' + Daemon.fx.fiatValue(Daemon.currentWallet.lightningCanReceive) + ' ' + Daemon.fx.fiatCurrency + ')' - : '' - } + FormattedAmount { + amount: Daemon.currentWallet.lightningCanReceive } - } Frame { diff --git a/electrum/gui/qml/components/ConfirmTxDialog.qml b/electrum/gui/qml/components/ConfirmTxDialog.qml index 46c9cef24..2beab78a0 100644 --- a/electrum/gui/qml/components/ConfirmTxDialog.qml +++ b/electrum/gui/qml/components/ConfirmTxDialog.qml @@ -61,7 +61,6 @@ ElDialog { text: qsTr('Amount to send') color: Material.accentColor } - RowLayout { Layout.fillWidth: true Label { @@ -94,16 +93,8 @@ ElDialog { color: Material.accentColor } - RowLayout { - Label { - id: fee - text: Config.formatSats(finalizer.fee) - } - - Label { - text: Config.baseUnit - color: Material.accentColor - } + FormattedAmount { + amount: finalizer.fee } Label { @@ -112,16 +103,9 @@ ElDialog { color: Material.accentColor } - RowLayout { + FormattedAmount { visible: !finalizer.extraFee.isEmpty - Label { - text: Config.formatSats(finalizer.extraFee) - } - - Label { - text: Config.baseUnit - color: Material.accentColor - } + amount: finalizer.extraFee } Label { @@ -133,6 +117,7 @@ ElDialog { Label { id: feeRate text: finalizer.feeRate + font.family: FixedFont } Label { diff --git a/electrum/gui/qml/components/CpfpBumpFeeDialog.qml b/electrum/gui/qml/components/CpfpBumpFeeDialog.qml index 15b055e37..310c443dd 100644 --- a/electrum/gui/qml/components/CpfpBumpFeeDialog.qml +++ b/electrum/gui/qml/components/CpfpBumpFeeDialog.qml @@ -72,15 +72,8 @@ ElDialog { color: Material.accentColor } - RowLayout { - Label { - text: Config.formatSats(cpfpfeebumper.inputAmount) - } - - Label { - text: Config.baseUnit - color: Material.accentColor - } + FormattedAmount { + amount: cpfpfeebumper.inputAmount } Label { @@ -88,16 +81,9 @@ ElDialog { color: Material.accentColor } - RowLayout { - Label { - text: cpfpfeebumper.valid ? Config.formatSats(cpfpfeebumper.outputAmount) : '' - } - - Label { - visible: cpfpfeebumper.valid - text: Config.baseUnit - color: Material.accentColor - } + FormattedAmount { + amount: cpfpfeebumper.outputAmount + valid: cpfpfeebumper.valid } Slider { @@ -143,17 +129,9 @@ ElDialog { color: Material.accentColor } - RowLayout { - Label { - id: fee - text: cpfpfeebumper.valid ? Config.formatSats(cpfpfeebumper.feeForChild) : '' - } - - Label { - visible: cpfpfeebumper.valid - text: Config.baseUnit - color: Material.accentColor - } + FormattedAmount { + amount: cpfpfeebumper.feeForChild + valid: cpfpfeebumper.valid } Label { @@ -161,16 +139,9 @@ ElDialog { color: Material.accentColor } - RowLayout { - Label { - text: cpfpfeebumper.valid ? Config.formatSats(cpfpfeebumper.totalFee) : '' - } - - Label { - visible: cpfpfeebumper.valid - text: Config.baseUnit - color: Material.accentColor - } + FormattedAmount { + amount: cpfpfeebumper.totalFee + valid: cpfpfeebumper.valid } Label { @@ -181,6 +152,7 @@ ElDialog { RowLayout { Label { text: cpfpfeebumper.valid ? cpfpfeebumper.totalFeeRate : '' + font.family: FixedFont } Label { diff --git a/electrum/gui/qml/components/RbfCancelDialog.qml b/electrum/gui/qml/components/RbfCancelDialog.qml index 5e59fc736..f8d5598ec 100644 --- a/electrum/gui/qml/components/RbfCancelDialog.qml +++ b/electrum/gui/qml/components/RbfCancelDialog.qml @@ -51,16 +51,8 @@ ElDialog { color: Material.accentColor } - RowLayout { - Label { - id: oldfee - text: Config.formatSats(txcanceller.oldfee) - } - - Label { - text: Config.baseUnit - color: Material.accentColor - } + FormattedAmount { + amount: txcanceller.oldfee } Label { @@ -72,6 +64,7 @@ ElDialog { Label { id: oldfeeRate text: txcanceller.oldfeeRate + font.family: FixedFont } Label { @@ -85,17 +78,9 @@ ElDialog { color: Material.accentColor } - RowLayout { - Label { - id: fee - text: txcanceller.valid ? Config.formatSats(txcanceller.fee) : '' - } - - Label { - visible: txcanceller.valid - text: Config.baseUnit - color: Material.accentColor - } + FormattedAmount { + amount: txcanceller.fee + valid: txcanceller.valid } Label { @@ -107,6 +92,7 @@ ElDialog { Label { id: feeRate text: txcanceller.valid ? txcanceller.feeRate : '' + font.family: FixedFont } Label { diff --git a/electrum/gui/qml/components/ReceiveDialog.qml b/electrum/gui/qml/components/ReceiveDialog.qml index e957100c0..a24daa57a 100644 --- a/electrum/gui/qml/components/ReceiveDialog.qml +++ b/electrum/gui/qml/components/ReceiveDialog.qml @@ -206,24 +206,9 @@ ElDialog { text: qsTr('Amount') color: Material.accentColor } - RowLayout { + FormattedAmount { visible: !request.amount.isEmpty - Label { - text: Config.formatSats(request.amount) - font.family: FixedFont - font.pixelSize: constants.fontSizeMedium - font.bold: true - } - Label { - text: Config.baseUnit - color: Material.accentColor - font.pixelSize: constants.fontSizeMedium - } - Label { - visible: Daemon.fx.enabled - text: '(' + Daemon.fx.fiatValue(request.amount, false) + ' ' + Daemon.fx.fiatCurrency + ')' - font.pixelSize: constants.fontSizeMedium - } + amount: request.amount } }