Browse Source

simplify tx history: do not use separate columns for lightning

dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
ThomasV 6 years ago
parent
commit
e584a7451c
  1. 43
      electrum/gui/qt/history_list.py
  2. 8
      electrum/wallet.py

43
electrum/gui/qt/history_list.py

@ -82,12 +82,10 @@ class HistoryColumns(IntEnum):
DESCRIPTION = 1 DESCRIPTION = 1
AMOUNT = 2 AMOUNT = 2
BALANCE = 3 BALANCE = 3
LN_AMOUNT = 4 FIAT_VALUE = 4
LN_BALANCE = 5 FIAT_ACQ_PRICE = 5
FIAT_VALUE = 6 FIAT_CAP_GAINS = 6
FIAT_ACQ_PRICE = 7 TXID = 7
FIAT_CAP_GAINS = 8
TXID = 9
class HistorySortModel(QSortFilterProxyModel): class HistorySortModel(QSortFilterProxyModel):
def lessThan(self, source_left: QModelIndex, source_right: QModelIndex): def lessThan(self, source_left: QModelIndex, source_right: QModelIndex):
@ -172,13 +170,11 @@ class HistoryModel(QAbstractItemModel, Logger):
HistoryColumns.DESCRIPTION: HistoryColumns.DESCRIPTION:
tx_item['label'] if 'label' in tx_item else None, tx_item['label'] if 'label' in tx_item else None,
HistoryColumns.AMOUNT: HistoryColumns.AMOUNT:
tx_item['bc_value'].value if 'bc_value' in tx_item else None, (tx_item['bc_value'].value if 'bc_value' in tx_item else 0)\
HistoryColumns.LN_AMOUNT: + (tx_item['ln_value'].value if 'ln_value' in tx_item else 0),
tx_item['ln_value'].value if 'ln_value' in tx_item else None,
HistoryColumns.BALANCE: HistoryColumns.BALANCE:
tx_item['balance'].value if not is_lightning else None, (tx_item['balance'].value if 'balance' in tx_item else 0)\
HistoryColumns.LN_BALANCE: + (tx_item['balance_msat']//1000 if 'balance_msat'in tx_item else 0),
tx_item['balance_msat'] if 'balance_msat' in tx_item else None,
HistoryColumns.FIAT_VALUE: HistoryColumns.FIAT_VALUE:
tx_item['fiat_value'].value if 'fiat_value' in tx_item else None, tx_item['fiat_value'].value if 'fiat_value' in tx_item else None,
HistoryColumns.FIAT_ACQ_PRICE: HistoryColumns.FIAT_ACQ_PRICE:
@ -216,22 +212,16 @@ class HistoryModel(QAbstractItemModel, Logger):
return QVariant(status_str) return QVariant(status_str)
elif col == HistoryColumns.DESCRIPTION and 'label' in tx_item: elif col == HistoryColumns.DESCRIPTION and 'label' in tx_item:
return QVariant(tx_item['label']) return QVariant(tx_item['label'])
elif col == HistoryColumns.AMOUNT and 'bc_value' in tx_item: elif col == HistoryColumns.AMOUNT:
value = tx_item['bc_value'].value bc_value = tx_item['bc_value'].value if 'bc_value' in tx_item else 0
ln_value = tx_item['ln_value'].value if 'ln_value' in tx_item else 0
value = bc_value + ln_value
v_str = self.parent.format_amount(value, is_diff=True, whitespaces=True) v_str = self.parent.format_amount(value, is_diff=True, whitespaces=True)
return QVariant(v_str) return QVariant(v_str)
elif col == HistoryColumns.LN_AMOUNT and 'ln_value' in tx_item: elif col == HistoryColumns.BALANCE:
ln_value = tx_item['ln_value'].value
v_str = self.parent.format_amount(ln_value, is_diff=True, whitespaces=True)
return QVariant(v_str)
elif col == HistoryColumns.BALANCE and not is_lightning:
balance = tx_item['balance'].value balance = tx_item['balance'].value
balance_str = self.parent.format_amount(balance, whitespaces=True) balance_str = self.parent.format_amount(balance, whitespaces=True)
return QVariant(balance_str) return QVariant(balance_str)
elif col == HistoryColumns.LN_BALANCE and 'balance_msat' in tx_item:
balance = tx_item['balance_msat']//1000
balance_str = self.parent.format_amount(balance, whitespaces=True)
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 = self.parent.fx.format_fiat(tx_item['fiat_value'].value) value_str = self.parent.fx.format_fiat(tx_item['fiat_value'].value)
return QVariant(value_str) return QVariant(value_str)
@ -370,9 +360,7 @@ class HistoryModel(QAbstractItemModel, Logger):
HistoryColumns.STATUS: _('Date'), HistoryColumns.STATUS: _('Date'),
HistoryColumns.DESCRIPTION: _('Description'), HistoryColumns.DESCRIPTION: _('Description'),
HistoryColumns.AMOUNT: _('Amount'), HistoryColumns.AMOUNT: _('Amount'),
HistoryColumns.LN_AMOUNT: u'\U0001f5f2 ' + _('Amount'),
HistoryColumns.BALANCE: _('Balance'), HistoryColumns.BALANCE: _('Balance'),
HistoryColumns.LN_BALANCE: u'\U0001f5f2 ' + _('Balance'),
HistoryColumns.FIAT_VALUE: fiat_title, HistoryColumns.FIAT_VALUE: fiat_title,
HistoryColumns.FIAT_ACQ_PRICE: fiat_acq_title, HistoryColumns.FIAT_ACQ_PRICE: fiat_acq_title,
HistoryColumns.FIAT_CAP_GAINS: fiat_cg_title, HistoryColumns.FIAT_CAP_GAINS: fiat_cg_title,
@ -419,9 +407,6 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
self.proxy = HistorySortModel(self) self.proxy = HistorySortModel(self)
self.proxy.setSourceModel(model) self.proxy.setSourceModel(model)
self.setModel(self.proxy) self.setModel(self.proxy)
if not self.config.get('lightning'):
self.setColumnHidden(HistoryColumns.LN_BALANCE, True)
self.setColumnHidden(HistoryColumns.LN_AMOUNT, True)
AcceptFileDragDrop.__init__(self, ".txn") AcceptFileDragDrop.__init__(self, ".txn")
self.setSortingEnabled(True) self.setSortingEnabled(True)
self.start_timestamp = None self.start_timestamp = None
@ -622,7 +607,7 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
menu.addAction(_("Remove"), lambda: self.remove_local_tx(tx_hash)) menu.addAction(_("Remove"), lambda: self.remove_local_tx(tx_hash))
menu.addAction(_("Copy Transaction ID"), lambda: self.parent.app.clipboard().setText(tx_hash)) menu.addAction(_("Copy Transaction ID"), lambda: self.parent.app.clipboard().setText(tx_hash))
amount_columns = [HistoryColumns.AMOUNT, HistoryColumns.BALANCE, HistoryColumns.LN_AMOUNT, HistoryColumns.LN_BALANCE, amount_columns = [HistoryColumns.AMOUNT, HistoryColumns.BALANCE,
HistoryColumns.FIAT_VALUE, HistoryColumns.FIAT_ACQ_PRICE, HistoryColumns.FIAT_CAP_GAINS] HistoryColumns.FIAT_VALUE, HistoryColumns.FIAT_ACQ_PRICE, HistoryColumns.FIAT_CAP_GAINS]
if column in amount_columns: if column in amount_columns:
column_data = column_data.strip() column_data = column_data.strip()

8
electrum/wallet.py

@ -491,7 +491,7 @@ class Abstract_Wallet(AddressSynchronizer):
'timestamp': tx_mined_status.timestamp, 'timestamp': tx_mined_status.timestamp,
'incoming': True if value>0 else False, 'incoming': True if value>0 else False,
'bc_value': Satoshis(value), 'bc_value': Satoshis(value),
'balance': Satoshis(balance), 'bc_balance': Satoshis(balance),
'date': timestamp_to_datetime(tx_mined_status.timestamp), 'date': timestamp_to_datetime(tx_mined_status.timestamp),
'label': self.get_label(tx_hash), 'label': self.get_label(tx_hash),
'txpos_in_block': tx_mined_status.txpos, 'txpos_in_block': tx_mined_status.txpos,
@ -505,6 +505,7 @@ class Abstract_Wallet(AddressSynchronizer):
txid = tx_item['txid'] txid = tx_item['txid']
transactions[txid] = tx_item transactions[txid] = tx_item
lightning_history = self.lnworker.get_history() if self.lnworker else [] lightning_history = self.lnworker.get_history() if self.lnworker else []
for i, tx_item in enumerate(lightning_history): for i, tx_item in enumerate(lightning_history):
txid = tx_item.get('txid') txid = tx_item.get('txid')
ln_value = Decimal(tx_item['amount_msat']) / 1000 ln_value = Decimal(tx_item['amount_msat']) / 1000
@ -512,7 +513,7 @@ class Abstract_Wallet(AddressSynchronizer):
item = transactions[txid] item = transactions[txid]
item['label'] = tx_item['label'] item['label'] = tx_item['label']
item['ln_value'] = Satoshis(ln_value) item['ln_value'] = Satoshis(ln_value)
item['balance_msat'] = tx_item['balance_msat'] item['ln_balance_msat'] = tx_item['balance_msat']
else: else:
tx_item['lightning'] = True tx_item['lightning'] = True
tx_item['ln_value'] = Satoshis(ln_value) tx_item['ln_value'] = Satoshis(ln_value)
@ -520,6 +521,7 @@ class Abstract_Wallet(AddressSynchronizer):
key = tx_item['payment_hash'] if 'payment_hash' in tx_item else tx_item['type'] + tx_item['channel_id'] key = tx_item['payment_hash'] if 'payment_hash' in tx_item else tx_item['type'] + tx_item['channel_id']
transactions[key] = tx_item transactions[key] = tx_item
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)
@ -528,6 +530,8 @@ class Abstract_Wallet(AddressSynchronizer):
if item.get('ln_value'): if item.get('ln_value'):
value += item.get('ln_value').value value += item.get('ln_value').value
item['value'] = Satoshis(value) item['value'] = Satoshis(value)
balance += value
item['balance'] = Satoshis(balance)
if fx: if fx:
timestamp = item['timestamp'] or now timestamp = item['timestamp'] or now
fiat_value = value / Decimal(bitcoin.COIN) * fx.timestamp_rate(timestamp) fiat_value = value / Decimal(bitcoin.COIN) * fx.timestamp_rate(timestamp)

Loading…
Cancel
Save