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 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
}
}
}
}

5
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)
}
}

16
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 {

9
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 = ''

9
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)

7
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)

Loading…
Cancel
Save