factor out hardcoded "sat/byte" and "sat/b" strings
Though note that the qml GUI has some more in qml/js context.
This commit is contained in:
@@ -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, "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_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, "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_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"),
|
||||||
|
|||||||
@@ -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_PRECISION, quantize_feerate, DECIMAL_POINT, FEERATE_UI_NAME_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 'sat/byte'
|
return FEERATE_UI_NAME_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)
|
||||||
|
|||||||
@@ -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) + ' sat/byte'
|
rate_str = format_fee_satoshis(fee_per_byte) + f" {util.FEERATE_UI_NAME_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) + ' 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):
|
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)
|
||||||
|
|||||||
@@ -792,6 +792,8 @@ 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"
|
||||||
|
FEERATE_UI_NAME_SAT_PER_VBYTE_SHORT = "sat/b"
|
||||||
|
|
||||||
|
|
||||||
def format_fee_satoshis(fee, *, num_zeros=0, precision=None):
|
def format_fee_satoshis(fee, *, num_zeros=0, precision=None):
|
||||||
|
|||||||
@@ -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) + ' 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) \
|
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)
|
||||||
@@ -3184,7 +3184,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
elif feerate > FEERATE_WARNING_HIGH_FEE / 1000:
|
elif feerate > FEERATE_WARNING_HIGH_FEE / 1000:
|
||||||
long_warning = ' '.join([
|
long_warning = ' '.join([
|
||||||
_("The fee for this transaction seems unusually high."),
|
_("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") + "!"
|
short_warning = _("high fee rate") + "!"
|
||||||
if long_warning is None:
|
if long_warning is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user