|
@ -185,6 +185,10 @@ class Plugin(BasePlugin): |
|
|
@hook |
|
|
@hook |
|
|
def init_qt(self, gui): |
|
|
def init_qt(self, gui): |
|
|
self.gui = 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 |
|
|
@hook |
|
|
def new_window(self, window): |
|
|
def new_window(self, window): |
|
@ -251,26 +255,44 @@ class Plugin(BasePlugin): |
|
|
|
|
|
|
|
|
@hook |
|
|
@hook |
|
|
def load_wallet(self, wallet, window): |
|
|
def load_wallet(self, wallet, window): |
|
|
|
|
|
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 = {} |
|
|
tx_list = {} |
|
|
for item in wallet.get_history(wallet.storage.get("current_account", None)): |
|
|
for item in wallet.get_history(wallet.storage.get("current_account", None)): |
|
|
tx_hash, conf, value, timestamp, balance = item |
|
|
tx_hash, conf, value, timestamp, balance = item |
|
|
tx_list[tx_hash] = {'value': value, 'timestamp': timestamp } |
|
|
tx_list[tx_hash] = {'value': value, 'timestamp': timestamp } |
|
|
|
|
|
# FIXME: not robust to request failure |
|
|
self.wallet_tx_list[wallet] = tx_list |
|
|
self.wallet_tx_list[wallet] = tx_list |
|
|
self.set_network(wallet.network) |
|
|
all_txs.update(self.wallet_tx_list[wallet]) |
|
|
t = threading.Thread(target=self.request_history_rates, args=(tx_list,)) |
|
|
if new: |
|
|
|
|
|
self.print_error("requesting historical FX rates") |
|
|
|
|
|
t = threading.Thread(target=self.request_historical_rates, |
|
|
|
|
|
args=(all_txs,)) |
|
|
t.setDaemon(True) |
|
|
t.setDaemon(True) |
|
|
t.start() |
|
|
t.start() |
|
|
|
|
|
|
|
|
|
|
|
def request_historical_rates(self, tx_list): |
|
|
def requires_settings(self): |
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def request_history_rates(self, tx_list): |
|
|
|
|
|
if self.config.get('history_rates') != "checked" or not tx_list: |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
mintimestr = datetime.datetime.fromtimestamp(int(min(tx_list.items(), key=lambda x: x[1]['timestamp'])[1]['timestamp'])).strftime('%Y-%m-%d') |
|
|
mintimestr = datetime.datetime.fromtimestamp(int(min(tx_list.items(), key=lambda x: x[1]['timestamp'])[1]['timestamp'])).strftime('%Y-%m-%d') |
|
|
except Exception: |
|
|
except Exception: |
|
@ -305,6 +327,9 @@ class Plugin(BasePlugin): |
|
|
for window in self.gui.windows: |
|
|
for window in self.gui.windows: |
|
|
window.need_update.set() |
|
|
window.need_update.set() |
|
|
|
|
|
|
|
|
|
|
|
def requires_settings(self): |
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
@hook |
|
|
@hook |
|
|
def history_tab_update(self, window): |
|
|
def history_tab_update(self, window): |
|
|
if self.config.get('history_rates') != "checked": |
|
|
if self.config.get('history_rates') != "checked": |
|
@ -360,6 +385,9 @@ class Plugin(BasePlugin): |
|
|
if Decimal(str(tx_info['value'])) < 0: |
|
|
if Decimal(str(tx_info['value'])) < 0: |
|
|
item.setForeground(6, QBrush(QColor("#BC1E1E"))) |
|
|
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 |
|
|
window.is_edit = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -426,7 +454,7 @@ class Plugin(BasePlugin): |
|
|
def on_change_hist(checked): |
|
|
def on_change_hist(checked): |
|
|
if checked: |
|
|
if checked: |
|
|
self.config.set_key('history_rates', 'checked') |
|
|
self.config.set_key('history_rates', 'checked') |
|
|
self.request_history_rates() |
|
|
self.get_historical_rates() |
|
|
else: |
|
|
else: |
|
|
self.config.set_key('history_rates', 'unchecked') |
|
|
self.config.set_key('history_rates', 'unchecked') |
|
|
for window in self.gui.windows: |
|
|
for window in self.gui.windows: |
|
|