diff --git a/electrum/gui/kivy/main_window.py b/electrum/gui/kivy/main_window.py index 73379bb22..811dda6f6 100644 --- a/electrum/gui/kivy/main_window.py +++ b/electrum/gui/kivy/main_window.py @@ -173,6 +173,7 @@ class ElectrumWindow(App): def on_history(self, d): Logger.info("on_history") + self.wallet.clear_coin_price_cache() self._trigger_update_history() def on_fee_histogram(self, *args): diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index 11dad7b61..7c3f5e2e0 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -222,6 +222,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): self.fetch_alias() def on_history(self, b): + self.wallet.clear_coin_price_cache() self.new_fx_history_signal.emit() def setup_exception_hook(self): diff --git a/electrum/wallet.py b/electrum/wallet.py index f3f3efe4c..a14bf4f92 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -182,7 +182,7 @@ class Abstract_Wallet(AddressSynchronizer): self.invoices = InvoiceStore(self.storage) self.contacts = Contacts(self.storage) - self.coin_price_cache = {} + self._coin_price_cache = {} def load_and_cleanup(self): self.load_keystore() @@ -1178,6 +1178,9 @@ class Abstract_Wallet(AddressSynchronizer): total_price += self.coin_price(ser.split(':')[0], price_func, ccy, v) return total_price / (input_value/Decimal(COIN)) + def clear_coin_price_cache(self): + self._coin_price_cache = {} + def coin_price(self, txid, price_func, ccy, txin_value): """ Acquisition price of a coin. @@ -1185,17 +1188,13 @@ class Abstract_Wallet(AddressSynchronizer): """ if txin_value is None: return Decimal('NaN') - # FIXME: this mutual recursion will be really slow and might even reach - # max recursion depth if there are no FX rates available as then - # nothing will be cached. cache_key = "{}:{}:{}".format(str(txid), str(ccy), str(txin_value)) - result = self.coin_price_cache.get(cache_key, None) + result = self._coin_price_cache.get(cache_key, None) if result is not None: return result if self.txi.get(txid, {}) != {}: result = self.average_price(txid, price_func, ccy) * txin_value/Decimal(COIN) - if not result.is_nan(): - self.coin_price_cache[cache_key] = result + self._coin_price_cache[cache_key] = result return result else: fiat_value = self.get_fiat_value(txid, ccy)