|
1 | 1 | import lvgl as lv |
2 | 2 |
|
3 | 3 | 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) |
4 | 57 |
|
5 | 58 | class NostrApp(Activity): |
6 | 59 |
|
@@ -133,6 +186,7 @@ def settings_button_tap(self, event): |
133 | 186 | {"title": "Nostr Private Key (nsec)", "key": "nostr_nsec", "placeholder": "nsec1...", "should_show": self.should_show_setting}, |
134 | 187 | {"title": "Nostr Follow Public Key (npub)", "key": "nostr_follow_npub", "placeholder": "npub1...", "should_show": self.should_show_setting}, |
135 | 188 | {"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}, |
136 | 190 | ]) |
137 | 191 | self.startActivity(intent) |
138 | 192 |
|
|
0 commit comments