URI: 
       tconfig: fix get_fee_text for static fees - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit fc97181aa554a3f7bc0a50068f68a830286f8796
   DIR parent de80f68e4d76ac2ae16f63089535bb00334c64f5
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Wed,  4 Nov 2020 01:49:57 +0100
       
       config: fix get_fee_text for static fees
       
       mismatching units
       
       Diffstat:
         M electrum/simple_config.py           |      48 ++++++++++++++++++++-----------
       
       1 file changed, 31 insertions(+), 17 deletions(-)
       ---
   DIR diff --git a/electrum/simple_config.py b/electrum/simple_config.py
       t@@ -385,22 +385,27 @@ class SimpleConfig(Logger):
                # convert to sat/kbyte
                return int(fee * 1000)
        
       -    def depth_target(self, slider_pos) -> int:
       +    def depth_target(self, slider_pos: int) -> int:
       +        """Returns mempool depth target in bytes for a fee slider position."""
                slider_pos = max(slider_pos, 0)
                slider_pos = min(slider_pos, len(FEE_DEPTH_TARGETS)-1)
                return FEE_DEPTH_TARGETS[slider_pos]
        
       -    def eta_target(self, i):
       -        if i == len(FEE_ETA_TARGETS):
       +    def eta_target(self, slider_pos: int) -> int:
       +        """Returns 'num blocks' ETA target for a fee slider position."""
       +        if slider_pos == len(FEE_ETA_TARGETS):
                    return 1
       -        return FEE_ETA_TARGETS[i]
       +        return FEE_ETA_TARGETS[slider_pos]
        
       -    def fee_to_eta(self, fee_per_kb):
       +    def fee_to_eta(self, fee_per_kb: int) -> int:
       +        """Returns 'num blocks' ETA estimate for given fee rate,
       +        or -1 for low fee.
       +        """
                import operator
       -        l = list(self.fee_estimates.items()) + [(1, self.eta_to_fee(4))]
       -        dist = map(lambda x: (x[0], abs(x[1] - fee_per_kb)), l)
       +        lst = list(self.fee_estimates.items()) + [(1, self.eta_to_fee(len(FEE_ETA_TARGETS)))]
       +        dist = map(lambda x: (x[0], abs(x[1] - fee_per_kb)), lst)
                min_target, min_value = min(dist, key=operator.itemgetter(1))
       -        if fee_per_kb < self.fee_estimates.get(25)/2:
       +        if fee_per_kb < self.fee_estimates.get(FEE_ETA_TARGETS[0])/2:
                    min_target = -1
                return min_target
        
       t@@ -426,34 +431,43 @@ class SimpleConfig(Logger):
                target, tooltip = self.get_fee_text(pos, dyn, mempool, fee_rate)
                return tooltip + '  [%s]'%target if dyn else target + '  [Static]'
        
       -    def get_fee_text(self, pos, dyn, mempool, fee_rate):
       +    def get_fee_text(
       +            self,
       +            slider_pos: int,
       +            dyn: bool,
       +            mempool: bool,
       +            fee_per_kb: Optional[int],
       +    ):
                """Returns (text, tooltip) where
                text is what we target: static fee / num blocks to confirm in / mempool depth
                tooltip is the corresponding estimate (e.g. num blocks for a static fee)
        
                fee_rate is in sat/kbyte
                """
       -        if fee_rate is None:
       +        if fee_per_kb is None:
                    rate_str = 'unknown'
       +            fee_per_byte = None
                else:
       -            fee_rate = fee_rate/1000
       -            rate_str = format_fee_satoshis(fee_rate) + ' sat/byte'
       +            fee_per_byte = fee_per_kb/1000
       +            rate_str = format_fee_satoshis(fee_per_byte) + ' sat/byte'
        
                if dyn:
                    if mempool:
       -                depth = self.depth_target(pos)
       +                depth = self.depth_target(slider_pos)
                        text = self.depth_tooltip(depth)
                    else:
       -                eta = self.eta_target(pos)
       +                eta = self.eta_target(slider_pos)
                        text = self.eta_tooltip(eta)
                    tooltip = rate_str
       -        else:
       +        else:  # using static fees
       +            assert fee_per_kb is not None
       +            assert fee_per_byte is not None
                    text = rate_str
                    if mempool and self.has_fee_mempool():
       -                depth = self.fee_to_depth(fee_rate)
       +                depth = self.fee_to_depth(fee_per_byte)
                        tooltip = self.depth_tooltip(depth)
                    elif not mempool and self.has_fee_etas():
       -                eta = self.fee_to_eta(fee_rate)
       +                eta = self.fee_to_eta(fee_per_kb)
                        tooltip = self.eta_tooltip(eta)
                    else:
                        tooltip = ''