Browse Source

factor out hardcoded "sat/byte" and "sat/b" strings

Though note that the qml GUI has some more in qml/js context.
master
SomberNight 2 years ago
parent
commit
13a421aabb
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 4
      electrum/commands.py
  2. 4
      electrum/gui/qt/amountedit.py
  3. 4
      electrum/simple_config.py
  4. 2
      electrum/util.py
  5. 4
      electrum/wallet.py

4
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"),

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 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)

4
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)

2
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):

4
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:

Loading…
Cancel
Save