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