|
|
@ -614,12 +614,18 @@ class FxThread(ThreadJob): |
|
|
|
return Decimal('NaN') |
|
|
|
return Decimal(rate) |
|
|
|
|
|
|
|
def format_amount(self, btc_balance): |
|
|
|
rate = self.exchange_rate() |
|
|
|
def format_amount(self, btc_balance, *, timestamp: int = None) -> str: |
|
|
|
if timestamp is None: |
|
|
|
rate = self.exchange_rate() |
|
|
|
else: |
|
|
|
rate = self.timestamp_rate(timestamp) |
|
|
|
return '' if rate.is_nan() else "%s" % self.value_str(btc_balance, rate) |
|
|
|
|
|
|
|
def format_amount_and_units(self, btc_balance): |
|
|
|
rate = self.exchange_rate() |
|
|
|
def format_amount_and_units(self, btc_balance, *, timestamp: int = None) -> str: |
|
|
|
if timestamp is None: |
|
|
|
rate = self.exchange_rate() |
|
|
|
else: |
|
|
|
rate = self.timestamp_rate(timestamp) |
|
|
|
return '' if rate.is_nan() else "%s %s" % (self.value_str(btc_balance, rate), self.ccy) |
|
|
|
|
|
|
|
def get_fiat_status_text(self, btc_balance, base_unit, decimal_point): |
|
|
@ -627,18 +633,18 @@ class FxThread(ThreadJob): |
|
|
|
return _(" (No FX rate available)") if rate.is_nan() else " 1 %s~%s %s" % (base_unit, |
|
|
|
self.value_str(COIN / (10**(8 - decimal_point)), rate), self.ccy) |
|
|
|
|
|
|
|
def fiat_value(self, satoshis, rate): |
|
|
|
def fiat_value(self, satoshis, rate) -> Decimal: |
|
|
|
return Decimal('NaN') if satoshis is None else Decimal(satoshis) / COIN * Decimal(rate) |
|
|
|
|
|
|
|
def value_str(self, satoshis, rate): |
|
|
|
def value_str(self, satoshis, rate) -> str: |
|
|
|
return self.format_fiat(self.fiat_value(satoshis, rate)) |
|
|
|
|
|
|
|
def format_fiat(self, value): |
|
|
|
def format_fiat(self, value: Decimal) -> str: |
|
|
|
if value.is_nan(): |
|
|
|
return _("No data") |
|
|
|
return "%s" % (self.ccy_amount_str(value, True)) |
|
|
|
|
|
|
|
def history_rate(self, d_t): |
|
|
|
def history_rate(self, d_t: Optional[datetime]) -> Decimal: |
|
|
|
if d_t is None: |
|
|
|
return Decimal('NaN') |
|
|
|
rate = self.exchange.historical_rate(self.ccy, d_t) |
|
|
@ -651,13 +657,13 @@ class FxThread(ThreadJob): |
|
|
|
rate = 'NaN' |
|
|
|
return Decimal(rate) |
|
|
|
|
|
|
|
def historical_value_str(self, satoshis, d_t): |
|
|
|
def historical_value_str(self, satoshis, d_t: Optional[datetime]) -> str: |
|
|
|
return self.format_fiat(self.historical_value(satoshis, d_t)) |
|
|
|
|
|
|
|
def historical_value(self, satoshis, d_t): |
|
|
|
def historical_value(self, satoshis, d_t: Optional[datetime]) -> Decimal: |
|
|
|
return self.fiat_value(satoshis, self.history_rate(d_t)) |
|
|
|
|
|
|
|
def timestamp_rate(self, timestamp): |
|
|
|
def timestamp_rate(self, timestamp: Optional[int]) -> Decimal: |
|
|
|
from .util import timestamp_to_datetime |
|
|
|
date = timestamp_to_datetime(timestamp) |
|
|
|
return self.history_rate(date) |
|
|
|