electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit e584a7451c04c9dee684aa3d92a6ac73af4ba6b8
parent 80c52d4808014fa58773021ac66f6686bebae08c
Author: ThomasV <thomasv@electrum.org>
Date:   Fri,  2 Aug 2019 10:03:08 +0200

simplify tx history: do not use separate columns for lightning

Diffstat:
Melectrum/gui/qt/history_list.py | 43++++++++++++++-----------------------------
Melectrum/wallet.py | 8++++++--
2 files changed, 20 insertions(+), 31 deletions(-)

diff --git a/electrum/gui/qt/history_list.py b/electrum/gui/qt/history_list.py @@ -82,12 +82,10 @@ class HistoryColumns(IntEnum): DESCRIPTION = 1 AMOUNT = 2 BALANCE = 3 - LN_AMOUNT = 4 - LN_BALANCE = 5 - FIAT_VALUE = 6 - FIAT_ACQ_PRICE = 7 - FIAT_CAP_GAINS = 8 - TXID = 9 + FIAT_VALUE = 4 + FIAT_ACQ_PRICE = 5 + FIAT_CAP_GAINS = 6 + TXID = 7 class HistorySortModel(QSortFilterProxyModel): def lessThan(self, source_left: QModelIndex, source_right: QModelIndex): @@ -172,13 +170,11 @@ class HistoryModel(QAbstractItemModel, Logger): HistoryColumns.DESCRIPTION: tx_item['label'] if 'label' in tx_item else None, HistoryColumns.AMOUNT: - tx_item['bc_value'].value if 'bc_value' in tx_item else None, - HistoryColumns.LN_AMOUNT: - tx_item['ln_value'].value if 'ln_value' in tx_item else None, + (tx_item['bc_value'].value if 'bc_value' in tx_item else 0)\ + + (tx_item['ln_value'].value if 'ln_value' in tx_item else 0), HistoryColumns.BALANCE: - tx_item['balance'].value if not is_lightning else None, - HistoryColumns.LN_BALANCE: - tx_item['balance_msat'] if 'balance_msat' in tx_item else None, + (tx_item['balance'].value if 'balance' in tx_item else 0)\ + + (tx_item['balance_msat']//1000 if 'balance_msat'in tx_item else 0), HistoryColumns.FIAT_VALUE: tx_item['fiat_value'].value if 'fiat_value' in tx_item else None, HistoryColumns.FIAT_ACQ_PRICE: @@ -216,22 +212,16 @@ class HistoryModel(QAbstractItemModel, Logger): return QVariant(status_str) elif col == HistoryColumns.DESCRIPTION and 'label' in tx_item: return QVariant(tx_item['label']) - elif col == HistoryColumns.AMOUNT and 'bc_value' in tx_item: - value = tx_item['bc_value'].value + elif col == HistoryColumns.AMOUNT: + 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) return QVariant(v_str) - elif col == HistoryColumns.LN_AMOUNT and 'ln_value' in tx_item: - 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: + elif col == HistoryColumns.BALANCE: balance = tx_item['balance'].value balance_str = self.parent.format_amount(balance, whitespaces=True) 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: value_str = self.parent.fx.format_fiat(tx_item['fiat_value'].value) return QVariant(value_str) @@ -370,9 +360,7 @@ class HistoryModel(QAbstractItemModel, Logger): HistoryColumns.STATUS: _('Date'), HistoryColumns.DESCRIPTION: _('Description'), HistoryColumns.AMOUNT: _('Amount'), - HistoryColumns.LN_AMOUNT: u'\U0001f5f2 ' + _('Amount'), HistoryColumns.BALANCE: _('Balance'), - HistoryColumns.LN_BALANCE: u'\U0001f5f2 ' + _('Balance'), HistoryColumns.FIAT_VALUE: fiat_title, HistoryColumns.FIAT_ACQ_PRICE: fiat_acq_title, HistoryColumns.FIAT_CAP_GAINS: fiat_cg_title, @@ -419,9 +407,6 @@ class HistoryList(MyTreeView, AcceptFileDragDrop): self.proxy = HistorySortModel(self) self.proxy.setSourceModel(model) 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") self.setSortingEnabled(True) self.start_timestamp = None @@ -622,7 +607,7 @@ class HistoryList(MyTreeView, AcceptFileDragDrop): menu.addAction(_("Remove"), lambda: self.remove_local_tx(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] if column in amount_columns: column_data = column_data.strip() diff --git a/electrum/wallet.py b/electrum/wallet.py @@ -491,7 +491,7 @@ class Abstract_Wallet(AddressSynchronizer): 'timestamp': tx_mined_status.timestamp, 'incoming': True if value>0 else False, 'bc_value': Satoshis(value), - 'balance': Satoshis(balance), + 'bc_balance': Satoshis(balance), 'date': timestamp_to_datetime(tx_mined_status.timestamp), 'label': self.get_label(tx_hash), 'txpos_in_block': tx_mined_status.txpos, @@ -505,6 +505,7 @@ class Abstract_Wallet(AddressSynchronizer): txid = tx_item['txid'] transactions[txid] = tx_item lightning_history = self.lnworker.get_history() if self.lnworker else [] + for i, tx_item in enumerate(lightning_history): txid = tx_item.get('txid') ln_value = Decimal(tx_item['amount_msat']) / 1000 @@ -512,7 +513,7 @@ class Abstract_Wallet(AddressSynchronizer): item = transactions[txid] item['label'] = tx_item['label'] item['ln_value'] = Satoshis(ln_value) - item['balance_msat'] = tx_item['balance_msat'] + item['ln_balance_msat'] = tx_item['balance_msat'] else: tx_item['lightning'] = True 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'] transactions[key] = tx_item now = time.time() + balance = 0 for item in transactions.values(): # add on-chain and lightning values value = Decimal(0) @@ -528,6 +530,8 @@ class Abstract_Wallet(AddressSynchronizer): if item.get('ln_value'): value += item.get('ln_value').value item['value'] = Satoshis(value) + balance += value + item['balance'] = Satoshis(balance) if fx: timestamp = item['timestamp'] or now fiat_value = value / Decimal(bitcoin.COIN) * fx.timestamp_rate(timestamp)