|
@ -11,6 +11,7 @@ from electrum.i18n import _, set_language |
|
|
from electrum.contacts import Contacts |
|
|
from electrum.contacts import Contacts |
|
|
from electrum.util import profiler |
|
|
from electrum.util import profiler |
|
|
from electrum.plugins import run_hook |
|
|
from electrum.plugins import run_hook |
|
|
|
|
|
from electrum.util import format_satoshis, format_satoshis_plain |
|
|
|
|
|
|
|
|
from kivy.app import App |
|
|
from kivy.app import App |
|
|
from kivy.core.window import Window |
|
|
from kivy.core.window import Window |
|
@ -35,7 +36,7 @@ Factory.register('ELTextInput', module='electrum_gui.kivy.uix.screens') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# delayed imports: for startup speed on android |
|
|
# delayed imports: for startup speed on android |
|
|
notification = app = ref = format_satoshis = None |
|
|
notification = app = ref = None |
|
|
util = False |
|
|
util = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -76,35 +77,35 @@ class ElectrumWindow(App): |
|
|
|
|
|
|
|
|
status = StringProperty(_('Not Connected')) |
|
|
status = StringProperty(_('Not Connected')) |
|
|
|
|
|
|
|
|
|
|
|
fiat_unit = StringProperty('') |
|
|
|
|
|
|
|
|
def decimal_point(self): |
|
|
def decimal_point(self): |
|
|
return base_units[self.base_unit] |
|
|
return base_units[self.base_unit] |
|
|
|
|
|
|
|
|
def _get_num_zeros(self): |
|
|
def toggle_fiat(self, a): |
|
|
try: |
|
|
if not a.is_fiat: |
|
|
return self.electrum_config.get('num_zeros', 0) |
|
|
if a.fiat_text: |
|
|
except AttributeError: |
|
|
a.fiat_amount = str(a.fiat_text).split()[0] |
|
|
return 0 |
|
|
else: |
|
|
|
|
|
if a.btc_text: |
|
|
def _set_num_zeros(self): |
|
|
a.amount = str(a.btc_text).split()[0] |
|
|
try: |
|
|
a.is_fiat = not a.is_fiat |
|
|
self.electrum_config.set_key('num_zeros', value, True) |
|
|
|
|
|
except AttributeError: |
|
|
def btc_to_fiat(self, amount_str): |
|
|
Logger.error('Electrum: Config not available ' |
|
|
if not amount_str: |
|
|
'While trying to save value to config') |
|
|
return '' |
|
|
|
|
|
satoshis = self.get_amount(amount_str + ' ' + self.base_unit) |
|
|
num_zeros = AliasProperty(_get_num_zeros , _set_num_zeros) |
|
|
fiat_text = run_hook('format_amount_and_units', satoshis) |
|
|
'''Number of zeros used while representing the value in base_unit. |
|
|
return fiat_text if fiat_text else '' |
|
|
''' |
|
|
|
|
|
|
|
|
def fiat_to_btc(self, fiat_amount): |
|
|
def get_amount_text(self, amount_str, is_fiat): |
|
|
if not fiat_amount: |
|
|
text = amount_str + ' ' + self.base_unit if amount_str else '' |
|
|
return '' |
|
|
if text: |
|
|
satoshis = pow(10, 8) |
|
|
amount = self.get_amount(text) |
|
|
x = run_hook('format_amount_and_units', satoshis) |
|
|
x = run_hook('format_amount_and_units', amount) |
|
|
rate, unit = x.split() |
|
|
if x: |
|
|
amount = satoshis * Decimal(fiat_amount) / Decimal(rate) |
|
|
text += ' / ' + x |
|
|
return format_satoshis_plain(amount, self.decimal_point()) + ' ' + self.base_unit |
|
|
return text |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_amount(self, amount_str): |
|
|
def get_amount(self, amount_str): |
|
|
a, u = amount_str.split() |
|
|
a, u = amount_str.split() |
|
@ -480,29 +481,33 @@ class ElectrumWindow(App): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_max_amount(self): |
|
|
def get_max_amount(self): |
|
|
from electrum.util import format_satoshis_plain |
|
|
|
|
|
inputs = self.wallet.get_spendable_coins(None) |
|
|
inputs = self.wallet.get_spendable_coins(None) |
|
|
amount, fee = self.wallet.get_max_amount(self.electrum_config, inputs, None) |
|
|
amount, fee = self.wallet.get_max_amount(self.electrum_config, inputs, None) |
|
|
return format_satoshis_plain(amount, self.decimal_point()) |
|
|
return format_satoshis_plain(amount, self.decimal_point()) |
|
|
|
|
|
|
|
|
def update_amount(self, amount, c): |
|
|
def update_amount(self, label, c): |
|
|
|
|
|
amount = label.fiat_amount if label.is_fiat else label.amount |
|
|
if c == '<': |
|
|
if c == '<': |
|
|
return amount[:-1] |
|
|
amount = amount[:-1] |
|
|
if c == '.' and amount == '': |
|
|
elif c == '.' and amount == '': |
|
|
return '0.' |
|
|
amount = '0.' |
|
|
if c == '0' and amount == '0': |
|
|
elif c == '0' and amount == '0': |
|
|
return '0' |
|
|
amount = '0' |
|
|
|
|
|
else: |
|
|
try: |
|
|
try: |
|
|
Decimal(amount+c) |
|
|
Decimal(amount+c) |
|
|
amount += c |
|
|
amount += c |
|
|
except: |
|
|
except: |
|
|
pass |
|
|
pass |
|
|
return amount |
|
|
|
|
|
|
|
|
if label.is_fiat: |
|
|
|
|
|
label.fiat_amount = amount |
|
|
|
|
|
else: |
|
|
|
|
|
label.amount = amount |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def format_amount(self, x, is_diff=False, whitespaces=False): |
|
|
def format_amount(self, x, is_diff=False, whitespaces=False): |
|
|
from electrum.util import format_satoshis |
|
|
return format_satoshis(x, is_diff, 0, self.decimal_point(), whitespaces) |
|
|
return format_satoshis(x, is_diff, self.num_zeros, |
|
|
|
|
|
self.decimal_point(), whitespaces) |
|
|
|
|
|
|
|
|
|
|
|
@profiler |
|
|
@profiler |
|
|
def update_wallet(self, *dt): |
|
|
def update_wallet(self, *dt): |
|
@ -786,7 +791,7 @@ class ElectrumWindow(App): |
|
|
assert u == self.base_unit |
|
|
assert u == self.base_unit |
|
|
popup.ids.a.amount = a |
|
|
popup.ids.a.amount = a |
|
|
def cb(): |
|
|
def cb(): |
|
|
o = popup.ids.a.text |
|
|
o = popup.ids.a.btc_text |
|
|
label.text = o if o else label.default_text |
|
|
label.text = o if o else label.default_text |
|
|
if callback: |
|
|
if callback: |
|
|
callback() |
|
|
callback() |
|
|