From f53f1772036090f36c9d6165b16f5f6f12c30328 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Thu, 15 Apr 2021 18:50:54 +0200 Subject: [PATCH] kivy swaps: handle no dynamic fee estimates fixes #7215 --- electrum/gui/kivy/uix/dialogs/lightning_channels.py | 4 ++-- electrum/simple_config.py | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/electrum/gui/kivy/uix/dialogs/lightning_channels.py b/electrum/gui/kivy/uix/dialogs/lightning_channels.py index 7395c3866..d643159c8 100644 --- a/electrum/gui/kivy/uix/dialogs/lightning_channels.py +++ b/electrum/gui/kivy/uix/dialogs/lightning_channels.py @@ -680,12 +680,12 @@ class SwapDialog(Factory.Popup): def update_fee_text(self): fee_per_kb = self.config.fee_per_kb() + fee_per_b = format_fee_satoshis(fee_per_kb / 1000) if fee_per_kb is not None else "unknown" # eta is -1 when block inclusion cannot be estimated for low fees eta = self.config.fee_to_eta(fee_per_kb) - fee_per_b = format_fee_satoshis(fee_per_kb / 1000) suggest_fee = self.config.eta_target_to_fee(RECOMMEND_BLOCKS_SWAP) - suggest_fee_per_b = format_fee_satoshis(suggest_fee / 1000) + suggest_fee_per_b = format_fee_satoshis(suggest_fee / 1000) if suggest_fee is not None else "unknown" s = 's' if eta > 1 else '' if eta > RECOMMEND_BLOCKS_SWAP or eta == -1: diff --git a/electrum/simple_config.py b/electrum/simple_config.py index 8b92844fb..394819165 100644 --- a/electrum/simple_config.py +++ b/electrum/simple_config.py @@ -405,12 +405,17 @@ class SimpleConfig(Logger): return 1 return FEE_ETA_TARGETS[slider_pos] - def fee_to_eta(self, fee_per_kb: int) -> int: + def fee_to_eta(self, fee_per_kb: Optional[int]) -> int: """Returns 'num blocks' ETA estimate for given fee rate, or -1 for low fee. """ import operator - lst = list(self.fee_estimates.items()) + [(1, self.eta_to_fee(len(FEE_ETA_TARGETS)))] + lst = list(self.fee_estimates.items()) + next_block_fee = self.eta_target_to_fee(1) + if next_block_fee is not None: + lst += [(1, next_block_fee)] + if not lst or fee_per_kb is None: + return -1 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(FEE_ETA_TARGETS[0])/2: