Let the GUI compute the balance displayed in history.
Since Qt groups swap transactions, the displayed balance was sometimes incorrect.
This commit is contained in:
@@ -20,7 +20,7 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
|
|||||||
|
|
||||||
# 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','value','balance','date','label','txpos_in_block','fee',
|
'incoming','value','date','label','txpos_in_block','fee',
|
||||||
'inputs','outputs','section','type','lightning','payment_hash','key','complete')
|
'inputs','outputs','section','type','lightning','payment_hash','key','complete')
|
||||||
_ROLE_KEYS = range(Qt.UserRole, Qt.UserRole + 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_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES]))
|
||||||
@@ -127,13 +127,11 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
|
|||||||
|
|
||||||
if item['lightning']:
|
if item['lightning']:
|
||||||
item['value'] = QEAmount(amount_sat=item['value'].value, amount_msat=item['amount_msat'])
|
item['value'] = QEAmount(amount_sat=item['value'].value, amount_msat=item['amount_msat'])
|
||||||
item['balance'] = QEAmount(amount_sat=item['balance'].value, amount_msat=item['amount_msat'])
|
|
||||||
if item['type'] == 'payment':
|
if item['type'] == 'payment':
|
||||||
item['incoming'] = True if item['direction'] == 'received' else False
|
item['incoming'] = True if item['direction'] == 'received' else False
|
||||||
item['confirmations'] = 0
|
item['confirmations'] = 0
|
||||||
else:
|
else:
|
||||||
item['value'] = QEAmount(amount_sat=item['value'].value)
|
item['value'] = QEAmount(amount_sat=item['value'].value)
|
||||||
item['balance'] = QEAmount(amount_sat=item['balance'].value)
|
|
||||||
|
|
||||||
if 'txid' in item:
|
if 'txid' in item:
|
||||||
tx = self.wallet.db.get_transaction(item['txid'])
|
tx = self.wallet.db.get_transaction(item['txid'])
|
||||||
|
|||||||
@@ -206,8 +206,8 @@ class HistoryNode(CustomNode):
|
|||||||
v_str = window.format_amount(value, is_diff=True, whitespaces=whitespaces, add_thousands_sep=add_thousands_sep)
|
v_str = window.format_amount(value, is_diff=True, whitespaces=whitespaces, add_thousands_sep=add_thousands_sep)
|
||||||
return QVariant(v_str)
|
return QVariant(v_str)
|
||||||
elif col == HistoryColumns.BALANCE:
|
elif col == HistoryColumns.BALANCE:
|
||||||
balance = tx_item['balance'].value
|
balance = tx_item['balance'].value if 'balance' in tx_item else None
|
||||||
balance_str = window.format_amount(balance, whitespaces=whitespaces, add_thousands_sep=add_thousands_sep)
|
balance_str = window.format_amount(balance, whitespaces=whitespaces, add_thousands_sep=add_thousands_sep) if balance is not None else ''
|
||||||
return QVariant(balance_str)
|
return QVariant(balance_str)
|
||||||
elif col == HistoryColumns.FIAT_VALUE and 'fiat_value' in tx_item:
|
elif col == HistoryColumns.FIAT_VALUE and 'fiat_value' in tx_item:
|
||||||
value_str = window.fx.format_fiat(tx_item['fiat_value'].value, add_thousands_sep=add_thousands_sep)
|
value_str = window.fx.format_fiat(tx_item['fiat_value'].value, add_thousands_sep=add_thousands_sep)
|
||||||
@@ -322,7 +322,6 @@ class HistoryModel(CustomModel, Logger):
|
|||||||
# add child to parent
|
# add child to parent
|
||||||
parent.addChild(node)
|
parent.addChild(node)
|
||||||
# update parent data
|
# update parent data
|
||||||
parent._data['balance'] = tx_item['balance']
|
|
||||||
parent._data['value'] += tx_item['value']
|
parent._data['value'] += tx_item['value']
|
||||||
if 'group_label' in tx_item:
|
if 'group_label' in tx_item:
|
||||||
parent._data['label'] = tx_item['group_label']
|
parent._data['label'] = tx_item['group_label']
|
||||||
@@ -339,6 +338,12 @@ class HistoryModel(CustomModel, Logger):
|
|||||||
parent._data['height'] = tx_item['height']
|
parent._data['height'] = tx_item['height']
|
||||||
parent._data['confirmations'] = tx_item['confirmations']
|
parent._data['confirmations'] = tx_item['confirmations']
|
||||||
|
|
||||||
|
# compute balance once all children have beed added
|
||||||
|
balance = 0
|
||||||
|
for node in self._root._children:
|
||||||
|
balance += node._data['value'].value
|
||||||
|
node._data['balance'] = Satoshis(balance
|
||||||
|
|
||||||
new_length = self._root.childCount()
|
new_length = self._root.childCount()
|
||||||
self.beginInsertRows(QModelIndex(), 0, new_length-1)
|
self.beginInsertRows(QModelIndex(), 0, new_length-1)
|
||||||
self.transactions = transactions
|
self.transactions = transactions
|
||||||
|
|||||||
@@ -115,8 +115,10 @@ class ElectrumGui(BaseElectrumGui, EventListener):
|
|||||||
time_str = 'unconfirmed'
|
time_str = 'unconfirmed'
|
||||||
|
|
||||||
label = self.wallet.get_label_for_txid(hist_item.txid)
|
label = self.wallet.get_label_for_txid(hist_item.txid)
|
||||||
messages.append(format_str % (time_str, label, format_satoshis(delta, whitespaces=True),
|
messages.append(format_str % (
|
||||||
format_satoshis(hist_item.balance, whitespaces=True)))
|
time_str, label,
|
||||||
|
format_satoshis(hist_item.delta, whitespaces=True),
|
||||||
|
format_satoshis(hist_item.balance, whitespaces=True)))
|
||||||
|
|
||||||
self.print_list(messages[::-1], format_str%(_("Date"), _("Description"), _("Amount"), _("Balance")))
|
self.print_list(messages[::-1], format_str%(_("Date"), _("Description"), _("Amount"), _("Balance")))
|
||||||
|
|
||||||
|
|||||||
@@ -164,9 +164,10 @@ class ElectrumGui(BaseElectrumGui, EventListener):
|
|||||||
domain = self.wallet.get_addresses()
|
domain = self.wallet.get_addresses()
|
||||||
self.history = []
|
self.history = []
|
||||||
self.txid = []
|
self.txid = []
|
||||||
|
balance_sat = 0
|
||||||
for item in self.wallet.get_full_history().values():
|
for item in self.wallet.get_full_history().values():
|
||||||
amount_sat = item['value'].value
|
amount_sat = item['value'].value
|
||||||
balance_sat = item['balance'].value
|
balance_sat += amount_sat
|
||||||
if item.get('lightning'):
|
if item.get('lightning'):
|
||||||
timestamp = item['timestamp']
|
timestamp = item['timestamp']
|
||||||
label = self.wallet.get_label_for_rhash(item['payment_hash'])
|
label = self.wallet.get_label_for_rhash(item['payment_hash'])
|
||||||
|
|||||||
@@ -1280,7 +1280,6 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
for k, v in sorted(list(transactions_tmp.items()), key=sort_key):
|
for k, v in sorted(list(transactions_tmp.items()), key=sort_key):
|
||||||
transactions[k] = v
|
transactions[k] = v
|
||||||
now = time.time()
|
now = time.time()
|
||||||
balance = 0
|
|
||||||
for item in transactions.values():
|
for item in transactions.values():
|
||||||
# add on-chain and lightning values
|
# add on-chain and lightning values
|
||||||
value = Decimal(0)
|
value = Decimal(0)
|
||||||
@@ -1288,10 +1287,8 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
value += item['bc_value'].value
|
value += item['bc_value'].value
|
||||||
if item.get('ln_value'):
|
if item.get('ln_value'):
|
||||||
value += item.get('ln_value').value
|
value += item.get('ln_value').value
|
||||||
# note: 'value' and 'balance' has msat precision (as LN has msat precision)
|
# note: 'value' has msat precision (as LN has msat precision)
|
||||||
item['value'] = Satoshis(value)
|
item['value'] = Satoshis(value)
|
||||||
balance += value
|
|
||||||
item['balance'] = Satoshis(balance)
|
|
||||||
if include_fiat:
|
if include_fiat:
|
||||||
txid = item.get('txid')
|
txid = item.get('txid')
|
||||||
if not item.get('lightning') and txid:
|
if not item.get('lightning') and txid:
|
||||||
|
|||||||
Reference in New Issue
Block a user