2021-11-14 19:21:20 +01:00
|
|
|
// ignore_for_file: file_names
|
|
|
|
|
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';
|
2021-03-02 07:05:47 +01:00
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
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-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
|
|
|
|
|
|
|
// ignore: must_be_immutable
|
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;
|
2021-11-14 19:21:20 +01:00
|
|
|
|
2021-03-02 07:05:47 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
2022-05-23 10:53:44 +02:00
|
|
|
GenerateWalletsProvider _generateWalletProvider =
|
|
|
|
Provider.of<GenerateWalletsProvider>(context);
|
|
|
|
WalletOptionsProvider _walletOptions =
|
|
|
|
Provider.of<WalletOptionsProvider>(context);
|
2021-03-02 07:05:47 +01:00
|
|
|
CommonElements common = CommonElements();
|
2022-05-23 10:53:44 +02:00
|
|
|
final int _pinLenght = _generateWalletProvider.pin.text.length;
|
2021-03-08 17:23:56 +01:00
|
|
|
|
2021-03-02 07:05:47 +01:00
|
|
|
return Scaffold(
|
2022-05-29 00:00:57 +02:00
|
|
|
backgroundColor: backgroundColor,
|
2022-05-23 10:53:44 +02:00
|
|
|
appBar: AppBar(
|
|
|
|
toolbarHeight: 60 * ratio,
|
2022-06-17 23:10:01 +02:00
|
|
|
title: SizedBox(
|
2022-05-23 10:53:44 +02:00
|
|
|
height: 22,
|
|
|
|
child: Text(
|
2022-06-17 23:10:01 +02:00
|
|
|
'myPassword'.tr(),
|
|
|
|
style: const TextStyle(fontWeight: FontWeight.w600),
|
2022-05-23 10:53:44 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-03-02 07:05:47 +01:00
|
|
|
extendBodyBehindAppBar: true,
|
|
|
|
body: SafeArea(
|
|
|
|
child: Column(children: <Widget>[
|
2022-05-23 10:53:44 +02:00
|
|
|
SizedBox(height: isTall ? 40 : 20),
|
|
|
|
common.buildProgressBar(9),
|
|
|
|
SizedBox(height: isTall ? 40 : 20),
|
2022-06-18 00:48:07 +02:00
|
|
|
common.buildText("geckoWillCheckPassword".tr()),
|
2022-05-23 10:53:44 +02:00
|
|
|
SizedBox(height: isTall ? 80 : 20),
|
2022-06-07 21:36:57 +02:00
|
|
|
Visibility(
|
|
|
|
visible: _generateWalletProvider.scanedWalletNumber != -1,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(bottom: 15),
|
|
|
|
child: SizedBox(
|
|
|
|
height: 22,
|
|
|
|
width: 22,
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
color: orangeC,
|
|
|
|
strokeWidth: 3,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-06-12 19:20:15 +02:00
|
|
|
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,
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
}),
|
|
|
|
Consumer<SubstrateSdk>(builder: (context, _sub, _) {
|
|
|
|
return _sub.nodeConnected
|
|
|
|
? InkWell(
|
|
|
|
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),
|
|
|
|
Text(
|
2022-06-18 00:48:07 +02:00
|
|
|
'rememberPassword'.tr(),
|
2022-06-12 19:20:15 +02:00
|
|
|
style:
|
|
|
|
TextStyle(fontSize: 16, color: Colors.grey[700]),
|
|
|
|
),
|
|
|
|
const Spacer()
|
|
|
|
]))
|
|
|
|
: const Text('');
|
|
|
|
}),
|
2022-05-31 18:23:56 +02:00
|
|
|
const SizedBox(height: 10),
|
2021-03-02 07:05:47 +01:00
|
|
|
]),
|
|
|
|
));
|
|
|
|
}
|
2022-05-23 10:53:44 +02:00
|
|
|
|
|
|
|
Widget pinForm(context, WalletOptionsProvider _walletOptions, _pinLenght,
|
|
|
|
int _walletNbr, int _derivation) {
|
|
|
|
// var _walletPin = '';
|
|
|
|
// ignore: close_sinks
|
|
|
|
StreamController<ErrorAnimationType> errorController =
|
|
|
|
StreamController<ErrorAnimationType>();
|
|
|
|
TextEditingController _enterPin = TextEditingController();
|
|
|
|
MyWalletsProvider _myWalletProvider =
|
|
|
|
Provider.of<MyWalletsProvider>(context);
|
|
|
|
GenerateWalletsProvider _generateWalletProvider =
|
|
|
|
Provider.of<GenerateWalletsProvider>(context);
|
|
|
|
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
|
|
|
|
|
|
|
|
final int? _currentChest = _myWalletProvider.getCurrentChest();
|
|
|
|
|
|
|
|
return Form(
|
|
|
|
key: formKey,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 30),
|
|
|
|
child: PinCodeTextField(
|
|
|
|
key: const Key('formKey2'),
|
|
|
|
autoFocus: true,
|
|
|
|
appContext: context,
|
|
|
|
pastedTextStyle: TextStyle(
|
|
|
|
color: Colors.green.shade600,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
length: _pinLenght,
|
|
|
|
obscureText: true,
|
|
|
|
obscuringCharacter: '*',
|
|
|
|
animationType: AnimationType.fade,
|
|
|
|
validator: (v) {
|
|
|
|
if (v!.length < _pinLenght) {
|
2022-06-18 03:21:54 +02:00
|
|
|
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),
|
|
|
|
fieldHeight: 60,
|
|
|
|
fieldWidth: 50,
|
|
|
|
activeFillColor: hasError ? Colors.blueAccent : Colors.black,
|
|
|
|
),
|
|
|
|
cursorColor: Colors.black,
|
|
|
|
animationDuration: const Duration(milliseconds: 300),
|
|
|
|
textStyle: const TextStyle(fontSize: 20, height: 1.6),
|
|
|
|
backgroundColor: const Color(0xffF9F9F1),
|
|
|
|
enableActiveFill: false,
|
|
|
|
errorAnimationController: errorController,
|
|
|
|
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,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
onCompleted: (_pin) async {
|
|
|
|
_myWalletProvider.pinCode = _pin.toUpperCase();
|
|
|
|
_myWalletProvider.pinLenght = _pinLenght;
|
|
|
|
log.d(_pin + ' || ' + _generateWalletProvider.pin.text);
|
|
|
|
if (_pin.toUpperCase() == _generateWalletProvider.pin.text) {
|
|
|
|
pinColor = Colors.green[500];
|
2022-06-07 21:36:57 +02:00
|
|
|
|
|
|
|
await _generateWalletProvider.storeHDWChest(context);
|
|
|
|
bool isAlive = false;
|
|
|
|
if (scanDerivation) {
|
|
|
|
isAlive = await _generateWalletProvider
|
2022-06-07 22:16:56 +02:00
|
|
|
.scanDerivations(context, numberScan: 20);
|
2022-06-07 21:36:57 +02:00
|
|
|
}
|
|
|
|
if (!isAlive) {
|
|
|
|
final address = await _sub.importAccount(
|
|
|
|
fromMnemonic: true,
|
|
|
|
mnemonic: _generateWalletProvider.generatedMnemonic!,
|
|
|
|
derivePath: '//2',
|
|
|
|
password: _generateWalletProvider.pin.text);
|
|
|
|
WalletData myWallet = WalletData(
|
|
|
|
version: dataVersion,
|
|
|
|
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,
|
|
|
|
imageDefaultPath: '0.png');
|
|
|
|
await walletBox.add(myWallet);
|
|
|
|
}
|
2022-05-23 10:53:44 +02:00
|
|
|
_myWalletProvider.readAllWallets(_currentChest);
|
|
|
|
_myWalletProvider.rebuildWidget();
|
2022-06-07 01:10:40 +02:00
|
|
|
|
2022-05-23 10:53:44 +02:00
|
|
|
_generateWalletProvider.generatedMnemonic = '';
|
2022-05-31 18:23:56 +02:00
|
|
|
_myWalletProvider.resetPinCode();
|
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 {
|
|
|
|
errorController.add(ErrorAnimationType
|
|
|
|
.shake); // Triggering error shake animation
|
|
|
|
hasError = true;
|
|
|
|
pinColor = Colors.red[600];
|
|
|
|
_walletOptions.reloadBuild();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onChanged: (value) {
|
|
|
|
if (pinColor != const Color(0xFFA4B600)) {
|
|
|
|
pinColor = const Color(0xFFA4B600);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
2021-03-02 07:05:47 +01:00
|
|
|
}
|