From bf072b037ceb18e4fd01163e7e4e79fe93be7d29 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Tue, 26 Apr 2022 13:18:34 +0200 Subject: [PATCH] hook up invoice confirm to payment flow (onchain only) fix some leftover QEAmount issues --- .../gui/qml/components/ConfirmInvoiceDialog.qml | 16 +++++++++++++--- .../gui/qml/components/ConfirmPaymentDialog.qml | 5 +++-- electrum/gui/qml/components/Send.qml | 16 +++++++++++++--- electrum/gui/qml/qeinvoice.py | 9 +++++++-- electrum/gui/qml/qetxfinalizer.py | 9 +++++---- electrum/gui/qml/qetypes.py | 7 ++++++- 6 files changed, 47 insertions(+), 15 deletions(-) diff --git a/electrum/gui/qml/components/ConfirmInvoiceDialog.qml b/electrum/gui/qml/components/ConfirmInvoiceDialog.qml index 7f3b447c5..19cc51bd2 100644 --- a/electrum/gui/qml/components/ConfirmInvoiceDialog.qml +++ b/electrum/gui/qml/components/ConfirmInvoiceDialog.qml @@ -13,6 +13,8 @@ Dialog { property Invoice invoice property string invoice_key + signal doPay + width: parent.width height: parent.height @@ -57,6 +59,9 @@ Dialog { Label { text: invoice.message Layout.fillWidth: true + wrapMode: Text.Wrap + maximumLineCount: 4 + elide: Text.ElideRight } Label { @@ -93,10 +98,11 @@ Dialog { text: invoice.status_str } + Item { Layout.fillHeight: true; Layout.preferredWidth: 1 } + RowLayout { Layout.columnSpan: 2 - Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom - Layout.fillHeight: true + Layout.alignment: Qt.AlignHCenter spacing: constants.paddingMedium Button { @@ -117,7 +123,11 @@ Dialog { text: qsTr('Pay now') enabled: invoice.invoiceType != Invoice.Invalid // TODO && has funds onClicked: { - console.log('pay now') + invoice.save_invoice() + dialog.close() + if (invoice.invoiceType == Invoice.OnchainInvoice) { + doPay() // only signal here + } } } } diff --git a/electrum/gui/qml/components/ConfirmPaymentDialog.qml b/electrum/gui/qml/components/ConfirmPaymentDialog.qml index 241c768f1..59f327113 100644 --- a/electrum/gui/qml/components/ConfirmPaymentDialog.qml +++ b/electrum/gui/qml/components/ConfirmPaymentDialog.qml @@ -164,6 +164,8 @@ Dialog { color: Material.accentColor } + Item { Layout.fillHeight: true; Layout.preferredWidth: 1 } + RowLayout { Layout.columnSpan: 2 Layout.alignment: Qt.AlignHCenter @@ -184,12 +186,11 @@ Dialog { } } } - Item { Layout.fillHeight: true; Layout.preferredWidth: 1 } } TxFinalizer { id: finalizer wallet: Daemon.currentWallet - onAmountChanged: console.log(amount) + onAmountChanged: console.log(amount.satsInt) } } diff --git a/electrum/gui/qml/components/Send.qml b/electrum/gui/qml/components/Send.qml index cdda2be21..c3ab6cfdc 100644 --- a/electrum/gui/qml/components/Send.qml +++ b/electrum/gui/qml/components/Send.qml @@ -157,10 +157,9 @@ Pane { var f_amount = parseFloat(amount.text) if (isNaN(f_amount)) return - var sats = Config.unitsToSats(amount.text).toString() var dialog = confirmPaymentDialog.createObject(app, { 'address': recipient.text, - 'satoshis': sats, + 'satoshis': Config.unitsToSats(amount.text), 'message': message.text }) dialog.open() @@ -244,7 +243,18 @@ Pane { Component { id: confirmInvoiceDialog - ConfirmInvoiceDialog {} + ConfirmInvoiceDialog { + onDoPay: { + if (invoice.invoiceType == Invoice.OnchainInvoice) { + var dialog = confirmPaymentDialog.createObject(rootItem, { + 'address': invoice.address, + 'satoshis': invoice.amount, + 'message': invoice.message + }) + dialog.open() + } + } + } } Connections { diff --git a/electrum/gui/qml/qeinvoice.py b/electrum/gui/qml/qeinvoice.py index 8dd3c6dc5..c8133e266 100644 --- a/electrum/gui/qml/qeinvoice.py +++ b/electrum/gui/qml/qeinvoice.py @@ -117,8 +117,8 @@ class QEInvoice(QObject): @pyqtProperty(int, notify=statusChanged) def status(self): if not self._effectiveInvoice: - return '' - status = self._wallet.wallet.get_invoice_status(self._effectiveInvoice) + return PR_UNKNOWN + return self._wallet.wallet.get_invoice_status(self._effectiveInvoice) @pyqtProperty(str, notify=statusChanged) def status_str(self): @@ -127,6 +127,11 @@ class QEInvoice(QObject): status = self._wallet.wallet.get_invoice_status(self._effectiveInvoice) return self._effectiveInvoice.get_status_str(status) + # single address only, TODO: n outputs + @pyqtProperty(str, notify=invoiceChanged) + def address(self): + return self._effectiveInvoice.get_address() if self._effectiveInvoice else '' + @pyqtSlot() def clear(self): self.recipient = '' diff --git a/electrum/gui/qml/qetxfinalizer.py b/electrum/gui/qml/qetxfinalizer.py index 3aa3faee1..a71199fe9 100644 --- a/electrum/gui/qml/qetxfinalizer.py +++ b/electrum/gui/qml/qetxfinalizer.py @@ -18,7 +18,7 @@ class QETxFinalizer(QObject): _address = '' _amount = QEAmount() - _fee = '' + _fee = QEAmount() _feeRate = '' _wallet = None _valid = False @@ -66,12 +66,12 @@ class QETxFinalizer(QObject): @amount.setter def amount(self, amount): if self._amount != amount: - self._logger.info('amount = "%s"' % repr(amount)) + self._logger.debug(str(amount)) self._amount = amount self.amountChanged.emit() feeChanged = pyqtSignal() - @pyqtProperty(str, notify=feeChanged) + @pyqtProperty(QEAmount, notify=feeChanged) def fee(self): return self._fee @@ -211,9 +211,10 @@ class QETxFinalizer(QObject): fee = tx.get_fee() feerate = Decimal(fee) / tx_size # sat/byte - self.fee = str(fee) + self.fee = QEAmount(amount_sat=fee) self.feeRate = f'{feerate:.1f}' + #TODO #x_fee = run_hook('get_tx_extra_fee', self._wallet.wallet, tx) fee_warning_tuple = self._wallet.wallet.get_tx_fee_warning( invoice_amt=amount, tx_size=tx_size, fee=fee) diff --git a/electrum/gui/qml/qetypes.py b/electrum/gui/qml/qetypes.py index c2f207189..cf8c8faba 100644 --- a/electrum/gui/qml/qetypes.py +++ b/electrum/gui/qml/qetypes.py @@ -44,7 +44,6 @@ class QEAmount(QObject): return self._is_max def __eq__(self, other): - self._logger.debug('__eq__') if isinstance(other, QEAmount): return self._amount_sat == other._amount_sat and self._amount_msat == other._amount_msat and self._is_max == other._is_max elif isinstance(other, int): @@ -53,3 +52,9 @@ class QEAmount(QObject): return self.satsStr == other return False + + def __str__(self): + s = _('Amount') + if self._is_max: + return '%s(MAX)' % s + return '%s(sats=%d, msats=%d)' % (s, self._amount_sat, self._amount_msat)