Skip to content

Commit

Permalink
feat: Setup restore at setup options for all app #2992
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Oct 25, 2024
1 parent 0f238ed commit b72d09e
Show file tree
Hide file tree
Showing 20 changed files with 409 additions and 192 deletions.
2 changes: 1 addition & 1 deletion lib/app/shared/constants/parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Parameters {

// 'false' for talao
// 'true' for altme
static const bool importAtOnboarding = true;
static const bool importAndRestoreAtOnboarding = true;

// false for talao
// 'true' for altme
Expand Down
1 change: 1 addition & 0 deletions lib/app/shared/enum/type/restore_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enum RestoreType { cryptoWallet, appBackup }
1 change: 1 addition & 0 deletions lib/app/shared/enum/type/type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export 'message_type/message_type.dart';
export 'oidc4vc_type.dart';
export 'profile/did_key_type.dart';
export 'profile/profile.dart';
export 'restore_type.dart';
export 'wallet_protection_type.dart';
export 'wallet_provider_type.dart';
export 'wallet_route_type.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class BackupCredentialView extends StatelessWidget {
),
const SizedBox(height: Sizes.spaceXLarge),
Text(
Parameters.importAtOnboarding
Parameters.importAndRestoreAtOnboarding
? l10n.saveBackupCredentialSubtitle
: l10n.saveBackupCredentialSubtitle2,
textAlign: TextAlign.center,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class RestoreCredentialCubit extends Cubit<RestoreCredentialState> {

late String stringForBackup;

if (Parameters.importAtOnboarding) {
if (Parameters.importAndRestoreAtOnboarding) {
final String? recoveryMnemonic = await secureStorageProvider
.get(SecureStorageKeys.recoverCredentialMnemonics);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,111 +72,133 @@ class _RestoreCredentialViewState extends State<RestoreCredentialView> {
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
return BasePage(
title: l10n.restoreCredential,
titleAlignment: Alignment.topCenter,
padding: const EdgeInsets.only(
top: 0,
left: Sizes.spaceSmall,
right: Sizes.spaceSmall,
bottom: Sizes.spaceSmall,
),
titleLeading: widget.fromOnBoarding
? null
: BackLeadingButton(
onPressed: () {
if (context.read<RestoreCredentialCubit>().state.status !=
AppStatus.loading) {
Navigator.of(context).pop();
}
},
),
body: BlocConsumer<RestoreCredentialCubit, RestoreCredentialState>(
listener: (context, state) async {
if (state.status == AppStatus.loading) {
LoadingView().show(context: context);
} else {
LoadingView().hide();
}

if (state.status == AppStatus.success &&
state.recoveredCredentialLength != null) {
final credentialLength = state.recoveredCredentialLength;
AlertMessage.showStateMessage(
context: context,
stateMessage: StateMessage.success(
stringMessage: l10n.recoveryCredentialSuccessMessage(
'''$credentialLength ${credentialLength! > 1 ? '${l10n.credential}s' : l10n.credential}''',
),
return WillPopScope(
onWillPop: () async => false,
child: BasePage(
title: l10n.restoreCredential,
titleAlignment: Alignment.topCenter,
padding: const EdgeInsets.only(
top: 0,
left: Sizes.spaceSmall,
right: Sizes.spaceSmall,
bottom: Sizes.spaceSmall,
),
titleLeading: widget.fromOnBoarding
? null
: BackLeadingButton(
onPressed: () {
if (context.read<RestoreCredentialCubit>().state.status !=
AppStatus.loading) {
Navigator.of(context).pop();
}
},
),
);
await Future<void>.delayed(const Duration(milliseconds: 800));
Navigator.of(context).pop();
Navigator.of(context).pop();
}

if (state.status == AppStatus.restoreWallet) {
await Navigator.pushAndRemoveUntil<void>(
context,
WalletReadyPage.route(),
(Route<dynamic> route) => route.isFirst,
);
}
body: BlocConsumer<RestoreCredentialCubit, RestoreCredentialState>(
listener: (context, state) async {
if (state.status == AppStatus.loading) {
LoadingView().show(context: context);
} else {
LoadingView().hide();
}

if (state.message != null) {
AlertMessage.showStateMessage(
context: context,
stateMessage: state.message!,
if (state.status == AppStatus.success &&
state.recoveredCredentialLength != null) {
final credentialLength = state.recoveredCredentialLength;
AlertMessage.showStateMessage(
context: context,
stateMessage: StateMessage.success(
stringMessage: l10n.recoveryCredentialSuccessMessage(
'''$credentialLength ${credentialLength! > 1 ? '${l10n.credential}s' : l10n.credential}''',
),
),
);
await Future<void>.delayed(const Duration(milliseconds: 800));
Navigator.of(context).pop();
Navigator.of(context).pop();
}

if (state.status == AppStatus.restoreWallet) {
await Navigator.pushAndRemoveUntil<void>(
context,
WalletReadyPage.route(),
(Route<dynamic> route) => route.isFirst,
);
}

if (state.message != null) {
AlertMessage.showStateMessage(
context: context,
stateMessage: state.message!,
);
}
},
builder: (context, state) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
const MStepper(
totalStep: 2,
step: 2,
),
const SizedBox(
height: Sizes.spaceNormal,
),
Text(
l10n.restoreCredentialStep2Title,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.labelMedium,
),
const SizedBox(
height: Sizes.spaceNormal,
),
UploadFile(
filePath: state.backupFilePath,
onTap: () async {
if (isAndroid) {
final appDir = (await getTemporaryDirectory()).path;
await Directory(appDir).delete(recursive: true);
}
await _pickRestoreFile();
},
),
],
);
}
},
builder: (context, state) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
const MStepper(
totalStep: 2,
step: 2,
),
const SizedBox(
height: Sizes.spaceNormal,
),
Text(
l10n.restoreCredentialStep2Title,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.labelMedium,
),
const SizedBox(
height: Sizes.spaceNormal,
},
),
navigation: Padding(
padding: const EdgeInsets.all(Sizes.spaceSmall),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
BlocBuilder<RestoreCredentialCubit, RestoreCredentialState>(
builder: (context, state) {
return MyElevatedButton(
onPressed: state.backupFilePath == null
? null
: () => context
.read<RestoreCredentialCubit>()
.recoverWallet(
isFromOnBoarding: widget.fromOnBoarding,
),
text: l10n.loadFile,
);
},
),
UploadFile(
filePath: state.backupFilePath,
onTap: () async {
if (isAndroid) {
final appDir = (await getTemporaryDirectory()).path;
await Directory(appDir).delete(recursive: true);
}
await _pickRestoreFile();
const SizedBox(height: 5),
MyOutlinedButton(
text: l10n.skip,
onPressed: () {
Navigator.pushAndRemoveUntil<void>(
context,
WalletReadyPage.route(),
(Route<dynamic> route) => route.isFirst,
);
},
),
],
);
},
),
navigation: Padding(
padding: const EdgeInsets.all(Sizes.spaceSmall),
child: BlocBuilder<RestoreCredentialCubit, RestoreCredentialState>(
builder: (context, state) {
return MyElevatedButton(
onPressed: state.backupFilePath == null
? null
: () => context.read<RestoreCredentialCubit>().recoverWallet(
isFromOnBoarding: widget.fromOnBoarding,
),
text: l10n.loadFile,
);
},
),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class WalletSecurityView extends StatelessWidget {
),
DrawerItem(
title: l10n.showWalletRecoveryPhrase,
subtitle: Parameters.importAtOnboarding
subtitle: Parameters.importAndRestoreAtOnboarding
? l10n.showWalletRecoveryPhraseSubtitle
: l10n.showWalletRecoveryPhraseSubtitle2,
onTap: () async {
Expand Down Expand Up @@ -117,44 +117,43 @@ class WalletSecurityView extends StatelessWidget {
);
},
),
if (Parameters.importAtOnboarding)
DrawerItem(
title: l10n.restore,
onTap: () async {
final confirm = await showDialog<bool>(
context: context,
builder: (context) => ConfirmDialog(
title: l10n.warningDialogTitle,
subtitle:
l10n.restorationCredentialWarningDialogSubtitle,
yes: l10n.showDialogYes,
no: l10n.showDialogNo,
),
) ??
false;
// DrawerItem(
// title: l10n.restore,
// onTap: () async {
// final confirm = await showDialog<bool>(
// context: context,
// builder: (context) => ConfirmDialog(
// title: l10n.warningDialogTitle,
// subtitle:
// l10n.restorationCredentialWarningDialogSubtitle,
// yes: l10n.showDialogYes,
// no: l10n.showDialogNo,
// ),
// ) ??
// false;

if (confirm) {
await securityCheck(
context: context,
localAuthApi: LocalAuthApi(),
onSuccess: () {
Navigator.of(context).push<void>(
RestoreCredentialMnemonicPage.route(
title: l10n.restoreCredential,
isValidCallback: () {
Navigator.of(context).push<void>(
RestoreCredentialPage.route(
fromOnBoarding: false,
),
);
},
),
);
},
);
}
},
),
// if (confirm) {
// await securityCheck(
// context: context,
// localAuthApi: LocalAuthApi(),
// onSuccess: () {
// Navigator.of(context).push<void>(
// RestoreCredentialMnemonicPage.route(
// title: l10n.restoreCredential,
// isValidCallback: () {
// Navigator.of(context).push<void>(
// RestoreCredentialPage.route(
// fromOnBoarding: false,
// ),
// );
// },
// ),
// );
// },
// );
// }
// },
// ),
],
),
);
Expand Down
4 changes: 3 additions & 1 deletion lib/import_wallet/cubit/import_wallet_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ class ImportWalletCubit extends Cubit<ImportWalletState> {

Future<void> import({
required String mnemonicOrKey,
required bool isFromOnboarding,
required RestoreType? restoreType,
String? accountName,
}) async {
final log = getLogger('ImportWalletCubit - import');
emit(state.loading());
await Future<void>.delayed(const Duration(milliseconds: 500));

final isFromOnboarding = restoreType != null;

try {
log.i('isFromOnboarding: $isFromOnboarding');
if (isFromOnboarding) {
Expand Down
Loading

0 comments on commit b72d09e

Please sign in to comment.