예제 #1
0
    def get_exported_data(self):
        history = self.wallet.get_history()
        lines = [[
            "transaction_hash", "label", "confirmations", "value", "timestamp"
        ]]
        for item in history:
            tx_hash, height, confirmations, timestamp, value, balance = item
            if height > 0:
                if timestamp is not None:
                    time_string = format_time(timestamp)
                else:
                    time_string = _("unverified")
            else:
                time_string = _("unconfirmed")

            if value is not None:
                value_string = format_satoshis(value, True)
            else:
                value_string = '--'

            if tx_hash:
                label = self.wallet.get_label(tx_hash)
            else:
                label = ""

            lines.append(
                [tx_hash, label, confirmations, value_string, time_string])
        return lines
예제 #2
0
 def update(self):
     inv_list = self.parent.invoices.unpaid_invoices()
     self.model().clear()
     self.update_headers([
         _('Expires'),
         _('Requestor'),
         _('Description'),
         _('Amount'),
         _('Status')
     ])
     self.header().setSectionResizeMode(1, QHeaderView.Interactive)
     for idx, pr in enumerate(inv_list):
         key = pr.get_id()
         status = self.parent.invoices.get_status(key)
         requestor = pr.get_requestor()
         exp = pr.get_expiration_date()
         date_str = format_time(exp) if exp else _('Never')
         labels = [
             date_str, requestor, pr.memo,
             self.parent.format_amount(pr.get_amount(), whitespaces=True),
             pr_tooltips.get(status, '')
         ]
         items = [QStandardItem(e) for e in labels]
         self.set_editability(items)
         items[4].setIcon(self.icon_cache.get(pr_icons.get(status)))
         items[0].setData(key, role=Qt.UserRole)
         items[1].setFont(QFont(MONOSPACE_FONT))
         items[3].setFont(QFont(MONOSPACE_FONT))
         self.model().insertRow(idx, items)
     self.selectionModel().select(self.model().index(0, 0),
                                  QItemSelectionModel.SelectCurrent)
     if self.parent.isVisible():
         b = len(inv_list) > 0
         self.setVisible(b)
         self.parent.invoices_label.setVisible(b)
예제 #3
0
    def update(self):
        self.menu_actions = [('Pay', self.do_pay), ('Details', self.do_view),
                             ('Delete', self.do_delete)]
        invoices_list = self.screen.ids.invoices_container
        invoices_list.clear_widgets()

        _list = self.app.invoices.sorted_list()
        for pr in _list:
            ci = Factory.InvoiceItem()
            ci.key = pr.get_id()
            ci.requestor = pr.get_requestor()
            ci.memo = pr.get_memo()
            amount = pr.get_amount()
            if amount:
                ci.amount = self.app.format_amount_and_units(amount)
                status = self.app.invoices.get_status(ci.key)
                ci.status = invoice_text[status]
                ci.icon = pr_icon[status]
            else:
                ci.amount = _('No Amount')
                ci.status = ''
            exp = pr.get_expiration_date()
            ci.date = format_time(exp) if exp else _('Never')
            ci.screen = self
            invoices_list.add_widget(ci)

        if not _list:
            msg = _(
                'This screen shows the list of payment requests that have been sent to you. You may also use it to store contact addresses.'
            )
            invoices_list.add_widget(EmptyLabel(text=msg))
예제 #4
0
    def update(self):

        self.menu_actions = [(_('Show'), self.do_show), (_('Delete'), self.do_delete)]

        requests_list = self.screen.ids.requests_container
        requests_list.clear_widgets()
        for req in self.app.wallet.get_sorted_requests(self.app.electrum_config):
            address = req['address']
            timestamp = req.get('time', 0)
            amount = req.get('amount')
            expiration = req.get('exp', None)
            status = req.get('status')
            signature = req.get('sig')
            ci = Factory.RequestItem()
            ci.address = req['address']
            ci.memo = self.app.wallet.get_label(address)
            status = req.get('status')
            if status == PR_PAID:
                ci.icon = "atlas://gui/kivy/theming/light/confirmed"
            elif status == PR_EXPIRED:
                ci.icon = "atlas://gui/kivy/theming/light/important"
            else:
                ci.icon = "atlas://gui/kivy/theming/light/important"
            ci.amount = self.app.format_amount_and_units(amount) if amount else ''
            ci.date = format_time(timestamp)
            ci.screen = self
            requests_list.add_widget(ci)
예제 #5
0
    def update(self):
        self.menu_actions = [('Pay', self.do_pay), ('Details', self.do_view), ('Delete', self.do_delete)]
        invoices_list = self.screen.ids.invoices_container
        invoices_list.clear_widgets()

        _list = self.app.invoices.sorted_list()
        for pr in _list:
            ci = Factory.InvoiceItem()
            ci.key = pr.get_id()
            ci.requestor = pr.get_requestor()
            ci.memo = pr.get_memo()
            amount = pr.get_amount()
            if amount:
                ci.amount = self.app.format_amount_and_units(amount)
                status = self.app.invoices.get_status(ci.key)
                ci.status = invoice_text[status]
                ci.icon = pr_icon[status]
            else:
                ci.amount = _('No Amount')
                ci.status = ''
            exp = pr.get_expiration_date()
            ci.date = format_time(exp) if exp else _('Never')
            ci.screen = self
            invoices_list.add_widget(ci)

        if not _list:
            msg = _('This screen shows the list of payment requests that have been sent to you. You may also use it to store contact addresses.')
            invoices_list.add_widget(EmptyLabel(text=msg))
예제 #6
0
    def update(self):
        if self._wallet is None:
            self._logger.error('wallet undefined')
            return

        if self._key not in self._wallet.wallet.lnworker.payment_info:
            self._logger.error('payment_hash not found')
            return

        # TODO this is horribly inefficient. need a payment getter/query method
        tx = self._wallet.wallet.lnworker.get_lightning_history()[bfh(
            self._key)]
        self._logger.debug(str(tx))

        self._fee = QEAmount() if not tx['fee_msat'] else QEAmount(
            amount_msat=tx['fee_msat'])
        self._amount = QEAmount(amount_msat=tx['amount_msat'])
        self._label = tx['label']
        self._date = format_time(tx['timestamp'])
        self._status = 'settled'  # TODO: other states? get_lightning_history is deciding the filter for us :(
        self._phash = tx['payment_hash']
        self._preimage = tx['preimage']

        invoice = (self._wallet.wallet.get_invoice(self._key)
                   or self._wallet.wallet.get_request(self._key))
        self._logger.debug(str(invoice))
        if invoice:
            self._invoice = invoice.lightning_invoice or ''
        else:
            self._invoice = ''

        self.detailsChanged.emit()
예제 #7
0
    def get_card(self, req):
        address = req['address']
        timestamp = req.get('time', 0)
        amount = req.get('amount')
        expiration = req.get('exp', None)
        status = req.get('status')
        signature = req.get('sig')

        ci = self.cards.get(address)
        if ci is None:
            ci = Factory.RequestItem()
            ci.screen = self
            ci.address = address
            self.cards[address] = ci

        ci.memo = self.app.wallet.get_label(address)
        if amount:
            status = req.get('status')
            ci.status = request_text[status]
        else:
            received = self.app.wallet.get_addr_received(address)
            ci.status = self.app.format_amount_and_units(amount)
        ci.icon = pr_icon[status]
        ci.amount = self.app.format_amount_and_units(amount) if amount else _(
            'No Amount')
        ci.date = format_time(timestamp)
        return ci
예제 #8
0
 def update(self):
     inv_list = self.parent.invoices.unpaid_invoices()
     self.model().clear()
     self.update_headers(self.__class__.headers)
     self.header().setSectionResizeMode(self.Columns.REQUESTOR,
                                        QHeaderView.Interactive)
     for idx, pr in enumerate(inv_list):
         key = pr.get_id()
         status = self.parent.invoices.get_status(key)
         requestor = pr.get_requestor()
         exp = pr.get_expiration_date()
         date_str = format_time(exp) if exp else _('Never')
         labels = [
             date_str, requestor, pr.memo,
             self.parent.format_amount(pr.get_amount(), whitespaces=True),
             pr_tooltips.get(status, '')
         ]
         items = [QStandardItem(e) for e in labels]
         self.set_editability(items)
         items[self.Columns.STATUS].setIcon(read_QIcon(
             pr_icons.get(status)))
         items[self.Columns.DATE].setData(key, role=Qt.UserRole)
         items[self.Columns.REQUESTOR].setFont(QFont(MONOSPACE_FONT))
         items[self.Columns.AMOUNT].setFont(QFont(MONOSPACE_FONT))
         self.model().insertRow(idx, items)
     self.selectionModel().select(self.model().index(0, 0),
                                  QItemSelectionModel.SelectCurrent)
     if self.parent.isVisible():
         b = len(inv_list) > 0
         self.setVisible(b)
         self.parent.invoices_label.setVisible(b)
예제 #9
0
    def update(self):

        self.menu_actions = [(_("Show"), self.do_show), (_("Delete"), self.do_delete)]
        requests_list = self.screen.ids.requests_container
        requests_list.clear_widgets()
        _list = self.app.wallet.get_sorted_requests(self.app.electrum_config)
        for req in _list:
            address = req["address"]
            timestamp = req.get("time", 0)
            amount = req.get("amount")
            expiration = req.get("exp", None)
            status = req.get("status")
            signature = req.get("sig")
            ci = Factory.RequestItem()
            ci.address = req["address"]
            ci.memo = self.app.wallet.get_label(address)
            status = req.get("status")
            if status == PR_PAID:
                ci.icon = "atlas://gui/kivy/theming/light/confirmed"
            elif status == PR_EXPIRED:
                ci.icon = "atlas://gui/kivy/theming/light/important"
            else:
                ci.icon = "atlas://gui/kivy/theming/light/important"
            ci.amount = self.app.format_amount_and_units(amount) if amount else ""
            ci.date = format_time(timestamp)
            ci.screen = self
            requests_list.add_widget(ci)

        if not _list:
            msg = _("This screen shows the list of payment requests you made.")
            requests_list.add_widget(EmptyLabel(text=msg))
예제 #10
0
    def update(self):
        self.menu_actions = [(_("Pay"), self.do_pay), (_("Delete"), self.do_delete)]
        invoices_list = self.screen.ids.invoices_container
        invoices_list.clear_widgets()

        _list = self.app.invoices.sorted_list()
        for pr in _list:
            ci = Factory.InvoiceItem()
            ci.key = pr.get_id()
            ci.requestor = pr.get_requestor()
            ci.memo = pr.memo
            ci.amount = self.app.format_amount_and_units(pr.get_amount())
            status = self.app.invoices.get_status(ci.key)
            if status == PR_PAID:
                ci.icon = "atlas://gui/kivy/theming/light/confirmed"
            elif status == PR_EXPIRED:
                ci.icon = "atlas://gui/kivy/theming/light/important"
            else:
                ci.icon = "atlas://gui/kivy/theming/light/important"
            exp = pr.get_expiration_date()
            ci.date = format_time(exp) if exp else _("Never")
            ci.screen = self
            invoices_list.add_widget(ci)

        if not _list:
            msg = _("This screen shows the list of payment requests that have been sent to you.")
            invoices_list.add_widget(EmptyLabel(text=msg))
예제 #11
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/gui/kivy/theming/light/lightning"
         message = tx_item['label']
     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/gui/kivy/theming/light/" + TX_ICONS[status]
         message = tx_item['label'] or tx_hash
     ri = {}
     ri['screen'] = self
     ri['key'] = key
     ri['icon'] = icon
     ri['date'] = status_str
     ri['message'] = message
     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
예제 #12
0
    def get_card(self, req):
        address = req['address']
        timestamp = req.get('time', 0)
        amount = req.get('amount')
        expiration = req.get('exp', None)
        status = req.get('status')
        signature = req.get('sig')

        ci = self.cards.get(address)
        if ci is None:
            ci = Factory.RequestItem()
            ci.screen = self
            ci.address = address
            self.cards[address] = ci

        ci.memo = self.app.wallet.get_label(address)
        if amount:
            status = req.get('status')
            ci.status = request_text[status]
        else:
            received = self.app.wallet.get_addr_received(address)
            ci.status = self.app.format_amount_and_units(amount)
        ci.icon = pr_icon[status]
        ci.amount = self.app.format_amount_and_units(amount) if amount else _('No Amount')
        ci.date = format_time(timestamp)
        return ci
예제 #13
0
 def update(self):
     # not calling maybe_defer_update() as it interferes with conditional-visibility
     self.proxy.setDynamicSortFilter(False)  # temp. disable re-sorting after every change
     self.std_model.clear()
     self.update_headers(self.__class__.headers)
     for idx, item in enumerate(self.wallet.get_unpaid_invoices()):
         key = self.wallet.get_key_for_outgoing_invoice(item)
         if item.is_lightning():
             icon_name = 'lightning.png'
         else:
             icon_name = 'bitcoin.png'
             if item.bip70:
                 icon_name = 'seal.png'
         status = self.wallet.get_invoice_status(item)
         status_str = item.get_status_str(status)
         message = item.message
         amount = item.get_amount_sat()
         timestamp = item.time or 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(item.type, role=ROLE_REQUEST_TYPE)
         items[self.Columns.DATE].setData(timestamp, role=ROLE_SORT_ORDER)
         self.std_model.insertRow(idx, items)
     self.filter()
     self.proxy.setDynamicSortFilter(True)
     # sort requests by date
     self.sortByColumn(self.Columns.DATE, Qt.DescendingOrder)
     self.hide_if_empty()
예제 #14
0
    def update(self):

        self.menu_actions = [('Show', self.do_show),
                             ('Delete', self.do_delete)]
        requests_list = self.screen.ids.requests_container
        requests_list.clear_widgets()
        _list = self.app.wallet.get_sorted_requests(self.app.electrum_config)
        for req in _list:
            address = req['address']
            timestamp = req.get('time', 0)
            amount = req.get('amount')
            expiration = req.get('exp', None)
            status = req.get('status')
            signature = req.get('sig')
            ci = Factory.RequestItem()
            ci.address = req['address']
            ci.memo = self.app.wallet.get_label(address)
            status = req.get('status')
            ci.status = pr_text[status]
            ci.icon = pr_icon[status]
            ci.amount = self.app.format_amount_and_units(
                amount) if amount else ''
            ci.date = format_time(timestamp)
            ci.screen = self
            requests_list.add_widget(ci)

        if not _list:
            msg = _('This screen shows the list of payment requests you made.')
            requests_list.add_widget(EmptyLabel(text=msg))
예제 #15
0
    def update(self):

        self.menu_actions = [('Show', self.do_show), ('Details', self.do_view), ('Delete', self.do_delete)]

        requests_list = self.screen.ids.requests_container
        requests_list.clear_widgets()
        _list = self.app.wallet.get_sorted_requests(self.app.electrum_config)
        for req in _list:
            address = req['address']
            timestamp = req.get('time', 0)
            amount = req.get('amount')
            expiration = req.get('exp', None)
            status = req.get('status')
            signature = req.get('sig')

            ci = Factory.RequestItem()
            ci.address = address
            ci.memo = self.app.wallet.get_label(address)
            if amount:
                status = req.get('status')
                ci.status = request_text[status]
            else:
                received = self.app.wallet.get_addr_received(address)
                ci.status = self.app.format_amount_and_units(amount)

            ci.icon = pr_icon[status]
            ci.amount = self.app.format_amount_and_units(amount) if amount else _('No Amount')
            ci.date = format_time(timestamp)
            ci.screen = self
            requests_list.add_widget(ci)

        if not _list:
            msg = _('This screen shows the list of payment requests you made.')
            requests_list.add_widget(EmptyLabel(text=msg))
예제 #16
0
 def update(self):
     inv_list = self.parent.invoices.unpaid_invoices()
     self.model().clear()
     self.update_headers(self.__class__.headers)
     self.header().setSectionResizeMode(self.Columns.REQUESTOR, QHeaderView.Interactive)
     for idx, pr in enumerate(inv_list):
         key = pr.get_id()
         status = self.parent.invoices.get_status(key)
         if status is None:
             continue
         requestor = pr.get_requestor()
         exp = pr.get_expiration_date()
         date_str = format_time(exp) if exp else _('Never')
         labels = [date_str, requestor, pr.memo, self.parent.format_amount(pr.get_amount(), whitespaces=True), pr_tooltips.get(status,'')]
         items = [QStandardItem(e) for e in labels]
         self.set_editability(items)
         items[self.Columns.STATUS].setIcon(read_QIcon(pr_icons.get(status)))
         items[self.Columns.DATE].setData(key, role=Qt.UserRole)
         items[self.Columns.REQUESTOR].setFont(QFont(MONOSPACE_FONT))
         items[self.Columns.AMOUNT].setFont(QFont(MONOSPACE_FONT))
         self.model().insertRow(idx, items)
     self.selectionModel().select(self.model().index(0,0), QItemSelectionModel.SelectCurrent)
     if self.parent.isVisible():
         b = len(inv_list) > 0
         self.setVisible(b)
         self.parent.invoices_label.setVisible(b)
예제 #17
0
 def update(self):
     current_key = self.get_current_key()
     # not calling maybe_defer_update() as it interferes with conditional-visibility
     self.proxy.setDynamicSortFilter(False)  # temp. disable re-sorting after every change
     self.std_model.clear()
     self.update_headers(self.__class__.headers)
     for req in self.wallet.get_unpaid_requests():
         key = self.wallet.get_key_for_receive_request(req)
         status = self.wallet.get_request_status(key)
         status_str = req.get_status_str(status)
         timestamp = req.get_time()
         amount = req.get_amount_sat()
         message = req.get_message()
         date = format_time(timestamp)
         amount_str = self.parent.format_amount(amount) if amount else ""
         labels = [date, message, amount_str, status_str]
         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].setData(timestamp, ROLE_SORT_ORDER)
         items[self.Columns.STATUS].setIcon(read_QIcon(pr_icons.get(status)))
         self.std_model.insertRow(self.std_model.rowCount(), items)
     self.filter()
     self.proxy.setDynamicSortFilter(True)
     # sort requests by date
     self.sortByColumn(self.Columns.DATE, Qt.DescendingOrder)
     self.hide_if_empty()
     if current_key is not None:
         self.set_current_key(current_key)
예제 #18
0
 def format_time(self, vtime):
     try:
         itime = int(vtime)
         if itime <= 0:
             raise Exception()
         return format_time(itime)
     except Exception as e:
         return ""
예제 #19
0
    def update(self):
        self.wallet = self.parent.wallet
        # hide receive tab if no receive requests available
        if self.parent.isVisible():
            b = len(self.wallet.receive_requests) > 0
            self.setVisible(b)
            self.parent.receive_requests_label.setVisible(b)
            if not b:
                self.parent.expires_label.hide()
                self.parent.expires_combo.show()

        # update the receive address if necessary
        current_address = self.parent.receive_address_e.text()
        domain = self.wallet.get_receiving_addresses()
        try:
            addr = self.wallet.get_unused_address()
        except InternalAddressCorruption as e:
            self.parent.show_error(str(e))
            addr = ''
        if not current_address in domain and addr:
            self.parent.set_receive_address(addr)
        self.parent.new_request_button.setEnabled(addr != current_address)

        self.model().clear()
        self.update_headers([
            _('Date'),
            _('Address'), '',
            _('Description'),
            _('Amount'),
            _('Status')
        ])
        self.hideColumn(1)  # hide address column
        for req in self.wallet.get_sorted_requests(self.config):
            address = req['address']
            if address not in domain:
                continue
            timestamp = req.get('time', 0)
            amount = req.get('amount')
            expiration = req.get('exp', None)
            message = req['memo']
            date = format_time(timestamp)
            status = req.get('status')
            signature = req.get('sig')
            requestor = req.get('name', '')
            amount_str = self.parent.format_amount(amount) if amount else ""
            labels = [
                date, address, '', message, amount_str,
                pr_tooltips.get(status, '')
            ]
            items = [QStandardItem(e) for e in labels]
            self.set_editability(items)
            if signature is not None:
                items[2].setIcon(self.icon_cache.get(":icons/seal.png"))
                items[2].setToolTip('signed by ' + requestor)
            if status is not PR_UNKNOWN:
                items[5].setIcon(self.icon_cache.get(pr_icons.get(status)))
            items[3].setData(address, Qt.UserRole)
            self.model().insertRow(self.model().rowCount(), items)
예제 #20
0
 def update(self):
     # not calling maybe_defer_update() as it interferes with conditional-visibility
     self.parent.update_receive_address_styling()
     self.proxy.setDynamicSortFilter(
         False)  # temp. disable re-sorting after every change
     self.std_model.clear()
     self.update_headers(self.__class__.headers)
     for req in self.wallet.get_unpaid_requests():
         if req.is_lightning():
             assert isinstance(req, LNInvoice)
             key = req.rhash
         else:
             assert isinstance(req, OnchainInvoice)
             key = req.id
         status = self.parent.wallet.get_request_status(key)
         status_str = req.get_status_str(status)
         request_type = req.type
         timestamp = req.time
         amount = req.get_amount_sat()
         message = req.message
         date = format_time(timestamp)
         amount_str = self.parent.format_amount(amount) if amount else ""
         labels = [date, message, amount_str, status_str]
         if req.is_lightning():
             assert isinstance(req, LNInvoice)
             key = req.rhash
             icon = read_QIcon("lightning.png")
             tooltip = 'lightning request'
         else:
             assert isinstance(req, OnchainInvoice)
             key = req.get_address()
             icon = read_QIcon("qtum.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].setData(timestamp, ROLE_SORT_ORDER)
         items[self.Columns.DATE].setIcon(icon)
         items[self.Columns.STATUS].setIcon(read_QIcon(
             pr_icons.get(status)))
         items[self.Columns.DATE].setToolTip(tooltip)
         self.std_model.insertRow(self.std_model.rowCount(), items)
     self.filter()
     self.proxy.setDynamicSortFilter(True)
     # sort requests by date
     self.sortByColumn(self.Columns.DATE, Qt.DescendingOrder)
     # hide list if empty
     if self.parent.isVisible():
         b = self.std_model.rowCount() > 0
         self.setVisible(b)
         self.parent.receive_requests_label.setVisible(b)
         if not b:
             # list got hidden, so selected item should also be cleared:
             self.item_changed(None)
예제 #21
0
    def invoice_to_model(self, invoice: Invoice):
        item = self.get_invoice_as_dict(invoice)
        #item['key'] = invoice.get_id()
        item['is_lightning'] = invoice.is_lightning()
        if invoice.is_lightning() and 'address' not in item:
            item['address'] = ''
        item['date'] = format_time(item['timestamp'])
        item['amount'] = QEAmount(from_invoice=invoice)
        item['onchain_fallback'] = invoice.is_lightning() and invoice._lnaddr.get_fallback_address()
        item['type'] = 'invoice'

        return item
예제 #22
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(self.config):
         status = req.get('status')
         if status == PR_PAID:
             continue
         request_type = REQUEST_TYPE_LN if req.get(
             'lightning', False) else REQUEST_TYPE_BITCOIN
         timestamp = req.get('time', 0)
         amount = req.get('amount')
         message = req['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]
         items = [QStandardItem(e) for e in labels]
         self.set_editability(items)
         items[self.Columns.DATE].setData(request_type, ROLE_REQUEST_TYPE)
         items[self.Columns.STATUS].setIcon(read_QIcon(
             pr_icons.get(status)))
         if request_type == REQUEST_TYPE_LN:
             items[self.Columns.DATE].setData(req['rhash'],
                                              ROLE_RHASH_OR_ADDR)
             items[self.Columns.DATE].setIcon(read_QIcon("lightning.png"))
             items[self.Columns.DATE].setData(REQUEST_TYPE_LN,
                                              ROLE_REQUEST_TYPE)
         else:
             address = req['address']
             if address not in domain:
                 continue
             expiration = req.get('exp', None)
             signature = req.get('sig')
             requestor = req.get('name', '')
             items[self.Columns.DATE].setData(address, ROLE_RHASH_OR_ADDR)
             if signature is not None:
                 items[self.Columns.DATE].setIcon(read_QIcon("seal.png"))
                 items[self.Columns.DATE].setToolTip(
                     f'signed by {requestor}')
             else:
                 items[self.Columns.DATE].setIcon(read_QIcon("bitcoin.png"))
         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)
 def on_update(self):
     #self.out_vote = self.parent.get_out_vote()
     #self.print_error("out_vote : ", self.out_vote)
     item = self.currentItem()
     current_key = item.data(6, Qt.UserRole) if item else None
     self.clear()
     #self.print_error("bill :", self.bill_list)
     self.print_error("status :", self.status)
     self.print_error("voted :", self.voter_ls)
     if self.status == 1:
         tmp_ls = self.voter_ls
     else:
         tmp_ls = self.bill_list
     if len(tmp_ls):
         for each in tmp_ls:
             item = QTreeWidgetItem(self)
             if (self.selected_list
                     and each.get('id') == self.selected_list[0].get('id')):
                 item.setCheckState(0, Qt.Checked)
             else:
                 item.setCheckState(0, Qt.Unchecked)
             item.setText(1, each.get('title'))
             item.setText(2, each.get('detail'))
             item.setText(3, each.get('url'))
             item.setText(4, format_time(each.get('endtime')))
             filter_button = QComboBox(self)
             filter_button.currentIndexChanged.connect(self.toggle_filter)
             #self.connect(filter_button, QtCore.SIGNAL("currentIndexChanged(int)"), self.toggle_filter)
             for option in each.get('options'):
                 filter_button.addItem(option.get('option'))
             if (self.selected_list
                     and each.get('id') == self.selected_list[0].get('id')):
                 filter_button.setCurrentIndex(
                     self.selected_list[0].get('index'))
             #if hasattr(each, 'index'): # myvote bill
             #filter_button.setCurrentIndex(each.get('index'))
             if (self.status == 1):
                 self.print_error("each :", each)
                 if 'index' in each:  # myvote bill
                     item.setText(5, each.get('index'))
             else:
                 self.setItemWidget(item, 5, filter_button)
             item.setText(6, each.get('id'))
             item.setText(7, str(each.get('endtime')))
             if (each.get('endtime') <= (int(time.time()))):
                 for i in range(8):
                     item.setBackground(i, QColor('red'))
             #item = QTreeWidgetItem([each.get('title'), each.get('detail'), each.get('url'), format_time(each.get('endtime')), json.dumps(each.get('options'), indent=4)])
             self.addTopLevelItem(item)
             if each.get('id') == current_key:
                 self.setCurrentItem(item)
     self.print_error("selected :", self.selected_list)
예제 #24
0
    def update(self):
        _list = self.parent.wallet.get_invoices()
        # filter out paid invoices unless we have the log
        lnworker_logs = self.parent.wallet.lnworker.logs if self.parent.wallet.lnworker else {}
        _list = [
            x for x in _list if x and x.get('status') != PR_PAID
            or x.get('rhash') in lnworker_logs
        ]
        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, status_str = get_request_status(item)
            message = item['message']
            amount = item['amount']
            timestamp = item.get('time', 0)
            date_str = format_time(timestamp) if timestamp else _('Unknown')
            txtype_str = TxType.NONVAULT.name if 'txtype' not in item else item[
                'txtype']
            txtype_str = TX_TYPES_DISPLAY_MAP[txtype_str]
            amount_str = self.parent.format_amount(amount, whitespaces=True)
            labels = [date_str, message, txtype_str, 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()
예제 #25
0
 def update(self):
     invoices_list = self.screen.ids.invoices_container
     invoices_list.clear_widgets()
     for pr in self.app.invoices.sorted_list():
         ci = Factory.InvoiceItem()
         ci.key = pr.get_id()
         ci.requestor = pr.get_requestor()
         ci.memo = pr.memo
         ci.amount = self.app.format_amount(pr.get_amount())
         #ci.status = self.invoices.get_status(key)
         exp = pr.get_expiration_date()
         ci.date = format_time(exp) if exp else _('Never')
         invoices_list.add_widget(ci)
예제 #26
0
    def update(self):
        self.wallet = self.parent.wallet
        # hide receive tab if no receive requests available
        if self.parent.isVisible():
            b = len(self.wallet.receive_requests) > 0
            self.setVisible(b)
            self.parent.receive_requests_label.setVisible(b)
            if not b:
                self.parent.expires_label.hide()
                self.parent.expires_combo.show()

        # update the receive address if necessary
        current_address = self.parent.receive_address_e.text()
        domain = self.wallet.get_receiving_addresses()
        try:
            addr = self.wallet.get_unused_address()
        except InternalAddressCorruption as e:
            self.parent.show_error(str(e))
            addr = ''
        if not current_address in domain and addr:
            self.parent.set_receive_address(addr)
        self.parent.new_request_button.setEnabled(addr != current_address)

        self.model().clear()
        self.update_headers(self.__class__.headers)
        self.hideColumn(self.Columns.ADDRESS)
        for req in self.wallet.get_sorted_requests(self.config):
            address = req['address']
            if address not in domain:
                continue
            timestamp = req.get('time', 0)
            amount = req.get('amount')
            expiration = req.get('exp', None)
            message = req['memo']
            date = format_time(timestamp)
            status = req.get('status')
            signature = req.get('sig')
            requestor = req.get('name', '')
            amount_str = self.parent.format_amount(amount) if amount else ""
            labels = [date, address, '', message, amount_str, pr_tooltips.get(status,'')]
            items = [QStandardItem(e) for e in labels]
            self.set_editability(items)
            if signature is not None:
                items[self.Columns.SIGNATURE].setIcon(read_QIcon("seal.png"))
                items[self.Columns.SIGNATURE].setToolTip(f'signed by {requestor}')
            if status is not PR_UNKNOWN:
                items[self.Columns.STATUS].setIcon(read_QIcon(pr_icons.get(status)))
            items[self.Columns.DESCRIPTION].setData(address, Qt.UserRole)
            self.model().insertRow(self.model().rowCount(), items)
예제 #27
0
 def get_icon(self, conf, timestamp):
     time_str = _("unknown")
     if conf > 0:
         time_str = format_time(timestamp)
     if conf == -1:
         time_str = _('Not Verified')
         icon = QIcon(":icons/unconfirmed.png")
     elif conf == 0:
         time_str = _('Unconfirmed')
         icon = QIcon(":icons/unconfirmed.png")
     elif conf < 6:
         icon = QIcon(":icons/clock%d.png" % conf)
     else:
         icon = QIcon(":icons/confirmed.png")
     return icon, time_str
예제 #28
0
 def get_icon(self, conf, timestamp):
     time_str = _("unknown")
     if conf > 0:
         time_str = format_time(timestamp)
     if conf == -1:
         time_str = "unverified"
         icon = QIcon(":icons/unconfirmed.png")
     elif conf == 0:
         time_str = "pending"
         icon = QIcon(":icons/unconfirmed.png")
     elif conf < 6:
         icon = QIcon(":icons/clock%d.png" % conf)
     else:
         icon = QIcon(":icons/confirmed.png")
     return icon, time_str
예제 #29
0
    def on_update(self):
        self.wallet = self.parent.wallet
        # hide receive tab if no receive requests available
        b = len(self.wallet.receive_requests) > 0
        self.setVisible(b)
        self.parent.receive_requests_label.setVisible(b)
        if not b:
            self.parent.expires_label.hide()
            self.parent.expires_combo.show()

        # check if it is necessary to show the account
        self.setColumnHidden(1, len(self.wallet.get_accounts()) == 1)

        # update the receive address if necessary
        current_address = self.parent.receive_address_e.text()
        domain = self.wallet.get_account_addresses(self.parent.current_account,
                                                   include_change=False)
        addr = self.wallet.get_unused_address(self.parent.current_account)
        if not current_address in domain and addr:
            self.parent.set_receive_address(addr)
        self.parent.new_request_button.setEnabled(addr != current_address)

        # clear the list and fill it again
        self.clear()
        for req in self.wallet.get_sorted_requests(self.config):
            address = req['address']
            if address not in domain:
                continue
            timestamp = req.get('time', 0)
            amount = req.get('amount')
            expiration = req.get('exp', None)
            message = req.get('memo', '')
            date = format_time(timestamp)
            status = req.get('status')
            signature = req.get('sig')
            requestor = req.get('name', '')
            amount_str = self.parent.format_amount(amount) if amount else ""
            account = ''
            item = QTreeWidgetItem([
                date, account, address, '', message, amount_str,
                pr_tooltips.get(status, '')
            ])
            if signature is not None:
                item.setIcon(3, QIcon(":icons/seal.png"))
                item.setToolTip(3, 'signed by ' + requestor)
            if status is not PR_UNKNOWN:
                item.setIcon(6, QIcon(pr_icons.get(status)))
            self.addTopLevelItem(item)
예제 #30
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_ADDRESS:
                key = item['address']
                icon_name = 'bitcoin.png'
            elif invoice_type == PR_TYPE_BIP70:
                key = item['id']
                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()
예제 #31
0
 def show_pr_details(self, req, status, is_invoice):
     from electrum.util import format_time
     requestor = req.get('requestor')
     exp = req.get('exp')
     memo = req.get('memo')
     amount = req.get('amount')
     popup = Builder.load_file('gui/kivy/uix/ui_screens/invoice.kv')
     popup.is_invoice = is_invoice
     popup.amount = amount
     popup.requestor = requestor if is_invoice else req.get('address')
     popup.exp = format_time(exp) if exp else ''
     popup.description = memo if memo else ''
     popup.signature = req.get('signature', '')
     popup.status = status
     txid = req.get('txid')
     popup.tx_hash = txid or ''
     popup.on_open = lambda: popup.ids.output_list.update(req.get('outputs', []))
     popup.open()
예제 #32
0
 def show_pr_details(self, req, status, is_invoice):
     from electrum.util import format_time
     requestor = req.get('requestor')
     exp = req.get('exp')
     memo = req.get('memo')
     amount = req.get('amount')
     popup = Builder.load_file('gui/kivy/uix/ui_screens/invoice.kv')
     popup.is_invoice = is_invoice
     popup.amount = amount
     popup.requestor = requestor if is_invoice else req.get('address')
     popup.exp = format_time(exp) if exp else ''
     popup.description = memo if memo else ''
     popup.signature = req.get('signature', '')
     popup.status = status
     txid = req.get('txid')
     if txid:
         popup.ids.txid_label.text =  _("Transaction ID") + ':\n' + ' '.join(map(''.join, zip(*[iter(txid)]*4)))
     popup.open()
예제 #33
0
 def on_update(self):
     inv_list = self.parent.invoices.unpaid_invoices()
     self.clear()
     for pr in inv_list:
         key = pr.get_id()
         status = self.parent.invoices.get_status(key)
         requestor = pr.get_requestor()
         exp = pr.get_expiration_date()
         date_str = format_time(exp) if exp else _('Never')
         item = QTreeWidgetItem([date_str, requestor, pr.memo, self.parent.format_amount(pr.get_amount(), whitespaces=True), pr_tooltips.get(status,'')])
         item.setIcon(4, QIcon(pr_icons.get(status)))
         item.setData(0, Qt.UserRole, key)
         item.setFont(1, QFont(MONOSPACE_FONT))
         item.setFont(3, QFont(MONOSPACE_FONT))
         self.addTopLevelItem(item)
     self.setCurrentItem(self.topLevelItem(0))
     self.setVisible(len(inv_list))
     self.parent.invoices_label.setVisible(len(inv_list))
예제 #34
0
    def update(self):
        requests_list = self.screen.ids.requests_container
        requests_list.clear_widgets()
        for req in self.app.wallet.get_sorted_requests(self.app.electrum_config):
            address = req['address']
            timestamp = req.get('time', 0)
            amount = req.get('amount')
            expiration = req.get('exp', None)
            status = req.get('status')
            signature = req.get('sig')

            ci = Factory.RequestItem()
            ci.address = req['address']
            ci.memo = req.get('memo', '')
            #ci.status = req.get('status')
            ci.amount = self.app.format_amount(amount) if amount else ''
            ci.date = format_time(timestamp)
            requests_list.add_widget(ci)
예제 #35
0
 def on_update(self):
     inv_list = self.parent.invoices.unpaid_invoices()
     self.clear()
     for pr in inv_list:
         key = pr.get_id()
         status = self.parent.invoices.get_status(key)
         requestor = pr.get_requestor()
         exp = pr.get_expiration_date()
         date_str = format_time(exp) if exp else _('Never')
         item = QTreeWidgetItem([date_str, requestor, pr.memo, self.parent.format_amount(pr.get_amount(), whitespaces=True), pr_tooltips.get(status,'')])
         item.setIcon(4, read_QIcon(pr_icons.get(status)))
         item.setData(0, Qt.UserRole, key)
         item.setFont(1, QFont(MONOSPACE_FONT))
         item.setFont(3, QFont(MONOSPACE_FONT))
         self.addTopLevelItem(item)
     self.setCurrentItem(self.topLevelItem(0))
     self.setVisible(len(inv_list))
     self.parent.invoices_label.setVisible(len(inv_list))
예제 #36
0
 def show_pr_details(self, req, status, is_invoice):
     from electrum.util import format_time
     requestor = req.get('requestor')
     exp = req.get('exp')
     memo = req.get('memo')
     amount = req.get('amount')
     popup = Builder.load_file('gui/kivy/uix/ui_screens/invoice.kv')
     popup.is_invoice = is_invoice
     popup.amount = amount
     popup.requestor = requestor if is_invoice else req.get('address')
     popup.exp = format_time(exp) if exp else ''
     popup.description = memo if memo else ''
     popup.signature = req.get('signature', '')
     popup.status = status
     txid = req.get('txid')
     popup.tx_hash = txid or ''
     popup.on_open = lambda: popup.ids.output_list.update(req.get('outputs', []))
     popup.open()
예제 #37
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])
예제 #38
0
    def update(self):
        self.wallet = self.parent.wallet
        # hide receive tab if no receive requests available
        b = len(self.wallet.receive_requests) > 0
        self.setVisible(b)
        self.parent.receive_requests_label.setVisible(b)
        if not b:
            self.parent.expires_label.hide()
            self.parent.expires_combo.show()

        # update the receive address if necessary
        current_address = self.parent.receive_address_e.text()
        domain = self.wallet.get_receiving_addresses()
        addr = self.wallet.get_unused_address()
        if not current_address in domain and addr:
            self.parent.set_receive_address(addr)
        self.parent.new_request_button.setEnabled(addr != current_address)

        self.model().clear()
        self.update_headers([_('Date'), _('Address'), '', _('Description'), _('Amount'), _('Status')])
        self.hideColumn(1) # hide address column
        for req in self.wallet.get_sorted_requests(self.config):
            address = req['address']
            if address not in domain:
                continue
            timestamp = req.get('time', 0)
            amount = req.get('amount')
            expiration = req.get('exp', None)
            message = req['memo']
            date = format_time(timestamp)
            status = req.get('status')
            signature = req.get('sig')
            requestor = req.get('name', '')
            amount_str = self.parent.format_amount(amount) if amount else ""
            labels = [date, address, '', message, amount_str, pr_tooltips.get(status,'')]
            items = [QStandardItem(e) for e in labels]
            self.set_editability(items)
            if signature is not None:
                items[2].setIcon(self.icon_cache.get(":icons/seal.png"))
                items[2].setToolTip('signed by '+ requestor)
            if status is not PR_UNKNOWN:
                items[5].setIcon(self.icon_cache.get(pr_icons.get(status)))
            items[3].setData(address, Qt.UserRole)
            self.model().insertRow(self.model().rowCount(), items)
예제 #39
0
    def on_update(self):
        self.wallet = self.parent.wallet
        # hide receive tab if no receive requests available
        b = len(self.wallet.receive_requests) > 0
        self.setVisible(b)
        self.parent.receive_requests_label.setVisible(b)
        if not b:
            self.parent.expires_label.hide()
            self.parent.expires_combo.show()

        # check if it is necessary to show the account
        self.setColumnHidden(1, len(self.wallet.get_accounts()) == 1)

        # update the receive address if necessary
        current_address = self.parent.receive_address_e.text()
        domain = self.wallet.get_account_addresses(self.parent.current_account, include_change=False)
        addr = self.wallet.get_unused_address(self.parent.current_account)
        if not current_address in domain and addr:
            self.parent.set_receive_address(addr)
        self.parent.new_request_button.setEnabled(addr != current_address)

        # clear the list and fill it again
        self.clear()
        for req in self.wallet.get_sorted_requests(self.config):
            address = req['address']
            if address not in domain:
                continue
            timestamp = req.get('time', 0)
            amount = req.get('amount')
            expiration = req.get('exp', None)
            message = req.get('memo', '')
            date = format_time(timestamp)
            status = req.get('status')
            signature = req.get('sig')
            requestor = req.get('name', '')
            amount_str = self.parent.format_amount(amount) if amount else ""
            account = ''
            item = QTreeWidgetItem([date, account, address, '', message, amount_str, pr_tooltips.get(status,'')])
            if signature is not None:
                item.setIcon(3, QIcon(":icons/seal.png"))
                item.setToolTip(3, 'signed by '+ requestor)
            if status is not PR_UNKNOWN:
                item.setIcon(6, QIcon(pr_icons.get(status)))
            self.addTopLevelItem(item)
예제 #40
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)
예제 #41
0
 def update(self):
     # not calling maybe_defer_update() as it interferes with conditional-visibility
     self.proxy.setDynamicSortFilter(
         False)  # temp. disable re-sorting after every change
     self.std_model.clear()
     self.update_headers(self.__class__.headers)
     for idx, item in enumerate(self.parent.wallet.get_invoices()):
         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, status_str = get_request_status(item)
         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)
         items[self.Columns.DATE].setData(timestamp, role=ROLE_SORT_ORDER)
         self.std_model.insertRow(idx, items)
     self.filter()
     self.proxy.setDynamicSortFilter(True)
     # sort requests by date
     self.sortByColumn(self.Columns.DATE, Qt.DescendingOrder)
     # hide list if empty
     if self.parent.isVisible():
         b = self.std_model.rowCount() > 0
         self.setVisible(b)
         self.parent.invoices_label.setVisible(b)
예제 #42
0
 def update(self):
     # not calling maybe_defer_update() as it interferes with conditional-visibility
     self.parent.update_receive_address_styling()
     self.model().clear()
     self.update_headers(self.__class__.headers)
     for req in self.wallet.get_sorted_requests():
         status, status_str = get_request_status(req)
         if status == PR_PAID:
             continue
         request_type = req['type']
         timestamp = req.get('time', 0)
         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 ""
         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.sortByColumn(self.Columns.DATE, Qt.AscendingOrder)
     # hide list if empty
     if self.parent.isVisible():
         b = self.model().rowCount() > 0
         self.setVisible(b)
         self.parent.receive_requests_label.setVisible(b)
         if not b:
             # list got hidden, so selected item should also be cleared:
             self.item_changed(None)
예제 #43
0
    def show_pr_details(self, req, status, is_invoice):
        from electrum.util import format_time

        requestor = req.get("requestor")
        exp = req.get("exp")
        memo = req.get("memo")
        amount = req.get("amount")
        popup = Builder.load_file("gui/kivy/uix/ui_screens/invoice.kv")
        popup.is_invoice = is_invoice
        popup.amount = amount
        popup.requestor = requestor if is_invoice else req.get("address")
        popup.exp = format_time(exp) if exp else ""
        popup.description = memo if memo else ""
        popup.signature = req.get("signature", "")
        popup.status = status
        txid = req.get("txid")
        popup.tx_hash = txid or ""
        popup.on_open = lambda: popup.ids.output_list.update(req.get("outputs", []))
        popup.open()
예제 #44
0
    def update(self, h):
        self.wallet = self.parent.wallet
        item = self.currentItem()
        current_tx = item.data(0, Qt.UserRole).toString() if item else None
        self.clear()
        for item in h:
            tx_hash, conf, value, timestamp, balance = item
            time_str = _("unknown")
            if conf is None and timestamp is None:
                continue  # skip history in offline mode
            if conf > 0:
                time_str = format_time(timestamp)
            if conf == -1:
                time_str = 'unverified'
                icon = QIcon(":icons/unconfirmed.png")
            elif conf == 0:
                time_str = 'pending'
                icon = QIcon(":icons/unconfirmed.png")
            elif conf < 6:
                icon = QIcon(":icons/clock%d.png" % conf)
            else:
                icon = QIcon(":icons/confirmed.png")
            v_str = self.parent.format_amount(value, True, whitespaces=True)
            balance_str = self.parent.format_amount(balance, whitespaces=True)
            label, is_default_label = self.wallet.get_label(tx_hash)
            item = QTreeWidgetItem(['', time_str, label, v_str, balance_str])
            item.setFont(2, QFont(MONOSPACE_FONT))
            item.setFont(3, QFont(MONOSPACE_FONT))
            item.setFont(4, QFont(MONOSPACE_FONT))
            if value < 0:
                item.setForeground(3, QBrush(QColor("#BC1E1E")))
            if tx_hash:
                item.setData(0, Qt.UserRole, tx_hash)
            if is_default_label:
                item.setForeground(2, QBrush(QColor('grey')))
            item.setIcon(0, icon)
            self.insertTopLevelItem(0, item)
            if current_tx == tx_hash:
                self.setCurrentItem(item)

        run_hook('history_tab_update')
예제 #45
0
    def update(self, h):
        self.wallet = self.parent.wallet
        item = self.currentItem()
        current_tx = item.data(0, Qt.UserRole).toString() if item else None
        self.clear()
        for item in h:
            tx_hash, conf, value, timestamp, balance = item
            time_str = _("unknown")
            if conf is None and timestamp is None:
                continue  # skip history in offline mode
            if conf > 0:
                time_str = format_time(timestamp)
            if conf == -1:
                time_str = 'unverified'
                icon = QIcon(":icons/unconfirmed.png")
            elif conf == 0:
                time_str = 'pending'
                icon = QIcon(":icons/unconfirmed.png")
            elif conf < 6:
                icon = QIcon(":icons/clock%d.png"%conf)
            else:
                icon = QIcon(":icons/confirmed.png")
            v_str = self.parent.format_amount(value, True, whitespaces=True)
            balance_str = self.parent.format_amount(balance, whitespaces=True)
            label, is_default_label = self.wallet.get_label(tx_hash)
            item = QTreeWidgetItem( [ '', time_str, label, v_str, balance_str] )
            item.setFont(2, QFont(MONOSPACE_FONT))
            item.setFont(3, QFont(MONOSPACE_FONT))
            item.setFont(4, QFont(MONOSPACE_FONT))
            if value < 0:
                item.setForeground(3, QBrush(QColor("#BC1E1E")))
            if tx_hash:
                item.setData(0, Qt.UserRole, tx_hash)
            if is_default_label:
                item.setForeground(2, QBrush(QColor('grey')))
            item.setIcon(0, icon)
            self.insertTopLevelItem(0, item)
            if current_tx == tx_hash:
                self.setCurrentItem(item)

        run_hook('history_tab_update')
예제 #46
0
 def update(self):
     self.menu_actions = [(_('Pay'), self.do_pay), (_('Delete'), self.do_delete)]
     invoices_list = self.screen.ids.invoices_container
     invoices_list.clear_widgets()
     for pr in self.app.invoices.sorted_list():
         ci = Factory.InvoiceItem()
         ci.key = pr.get_id()
         ci.requestor = pr.get_requestor()
         ci.memo = pr.memo
         ci.amount = self.app.format_amount_and_units(pr.get_amount())
         status = self.app.invoices.get_status(ci.key)
         if status == PR_PAID:
             ci.icon = "atlas://gui/kivy/theming/light/confirmed"
         elif status == PR_EXPIRED:
             ci.icon = "atlas://gui/kivy/theming/light/important"
         else:
             ci.icon = "atlas://gui/kivy/theming/light/important"
         exp = pr.get_expiration_date()
         ci.date = format_time(exp) if exp else _('Never')
         ci.screen = self
         invoices_list.add_widget(ci)
예제 #47
0
 def update(self):
     inv_list = self.parent.invoices.unpaid_invoices()
     self.model().clear()
     self.update_headers([_('Expires'), _('Requestor'), _('Description'), _('Amount'), _('Status')])
     self.header().setSectionResizeMode(1, QHeaderView.Interactive)
     for pr in inv_list:
         key = pr.get_id()
         status = self.parent.invoices.get_status(key)
         requestor = pr.get_requestor()
         exp = pr.get_expiration_date()
         date_str = format_time(exp) if exp else _('Never')
         labels = [date_str, requestor, pr.memo, self.parent.format_amount(pr.get_amount(), whitespaces=True), pr_tooltips.get(status,'')]
         item = [QStandardItem(e) for e in labels]
         item[4].setIcon(self.icon_cache.get(pr_icons.get(status)))
         item[0].setData(Qt.UserRole, key)
         item[1].setFont(QFont(MONOSPACE_FONT))
         item[3].setFont(QFont(MONOSPACE_FONT))
         self.addTopLevelItem(item)
     self.selectionModel().select(self.model().index(0,0), QItemSelectionModel.SelectCurrent)
     self.setVisible(len(inv_list))
     self.parent.invoices_label.setVisible(len(inv_list))
예제 #48
0
 def get_card(self, pr):
     key = pr.get_id()
     ci = self.cards.get(key)
     if ci is None:
         ci = Factory.InvoiceItem()
         ci.key = key
         ci.screen = self
         self.cards[key] = ci
     ci.requestor = pr.get_requestor()
     ci.memo = pr.get_memo()
     amount = pr.get_amount()
     if amount:
         ci.amount = self.app.format_amount_and_units(amount)
         status = self.app.wallet.invoices.get_status(ci.key)
         ci.status = invoice_text[status]
         ci.icon = pr_icon[status]
     else:
         ci.amount = _('No Amount')
         ci.status = ''
     exp = pr.get_expiration_date()
     ci.date = format_time(exp) if exp else _('Never')
     return ci