2021-11-14 19:21:20 +01:00
|
|
|
// ignore_for_file: file_names
|
2022-09-05 04:15:27 +02:00
|
|
|
// ignore_for_file: must_be_immutable
|
2021-11-14 19:21:20 +01:00
|
|
|
|
2022-05-23 10:53:44 +02:00
|
|
|
import 'dart:async';
|
2022-06-17 01:13:14 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-08-22 22:58:54 +02:00
|
|
|
import 'package:flutter/foundation.dart';
|
2022-11-30 05:22:37 +01:00
|
|
|
|
2021-03-02 07:05:47 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2021-03-08 00:32:18 +01:00
|
|
|
import 'package:gecko/globals.dart';
|
2022-06-07 21:36:57 +02:00
|
|
|
import 'package:gecko/models/wallet_data.dart';
|
2022-08-22 22:58:54 +02:00
|
|
|
import 'package:gecko/models/widgets_keys.dart';
|
2022-05-23 10:53:44 +02:00
|
|
|
import 'package:gecko/providers/generate_wallets.dart';
|
|
|
|
import 'package:gecko/providers/my_wallets.dart';
|
|
|
|
import 'package:gecko/providers/substrate_sdk.dart';
|
|
|
|
import 'package:gecko/providers/wallet_options.dart';
|
2021-11-14 19:21:20 +01:00
|
|
|
import 'package:gecko/screens/common_elements.dart';
|
2022-05-23 10:53:44 +02:00
|
|
|
import 'package:gecko/screens/onBoarding/11_congratulations.dart';
|
|
|
|
import 'package:pin_code_fields/pin_code_fields.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2021-03-02 07:05:47 +01:00
|
|
|
|
2022-05-25 20:40:25 +02:00
|
|
|
class OnboardingStepTen extends StatelessWidget {
|
2022-06-07 01:10:40 +02:00
|
|
|
OnboardingStepTen({Key? validationKey, this.scanDerivation = false})
|
|
|
|
: super(key: validationKey);
|
2021-03-02 07:05:47 +01:00
|
|
|
|
2022-06-07 01:10:40 +02:00
|
|
|
final bool scanDerivation;
|
2022-05-23 10:53:44 +02:00
|
|
|
final formKey = GlobalKey<FormState>();
|
|
|
|
Color? pinColor = const Color(0xFFA4B600);
|
|
|
|
bool hasError = false;
|
2022-12-05 14:49:32 +01:00
|
|
|
TextEditingController enterPin = TextEditingController();
|
|
|
|
FocusNode pinFocus = FocusNode(debugLabel: 'pinFocusNode');
|
2021-11-14 19:21:20 +01:00
|
|
|
|
2021-03-02 07:05:47 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-11-30 05:42:08 +01:00
|
|
|
final generateWalletProvider =
|
2022-05-23 10:53:44 +02:00
|
|
|
Provider.of<GenerateWalletsProvider>(context);
|
2022-11-30 05:42:08 +01:00
|
|
|
final walletOptions = Provider.of<WalletOptionsProvider>(context);
|
2022-12-07 23:10:28 +01:00
|
|
|
final sub = Provider.of<SubstrateSdk>(context);
|
2022-12-05 14:49:32 +01:00
|
|
|
final myWalletProvider =
|
|
|
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
2021-03-02 07:05:47 +01:00
|
|
|
CommonElements common = CommonElements();
|
2022-12-02 10:23:21 +01:00
|
|
|
final pinLenght = generateWalletProvider.pin.text.length;
|
2021-03-08 17:23:56 +01:00
|
|
|
|
2022-12-05 14:49:32 +01:00
|
|
|
return WillPopScope(
|
|
|
|
onWillPop: () {
|
|
|
|
myWalletProvider.isPinValid = false;
|
|
|
|
myWalletProvider.isPinLoading = true;
|
|
|
|
return Future<bool>.value(true);
|
|
|
|
},
|
|
|
|
child: Scaffold(
|
|
|
|
backgroundColor: backgroundColor,
|
|
|
|
appBar: AppBar(
|
|
|
|
toolbarHeight: 60 * ratio,
|
|
|
|
title: SizedBox(
|
|
|
|
height: 22,
|
|
|
|
child: Text(
|
|
|
|
'myPassword'.tr(),
|
|
|
|
style: const TextStyle(fontWeight: FontWeight.w600),
|
|
|
|
),
|
2022-05-23 10:53:44 +02:00
|
|
|
),
|
2022-12-05 14:49:32 +01:00
|
|
|
leading: IconButton(
|
|
|
|
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
|
|
|
onPressed: () {
|
|
|
|
myWalletProvider.isPinValid = false;
|
|
|
|
myWalletProvider.isPinLoading = true;
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
}),
|
2022-05-23 10:53:44 +02:00
|
|
|
),
|
2022-12-05 14:49:32 +01:00
|
|
|
extendBodyBehindAppBar: true,
|
|
|
|
body: SafeArea(
|
|
|
|
child: Stack(children: [
|
|
|
|
Column(children: <Widget>[
|
|
|
|
SizedBox(height: isTall ? 40 : 20),
|
|
|
|
common.buildProgressBar(9),
|
|
|
|
SizedBox(height: isTall ? 40 : 20),
|
|
|
|
common.buildText("geckoWillCheckPassword".tr()),
|
|
|
|
SizedBox(height: isTall ? 60 : 10),
|
|
|
|
Visibility(
|
|
|
|
visible: generateWalletProvider.scanedValidWalletNumber != -1,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(bottom: 15),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text("derivationsScanProgress".tr(args: [
|
|
|
|
'${generateWalletProvider.scanedWalletNumber}',
|
|
|
|
'${generateWalletProvider.numberScan + 1}'
|
|
|
|
])),
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
const SizedBox(
|
|
|
|
height: 22,
|
|
|
|
width: 22,
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
color: orangeC,
|
|
|
|
strokeWidth: 3,
|
|
|
|
),
|
2022-08-17 23:01:20 +02:00
|
|
|
),
|
2022-12-05 14:49:32 +01:00
|
|
|
],
|
|
|
|
),
|
2022-08-17 23:01:20 +02:00
|
|
|
),
|
2022-06-07 21:36:57 +02:00
|
|
|
),
|
2022-12-05 14:49:32 +01:00
|
|
|
Consumer<MyWalletsProvider>(builder: (context, mw, _) {
|
|
|
|
return Visibility(
|
|
|
|
visible: !myWalletProvider.isPinValid &&
|
|
|
|
!myWalletProvider.isPinLoading,
|
|
|
|
child: Text(
|
|
|
|
"Ce n'est pas le bon code".tr(),
|
|
|
|
style: const TextStyle(
|
|
|
|
color: Colors.red, fontWeight: FontWeight.w500),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
SizedBox(height: isTall ? 20 : 10),
|
|
|
|
Consumer<SubstrateSdk>(builder: (context, sub, _) {
|
|
|
|
return sub.nodeConnected
|
|
|
|
? pinForm(context, walletOptions, pinLenght, 1, 2)
|
|
|
|
: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: const [
|
|
|
|
Text(
|
|
|
|
'Vous devez vous connecter à internet\npour valider votre coffre',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20,
|
|
|
|
color: Colors.redAccent,
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
),
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
}),
|
2022-12-07 23:10:28 +01:00
|
|
|
Consumer<WalletOptionsProvider>(
|
|
|
|
builder: (context, walletOptions, _) {
|
2022-12-05 14:49:32 +01:00
|
|
|
return sub.nodeConnected
|
|
|
|
? InkWell(
|
|
|
|
key: keyCachePassword,
|
|
|
|
onTap: () {
|
|
|
|
walletOptions.changePinCacheChoice();
|
|
|
|
},
|
|
|
|
child: Row(children: [
|
|
|
|
const SizedBox(height: 30),
|
|
|
|
const Spacer(),
|
|
|
|
Icon(
|
|
|
|
configBox.get('isCacheChecked') ?? false
|
|
|
|
? Icons.check_box
|
|
|
|
: Icons.check_box_outline_blank,
|
|
|
|
color: orangeC,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 8),
|
2022-08-17 23:01:20 +02:00
|
|
|
Text(
|
2022-12-05 14:49:32 +01:00
|
|
|
'rememberPassword'.tr(),
|
2022-08-17 23:01:20 +02:00
|
|
|
style: TextStyle(
|
2022-12-05 14:49:32 +01:00
|
|
|
fontSize: 16, color: Colors.grey[700]),
|
2022-08-17 23:01:20 +02:00
|
|
|
),
|
2022-12-05 14:49:32 +01:00
|
|
|
const Spacer()
|
|
|
|
]))
|
|
|
|
: const Text('');
|
|
|
|
}),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
]),
|
|
|
|
CommonElements().offlineInfo(context),
|
2022-08-17 23:01:20 +02:00
|
|
|
]),
|
2022-12-05 14:49:32 +01:00
|
|
|
)),
|
|
|
|
);
|
2021-03-02 07:05:47 +01:00
|
|
|
}
|
2022-05-23 10:53:44 +02:00
|
|
|
|
2022-11-30 05:42:08 +01:00
|
|
|
Widget pinForm(
|
|
|
|
context, final walletOptions, pinLenght, int walletNbr, int derivation) {
|
|
|
|
final myWalletProvider = Provider.of<MyWalletsProvider>(context);
|
|
|
|
final generateWalletProvider =
|
2022-05-23 10:53:44 +02:00
|
|
|
Provider.of<GenerateWalletsProvider>(context);
|
2022-11-30 05:42:08 +01:00
|
|
|
final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
2022-05-23 10:53:44 +02:00
|
|
|
|
2022-12-02 10:23:21 +01:00
|
|
|
final currentChest = myWalletProvider.getCurrentChest();
|
2022-05-23 10:53:44 +02:00
|
|
|
|
|
|
|
return Form(
|
|
|
|
key: formKey,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 30),
|
|
|
|
child: PinCodeTextField(
|
2022-08-22 22:58:54 +02:00
|
|
|
key: keyPinForm,
|
2022-12-05 14:49:32 +01:00
|
|
|
textCapitalization: TextCapitalization.characters,
|
|
|
|
// autoDisposeControllers: false,
|
|
|
|
focusNode: pinFocus,
|
2022-05-23 10:53:44 +02:00
|
|
|
autoFocus: true,
|
|
|
|
appContext: context,
|
|
|
|
pastedTextStyle: TextStyle(
|
|
|
|
color: Colors.green.shade600,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-08-06 02:22:41 +02:00
|
|
|
length: pinLenght,
|
2022-05-23 10:53:44 +02:00
|
|
|
obscureText: true,
|
|
|
|
obscuringCharacter: '*',
|
2022-12-05 14:49:32 +01:00
|
|
|
animationType: AnimationType.slide,
|
2022-12-07 23:10:28 +01:00
|
|
|
animationDuration: const Duration(milliseconds: 40),
|
2022-05-23 10:53:44 +02:00
|
|
|
validator: (v) {
|
2022-08-06 02:22:41 +02:00
|
|
|
if (v!.length < pinLenght) {
|
|
|
|
return "yourPasswordLengthIsX".tr(args: [pinLenght.toString()]);
|
2022-05-23 10:53:44 +02:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
pinTheme: PinTheme(
|
|
|
|
activeColor: pinColor,
|
|
|
|
borderWidth: 4,
|
|
|
|
shape: PinCodeFieldShape.box,
|
|
|
|
borderRadius: BorderRadius.circular(5),
|
2022-12-05 14:49:32 +01:00
|
|
|
fieldHeight: 50 * ratio,
|
2022-05-23 10:53:44 +02:00
|
|
|
fieldWidth: 50,
|
2022-12-05 14:49:32 +01:00
|
|
|
activeFillColor: Colors.black,
|
2022-05-23 10:53:44 +02:00
|
|
|
),
|
2022-08-22 22:58:54 +02:00
|
|
|
showCursor: kDebugMode ? false : true,
|
2022-05-23 10:53:44 +02:00
|
|
|
cursorColor: Colors.black,
|
2022-12-05 14:49:32 +01:00
|
|
|
textStyle: const TextStyle(fontSize: 27, height: 1.6),
|
2022-05-23 10:53:44 +02:00
|
|
|
backgroundColor: const Color(0xffF9F9F1),
|
|
|
|
enableActiveFill: false,
|
2022-08-06 02:22:41 +02:00
|
|
|
controller: enterPin,
|
2022-05-28 19:13:30 +02:00
|
|
|
keyboardType: TextInputType.visiblePassword,
|
2022-05-23 10:53:44 +02:00
|
|
|
boxShadows: const [
|
|
|
|
BoxShadow(
|
|
|
|
offset: Offset(0, 1),
|
|
|
|
color: Colors.black12,
|
|
|
|
blurRadius: 10,
|
|
|
|
)
|
|
|
|
],
|
2022-08-06 02:22:41 +02:00
|
|
|
onCompleted: (pin) async {
|
|
|
|
myWalletProvider.pinCode = pin.toUpperCase();
|
|
|
|
myWalletProvider.pinLenght = pinLenght;
|
|
|
|
log.d('$pin || ${generateWalletProvider.pin.text}');
|
|
|
|
if (pin.toUpperCase() == generateWalletProvider.pin.text) {
|
2022-05-23 10:53:44 +02:00
|
|
|
pinColor = Colors.green[500];
|
2022-12-05 14:49:32 +01:00
|
|
|
myWalletProvider.isPinLoading = false;
|
|
|
|
myWalletProvider.isPinValid = true;
|
2022-06-07 21:36:57 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
await generateWalletProvider.storeHDWChest(context);
|
2022-06-07 21:36:57 +02:00
|
|
|
bool isAlive = false;
|
|
|
|
if (scanDerivation) {
|
2022-08-15 12:58:47 +02:00
|
|
|
isAlive =
|
|
|
|
await generateWalletProvider.scanDerivations(context);
|
2022-06-07 21:36:57 +02:00
|
|
|
}
|
|
|
|
if (!isAlive) {
|
2022-08-06 02:22:41 +02:00
|
|
|
final address = await sub.importAccount(
|
|
|
|
mnemonic: generateWalletProvider.generatedMnemonic!,
|
2022-06-07 21:36:57 +02:00
|
|
|
derivePath: '//2',
|
2022-08-06 02:22:41 +02:00
|
|
|
password: generateWalletProvider.pin.text);
|
2022-06-07 21:36:57 +02:00
|
|
|
WalletData myWallet = WalletData(
|
|
|
|
chest: configBox.get('currentChest'),
|
|
|
|
address: address,
|
|
|
|
number: 0,
|
2022-06-17 01:13:14 +02:00
|
|
|
name: 'currentWallet'.tr(),
|
2022-06-07 21:36:57 +02:00
|
|
|
derivation: 2,
|
2022-12-07 23:10:28 +01:00
|
|
|
imageDefaultPath: '0.png',
|
|
|
|
isOwned: true);
|
|
|
|
await walletBox.put(myWallet.address, myWallet);
|
2022-06-07 21:36:57 +02:00
|
|
|
}
|
2022-08-06 02:22:41 +02:00
|
|
|
myWalletProvider.readAllWallets(currentChest);
|
2022-09-09 01:12:17 +02:00
|
|
|
myWalletProvider.reload();
|
2022-06-07 01:10:40 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
generateWalletProvider.generatedMnemonic = '';
|
|
|
|
myWalletProvider.resetPinCode();
|
2022-09-01 04:51:51 +02:00
|
|
|
// sleep(const Duration(milliseconds: 500));
|
2022-05-23 10:53:44 +02:00
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
FaderTransition(
|
2022-05-25 20:40:25 +02:00
|
|
|
page: const OnboardingStepEleven(), isFast: false),
|
2022-05-23 10:53:44 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
hasError = true;
|
2022-12-05 14:49:32 +01:00
|
|
|
myWalletProvider.isPinLoading = false;
|
|
|
|
myWalletProvider.isPinValid = false;
|
2022-05-23 10:53:44 +02:00
|
|
|
pinColor = Colors.red[600];
|
2022-12-05 14:49:32 +01:00
|
|
|
enterPin.text = '';
|
|
|
|
// myWalletProvider.reload();
|
|
|
|
pinFocus.requestFocus();
|
2022-05-23 10:53:44 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onChanged: (value) {
|
2022-12-05 14:49:32 +01:00
|
|
|
if (enterPin.text != '') myWalletProvider.isPinLoading = true;
|
2022-05-23 10:53:44 +02:00
|
|
|
if (pinColor != const Color(0xFFA4B600)) {
|
|
|
|
pinColor = const Color(0xFFA4B600);
|
|
|
|
}
|
2022-12-05 14:49:32 +01:00
|
|
|
myWalletProvider.reload();
|
2022-05-23 10:53:44 +02:00
|
|
|
},
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
2021-03-02 07:05:47 +01:00
|
|
|
}
|