From e8ce221a34f5fdfe9a94c96e0eb00f60351a7723 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Thu, 14 Apr 2022 11:20:00 +0200 Subject: [PATCH] Qt.UserRole can be 0 offset, don't repeat wallet create request dict --- electrum/gui/qml/components/RequestDialog.qml | 2 +- electrum/gui/qml/qeaddresslistmodel.py | 4 ++-- electrum/gui/qml/qedaemon.py | 4 ++-- electrum/gui/qml/qerequestlistmodel.py | 21 +++++-------------- electrum/gui/qml/qetransactionlistmodel.py | 4 ++-- 5 files changed, 12 insertions(+), 23 deletions(-) diff --git a/electrum/gui/qml/components/RequestDialog.qml b/electrum/gui/qml/components/RequestDialog.qml index 45f9b06dc..614595a5f 100644 --- a/electrum/gui/qml/components/RequestDialog.qml +++ b/electrum/gui/qml/components/RequestDialog.qml @@ -199,7 +199,7 @@ Dialog { } Component.onCompleted: { - _bip21uri = bitcoin.create_uri(modelItem.address, modelItem.amount, modelItem.message, modelItem.timestamp, modelItem.exp) + _bip21uri = bitcoin.create_uri(modelItem.address, modelItem.amount, modelItem.message, modelItem.timestamp, modelItem.expiration) qr.source = 'image://qrgen/' + _bip21uri } diff --git a/electrum/gui/qml/qeaddresslistmodel.py b/electrum/gui/qml/qeaddresslistmodel.py index 5549c87b4..e32caf180 100644 --- a/electrum/gui/qml/qeaddresslistmodel.py +++ b/electrum/gui/qml/qeaddresslistmodel.py @@ -16,7 +16,7 @@ class QEAddressListModel(QAbstractListModel): # define listmodel rolemap _ROLE_NAMES=('type','iaddr','address','label','balance','numtx', 'held') - _ROLE_KEYS = range(Qt.UserRole + 1, Qt.UserRole + 1 + len(_ROLE_NAMES)) + _ROLE_KEYS = range(Qt.UserRole, Qt.UserRole + len(_ROLE_NAMES)) _ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES])) def rowCount(self, index): @@ -30,7 +30,7 @@ class QEAddressListModel(QAbstractListModel): address = self.change_addresses[index.row() - len(self.receive_addresses)] else: address = self.receive_addresses[index.row()] - role_index = role - (Qt.UserRole + 1) + role_index = role - Qt.UserRole value = address[self._ROLE_NAMES[role_index]] if isinstance(value, bool) or isinstance(value, list) or isinstance(value, int) or value is None: return value diff --git a/electrum/gui/qml/qedaemon.py b/electrum/gui/qml/qedaemon.py index c8c66191f..113baf938 100644 --- a/electrum/gui/qml/qedaemon.py +++ b/electrum/gui/qml/qedaemon.py @@ -22,7 +22,7 @@ class QEWalletListModel(QAbstractListModel): # define listmodel rolemap _ROLE_NAMES= ('name','path','active') - _ROLE_KEYS = range(Qt.UserRole + 1, Qt.UserRole + 1 + len(_ROLE_NAMES)) + _ROLE_KEYS = range(Qt.UserRole, Qt.UserRole + len(_ROLE_NAMES)) _ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES])) def rowCount(self, index): @@ -33,7 +33,7 @@ class QEWalletListModel(QAbstractListModel): def data(self, index, role): (wallet_name, wallet_path, wallet) = self.wallets[index.row()] - role_index = role - (Qt.UserRole + 1) + role_index = role - Qt.UserRole role_name = self._ROLE_NAMES[role_index] if role_name == 'name': return wallet_name diff --git a/electrum/gui/qml/qerequestlistmodel.py b/electrum/gui/qml/qerequestlistmodel.py index f6b129120..a664a106c 100644 --- a/electrum/gui/qml/qerequestlistmodel.py +++ b/electrum/gui/qml/qerequestlistmodel.py @@ -14,8 +14,8 @@ class QERequestListModel(QAbstractListModel): _logger = get_logger(__name__) # define listmodel rolemap - _ROLE_NAMES=('key','type','timestamp','date','message','amount','status','status_str','address','exp') - _ROLE_KEYS = range(Qt.UserRole + 1, Qt.UserRole + 1 + len(_ROLE_NAMES)) + _ROLE_NAMES=('key','type','timestamp','date','message','amount','status','status_str','address','expiration') + _ROLE_KEYS = range(Qt.UserRole, Qt.UserRole + len(_ROLE_NAMES)) _ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES])) _ROLE_RMAP = dict(zip(_ROLE_NAMES, _ROLE_KEYS)) @@ -27,7 +27,7 @@ class QERequestListModel(QAbstractListModel): def data(self, index, role): request = self.requests[index.row()] - role_index = role - (Qt.UserRole + 1) + role_index = role - Qt.UserRole value = request[self._ROLE_NAMES[role_index]] if isinstance(value, bool) or isinstance(value, list) or isinstance(value, int) or value is None: return value @@ -41,22 +41,11 @@ class QERequestListModel(QAbstractListModel): self.endResetModel() def request_to_model(self, req: Invoice): - item = {} - key = self.wallet.get_key_for_receive_request(req) # (verified) address for onchain, rhash for LN - status = self.wallet.get_request_status(key) - item['status'] = status - item['status_str'] = req.get_status_str(status) + item = self.wallet.export_request(req) + item['key'] = self.wallet.get_key_for_receive_request(req) item['type'] = req.type # 0=onchain, 2=LN - item['timestamp'] = req.time item['date'] = format_time(item['timestamp']) item['amount'] = req.get_amount_sat() - item['message'] = req.message - item['exp'] = req.exp - if req.type == 0: # OnchainInvoice - item['key'] = item['address'] = req.get_address() - elif req.type == 2: # LNInvoice - #item['key'] = req.getrhash() - pass return item diff --git a/electrum/gui/qml/qetransactionlistmodel.py b/electrum/gui/qml/qetransactionlistmodel.py index 0e05b40c8..453e1a85b 100644 --- a/electrum/gui/qml/qetransactionlistmodel.py +++ b/electrum/gui/qml/qetransactionlistmodel.py @@ -18,7 +18,7 @@ class QETransactionListModel(QAbstractListModel): _ROLE_NAMES=('txid','fee_sat','height','confirmations','timestamp','monotonic_timestamp', 'incoming','bc_value','bc_balance','date','label','txpos_in_block','fee', 'inputs','outputs','section') - _ROLE_KEYS = range(Qt.UserRole + 1, Qt.UserRole + 1 + len(_ROLE_NAMES)) + _ROLE_KEYS = range(Qt.UserRole, Qt.UserRole + len(_ROLE_NAMES)) _ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES])) _ROLE_RMAP = dict(zip(_ROLE_NAMES, _ROLE_KEYS)) @@ -30,7 +30,7 @@ class QETransactionListModel(QAbstractListModel): def data(self, index, role): tx = self.tx_history[index.row()] - role_index = role - (Qt.UserRole + 1) + role_index = role - Qt.UserRole value = tx[self._ROLE_NAMES[role_index]] if isinstance(value, bool) or isinstance(value, list) or isinstance(value, int) or value is None: return value