2021-12-20 21:33:03 +01:00
|
|
|
import 'package:durt/durt.dart';
|
2021-02-27 20:29:35 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2021-11-08 23:12:25 +01:00
|
|
|
import 'package:gecko/globals.dart';
|
2021-12-23 15:13:58 +01:00
|
|
|
import 'package:gecko/providers/generate_wallets.dart';
|
2021-11-14 19:21:20 +01:00
|
|
|
import 'package:gecko/screens/myWallets/confirm_wallet_storage.dart';
|
2021-01-13 00:00:11 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2021-01-29 02:20:15 +01:00
|
|
|
import 'package:printing/printing.dart';
|
2021-01-26 21:00:26 +01:00
|
|
|
import 'package:provider/provider.dart';
|
2021-01-13 05:36:23 +01:00
|
|
|
import 'package:super_tooltip/super_tooltip.dart';
|
2021-01-13 00:00:11 +01:00
|
|
|
|
2021-01-26 21:00:26 +01:00
|
|
|
// ignore: must_be_immutable
|
2021-11-18 04:41:45 +01:00
|
|
|
class GenerateFastChestScreen extends StatelessWidget {
|
2021-12-23 12:36:09 +01:00
|
|
|
SuperTooltip? tooltip;
|
2021-01-13 00:00:11 +01:00
|
|
|
bool hasError = false;
|
|
|
|
String validPin = 'NO PIN';
|
|
|
|
String currentText = "";
|
|
|
|
var pinColor = Colors.grey[300];
|
|
|
|
|
2021-11-14 19:21:20 +01:00
|
|
|
final GlobalKey _toolTipSentence = GlobalKey();
|
|
|
|
final GlobalKey _toolTipSecret = GlobalKey();
|
|
|
|
|
2021-12-23 12:36:09 +01:00
|
|
|
GenerateFastChestScreen({Key? key}) : super(key: key);
|
2021-01-29 02:20:15 +01:00
|
|
|
|
2021-01-13 00:00:11 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-02-27 20:29:35 +01:00
|
|
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
2021-01-28 15:10:09 +01:00
|
|
|
GenerateWalletsProvider _generateWalletProvider =
|
|
|
|
Provider.of<GenerateWalletsProvider>(context);
|
2021-02-18 04:42:57 +01:00
|
|
|
|
2021-12-20 21:33:03 +01:00
|
|
|
if (_generateWalletProvider.mnemonicController.text == '') {
|
|
|
|
_generateWalletProvider.generateWordList();
|
|
|
|
_generateWalletProvider.mnemonicController.text =
|
2021-12-23 12:36:09 +01:00
|
|
|
_generateWalletProvider.generatedMnemonic!;
|
2021-12-23 15:13:58 +01:00
|
|
|
_generateWalletProvider.pin.text = randomSecretCode(pinLength);
|
2021-12-20 21:33:03 +01:00
|
|
|
}
|
|
|
|
|
2021-12-27 20:15:12 +01:00
|
|
|
return WillPopScope(
|
|
|
|
onWillPop: () {
|
|
|
|
_generateWalletProvider.pin.text = '';
|
|
|
|
_generateWalletProvider.mnemonicController.text = '';
|
|
|
|
return Future<bool>.value(true);
|
|
|
|
},
|
|
|
|
child: Scaffold(
|
2021-01-15 03:11:58 +01:00
|
|
|
appBar: AppBar(
|
2021-11-15 04:16:25 +01:00
|
|
|
toolbarHeight: 60 * ratio,
|
2021-12-27 20:15:12 +01:00
|
|
|
leading: IconButton(
|
|
|
|
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
|
|
|
onPressed: () {
|
|
|
|
_generateWalletProvider.pin.text = '';
|
|
|
|
_generateWalletProvider.mnemonicController.text = '';
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
}),
|
2021-11-14 19:21:20 +01:00
|
|
|
title: const SizedBox(
|
2021-11-15 04:16:25 +01:00
|
|
|
height: 22,
|
|
|
|
child: Text('Générer un trousseau'),
|
|
|
|
)),
|
2021-11-14 19:21:20 +01:00
|
|
|
floatingActionButton: SizedBox(
|
2021-01-13 00:00:11 +01:00
|
|
|
height: 80.0,
|
|
|
|
width: 80.0,
|
|
|
|
child: FittedBox(
|
|
|
|
child: FloatingActionButton(
|
|
|
|
heroTag: "buttonGenerateWallet",
|
2021-12-20 21:33:03 +01:00
|
|
|
onPressed: () {
|
|
|
|
_generateWalletProvider.generateWordList();
|
|
|
|
_generateWalletProvider.mnemonicController.text =
|
2021-12-23 12:36:09 +01:00
|
|
|
_generateWalletProvider.generatedMnemonic!;
|
2021-12-20 21:33:03 +01:00
|
|
|
},
|
2021-11-14 19:21:20 +01:00
|
|
|
child: SizedBox(
|
2021-01-16 03:32:41 +01:00
|
|
|
height: 40.0,
|
|
|
|
width: 40.0,
|
|
|
|
child: Icon(Icons.replay, color: Colors.grey[850]),
|
|
|
|
),
|
2021-11-08 23:12:25 +01:00
|
|
|
backgroundColor:
|
|
|
|
floattingYellow, //smoothYellow, //Color.fromARGB(500, 204, 255, 255),
|
2021-01-13 00:00:11 +01:00
|
|
|
))),
|
2021-02-07 02:59:48 +01:00
|
|
|
body: Builder(
|
2021-12-27 20:15:12 +01:00
|
|
|
builder: (ctx) => SafeArea(
|
|
|
|
child: Column(children: <Widget>[
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
toolTips(_toolTipSentence, 'Phrase de restauration:',
|
|
|
|
"Notez et gardez cette phrase précieusement sur un papier, elle vous servira à restaurer votre portefeuille sur un autre appareil"),
|
|
|
|
TextField(
|
|
|
|
enabled: false,
|
|
|
|
controller: _generateWalletProvider.mnemonicController,
|
|
|
|
maxLines: 3,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
contentPadding: EdgeInsets.all(15.0),
|
|
|
|
),
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 22.0,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.w400)),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
toolTips(_toolTipSecret, 'Code secret:',
|
|
|
|
"Retenez bien votre code secret, il vous sera demandé à chaque paiement, ainsi que pour configurer votre portefeuille"),
|
|
|
|
Stack(
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
children: <Widget>[
|
|
|
|
TextField(
|
|
|
|
key: const Key('generatedPin'),
|
|
|
|
enabled: false,
|
|
|
|
controller: _generateWalletProvider.pin,
|
|
|
|
maxLines: 1,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
decoration: const InputDecoration(),
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 30.0,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.bold)),
|
|
|
|
IconButton(
|
|
|
|
icon: const Icon(Icons.replay),
|
|
|
|
color: orangeC,
|
|
|
|
onPressed: () {
|
|
|
|
_generateWalletProvider.changePinCode(reload: true);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
ElevatedButton(
|
|
|
|
key: const Key('storeKeychain'),
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
primary: yellowC, // background
|
|
|
|
onPrimary: Colors.black, // foreground
|
|
|
|
),
|
|
|
|
onPressed: _generateWalletProvider.walletIsGenerated
|
|
|
|
? () async {
|
|
|
|
_generateWalletProvider.nbrWord =
|
|
|
|
_generateWalletProvider.getRandomInt();
|
|
|
|
_generateWalletProvider.actualWallet = await Dewif()
|
|
|
|
.generateDewif(
|
|
|
|
_generateWalletProvider.generatedMnemonic!,
|
|
|
|
_generateWalletProvider.pin.text,
|
|
|
|
lang: appLang);
|
|
|
|
await Navigator.push(
|
2021-02-07 02:59:48 +01:00
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
2021-12-27 20:15:12 +01:00
|
|
|
return ConfirmStoreWallet(
|
|
|
|
generatedMnemonic:
|
|
|
|
_generateWalletProvider.generatedMnemonic,
|
|
|
|
generatedWallet:
|
|
|
|
_generateWalletProvider.actualWallet);
|
2021-02-07 02:59:48 +01:00
|
|
|
}),
|
|
|
|
);
|
2021-12-27 20:15:12 +01:00
|
|
|
}
|
|
|
|
: null,
|
|
|
|
child: const Text('Enregistrer ce trousseau',
|
|
|
|
style: TextStyle(fontSize: 20))),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
|
|
|
return PrintWallet(
|
|
|
|
_generateWalletProvider.generatedMnemonic);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: const Icon(Icons.print))
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2021-01-13 00:00:11 +01:00
|
|
|
}
|
2021-01-29 02:20:15 +01:00
|
|
|
|
|
|
|
Widget toolTips(_key, _text, _message) {
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
final dynamic _toolTip = _key.currentState;
|
|
|
|
_toolTip.ensureTooltipVisible();
|
|
|
|
},
|
|
|
|
child: Tooltip(
|
2021-11-14 19:21:20 +01:00
|
|
|
padding: const EdgeInsets.all(10),
|
2021-01-29 02:20:15 +01:00
|
|
|
key: _key,
|
2021-11-14 19:21:20 +01:00
|
|
|
showDuration: const Duration(seconds: 5),
|
2021-01-29 02:20:15 +01:00
|
|
|
message: _message,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
2021-11-14 19:21:20 +01:00
|
|
|
const SizedBox(width: 20),
|
2021-01-29 02:20:15 +01:00
|
|
|
Column(children: <Widget>[
|
|
|
|
SizedBox(
|
|
|
|
width: 30,
|
|
|
|
height: 25,
|
2021-11-08 23:12:25 +01:00
|
|
|
child:
|
|
|
|
Icon(Icons.info_outline, size: 22, color: orangeC)),
|
2021-11-14 19:21:20 +01:00
|
|
|
const SizedBox(height: 1)
|
2021-01-29 02:20:15 +01:00
|
|
|
]),
|
|
|
|
Text(
|
|
|
|
_text,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 15.0,
|
|
|
|
color: Colors.grey[600],
|
|
|
|
fontWeight: FontWeight.w400),
|
|
|
|
),
|
2021-11-14 19:21:20 +01:00
|
|
|
const SizedBox(width: 45)
|
2021-01-29 02:20:15 +01:00
|
|
|
])));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore: must_be_immutable
|
|
|
|
class PrintWallet extends StatelessWidget {
|
2021-12-23 12:36:09 +01:00
|
|
|
const PrintWallet(this.sentence, {Key? key}) : super(key: key);
|
2021-01-29 02:20:15 +01:00
|
|
|
|
2021-12-23 12:36:09 +01:00
|
|
|
final String? sentence;
|
2021-01-29 02:20:15 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
GenerateWalletsProvider _generateWalletProvider =
|
|
|
|
Provider.of<GenerateWalletsProvider>(context);
|
|
|
|
return MaterialApp(
|
|
|
|
home: Scaffold(
|
2021-11-15 04:16:25 +01:00
|
|
|
appBar: AppBar(
|
2021-12-21 16:10:33 +01:00
|
|
|
leading: IconButton(
|
|
|
|
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context);
|
|
|
|
}),
|
2021-11-15 04:16:25 +01:00
|
|
|
toolbarHeight: 60 * ratio,
|
|
|
|
title: const Text('Imprimer ce trousseau')),
|
2021-01-29 02:20:15 +01:00
|
|
|
body: PdfPreview(
|
2021-02-14 21:04:58 +01:00
|
|
|
build: (format) => _generateWalletProvider.printWallet(sentence),
|
2021-01-29 02:20:15 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2021-01-13 00:00:11 +01:00
|
|
|
}
|