receive requests: encode lightning invoices as uppercase -> smaller QRs
By encoding bolt11 invoices as uppercase text in QR codes, we can use the alphanumeric mode, which results in non-negligibly smaller QR codes.
This commit is contained in:
@@ -431,9 +431,8 @@ class ElectrumWindow(App):
|
|||||||
def show_request(self, is_lightning, key):
|
def show_request(self, is_lightning, key):
|
||||||
from .uix.dialogs.request_dialog import RequestDialog
|
from .uix.dialogs.request_dialog import RequestDialog
|
||||||
request = self.wallet.get_request(key)
|
request = self.wallet.get_request(key)
|
||||||
status = request['status']
|
|
||||||
data = request['invoice'] if is_lightning else request['URI']
|
data = request['invoice'] if is_lightning else request['URI']
|
||||||
self.request_popup = RequestDialog('Request', data, key)
|
self.request_popup = RequestDialog('Request', data, key, is_lightning=is_lightning)
|
||||||
self.request_popup.set_status(request['status'])
|
self.request_popup.set_status(request['status'])
|
||||||
self.request_popup.open()
|
self.request_popup.open()
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from kivy.app import App
|
from kivy.app import App
|
||||||
from kivy.factory import Factory
|
from kivy.factory import Factory
|
||||||
from kivy.properties import ObjectProperty
|
from kivy.properties import ObjectProperty
|
||||||
@@ -7,6 +9,10 @@ from kivy.uix.popup import Popup
|
|||||||
|
|
||||||
from electrum.gui.kivy.i18n import _
|
from electrum.gui.kivy.i18n import _
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from ...main_window import ElectrumWindow
|
||||||
|
|
||||||
|
|
||||||
Builder.load_string('''
|
Builder.load_string('''
|
||||||
<AddressLabel@Label>
|
<AddressLabel@Label>
|
||||||
text_size: self.width, None
|
text_size: self.width, None
|
||||||
@@ -184,7 +190,7 @@ class AddressesDialog(Factory.Popup):
|
|||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
Factory.Popup.__init__(self)
|
Factory.Popup.__init__(self)
|
||||||
self.app = app
|
self.app = app # type: ElectrumWindow
|
||||||
|
|
||||||
def get_card(self, addr, balance, is_used, label):
|
def get_card(self, addr, balance, is_used, label):
|
||||||
ci = {}
|
ci = {}
|
||||||
|
|||||||
@@ -66,16 +66,22 @@ Builder.load_string('''
|
|||||||
|
|
||||||
class RequestDialog(Factory.Popup):
|
class RequestDialog(Factory.Popup):
|
||||||
|
|
||||||
def __init__(self, title, data, key):
|
def __init__(self, title, data, key, *, is_lightning=False):
|
||||||
self.status = PR_UNKNOWN
|
self.status = PR_UNKNOWN
|
||||||
Factory.Popup.__init__(self)
|
Factory.Popup.__init__(self)
|
||||||
self.app = App.get_running_app()
|
self.app = App.get_running_app()
|
||||||
self.title = title
|
self.title = title
|
||||||
self.data = data
|
self.data = data
|
||||||
self.key = key
|
self.key = key
|
||||||
|
self.is_lightning = is_lightning
|
||||||
|
|
||||||
def on_open(self):
|
def on_open(self):
|
||||||
self.ids.qr.set_data(self.data)
|
data = self.data
|
||||||
|
if self.is_lightning:
|
||||||
|
# encode lightning invoices as uppercase so QR encoding can use
|
||||||
|
# alphanumeric mode; resulting in smaller QR codes
|
||||||
|
data = data.upper()
|
||||||
|
self.ids.qr.set_data(data)
|
||||||
|
|
||||||
def set_status(self, status):
|
def set_status(self, status):
|
||||||
self.status = status
|
self.status = status
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ from electrum.util import (format_time, format_satoshis, format_fee_satoshis,
|
|||||||
decimal_point_to_base_unit_name,
|
decimal_point_to_base_unit_name,
|
||||||
UnknownBaseUnit, DECIMAL_POINT_DEFAULT, UserFacingException,
|
UnknownBaseUnit, DECIMAL_POINT_DEFAULT, UserFacingException,
|
||||||
get_new_wallet_name, send_exception_to_crash_reporter,
|
get_new_wallet_name, send_exception_to_crash_reporter,
|
||||||
InvalidBitcoinURI)
|
InvalidBitcoinURI, maybe_extract_bolt11_invoice)
|
||||||
from electrum.util import PR_TYPE_ONCHAIN, PR_TYPE_LN
|
from electrum.util import PR_TYPE_ONCHAIN, PR_TYPE_LN
|
||||||
from electrum.transaction import (Transaction, PartialTxInput,
|
from electrum.transaction import (Transaction, PartialTxInput,
|
||||||
PartialTransaction, PartialTxOutput)
|
PartialTransaction, PartialTxOutput)
|
||||||
@@ -1171,6 +1171,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
|
|
||||||
def update_receive_qr(self):
|
def update_receive_qr(self):
|
||||||
uri = str(self.receive_address_e.text())
|
uri = str(self.receive_address_e.text())
|
||||||
|
if maybe_extract_bolt11_invoice(uri):
|
||||||
|
# encode lightning invoices as uppercase so QR encoding can use
|
||||||
|
# alphanumeric mode; resulting in smaller QR codes
|
||||||
|
uri = uri.upper()
|
||||||
self.receive_qr.setData(uri)
|
self.receive_qr.setData(uri)
|
||||||
if self.qr_window and self.qr_window.isVisible():
|
if self.qr_window and self.qr_window.isVisible():
|
||||||
self.qr_window.qrw.setData(uri)
|
self.qr_window.qrw.setData(uri)
|
||||||
|
|||||||
Reference in New Issue
Block a user