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
master
Sander van Grieken 4 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): def __init__(self, *, amount_sat: int = 0, amount_msat: int = 0, is_max: bool = False, from_invoice = None, parent=None):
super().__init__(parent) super().__init__(parent)
self._amount_sat = amount_sat self._amount_sat = int(amount_sat) if amount_sat is not None else None
self._amount_msat = amount_msat self._amount_msat = int(amount_msat) if amount_msat is not None else None
self._is_max = is_max self._is_max = is_max
if from_invoice: if from_invoice:
inv_amt = from_invoice.get_amount_msat() inv_amt = from_invoice.get_amount_msat()
if inv_amt == '!': if inv_amt == '!':
self._is_max = True self._is_max = True
elif inv_amt is not None: elif inv_amt is not None:
self._amount_msat = inv_amt self._amount_msat = int(inv_amt)
self._amount_sat = from_invoice.get_amount_sat() self._amount_sat = int(from_invoice.get_amount_sat())
valueChanged = pyqtSignal() valueChanged = pyqtSignal()

15
electrum/gui/qml/qewallet.py

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

Loading…
Cancel
Save