def history_tab_update(self, tx, entry): if not self.show_history(): return tx_hash, conf, value, timestamp, balance = tx if conf <= 0: date = timestamp_to_datetime(time.time()) else: date = timestamp_to_datetime(timestamp) for amount in [value, balance]: text = self.historical_value_str(amount, date) entry.append(text)
def history_tab_update(self, tx, entry): if not self.show_history(): return tx_hash, conf, value, timestamp, balance = tx if conf <= 0: date = timestamp_to_datetime(time.time()) else: date = timestamp_to_datetime(timestamp) for amount in [value, balance]: text = self.historical_value_str(amount, date) entry.append(text)
def parse_history(self, items): for item in items: tx_hash, conf, value, timestamp, balance = item time_str = _("unknown") if conf > 0: try: time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3] except Exception: time_str = _("error") if conf == -1: time_str = _('Not Verified') icon = "atlas://gui/kivy/theming/light/close" elif conf == 0: time_str = _('Unconfirmed') icon = "atlas://gui/kivy/theming/light/unconfirmed" elif conf < 6: conf = max(1, conf) icon = "atlas://gui/kivy/theming/light/clock{}".format(conf) else: icon = "atlas://gui/kivy/theming/light/confirmed" label = self.app.wallet.get_label(tx_hash) if tx_hash else _( 'Pruned transaction outputs') date = timestamp_to_datetime(timestamp) quote_text = '' if self.app.fiat_unit and date: rate = run_hook('history_rate', date) if rate: s = run_hook('value_str', value, rate) quote_text = '' if s is None else s + ' ' + self.app.fiat_unit yield (conf, icon, time_str, label, value, tx_hash, quote_text)
def get_card(self, tx_hash, height, conf, timestamp, value, balance): status, status_str = self.app.wallet.get_tx_status( tx_hash, height, conf, timestamp) icon = "atlas://gui/kivy/theming/light/" + TX_ICONS[status] label = self.app.wallet.get_label(tx_hash) if tx_hash else _( 'Pruned transaction outputs') date = timestamp_to_datetime(timestamp) ri = self.cards.get(tx_hash) if ri is None: ri = Factory.HistoryItem() ri.screen = self ri.tx_hash = tx_hash self.cards[tx_hash] = ri ri.icon = icon ri.date = status_str ri.message = label ri.value = value or 0 ri.amount = self.app.format_amount(value, True) if value is not None else '--' ri.confirmations = conf if self.app.fiat_unit and date: rate = self.app.fx.history_rate(date) if rate: s = self.app.fx.value_str(value, rate) ri.quote_text = '' if s is None else s + ' ' + self.app.fiat_unit return ri
def parse_history(self, items): for item in items: tx_hash, conf, value, timestamp, balance = item time_str = _("unknown") if conf > 0: try: time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3] except Exception: time_str = _("error") if conf == -1: time_str = _('Not Verified') icon = "atlas://gui/kivy/theming/light/close" elif conf == 0: time_str = _('Unconfirmed') icon = "atlas://gui/kivy/theming/light/unconfirmed" elif conf < 6: conf = max(1, conf) icon = "atlas://gui/kivy/theming/light/clock{}".format(conf) else: icon = "atlas://gui/kivy/theming/light/confirmed" label = self.app.wallet.get_label(tx_hash) if tx_hash else _('Pruned transaction outputs') date = timestamp_to_datetime(timestamp) quote_text = '' if self.app.fiat_unit and date: rate = run_hook('history_rate', date) if rate: s = run_hook('value_str', value, rate) quote_text = '' if s is None else s + ' ' + self.app.fiat_unit yield (conf, icon, time_str, label, value, tx_hash, quote_text)
def parse_history(self, items): for item in items: tx_hash, conf, value, timestamp, balance = item time_str = _("unknown") if conf > 0: try: time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3] except Exception: time_str = _("error") if conf == -1: time_str = _('unverified') icon = "atlas://gui/kivy/theming/light/close" elif conf == 0: time_str = _('pending') icon = "atlas://gui/kivy/theming/light/unconfirmed" elif conf < 6: conf = max(1, conf) icon = "atlas://gui/kivy/theming/light/clock{}".format(conf) else: icon = "atlas://gui/kivy/theming/light/confirmed" label = self.app.wallet.get_label(tx_hash) if tx_hash else _('Pruned transaction outputs') date = timestamp_to_datetime(timestamp) rate = run_hook('history_rate', date) if self.app.fiat_unit: quote_text = "..." if rate is None else "{0:.3} {1}".format(Decimal(value) / 100000000 * Decimal(rate), self.app.fiat_unit) else: quote_text = '' yield (conf, icon, time_str, label, value, tx_hash, quote_text)
def update_tx_mined_status(self, tx_hash: str, tx_mined_info: TxMinedInfo): try: row = self.transactions.pos_from_key(tx_hash) tx_item = self.transactions[tx_hash] except KeyError: return self.tx_status_cache[tx_hash] = self.parent.wallet.get_tx_status(tx_hash, tx_mined_info) tx_item.update({ 'confirmations': tx_mined_info.conf, 'timestamp': tx_mined_info.timestamp, 'txpos_in_block': tx_mined_info.txpos, 'date': timestamp_to_datetime(tx_mined_info.timestamp), }) topLeft = self.createIndex(row, 0) bottomRight = self.createIndex(row, len(HistoryColumns) - 1) self.dataChanged.emit(topLeft, bottomRight)
def on_update(self): # TODO save and restore scroll position (maybe based on y coord or selected item?) self.wallet = self.parent.wallet h = self.wallet.get_history(self.get_domain()) item = self.currentItem() current_tx = item.data(0, Qt.UserRole) if item else None self.clear() fx = self.parent.fx if fx: fx.history_used_spot = False for h_item in h: tx_hash, height, conf, timestamp, value, balance = h_item status, status_str = self.wallet.get_tx_status( tx_hash, height, conf, timestamp) has_invoice = self.wallet.invoices.paid.get(tx_hash) icon = QIcon(":icons/" + TX_ICONS[status]) v_str = self.parent.format_amount(value, True, whitespaces=True) balance_str = self.parent.format_amount(balance, whitespaces=True) label = self.wallet.get_label(tx_hash) entry = ['', tx_hash, status_str, label, v_str, balance_str] if fx and fx.show_history(): date = timestamp_to_datetime( time.time() if conf <= 0 else timestamp) for amount in [value, balance]: text = fx.historical_value_str(amount, date) entry.append(text) item = QTreeWidgetItem(entry) item.setIcon(0, icon) item.setToolTip( 0, str(conf) + " confirmation" + ("s" if conf != 1 else "")) if has_invoice: item.setIcon(3, QIcon(":icons/seal")) for i in range(len(entry)): if i > 3: item.setTextAlignment(i, Qt.AlignRight) if i != 2: item.setFont(i, QFont(MONOSPACE_FONT)) if value and value < 0: item.setForeground(3, QBrush(QColor("#BC1E1E"))) item.setForeground(4, QBrush(QColor("#BC1E1E"))) if tx_hash: item.setData(0, Qt.UserRole, tx_hash) self.insertTopLevelItem(0, item) if current_tx == tx_hash: self.setCurrentItem(item)
def on_update(self): self.wallet = self.parent.wallet h = self.wallet.get_history(self.get_domain()) item = self.currentItem() current_tx = item.data(0, Qt.UserRole).toString() if item else None self.clear() fx = self.parent.fx fx.history_used_spot = False for h_item in h: tx_hash, height, conf, timestamp, value, balance = h_item status, status_str = self.wallet.get_tx_status( tx_hash, height, conf, timestamp) icon = QIcon(":icons/" + TX_ICONS[status]) v_str = self.parent.format_amount(value, True, whitespaces=True) balance_str = self.parent.format_amount(balance, whitespaces=True) label = self.wallet.get_label(tx_hash) entry = ['', tx_hash, status_str, label, v_str, balance_str] if fx.show_history(): date = timestamp_to_datetime( time.time() if conf <= 0 else timestamp) for amount in [value, balance]: text = fx.historical_value_str(amount, date) entry.append(text) item = QTreeWidgetItem(entry) item.setIcon(0, icon) for i in range(len(entry)): if i > 3: item.setTextAlignment(i, Qt.AlignRight) if i != 2: item.setFont(i, QFont(MONOSPACE_FONT)) if value < 0: item.setForeground(3, QBrush(QColor("#BC1E1E"))) item.setForeground(4, QBrush(QColor("#BC1E1E"))) if tx_hash: item.setData(0, Qt.UserRole, tx_hash) self.insertTopLevelItem(0, item) if current_tx == tx_hash: self.setCurrentItem(item)
def get_card(self, tx_hash, height, conf, timestamp, value, balance): status, status_str = self.app.wallet.get_tx_status(tx_hash, height, conf, timestamp) icon = "atlas://gui/kivy/theming/light/" + TX_ICONS[status] label = self.app.wallet.get_label(tx_hash) if tx_hash else _('Pruned transaction outputs') date = timestamp_to_datetime(timestamp) ri = self.cards.get(tx_hash) if ri is None: ri = Factory.HistoryItem() ri.screen = self ri.tx_hash = tx_hash self.cards[tx_hash] = ri ri.icon = icon ri.date = status_str ri.message = label ri.value = value or 0 ri.value_known = value is not None ri.confirmations = conf if self.app.fiat_unit and date: rate = run_hook('history_rate', date) if rate: s = run_hook('value_str', value, rate) ri.quote_text = '' if s is None else s + ' ' + self.app.fiat_unit return ri
def on_update(self): self.wallet = self.parent.wallet h = self.wallet.get_history(self.get_domain()) item = self.currentItem() current_tx = item.data(0, Qt.UserRole).toString() if item else None self.clear() fx = self.parent.fx fx.history_used_spot = False for h_item in h: tx_hash, height, conf, timestamp, value, balance = h_item status, status_str = self.wallet.get_tx_status(tx_hash, height, conf, timestamp) icon = QIcon(":icons/" + TX_ICONS[status]) v_str = self.parent.format_amount(value, True, whitespaces=True) balance_str = self.parent.format_amount(balance, whitespaces=True) label = self.wallet.get_label(tx_hash) entry = ['', tx_hash, status_str, label, v_str, balance_str] if fx.show_history(): date = timestamp_to_datetime(time.time() if conf <= 0 else timestamp) for amount in [value, balance]: text = fx.historical_value_str(amount, date) entry.append(text) item = QTreeWidgetItem(entry) item.setIcon(0, icon) for i in range(len(entry)): if i>3: item.setTextAlignment(i, Qt.AlignRight) if i!=2: item.setFont(i, QFont(MONOSPACE_FONT)) if value < 0: item.setForeground(3, QBrush(QColor("#BC1E1E"))) item.setForeground(4, QBrush(QColor("#BC1E1E"))) if tx_hash: item.setData(0, Qt.UserRole, tx_hash) self.insertTopLevelItem(0, item) if current_tx == tx_hash: self.setCurrentItem(item)
def timestamp_rate(self, timestamp): from electrum_ltc.util import timestamp_to_datetime date = timestamp_to_datetime(timestamp) return self.history_rate(date)
def on_update(self): self.wallet = self.parent.wallet fx = self.parent.fx r = self.wallet.get_full_history(domain=self.get_domain(), from_timestamp=self.start_timestamp, to_timestamp=self.end_timestamp, fx=fx) self.transactions = r['transactions'] self.summary = r['summary'] if not self.years and self.start_timestamp is None and self.end_timestamp is None: start_date = self.summary['start_date'] end_date = self.summary['end_date'] if start_date and end_date: self.years = [ str(i) for i in range(start_date.year, end_date.year + 1) ] self.period_combo.insertItems(1, self.years) item = self.currentItem() current_tx = item.data(0, Qt.UserRole) if item else None self.clear() if fx: fx.history_used_spot = False for tx_item in self.transactions: tx_hash = tx_item['txid'] height = tx_item['height'] conf = tx_item['confirmations'] timestamp = tx_item['timestamp'] value = tx_item['value'].value balance = tx_item['balance'].value label = tx_item['label'] status, status_str = self.wallet.get_tx_status( tx_hash, height, conf, timestamp) has_invoice = self.wallet.invoices.paid.get(tx_hash) icon = QIcon(":icons/" + TX_ICONS[status]) v_str = self.parent.format_amount(value, True, whitespaces=True) balance_str = self.parent.format_amount(balance, whitespaces=True) entry = ['', tx_hash, status_str, label, v_str, balance_str] fiat_value = None if value is not None and fx and fx.show_history(): date = timestamp_to_datetime( time.time() if conf <= 0 else timestamp) fiat_value = tx_item['fiat_value'].value value_str = fx.format_fiat(fiat_value) entry.append(value_str) # fixme: should use is_mine if value < 0: entry.append( fx.format_fiat(tx_item['acquisition_price'].value)) entry.append(fx.format_fiat(tx_item['capital_gain'].value)) item = QTreeWidgetItem(entry) item.setIcon(0, icon) item.setToolTip( 0, str(conf) + " confirmation" + ("s" if conf != 1 else "")) if has_invoice: item.setIcon(3, QIcon(":icons/seal")) for i in range(len(entry)): if i > 3: item.setTextAlignment(i, Qt.AlignRight) if i != 2: item.setFont(i, QFont(MONOSPACE_FONT)) if value and value < 0: item.setForeground(3, QBrush(QColor("#BC1E1E"))) item.setForeground(4, QBrush(QColor("#BC1E1E"))) if fiat_value and not tx_item['fiat_default']: item.setForeground(6, QBrush(QColor("#1E1EFF"))) if tx_hash: item.setData(0, Qt.UserRole, tx_hash) self.insertTopLevelItem(0, item) if current_tx == tx_hash: self.setCurrentItem(item)
def get_history_rate(self, btc_balance, timestamp): date = timestamp_to_datetime(timestamp) return run_hook('historical_value_str', btc_balance, date)