Browse Source

qml: just to be sure, keep QEAmount instances around if exposed to QML

master
Sander van Grieken 3 years ago
parent
commit
d79de092e2
  1. 15
      electrum/gui/qml/qeinvoice.py
  2. 6
      electrum/gui/qml/qelnpaymentdetails.py
  3. 5
      electrum/gui/qml/qetypes.py

15
electrum/gui/qml/qeinvoice.py

@ -175,11 +175,10 @@ class QEInvoiceParser(QEInvoice):
@pyqtProperty(QEAmount, notify=invoiceChanged) @pyqtProperty(QEAmount, notify=invoiceChanged)
def amount(self): 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: if not self._effectiveInvoice:
self._amount.clear()
return self._amount return self._amount
self._amount = QEAmount(from_invoice=self._effectiveInvoice) self._amount.copyFrom(QEAmount(from_invoice=self._effectiveInvoice))
return self._amount return self._amount
@amount.setter @amount.setter
@ -508,16 +507,14 @@ class QEInvoiceParser(QEInvoice):
class QEUserEnteredPayment(QEInvoice): class QEUserEnteredPayment(QEInvoice):
_logger = get_logger(__name__) _logger = get_logger(__name__)
_recipient = None
_message = None
_amount = QEAmount()
validationError = pyqtSignal([str,str], arguments=['code','message']) validationError = pyqtSignal([str,str], arguments=['code','message'])
invoiceCreateError = pyqtSignal([str,str], arguments=['code', 'message']) invoiceCreateError = pyqtSignal([str,str], arguments=['code', 'message'])
invoiceSaved = pyqtSignal() invoiceSaved = pyqtSignal()
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent) super().__init__(parent)
self._amount = QEAmount()
self.clear() self.clear()
recipientChanged = pyqtSignal() recipientChanged = pyqtSignal()
@ -551,7 +548,7 @@ class QEUserEnteredPayment(QEInvoice):
@amount.setter @amount.setter
def amount(self, amount): def amount(self, amount):
if self._amount != amount: if self._amount != amount:
self._amount = amount self._amount.copyFrom(amount)
self.validate() self.validate()
self.amountChanged.emit() self.amountChanged.emit()
@ -604,7 +601,7 @@ class QEUserEnteredPayment(QEInvoice):
@pyqtSlot() @pyqtSlot()
def clear(self): def clear(self):
self._recipient = None self._recipient = None
self._amount = QEAmount() self._amount.clear()
self._message = None self._message = None
self.canSave = False self.canSave = False
self.canPay = False self.canPay = False

6
electrum/gui/qml/qelnpaymentdetails.py

@ -17,6 +17,8 @@ class QELnPaymentDetails(QObject):
self._wallet = None self._wallet = None
self._key = None self._key = None
self._date = None self._date = None
self._fee = QEAmount()
self._amount = QEAmount()
walletChanged = pyqtSignal() walletChanged = pyqtSignal()
@pyqtProperty(QEWallet, notify=walletChanged) @pyqtProperty(QEWallet, notify=walletChanged)
@ -91,8 +93,8 @@ class QELnPaymentDetails(QObject):
tx = self._wallet.wallet.lnworker.get_lightning_history()[bfh(self._key)] tx = self._wallet.wallet.lnworker.get_lightning_history()[bfh(self._key)]
self._logger.debug(str(tx)) self._logger.debug(str(tx))
self._fee = QEAmount() if not tx['fee_msat'] else QEAmount(amount_msat=tx['fee_msat']) self._fee.msatsInt = 0 if not tx['fee_msat'] else int(tx['fee_msat'])
self._amount = QEAmount(amount_msat=tx['amount_msat']) self._amount.msatsInt = int(tx['amount_msat'])
self._label = tx['label'] self._label = tx['label']
self._date = format_time(tx['timestamp']) self._date = format_time(tx['timestamp'])
self._status = 'settled' # TODO: other states? get_lightning_history is deciding the filter for us :( self._status = 'settled' # TODO: other states? get_lightning_history is deciding the filter for us :(

5
electrum/gui/qml/qetypes.py

@ -77,6 +77,11 @@ class QEAmount(QObject):
def isEmpty(self): def isEmpty(self):
return not(self._is_max or self._amount_sat or self._amount_msat) 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): def copyFrom(self, amount):
if not amount: if not amount:
self._logger.warning('copyFrom with None argument. assuming 0') # TODO self._logger.warning('copyFrom with None argument. assuming 0') # TODO

Loading…
Cancel
Save