kivy: updates
This commit is contained in:
parent
84b18e0949
commit
9b2885e697
|
@ -95,18 +95,20 @@ class ElectrumWindow(App):
|
|||
def btc_to_fiat(self, amount_str):
|
||||
if not amount_str:
|
||||
return ''
|
||||
satoshis = self.get_amount(amount_str + ' ' + self.base_unit)
|
||||
fiat_text = run_hook('format_amount_and_units', satoshis)
|
||||
return fiat_text if fiat_text else ''
|
||||
rate = run_hook('exchange_rate')
|
||||
if not rate:
|
||||
return ''
|
||||
fiat_amount = self.get_amount(amount_str + ' ' + self.base_unit) * rate / pow(10, 8)
|
||||
return "{:.2f}".format(fiat_amount).rstrip('0').rstrip('.') + ' ' + self.fiat_unit
|
||||
|
||||
def fiat_to_btc(self, fiat_amount):
|
||||
if not fiat_amount:
|
||||
return ''
|
||||
satoshis = pow(10, 8)
|
||||
x = run_hook('format_amount_and_units', satoshis)
|
||||
rate, unit = x.split()
|
||||
amount = satoshis * Decimal(fiat_amount) / Decimal(rate)
|
||||
return format_satoshis_plain(amount, self.decimal_point()) + ' ' + self.base_unit
|
||||
rate = run_hook('exchange_rate')
|
||||
if not rate:
|
||||
return ''
|
||||
satoshis = int(pow(10,8) * Decimal(fiat_amount) / Decimal(rate))
|
||||
return format_satoshis_plain(satoshis, self.decimal_point()) + ' ' + self.base_unit
|
||||
|
||||
def get_amount(self, amount_str):
|
||||
a, u = amount_str.split()
|
||||
|
|
|
@ -72,12 +72,14 @@ Popup:
|
|||
size_hint: 1, None
|
||||
height: '48dp'
|
||||
text: 'Max'
|
||||
on_release: a.amount = app.get_max_amount()
|
||||
on_release:
|
||||
a.is_fiat = False
|
||||
a.amount = app.get_max_amount()
|
||||
Button:
|
||||
id: button_fiat
|
||||
size_hint: 1, None
|
||||
height: '48dp'
|
||||
text: '/'
|
||||
text: app.fiat_unit if a.is_fiat else app.base_unit
|
||||
on_release:
|
||||
app.toggle_fiat(a)
|
||||
Button:
|
||||
|
|
|
@ -309,6 +309,7 @@ class FxPlugin(BasePlugin, ThreadJob):
|
|||
def on_history(self):
|
||||
pass
|
||||
|
||||
@hook
|
||||
def exchange_rate(self):
|
||||
'''Returns None, or the exchange rate as a Decimal'''
|
||||
rate = self.exchange.quotes.get(self.ccy)
|
||||
|
|
|
@ -9,3 +9,7 @@ class Plugin(FxPlugin):
|
|||
def on_quotes(self):
|
||||
self.print_error("on quotes", self.ccy)
|
||||
self.window.fiat_unit = self.ccy
|
||||
|
||||
def on_history(self):
|
||||
self.print_error("on history")
|
||||
self.window.history_screen.update()
|
||||
|
|
Loading…
Reference in New Issue