Skip to content

Commit 775b7c8

Browse files
Nostr: show QR of npub
1 parent 7296a41 commit 775b7c8

File tree

4 files changed

+77
-4
lines changed

4 files changed

+77
-4
lines changed

internal_filesystem/apps/com.micropythonos.nostr/assets/fullscreen_qr.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,23 @@ class FullscreenQR(Activity):
66
# No __init__() so super.__init__() will be called automatically
77

88
def onCreate(self):
9-
receive_qr_data = self.getIntent().extras.get("receive_qr_data")
9+
print("FullscreenQR.onCreate() called")
10+
intent = self.getIntent()
11+
print(f"Got intent: {intent}")
12+
extras = intent.extras
13+
print(f"Got extras: {extras}")
14+
receive_qr_data = extras.get("receive_qr_data")
15+
print(f"Got receive_qr_data: {receive_qr_data}")
16+
17+
if not receive_qr_data:
18+
print("ERROR: receive_qr_data is None or empty!")
19+
error_screen = lv.obj()
20+
error_label = lv.label(error_screen)
21+
error_label.set_text("No QR data")
22+
error_label.center()
23+
self.setContentView(error_screen)
24+
return
25+
1026
qr_screen = lv.obj()
1127
qr_screen.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
1228
qr_screen.set_scroll_dir(lv.DIR.NONE)
@@ -18,5 +34,8 @@ def onCreate(self):
1834
big_receive_qr.center()
1935
big_receive_qr.set_style_border_color(lv.color_white(), 0)
2036
big_receive_qr.set_style_border_width(0, 0);
37+
print(f"Updating QR code with data: {receive_qr_data[:20]}...")
2138
big_receive_qr.update(receive_qr_data, len(receive_qr_data))
39+
print("QR code updated, setting content view")
2240
self.setContentView(qr_screen)
41+
print("Content view set")

internal_filesystem/apps/com.micropythonos.nostr/assets/nostr_app.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,59 @@
11
import lvgl as lv
22

33
from mpos import Activity, Intent, ConnectivityManager, pct_of_display_width, pct_of_display_height, SharedPreferences, SettingsActivity
4+
from fullscreen_qr import FullscreenQR
5+
6+
class ShowNpubQRActivity(Activity):
7+
"""Activity that computes npub from nsec and displays it as a QR code"""
8+
9+
def onCreate(self):
10+
try:
11+
print("ShowNpubQRActivity.onCreate() called")
12+
prefs = self.getIntent().extras.get("prefs")
13+
print(f"Got prefs: {prefs}")
14+
nsec = prefs.get_string("nostr_nsec")
15+
print(f"Got nsec: {nsec[:20] if nsec else 'None'}...")
16+
17+
if not nsec:
18+
print("ERROR: No nsec configured")
19+
# Show error screen
20+
error_screen = lv.obj()
21+
error_label = lv.label(error_screen)
22+
error_label.set_text("No nsec configured")
23+
error_label.center()
24+
self.setContentView(error_screen)
25+
return
26+
27+
# Compute npub from nsec
28+
print("Importing PrivateKey...")
29+
from nostr.key import PrivateKey
30+
print("Computing npub from nsec...")
31+
if nsec.startswith("nsec1"):
32+
print("Using from_nsec()")
33+
private_key = PrivateKey.from_nsec(nsec)
34+
else:
35+
print("Using hex format")
36+
private_key = PrivateKey(bytes.fromhex(nsec))
37+
38+
npub = private_key.public_key.bech32()
39+
print(f"Computed npub: {npub[:20]}...")
40+
41+
# Launch FullscreenQR activity with npub as QR data
42+
print("Creating FullscreenQR intent...")
43+
intent = Intent(activity_class=FullscreenQR)
44+
intent.putExtra("receive_qr_data", npub)
45+
print(f"Starting FullscreenQR activity with npub: {npub[:20]}...")
46+
self.startActivity(intent)
47+
except Exception as e:
48+
print(f"ShowNpubQRActivity exception: {e}")
49+
# Show error screen
50+
error_screen = lv.obj()
51+
error_label = lv.label(error_screen)
52+
error_label.set_text(f"Error: {e}")
53+
error_label.center()
54+
self.setContentView(error_screen)
55+
import sys
56+
sys.print_exception(e)
457

558
class NostrApp(Activity):
659

@@ -133,6 +186,7 @@ def settings_button_tap(self, event):
133186
{"title": "Nostr Private Key (nsec)", "key": "nostr_nsec", "placeholder": "nsec1...", "should_show": self.should_show_setting},
134187
{"title": "Nostr Follow Public Key (npub)", "key": "nostr_follow_npub", "placeholder": "npub1...", "should_show": self.should_show_setting},
135188
{"title": "Nostr Relay", "key": "nostr_relay", "placeholder": "wss://relay.example.com", "should_show": self.should_show_setting},
189+
{"title": "Show My Public Key (npub)", "key": "show_npub_qr", "ui": "activity", "activity_class": ShowNpubQRActivity, "dont_persist": True, "should_show": self.should_show_setting},
136190
])
137191
self.startActivity(intent)
138192

internal_filesystem/apps/com.micropythonos.nostr/assets/nostr_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __str__(self):
2323
class NostrClient():
2424
"""Simple Nostr event subscriber that connects to a relay and subscribes to a public key's events"""
2525

26-
EVENTS_TO_SHOW = 10
26+
EVENTS_TO_SHOW = 50
2727

2828
relay = None
2929
nsec = None

internal_filesystem/lib/mpos/ui/settings_activity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ def onResume(self, screen):
6767
focusgroup.add_obj(setting_cont)
6868

6969
def focus_container(self, container):
70-
print(f"container {container} focused, setting border...")
70+
#print(f"container {container} focused, setting border...")
7171
container.set_style_border_color(lv.theme_get_color_primary(None),lv.PART.MAIN)
7272
container.set_style_border_width(1, lv.PART.MAIN)
7373
container.scroll_to_view(True) # scroll to bring it into view
7474

7575
def defocus_container(self, container):
76-
print(f"container {container} defocused, unsetting border...")
76+
#print(f"container {container} defocused, unsetting border...")
7777
container.set_style_border_width(0, lv.PART.MAIN)
7878

7979
def startSettingActivity(self, setting):

0 commit comments

Comments
 (0)