You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
Nostr: show QR of npub
This commit is contained in:
@@ -6,7 +6,23 @@ class FullscreenQR(Activity):
|
||||
# No __init__() so super.__init__() will be called automatically
|
||||
|
||||
def onCreate(self):
|
||||
receive_qr_data = self.getIntent().extras.get("receive_qr_data")
|
||||
print("FullscreenQR.onCreate() called")
|
||||
intent = self.getIntent()
|
||||
print(f"Got intent: {intent}")
|
||||
extras = intent.extras
|
||||
print(f"Got extras: {extras}")
|
||||
receive_qr_data = extras.get("receive_qr_data")
|
||||
print(f"Got receive_qr_data: {receive_qr_data}")
|
||||
|
||||
if not receive_qr_data:
|
||||
print("ERROR: receive_qr_data is None or empty!")
|
||||
error_screen = lv.obj()
|
||||
error_label = lv.label(error_screen)
|
||||
error_label.set_text("No QR data")
|
||||
error_label.center()
|
||||
self.setContentView(error_screen)
|
||||
return
|
||||
|
||||
qr_screen = lv.obj()
|
||||
qr_screen.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
|
||||
qr_screen.set_scroll_dir(lv.DIR.NONE)
|
||||
@@ -18,5 +34,8 @@ class FullscreenQR(Activity):
|
||||
big_receive_qr.center()
|
||||
big_receive_qr.set_style_border_color(lv.color_white(), 0)
|
||||
big_receive_qr.set_style_border_width(0, 0);
|
||||
print(f"Updating QR code with data: {receive_qr_data[:20]}...")
|
||||
big_receive_qr.update(receive_qr_data, len(receive_qr_data))
|
||||
print("QR code updated, setting content view")
|
||||
self.setContentView(qr_screen)
|
||||
print("Content view set")
|
||||
|
||||
@@ -1,6 +1,59 @@
|
||||
import lvgl as lv
|
||||
|
||||
from mpos import Activity, Intent, ConnectivityManager, pct_of_display_width, pct_of_display_height, SharedPreferences, SettingsActivity
|
||||
from fullscreen_qr import FullscreenQR
|
||||
|
||||
class ShowNpubQRActivity(Activity):
|
||||
"""Activity that computes npub from nsec and displays it as a QR code"""
|
||||
|
||||
def onCreate(self):
|
||||
try:
|
||||
print("ShowNpubQRActivity.onCreate() called")
|
||||
prefs = self.getIntent().extras.get("prefs")
|
||||
print(f"Got prefs: {prefs}")
|
||||
nsec = prefs.get_string("nostr_nsec")
|
||||
print(f"Got nsec: {nsec[:20] if nsec else 'None'}...")
|
||||
|
||||
if not nsec:
|
||||
print("ERROR: No nsec configured")
|
||||
# Show error screen
|
||||
error_screen = lv.obj()
|
||||
error_label = lv.label(error_screen)
|
||||
error_label.set_text("No nsec configured")
|
||||
error_label.center()
|
||||
self.setContentView(error_screen)
|
||||
return
|
||||
|
||||
# Compute npub from nsec
|
||||
print("Importing PrivateKey...")
|
||||
from nostr.key import PrivateKey
|
||||
print("Computing npub from nsec...")
|
||||
if nsec.startswith("nsec1"):
|
||||
print("Using from_nsec()")
|
||||
private_key = PrivateKey.from_nsec(nsec)
|
||||
else:
|
||||
print("Using hex format")
|
||||
private_key = PrivateKey(bytes.fromhex(nsec))
|
||||
|
||||
npub = private_key.public_key.bech32()
|
||||
print(f"Computed npub: {npub[:20]}...")
|
||||
|
||||
# Launch FullscreenQR activity with npub as QR data
|
||||
print("Creating FullscreenQR intent...")
|
||||
intent = Intent(activity_class=FullscreenQR)
|
||||
intent.putExtra("receive_qr_data", npub)
|
||||
print(f"Starting FullscreenQR activity with npub: {npub[:20]}...")
|
||||
self.startActivity(intent)
|
||||
except Exception as e:
|
||||
print(f"ShowNpubQRActivity exception: {e}")
|
||||
# Show error screen
|
||||
error_screen = lv.obj()
|
||||
error_label = lv.label(error_screen)
|
||||
error_label.set_text(f"Error: {e}")
|
||||
error_label.center()
|
||||
self.setContentView(error_screen)
|
||||
import sys
|
||||
sys.print_exception(e)
|
||||
|
||||
class NostrApp(Activity):
|
||||
|
||||
@@ -133,6 +186,7 @@ class NostrApp(Activity):
|
||||
{"title": "Nostr Private Key (nsec)", "key": "nostr_nsec", "placeholder": "nsec1...", "should_show": self.should_show_setting},
|
||||
{"title": "Nostr Follow Public Key (npub)", "key": "nostr_follow_npub", "placeholder": "npub1...", "should_show": self.should_show_setting},
|
||||
{"title": "Nostr Relay", "key": "nostr_relay", "placeholder": "wss://relay.example.com", "should_show": self.should_show_setting},
|
||||
{"title": "Show My Public Key (npub)", "key": "show_npub_qr", "ui": "activity", "activity_class": ShowNpubQRActivity, "dont_persist": True, "should_show": self.should_show_setting},
|
||||
])
|
||||
self.startActivity(intent)
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class NostrEvent:
|
||||
class NostrClient():
|
||||
"""Simple Nostr event subscriber that connects to a relay and subscribes to a public key's events"""
|
||||
|
||||
EVENTS_TO_SHOW = 10
|
||||
EVENTS_TO_SHOW = 50
|
||||
|
||||
relay = None
|
||||
nsec = None
|
||||
|
||||
@@ -67,13 +67,13 @@ class SettingsActivity(Activity):
|
||||
focusgroup.add_obj(setting_cont)
|
||||
|
||||
def focus_container(self, container):
|
||||
print(f"container {container} focused, setting border...")
|
||||
#print(f"container {container} focused, setting border...")
|
||||
container.set_style_border_color(lv.theme_get_color_primary(None),lv.PART.MAIN)
|
||||
container.set_style_border_width(1, lv.PART.MAIN)
|
||||
container.scroll_to_view(True) # scroll to bring it into view
|
||||
|
||||
def defocus_container(self, container):
|
||||
print(f"container {container} defocused, unsetting border...")
|
||||
#print(f"container {container} defocused, unsetting border...")
|
||||
container.set_style_border_width(0, lv.PART.MAIN)
|
||||
|
||||
def startSettingActivity(self, setting):
|
||||
|
||||
Reference in New Issue
Block a user