2021-03-08 02:20:48 +01:00
|
|
|
import 'dart:async';
|
2022-06-17 01:13:14 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2021-03-08 02:20:48 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2021-11-15 00:39:40 +01:00
|
|
|
import 'package:gecko/models/chest_data.dart';
|
2022-05-19 07:00:25 +02:00
|
|
|
import 'package:gecko/providers/substrate_sdk.dart';
|
2021-12-23 15:13:58 +01:00
|
|
|
import 'package:gecko/providers/my_wallets.dart';
|
2021-11-14 19:21:20 +01:00
|
|
|
import 'package:gecko/models/wallet_data.dart';
|
2021-12-23 15:13:58 +01:00
|
|
|
import 'package:gecko/providers/wallet_options.dart';
|
2021-03-08 02:20:48 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2021-11-15 03:55:08 +01:00
|
|
|
import 'package:gecko/screens/myWallets/choose_chest.dart';
|
2021-03-08 02:20:48 +01:00
|
|
|
import 'package:pin_code_fields/pin_code_fields.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2021-04-02 12:05:37 +02:00
|
|
|
import 'package:gecko/globals.dart';
|
2021-03-08 02:20:48 +01:00
|
|
|
|
|
|
|
// ignore: must_be_immutable
|
|
|
|
class UnlockingWallet extends StatelessWidget {
|
2022-05-31 18:23:56 +02:00
|
|
|
UnlockingWallet({Key? keyUnlockWallet, required this.wallet})
|
2021-04-03 00:07:03 +02:00
|
|
|
: super(key: keyUnlockWallet);
|
2021-12-23 12:36:09 +01:00
|
|
|
WalletData? wallet;
|
2022-05-19 13:44:22 +02:00
|
|
|
late int currentChestNumber;
|
|
|
|
late ChestData currentChest;
|
2022-06-12 18:03:17 +02:00
|
|
|
bool canUnlock = true;
|
2021-03-08 02:20:48 +01:00
|
|
|
|
|
|
|
// ignore: close_sinks
|
2021-12-23 12:36:09 +01:00
|
|
|
StreamController<ErrorAnimationType>? errorController;
|
2021-03-08 02:20:48 +01:00
|
|
|
final formKey = GlobalKey<FormState>();
|
2021-12-23 12:36:09 +01:00
|
|
|
Color? pinColor = const Color(0xffF9F9F1);
|
2021-03-08 02:20:48 +01:00
|
|
|
var walletPin = '';
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
2022-08-06 02:22:41 +02:00
|
|
|
WalletOptionsProvider walletOptions =
|
2021-03-08 02:20:48 +01:00
|
|
|
Provider.of<WalletOptionsProvider>(context);
|
2022-05-19 07:00:25 +02:00
|
|
|
// final double statusBarHeight = MediaQuery.of(context).padding.top;
|
2021-04-03 02:39:09 +02:00
|
|
|
|
2022-05-19 13:44:22 +02:00
|
|
|
currentChestNumber = configBox.get('currentChest');
|
|
|
|
currentChest = chestBox.get(currentChestNumber)!;
|
2022-05-29 01:38:27 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
int pinLenght = walletOptions.getPinLenght(wallet!.number);
|
2021-03-08 02:20:48 +01:00
|
|
|
errorController = StreamController<ErrorAnimationType>();
|
|
|
|
|
|
|
|
return Scaffold(
|
2022-05-29 00:00:57 +02:00
|
|
|
backgroundColor: backgroundColor,
|
2021-03-08 02:20:48 +01:00
|
|
|
body: SafeArea(
|
2022-05-29 00:00:57 +02:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Stack(children: <Widget>[
|
|
|
|
Positioned(
|
|
|
|
top: 10, //statusBarHeight + 10,
|
|
|
|
left: 15,
|
|
|
|
child: Builder(
|
|
|
|
builder: (context) => IconButton(
|
|
|
|
key: const Key('popButton'),
|
|
|
|
icon: const Icon(
|
|
|
|
Icons.arrow_back,
|
|
|
|
color: Colors.black,
|
|
|
|
size: 30,
|
|
|
|
),
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
),
|
2021-12-23 15:13:58 +01:00
|
|
|
),
|
2021-12-21 11:06:11 +01:00
|
|
|
),
|
2022-05-29 00:00:57 +02:00
|
|
|
Column(children: <Widget>[
|
|
|
|
SizedBox(height: isTall ? 100 : 20),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
currentChest.imageFile == null
|
|
|
|
? Image.asset(
|
|
|
|
'assets/chests/${currentChest.imageName}',
|
|
|
|
width: isTall ? 130 : 100,
|
|
|
|
)
|
|
|
|
: Image.file(
|
|
|
|
currentChest.imageFile!,
|
|
|
|
width: isTall ? 130 : 100,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 5),
|
|
|
|
SizedBox(
|
|
|
|
width: 250,
|
|
|
|
child: Text(
|
|
|
|
currentChest.name!,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 25,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.w700),
|
|
|
|
)),
|
|
|
|
]),
|
|
|
|
SizedBox(height: 30 * ratio),
|
2022-06-17 01:13:14 +02:00
|
|
|
SizedBox(
|
2022-05-29 00:00:57 +02:00
|
|
|
width: 400,
|
2021-12-21 11:06:11 +01:00
|
|
|
child: Text(
|
2022-06-17 01:13:14 +02:00
|
|
|
'toUnlockEnterPassword'.tr(),
|
|
|
|
style: const TextStyle(
|
2022-05-29 00:00:57 +02:00
|
|
|
fontSize: 19,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.w400),
|
|
|
|
)),
|
|
|
|
SizedBox(height: 40 * ratio),
|
2022-08-06 02:22:41 +02:00
|
|
|
pinForm(context, pinLenght),
|
2022-05-29 00:00:57 +02:00
|
|
|
SizedBox(height: 3 * ratio),
|
2022-06-12 18:03:17 +02:00
|
|
|
if (canUnlock)
|
|
|
|
InkWell(
|
2022-05-29 00:00:57 +02:00
|
|
|
onTap: () {
|
2022-08-06 02:22:41 +02:00
|
|
|
walletOptions.changePinCacheChoice();
|
2022-05-29 00:00:57 +02:00
|
|
|
},
|
2022-06-12 18:03:17 +02:00
|
|
|
child: Row(children: [
|
|
|
|
const SizedBox(height: 30),
|
|
|
|
const Spacer(),
|
|
|
|
Icon(
|
|
|
|
configBox.get('isCacheChecked')
|
|
|
|
? Icons.check_box
|
|
|
|
: Icons.check_box_outline_blank,
|
|
|
|
color: orangeC,
|
2022-05-29 00:00:57 +02:00
|
|
|
),
|
2022-06-12 18:03:17 +02:00
|
|
|
const SizedBox(width: 8),
|
|
|
|
Text(
|
2022-06-17 01:13:14 +02:00
|
|
|
'rememberPassword'.tr(),
|
2022-06-12 18:03:17 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16, color: Colors.grey[700]),
|
|
|
|
),
|
|
|
|
const Spacer()
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
2022-06-12 19:20:15 +02:00
|
|
|
// if (canUnlock)
|
|
|
|
InkWell(
|
|
|
|
key: const Key('chooseChest'),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
|
|
|
return const ChooseChest();
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: SizedBox(
|
|
|
|
width: 400,
|
|
|
|
height: 50,
|
|
|
|
child: Center(
|
|
|
|
child: Text(
|
2022-06-17 01:13:14 +02:00
|
|
|
'changeChest'.tr(),
|
2022-06-12 19:20:15 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 22,
|
|
|
|
color: orangeC,
|
|
|
|
fontWeight: FontWeight.w600),
|
2022-06-12 18:03:17 +02:00
|
|
|
),
|
2022-06-12 19:20:15 +02:00
|
|
|
),
|
|
|
|
)),
|
2022-05-29 00:00:57 +02:00
|
|
|
]),
|
|
|
|
]),
|
2021-12-21 11:06:11 +01:00
|
|
|
]),
|
2022-05-29 00:00:57 +02:00
|
|
|
));
|
2021-03-08 02:20:48 +01:00
|
|
|
}
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
Widget pinForm(context, pinLenght) {
|
2021-03-08 02:20:48 +01:00
|
|
|
// var _walletPin = '';
|
|
|
|
// ignore: close_sinks
|
|
|
|
StreamController<ErrorAnimationType> errorController =
|
|
|
|
StreamController<ErrorAnimationType>();
|
2022-08-06 02:22:41 +02:00
|
|
|
TextEditingController enterPin = TextEditingController();
|
|
|
|
WalletOptionsProvider walletOptions =
|
2021-03-08 02:20:48 +01:00
|
|
|
Provider.of<WalletOptionsProvider>(context);
|
2022-08-06 02:22:41 +02:00
|
|
|
MyWalletsProvider myWalletProvider =
|
2021-04-03 00:07:03 +02:00
|
|
|
Provider.of<MyWalletsProvider>(context);
|
2022-08-06 02:22:41 +02:00
|
|
|
SubstrateSdk sub = Provider.of<SubstrateSdk>(context, listen: false);
|
2022-06-12 18:03:17 +02:00
|
|
|
FocusNode pinFocus = FocusNode();
|
2022-05-19 07:00:25 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
WalletData defaultWallet = myWalletProvider.getDefaultWallet();
|
2022-05-29 01:38:27 +02:00
|
|
|
|
2022-06-12 18:03:17 +02:00
|
|
|
// defaultWallet.address = null;
|
|
|
|
if (defaultWallet.address == null) {
|
|
|
|
canUnlock = false;
|
|
|
|
return Text(
|
|
|
|
'Impossible de retrouver votre\nportefeuille par défaut.\nID: ${defaultWallet.id()}',
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: const TextStyle(
|
|
|
|
color: Colors.redAccent, fontWeight: FontWeight.w500),
|
|
|
|
);
|
|
|
|
}
|
2021-11-17 06:20:23 +01:00
|
|
|
|
2021-03-08 02:20:48 +01:00
|
|
|
return Form(
|
|
|
|
key: formKey,
|
|
|
|
child: Padding(
|
2021-11-15 18:05:08 +01:00
|
|
|
padding: EdgeInsets.symmetric(vertical: 5 * ratio, horizontal: 30),
|
2021-03-08 02:20:48 +01:00
|
|
|
child: PinCodeTextField(
|
2021-11-17 06:20:23 +01:00
|
|
|
focusNode: pinFocus,
|
2021-03-08 02:20:48 +01:00
|
|
|
autoFocus: true,
|
|
|
|
appContext: context,
|
|
|
|
pastedTextStyle: TextStyle(
|
|
|
|
color: Colors.green.shade600,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-08-06 02:22:41 +02:00
|
|
|
length: pinLenght,
|
2021-04-27 23:05:58 +02:00
|
|
|
obscureText: true,
|
2021-03-08 02:20:48 +01:00
|
|
|
obscuringCharacter: '*',
|
|
|
|
animationType: AnimationType.fade,
|
|
|
|
validator: (v) {
|
2022-08-06 02:22:41 +02:00
|
|
|
if (v!.length < pinLenght) {
|
|
|
|
return "yourPasswordLengthIsX".tr(args: [pinLenght.toString()]);
|
2021-03-08 02:20:48 +01:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
pinTheme: PinTheme(
|
|
|
|
activeColor: pinColor,
|
|
|
|
borderWidth: 4,
|
|
|
|
shape: PinCodeFieldShape.box,
|
|
|
|
borderRadius: BorderRadius.circular(5),
|
2021-11-15 18:05:08 +01:00
|
|
|
fieldHeight: 50 * ratio,
|
2021-03-08 02:20:48 +01:00
|
|
|
fieldWidth: 50,
|
2021-11-17 06:20:23 +01:00
|
|
|
activeFillColor: Colors.black,
|
2021-03-08 02:20:48 +01:00
|
|
|
),
|
|
|
|
cursorColor: Colors.black,
|
2021-11-14 19:21:20 +01:00
|
|
|
animationDuration: const Duration(milliseconds: 300),
|
|
|
|
textStyle: const TextStyle(fontSize: 20, height: 1.6),
|
|
|
|
backgroundColor: const Color(0xffF9F9F1),
|
2021-03-08 02:20:48 +01:00
|
|
|
enableActiveFill: false,
|
|
|
|
errorAnimationController: errorController,
|
2022-08-06 02:22:41 +02:00
|
|
|
controller: enterPin,
|
2022-05-28 19:13:30 +02:00
|
|
|
keyboardType: TextInputType.visiblePassword,
|
2021-11-14 19:21:20 +01:00
|
|
|
boxShadows: const [
|
2021-03-08 02:20:48 +01:00
|
|
|
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();
|
|
|
|
final isValid = await sub.checkPassword(
|
|
|
|
defaultWallet.address!, pin.toUpperCase());
|
2021-04-03 00:07:03 +02:00
|
|
|
|
2022-05-19 07:00:25 +02:00
|
|
|
if (!isValid) {
|
2021-12-30 00:51:04 +01:00
|
|
|
await Future.delayed(const Duration(milliseconds: 50));
|
2021-03-08 02:20:48 +01:00
|
|
|
errorController.add(ErrorAnimationType
|
|
|
|
.shake); // Triggering error shake animation
|
|
|
|
pinColor = Colors.red[600];
|
2022-08-06 02:22:41 +02:00
|
|
|
myWalletProvider.pinCode = myWalletProvider.mnemonic = '';
|
|
|
|
walletOptions.reloadBuild();
|
2021-11-17 06:20:23 +01:00
|
|
|
pinFocus.requestFocus();
|
2021-03-08 02:20:48 +01:00
|
|
|
} else {
|
|
|
|
pinColor = Colors.green[400];
|
2022-08-06 02:22:41 +02:00
|
|
|
myWalletProvider.resetPinCode();
|
|
|
|
Navigator.pop(context, pin.toUpperCase());
|
2021-03-08 02:20:48 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onChanged: (value) {
|
2021-11-14 19:21:20 +01:00
|
|
|
if (pinColor != const Color(0xFFA4B600)) {
|
|
|
|
pinColor = const Color(0xFFA4B600);
|
2021-03-08 02:20:48 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|