Exemple #1
0
 def get_tx_height(self, txid):
     # because we use a current timestamp, and history is empty,
     # FxThread.history_rate will use spot prices
     return TxMinedStatus(height=10,
                          conf=10,
                          timestamp=time.time(),
                          header_hash='def')
Exemple #2
0
    def on_update(self):
        wallet = self.parent.wallet
        item = self.currentItem()
        current_key = item.data(0, Qt.UserRole) if item else None
        self.clear()
        for hist in wallet.get_token_history():
            _from, to, amount, token, txid, height, conf, timestamp, call_index, log_index = hist
            payout = False
            if _from == to:
                amount = 0
            if hash160_to_p2pkh(binascii.a2b_hex(to)) == token.bind_addr:
                balance_str = '+'
            else:
                balance_str = '-'
                payout = True
            balance_str += '{}'.format(amount / 10**token.decimals)
            tx_mined_status = TxMinedStatus(height, conf, timestamp, None)
            status, status_str = wallet.get_tx_status(txid, tx_mined_status)
            icon = read_QIcon(TX_ICONS[status])

            item = QTreeWidgetItem(
                ['', status_str, token.bind_addr, token.symbol, balance_str])
            item.setIcon(0, icon)
            item.setToolTip(
                0,
                str(conf) + " confirmation" + ("s" if conf != 1 else ""))
            item.setData(0, Qt.UserRole, txid)
            item.setTextAlignment(0, Qt.AlignLeft | Qt.AlignVCenter)
            self.addTopLevelItem(item)
            if txid == current_key:
                self.setCurrentItem(item)
            if payout:
                item.setForeground(3, QBrush(QColor("#BC1E1E")))
                item.setForeground(4, QBrush(QColor("#BC1E1E")))
        run_hook('update_token_hist_tab', self)
Exemple #3
0
 def insert_tx(self, tx_item):
     fx = self.parent.fx
     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']
     tx_mined_status = TxMinedStatus(height, conf, timestamp, None)
     status, status_str = self.wallet.get_tx_status(tx_hash,
                                                    tx_mined_status)
     has_invoice = self.wallet.invoices.paid.get(tx_hash)
     v_str = self.parent.format_amount(value,
                                       is_diff=True,
                                       whitespaces=True)
     balance_str = self.parent.format_amount(balance, whitespaces=True)
     entry = ['', status_str, label, v_str, balance_str]
     item = [QStandardItem(e) for e in entry]
     item[3].setData(value, self.SORT_ROLE)
     item[4].setData(balance, self.SORT_ROLE)
     if has_invoice:
         item[2].setIcon(self.icon_cache.get(":icons/seal"))
     for i in range(len(entry)):
         self.set_item_properties(item[i], i, tx_hash)
     if value and value < 0:
         item[2].setForeground(self.red_brush)
         item[3].setForeground(self.red_brush)
     self.txid_to_items[tx_hash] = item
     self.update_item(tx_hash, self.wallet.get_tx_height(tx_hash))
     source_row_idx = self.std_model.rowCount()
     self.std_model.insertRow(source_row_idx, item)
     new_idx = self.std_model.index(source_row_idx, 0)
     history = fx.show_history()
     if history:
         self.update_fiat(tx_hash, tx_item)
     self.hide_row(self.proxy.mapFromSource(new_idx).row())
 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.transactions:
         from datetime import date
         start_date = self.transactions[0].get('date') or date.today()
         end_date = self.transactions[-1].get('date') or date.today()
         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
     blue_brush = QBrush(QColor("#1E1EFF"))
     red_brush = QBrush(QColor("#BC1E1E"))
     monospace_font = QFont(MONOSPACE_FONT)
     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']
         tx_mined_status = TxMinedStatus(height, conf, timestamp, None)
         status, status_str = self.wallet.get_tx_status(
             tx_hash, tx_mined_status)
         has_invoice = self.wallet.invoices.paid.get(tx_hash)
         icon = self.icon_cache.get(":icons/" + TX_ICONS[status])
         v_str = self.parent.format_amount(value,
                                           is_diff=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():
             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 = SortableTreeWidgetItem(entry)
         item.setIcon(0, icon)
         item.setToolTip(
             0,
             str(conf) + " confirmation" + ("s" if conf != 1 else ""))
         item.setData(0, SortableTreeWidgetItem.DataRole, (status, conf))
         if has_invoice:
             item.setIcon(3, self.icon_cache.get(":icons/seal"))
         for i in range(len(entry)):
             if i > 3:
                 item.setTextAlignment(i, Qt.AlignRight | Qt.AlignVCenter)
             if i != 2:
                 item.setFont(i, monospace_font)
         if value and value < 0:
             item.setForeground(3, red_brush)
             item.setForeground(4, red_brush)
         if fiat_value and not tx_item['fiat_default']:
             item.setForeground(6, blue_brush)
         if tx_hash:
             item.setData(0, Qt.UserRole, tx_hash)
         self.insertTopLevelItem(0, item)
         if current_tx == tx_hash:
             self.setCurrentItem(item)