1
0

fix 'max' button in Kivy (fix #6169)

This commit is contained in:
ThomasV
2020-11-27 12:48:32 +01:00
parent 9e1c4a59e5
commit 915e132c33
4 changed files with 23 additions and 8 deletions

View File

@@ -1173,7 +1173,12 @@ class ElectrumWindow(App, Logger):
amount, u = str(amount).split()
assert u == self.base_unit
def cb(amount):
screen.amount = amount
if amount == '!':
screen.is_max = True
screen.amount = self.get_max_amount() + ' ' + self.base_unit
else:
screen.amount = amount
screen.is_max = False
popup = AmountDialog(show_max, amount, cb)
popup.open()

View File

@@ -49,6 +49,7 @@ Builder.load_string('''
amount: ''
fiat_amount: ''
is_fiat: False
is_max: False
on_fiat_amount: if self.is_fiat: self.amount = app.fiat_to_btc(self.fiat_amount)
on_amount: if not self.is_fiat: self.fiat_amount = app.btc_to_fiat(self.amount)
size_hint: 1, None
@@ -92,6 +93,7 @@ Builder.load_string('''
on_release:
kb.is_fiat = False
kb.amount = app.get_max_amount()
kb.is_max = True
Button:
size_hint: 1, None
height: '48dp'
@@ -99,6 +101,7 @@ Builder.load_string('''
on_release:
kb.amount = ''
kb.fiat_amount = ''
kb.is_max = False
Widget:
size_hint: 1, 0.2
BoxLayout:
@@ -112,7 +115,7 @@ Builder.load_string('''
height: '48dp'
text: _('OK')
on_release:
root.callback(btc.text if kb.amount else '')
root.callback('!' if kb.is_max else btc.text if kb.amount else '')
popup.dismiss()
''')

View File

@@ -23,6 +23,7 @@ Builder.load_string('''
title: _('Open Lightning Channel')
pubkey: ''
amount: ''
is_max: False
ipport: ''
BoxLayout
spacing: '12dp'
@@ -154,7 +155,7 @@ class LightningOpenChannelDialog(Factory.Popup, Logger):
conn_str = self.pubkey
if self.ipport:
conn_str += '@' + self.ipport.strip()
amount = self.app.get_amount(self.amount)
amount = '!' if self.is_max else self.app.get_amount(self.amount)
self.app.protected('Create a new channel?', self.do_open_channel, (conn_str, amount))
self.dismiss()

View File

@@ -196,6 +196,7 @@ class SendScreen(CScreen, Logger):
self.address = uri.get('address', '')
self.message = uri.get('message', '')
self.amount = self.app.format_amount_and_units(amount) if amount else ''
self.is_max = False
self.payment_request = None
self.is_lightning = False
@@ -260,6 +261,7 @@ class SendScreen(CScreen, Logger):
self.is_lightning = False
self.is_bip70 = False
self.parsed_URI = None
self.is_max = False
def set_request(self, pr: 'PaymentRequest'):
self.address = pr.get_requestor()
@@ -298,11 +300,14 @@ class SendScreen(CScreen, Logger):
if not self.amount:
self.app.show_error(_('Please enter an amount'))
return
try:
amount = self.app.get_amount(self.amount)
except:
self.app.show_error(_('Invalid amount') + ':\n' + self.amount)
return
if self.is_max:
amount = '!'
else:
try:
amount = self.app.get_amount(self.amount)
except:
self.app.show_error(_('Invalid amount') + ':\n' + self.amount)
return
message = self.message
if self.is_lightning:
return LNInvoice.from_bech32(address)
@@ -439,6 +444,7 @@ class ReceiveScreen(CScreen):
def clear(self):
self.address = ''
self.amount = ''
self.is_max = False # not used for receiving (see app.amount_dialog)
self.message = ''
self.lnaddr = ''