Browse Source

follow-up: factor out more hardcoded "sat/byte" and "sat/b" strings

- rename globals
- also rm hardcoded strings from qml
- use consistent unit names in qml
  (previously mixed sat/vB and sat/byte (latter coming from core lib))
master
SomberNight 2 years ago
parent
commit
a9a8ed2eb4
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 4
      electrum/commands.py
  2. 2
      electrum/gui/qml/components/ConfirmTxDialog.qml
  3. 4
      electrum/gui/qml/components/CpfpBumpFeeDialog.qml
  4. 9
      electrum/gui/qml/components/NetworkOverview.qml
  5. 4
      electrum/gui/qml/components/RbfBumpFeeDialog.qml
  6. 4
      electrum/gui/qml/components/RbfCancelDialog.qml
  7. 7
      electrum/gui/qml/qeapp.py
  8. 4
      electrum/gui/qt/amountedit.py
  9. 4
      electrum/gui/qt/main_window.py
  10. 4
      electrum/gui/qt/transaction_dialog.py
  11. 6
      electrum/simple_config.py
  12. 6
      electrum/util.py
  13. 2
      electrum/wallet.py

4
electrum/commands.py

@ -1428,7 +1428,7 @@ command_options = {
'nocheck': (None, "Do not verify aliases"), 'nocheck': (None, "Do not verify aliases"),
'imax': (None, "Maximum number of inputs"), 'imax': (None, "Maximum number of inputs"),
'fee': ("-f", "Transaction fee (absolute, in BTC)"), 'fee': ("-f", "Transaction fee (absolute, in BTC)"),
'feerate': (None, f"Transaction fee rate (in {util.FEERATE_UI_NAME_SAT_PER_VBYTE})"), 'feerate': (None, f"Transaction fee rate (in {util.UI_UNIT_NAME_FEERATE_SAT_PER_VBYTE})"),
'from_addr': ("-F", "Source address (must be a wallet address; use sweep to spend from non-wallet address)."), 'from_addr': ("-F", "Source address (must be a wallet address; use sweep to spend from non-wallet address)."),
'from_coins': (None, "Source coins (must be in wallet; use sweep to spend from non-wallet address)."), 'from_coins': (None, "Source coins (must be in wallet; use sweep to spend from non-wallet address)."),
'change_addr': ("-c", "Change address. Default is a spare address, or the source address if it's not in the wallet"), 'change_addr': ("-c", "Change address. Default is a spare address, or the source address if it's not in the wallet"),
@ -1461,7 +1461,7 @@ command_options = {
'iknowwhatimdoing': (None, "Acknowledge that I understand the full implications of what I am about to do"), 'iknowwhatimdoing': (None, "Acknowledge that I understand the full implications of what I am about to do"),
'gossip': (None, "Apply command to gossip node instead of wallet"), 'gossip': (None, "Apply command to gossip node instead of wallet"),
'connection_string': (None, "Lightning network node ID or network address"), 'connection_string': (None, "Lightning network node ID or network address"),
'new_fee_rate': (None, f"The Updated/Increased Transaction fee rate (in {util.FEERATE_UI_NAME_SAT_PER_VBYTE})"), 'new_fee_rate': (None, f"The Updated/Increased Transaction fee rate (in {util.UI_UNIT_NAME_FEERATE_SAT_PER_VBYTE})"),
'from_amount': (None, "Amount to convert (default: 1)"), 'from_amount': (None, "Amount to convert (default: 1)"),
'from_ccy': (None, "Currency to convert from"), 'from_ccy': (None, "Currency to convert from"),
'to_ccy': (None, "Currency to convert to"), 'to_ccy': (None, "Currency to convert to"),

2
electrum/gui/qml/components/ConfirmTxDialog.qml

@ -123,7 +123,7 @@ ElDialog {
} }
Label { Label {
text: 'sat/vB' text: UI_UNIT_NAME.FEERATE_SAT_PER_VB
color: Material.accentColor color: Material.accentColor
} }
} }

4
electrum/gui/qml/components/CpfpBumpFeeDialog.qml

@ -65,7 +65,7 @@ ElDialog {
Label { Label {
Layout.preferredWidth: 1 Layout.preferredWidth: 1
Layout.fillWidth: true Layout.fillWidth: true
text: qsTr('%1 bytes').arg(cpfpfeebumper.totalSize) text: cpfpfeebumper.totalSize + ' ' + UI_UNIT_NAME.TXSIZE_VBYTES
} }
Label { Label {
@ -161,7 +161,7 @@ ElDialog {
Label { Label {
visible: cpfpfeebumper.valid visible: cpfpfeebumper.valid
text: 'sat/vB' text: UI_UNIT_NAME.FEERATE_SAT_PER_VB
color: Material.accentColor color: Material.accentColor
} }
} }

9
electrum/gui/qml/components/NetworkOverview.qml

@ -100,7 +100,10 @@ Pane {
Layout.fillWidth: true Layout.fillWidth: true
height: parent.height height: parent.height
color: Qt.hsva(2/3-(2/3*(Math.log(Math.min(600, modelData[0]))/Math.log(600))), 0.8, 1, 1) color: Qt.hsva(2/3-(2/3*(Math.log(Math.min(600, modelData[0]))/Math.log(600))), 0.8, 1, 1)
ToolTip.text: modelData[0] + " sat/vB around depth " + (modelData[2]/1000000).toFixed(2) + " MB" ToolTip.text: (qsTr("%1 around depth %2")
.arg(modelData[0] + " " + UI_UNIT_NAME.FEERATE_SAT_PER_VB)
.arg((modelData[2]/1000000).toFixed(2) + " " + UI_UNIT_NAME.MEMPOOL_MB)
)
ToolTip.visible: ma.containsMouse ToolTip.visible: ma.containsMouse
MouseArea { MouseArea {
id: ma id: ma
@ -144,14 +147,14 @@ Pane {
RowLayout { RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
Label { Label {
text: '<-- ' + qsTr('%1 sat/vB').arg(Math.ceil(Network.feeHistogram.max_fee)) text: '<-- ' + Math.ceil(Network.feeHistogram.max_fee) + " " + UI_UNIT_NAME.FEERATE_SAT_PER_VB
font.pixelSize: constants.fontSizeXSmall font.pixelSize: constants.fontSizeXSmall
color: Material.accentColor color: Material.accentColor
} }
Label { Label {
Layout.fillWidth: true Layout.fillWidth: true
horizontalAlignment: Text.AlignRight horizontalAlignment: Text.AlignRight
text: qsTr('%1 sat/vB').arg(Math.floor(Network.feeHistogram.min_fee)) + ' -->' text: Math.floor(Network.feeHistogram.min_fee) + " " + UI_UNIT_NAME.FEERATE_SAT_PER_VB + ' -->'
font.pixelSize: constants.fontSizeXSmall font.pixelSize: constants.fontSizeXSmall
color: Material.accentColor color: Material.accentColor
} }

4
electrum/gui/qml/components/RbfBumpFeeDialog.qml

@ -104,7 +104,7 @@ ElDialog {
} }
Label { Label {
text: 'sat/vB' text: UI_UNIT_NAME.FEERATE_SAT_PER_VB
color: Material.accentColor color: Material.accentColor
} }
} }
@ -133,7 +133,7 @@ ElDialog {
Label { Label {
visible: rbffeebumper.valid visible: rbffeebumper.valid
text: 'sat/vB' text: UI_UNIT_NAME.FEERATE_SAT_PER_VB
color: Material.accentColor color: Material.accentColor
} }
} }

4
electrum/gui/qml/components/RbfCancelDialog.qml

@ -67,7 +67,7 @@ ElDialog {
} }
Label { Label {
text: 'sat/vB' text: UI_UNIT_NAME.FEERATE_SAT_PER_VB
color: Material.accentColor color: Material.accentColor
} }
} }
@ -96,7 +96,7 @@ ElDialog {
Label { Label {
visible: txcanceller.valid visible: txcanceller.valid
text: 'sat/vB' text: UI_UNIT_NAME.FEERATE_SAT_PER_VB
color: Material.accentColor color: Material.accentColor
} }
} }

7
electrum/gui/qml/qeapp.py

@ -12,6 +12,7 @@ from PyQt6.QtCore import (pyqtSlot, pyqtSignal, pyqtProperty, QObject, QT_VERSIO
from PyQt6.QtGui import QGuiApplication, QFontDatabase, QScreen from PyQt6.QtGui import QGuiApplication, QFontDatabase, QScreen
from PyQt6.QtQml import qmlRegisterType, qmlRegisterUncreatableType, QQmlApplicationEngine from PyQt6.QtQml import qmlRegisterType, qmlRegisterUncreatableType, QQmlApplicationEngine
import electrum
from electrum import version, constants from electrum import version, constants
from electrum.i18n import _ from electrum.i18n import _
from electrum.logging import Logger, get_logger from electrum.logging import Logger, get_logger
@ -417,6 +418,12 @@ class ElectrumQmlApplication(QGuiApplication):
'qt_version': QT_VERSION_STR, 'qt_version': QT_VERSION_STR,
'pyqt_version': PYQT_VERSION_STR 'pyqt_version': PYQT_VERSION_STR
}) })
self.context.setContextProperty('UI_UNIT_NAME', {
"FEERATE_SAT_PER_VBYTE": electrum.util.UI_UNIT_NAME_FEERATE_SAT_PER_VBYTE,
"FEERATE_SAT_PER_VB": electrum.util.UI_UNIT_NAME_FEERATE_SAT_PER_VB,
"TXSIZE_VBYTES": electrum.util.UI_UNIT_NAME_TXSIZE_VBYTES,
"MEMPOOL_MB": electrum.util.UI_UNIT_NAME_MEMPOOL_MB,
})
self.plugins.load_plugin('trustedcoin') self.plugins.load_plugin('trustedcoin')

4
electrum/gui/qt/amountedit.py

@ -10,7 +10,7 @@ from PyQt5.QtWidgets import (QLineEdit, QStyle, QStyleOptionFrame, QSizePolicy)
from .util import char_width_in_lineedit, ColorScheme from .util import char_width_in_lineedit, ColorScheme
from electrum.util import (format_satoshis_plain, decimal_point_to_base_unit_name, from electrum.util import (format_satoshis_plain, decimal_point_to_base_unit_name,
FEERATE_PRECISION, quantize_feerate, DECIMAL_POINT, FEERATE_UI_NAME_SAT_PER_VBYTE) FEERATE_PRECISION, quantize_feerate, DECIMAL_POINT, UI_UNIT_NAME_FEERATE_SAT_PER_VBYTE)
from electrum.bitcoin import COIN, TOTAL_COIN_SUPPLY_LIMIT_IN_BTC from electrum.bitcoin import COIN, TOTAL_COIN_SUPPLY_LIMIT_IN_BTC
_NOT_GIVEN = object() # sentinel value _NOT_GIVEN = object() # sentinel value
@ -165,7 +165,7 @@ class FeerateEdit(BTCAmountEdit):
self.extra_precision = FEERATE_PRECISION self.extra_precision = FEERATE_PRECISION
def _base_unit(self): def _base_unit(self):
return FEERATE_UI_NAME_SAT_PER_VBYTE return UI_UNIT_NAME_FEERATE_SAT_PER_VBYTE
def _get_amount_from_text(self, text): def _get_amount_from_text(self, text):
sat_per_byte_amount = super()._get_amount_from_text(text) sat_per_byte_amount = super()._get_amount_from_text(text)

4
electrum/gui/qt/main_window.py

@ -56,7 +56,7 @@ from electrum.plugin import run_hook, BasePlugin
from electrum.i18n import _ from electrum.i18n import _
from electrum.util import (format_time, UserCancelled, profiler, bfh, InvalidPassword, from electrum.util import (format_time, UserCancelled, profiler, bfh, InvalidPassword,
UserFacingException, get_new_wallet_name, send_exception_to_crash_reporter, UserFacingException, get_new_wallet_name, send_exception_to_crash_reporter,
AddTransactionException, os_chmod) AddTransactionException, os_chmod, UI_UNIT_NAME_TXSIZE_VBYTES)
from electrum.bip21 import BITCOIN_BIP21_URI_SCHEME from electrum.bip21 import BITCOIN_BIP21_URI_SCHEME
from electrum.payment_identifier import PaymentIdentifier from electrum.payment_identifier import PaymentIdentifier
from electrum.invoices import PR_PAID, Invoice from electrum.invoices import PR_PAID, Invoice
@ -2566,7 +2566,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
vbox.addWidget(WWLabel(msg2)) vbox.addWidget(WWLabel(msg2))
grid = QGridLayout() grid = QGridLayout()
grid.addWidget(QLabel(_('Total size') + ':'), 0, 0) grid.addWidget(QLabel(_('Total size') + ':'), 0, 0)
grid.addWidget(QLabel('%d bytes'% total_size), 0, 1) grid.addWidget(QLabel(f"{total_size} {UI_UNIT_NAME_TXSIZE_VBYTES}"), 0, 1)
max_fee = new_tx.output_value() max_fee = new_tx.output_value()
grid.addWidget(QLabel(_('Input amount') + ':'), 1, 0) grid.addWidget(QLabel(_('Input amount') + ':'), 1, 0)
grid.addWidget(QLabel(self.format_amount(max_fee) + ' ' + self.base_unit()), 1, 1) grid.addWidget(QLabel(self.format_amount(max_fee) + ' ' + self.base_unit()), 1, 1)

4
electrum/gui/qt/transaction_dialog.py

@ -52,7 +52,7 @@ from electrum.plugin import run_hook
from electrum import simple_config from electrum import simple_config
from electrum.transaction import SerializationError, Transaction, PartialTransaction, TxOutpoint, TxinDataFetchProgress from electrum.transaction import SerializationError, Transaction, PartialTransaction, TxOutpoint, TxinDataFetchProgress
from electrum.logging import get_logger from electrum.logging import get_logger
from electrum.util import ShortID, get_asyncio_loop from electrum.util import ShortID, get_asyncio_loop, UI_UNIT_NAME_TXSIZE_VBYTES
from electrum.network import Network from electrum.network import Network
from electrum.wallet import TxSighashRiskLevel, TxSighashDanger from electrum.wallet import TxSighashRiskLevel, TxSighashDanger
@ -863,7 +863,7 @@ class TxDialog(QDialog, MessageBoxMixin):
self.amount_label.setText(amount_str) self.amount_label.setText(amount_str)
else: else:
self.amount_label.hide() self.amount_label.hide()
size_str = _("Size:") + ' %d bytes'% size size_str = _("Size:") + f" {size} {UI_UNIT_NAME_TXSIZE_VBYTES}"
if fee is None: if fee is None:
if prog := self._fetch_txin_data_progress: if prog := self._fetch_txin_data_progress:
if not prog.has_errored: if not prog.has_errored:

6
electrum/simple_config.py

@ -590,7 +590,7 @@ class SimpleConfig(Logger):
def get_depth_mb_str(self, depth: int) -> str: def get_depth_mb_str(self, depth: int) -> str:
# e.g. 500_000 -> "0.50 MB" # e.g. 500_000 -> "0.50 MB"
depth_mb = "{:.2f}".format(depth / 1_000_000) # maybe .rstrip("0") ? depth_mb = "{:.2f}".format(depth / 1_000_000) # maybe .rstrip("0") ?
return f"{depth_mb} MB" return f"{depth_mb} {util.UI_UNIT_NAME_MEMPOOL_MB}"
def depth_tooltip(self, depth: Optional[int]) -> str: def depth_tooltip(self, depth: Optional[int]) -> str:
"""Returns text tooltip for given mempool depth (in vbytes).""" """Returns text tooltip for given mempool depth (in vbytes)."""
@ -637,7 +637,7 @@ class SimpleConfig(Logger):
fee_per_byte = None fee_per_byte = None
else: else:
fee_per_byte = fee_per_kb/1000 fee_per_byte = fee_per_kb/1000
rate_str = format_fee_satoshis(fee_per_byte) + f" {util.FEERATE_UI_NAME_SAT_PER_VBYTE}" rate_str = format_fee_satoshis(fee_per_byte) + f" {util.UI_UNIT_NAME_FEERATE_SAT_PER_VBYTE}"
if dyn: if dyn:
if mempool: if mempool:
@ -875,7 +875,7 @@ class SimpleConfig(Logger):
def format_fee_rate(self, fee_rate) -> str: def format_fee_rate(self, fee_rate) -> str:
"""fee_rate is in sat/kvByte.""" """fee_rate is in sat/kvByte."""
return format_fee_satoshis(fee_rate/1000, num_zeros=self.num_zeros) + f" {util.FEERATE_UI_NAME_SAT_PER_VBYTE}" return format_fee_satoshis(fee_rate/1000, num_zeros=self.num_zeros) + f" {util.UI_UNIT_NAME_FEERATE_SAT_PER_VBYTE}"
def get_base_unit(self): def get_base_unit(self):
return decimal_point_to_base_unit_name(self.decimal_point) return decimal_point_to_base_unit_name(self.decimal_point)

6
electrum/util.py

@ -792,8 +792,10 @@ def format_satoshis(
FEERATE_PRECISION = 1 # num fractional decimal places for sat/byte fee rates FEERATE_PRECISION = 1 # num fractional decimal places for sat/byte fee rates
_feerate_quanta = Decimal(10) ** (-FEERATE_PRECISION) _feerate_quanta = Decimal(10) ** (-FEERATE_PRECISION)
FEERATE_UI_NAME_SAT_PER_VBYTE = "sat/byte" UI_UNIT_NAME_FEERATE_SAT_PER_VBYTE = "sat/byte"
FEERATE_UI_NAME_SAT_PER_VBYTE_SHORT = "sat/b" UI_UNIT_NAME_FEERATE_SAT_PER_VB = "sat/b"
UI_UNIT_NAME_TXSIZE_VBYTES = "bytes"
UI_UNIT_NAME_MEMPOOL_MB = "MB"
def format_fee_satoshis(fee, *, num_zeros=0, precision=None): def format_fee_satoshis(fee, *, num_zeros=0, precision=None):

2
electrum/wallet.py

@ -1657,7 +1657,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
if fee is not None: if fee is not None:
size = tx.estimated_size() size = tx.estimated_size()
fee_per_byte = fee / size fee_per_byte = fee / size
extra.append(format_fee_satoshis(fee_per_byte) + f" {util.FEERATE_UI_NAME_SAT_PER_VBYTE_SHORT}") extra.append(format_fee_satoshis(fee_per_byte) + f" {util.UI_UNIT_NAME_FEERATE_SAT_PER_VB}")
if fee is not None and height in (TX_HEIGHT_UNCONF_PARENT, TX_HEIGHT_UNCONFIRMED) \ if fee is not None and height in (TX_HEIGHT_UNCONF_PARENT, TX_HEIGHT_UNCONFIRMED) \
and self.config.has_fee_mempool(): and self.config.has_fee_mempool():
exp_n = self.config.fee_to_depth(fee_per_byte) exp_n = self.config.fee_to_depth(fee_per_byte)

Loading…
Cancel
Save