qml: map fields of tx history
This commit is contained in:
@@ -24,7 +24,7 @@ class QEQR(QObject):
|
||||
self.scan_ready_changed.emit()
|
||||
|
||||
pilimage = self.convertToPILImage(image)
|
||||
parseQR(pilimage)
|
||||
self.parseQR(pilimage)
|
||||
|
||||
self._ready = True
|
||||
|
||||
@@ -50,6 +50,7 @@ class QEQR(QObject):
|
||||
return Image.frombytes('RGBA', (image.width(), image.height()), buf2, 'raw')
|
||||
|
||||
def parseQR(self, image):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
@pyqtProperty(bool, notify=scan_ready_changed)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QUrl
|
||||
from PyQt5.QtCore import Qt, QAbstractListModel, QModelIndex
|
||||
from PyQt5.QtCore import Qt, QAbstractListModel, QModelIndex, QByteArray
|
||||
|
||||
from electrum.util import register_callback
|
||||
from electrum.util import register_callback, Satoshis
|
||||
from electrum.logging import get_logger
|
||||
from electrum.wallet import Wallet, Abstract_Wallet
|
||||
|
||||
@@ -10,16 +10,35 @@ class QETransactionsListModel(QAbstractListModel):
|
||||
super().__init__(parent)
|
||||
self.tx_history = []
|
||||
|
||||
_logger = get_logger(__name__)
|
||||
|
||||
# define listmodel rolemap
|
||||
ROLES=('txid','fee_sat','height','confirmations','timestamp','monotonic_timestamp','incoming','bc_value',
|
||||
'bc_balance','date','label','txpos_in_block','fee','inputs','outputs')
|
||||
keys = range(Qt.UserRole + 1, Qt.UserRole + 1 + len(ROLES))
|
||||
ROLENAMES = [bytearray(x.encode()) for x in ROLES]
|
||||
_ROLE_MAP = dict(zip(keys, ROLENAMES))
|
||||
|
||||
def rowCount(self, index):
|
||||
return len(self.tx_history)
|
||||
|
||||
def roleNames(self):
|
||||
return self._ROLE_MAP
|
||||
|
||||
def data(self, index, role):
|
||||
if role == Qt.DisplayRole:
|
||||
return str(self.tx_history[index.row()]['bc_value'])
|
||||
tx = self.tx_history[index.row()]
|
||||
role_index = role - (Qt.UserRole + 1)
|
||||
value = tx[self.ROLES[role_index]]
|
||||
if isinstance(value, bool) or isinstance(value, list) or isinstance(value, int) or value is None:
|
||||
return value
|
||||
if isinstance(value, Satoshis):
|
||||
return value.value
|
||||
return str(value)
|
||||
|
||||
def set_history(self, history):
|
||||
self.beginInsertRows(QModelIndex(), 0, len(history) - 1)
|
||||
self.tx_history = history
|
||||
self.tx_history.reverse()
|
||||
self.endInsertRows()
|
||||
|
||||
class QEWallet(QObject):
|
||||
@@ -39,5 +58,10 @@ class QEWallet(QObject):
|
||||
def get_history(self):
|
||||
history = self.wallet.get_detailed_history(show_addresses = True)
|
||||
txs = history['transactions']
|
||||
self._logger.info(txs)
|
||||
# use primitives
|
||||
for tx in txs:
|
||||
for output in tx['outputs']:
|
||||
output['value'] = output['value'].value
|
||||
self._historyModel.set_history(txs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user