tExchange rate plugin fixes - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 613403f4183cc12a6285a2fb4c1f0a61c9add646 DIR parent 5df03951e568e900c301e88878902c13da3729b1 HTML Author: Neil Booth <kyuupichan@gmail.com> Date: Thu, 3 Sep 2015 16:26:52 +0900 Exchange rate plugin fixes Set the new column width even though autosizing Register all wallets in mid-session loads Improved historical rate fetching Diffstat: M plugins/exchange_rate.py | 68 ++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 20 deletions(-) --- DIR diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py t@@ -185,6 +185,10 @@ class Plugin(BasePlugin): @hook def init_qt(self, gui): self.gui = gui + # For mid-session plugin loads + for window in gui.windows: + self.new_window(window) + self.new_wallets([window.wallet for window in gui.windows]) @hook def new_window(self, window): t@@ -251,26 +255,44 @@ class Plugin(BasePlugin): @hook def load_wallet(self, wallet, window): - tx_list = {} - for item in wallet.get_history(wallet.storage.get("current_account", None)): - tx_hash, conf, value, timestamp, balance = item - tx_list[tx_hash] = {'value': value, 'timestamp': timestamp } - - self.wallet_tx_list[wallet] = tx_list - self.set_network(wallet.network) - t = threading.Thread(target=self.request_history_rates, args=(tx_list,)) - t.setDaemon(True) - t.start() - - - def requires_settings(self): - return True - - - def request_history_rates(self, tx_list): - if self.config.get('history_rates') != "checked" or not tx_list: + self.new_wallets([wallet]) + + def new_wallets(self, wallets): + if wallets: + # For mid-session plugin loads + self.set_network(wallets[0].network) + for wallet in wallets: + if wallet not in self.wallet_tx_list: + self.wallet_tx_list[wallet] = None + self.get_historical_rates() + + def get_historical_rates(self): + '''Request historic rates for all wallets for which they haven't yet + been requested + ''' + if self.config.get('history_rates') != "checked": return - + all_txs = {} + new = False + for wallet in self.wallet_tx_list: + if self.wallet_tx_list[wallet] is None: + new = True + self.print_error("New wallet:", wallet) + tx_list = {} + for item in wallet.get_history(wallet.storage.get("current_account", None)): + tx_hash, conf, value, timestamp, balance = item + tx_list[tx_hash] = {'value': value, 'timestamp': timestamp } + # FIXME: not robust to request failure + self.wallet_tx_list[wallet] = tx_list + all_txs.update(self.wallet_tx_list[wallet]) + if new: + self.print_error("requesting historical FX rates") + t = threading.Thread(target=self.request_historical_rates, + args=(all_txs,)) + t.setDaemon(True) + t.start() + + def request_historical_rates(self, tx_list): try: mintimestr = datetime.datetime.fromtimestamp(int(min(tx_list.items(), key=lambda x: x[1]['timestamp'])[1]['timestamp'])).strftime('%Y-%m-%d') except Exception: t@@ -305,6 +327,9 @@ class Plugin(BasePlugin): for window in self.gui.windows: window.need_update.set() + def requires_settings(self): + return True + @hook def history_tab_update(self, window): if self.config.get('history_rates') != "checked": t@@ -360,6 +385,9 @@ class Plugin(BasePlugin): if Decimal(str(tx_info['value'])) < 0: item.setForeground(6, QBrush(QColor("#BC1E1E"))) + # We autosize but in some cases QT doesn't handle that + # properly for new columns it seems + window.history_list.setColumnWidth(6, 120) window.is_edit = False t@@ -426,7 +454,7 @@ class Plugin(BasePlugin): def on_change_hist(checked): if checked: self.config.set_key('history_rates', 'checked') - self.request_history_rates() + self.get_historical_rates() else: self.config.set_key('history_rates', 'unchecked') for window in self.gui.windows: