commit c66c54a254dd81dfd5526536aa4067c5a67dc8b6
parent f1d54d3cd8ba4784cad6ed957db6226a0a63b2ad
Author: SomberNight <somber.night@protonmail.com>
Date: Wed, 8 Jul 2020 04:16:30 +0200
android: handle on-chain/lightning URI on app open
fixes #6352
Diffstat:
3 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/electrum/gui/kivy/main_window.py b/electrum/gui/kivy/main_window.py
@@ -201,11 +201,31 @@ class ElectrumWindow(App):
self.send_screen.set_ln_invoice(invoice)
def on_new_intent(self, intent):
- data = intent.getDataString()
- if intent.getScheme() == 'bitcoin':
- self.set_URI(data)
- elif intent.getScheme() == 'lightning':
- self.set_ln_invoice(data)
+ data = str(intent.getDataString())
+ if str(intent.getScheme()).lower() in ('bitcoin', 'lightning'):
+ self._process_invoice_str(data)
+
+ _invoice_intent_queued = None # type: Optional[str]
+ def _process_invoice_str(self, invoice: str) -> None:
+ if not self.wallet:
+ self._invoice_intent_queued = invoice
+ return
+ if not self.send_screen:
+ self.switch_to('send')
+ self._invoice_intent_queued = invoice
+ return
+ if invoice.lower().startswith('bitcoin:'):
+ self.set_URI(invoice)
+ elif invoice.lower().startswith('lightning:'):
+ self.set_ln_invoice(invoice)
+
+ def _maybe_process_queued_invoice(self, *dt):
+ if not self.wallet:
+ return
+ invoice_queued = self._invoice_intent_queued
+ if invoice_queued:
+ self._invoice_intent_queued = None
+ self._process_invoice_str(invoice_queued)
def on_language(self, instance, language):
Logger.info('language: {}'.format(language))
@@ -377,6 +397,7 @@ class ElectrumWindow(App):
self._trigger_update_interfaces = Clock.create_trigger(self.update_interfaces, .5)
self._periodic_update_status_during_sync = Clock.schedule_interval(self.update_wallet_synchronizing_progress, .5)
+ self._periodic_process_queued_invoice = Clock.schedule_interval(self._maybe_process_queued_invoice, .5)
# cached dialogs
self._settings_dialog = None
diff --git a/electrum/gui/kivy/uix/screens.py b/electrum/gui/kivy/uix/screens.py
@@ -177,12 +177,10 @@ class SendScreen(CScreen):
kvname = 'send'
payment_request = None # type: Optional[PaymentRequest]
- payment_request_queued = None # type: Optional[str]
parsed_URI = None
def set_URI(self, text: str):
if not self.app.wallet:
- self.payment_request_queued = text
return
try:
uri = parse_URI(text, self.app.on_pr, loop=self.app.asyncio_loop)
@@ -197,7 +195,7 @@ class SendScreen(CScreen):
self.payment_request = None
self.is_lightning = False
- def set_ln_invoice(self, invoice):
+ def set_ln_invoice(self, invoice: str):
try:
invoice = str(invoice).lower()
lnaddr = lndecode(invoice, expected_hrp=constants.net.SEGWIT_HRP)
@@ -213,9 +211,6 @@ class SendScreen(CScreen):
def update(self):
if self.app.wallet is None:
return
- if self.payment_request_queued:
- self.set_URI(self.payment_request_queued)
- self.payment_request_queued = None
_list = self.app.wallet.get_invoices()
_list.reverse()
payments_container = self.ids.payments_container
diff --git a/electrum/gui/qt/request_list.py b/electrum/gui/qt/request_list.py
@@ -96,7 +96,7 @@ class RequestList(MyTreeView):
self.update()
return
if req.is_lightning():
- self.parent.receive_payreq_e.setText(req.invoice)
+ self.parent.receive_payreq_e.setText(req.invoice) # TODO maybe prepend "lightning:" ??
self.parent.receive_address_e.setText(req.invoice)
else:
self.parent.receive_payreq_e.setText(self.parent.wallet.get_request_URI(req))