Browse Source

Qt.UserRole can be 0 offset, don't repeat wallet create request dict

patch-4
Sander van Grieken 3 years ago
parent
commit
e8ce221a34
  1. 2
      electrum/gui/qml/components/RequestDialog.qml
  2. 4
      electrum/gui/qml/qeaddresslistmodel.py
  3. 4
      electrum/gui/qml/qedaemon.py
  4. 21
      electrum/gui/qml/qerequestlistmodel.py
  5. 4
      electrum/gui/qml/qetransactionlistmodel.py

2
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
}

4
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

4
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

21
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

4
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

Loading…
Cancel
Save