electrum

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

commit 8de52bf523bff8280de02e8015d31ccd525f3c0e
parent 3c019c2f9c4d2fdefe52d84444632b54d421e140
Author: SomberNight <somber.night@protonmail.com>
Date:   Tue,  9 Mar 2021 18:22:30 +0100

wallet: (trivial) use kwargs for get_tx_item_fiat

Diffstat:
Melectrum/gui/qt/history_list.py | 5+++--
Melectrum/gui/qt/transaction_dialog.py | 3++-
Melectrum/wallet.py | 20++++++++++++++------
3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/electrum/gui/qt/history_list.py b/electrum/gui/qt/history_list.py @@ -356,10 +356,11 @@ class HistoryModel(CustomModel, Logger): def update_fiat(self, idx): tx_item = idx.internalPointer().get_data() - key = tx_item['txid'] + txid = tx_item['txid'] fee = tx_item.get('fee') value = tx_item['value'].value - fiat_fields = self.parent.wallet.get_tx_item_fiat(key, value, self.parent.fx, fee.value if fee else None) + fiat_fields = self.parent.wallet.get_tx_item_fiat( + tx_hash=txid, amount_sat=value, fx=self.parent.fx, tx_fee=fee.value if fee else None) tx_item.update(fiat_fields) self.dataChanged.emit(idx, idx, [Qt.DisplayRole, Qt.ForegroundRole]) diff --git a/electrum/gui/qt/transaction_dialog.py b/electrum/gui/qt/transaction_dialog.py @@ -443,7 +443,8 @@ class BaseTxDialog(QDialog, MessageBoxMixin): tx_item_fiat = None if (self.finalized # ensures we don't use historical rates for tx being constructed *now* and txid is not None and fx.is_enabled() and amount is not None): - tx_item_fiat = self.wallet.get_tx_item_fiat(txid, abs(amount), fx, fee) + tx_item_fiat = self.wallet.get_tx_item_fiat( + tx_hash=txid, amount_sat=abs(amount), fx=fx, tx_fee=fee) lnworker_history = self.wallet.lnworker.get_onchain_history() if self.wallet.lnworker else {} if txid in lnworker_history: item = lnworker_history[txid] diff --git a/electrum/wallet.py b/electrum/wallet.py @@ -86,6 +86,7 @@ from .util import read_json_file, write_json_file, UserFacingException if TYPE_CHECKING: from .network import Network + from .exchange_rate import FxThread _logger = get_logger(__name__) @@ -947,7 +948,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC): if fx and fx.is_enabled() and fx.get_history_config(): txid = item.get('txid') if not item.get('lightning') and txid: - fiat_fields = self.get_tx_item_fiat(txid, value, fx, item['fee_sat']) + fiat_fields = self.get_tx_item_fiat(tx_hash=txid, amount_sat=value, fx=fx, tx_fee=item['fee_sat']) item.update(fiat_fields) else: timestamp = item['timestamp'] or now @@ -998,7 +999,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC): income += value # fiat computations if fx and fx.is_enabled() and fx.get_history_config(): - fiat_fields = self.get_tx_item_fiat(tx_hash, value, fx, tx_fee) + fiat_fields = self.get_tx_item_fiat(tx_hash=tx_hash, amount_sat=value, fx=fx, tx_fee=tx_fee) fiat_value = fiat_fields['fiat_value'].value item.update(fiat_fields) if value < 0: @@ -1049,20 +1050,27 @@ class Abstract_Wallet(AddressSynchronizer, ABC): def default_fiat_value(self, tx_hash, fx, value_sat): return value_sat / Decimal(COIN) * self.price_at_timestamp(tx_hash, fx.timestamp_rate) - def get_tx_item_fiat(self, tx_hash, value, fx, tx_fee): + def get_tx_item_fiat( + self, + *, + tx_hash: str, + amount_sat: int, + fx: 'FxThread', + tx_fee: Optional[int], + ) -> Dict[str, Any]: item = {} fiat_value = self.get_fiat_value(tx_hash, fx.ccy) fiat_default = fiat_value is None fiat_rate = self.price_at_timestamp(tx_hash, fx.timestamp_rate) - fiat_value = fiat_value if fiat_value is not None else self.default_fiat_value(tx_hash, fx, value) + fiat_value = fiat_value if fiat_value is not None else self.default_fiat_value(tx_hash, fx, amount_sat) fiat_fee = tx_fee / Decimal(COIN) * fiat_rate if tx_fee is not None else None item['fiat_currency'] = fx.ccy item['fiat_rate'] = Fiat(fiat_rate, fx.ccy) item['fiat_value'] = Fiat(fiat_value, fx.ccy) item['fiat_fee'] = Fiat(fiat_fee, fx.ccy) if fiat_fee else None item['fiat_default'] = fiat_default - if value < 0: - acquisition_price = - value / Decimal(COIN) * self.average_price(tx_hash, fx.timestamp_rate, fx.ccy) + if amount_sat < 0: + acquisition_price = - amount_sat / Decimal(COIN) * self.average_price(tx_hash, fx.timestamp_rate, fx.ccy) liquidation_price = - fiat_value item['acquisition_price'] = Fiat(acquisition_price, fx.ccy) cg = liquidation_price - acquisition_price