88# screens:
99main_screen = None
1010settings_screen = None
11+ qr_screen = None
1112
1213# widgets
1314receive_qr = None
1415balance_label = None
1516payments_label = None
1617
18+ # variables
1719wallet = None
20+ receive_qr_data = None
1821
1922# Settings screen implementation
2023class SettingsScreen ():
@@ -25,8 +28,8 @@ def __init__(self):
2528 {"title" : "Wallet Type" , "key" : "wallet_type" , "value_label" : None },
2629 {"title" : "LNBits URL" , "key" : "lnbits_url" , "value_label" : None },
2730 {"title" : "LNBits Read/Invoice Key" , "key" : "lnbits_readkey" , "value_label" : None },
31+ {"title" : "Static receive code" , "key" : "lnbits_static_receive_code" , "value_label" : None },
2832 {"title" : "NWC URL" , "key" : "nwc_url" , "value_label" : None },
29- {"title" : "Static receive code" , "key" : "static_receive_code" , "value_label" : None },
3033 ]
3134 self .keyboard = None
3235 self .textarea = None
@@ -199,6 +202,21 @@ def main_ui_set_defaults():
199202 payments_label .set_text (lv .SYMBOL .REFRESH )
200203 receive_qr .update ("" , len ("" ))
201204
205+ def qr_clicked_cb (event ):
206+ global qr_screen , big_receive_qr , receive_qr_data
207+ print ("QR clicked" )
208+ qr_screen = lv .obj ()
209+ big_receive_qr = lv .qrcode (qr_screen )
210+ big_receive_qr .set_size (240 ) # TODO: make this dynamic
211+ big_receive_qr .set_dark_color (lv .color_black ())
212+ big_receive_qr .set_light_color (lv .color_white ())
213+ big_receive_qr .center ()
214+ big_receive_qr .set_style_border_color (lv .color_white (), 0 )
215+ big_receive_qr .set_style_border_width (3 , 0 );
216+ big_receive_qr .update (receive_qr_data , len (receive_qr_data ))
217+ mpos .ui .load_screen (qr_screen )
218+
219+
202220def build_main_ui ():
203221 global main_screen , balance_label , payments_label , receive_qr
204222 main_screen = lv .obj ()
@@ -213,6 +231,8 @@ def build_main_ui():
213231 receive_qr .align (lv .ALIGN .TOP_RIGHT ,0 ,0 )
214232 receive_qr .set_style_border_color (lv .color_white (), 0 )
215233 receive_qr .set_style_border_width (3 , 0 );
234+ receive_qr .add_flag (lv .obj .FLAG .CLICKABLE )
235+ receive_qr .add_event_cb (qr_clicked_cb ,lv .EVENT .CLICKED ,None )
216236 style_line = lv .style_t ()
217237 style_line .init ()
218238 style_line .set_line_width (2 )
@@ -243,34 +263,34 @@ def redraw_payments_cb():
243263 payments_label .set_text (str (wallet .payment_list ))
244264
245265def janitor_cb (timer ):
246- global wallet , config
266+ global wallet , config , receive_qr_data
247267 if lv .screen_active () == main_screen and (not wallet or not wallet .is_running ()): # just started the app or just returned from settings_screen
248268 main_ui_set_defaults ()
249269 config = mpos .config .SharedPreferences ("com.lightningpiggy.displaywallet" )
250270 wallet_type = config .get_string ("wallet_type" )
251271 if wallet_type == "lnbits" :
252272 try :
253- static_receive_code = config .get_string ("static_receive_code " )
273+ receive_qr_data = config .get_string ("lnbits_static_receive_code " )
254274 wallet = LNBitsWallet (config .get_string ("lnbits_url" ), config .get_string ("lnbits_readkey" ))
255275 except Exception as e :
256276 print (f"Couldn't initialize LNBitsWallet because: { e } " )
257277 elif wallet_type == "nwc" :
258278 try :
259279 wallet = NWCWallet (config .get_string ("nwc_url" ))
260- static_receive_code = wallet .lud16
280+ receive_qr_data = wallet .lud16
261281 except Exception as e :
262282 print (f"Couldn't initialize NWCWallet because: { e } " )
263283 else :
264284 print (f"No or unsupported wallet type configured: '{ wallet_type } '" )
265- if static_receive_code :
266- print (f"Setting static_receive_code: { static_receive_code } " )
267- receive_qr .update (static_receive_code , len (static_receive_code ))
285+ if receive_qr_data :
286+ print (f"Setting static_receive_code: { receive_qr_data } " )
287+ receive_qr .update (receive_qr_data , len (receive_qr_data ))
268288 if wallet :
269289 print ("Starting wallet..." )
270290 wallet .start (redraw_balance_cb , redraw_payments_cb )
271291 else :
272292 print ("ERROR: could not start any wallet!" ) # maybe call the error callback to show the error to the user
273- elif lv .screen_active () != main_screen and lv .screen_active () != settings_screen :
293+ elif lv .screen_active () != main_screen and lv .screen_active () != settings_screen and lv . screen_active () != qr_screen :
274294 print ("app backgrounded, cleaning up..." )
275295 janitor .delete ()
276296 wallet .stop ()
0 commit comments