kivy: rm code dupe between app.on_qr and send_screen.do_paste
This commit is contained in:
@@ -475,20 +475,16 @@ class ElectrumWindow(App, Logger, EventListener):
|
|||||||
self.show_error("invoice error:" + pr.error)
|
self.show_error("invoice error:" + pr.error)
|
||||||
self.send_screen.do_clear()
|
self.send_screen.do_clear()
|
||||||
|
|
||||||
def on_qr(self, data: str): # TODO duplicate of send_screen.do_paste
|
def on_qr(self, data: str):
|
||||||
from electrum.bitcoin import is_address
|
self.on_data_input(data)
|
||||||
|
|
||||||
|
def on_data_input(self, data: str) -> None:
|
||||||
|
"""on_qr / on_paste shared logic"""
|
||||||
data = data.strip()
|
data = data.strip()
|
||||||
if is_address(data):
|
|
||||||
self.set_URI(data)
|
|
||||||
return
|
|
||||||
if is_uri(data) or maybe_extract_lightning_payment_identifier(data):
|
|
||||||
# TODO what about "lightning address"?
|
|
||||||
self.set_URI(data)
|
|
||||||
return
|
|
||||||
if data.lower().startswith('channel_backup:'):
|
if data.lower().startswith('channel_backup:'):
|
||||||
self.import_channel_backup(data)
|
self.import_channel_backup(data)
|
||||||
return
|
return
|
||||||
# try to decode transaction
|
# try to decode as transaction
|
||||||
from electrum.transaction import tx_from_any
|
from electrum.transaction import tx_from_any
|
||||||
try:
|
try:
|
||||||
tx = tx_from_any(data)
|
tx = tx_from_any(data)
|
||||||
@@ -497,8 +493,8 @@ class ElectrumWindow(App, Logger, EventListener):
|
|||||||
if tx:
|
if tx:
|
||||||
self.tx_dialog(tx)
|
self.tx_dialog(tx)
|
||||||
return
|
return
|
||||||
# show error
|
# try to decode as URI/address
|
||||||
self.show_error("Unable to decode QR data")
|
self.set_URI(data)
|
||||||
|
|
||||||
def update_tab(self, name):
|
def update_tab(self, name):
|
||||||
s = getattr(self, name + '_screen', None)
|
s = getattr(self, name + '_screen', None)
|
||||||
|
|||||||
@@ -315,22 +315,12 @@ class SendScreen(CScreen, Logger):
|
|||||||
self.locked = True
|
self.locked = True
|
||||||
self.payment_request = pr
|
self.payment_request = pr
|
||||||
|
|
||||||
def do_paste(self): # TODO duplicate of app.on_qr
|
def do_paste(self):
|
||||||
data = self.app._clipboard.paste().strip()
|
data = self.app._clipboard.paste().strip()
|
||||||
if not data:
|
if not data:
|
||||||
self.app.show_info(_("Clipboard is empty"))
|
self.app.show_info(_("Clipboard is empty"))
|
||||||
return
|
return
|
||||||
# try to decode as transaction
|
self.app.on_data_input(data)
|
||||||
try:
|
|
||||||
tx = tx_from_any(data)
|
|
||||||
tx.deserialize()
|
|
||||||
except:
|
|
||||||
tx = None
|
|
||||||
if tx:
|
|
||||||
self.app.tx_dialog(tx)
|
|
||||||
return
|
|
||||||
# try to decode as URI/address
|
|
||||||
self.set_URI(data)
|
|
||||||
|
|
||||||
def read_invoice(self):
|
def read_invoice(self):
|
||||||
address = str(self.address)
|
address = str(self.address)
|
||||||
|
|||||||
Reference in New Issue
Block a user