Browse Source

fix some issues with QEAmount use

- always cast amount_sat and amount_msat to int within QEAmount to avoid conversion issues
  on the Qt/python boundary
- lightningBalance/lightningCanSend/lightningCanReceive were returning a floating QEAMount instance, leading to a crash
patch-4
Sander van Grieken 3 years ago
parent
commit
4e98022686
  1. 8
      electrum/gui/qml/qetypes.py
  2. 15
      electrum/gui/qml/qewallet.py

8
electrum/gui/qml/qetypes.py

@ -17,16 +17,16 @@ class QEAmount(QObject):
def __init__(self, *, amount_sat: int = 0, amount_msat: int = 0, is_max: bool = False, from_invoice = None, parent=None):
super().__init__(parent)
self._amount_sat = amount_sat
self._amount_msat = amount_msat
self._amount_sat = int(amount_sat) if amount_sat is not None else None
self._amount_msat = int(amount_msat) if amount_msat is not None else None
self._is_max = is_max
if from_invoice:
inv_amt = from_invoice.get_amount_msat()
if inv_amt == '!':
self._is_max = True
elif inv_amt is not None:
self._amount_msat = inv_amt
self._amount_sat = from_invoice.get_amount_sat()
self._amount_msat = int(inv_amt)
self._amount_sat = int(from_invoice.get_amount_sat())
valueChanged = pyqtSignal()

15
electrum/gui/qml/qewallet.py

@ -306,22 +306,25 @@ class QEWallet(QObject):
@pyqtProperty(QEAmount, notify=balanceChanged)
def lightningBalance(self):
if not self.isLightning:
return QEAmount()
self._lightningbalance = QEAmount(amount_sat=int(self.wallet.lnworker.get_balance()))
self._lightningbalance = QEAmount()
else:
self._lightningbalance = QEAmount(amount_sat=int(self.wallet.lnworker.get_balance()))
return self._lightningbalance
@pyqtProperty(QEAmount, notify=balanceChanged)
def lightningCanSend(self):
if not self.isLightning:
return QEAmount()
self._lightningcansend = QEAmount(amount_sat=int(self.wallet.lnworker.num_sats_can_send()))
self._lightningcansend = QEAmount()
else:
self._lightningcansend = QEAmount(amount_sat=int(self.wallet.lnworker.num_sats_can_send()))
return self._lightningcansend
@pyqtProperty(QEAmount, notify=balanceChanged)
def lightningCanReceive(self):
if not self.isLightning:
return QEAmount()
self._lightningcanreceive = QEAmount(amount_sat=int(self.wallet.lnworker.num_sats_can_receive()))
self._lightningcanreceive = QEAmount()
else:
self._lightningcanreceive = QEAmount(amount_sat=int(self.wallet.lnworker.num_sats_can_receive()))
return self._lightningcanreceive
@pyqtSlot()

Loading…
Cancel
Save