1
0

fix: Re-add fiat values to csv history export

Re-add fiat values to the csv history export as they were missing due to
a regression.
This commit is contained in:
f321x
2025-09-05 17:51:51 +02:00
parent c438f1dfe7
commit 55d8974c8f

View File

@@ -43,7 +43,7 @@ from electrum.address_synchronizer import TX_HEIGHT_LOCAL
from electrum.i18n import _
from electrum.util import (block_explorer_URL, profiler, TxMinedInfo,
OrderedDictWithIndex, timestamp_to_datetime,
Satoshis, format_time)
Satoshis, format_time, Fiat)
from electrum.logging import get_logger, Logger
from electrum.simple_config import SimpleConfig
@@ -853,26 +853,32 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
self.main_window.show_message(_("Your wallet history has been successfully exported."))
def do_export_history(self, file_name, is_csv):
txns = self.wallet.get_full_history(fx=self.main_window.fx)
txns = self.wallet.get_full_history(fx=self.main_window.fx, include_fiat=self.main_window.fx.is_enabled())
lines = []
def get_all_fees_paid_sat(h_item: dict) -> int:
def get_all_fees_paid_by_item(h_item: dict) -> Tuple[int, Fiat]:
# gets all fees paid in an item (or group), as the outer group doesn't contain the
# transaction fees paid by the children
fees_sat = 0
fees_fiat = Fiat(ccy=self.main_window.fx.ccy, value=Decimal())
for child in h_item.get('children', []):
fees_sat += child['fee_sat'] or 0 if 'fee_sat' in child \
else (child.get('fee_msat', 0) or 0) // 1000
if child_fiat_fee := child.get('fiat_fee'):
fees_fiat += child_fiat_fee
fees_sat += h_item['fee_sat'] or 0 if 'fee_sat' in h_item \
else (h_item.get('fee_msat', 0) or 0) // 1000
return fees_sat
if h_item_fiat_fee := h_item.get('fiat_fee'):
fees_fiat += h_item_fiat_fee
return fees_sat, fees_fiat
if is_csv:
# sort by timestamp so the generated csv is more understandable on first sight
txns = dict(sorted(txns.items(), key=lambda h_item: h_item[1]['timestamp'] or 0))
for item in txns.values():
# tx groups will are shown as single element
fees_sat, fees_fiat = get_all_fees_paid_by_item(item)
line = [
item.get('txid', ''),
item.get('payment_hash', ''),
@@ -881,8 +887,8 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
item['bc_value'],
item['ln_value'],
item.get('fiat_value', ''),
get_all_fees_paid_sat(item),
item.get('fiat_fee', ''),
fees_sat,
str(fees_fiat),
item['date']
]
lines.append(line)