11import 'dart:async' ;
22import 'dart:convert' ;
3+ import 'dart:ui' ;
34
45import 'package:amberflutter/amberflutter.dart' ;
56import 'package:flutter/foundation.dart' ;
7+ import 'package:flutter/material.dart' ;
68import 'package:flutter_secure_storage/flutter_secure_storage.dart' ;
9+ import 'package:go_router/go_router.dart' ;
710import 'package:ndk/data_layer/repositories/signers/nip46_event_signer.dart' ;
811import 'package:ndk/ndk.dart' ;
912import 'package:ndk/shared/nips/nip19/nip19.dart' ;
1013import 'package:ndk_amber/ndk_amber.dart' ;
14+ import 'package:phosphor_flutter/phosphor_flutter.dart' ;
15+ import '../../l10n/app_localizations.dart' ;
1116import '../../presentation_layer/providers/signer_provider.dart' ;
1217import '../entities/stored_account.dart' ;
1318
@@ -127,6 +132,18 @@ class AppAuth {
127132 return null ;
128133 }
129134
135+ case LoginType .readOnly:
136+ // For read-only accounts, use NDK's loginReadOnlyPubkey
137+ if (startupAccountData.account? .pubkey != null ) {
138+ ndk.accounts.loginPublicKey (
139+ pubkey: startupAccountData.account! .pubkey! ,
140+ );
141+ }
142+ return null ;
143+
144+ case LoginType .anon:
145+ return null ;
146+
130147 case LoginType .register:
131148 return null ;
132149 }
@@ -141,7 +158,7 @@ class AppAuth {
141158 );
142159
143160 if (activeAccountPubkey == null || storedAccountsString == null ) {
144- return StartupAccountData (loginType: LoginType .register );
161+ return StartupAccountData (loginType: LoginType .anon );
145162 }
146163
147164 final storedAccounts = jsonDecode (storedAccountsString) as List ;
@@ -160,7 +177,7 @@ class AppAuth {
160177 // if no match found, use last account or register if list is empty
161178 matchedAccount = storedAccountsList.isNotEmpty
162179 ? storedAccountsList.last
163- : LocalStorageAccount (loginType: LoginType .register );
180+ : LocalStorageAccount (loginType: LoginType .anon );
164181 }
165182
166183 return StartupAccountData (
@@ -202,4 +219,42 @@ class AppAuth {
202219 await secureStorage.delete (key: AppAuth .activeAccountPubkeyStorageKey);
203220 await secureStorage.delete (key: AppAuth .accountStorageKey);
204221 }
222+
223+ static void showLoginPrompt (BuildContext context) {
224+ showDialog (
225+ context: context,
226+ builder: (context) => BackdropFilter (
227+ filter: ImageFilter .blur (sigmaX: 5 , sigmaY: 5 ),
228+ child: AlertDialog (
229+ icon: Icon (
230+ PhosphorIcons .lockKey (),
231+ size: 48 ,
232+ color: Theme .of (context).colorScheme.primary,
233+ ),
234+ title: Text (
235+ AppLocalizations .of (context)! .loginRegistrationRequired,
236+ textAlign: TextAlign .center,
237+ ),
238+ content: Text (
239+ AppLocalizations .of (context)! .pleaseLoginToInteract,
240+ textAlign: TextAlign .center,
241+ ),
242+ actionsAlignment: MainAxisAlignment .center,
243+ actions: [
244+ TextButton (
245+ onPressed: () => Navigator .pop (context),
246+ child: Text (AppLocalizations .of (context)! .cancel),
247+ ),
248+ FilledButton (
249+ onPressed: () {
250+ Navigator .pop (context);
251+ context.push ('/onboarding' );
252+ },
253+ child: Text (AppLocalizations .of (context)! .loginRegister),
254+ ),
255+ ],
256+ ),
257+ ),
258+ );
259+ }
205260}
0 commit comments