Beispiel #1
0
 def append_lnaddr(self, it: HTLCItem, lnaddr: LnAddr):
     invoice = HTLCItem(_('Invoice'))
     invoice.appendRow([HTLCItem(_('Remote node public key')), HTLCItem(bh2u(lnaddr.pubkey.serialize()))])
     invoice.appendRow([HTLCItem(_('Amount in sat')), HTLCItem(str(lnaddr.amount * COIN))]) # might have a comma because mSAT!
     invoice.appendRow([HTLCItem(_('Description')), HTLCItem(dict(lnaddr.tags).get('d', _('N/A')))])
     invoice.appendRow([HTLCItem(_('Date')), HTLCItem(format_time(lnaddr.date))])
     it.appendRow([invoice])
Beispiel #2
0
    def update(self):
        _list = self.parent.wallet.get_invoices()
        self.model().clear()
        self.update_headers(self.__class__.headers)
        for idx, item in enumerate(_list):
            invoice_type = item['type']
            if invoice_type == PR_TYPE_LN:
                key = item['rhash']
                icon_name = 'lightning.png'
            elif invoice_type == PR_TYPE_ONCHAIN:
                key = item['id']
                icon_name = 'bitcoin.png'
                if item.get('bip70'):
                    icon_name = 'seal.png'
            else:
                raise Exception('Unsupported type')
            status = item['status']
            status_str = get_request_status(item)  # convert to str
            message = item['message']
            amount = item['amount']
            timestamp = item.get('time', 0)
            date_str = format_time(timestamp) if timestamp else _('Unknown')
            amount_str = self.parent.format_amount(amount, whitespaces=True)
            labels = [date_str, message, amount_str, status_str]
            items = [QStandardItem(e) for e in labels]
            self.set_editability(items)
            items[self.Columns.DATE].setIcon(read_QIcon(icon_name))
            items[self.Columns.STATUS].setIcon(read_QIcon(
                pr_icons.get(status)))
            items[self.Columns.DATE].setData(key, role=ROLE_REQUEST_ID)
            items[self.Columns.DATE].setData(invoice_type,
                                             role=ROLE_REQUEST_TYPE)
            self.model().insertRow(idx, items)

        self.selectionModel().select(self.model().index(0, 0),
                                     QItemSelectionModel.SelectCurrent)
        # sort requests by date
        self.model().sort(self.Columns.DATE)
        # hide list if empty
        if self.parent.isVisible():
            b = self.model().rowCount() > 0
            self.setVisible(b)
            self.parent.invoices_label.setVisible(b)
        self.filter()
Beispiel #3
0
 def get_card(self, tx_item):  #tx_hash, tx_mined_status, value, balance):
     is_lightning = tx_item.get('lightning', False)
     timestamp = tx_item['timestamp']
     key = tx_item.get('txid') or tx_item['payment_hash']
     if is_lightning:
         status = 0
         txpos = tx_item['txpos']
         status_str = 'unconfirmed' if timestamp is None else format_time(
             int(timestamp))
         icon = "atlas://electrum_gzro/gui/kivy/theming/light/lightning"
         message = tx_item['label']
         fee_msat = tx_item['fee_msat']
         fee = int(fee_msat / 1000) if fee_msat else None
         fee_text = '' if fee is None else 'fee: %d sat' % fee
     else:
         tx_hash = tx_item['txid']
         conf = tx_item['confirmations']
         txpos = tx_item['txpos_in_block'] or 0
         height = tx_item['height']
         tx_mined_info = TxMinedInfo(height=tx_item['height'],
                                     conf=tx_item['confirmations'],
                                     timestamp=tx_item['timestamp'])
         status, status_str = self.app.wallet.get_tx_status(
             tx_hash, tx_mined_info)
         icon = "atlas://electrum_gzro/gui/kivy/theming/light/" + TX_ICONS[
             status]
         message = tx_item['label'] or tx_hash
         fee = tx_item['fee_sat']
         fee_text = '' if fee is None else 'fee: %d sat' % fee
     ri = {}
     ri['screen'] = self
     ri['key'] = key
     ri['icon'] = icon
     ri['date'] = status_str
     ri['message'] = message
     ri['fee_text'] = fee_text
     value = tx_item['value'].value
     if value is not None:
         ri['is_mine'] = value <= 0
         ri['amount'] = self.app.format_amount(value, is_diff=True)
         if 'fiat_value' in tx_item:
             ri['quote_text'] = str(tx_item['fiat_value'])
     return ri
Beispiel #4
0
 def update(self):
     self.wallet = self.parent.wallet
     domain = self.wallet.get_receiving_addresses()
     self.parent.update_receive_address_styling()
     self.model().clear()
     self.update_headers(self.__class__.headers)
     for req in self.wallet.get_sorted_requests():
         status = req.get('status')
         if status == PR_PAID:
             continue
         request_type = req['type']
         timestamp = req.get('time', 0)
         expiration = req.get('exp', None)
         amount = req.get('amount')
         message = req.get('message') or req.get('memo')
         date = format_time(timestamp)
         amount_str = self.parent.format_amount(amount) if amount else ""
         status_str = get_request_status(req)
         labels = [date, message, amount_str, status_str]
         if request_type == PR_TYPE_LN:
             key = req['rhash']
             icon = read_QIcon("lightning.png")
             tooltip = 'lightning request'
         elif request_type == PR_TYPE_ONCHAIN:
             key = req['address']
             icon = read_QIcon("bitcoin.png")
             tooltip = 'onchain request'
         items = [QStandardItem(e) for e in labels]
         self.set_editability(items)
         items[self.Columns.DATE].setData(request_type, ROLE_REQUEST_TYPE)
         items[self.Columns.DATE].setData(key, ROLE_KEY)
         items[self.Columns.DATE].setIcon(icon)
         items[self.Columns.STATUS].setIcon(read_QIcon(pr_icons.get(status)))
         items[self.Columns.DATE].setToolTip(tooltip)
         self.model().insertRow(self.model().rowCount(), items)
     self.filter()
     # sort requests by date
     self.model().sort(self.Columns.DATE)
     # hide list if empty
     if self.parent.isVisible():
         b = self.model().rowCount() > 0
         self.setVisible(b)
         self.parent.receive_requests_label.setVisible(b)
Beispiel #5
0
    def data(self, index: QModelIndex, role: Qt.ItemDataRole) -> QVariant:
        # note: this method is performance-critical.
        # it is called a lot, and so must run extremely fast.
        assert index.isValid()
        col = index.column()
        tx_item = self.transactions.value_from_pos(index.row())
        is_lightning = tx_item.get('lightning', False)
        timestamp = tx_item['timestamp']
        if is_lightning:
            status = 0
            txpos = tx_item['txpos']
            if timestamp is None:
                status_str = 'unconfirmed'
            else:
                status_str = format_time(int(timestamp))
        else:
            tx_hash = tx_item['txid']
            conf = tx_item['confirmations']
            txpos = tx_item['txpos_in_block'] or 0
            height = tx_item['height']
            try:
                status, status_str = self.tx_status_cache[tx_hash]
            except KeyError:
                tx_mined_info = self.tx_mined_info_from_tx_item(tx_item)
                status, status_str = self.parent.wallet.get_tx_status(
                    tx_hash, tx_mined_info)

        # we sort by timestamp
        if timestamp is None:
            timestamp = float("inf")

        if role == Qt.UserRole:
            # for sorting
            d = {
                HistoryColumns.STATUS:
                    # height breaks ties for unverified txns
                    # txpos breaks ties for verified same block txns
                    (-timestamp, conf, -status, -height, -txpos) if not is_lightning else (-timestamp, 0,0,0,-txpos),
                HistoryColumns.DESCRIPTION:
                    tx_item['label'] if 'label' in tx_item else None,
                HistoryColumns.AMOUNT:
                    (tx_item['bc_value'].value if 'bc_value' in tx_item else 0)\
                    + (tx_item['ln_value'].value if 'ln_value' in tx_item else 0),
                HistoryColumns.BALANCE:
                    (tx_item['balance'].value if 'balance' in tx_item else 0)\
                    + (tx_item['balance_msat']//1000 if 'balance_msat'in tx_item else 0),
                HistoryColumns.FIAT_VALUE:
                    tx_item['fiat_value'].value if 'fiat_value' in tx_item else None,
                HistoryColumns.FIAT_ACQ_PRICE:
                    tx_item['acquisition_price'].value if 'acquisition_price' in tx_item else None,
                HistoryColumns.FIAT_CAP_GAINS:
                    tx_item['capital_gain'].value if 'capital_gain' in tx_item else None,
                HistoryColumns.TXID: tx_hash if not is_lightning else None,
            }
            return QVariant(d[col])
        if role not in (Qt.DisplayRole, Qt.EditRole):
            if col == HistoryColumns.STATUS and role == Qt.DecorationRole:
                icon = "lightning" if is_lightning else TX_ICONS[status]
                return QVariant(read_QIcon(icon))
            elif col == HistoryColumns.STATUS and role == Qt.ToolTipRole:
                msg = 'lightning transaction' if is_lightning else str(
                    conf) + _(" confirmation" + ("s" if conf != 1 else ""))
                return QVariant(msg)
            elif col > HistoryColumns.DESCRIPTION and role == Qt.TextAlignmentRole:
                return QVariant(Qt.AlignRight | Qt.AlignVCenter)
            elif col != HistoryColumns.STATUS and role == Qt.FontRole:
                monospace_font = QFont(MONOSPACE_FONT)
                return QVariant(monospace_font)
            #elif col == HistoryColumns.DESCRIPTION and role == Qt.DecorationRole and not is_lightning\
            #        and self.parent.wallet.invoices.paid.get(tx_hash):
            #    return QVariant(read_QIcon("seal"))
            elif col in (HistoryColumns.DESCRIPTION, HistoryColumns.AMOUNT) \
                    and role == Qt.ForegroundRole and not is_lightning and tx_item['value'].value < 0:
                red_brush = QBrush(QColor("#BC1E1E"))
                return QVariant(red_brush)
            elif col == HistoryColumns.FIAT_VALUE and role == Qt.ForegroundRole \
                    and not tx_item.get('fiat_default') and tx_item.get('fiat_value') is not None:
                blue_brush = QBrush(QColor("#1E1EFF"))
                return QVariant(blue_brush)
            return QVariant()
        if col == HistoryColumns.STATUS:
            return QVariant(status_str)
        elif col == HistoryColumns.DESCRIPTION and 'label' in tx_item:
            return QVariant(tx_item['label'])
        elif col == HistoryColumns.AMOUNT:
            bc_value = tx_item['bc_value'].value if 'bc_value' in tx_item else 0
            ln_value = tx_item['ln_value'].value if 'ln_value' in tx_item else 0
            value = bc_value + ln_value
            v_str = self.parent.format_amount(value,
                                              is_diff=True,
                                              whitespaces=True)
            return QVariant(v_str)
        elif col == HistoryColumns.BALANCE:
            balance = tx_item['balance'].value
            balance_str = self.parent.format_amount(balance, whitespaces=True)
            return QVariant(balance_str)
        elif col == HistoryColumns.FIAT_VALUE and 'fiat_value' in tx_item:
            value_str = self.parent.fx.format_fiat(tx_item['fiat_value'].value)
            return QVariant(value_str)
        elif col == HistoryColumns.FIAT_ACQ_PRICE and \
                tx_item['value'].value < 0 and 'acquisition_price' in tx_item:
            # fixme: should use is_mine
            acq = tx_item['acquisition_price'].value
            return QVariant(self.parent.fx.format_fiat(acq))
        elif col == HistoryColumns.FIAT_CAP_GAINS and 'capital_gain' in tx_item:
            cg = tx_item['capital_gain'].value
            return QVariant(self.parent.fx.format_fiat(cg))
        elif col == HistoryColumns.TXID:
            return QVariant(tx_hash)
        return QVariant()