-
Notifications
You must be signed in to change notification settings - Fork 8
/
sendPage.py
39 lines (34 loc) · 1.56 KB
/
sendPage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from PyQt5.QtWidgets import QWidget
from forms.ui_sendpage import Ui_SendPage
class SendPage(QWidget, Ui_SendPage):
"""The page to decode and/or pay bolt11 invoices"""
def __init__(self, plugin):
super().__init__()
self.setupUi(self)
self.plugin = plugin
self.initUi()
def decodeInvoice(self):
"""Decode the given bolt11 invoice"""
invoice = self.plugin.rpc.decodepay(self.lineInvoice.text())
# Condition to prevent for RPC errors
if invoice:
value = str(invoice["amount_msat"])
if invoice["currency"] == "tb":
value += " (testnet)"
self.labelValue.setText(value)
self.labelDescription.setText(invoice["description"])
self.labelExpiry.setText(str(invoice["expiry"]))
self.labelPublicKey.setText(invoice["payee"])
def initUi(self):
"""Initialize the UI by connecting actions"""
self.buttonDecode.clicked.connect(self.decodeInvoice)
self.buttonPay.clicked.connect(self.payInvoice)
def payInvoice(self):
"""Pay the given bolt11 invoice"""
pay_return = self.plugin.rpc.pay(self.lineInvoice.text())
# Condition to prevent for RPC errors
if pay_return:
if "payment_preimage" in pay_return:
self.labelPaymentResult.setText("Succesfully paid invoice. Preimage: {}".format(pay_return["payment_preimage"]))
else:
self.labelPaymentResult.setText("Could not pay invoice. Maybe you should open a channel with the payee")