Browse Source

hook up invoice confirm to payment flow (onchain only)

fix some leftover QEAmount issues
patch-4
Sander van Grieken 3 years ago
parent
commit
bf072b037c
  1. 16
      electrum/gui/qml/components/ConfirmInvoiceDialog.qml
  2. 5
      electrum/gui/qml/components/ConfirmPaymentDialog.qml
  3. 16
      electrum/gui/qml/components/Send.qml
  4. 9
      electrum/gui/qml/qeinvoice.py
  5. 9
      electrum/gui/qml/qetxfinalizer.py
  6. 7
      electrum/gui/qml/qetypes.py

16
electrum/gui/qml/components/ConfirmInvoiceDialog.qml

@ -13,6 +13,8 @@ Dialog {
property Invoice invoice property Invoice invoice
property string invoice_key property string invoice_key
signal doPay
width: parent.width width: parent.width
height: parent.height height: parent.height
@ -57,6 +59,9 @@ Dialog {
Label { Label {
text: invoice.message text: invoice.message
Layout.fillWidth: true Layout.fillWidth: true
wrapMode: Text.Wrap
maximumLineCount: 4
elide: Text.ElideRight
} }
Label { Label {
@ -93,10 +98,11 @@ Dialog {
text: invoice.status_str text: invoice.status_str
} }
Item { Layout.fillHeight: true; Layout.preferredWidth: 1 }
RowLayout { RowLayout {
Layout.columnSpan: 2 Layout.columnSpan: 2
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom Layout.alignment: Qt.AlignHCenter
Layout.fillHeight: true
spacing: constants.paddingMedium spacing: constants.paddingMedium
Button { Button {
@ -117,7 +123,11 @@ Dialog {
text: qsTr('Pay now') text: qsTr('Pay now')
enabled: invoice.invoiceType != Invoice.Invalid // TODO && has funds enabled: invoice.invoiceType != Invoice.Invalid // TODO && has funds
onClicked: { onClicked: {
console.log('pay now') invoice.save_invoice()
dialog.close()
if (invoice.invoiceType == Invoice.OnchainInvoice) {
doPay() // only signal here
}
} }
} }
} }

5
electrum/gui/qml/components/ConfirmPaymentDialog.qml

@ -164,6 +164,8 @@ Dialog {
color: Material.accentColor color: Material.accentColor
} }
Item { Layout.fillHeight: true; Layout.preferredWidth: 1 }
RowLayout { RowLayout {
Layout.columnSpan: 2 Layout.columnSpan: 2
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
@ -184,12 +186,11 @@ Dialog {
} }
} }
} }
Item { Layout.fillHeight: true; Layout.preferredWidth: 1 }
} }
TxFinalizer { TxFinalizer {
id: finalizer id: finalizer
wallet: Daemon.currentWallet wallet: Daemon.currentWallet
onAmountChanged: console.log(amount) onAmountChanged: console.log(amount.satsInt)
} }
} }

16
electrum/gui/qml/components/Send.qml

@ -157,10 +157,9 @@ Pane {
var f_amount = parseFloat(amount.text) var f_amount = parseFloat(amount.text)
if (isNaN(f_amount)) if (isNaN(f_amount))
return return
var sats = Config.unitsToSats(amount.text).toString()
var dialog = confirmPaymentDialog.createObject(app, { var dialog = confirmPaymentDialog.createObject(app, {
'address': recipient.text, 'address': recipient.text,
'satoshis': sats, 'satoshis': Config.unitsToSats(amount.text),
'message': message.text 'message': message.text
}) })
dialog.open() dialog.open()
@ -244,7 +243,18 @@ Pane {
Component { Component {
id: confirmInvoiceDialog 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 { Connections {

9
electrum/gui/qml/qeinvoice.py

@ -117,8 +117,8 @@ class QEInvoice(QObject):
@pyqtProperty(int, notify=statusChanged) @pyqtProperty(int, notify=statusChanged)
def status(self): def status(self):
if not self._effectiveInvoice: if not self._effectiveInvoice:
return '' return PR_UNKNOWN
status = self._wallet.wallet.get_invoice_status(self._effectiveInvoice) return self._wallet.wallet.get_invoice_status(self._effectiveInvoice)
@pyqtProperty(str, notify=statusChanged) @pyqtProperty(str, notify=statusChanged)
def status_str(self): def status_str(self):
@ -127,6 +127,11 @@ class QEInvoice(QObject):
status = self._wallet.wallet.get_invoice_status(self._effectiveInvoice) status = self._wallet.wallet.get_invoice_status(self._effectiveInvoice)
return self._effectiveInvoice.get_status_str(status) 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() @pyqtSlot()
def clear(self): def clear(self):
self.recipient = '' self.recipient = ''

9
electrum/gui/qml/qetxfinalizer.py

@ -18,7 +18,7 @@ class QETxFinalizer(QObject):
_address = '' _address = ''
_amount = QEAmount() _amount = QEAmount()
_fee = '' _fee = QEAmount()
_feeRate = '' _feeRate = ''
_wallet = None _wallet = None
_valid = False _valid = False
@ -66,12 +66,12 @@ class QETxFinalizer(QObject):
@amount.setter @amount.setter
def amount(self, amount): def amount(self, amount):
if self._amount != amount: if self._amount != amount:
self._logger.info('amount = "%s"' % repr(amount)) self._logger.debug(str(amount))
self._amount = amount self._amount = amount
self.amountChanged.emit() self.amountChanged.emit()
feeChanged = pyqtSignal() feeChanged = pyqtSignal()
@pyqtProperty(str, notify=feeChanged) @pyqtProperty(QEAmount, notify=feeChanged)
def fee(self): def fee(self):
return self._fee return self._fee
@ -211,9 +211,10 @@ class QETxFinalizer(QObject):
fee = tx.get_fee() fee = tx.get_fee()
feerate = Decimal(fee) / tx_size # sat/byte feerate = Decimal(fee) / tx_size # sat/byte
self.fee = str(fee) self.fee = QEAmount(amount_sat=fee)
self.feeRate = f'{feerate:.1f}' self.feeRate = f'{feerate:.1f}'
#TODO
#x_fee = run_hook('get_tx_extra_fee', self._wallet.wallet, tx) #x_fee = run_hook('get_tx_extra_fee', self._wallet.wallet, tx)
fee_warning_tuple = self._wallet.wallet.get_tx_fee_warning( fee_warning_tuple = self._wallet.wallet.get_tx_fee_warning(
invoice_amt=amount, tx_size=tx_size, fee=fee) invoice_amt=amount, tx_size=tx_size, fee=fee)

7
electrum/gui/qml/qetypes.py

@ -44,7 +44,6 @@ class QEAmount(QObject):
return self._is_max return self._is_max
def __eq__(self, other): def __eq__(self, other):
self._logger.debug('__eq__')
if isinstance(other, QEAmount): 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 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): elif isinstance(other, int):
@ -53,3 +52,9 @@ class QEAmount(QObject):
return self.satsStr == other return self.satsStr == other
return False 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)

Loading…
Cancel
Save