def get_card(self, item): invoice_type = item['type'] if invoice_type == PR_TYPE_LN: key = item['rhash'] status = get_request_status(item) # convert to str elif invoice_type == PR_TYPE_ONCHAIN: key = item['id'] status = get_request_status(item) # convert to str else: raise Exception('unknown invoice type') return { 'is_lightning': invoice_type == PR_TYPE_LN, 'is_bip70': 'bip70' in item, 'screen': self, 'status': status, 'key': key, 'memo': item['message'], 'amount': self.app.format_amount_and_units(item['amount'] or 0), }
def refresh_status(self): m = self.model() for r in range(m.rowCount()): idx = m.index(r, self.Columns.STATUS) date_idx = idx.sibling(idx.row(), self.Columns.DATE) date_item = m.itemFromIndex(date_idx) status_item = m.itemFromIndex(idx) key = date_item.data(ROLE_KEY) is_lightning = date_item.data(ROLE_REQUEST_TYPE) == PR_TYPE_LN req = self.wallet.get_request(key) if req: status = req['status'] status_str = get_request_status(req) status_item.setText(status_str) status_item.setIcon(read_QIcon(pr_icons.get(status)))
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()
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)
def get_card(self, req): is_lightning = req.get('type') == PR_TYPE_LN if not is_lightning: address = req['address'] key = address else: key = req['rhash'] address = req['invoice'] amount = req.get('amount') description = req.get('memo', '') ci = {} ci['screen'] = self ci['address'] = address ci['is_lightning'] = is_lightning ci['key'] = key ci['amount'] = self.app.format_amount_and_units( amount) if amount else '' ci['memo'] = description ci['status'] = get_request_status(req) ci['is_expired'] = req['status'] == PR_EXPIRED return ci