|
@ -1,4 +1,4 @@ |
|
|
from datetime import datetime |
|
|
from datetime import datetime, timedelta |
|
|
|
|
|
|
|
|
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject |
|
|
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject |
|
|
from PyQt5.QtCore import Qt, QAbstractListModel, QModelIndex |
|
|
from PyQt5.QtCore import Qt, QAbstractListModel, QModelIndex |
|
@ -17,7 +17,7 @@ class QETransactionListModel(QAbstractListModel): |
|
|
# define listmodel rolemap |
|
|
# define listmodel rolemap |
|
|
_ROLE_NAMES=('txid','fee_sat','height','confirmations','timestamp','monotonic_timestamp', |
|
|
_ROLE_NAMES=('txid','fee_sat','height','confirmations','timestamp','monotonic_timestamp', |
|
|
'incoming','bc_value','bc_balance','date','label','txpos_in_block','fee', |
|
|
'incoming','bc_value','bc_balance','date','label','txpos_in_block','fee', |
|
|
'inputs','outputs') |
|
|
'inputs','outputs','section') |
|
|
_ROLE_KEYS = range(Qt.UserRole + 1, Qt.UserRole + 1 + len(_ROLE_NAMES)) |
|
|
_ROLE_KEYS = range(Qt.UserRole + 1, Qt.UserRole + 1 + len(_ROLE_NAMES)) |
|
|
_ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES])) |
|
|
_ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES])) |
|
|
_ROLE_RMAP = dict(zip(_ROLE_NAMES, _ROLE_KEYS)) |
|
|
_ROLE_RMAP = dict(zip(_ROLE_NAMES, _ROLE_KEYS)) |
|
@ -43,14 +43,38 @@ class QETransactionListModel(QAbstractListModel): |
|
|
self.tx_history = [] |
|
|
self.tx_history = [] |
|
|
self.endResetModel() |
|
|
self.endResetModel() |
|
|
|
|
|
|
|
|
|
|
|
def tx_to_model(self, tx): |
|
|
|
|
|
item = tx |
|
|
|
|
|
for output in item['outputs']: |
|
|
|
|
|
output['value'] = output['value'].value |
|
|
|
|
|
|
|
|
|
|
|
# newly arriving txs have no (block) timestamp |
|
|
|
|
|
# TODO? |
|
|
|
|
|
if not item['timestamp']: |
|
|
|
|
|
item['timestamp'] = datetime.timestamp(datetime.now()) |
|
|
|
|
|
|
|
|
|
|
|
txts = datetime.fromtimestamp(item['timestamp']) |
|
|
|
|
|
today = datetime.today().replace(hour=0, minute=0, second=0, microsecond=0) |
|
|
|
|
|
|
|
|
|
|
|
if (txts > today): |
|
|
|
|
|
item['section'] = 'today' |
|
|
|
|
|
elif (txts > today - timedelta(days=1)): |
|
|
|
|
|
item['section'] = 'yesterday' |
|
|
|
|
|
elif (txts > today - timedelta(days=7)): |
|
|
|
|
|
item['section'] = 'lastweek' |
|
|
|
|
|
elif (txts > today - timedelta(days=31)): |
|
|
|
|
|
item['section'] = 'lastmonth' |
|
|
|
|
|
else: |
|
|
|
|
|
item['section'] = 'older' |
|
|
|
|
|
|
|
|
|
|
|
return item |
|
|
|
|
|
|
|
|
# initial model data |
|
|
# initial model data |
|
|
def init_model(self): |
|
|
def init_model(self): |
|
|
history = self.wallet.get_detailed_history(show_addresses = True) |
|
|
history = self.wallet.get_detailed_history(show_addresses = True) |
|
|
txs = history['transactions'] |
|
|
txs = [] |
|
|
# use primitives |
|
|
for tx in history['transactions']: |
|
|
for tx in txs: |
|
|
txs.append(self.tx_to_model(tx)) |
|
|
for output in tx['outputs']: |
|
|
|
|
|
output['value'] = output['value'].value |
|
|
|
|
|
|
|
|
|
|
|
self.clear() |
|
|
self.clear() |
|
|
self.beginInsertRows(QModelIndex(), 0, len(txs) - 1) |
|
|
self.beginInsertRows(QModelIndex(), 0, len(txs) - 1) |
|
|