Skip to content

Commit 26c533d

Browse files
authored
Hide show phrase (#995)
1 parent 13c3643 commit 26c533d

3 files changed

Lines changed: 99 additions & 34 deletions

File tree

app/lib/screens/identity_verification_screen.dart

Lines changed: 93 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class IdentityVerificationScreenState
4040
bool emailVerified = false;
4141
bool phoneVerified = false;
4242
bool isLoading = false;
43+
bool failed = false;
4344
bool hidePhoneVerifyButton = false;
4445
bool emailInputValidated = false;
4546
int emailCountdown = 60;
@@ -196,20 +197,44 @@ class IdentityVerificationScreenState
196197
}
197198

198199
void getUserValues() async {
199-
doubleName = (await getDoubleName())?.replaceAll('.3bot', '') ?? 'Unknown';
200-
phrase = (await getPhrase())!;
201-
final emailMap = await getEmail();
202-
if (emailMap['email'] != null) {
203-
email = emailMap['email']!;
204-
changeEmailController.text = email;
205-
emailVerified = (emailMap['sei'] != null);
206-
}
207-
final phoneMap = await getPhone();
208-
if (phoneMap['phone'] != null) {
209-
phone = phoneMap['phone']!;
210-
phoneVerified = (phoneMap['spi'] != null);
200+
setState(() => isLoading = true);
201+
try {
202+
doubleName =
203+
(await getDoubleName())?.replaceAll('.3bot', '') ?? 'Unknown';
204+
phrase = (await getPhrase()) ?? '';
205+
final emailMap = await getEmail();
206+
if (emailMap['email'] != null) {
207+
email = emailMap['email']!;
208+
changeEmailController.text = email;
209+
emailVerified = (emailMap['sei'] != null);
210+
}
211+
final phoneMap = await getPhone();
212+
if (phoneMap['phone'] != null) {
213+
phone = phoneMap['phone']!;
214+
phoneVerified = (phoneMap['spi'] != null);
215+
}
216+
} catch (e) {
217+
setState(() {
218+
failed = true;
219+
});
220+
logger.e('Failed to get user values due to $e');
221+
if (context.mounted) {
222+
final loadingFarmsFailure = SnackBar(
223+
content: Text(
224+
'Failed to get user values',
225+
style: Theme.of(context)
226+
.textTheme
227+
.bodyMedium!
228+
.copyWith(color: Theme.of(context).colorScheme.errorContainer),
229+
),
230+
duration: const Duration(seconds: 3),
231+
);
232+
ScaffoldMessenger.of(context).clearSnackBars();
233+
ScaffoldMessenger.of(context).showSnackBar(loadingFarmsFailure);
234+
}
235+
} finally {
236+
if (mounted) setState(() => isLoading = false);
211237
}
212-
setState(() {});
213238
}
214239

215240
Future copySeedPhrase() async {
@@ -619,9 +644,44 @@ class IdentityVerificationScreenState
619644

620645
@override
621646
Widget build(BuildContext context) {
622-
return LayoutDrawer(
623-
titleText: 'Identity',
624-
content: Padding(
647+
final Widget content;
648+
if (isLoading) {
649+
content = Center(
650+
child: Column(
651+
mainAxisAlignment: MainAxisAlignment.center,
652+
children: [
653+
const CircularProgressIndicator(),
654+
const SizedBox(height: 15),
655+
Text(
656+
'Loading identity information...',
657+
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
658+
color: Theme.of(context).colorScheme.onSurface,
659+
fontWeight: FontWeight.bold),
660+
),
661+
],
662+
));
663+
} else if (failed) {
664+
content = Center(
665+
child: Column(
666+
mainAxisAlignment: MainAxisAlignment.center,
667+
children: [
668+
const SizedBox(height: 15),
669+
ElevatedButton.icon(
670+
icon: const Icon(Icons.refresh),
671+
label: const Text('Try Again'),
672+
onPressed: () {
673+
setState(() {
674+
failed = false;
675+
isLoading = true;
676+
});
677+
getUserValues();
678+
},
679+
),
680+
],
681+
),
682+
);
683+
} else {
684+
content = Padding(
625685
padding: const EdgeInsets.symmetric(horizontal: 4.0),
626686
child: SingleChildScrollView(
627687
child: Column(
@@ -641,16 +701,18 @@ class IdentityVerificationScreenState
641701
title: Text(doubleName),
642702
),
643703
customDivider(context: context),
644-
Padding(
645-
padding: const EdgeInsets.only(right: 2.0),
646-
child: ListTile(
647-
trailing: const Icon(Icons.visibility),
648-
leading: const Icon(Icons.vpn_key),
649-
title: const Text('Show phrase'),
650-
onTap: _showPhrase,
704+
if (phrase.isNotEmpty) ...[
705+
Padding(
706+
padding: const EdgeInsets.only(right: 2.0),
707+
child: ListTile(
708+
trailing: const Icon(Icons.visibility),
709+
leading: const Icon(Icons.vpn_key),
710+
title: const Text('Show phrase'),
711+
onTap: _showPhrase,
712+
),
651713
),
652-
),
653-
customDivider(context: context),
714+
customDivider(context: context),
715+
],
654716
infoWidget(1, email, Icons.email, emailVerified),
655717
customDivider(context: context),
656718
infoWidget(2, phone, Icons.phone, phoneVerified),
@@ -661,7 +723,12 @@ class IdentityVerificationScreenState
661723
],
662724
),
663725
),
664-
),
726+
);
727+
}
728+
729+
return LayoutDrawer(
730+
titleText: 'Identity',
731+
content: content,
665732
);
666733
}
667734
}

app/lib/screens/mobile_registration_screen.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,12 @@ class _MobileRegistrationScreenState extends State<MobileRegistrationScreen> {
254254
}
255255

256256
void saveRegistration() async {
257-
savePrivateKey(_registrationData.keyPair.secretKey.extractBytes());
258-
savePublicKey(_registrationData.keyPair.publicKey);
259-
saveFingerprint(false);
260-
saveEmail(_registrationData.email, null);
261-
saveDoubleName(_registrationData.doubleName);
262-
savePhrase(_registrationData.phrase);
257+
await savePrivateKey(_registrationData.keyPair.secretKey.extractBytes());
258+
await savePublicKey(_registrationData.keyPair.publicKey);
259+
await saveFingerprint(false);
260+
await saveEmail(_registrationData.email, null);
261+
await saveDoubleName(_registrationData.doubleName);
262+
await savePhrase(_registrationData.phrase);
263263

264264
FlutterPkid client = await getPkidClient();
265265
client.setPKidDoc('email', json.encode({'email': _registrationData.email}));

app/lib/services/shared_preference_service.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ Future<Map<String, String>> getEdCurveKeys() async {
111111

112112
Future<void> savePhrase(String phrase) async {
113113
final SharedPreferences prefs = await SharedPreferences.getInstance();
114-
prefs.remove('phrase');
115-
116114
prefs.setString('phrase', phrase);
117115
}
118116

0 commit comments

Comments
 (0)