Skip to content

Commit

Permalink
Add waiting icon when user create keychain in welcome process #170
Browse files Browse the repository at this point in the history
  • Loading branch information
redDwarf03 committed Jul 11, 2022
1 parent 0cb5519 commit 46a19ab
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 53 deletions.
103 changes: 61 additions & 42 deletions packages/aeuniverse/lib/ui/views/intro/intro_configure_security.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// ignore_for_file: always_specify_types

// Flutter imports:
import 'package:aeuniverse/ui/widgets/components/dialog.dart';
import 'package:core/model/data/appdb.dart';
import 'package:core/model/primary_currency.dart';
import 'package:core/util/keychain_util.dart';
Expand Down Expand Up @@ -38,6 +39,13 @@ class IntroConfigureSecurity extends StatefulWidget {

class _IntroConfigureSecurityState extends State<IntroConfigureSecurity> {
PickerItem? _accessModesSelected;
bool? animationOpen;

@override
void initState() {
animationOpen = false;
super.initState();
}

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -137,38 +145,51 @@ class _IntroConfigureSecurityState extends State<IntroConfigureSecurity> {
_accessModesSelected!.value as AuthMethod;
switch (_authMethod) {
case AuthMethod.biometrics:
await authenticateWithBiometrics();
final Preferences _preferences =
await Preferences.getInstance();
_preferences.setLock(true);
_preferences.setShowBalances(true);
_preferences.setShowBlog(true);
_preferences.setActiveVibrations(true);
_preferences.setActiveNotifications(true);
StateContainer.of(context)
.checkTransactionInputs(
final bool authenticated = await sl
.get<BiometricUtil>()
.authenticateWithBiometrics(
context,
AppLocalization.of(context)!
.transactionInputNotification);
_preferences.setPinPadShuffle(false);
_preferences.setShowPriceChart(true);
_preferences.setPrimaryCurrency(
PrimaryCurrencySetting(
AvailablePrimaryCurrency.NATIVE));
_preferences.setLockTimeout(
LockTimeoutSetting(
LockTimeoutOption.one));
_preferences.setAuthMethod(
AuthenticationMethod(
AuthMethod.biometrics));
await sl.get<DBHelper>().clearAppWallet();
final Vault vault =
await Vault.getInstance();
await vault.setSeed(widget.seed!);
StateContainer.of(context).appWallet =
await KeychainUtil().newAppWallet(
widget.seed!, widget.name!);
await StateContainer.of(context)
.requestUpdate();
.unlockBiometrics);
if (authenticated) {
_showSendingAnimation(context);
final Preferences _preferences =
await Preferences.getInstance();
_preferences.setLock(true);
_preferences.setShowBalances(true);
_preferences.setShowBlog(true);
_preferences.setActiveVibrations(true);
_preferences.setActiveNotifications(true);
StateContainer.of(context)
.checkTransactionInputs(
AppLocalization.of(context)!
.transactionInputNotification);
_preferences.setPinPadShuffle(false);
_preferences.setShowPriceChart(true);
_preferences.setPrimaryCurrency(
PrimaryCurrencySetting(
AvailablePrimaryCurrency.NATIVE));
_preferences.setLockTimeout(
LockTimeoutSetting(
LockTimeoutOption.one));
_preferences.setAuthMethod(
AuthenticationMethod(
AuthMethod.biometrics));
await sl.get<DBHelper>().clearAppWallet();
final Vault vault =
await Vault.getInstance();
await vault.setSeed(widget.seed!);
StateContainer.of(context).appWallet =
await KeychainUtil().newAppWallet(
widget.seed!, widget.name!);
await StateContainer.of(context)
.requestUpdate();
}
await Navigator.of(context)
.pushNamedAndRemoveUntil(
'/home',
(Route<dynamic> route) => false,
);
break;
case AuthMethod.password:
Navigator.of(context).pushNamed(
Expand All @@ -189,6 +210,7 @@ class _IntroConfigureSecurityState extends State<IntroConfigureSecurity> {
}));

if (pin.length > 5) {
_showSendingAnimation(context);
final Vault _vault =
await Vault.getInstance();
_vault.setPin(pin);
Expand Down Expand Up @@ -255,16 +277,13 @@ class _IntroConfigureSecurityState extends State<IntroConfigureSecurity> {
);
}

Future<void> authenticateWithBiometrics() async {
final bool authenticated = await sl
.get<BiometricUtil>()
.authenticateWithBiometrics(
context, AppLocalization.of(context)!.unlockBiometrics);
if (authenticated) {
await Navigator.of(context).pushNamedAndRemoveUntil(
'/home',
(Route<dynamic> route) => false,
);
}
void _showSendingAnimation(BuildContext context) {
animationOpen = true;
Navigator.of(context).push(AnimationLoadingOverlay(
AnimationType.send,
StateContainer.of(context).curTheme.animationOverlayStrong!,
StateContainer.of(context).curTheme.animationOverlayMedium!,
onPoppedCallback: () => animationOpen = false,
title: AppLocalization.of(context)!.keychainCreationInProgress));
}
}
14 changes: 14 additions & 0 deletions packages/aeuniverse/lib/ui/views/settings/set_password.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// SPDX-License-Identifier: AGPL-3.0-or-later
// Flutter imports:
import 'package:aeuniverse/ui/widgets/components/dialog.dart';
import 'package:core/model/data/appdb.dart';
import 'package:core/model/primary_currency.dart';
import 'package:core/util/get_it_instance.dart';
Expand Down Expand Up @@ -49,6 +50,7 @@ class _SetPasswordState extends State<SetPassword> {
TextEditingController? setPasswordController;
FocusNode? confirmPasswordFocusNode;
TextEditingController? confirmPasswordController;
bool? animationOpen;

String? passwordError;
bool? passwordsMatch;
Expand All @@ -66,6 +68,7 @@ class _SetPasswordState extends State<SetPassword> {
confirmPasswordFocusNode = FocusNode();
setPasswordController = TextEditingController();
confirmPasswordController = TextEditingController();
animationOpen = false;
}

@override
Expand Down Expand Up @@ -470,6 +473,7 @@ class _SetPasswordState extends State<SetPassword> {
});
}
} else {
_showSendingAnimation(context);
Vault _vault = await Vault.getInstance();
_vault.setPassword(
stringEncryptBase64(setPasswordController!.text, widget.seed));
Expand Down Expand Up @@ -501,4 +505,14 @@ class _SetPasswordState extends State<SetPassword> {
);
}
}

void _showSendingAnimation(BuildContext context) {
animationOpen = true;
Navigator.of(context).push(AnimationLoadingOverlay(
AnimationType.send,
StateContainer.of(context).curTheme.animationOverlayStrong!,
StateContainer.of(context).curTheme.animationOverlayMedium!,
onPoppedCallback: () => animationOpen = false,
title: AppLocalization.of(context)!.keychainCreationInProgress));
}
}
15 changes: 14 additions & 1 deletion packages/aeuniverse/lib/ui/views/settings/set_yubikey.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// SPDX-License-Identifier: AGPL-3.0-or-later
// Flutter imports:
import 'package:aeuniverse/ui/widgets/components/dialog.dart';
import 'package:core/model/data/appdb.dart';
import 'package:core/model/primary_currency.dart';
import 'package:core/util/get_it_instance.dart';
Expand Down Expand Up @@ -54,7 +55,7 @@ class _SetYubikeyState extends State<SetYubikey> {
TextEditingController? _clientIDController;
FocusNode? _clientAPIKeyFocusNode;
TextEditingController? _clientAPIKeyController;

bool? animationOpen;
String _clientIDValidationText = '';
String _clientAPIKeyValidationText = '';

Expand All @@ -71,6 +72,7 @@ class _SetYubikeyState extends State<SetYubikey> {
if (widget.clientID != null) {
_clientIDController!.text = widget.clientID!;
}
animationOpen = false;
}

@override
Expand Down Expand Up @@ -297,6 +299,7 @@ class _SetYubikeyState extends State<SetYubikey> {
});
}
} else {
_showSendingAnimation(context);
Vault _vault = await Vault.getInstance();
_vault.setYubikeyClientAPIKey(_clientAPIKeyController!.text);
_vault.setYubikeyClientID(_clientIDController!.text);
Expand Down Expand Up @@ -339,4 +342,14 @@ class _SetYubikeyState extends State<SetYubikey> {
}
}
}

void _showSendingAnimation(BuildContext context) {
animationOpen = true;
Navigator.of(context).push(AnimationLoadingOverlay(
AnimationType.send,
StateContainer.of(context).curTheme.animationOverlayStrong!,
StateContainer.of(context).curTheme.animationOverlayMedium!,
onPoppedCallback: () => animationOpen = false,
title: AppLocalization.of(context)!.keychainCreationInProgress));
}
}
27 changes: 20 additions & 7 deletions packages/aeuniverse/lib/ui/widgets/components/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,13 @@ enum AnimationType {

class AnimationLoadingOverlay extends ModalRoute<void> {
AnimationLoadingOverlay(this.type, this.overlay85, this.overlay70,
{this.onPoppedCallback});
{this.onPoppedCallback, this.title});

AnimationType type;
Function? onPoppedCallback;
Color overlay85;
Color overlay70;
String? title;

@override
Duration get transitionDuration => const Duration(milliseconds: 0);
Expand Down Expand Up @@ -168,7 +169,9 @@ class AnimationLoadingOverlay extends ModalRoute<void> {
Widget _getAnimation(BuildContext context) {
switch (type) {
case AnimationType.send:
return PulsatingCircleLogo();
return PulsatingCircleLogo(
title: title,
);
default:
return CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Expand Down Expand Up @@ -201,12 +204,11 @@ class AnimationLoadingOverlay extends ModalRoute<void> {
}

class PulsatingCircleLogo extends StatefulWidget {
const PulsatingCircleLogo({
Key? key,
}) : super(key: key);
final String? title;
const PulsatingCircleLogo({super.key, this.title});

@override
PulsatingCircleLogoState createState() => PulsatingCircleLogoState();
State<PulsatingCircleLogo> createState() => PulsatingCircleLogoState();
}

class PulsatingCircleLogoState extends State<PulsatingCircleLogo>
Expand All @@ -225,6 +227,14 @@ class PulsatingCircleLogoState extends State<PulsatingCircleLogo>
super.initState();
}

@override
void dispose() {
if (_animationController != null) {
_animationController!.dispose();
}
super.dispose();
}

@override
Widget build(BuildContext context) {
return Column(
Expand Down Expand Up @@ -265,7 +275,10 @@ class PulsatingCircleLogoState extends State<PulsatingCircleLogo>
height: 40,
),
Text(
AppLocalization.of(context)!.pleaseWait,
widget.title != null
? widget.title!
: AppLocalization.of(context)!.pleaseWait,
textAlign: TextAlign.center,
style: AppStyles.textStyleSize16W600EquinoxPrimary(context),
)
],
Expand Down
3 changes: 2 additions & 1 deletion packages/core/lib/l10n/intl_ar.arb
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,6 @@
"activateNotifications": "Activate notifications",
"transactionInputNotification": "You have received %1 %2 on your %3 account",
"searchField": "Search...",
"pleaseWait": "Please wait"
"pleaseWait": "Please wait",
"keychainCreationInProgress": "Your keychain is being created..."
}
6 changes: 6 additions & 0 deletions packages/core/lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1697,5 +1697,11 @@
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"keychainCreationInProgress": "Your keychain is being created...",
"@keychainCreationInProgress": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
}
}
3 changes: 2 additions & 1 deletion packages/core/lib/l10n/intl_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,6 @@
"activateNotifications": "Activer les notifications",
"transactionInputNotification": "Vous avez reçu %1 %2 sur votre compte %3",
"searchField": "Recherche...",
"pleaseWait": "Veuillez patienter"
"pleaseWait": "Veuillez patienter",
"keychainCreationInProgress": "Votre porte-clés est en cours de création..."
}
8 changes: 7 additions & 1 deletion packages/core/lib/l10n/intl_messages.arb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"@@last_modified": "2022-07-10T10:56:00.642771",
"@@last_modified": "2022-07-11T10:06:57.395223",
"welcomeText": "Welcome to Internet of Trust.\n\nArchethic gives back to humanity control over technology, and to each individual, control over their identity.",
"@welcomeText": {
"type": "text",
Expand Down Expand Up @@ -1739,5 +1739,11 @@
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"keychainCreationInProgress": "Your keychain is being created...",
"@keychainCreationInProgress": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
}
}
1 change: 1 addition & 0 deletions packages/core/lib/l10n/messages_ar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class MessageLookup extends MessageLookupByLibrary {
"invalidAddress" : MessageLookupByLibrary.simpleMessage("L\'adresse saisie n\'est pas valide"),
"invalidPassword" : MessageLookupByLibrary.simpleMessage("Le mot de passe est invalide"),
"iveBackedItUp" : MessageLookupByLibrary.simpleMessage("Je l\'ai sauvegardé"),
"keychainCreationInProgress" : MessageLookupByLibrary.simpleMessage("Your keychain is being created..."),
"labLinkDesc" : MessageLookupByLibrary.simpleMessage("Dernières nouvelles sur l\'écosystème Archethic"),
"labLinkHeader" : MessageLookupByLibrary.simpleMessage("Lab"),
"language" : MessageLookupByLibrary.simpleMessage("Langue"),
Expand Down
1 change: 1 addition & 0 deletions packages/core/lib/l10n/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class MessageLookup extends MessageLookupByLibrary {
"introNewWalletGetFirstInfosWelcome" : MessageLookupByLibrary.simpleMessage("Welcome to Archethic Wallet."),
"invalidAddress" : MessageLookupByLibrary.simpleMessage("Address entered is invalid"),
"iveBackedItUp" : MessageLookupByLibrary.simpleMessage("I\'ve Backed It Up"),
"keychainCreationInProgress" : MessageLookupByLibrary.simpleMessage("Your keychain is being created..."),
"labLinkDesc" : MessageLookupByLibrary.simpleMessage("Latest tech and product updates on the Archethic ecosystem"),
"labLinkHeader" : MessageLookupByLibrary.simpleMessage("Lab"),
"language" : MessageLookupByLibrary.simpleMessage("Language"),
Expand Down
1 change: 1 addition & 0 deletions packages/core/lib/l10n/messages_fr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class MessageLookup extends MessageLookupByLibrary {
"invalidAddress" : MessageLookupByLibrary.simpleMessage("L\'adresse saisie n\'est pas valide"),
"invalidPassword" : MessageLookupByLibrary.simpleMessage("Le mot de passe est invalide"),
"iveBackedItUp" : MessageLookupByLibrary.simpleMessage("Je l\'ai sauvegardé"),
"keychainCreationInProgress" : MessageLookupByLibrary.simpleMessage("Votre porte-clés est en cours de création..."),
"labLinkDesc" : MessageLookupByLibrary.simpleMessage("Dernières nouvelles sur l\'écosystème Archethic"),
"labLinkHeader" : MessageLookupByLibrary.simpleMessage("Lab"),
"language" : MessageLookupByLibrary.simpleMessage("Langue"),
Expand Down
1 change: 1 addition & 0 deletions packages/core/lib/l10n/messages_messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class MessageLookup extends MessageLookupByLibrary {
"invalidAddress" : MessageLookupByLibrary.simpleMessage("Address entered is invalid"),
"invalidPassword" : MessageLookupByLibrary.simpleMessage("Invalid Password"),
"iveBackedItUp" : MessageLookupByLibrary.simpleMessage("I\'ve Backed It Up"),
"keychainCreationInProgress" : MessageLookupByLibrary.simpleMessage("Your keychain is being created..."),
"labLinkDesc" : MessageLookupByLibrary.simpleMessage("Latest tech and product updates on the Archethic ecosystem"),
"labLinkHeader" : MessageLookupByLibrary.simpleMessage("Lab"),
"language" : MessageLookupByLibrary.simpleMessage("Language"),
Expand Down
5 changes: 5 additions & 0 deletions packages/core/lib/localization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,11 @@ class AppLocalization {
String get pleaseWait {
return Intl.message("Please wait", name: 'pleaseWait');
}

String get keychainCreationInProgress {
return Intl.message("Your keychain is being created...",
name: 'keychainCreationInProgress');
}
}

class AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalization> {
Expand Down

0 comments on commit 46a19ab

Please sign in to comment.