qml: add 'local' and 'mempool' sections to history, update section on on_tx_verified callback
This commit is contained in:
@@ -27,6 +27,8 @@ Pane {
|
||||
model: visualModel
|
||||
|
||||
readonly property variant sectionLabels: {
|
||||
'local': qsTr('Local'),
|
||||
'mempool': qsTr('Mempool'),
|
||||
'today': qsTr('Today'),
|
||||
'yesterday': qsTr('Yesterday'),
|
||||
'lastweek': qsTr('Last week'),
|
||||
|
||||
@@ -64,7 +64,7 @@ Item {
|
||||
Layout.rowSpan: 2
|
||||
source: model.lightning
|
||||
? "../../../icons/lightning.png"
|
||||
: model.complete
|
||||
: model.complete && model.section != 'local'
|
||||
? tx_icons[Math.min(6,model.confirmations)]
|
||||
: '../../../icons/offline_tx.png'
|
||||
}
|
||||
@@ -93,7 +93,7 @@ Item {
|
||||
}
|
||||
Label {
|
||||
font.pixelSize: constants.fontSizeSmall
|
||||
text: model.date
|
||||
text: model.date ? model.date : ''
|
||||
color: constants.mutedForeground
|
||||
}
|
||||
Label {
|
||||
|
||||
@@ -89,35 +89,35 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
|
||||
item['value'] = QEAmount(amount_sat=item['value'].value)
|
||||
item['balance'] = QEAmount(amount_sat=item['balance'].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'
|
||||
|
||||
item['date'] = self.format_date_by_section(item['section'], datetime.fromtimestamp(item['timestamp']))
|
||||
|
||||
if 'txid' in item:
|
||||
tx = self.wallet.get_input_tx(item['txid'])
|
||||
item['complete'] = tx.is_complete()
|
||||
#else:
|
||||
#item['complete'] = True
|
||||
|
||||
# newly arriving txs, or (partially/fully signed) local txs have no (block) timestamp
|
||||
if not item['timestamp']:
|
||||
txinfo = self.wallet.get_tx_info(tx)
|
||||
item['section'] = 'mempool' if item['complete'] and not txinfo.can_broadcast else 'local'
|
||||
else:
|
||||
item['section'] = self.get_section_by_timestamp(item['timestamp'])
|
||||
item['date'] = self.format_date_by_section(item['section'], datetime.fromtimestamp(item['timestamp']))
|
||||
|
||||
return item
|
||||
|
||||
def get_section_by_timestamp(self, timestamp):
|
||||
txts = datetime.fromtimestamp(timestamp)
|
||||
today = datetime.today().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
|
||||
if (txts > today):
|
||||
return 'today'
|
||||
elif (txts > today - timedelta(days=1)):
|
||||
return 'yesterday'
|
||||
elif (txts > today - timedelta(days=7)):
|
||||
return 'lastweek'
|
||||
elif (txts > today - timedelta(days=31)):
|
||||
return 'lastmonth'
|
||||
else:
|
||||
return 'older'
|
||||
|
||||
def format_date_by_section(self, section, date):
|
||||
#TODO: l10n
|
||||
dfmt = {
|
||||
@@ -154,9 +154,10 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
|
||||
tx['height'] = info.height
|
||||
tx['confirmations'] = info.conf
|
||||
tx['timestamp'] = info.timestamp
|
||||
tx['section'] = self.get_section_by_timestamp(info.timestamp)
|
||||
tx['date'] = self.format_date_by_section(tx['section'], datetime.fromtimestamp(info.timestamp))
|
||||
index = self.index(i,0)
|
||||
roles = [self._ROLE_RMAP[x] for x in ['height','confirmations','timestamp','date']]
|
||||
roles = [self._ROLE_RMAP[x] for x in ['section','height','confirmations','timestamp','date']]
|
||||
self.dataChanged.emit(index, index, roles)
|
||||
return
|
||||
i = i + 1
|
||||
|
||||
Reference in New Issue
Block a user