Exemplo n.º 1
0
    def _payment_request_imported(self, row: InvoiceRow) -> None:
        self._invoice_list.update()

        self._payto_e.is_pr = True
        if not has_expired(row.date_expires):
            self._payto_e.set_validated()
        else:
            self._payto_e.set_expired()
        self._payto_e.setText(row.payment_uri)
        self.amount_e.setText(
            format_satoshis_plain(row.value, app_state.decimal_point))
        self._message_e.setText(row.description)
        # signal to set fee
        self.amount_e.textEdited.emit("")
Exemplo n.º 2
0
    def _event_create_menu(self, position):
        menu = QMenu()

        # What the user clicked on.
        menu_index = self.indexAt(position)
        menu_source_index = get_source_index(menu_index, _ItemModel)

        if menu_source_index.row() != -1:
            menu_line = self._data[menu_source_index.row()]
            menu_column = menu_source_index.column()
            column_title = self._headers[menu_column]
            if menu_column == 0:
                copy_text = hash_to_hex_str(menu_line.hash)
            else:
                copy_text = str(
                    menu_source_index.model().data(menu_source_index, Qt.DisplayRole)).strip()
            menu.addAction(_("Copy {}").format(column_title),
                lambda: self._main_window.app.clipboard().setText(copy_text))

        # The row selection.
        selected_indexes = self.selectedIndexes()
        if len(selected_indexes):
            # This is an index on the sort/filter model, translate it to the base model.
            selected = []
            for selected_index in selected_indexes:
                base_index = get_source_index(selected_index, _ItemModel)

                row = base_index.row()
                column = base_index.column()
                line = self._data[row]
                selected.append((row, column, line, selected_index, base_index))

            rows = set(v[0] for v in selected)
            multi_select = len(rows) > 1

            if not multi_select:
                row, column, line, selected_index, base_index = selected[0]
                menu.addAction(_('Details'), lambda: self._main_window.show_transaction(
                    self._account, self._account.get_transaction(line.hash)))

                entry = self._account.get_transaction_entry(line.hash)
                if entry.flags & TxFlags.PaysInvoice:
                    menu.addAction(self._invoice_icon, _("View invoice"),
                        partial(self._show_invoice_window, line.hash))
                line_URL = web.BE_URL(self._main_window.config, 'tx', hash_to_hex_str(line.hash))
                if line_URL:
                    menu.addAction(_("View on block explorer"), lambda: webbrowser.open(line_URL))

                menu.addSeparator()
                if column == LABEL_COLUMN:
                    menu.addAction(_("Edit {}").format(column_title),
                        lambda: self.edit(selected_index))

                if entry.flags & TxFlags.STATE_UNCLEARED_MASK != 0:
                    if entry.flags & TxFlags.PaysInvoice:
                        broadcast_action = menu.addAction(self._invoice_icon, _("Pay invoice"),
                            lambda: self._pay_invoice(line.hash))

                        row = self._account.invoices.get_invoice_for_tx_hash(line.hash)
                        if row is None:
                            # The associated invoice has been deleted.
                            broadcast_action.setEnabled(False)
                        elif row.flags & PaymentFlag.UNPAID == 0:
                            # The associated invoice has already been paid.
                            broadcast_action.setEnabled(False)
                        elif has_expired(row.date_expires):
                            # The associated invoice has expired.
                            broadcast_action.setEnabled(False)
                    else:
                        menu.addAction(_("Broadcast"),
                            lambda: self._broadcast_transaction(line.hash))

                    menu.addSeparator()
                    menu.addAction(_("Remove from account"),
                        partial(self._delete_transaction, line.hash))

        menu.exec_(self.viewport().mapToGlobal(position))
Exemplo n.º 3
0
    def __init__(self, main_window: 'ElectrumWindow', row: InvoiceRow) -> None:
        super().__init__(main_window, _("Invoice"))

        self.setMinimumWidth(400)

        self._main_window = weakref.proxy(main_window)

        self._pr = pr = PaymentRequest.from_json(row.invoice_data)

        state = row.flags & PaymentFlag.STATE_MASK
        if state & PaymentFlag.UNPAID and has_expired(row.date_expires):
            state = PaymentFlag.EXPIRED

        total_amount = 0
        for output in pr.outputs:
            total_amount += output.amount

        vbox = QVBoxLayout(self)
        form = FormSectionWidget(minimum_label_width=120)
        form.add_row(_('Type'), QLabel(_("BIP270")))
        form.add_row(_("State"), QLabel(pr_tooltips.get(state, _("Unknown"))))
        form.add_row(
            _('Amount'),
            QLabel(
                app_state.format_amount(output.amount) + " " +
                app_state.base_unit()))
        form.add_row(_('Memo'), QLabel(row.description))
        form.add_row(_('Date Created'),
                     QLabel(format_time(pr.creation_timestamp, _("Unknown"))))
        form.add_row(_('Date Received'),
                     QLabel(format_time(row.date_created, _("Unknown"))))
        if row.date_expires:
            form.add_row(_('Date Expires'),
                         QLabel(format_time(row.date_expires, _("Unknown"))))
        vbox.addWidget(form)

        self._table = table = ButtonsTableWidget()
        table.setSelectionBehavior(QAbstractItemView.SelectRows)
        table.setSelectionMode(QAbstractItemView.SingleSelection)

        vh = table.verticalHeader()
        vh.setSectionResizeMode(QHeaderView.ResizeToContents)
        vh.hide()

        table.setColumnCount(3)
        table.setContextMenuPolicy(Qt.CustomContextMenu)
        table.customContextMenuRequested.connect(self._on_table_menu)
        table.setHorizontalHeaderLabels(self._table_column_names)
        table.setRowCount(len(pr.outputs))
        # table.addButton("icons8-copy-to-clipboard-32.png", f,
        #     _("Copy all listed destinations to the clipboard"))
        # table.addButton("icons8-save-as-32-windows.png", f,
        #     _("Save the listed destinations to a file"))
        hh = table.horizontalHeader()
        hh.setStretchLastSection(True)

        for row, output in enumerate(pr.outputs):
            label = QLabel(
                app_state.format_amount(output.amount) + " " +
                app_state.base_unit())
            table.setCellWidget(row, 0, label)

            table.setCellWidget(row, 1, QLabel(output.description))

            kind = classify_output_script(output.script, Net.COIN)
            text = script_to_display_text(output.script, kind)
            table.setCellWidget(row, 2, QLabel(text))

            vbox.addWidget(table, 1)

        def do_export():
            fn = self._main_window.getSaveFileName(_("Export invoice to file"),
                                                   "*.bip270.json")
            if not fn:
                return
            with open(fn, 'w') as f:
                data = f.write(row.invoice_data)
            self._main_window.show_message(_('Invoice saved as' + ' ' + fn))

        exportButton = EnterButton(_('Export'), do_export)

        def do_delete():
            if self.question(
                    _('Are you sure you want to delete this invoice?'),
                    title=_("Delete invoice"),
                    icon=QMessageBox.Warning):
                self._main_window._send_view._invoice_list._delete_invoice(
                    row.invoice_id)
                self.close()

        deleteButton = EnterButton(_('Delete'), do_delete)

        vbox.addLayout(Buttons(exportButton, deleteButton, CloseButton(self)))