format_amount_and_units: general method to display amounts and fiat values. fixes #1078
This commit is contained in:
parent
7c4b749340
commit
483cf2286f
|
@ -432,8 +432,8 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
is_relevant, is_mine, v, fee = self.wallet.get_wallet_delta(tx)
|
is_relevant, is_mine, v, fee = self.wallet.get_wallet_delta(tx)
|
||||||
if(v > 0):
|
if(v > 0):
|
||||||
total_amount += v
|
total_amount += v
|
||||||
self.notify(_("%(txs)s new transactions received. Total amount received in the new transactions %(amount)s %(unit)s") \
|
self.notify(_("%(txs)s new transactions received. Total amount received in the new transactions %(amount)s") \
|
||||||
% { 'txs' : tx_amount, 'amount' : self.format_amount(total_amount), 'unit' : self.base_unit()})
|
% { 'txs' : tx_amount, 'amount' : self.format_amount_and_units(total_amount)})
|
||||||
self.tx_notifications = []
|
self.tx_notifications = []
|
||||||
else:
|
else:
|
||||||
for tx in self.tx_notifications:
|
for tx in self.tx_notifications:
|
||||||
|
@ -441,7 +441,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
self.tx_notifications.remove(tx)
|
self.tx_notifications.remove(tx)
|
||||||
is_relevant, is_mine, v, fee = self.wallet.get_wallet_delta(tx)
|
is_relevant, is_mine, v, fee = self.wallet.get_wallet_delta(tx)
|
||||||
if(v > 0):
|
if(v > 0):
|
||||||
self.notify(_("New transaction received. %(amount)s %(unit)s") % { 'amount' : self.format_amount(v), 'unit' : self.base_unit()})
|
self.notify(_("New transaction received. %(amount)s") % { 'amount' : self.format_amount_and_units(v)})
|
||||||
|
|
||||||
def notify(self, message):
|
def notify(self, message):
|
||||||
if self.tray:
|
if self.tray:
|
||||||
|
@ -483,6 +483,13 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
def format_amount(self, x, is_diff=False, whitespaces=False):
|
def format_amount(self, x, is_diff=False, whitespaces=False):
|
||||||
return format_satoshis(x, is_diff, self.num_zeros, self.decimal_point, whitespaces)
|
return format_satoshis(x, is_diff, self.num_zeros, self.decimal_point, whitespaces)
|
||||||
|
|
||||||
|
def format_amount_and_units(self, amount):
|
||||||
|
text = self.format_amount(amount) + ' '+ self.base_unit()
|
||||||
|
x = run_hook('format_amount_and_units', amount)
|
||||||
|
if x:
|
||||||
|
text += ''.join(x)
|
||||||
|
return text
|
||||||
|
|
||||||
def get_decimal_point(self):
|
def get_decimal_point(self):
|
||||||
return self.decimal_point
|
return self.decimal_point
|
||||||
|
|
||||||
|
@ -518,7 +525,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
icon = QIcon(":icons/status_lagging.png")
|
icon = QIcon(":icons/status_lagging.png")
|
||||||
else:
|
else:
|
||||||
c, u, x = self.wallet.get_account_balance(self.current_account)
|
c, u, x = self.wallet.get_account_balance(self.current_account)
|
||||||
text = _("Balance" ) + ": %s "%(self.format_amount(c)) + self.base_unit()
|
text = _("Balance" ) + ": %s "%(self.format_amount_and_units(c))
|
||||||
if u:
|
if u:
|
||||||
text += " [%s unconfirmed]"%(self.format_amount(u, True).strip())
|
text += " [%s unconfirmed]"%(self.format_amount(u, True).strip())
|
||||||
if x:
|
if x:
|
||||||
|
@ -1170,6 +1177,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
if not r:
|
if not r:
|
||||||
return
|
return
|
||||||
outputs, fee, tx_desc, coins = r
|
outputs, fee, tx_desc, coins = r
|
||||||
|
amount = sum(map(lambda x:x[2], outputs))
|
||||||
try:
|
try:
|
||||||
tx = self.wallet.make_unsigned_transaction(coins, outputs, self.config, fee)
|
tx = self.wallet.make_unsigned_transaction(coins, outputs, self.config, fee)
|
||||||
except NotEnoughFunds:
|
except NotEnoughFunds:
|
||||||
|
@ -1188,11 +1196,10 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
self.show_transaction(tx, tx_desc)
|
self.show_transaction(tx, tx_desc)
|
||||||
return
|
return
|
||||||
# confirmation dialog
|
# confirmation dialog
|
||||||
amount = sum(map(lambda x:x[2], outputs))
|
|
||||||
confirm_amount = self.config.get('confirm_amount', COIN)
|
confirm_amount = self.config.get('confirm_amount', COIN)
|
||||||
msg = [
|
msg = [
|
||||||
_("Amount to be sent") + ": %s"%(self.format_amount(amount) + ' '+ self.base_unit()),
|
_("Amount to be sent") + ": " + self.format_amount_and_units(amount),
|
||||||
_("Transaction fee") + ": %s"%(self.format_amount(fee) + ' '+ self.base_unit()),
|
_("Transaction fee") + ": " + self.format_amount_and_units(fee),
|
||||||
]
|
]
|
||||||
if self.wallet.use_encryption:
|
if self.wallet.use_encryption:
|
||||||
msg.append(_("Enter your password to proceed"))
|
msg.append(_("Enter your password to proceed"))
|
||||||
|
@ -1248,7 +1255,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
if tx.get_fee() >= confirm_fee:
|
if tx.get_fee() >= confirm_fee:
|
||||||
msg = '\n'.join([
|
msg = '\n'.join([
|
||||||
_("The fee for this transaction seems unusually high."),
|
_("The fee for this transaction seems unusually high."),
|
||||||
_("Are you really sure you want to pay %(fee)s in fees?")%{ 'fee' : self.format_amount(fee) + ' '+ self.base_unit()}
|
_("Are you really sure you want to pay %(fee)s in fees?")%{ 'fee' : self.format_amount_and_units(fee)}
|
||||||
])
|
])
|
||||||
if not self.question(msg):
|
if not self.question(msg):
|
||||||
return
|
return
|
||||||
|
|
|
@ -393,6 +393,11 @@ class Plugin(BasePlugin, ThreadJob):
|
||||||
if rate:
|
if rate:
|
||||||
return Decimal(rate)
|
return Decimal(rate)
|
||||||
|
|
||||||
|
@hook
|
||||||
|
def format_amount_and_units(self, btc_balance):
|
||||||
|
rate = self.exchange_rate()
|
||||||
|
return '' if rate is None else " (%s %s)" % (self.value_str(btc_balance, rate), self.ccy)
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def get_fiat_status_text(self, btc_balance, result):
|
def get_fiat_status_text(self, btc_balance, result):
|
||||||
# return status as: (1.23 USD) 1 BTC~123.45 USD
|
# return status as: (1.23 USD) 1 BTC~123.45 USD
|
||||||
|
@ -400,8 +405,7 @@ class Plugin(BasePlugin, ThreadJob):
|
||||||
if rate is None:
|
if rate is None:
|
||||||
text = _(" (No FX rate available)")
|
text = _(" (No FX rate available)")
|
||||||
else:
|
else:
|
||||||
text = " (%s %s) 1 BTC~%s %s" % (self.value_str(btc_balance, rate), self.ccy,
|
text = "1 BTC~%s %s" % (self.value_str(COIN, rate), self.ccy)
|
||||||
self.value_str(COIN, rate), self.ccy)
|
|
||||||
result['text'] = text
|
result['text'] = text
|
||||||
|
|
||||||
def get_historical_rates(self):
|
def get_historical_rates(self):
|
||||||
|
|
Loading…
Reference in New Issue