qml: just to be sure, keep QEAmount instances around if exposed to QML
This commit is contained in:
@@ -175,11 +175,10 @@ class QEInvoiceParser(QEInvoice):
|
||||
|
||||
@pyqtProperty(QEAmount, notify=invoiceChanged)
|
||||
def amount(self):
|
||||
# store ref to QEAmount on instance, otherwise we get destroyed when going out of scope
|
||||
self._amount = QEAmount()
|
||||
if not self._effectiveInvoice:
|
||||
self._amount.clear()
|
||||
return self._amount
|
||||
self._amount = QEAmount(from_invoice=self._effectiveInvoice)
|
||||
self._amount.copyFrom(QEAmount(from_invoice=self._effectiveInvoice))
|
||||
return self._amount
|
||||
|
||||
@amount.setter
|
||||
@@ -508,16 +507,14 @@ class QEInvoiceParser(QEInvoice):
|
||||
class QEUserEnteredPayment(QEInvoice):
|
||||
_logger = get_logger(__name__)
|
||||
|
||||
_recipient = None
|
||||
_message = None
|
||||
_amount = QEAmount()
|
||||
|
||||
validationError = pyqtSignal([str,str], arguments=['code','message'])
|
||||
invoiceCreateError = pyqtSignal([str,str], arguments=['code', 'message'])
|
||||
invoiceSaved = pyqtSignal()
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self._amount = QEAmount()
|
||||
self.clear()
|
||||
|
||||
recipientChanged = pyqtSignal()
|
||||
@@ -551,7 +548,7 @@ class QEUserEnteredPayment(QEInvoice):
|
||||
@amount.setter
|
||||
def amount(self, amount):
|
||||
if self._amount != amount:
|
||||
self._amount = amount
|
||||
self._amount.copyFrom(amount)
|
||||
self.validate()
|
||||
self.amountChanged.emit()
|
||||
|
||||
@@ -604,7 +601,7 @@ class QEUserEnteredPayment(QEInvoice):
|
||||
@pyqtSlot()
|
||||
def clear(self):
|
||||
self._recipient = None
|
||||
self._amount = QEAmount()
|
||||
self._amount.clear()
|
||||
self._message = None
|
||||
self.canSave = False
|
||||
self.canPay = False
|
||||
|
||||
@@ -17,6 +17,8 @@ class QELnPaymentDetails(QObject):
|
||||
self._wallet = None
|
||||
self._key = None
|
||||
self._date = None
|
||||
self._fee = QEAmount()
|
||||
self._amount = QEAmount()
|
||||
|
||||
walletChanged = pyqtSignal()
|
||||
@pyqtProperty(QEWallet, notify=walletChanged)
|
||||
@@ -91,8 +93,8 @@ class QELnPaymentDetails(QObject):
|
||||
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._fee.msatsInt = 0 if not tx['fee_msat'] else int(tx['fee_msat'])
|
||||
self._amount.msatsInt = int(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 :(
|
||||
|
||||
@@ -77,6 +77,11 @@ class QEAmount(QObject):
|
||||
def isEmpty(self):
|
||||
return not(self._is_max or self._amount_sat or self._amount_msat)
|
||||
|
||||
def clear(self):
|
||||
self.satsInt = 0
|
||||
self.msatsInt = 0
|
||||
self.isMax = False
|
||||
|
||||
def copyFrom(self, amount):
|
||||
if not amount:
|
||||
self._logger.warning('copyFrom with None argument. assuming 0') # TODO
|
||||
|
||||
Reference in New Issue
Block a user