gecko/lib/screens/myWallets/restore_chest.dart

242 lines
9.2 KiB
Dart
Raw Normal View History

2023-02-01 22:25:26 +01:00
// ignore_for_file: use_build_context_synchronously
2021-11-21 06:36:12 +01:00
import 'package:bubble/bubble.dart';
2022-06-18 00:48:07 +02:00
import 'package:easy_localization/easy_localization.dart';
2021-11-21 06:36:12 +01:00
import 'package:gecko/globals.dart';
import 'package:flutter/material.dart';
import 'package:gecko/models/scale_functions.dart';
import 'package:gecko/models/widgets_keys.dart';
import 'package:gecko/providers/generate_wallets.dart';
2022-05-21 06:47:26 +02:00
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:gecko/screens/onBoarding/7.dart';
2022-05-23 10:53:44 +02:00
import 'package:gecko/screens/onBoarding/9.dart';
2022-12-10 08:16:38 +01:00
import 'package:gecko/widgets/commons/fader_transition.dart';
import 'package:gecko/widgets/commons/offline_info.dart';
import 'package:gecko/widgets/commons/top_appbar.dart';
2021-11-21 06:36:12 +01:00
import 'package:provider/provider.dart';
// import 'package:gecko/models/home.dart';
// import 'package:provider/provider.dart';
class RestoreChest extends StatelessWidget {
const RestoreChest({Key? key, this.skipIntro = false}) : super(key: key);
final bool skipIntro;
2021-11-21 06:36:12 +01:00
@override
Widget build(BuildContext context) {
final genW = Provider.of<GenerateWalletsProvider>(context, listen: false);
final sub = Provider.of<SubstrateSdk>(context, listen: false);
2021-11-21 06:36:12 +01:00
2022-05-21 06:47:26 +02:00
if (genW.isSentenceComplete(context)) {
genW.generatedMnemonic =
'${genW.cellController0.text} ${genW.cellController1.text} ${genW.cellController2.text} ${genW.cellController3.text} ${genW.cellController4.text} ${genW.cellController5.text} ${genW.cellController6.text} ${genW.cellController7.text} ${genW.cellController8.text} ${genW.cellController9.text} ${genW.cellController10.text} ${genW.cellController11.text}';
}
2021-11-22 03:54:22 +01:00
return PopScope(
onPopInvoked: (_) {
2022-05-21 06:47:26 +02:00
genW.resetImportView();
2021-11-21 06:36:12 +01:00
},
child: Scaffold(
2022-05-29 00:00:57 +02:00
backgroundColor: backgroundColor,
appBar: GeckoAppBar('restoreAChest'.tr()),
2021-11-21 06:36:12 +01:00
body: SafeArea(
child: Stack(children: [
2021-11-21 06:36:12 +01:00
Column(children: <Widget>[
ScaledSizedBox(height: isTall ? 20 : 3),
bubbleSpeak('toRestoreEnterMnemonic'.tr()),
ScaledSizedBox(height: isTall ? 20 : 5),
Column(children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
arrayCell(context, genW.cellController0),
arrayCell(context, genW.cellController1),
arrayCell(context, genW.cellController2),
arrayCell(context, genW.cellController3),
]),
ScaledSizedBox(height: isTall ? 10 : 3),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
arrayCell(context, genW.cellController4),
arrayCell(context, genW.cellController5),
arrayCell(context, genW.cellController6),
arrayCell(context, genW.cellController7),
]),
ScaledSizedBox(height: isTall ? 10 : 3),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
arrayCell(context, genW.cellController8),
arrayCell(context, genW.cellController9),
arrayCell(context, genW.cellController10),
arrayCell(context, genW.cellController11),
]),
]),
// const Spacer(),
if (genW.isSentenceComplete(context))
Expanded(
child: Align(
alignment: Alignment.center,
child: ScaledSizedBox(
width: 340,
height: 55,
child: ElevatedButton(
key: keyGoNext,
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
elevation: 4,
backgroundColor: orangeC,
),
onPressed: () async {
if (await sub
.isMnemonicValid(genW.generatedMnemonic!)) {
genW.resetImportView();
await Navigator.push(
context,
FaderTransition(
page: skipIntro
? const OnboardingStepNine(
scanDerivation: true)
: const OnboardingStepSeven(
scanDerivation: true),
isFast: true),
);
} else {
await badMnemonicPopup(context);
}
},
child: Text(
'restoreThisChest'.tr(),
style: scaledTextStyle(
2024-01-07 17:11:45 +01:00
fontSize: 19,
fontWeight: FontWeight.w600,
color: Colors.white),
),
),
),
// SizedBox(height: isTall ? 80 : 80),
))
else
Column(children: [
ScaledSizedBox(height: 20),
ScaledSizedBox(
width: 210,
height: 55,
child: ElevatedButton(
key: keyPastMnemonic,
style: ElevatedButton.styleFrom(
foregroundColor: Colors.black,
elevation: 4,
backgroundColor: yellowC,
),
onPressed: () {
genW.pasteMnemonic(context);
},
child: Row(
2023-11-17 14:16:01 +01:00
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Icon(
Icons.content_paste_go,
size: scaleSize(28),
),
Text(
'pasteFromClipboard'.tr(),
textAlign: TextAlign.center,
style: scaledTextStyle(
fontSize: 16, fontWeight: FontWeight.w400),
),
],
)),
)
])
]),
2022-12-10 08:16:38 +01:00
const OfflineInfo(),
2021-11-21 06:36:12 +01:00
]),
),
),
);
}
Widget bubbleSpeak(String text) {
return Bubble(
margin: const BubbleEdges.symmetric(horizontal: 20),
padding: BubbleEdges.all(scaleSize(15)),
2021-11-21 06:36:12 +01:00
borderWidth: 1,
borderColor: Colors.black,
radius: Radius.zero,
color: Colors.white,
child: Text(
text,
key: keyBubbleSpeak,
2021-11-21 06:36:12 +01:00
textAlign: TextAlign.justify,
style: scaledTextStyle(
color: Colors.black, fontSize: 17, fontWeight: FontWeight.w400),
2021-11-21 06:36:12 +01:00
),
);
}
2024-01-04 01:37:33 +01:00
Widget arrayCell(BuildContext context, final cellCtl) {
final generateWalletProvider =
2021-11-21 06:36:12 +01:00
Provider.of<GenerateWalletsProvider>(context);
return Container(
width: scaleSize(87),
height: scaleSize(37),
// ),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
color: Colors.white,
borderRadius: BorderRadius.circular(3),
),
// child: RawKeyboardListener(
// focusNode: FocusNode(), // or FocusNode()
// onKey: (event) {
// if (event.logicalKey == LogicalKeyboardKey.space) {
// FocusScope.of(context).nextFocus();
// }
// },
2021-11-21 06:36:12 +01:00
child: TextField(
autofocus: true,
controller: cellCtl,
textInputAction: TextInputAction.next,
onChanged: (v) {
if (v.contains(' ')) {
cellCtl.text = cellCtl.text.replaceAll(' ', '');
FocusScope.of(context).nextFocus();
}
2021-11-21 06:36:12 +01:00
bool isValid = generateWalletProvider.isBipWord(v);
if (isValid) cellCtl.text = cellCtl.text.toLowerCase();
2021-11-21 06:36:12 +01:00
if (isValid && generateWalletProvider.cellController11.text.isEmpty) {
FocusScope.of(context).nextFocus();
}
},
textAlign: TextAlign.center,
style: scaledTextStyle(fontSize: 17),
2021-11-21 06:36:12 +01:00
),
);
}
2021-12-23 12:36:09 +01:00
Future<bool?> badMnemonicPopup(BuildContext context) async {
2021-11-21 06:36:12 +01:00
return showDialog<bool>(
context: context,
barrierDismissible: true,
2021-11-21 06:36:12 +01:00
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Phrase incorrecte'),
content: const Text(
2022-05-21 06:47:26 +02:00
'Votre phrase de restauration semble incorrecte, les mots ne sont pas dans le bon ordre.\nVeuillez la corriger.'),
2021-11-21 06:36:12 +01:00
actions: <Widget>[
TextButton(
child: const Text("OK"),
onPressed: () {
Navigator.pop(context);
},
),
],
);
},
);
}
}