2021-04-05 20:48:28 +02:00
|
|
|
import 'dart:async';
|
|
|
|
|
2021-01-28 15:26:26 +01:00
|
|
|
import 'package:dubp/dubp.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2021-11-15 04:16:25 +01:00
|
|
|
import 'package:gecko/globals.dart';
|
2021-11-14 19:21:20 +01:00
|
|
|
import 'package:gecko/models/generate_wallets.dart';
|
|
|
|
import 'package:gecko/models/my_wallets.dart';
|
|
|
|
import 'package:gecko/models/wallet_options.dart';
|
2021-11-19 03:18:39 +01:00
|
|
|
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
|
2021-01-28 15:26:26 +01:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
// ignore: must_be_immutable
|
|
|
|
class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
|
|
|
|
ConfirmStoreWallet({
|
|
|
|
Key validationKey,
|
|
|
|
@required this.generatedMnemonic,
|
|
|
|
@required this.generatedWallet,
|
|
|
|
}) : super(key: validationKey);
|
|
|
|
|
|
|
|
String generatedMnemonic;
|
|
|
|
NewWallet generatedWallet;
|
|
|
|
|
2021-11-14 19:21:20 +01:00
|
|
|
final TextEditingController _mnemonicController = TextEditingController();
|
|
|
|
final TextEditingController _inputRestoreWord = TextEditingController();
|
2021-01-28 15:26:26 +01:00
|
|
|
TextEditingController walletName = TextEditingController();
|
2021-11-14 19:21:20 +01:00
|
|
|
final FocusNode _wordFocus = FocusNode();
|
2021-01-28 15:26:26 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-02-27 20:29:35 +01:00
|
|
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
2021-01-28 15:26:26 +01:00
|
|
|
GenerateWalletsProvider _generateWalletProvider =
|
|
|
|
Provider.of<GenerateWalletsProvider>(context);
|
|
|
|
MyWalletsProvider _myWalletProvider =
|
|
|
|
Provider.of<MyWalletsProvider>(context);
|
2021-04-29 02:12:14 +02:00
|
|
|
WalletOptionsProvider _walletOptions =
|
|
|
|
Provider.of<WalletOptionsProvider>(context);
|
2021-03-19 06:33:48 +01:00
|
|
|
final int _currentChest = _myWalletProvider.getCurrentChest();
|
|
|
|
|
2021-11-14 19:21:20 +01:00
|
|
|
_mnemonicController.text = generatedMnemonic;
|
2021-01-28 15:26:26 +01:00
|
|
|
return WillPopScope(
|
|
|
|
onWillPop: () {
|
|
|
|
_generateWalletProvider.isAskedWordValid = false;
|
|
|
|
_generateWalletProvider.askedWordColor = Colors.black;
|
|
|
|
return Future<bool>.value(true);
|
|
|
|
},
|
|
|
|
child: Scaffold(
|
|
|
|
resizeToAvoidBottomInset: false,
|
|
|
|
appBar: AppBar(
|
2021-11-15 04:16:25 +01:00
|
|
|
toolbarHeight: 60 * ratio,
|
2021-01-28 15:26:26 +01:00
|
|
|
leading: IconButton(
|
2021-11-14 19:21:20 +01:00
|
|
|
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
2021-01-28 15:26:26 +01:00
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
_generateWalletProvider.isAskedWordValid = false;
|
|
|
|
_generateWalletProvider.askedWordColor = Colors.black;
|
|
|
|
}),
|
2021-11-14 19:21:20 +01:00
|
|
|
title: const SizedBox(
|
2021-01-28 15:26:26 +01:00
|
|
|
height: 22,
|
2021-02-14 21:04:58 +01:00
|
|
|
child: Text('Enregistrer ce trousseau'),
|
2021-01-28 15:26:26 +01:00
|
|
|
)),
|
|
|
|
body: Center(
|
|
|
|
child: Column(children: <Widget>[
|
2021-11-14 19:21:20 +01:00
|
|
|
const SizedBox(height: 15),
|
|
|
|
SizedBox(
|
2021-02-14 21:04:58 +01:00
|
|
|
width: 360,
|
|
|
|
child: Text(
|
|
|
|
'Quel est le ${_generateWalletProvider.nbrWord + 1}ème mot de votre phrase de restauration ?',
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 17.0,
|
|
|
|
color: Colors.grey[600],
|
|
|
|
fontWeight: FontWeight.w400),
|
|
|
|
)),
|
2021-01-28 15:26:26 +01:00
|
|
|
TextFormField(
|
2021-11-14 19:21:20 +01:00
|
|
|
key: const Key('askedWord'),
|
2021-01-28 15:26:26 +01:00
|
|
|
focusNode: _wordFocus,
|
|
|
|
autofocus: true,
|
|
|
|
enabled: !_generateWalletProvider.isAskedWordValid,
|
2021-11-14 19:21:20 +01:00
|
|
|
controller: _inputRestoreWord,
|
2021-01-28 15:26:26 +01:00
|
|
|
textInputAction: TextInputAction.next,
|
|
|
|
onChanged: (value) {
|
|
|
|
_generateWalletProvider.checkAskedWord(
|
|
|
|
value, _mnemonicController.text);
|
|
|
|
},
|
|
|
|
maxLines: 1,
|
|
|
|
textAlign: TextAlign.center,
|
2021-11-14 19:21:20 +01:00
|
|
|
decoration: const InputDecoration(),
|
2021-01-28 15:26:26 +01:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 30.0,
|
|
|
|
color: _generateWalletProvider.askedWordColor,
|
|
|
|
fontWeight: FontWeight.w500)),
|
2021-11-14 19:21:20 +01:00
|
|
|
const SizedBox(height: 12),
|
|
|
|
SizedBox(
|
2021-02-14 21:04:58 +01:00
|
|
|
width: 360,
|
|
|
|
child: Text(
|
|
|
|
'Choisissez un nom pour votre premier portefeuille :',
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 17.0,
|
|
|
|
color: Colors.grey[600],
|
|
|
|
fontWeight: FontWeight.w400),
|
|
|
|
)),
|
2021-01-28 15:26:26 +01:00
|
|
|
TextFormField(
|
2021-11-14 19:21:20 +01:00
|
|
|
key: const Key('walletName'),
|
2021-01-28 15:26:26 +01:00
|
|
|
focusNode: _generateWalletProvider.walletNameFocus,
|
|
|
|
inputFormatters: [
|
|
|
|
FilteringTextInputFormatter.allow(
|
|
|
|
RegExp('[A-Za-z|0-9|\\-|_| ]')),
|
|
|
|
],
|
2021-11-14 19:21:20 +01:00
|
|
|
controller: walletName,
|
2021-01-28 15:26:26 +01:00
|
|
|
textInputAction: TextInputAction.next,
|
|
|
|
onChanged: (v) {
|
|
|
|
_generateWalletProvider.nameChanged();
|
|
|
|
},
|
|
|
|
maxLines: 1,
|
|
|
|
textAlign: TextAlign.center,
|
2021-11-14 19:21:20 +01:00
|
|
|
decoration: const InputDecoration(),
|
|
|
|
style: const TextStyle(
|
2021-01-28 15:26:26 +01:00
|
|
|
fontSize: 30.0,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.w500)),
|
|
|
|
Expanded(
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
child: SizedBox(
|
|
|
|
width: 200,
|
|
|
|
height: 50,
|
|
|
|
child: ElevatedButton(
|
2021-11-14 19:21:20 +01:00
|
|
|
key: const Key('confirmStorage'),
|
2021-01-28 15:26:26 +01:00
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
elevation: 12,
|
2021-11-08 23:12:25 +01:00
|
|
|
primary: Colors
|
|
|
|
.green[400], //smoothYellow, // background
|
2021-01-28 15:26:26 +01:00
|
|
|
onPrimary: Colors.black, // foreground
|
|
|
|
),
|
|
|
|
onPressed: (_generateWalletProvider
|
|
|
|
.isAskedWordValid &&
|
2021-11-14 19:21:20 +01:00
|
|
|
walletName.text != '')
|
2021-11-22 18:45:59 +01:00
|
|
|
? () async {
|
2021-11-07 04:23:05 +01:00
|
|
|
_generateWalletProvider.storeHDWChest(
|
2021-01-28 15:26:26 +01:00
|
|
|
generatedWallet,
|
|
|
|
walletName.text,
|
2021-03-11 07:08:45 +01:00
|
|
|
context);
|
2021-01-28 15:26:26 +01:00
|
|
|
_generateWalletProvider.isAskedWordValid =
|
|
|
|
false;
|
|
|
|
_generateWalletProvider.askedWordColor =
|
|
|
|
Colors.black;
|
2021-04-29 02:12:14 +02:00
|
|
|
_myWalletProvider.listWallets =
|
|
|
|
_myWalletProvider
|
|
|
|
.readAllWallets(_currentChest);
|
2021-11-22 18:45:59 +01:00
|
|
|
await Future.delayed(
|
|
|
|
const Duration(milliseconds: 50));
|
|
|
|
_myWalletProvider.rebuildWidget();
|
2021-11-19 03:18:39 +01:00
|
|
|
Navigator.pushAndRemoveUntil(context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
|
|
|
return UnlockingWallet(
|
|
|
|
wallet:
|
|
|
|
_myWalletProvider.getDefaultWallet(
|
2021-11-22 18:45:59 +01:00
|
|
|
configBox.get('currentChest'),
|
|
|
|
),
|
2021-11-19 03:18:39 +01:00
|
|
|
action: "mywallets",
|
|
|
|
);
|
|
|
|
}), ModalRoute.withName('/'));
|
2021-01-28 15:26:26 +01:00
|
|
|
}
|
|
|
|
: null,
|
2021-11-14 19:21:20 +01:00
|
|
|
child: const Text('Confirmer',
|
2021-01-28 15:26:26 +01:00
|
|
|
style: TextStyle(fontSize: 28))),
|
|
|
|
))),
|
2021-11-14 19:21:20 +01:00
|
|
|
const SizedBox(height: 70),
|
|
|
|
Text('TRICHE PENDANT ALPHA: ' + _mnemonicController.text,
|
|
|
|
style: const TextStyle(
|
2021-01-28 15:26:26 +01:00
|
|
|
fontSize: 10.0,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.normal)),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|