From 13a421aabbf9cbbf2fca9c99ddde01dfa25e3ca3 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Sat, 3 Feb 2024 04:18:46 +0000 Subject: [PATCH] factor out hardcoded "sat/byte" and "sat/b" strings Though note that the qml GUI has some more in qml/js context. --- electrum/commands.py | 4 ++-- electrum/gui/qt/amountedit.py | 4 ++-- electrum/simple_config.py | 4 ++-- electrum/util.py | 2 ++ electrum/wallet.py | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/electrum/commands.py b/electrum/commands.py index d16d04cad..adc7b3a36 100644 --- a/electrum/commands.py +++ b/electrum/commands.py @@ -1428,7 +1428,7 @@ command_options = { 'nocheck': (None, "Do not verify aliases"), 'imax': (None, "Maximum number of inputs"), 'fee': ("-f", "Transaction fee (absolute, in BTC)"), - 'feerate': (None, "Transaction fee rate (in sat/byte)"), + 'feerate': (None, f"Transaction fee rate (in {util.FEERATE_UI_NAME_SAT_PER_VBYTE})"), '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)."), '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"), 'gossip': (None, "Apply command to gossip node instead of wallet"), 'connection_string': (None, "Lightning network node ID or network address"), - 'new_fee_rate': (None, "The Updated/Increased Transaction fee rate (in sat/byte)"), + 'new_fee_rate': (None, f"The Updated/Increased Transaction fee rate (in {util.FEERATE_UI_NAME_SAT_PER_VBYTE})"), 'from_amount': (None, "Amount to convert (default: 1)"), 'from_ccy': (None, "Currency to convert from"), 'to_ccy': (None, "Currency to convert to"), diff --git a/electrum/gui/qt/amountedit.py b/electrum/gui/qt/amountedit.py index 4e3073d08..3ada52917 100644 --- a/electrum/gui/qt/amountedit.py +++ b/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 electrum.util import (format_satoshis_plain, decimal_point_to_base_unit_name, - FEERATE_PRECISION, quantize_feerate, DECIMAL_POINT) + FEERATE_PRECISION, quantize_feerate, DECIMAL_POINT, FEERATE_UI_NAME_SAT_PER_VBYTE) from electrum.bitcoin import COIN, TOTAL_COIN_SUPPLY_LIMIT_IN_BTC _NOT_GIVEN = object() # sentinel value @@ -165,7 +165,7 @@ class FeerateEdit(BTCAmountEdit): self.extra_precision = FEERATE_PRECISION def _base_unit(self): - return 'sat/byte' + return FEERATE_UI_NAME_SAT_PER_VBYTE def _get_amount_from_text(self, text): sat_per_byte_amount = super()._get_amount_from_text(text) diff --git a/electrum/simple_config.py b/electrum/simple_config.py index 16ba28fa5..fbb034728 100644 --- a/electrum/simple_config.py +++ b/electrum/simple_config.py @@ -637,7 +637,7 @@ class SimpleConfig(Logger): fee_per_byte = None else: fee_per_byte = fee_per_kb/1000 - rate_str = format_fee_satoshis(fee_per_byte) + ' sat/byte' + rate_str = format_fee_satoshis(fee_per_byte) + f" {util.FEERATE_UI_NAME_SAT_PER_VBYTE}" if dyn: if mempool: @@ -875,7 +875,7 @@ class SimpleConfig(Logger): def format_fee_rate(self, fee_rate) -> str: """fee_rate is in sat/kvByte.""" - return format_fee_satoshis(fee_rate/1000, num_zeros=self.num_zeros) + ' sat/byte' + return format_fee_satoshis(fee_rate/1000, num_zeros=self.num_zeros) + f" {util.FEERATE_UI_NAME_SAT_PER_VBYTE}" def get_base_unit(self): return decimal_point_to_base_unit_name(self.decimal_point) diff --git a/electrum/util.py b/electrum/util.py index 740177fbe..abe98c47f 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -792,6 +792,8 @@ def format_satoshis( FEERATE_PRECISION = 1 # num fractional decimal places for sat/byte fee rates _feerate_quanta = Decimal(10) ** (-FEERATE_PRECISION) +FEERATE_UI_NAME_SAT_PER_VBYTE = "sat/byte" +FEERATE_UI_NAME_SAT_PER_VBYTE_SHORT = "sat/b" def format_fee_satoshis(fee, *, num_zeros=0, precision=None): diff --git a/electrum/wallet.py b/electrum/wallet.py index b93cdc983..45245be24 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -1657,7 +1657,7 @@ class Abstract_Wallet(ABC, Logger, EventListener): if fee is not None: size = tx.estimated_size() fee_per_byte = fee / size - extra.append(format_fee_satoshis(fee_per_byte) + ' sat/b') + extra.append(format_fee_satoshis(fee_per_byte) + f" {util.FEERATE_UI_NAME_SAT_PER_VBYTE_SHORT}") if fee is not None and height in (TX_HEIGHT_UNCONF_PARENT, TX_HEIGHT_UNCONFIRMED) \ and self.config.has_fee_mempool(): exp_n = self.config.fee_to_depth(fee_per_byte) @@ -3184,7 +3184,7 @@ class Abstract_Wallet(ABC, Logger, EventListener): elif feerate > FEERATE_WARNING_HIGH_FEE / 1000: long_warning = ' '.join([ _("The fee for this transaction seems unusually high."), - _("(feerate: {} sat/byte)").format(f'{feerate:.2f}') + _("(feerate: {})").format(self.config.format_fee_rate(1000 * feerate)) ]) short_warning = _("high fee rate") + "!" if long_warning is None: