add base_unit to amount fields
This commit is contained in:
parent
67bc6da794
commit
aa83f5fdca
@ -73,10 +73,6 @@ class ElectrumGui:
|
|||||||
# base
|
# base
|
||||||
#init_plugins(self)
|
#init_plugins(self)
|
||||||
|
|
||||||
def set_url(self, url):
|
|
||||||
#self.current_window.pary_from_URI
|
|
||||||
pass
|
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
''' The main entry point of the kivy ux
|
''' The main entry point of the kivy ux
|
||||||
:param url: 'bitcoin:' uri as mentioned in bip0021
|
:param url: 'bitcoin:' uri as mentioned in bip0021
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import datetime
|
|||||||
import traceback
|
import traceback
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
import electrum
|
||||||
from electrum import WalletStorage, Wallet
|
from electrum import WalletStorage, Wallet
|
||||||
from electrum.i18n import _, set_language
|
from electrum.i18n import _, set_language
|
||||||
from electrum.contacts import Contacts
|
from electrum.contacts import Contacts
|
||||||
@ -93,10 +94,10 @@ class ElectrumWindow(App):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
def get_amount(self, amount_str):
|
def get_amount(self, amount_str):
|
||||||
from electrum.bitcoin import COIN
|
a, u = amount_str.split()
|
||||||
from decimal import Decimal
|
assert u == self.base_unit
|
||||||
try:
|
try:
|
||||||
x = Decimal(str(amount_str))
|
x = Decimal(a)
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
p = pow(10, self.decimal_point())
|
p = pow(10, self.decimal_point())
|
||||||
@ -168,9 +169,9 @@ class ElectrumWindow(App):
|
|||||||
|
|
||||||
self.bind(url=self.set_url)
|
self.bind(url=self.set_url)
|
||||||
# were we sent a url?
|
# were we sent a url?
|
||||||
url = kwargs.get('url', None)
|
url = self.electrum_config.get('url', None)
|
||||||
if url:
|
if url:
|
||||||
self.gui_object.set_url(url)
|
self.set_url(url)
|
||||||
|
|
||||||
# create triggers so as to minimize updation a max of 2 times a sec
|
# create triggers so as to minimize updation a max of 2 times a sec
|
||||||
self._trigger_update_wallet =\
|
self._trigger_update_wallet =\
|
||||||
@ -180,10 +181,10 @@ class ElectrumWindow(App):
|
|||||||
self._trigger_notify_transactions = \
|
self._trigger_notify_transactions = \
|
||||||
Clock.create_trigger(self.notify_transactions, 5)
|
Clock.create_trigger(self.notify_transactions, 5)
|
||||||
|
|
||||||
|
def set_url(self, url):
|
||||||
|
print "set url", url
|
||||||
def set_url(self, instance, url):
|
url = electrum.util.parse_URI(url)
|
||||||
self.gui_object.set_url(url)
|
self.send_screen.set_qr_data(url)
|
||||||
|
|
||||||
def scan_qr(self, on_complete):
|
def scan_qr(self, on_complete):
|
||||||
from jnius import autoclass
|
from jnius import autoclass
|
||||||
@ -197,7 +198,7 @@ class ElectrumWindow(App):
|
|||||||
if resultCode == -1: # RESULT_OK:
|
if resultCode == -1: # RESULT_OK:
|
||||||
contents = intent.getStringExtra("SCAN_RESULT")
|
contents = intent.getStringExtra("SCAN_RESULT")
|
||||||
if intent.getStringExtra("SCAN_RESULT_FORMAT") == 'QR_CODE':
|
if intent.getStringExtra("SCAN_RESULT_FORMAT") == 'QR_CODE':
|
||||||
uri = App.get_running_app().decode_uri(contents)
|
uri = electrum.util.parse_URI(contents)
|
||||||
on_complete(uri)
|
on_complete(uri)
|
||||||
activity.bind(on_activity_result=on_qr_result)
|
activity.bind(on_activity_result=on_qr_result)
|
||||||
PythonActivity.mActivity.startActivityForResult(intent, 0)
|
PythonActivity.mActivity.startActivityForResult(intent, 0)
|
||||||
@ -638,54 +639,6 @@ class ElectrumWindow(App):
|
|||||||
self.do_clear()
|
self.do_clear()
|
||||||
self.show_info(self.gui_object.payment_request.error)
|
self.show_info(self.gui_object.payment_request.error)
|
||||||
|
|
||||||
def encode_uri(self, addr, amount=0, label='',
|
|
||||||
message='', size='', currency='btc'):
|
|
||||||
''' Convert to BIP0021 compatible URI
|
|
||||||
'''
|
|
||||||
uri = 'bitcoin:{}'.format(addr)
|
|
||||||
first = True
|
|
||||||
if amount:
|
|
||||||
uri += '{}amount={}'.format('?' if first else '&', amount)
|
|
||||||
first = False
|
|
||||||
if label:
|
|
||||||
uri += '{}label={}'.format('?' if first else '&', label)
|
|
||||||
first = False
|
|
||||||
if message:
|
|
||||||
uri += '{}?message={}'.format('?' if first else '&', message)
|
|
||||||
first = False
|
|
||||||
if size:
|
|
||||||
uri += '{}size={}'.format('?' if not first else '&', size)
|
|
||||||
return uri
|
|
||||||
|
|
||||||
def decode_uri(self, uri):
|
|
||||||
if ':' not in uri:
|
|
||||||
# It's just an address (not BIP21)
|
|
||||||
return {'address': uri}
|
|
||||||
|
|
||||||
if '//' not in uri:
|
|
||||||
# Workaround for urlparse, it don't handle bitcoin: URI properly
|
|
||||||
uri = uri.replace(':', '://')
|
|
||||||
|
|
||||||
try:
|
|
||||||
uri = urlparse(uri)
|
|
||||||
except NameError:
|
|
||||||
# delayed import
|
|
||||||
from urlparse import urlparse, parse_qs
|
|
||||||
uri = urlparse(uri)
|
|
||||||
|
|
||||||
result = {'address': uri.netloc}
|
|
||||||
|
|
||||||
if uri.path.startswith('?'):
|
|
||||||
params = parse_qs(uri.path[1:])
|
|
||||||
else:
|
|
||||||
params = parse_qs(uri.path)
|
|
||||||
|
|
||||||
for k,v in params.items():
|
|
||||||
if k in ('amount', 'label', 'message', 'size'):
|
|
||||||
result[k] = v[0]
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def show_error(self, error, width='200dp', pos=None, arrow_pos=None,
|
def show_error(self, error, width='200dp', pos=None, arrow_pos=None,
|
||||||
exit=False, icon='atlas://gui/kivy/theming/light/error', duration=0,
|
exit=False, icon='atlas://gui/kivy/theming/light/error', duration=0,
|
||||||
modal=False):
|
modal=False):
|
||||||
@ -757,7 +710,9 @@ class ElectrumWindow(App):
|
|||||||
def amount_dialog(self, label, callback):
|
def amount_dialog(self, label, callback):
|
||||||
popup = Builder.load_file('gui/kivy/uix/ui_screens/amount.kv')
|
popup = Builder.load_file('gui/kivy/uix/ui_screens/amount.kv')
|
||||||
if label.text != label.default_text:
|
if label.text != label.default_text:
|
||||||
popup.ids.amount_label.text = label.text
|
a, u = label.text.split()
|
||||||
|
assert u == self.base_unit
|
||||||
|
popup.ids.amount_label.value = a
|
||||||
def cb():
|
def cb():
|
||||||
o = popup.ids.amount_label.text
|
o = popup.ids.amount_label.text
|
||||||
label.text = o if o else label.default_text
|
label.text = o if o else label.default_text
|
||||||
|
|||||||
@ -193,12 +193,15 @@ class SendScreen(CScreen):
|
|||||||
def set_qr_data(self, uri):
|
def set_qr_data(self, uri):
|
||||||
self.ids.payto_e.text = uri.get('address', '')
|
self.ids.payto_e.text = uri.get('address', '')
|
||||||
self.ids.message_e.text = uri.get('message', '')
|
self.ids.message_e.text = uri.get('message', '')
|
||||||
self.ids.amount_e.text = uri.get('amount', '')
|
amount = uri.get('amount')
|
||||||
|
if amount:
|
||||||
|
amount_str = str( a / Decimal(self.app.decimal_point()))
|
||||||
|
self.ids.amount_e.text = amount_str + ' ' + self.app.base_unit
|
||||||
|
|
||||||
def do_clear(self):
|
def do_clear(self):
|
||||||
cts = self.ids
|
self.ids.payto_e.text = ''
|
||||||
cts.payto_e.text = cts.message_e.text = ''
|
self.ids.message_e.text = ''
|
||||||
cts.amount_e.text = 'Amount'
|
self.ids.amount_e.text = 'Amount'
|
||||||
#self.set_frozen(content, False)
|
#self.set_frozen(content, False)
|
||||||
#self.update_status()
|
#self.update_status()
|
||||||
|
|
||||||
@ -268,7 +271,12 @@ class ReceiveScreen(CScreen):
|
|||||||
address = self.screen.ids.get('address').text
|
address = self.screen.ids.get('address').text
|
||||||
amount = self.screen.ids.get('amount').text
|
amount = self.screen.ids.get('amount').text
|
||||||
default_text = self.screen.ids.get('amount').default_text
|
default_text = self.screen.ids.get('amount').default_text
|
||||||
amount = None if amount == default_text else 100000000 * Decimal(amount)
|
if amount == default_text:
|
||||||
|
amount = None
|
||||||
|
else:
|
||||||
|
a, u = amount.split()
|
||||||
|
assert u == self.app.base_unit
|
||||||
|
amount = Decimal(a) * pow(10, self.app.decimal_point())
|
||||||
msg = self.screen.ids.get('message').text
|
msg = self.screen.ids.get('message').text
|
||||||
uri = create_URI(address, amount, msg)
|
uri = create_URI(address, amount, msg)
|
||||||
qr = self.screen.ids.get('qr')
|
qr = self.screen.ids.get('qr')
|
||||||
|
|||||||
@ -12,49 +12,55 @@ Popup:
|
|||||||
|
|
||||||
halign: 'center'
|
halign: 'center'
|
||||||
|
|
||||||
Label:
|
BoxLayout:
|
||||||
id: amount_label
|
Label:
|
||||||
text: ''
|
id: amount_label
|
||||||
|
text: ''
|
||||||
|
value: ''
|
||||||
|
on_value:
|
||||||
|
self.text = self.value + ' ' + app.base_unit
|
||||||
|
Widget:
|
||||||
|
size_hint_x: 1
|
||||||
|
|
||||||
GridLayout:
|
GridLayout:
|
||||||
cols: 3
|
cols: 3
|
||||||
size_hint: 0.5, 1
|
size_hint: 0.5, 1
|
||||||
KButton:
|
KButton:
|
||||||
text: '1'
|
text: '1'
|
||||||
on_release: amount_label.text += self.text
|
on_release: amount_label.value += self.text
|
||||||
KButton:
|
KButton:
|
||||||
text: '2'
|
text: '2'
|
||||||
on_release: amount_label.text += self.text
|
on_release: amount_label.value += self.text
|
||||||
KButton:
|
KButton:
|
||||||
text: '3'
|
text: '3'
|
||||||
on_release: amount_label.text += self.text
|
on_release: amount_label.value += self.text
|
||||||
KButton:
|
KButton:
|
||||||
text: '4'
|
text: '4'
|
||||||
on_release: amount_label.text += self.text
|
on_release: amount_label.value += self.text
|
||||||
KButton:
|
KButton:
|
||||||
text: '5'
|
text: '5'
|
||||||
on_release: amount_label.text += self.text
|
on_release: amount_label.value += self.text
|
||||||
KButton:
|
KButton:
|
||||||
text: '6'
|
text: '6'
|
||||||
on_release: amount_label.text += self.text
|
on_release: amount_label.value += self.text
|
||||||
KButton:
|
KButton:
|
||||||
text: '7'
|
text: '7'
|
||||||
on_release: amount_label.text += self.text
|
on_release: amount_label.value += self.text
|
||||||
KButton:
|
KButton:
|
||||||
text: '8'
|
text: '8'
|
||||||
on_release: amount_label.text += self.text
|
on_release: amount_label.value += self.text
|
||||||
KButton:
|
KButton:
|
||||||
text: '9'
|
text: '9'
|
||||||
on_release: amount_label.text += self.text
|
on_release: amount_label.value += self.text
|
||||||
KButton:
|
KButton:
|
||||||
text: '.'
|
text: '.'
|
||||||
on_release: amount_label.text += self.text
|
on_release: amount_label.value += self.text
|
||||||
KButton:
|
KButton:
|
||||||
text: '0'
|
text: '0'
|
||||||
on_release: amount_label.text += self.text
|
on_release: amount_label.value += self.text
|
||||||
KButton:
|
KButton:
|
||||||
text: '<'
|
text: '<'
|
||||||
on_release: amount_label.text = amount_label.text[:-1]
|
on_release: amount_label.value = amount_label.value[:-1]
|
||||||
|
|
||||||
BoxLayout:
|
BoxLayout:
|
||||||
size_hint: 0.5, None
|
size_hint: 0.5, None
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user