Sander van Grieken
3 years ago
15 changed files with 682 additions and 68 deletions
After Width: | Height: | Size: 946 B |
@ -0,0 +1,261 @@ |
|||||
|
import QtQuick 2.6 |
||||
|
import QtQuick.Layouts 1.0 |
||||
|
import QtQuick.Controls 2.3 |
||||
|
import QtQuick.Controls.Material 2.0 |
||||
|
|
||||
|
import org.electrum 1.0 |
||||
|
|
||||
|
import "controls" |
||||
|
|
||||
|
Pane { |
||||
|
id: root |
||||
|
width: parent.width |
||||
|
height: parent.height |
||||
|
|
||||
|
property string title: qsTr("Lightning payment details") |
||||
|
|
||||
|
property string key |
||||
|
|
||||
|
property alias label: lnpaymentdetails.label |
||||
|
|
||||
|
signal detailsChanged |
||||
|
|
||||
|
Flickable { |
||||
|
anchors.fill: parent |
||||
|
contentHeight: rootLayout.height |
||||
|
clip: true |
||||
|
interactive: height < contentHeight |
||||
|
|
||||
|
GridLayout { |
||||
|
id: rootLayout |
||||
|
width: parent.width |
||||
|
columns: 2 |
||||
|
|
||||
|
Label { |
||||
|
text: qsTr('Status') |
||||
|
color: Material.accentColor |
||||
|
} |
||||
|
|
||||
|
Label { |
||||
|
text: lnpaymentdetails.status |
||||
|
} |
||||
|
|
||||
|
Label { |
||||
|
text: qsTr('Date') |
||||
|
color: Material.accentColor |
||||
|
} |
||||
|
|
||||
|
Label { |
||||
|
text: lnpaymentdetails.date |
||||
|
} |
||||
|
|
||||
|
Label { |
||||
|
text: lnpaymentdetails.amount.msatsInt > 0 |
||||
|
? qsTr('Amount received') |
||||
|
: qsTr('Amount sent') |
||||
|
color: Material.accentColor |
||||
|
} |
||||
|
|
||||
|
RowLayout { |
||||
|
Label { |
||||
|
text: Config.formatMilliSats(lnpaymentdetails.amount) |
||||
|
} |
||||
|
Label { |
||||
|
text: Config.baseUnit |
||||
|
color: Material.accentColor |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
Label { |
||||
|
visible: lnpaymentdetails.amount.msatsInt < 0 |
||||
|
text: qsTr('Transaction fee') |
||||
|
color: Material.accentColor |
||||
|
} |
||||
|
|
||||
|
RowLayout { |
||||
|
visible: lnpaymentdetails.amount.msatsInt < 0 |
||||
|
Label { |
||||
|
text: Config.formatMilliSats(lnpaymentdetails.fee) |
||||
|
} |
||||
|
Label { |
||||
|
text: Config.baseUnit |
||||
|
color: Material.accentColor |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
Label { |
||||
|
text: qsTr('Label') |
||||
|
Layout.columnSpan: 2 |
||||
|
color: Material.accentColor |
||||
|
} |
||||
|
|
||||
|
TextHighlightPane { |
||||
|
id: labelContent |
||||
|
|
||||
|
property bool editmode: false |
||||
|
|
||||
|
Layout.columnSpan: 2 |
||||
|
Layout.fillWidth: true |
||||
|
padding: 0 |
||||
|
leftPadding: constants.paddingSmall |
||||
|
|
||||
|
RowLayout { |
||||
|
width: parent.width |
||||
|
Label { |
||||
|
visible: !labelContent.editmode |
||||
|
text: lnpaymentdetails.label |
||||
|
wrapMode: Text.Wrap |
||||
|
Layout.fillWidth: true |
||||
|
font.pixelSize: constants.fontSizeLarge |
||||
|
} |
||||
|
ToolButton { |
||||
|
visible: !labelContent.editmode |
||||
|
icon.source: '../../icons/pen.png' |
||||
|
icon.color: 'transparent' |
||||
|
onClicked: { |
||||
|
labelEdit.text = lnpaymentdetails.label |
||||
|
labelContent.editmode = true |
||||
|
labelEdit.focus = true |
||||
|
} |
||||
|
} |
||||
|
TextField { |
||||
|
id: labelEdit |
||||
|
visible: labelContent.editmode |
||||
|
text: lnpaymentdetails.label |
||||
|
font.pixelSize: constants.fontSizeLarge |
||||
|
Layout.fillWidth: true |
||||
|
} |
||||
|
ToolButton { |
||||
|
visible: labelContent.editmode |
||||
|
icon.source: '../../icons/confirmed.png' |
||||
|
icon.color: 'transparent' |
||||
|
onClicked: { |
||||
|
labelContent.editmode = false |
||||
|
lnpaymentdetails.set_label(labelEdit.text) |
||||
|
} |
||||
|
} |
||||
|
ToolButton { |
||||
|
visible: labelContent.editmode |
||||
|
icon.source: '../../icons/delete.png' |
||||
|
icon.color: 'transparent' |
||||
|
onClicked: labelContent.editmode = false |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
Label { |
||||
|
text: qsTr('Payment hash') |
||||
|
Layout.columnSpan: 2 |
||||
|
color: Material.accentColor |
||||
|
} |
||||
|
|
||||
|
TextHighlightPane { |
||||
|
Layout.columnSpan: 2 |
||||
|
Layout.fillWidth: true |
||||
|
padding: 0 |
||||
|
leftPadding: constants.paddingSmall |
||||
|
|
||||
|
RowLayout { |
||||
|
width: parent.width |
||||
|
Label { |
||||
|
text: lnpaymentdetails.payment_hash |
||||
|
font.pixelSize: constants.fontSizeLarge |
||||
|
font.family: FixedFont |
||||
|
Layout.fillWidth: true |
||||
|
wrapMode: Text.Wrap |
||||
|
} |
||||
|
ToolButton { |
||||
|
icon.source: '../../icons/share.png' |
||||
|
icon.color: 'transparent' |
||||
|
onClicked: { |
||||
|
var dialog = share.createObject(root, { 'title': qsTr('Payment hash'), 'text': lnpaymentdetails.payment_hash }) |
||||
|
dialog.open() |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
Label { |
||||
|
text: qsTr('Preimage') |
||||
|
Layout.columnSpan: 2 |
||||
|
color: Material.accentColor |
||||
|
} |
||||
|
|
||||
|
TextHighlightPane { |
||||
|
Layout.columnSpan: 2 |
||||
|
Layout.fillWidth: true |
||||
|
padding: 0 |
||||
|
leftPadding: constants.paddingSmall |
||||
|
|
||||
|
RowLayout { |
||||
|
width: parent.width |
||||
|
Label { |
||||
|
text: lnpaymentdetails.preimage |
||||
|
font.pixelSize: constants.fontSizeLarge |
||||
|
font.family: FixedFont |
||||
|
Layout.fillWidth: true |
||||
|
wrapMode: Text.Wrap |
||||
|
} |
||||
|
ToolButton { |
||||
|
icon.source: '../../icons/share.png' |
||||
|
icon.color: 'transparent' |
||||
|
onClicked: { |
||||
|
var dialog = share.createObject(root, { 'title': qsTr('Preimage'), 'text': lnpaymentdetails.preimage }) |
||||
|
dialog.open() |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
Label { |
||||
|
text: qsTr('Lightning invoice') |
||||
|
Layout.columnSpan: 2 |
||||
|
color: Material.accentColor |
||||
|
} |
||||
|
|
||||
|
TextHighlightPane { |
||||
|
Layout.columnSpan: 2 |
||||
|
Layout.fillWidth: true |
||||
|
padding: 0 |
||||
|
leftPadding: constants.paddingSmall |
||||
|
|
||||
|
RowLayout { |
||||
|
width: parent.width |
||||
|
Label { |
||||
|
Layout.fillWidth: true |
||||
|
text: lnpaymentdetails.invoice |
||||
|
font.pixelSize: constants.fontSizeLarge |
||||
|
font.family: FixedFont |
||||
|
wrapMode: Text.Wrap |
||||
|
maximumLineCount: 3 |
||||
|
elide: Text.ElideRight |
||||
|
} |
||||
|
ToolButton { |
||||
|
icon.source: '../../icons/share.png' |
||||
|
icon.color: enabled ? 'transparent' : constants.mutedForeground |
||||
|
enabled: lnpaymentdetails.invoice != '' |
||||
|
onClicked: { |
||||
|
var dialog = share.createObject(root, { 'title': qsTr('Lightning Invoice'), 'text': lnpaymentdetails.invoice }) |
||||
|
dialog.open() |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
LnPaymentDetails { |
||||
|
id: lnpaymentdetails |
||||
|
wallet: Daemon.currentWallet |
||||
|
key: root.key |
||||
|
onLabelChanged: root.detailsChanged() |
||||
|
} |
||||
|
|
||||
|
Component { |
||||
|
id: share |
||||
|
GenericShareDialog {} |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,127 @@ |
|||||
|
import QtQuick 2.6 |
||||
|
import QtQuick.Layouts 1.0 |
||||
|
import QtQuick.Controls 2.14 |
||||
|
import QtQuick.Controls.Material 2.0 |
||||
|
|
||||
|
import org.electrum 1.0 |
||||
|
|
||||
|
import "controls" |
||||
|
|
||||
|
Dialog { |
||||
|
id: dialog |
||||
|
|
||||
|
required property string invoice_key |
||||
|
|
||||
|
width: parent.width |
||||
|
height: parent.height |
||||
|
|
||||
|
title: qsTr('Paying Lightning Invoice...') |
||||
|
standardButtons: Dialog.Cancel |
||||
|
|
||||
|
modal: true |
||||
|
parent: Overlay.overlay |
||||
|
Overlay.modal: Rectangle { |
||||
|
color: "#aa000000" |
||||
|
} |
||||
|
|
||||
|
Item { |
||||
|
id: s |
||||
|
state: '' |
||||
|
states: [ |
||||
|
State { |
||||
|
name: '' |
||||
|
}, |
||||
|
State { |
||||
|
name: 'success' |
||||
|
PropertyChanges { target: spinner; running: false } |
||||
|
PropertyChanges { target: helpText; text: qsTr('Paid!') } |
||||
|
PropertyChanges { target: dialog; standardButtons: Dialog.Ok } |
||||
|
PropertyChanges { target: icon; source: '../../icons/confirmed.png' } |
||||
|
}, |
||||
|
State { |
||||
|
name: 'failed' |
||||
|
PropertyChanges { target: spinner; running: false } |
||||
|
PropertyChanges { target: helpText; text: qsTr('Payment failed') } |
||||
|
PropertyChanges { target: dialog; standardButtons: Dialog.Ok } |
||||
|
PropertyChanges { target: errorText; visible: true } |
||||
|
PropertyChanges { target: icon; source: '../../icons/warning.png' } |
||||
|
} |
||||
|
] |
||||
|
transitions: [ |
||||
|
Transition { |
||||
|
from: '' |
||||
|
to: 'success' |
||||
|
PropertyAnimation { target: helpText; properties: 'text'; duration: 0} |
||||
|
NumberAnimation { target: icon; properties: 'opacity'; from: 0; to: 1; duration: 200 } |
||||
|
NumberAnimation { target: icon; properties: 'scale'; from: 0; to: 1; duration: 500 |
||||
|
easing.type: Easing.OutBack |
||||
|
easing.overshoot: 10 |
||||
|
} |
||||
|
}, |
||||
|
Transition { |
||||
|
from: '' |
||||
|
to: 'failed' |
||||
|
PropertyAnimation { target: helpText; properties: 'text'; duration: 0} |
||||
|
NumberAnimation { target: icon; properties: 'opacity'; from: 0; to: 1; duration: 500 } |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
|
||||
|
ColumnLayout { |
||||
|
id: content |
||||
|
anchors.centerIn: parent |
||||
|
|
||||
|
Item { |
||||
|
Layout.alignment: Qt.AlignHCenter |
||||
|
Layout.preferredWidth: constants.iconSizeXXLarge |
||||
|
Layout.preferredHeight: constants.iconSizeXXLarge |
||||
|
|
||||
|
BusyIndicator { |
||||
|
id: spinner |
||||
|
visible: s.state == '' |
||||
|
width: constants.iconSizeXXLarge |
||||
|
height: constants.iconSizeXXLarge |
||||
|
} |
||||
|
|
||||
|
Image { |
||||
|
id: icon |
||||
|
width: constants.iconSizeXXLarge |
||||
|
height: constants.iconSizeXXLarge |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
Label { |
||||
|
id: helpText |
||||
|
text: qsTr('Paying...') |
||||
|
font.pixelSize: constants.fontSizeXXLarge |
||||
|
Layout.alignment: Qt.AlignHCenter |
||||
|
} |
||||
|
|
||||
|
Label { |
||||
|
id: errorText |
||||
|
font.pixelSize: constants.fontSizeLarge |
||||
|
Layout.alignment: Qt.AlignHCenter |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
Connections { |
||||
|
target: Daemon.currentWallet |
||||
|
function onPaymentSucceeded(key) { |
||||
|
if (key != invoice_key) { |
||||
|
console.log('wrong invoice ' + key + ' != ' + invoice_key) |
||||
|
return |
||||
|
} |
||||
|
console.log('payment succeeded!') |
||||
|
s.state = 'success' |
||||
|
} |
||||
|
function onPaymentFailed(key, reason) { |
||||
|
if (key != invoice_key) { |
||||
|
console.log('wrong invoice ' + key + ' != ' + invoice_key) |
||||
|
return |
||||
|
} |
||||
|
console.log('payment failed: ' + reason) |
||||
|
s.state = 'failed' |
||||
|
errorText.text = reason |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,114 @@ |
|||||
|
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject |
||||
|
|
||||
|
from electrum.logging import get_logger |
||||
|
from electrum.util import format_time, bfh, format_time |
||||
|
|
||||
|
from .qewallet import QEWallet |
||||
|
from .qetypes import QEAmount |
||||
|
|
||||
|
class QELnPaymentDetails(QObject): |
||||
|
def __init__(self, parent=None): |
||||
|
super().__init__(parent) |
||||
|
|
||||
|
_logger = get_logger(__name__) |
||||
|
|
||||
|
_wallet = None |
||||
|
_key = None |
||||
|
_date = None |
||||
|
|
||||
|
detailsChanged = pyqtSignal() |
||||
|
|
||||
|
walletChanged = pyqtSignal() |
||||
|
@pyqtProperty(QEWallet, notify=walletChanged) |
||||
|
def wallet(self): |
||||
|
return self._wallet |
||||
|
|
||||
|
@wallet.setter |
||||
|
def wallet(self, wallet: QEWallet): |
||||
|
if self._wallet != wallet: |
||||
|
self._wallet = wallet |
||||
|
self.walletChanged.emit() |
||||
|
|
||||
|
keyChanged = pyqtSignal() |
||||
|
@pyqtProperty(str, notify=keyChanged) |
||||
|
def key(self): |
||||
|
return self._key |
||||
|
|
||||
|
@key.setter |
||||
|
def key(self, key: str): |
||||
|
if self._key != key: |
||||
|
self._logger.debug('key set -> %s' % key) |
||||
|
self._key = key |
||||
|
self.keyChanged.emit() |
||||
|
self.update() |
||||
|
|
||||
|
labelChanged = pyqtSignal() |
||||
|
@pyqtProperty(str, notify=labelChanged) |
||||
|
def label(self): |
||||
|
return self._label |
||||
|
|
||||
|
@pyqtSlot(str) |
||||
|
def set_label(self, label: str): |
||||
|
if label != self._label: |
||||
|
self._wallet.wallet.set_label(self._key, label) |
||||
|
self._label = label |
||||
|
self.labelChanged.emit() |
||||
|
|
||||
|
@pyqtProperty(str, notify=detailsChanged) |
||||
|
def status(self): |
||||
|
return self._status |
||||
|
|
||||
|
@pyqtProperty(str, notify=detailsChanged) |
||||
|
def date(self): |
||||
|
return self._date |
||||
|
|
||||
|
@pyqtProperty(str, notify=detailsChanged) |
||||
|
def payment_hash(self): |
||||
|
return self._phash |
||||
|
|
||||
|
@pyqtProperty(str, notify=detailsChanged) |
||||
|
def preimage(self): |
||||
|
return self._preimage |
||||
|
|
||||
|
@pyqtProperty(str, notify=detailsChanged) |
||||
|
def invoice(self): |
||||
|
return self._invoice |
||||
|
|
||||
|
@pyqtProperty(QEAmount, notify=detailsChanged) |
||||
|
def amount(self): |
||||
|
return self._amount |
||||
|
|
||||
|
@pyqtProperty(QEAmount, notify=detailsChanged) |
||||
|
def fee(self): |
||||
|
return self._fee |
||||
|
|
||||
|
def update(self): |
||||
|
if self._wallet is None: |
||||
|
self._logger.error('wallet undefined') |
||||
|
return |
||||
|
|
||||
|
if self._key not in self._wallet.wallet.lnworker.payments: |
||||
|
self._logger.error('payment_hash not found') |
||||
|
return |
||||
|
|
||||
|
# TODO this is horribly inefficient. need a payment getter/query method |
||||
|
tx = self._wallet.wallet.lnworker.get_lightning_history()[bfh(self._key)] |
||||
|
self._logger.debug(str(tx)) |
||||
|
|
||||
|
self._fee = QEAmount() if not tx['fee_msat'] else QEAmount(amount_msat=tx['fee_msat']) |
||||
|
self._amount = QEAmount(amount_msat=tx['amount_msat']) |
||||
|
self._label = tx['label'] |
||||
|
self._date = format_time(tx['timestamp']) |
||||
|
self._status = 'settled' # TODO: other states? get_lightning_history is deciding the filter for us :( |
||||
|
self._phash = tx['payment_hash'] |
||||
|
self._preimage = tx['preimage'] |
||||
|
|
||||
|
invoice = (self._wallet.wallet.get_invoice(self._key) |
||||
|
or self._wallet.wallet.get_request(self._key)) |
||||
|
self._logger.debug(str(invoice)) |
||||
|
if invoice: |
||||
|
self._invoice = invoice.lightning_invoice or '' |
||||
|
else: |
||||
|
self._invoice = '' |
||||
|
|
||||
|
self.detailsChanged.emit() |
Loading…
Reference in new issue