From a8427f5b9d154a2cdabe7cf4485388a1bc1d4829 Mon Sep 17 00:00:00 2001 From: poka Date: Wed, 13 Jan 2021 05:36:23 +0100 Subject: [PATCH] Add button for renew PIN; Add tooltips on walletGeneration page; WIP: Use custom wallet name --- lib/ui/myWallets/confirmWalletStorage.dart | 168 +++++++++++++++++++++------- lib/ui/myWallets/generateWalletsScreen.dart | 99 +++++++++++----- lib/ui/myWallets/myWalletsList.dart | 4 +- lib/ui/myWallets/walletsHome.dart | 12 +- pubspec.lock | 7 ++ pubspec.yaml | 1 + 6 files changed, 220 insertions(+), 71 deletions(-) diff --git a/lib/ui/myWallets/confirmWalletStorage.dart b/lib/ui/myWallets/confirmWalletStorage.dart index 19f9f4e..15157f4 100644 --- a/lib/ui/myWallets/confirmWalletStorage.dart +++ b/lib/ui/myWallets/confirmWalletStorage.dart @@ -1,4 +1,5 @@ import 'dart:io'; +import 'dart:math'; import 'package:dubp/dubp.dart'; import 'package:flutter/material.dart'; import 'package:path_provider/path_provider.dart'; @@ -24,30 +25,34 @@ class ConfirmStoreWalletState extends State { // DubpRust.setup(); this._mnemonicController.text = widget.generatedMnemonic; this._pubkey.text = widget.generatedWallet.publicKey; + nbrWord = getRandomInt(); } TextEditingController _mnemonicController = new TextEditingController(); TextEditingController _pubkey = new TextEditingController(); TextEditingController _pin = new TextEditingController(); - String walletName = 'MonWallet'; - List _listWallets = []; + TextEditingController _inputRestoreWord = new TextEditingController(); + TextEditingController walletName = new TextEditingController(); + // List _listWallets = []; + int nbrWord; + bool isAskedWordValid = false; @override Widget build(BuildContext context) { return Scaffold( + resizeToAvoidBottomInset: false, appBar: AppBar(), body: Center( child: Column(children: [ - TextField( - enabled: false, - controller: this._mnemonicController, - maxLines: 2, - textAlign: TextAlign.center, - decoration: InputDecoration(), - style: TextStyle( - fontSize: 15.0, - color: Colors.black, - fontWeight: FontWeight.bold)), + SizedBox(height: 15), + Text( + 'Votre clé publique est :', + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 17.0, + color: Colors.grey[600], + fontWeight: FontWeight.w400), + ), TextField( enabled: false, controller: this._pubkey, @@ -58,13 +63,76 @@ class ConfirmStoreWalletState extends State { fontSize: 14.0, color: Colors.black, fontWeight: FontWeight.bold)), - new ElevatedButton( - style: ElevatedButton.styleFrom( - primary: Color(0xffFFD68E), // background - onPrimary: Colors.black, // foreground - ), - onPressed: () => storeWallet(), - child: Text('Confirmer', style: TextStyle(fontSize: 20))), + SizedBox(height: 12), + Text( + 'Quel est le ${nbrWord + 1}ème mot de votre phrase de restauration ?', + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 17.0, + color: Colors.grey[600], + fontWeight: FontWeight.w400), + ), + TextField( + enabled: !isAskedWordValid, + controller: this._inputRestoreWord, + onChanged: (value) { + checkAskedWord(value); + }, + maxLines: 2, + textAlign: TextAlign.center, + decoration: InputDecoration(), + style: TextStyle( + fontSize: 30.0, + color: Colors.black, + fontWeight: FontWeight.w500)), + SizedBox(height: 12), + Text( + 'Choisissez un nom pour votre portefeuille :', + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 17.0, + color: Colors.grey[600], + fontWeight: FontWeight.w400), + ), + TextField( + enabled: isAskedWordValid, + controller: this.walletName, + onChanged: (v) { + nameChanged(); + }, + maxLines: 2, + textAlign: TextAlign.center, + decoration: InputDecoration(), + style: TextStyle( + fontSize: 30.0, + color: Colors.black, + fontWeight: FontWeight.w500)), + Expanded( + child: Align( + alignment: Alignment.bottomCenter, + child: SizedBox( + width: 200, + height: 50, + child: ElevatedButton( + style: ElevatedButton.styleFrom( + elevation: 12, + primary: Colors + .green[400], //Color(0xffFFD68E), // background + onPrimary: Colors.black, // foreground + ), + onPressed: + (isAskedWordValid && this.walletName.text != '') + ? () => storeWallet() + : null, + child: + Text('Confirmer', style: TextStyle(fontSize: 28))), + ))), + SizedBox(height: 70), + Text('TRICHE PENDANT ALPHA: ' + this._mnemonicController.text, + style: TextStyle( + fontSize: 10.0, + color: Colors.black, + fontWeight: FontWeight.normal)), ]), ), ); @@ -72,24 +140,27 @@ class ConfirmStoreWalletState extends State { Future storeWallet() async { final appPath = await _localPath; - final walletFile = File('$appPath/wallets/${this.walletName}/wallet.dewif'); + final walletFile = + // File('$appPath/wallets/${this.walletName.text}/wallet.dewif'); + File('$appPath/wallets/MonWallet/wallet.dewif'); + // TODO: Use custom wallet name for storage final isExist = await Directory('$appPath/wallets').exists(); if (isExist == false) { new Directory('$appPath/wallets').createSync(); } - new Directory('$appPath/wallets/${this.walletName}').createSync(); + new Directory('$appPath/wallets/${this.walletName.text}').createSync(); walletFile.writeAsString('${widget.generatedWallet.dewif}'); _pin.clear(); - await getAllWalletsNames(); - Navigator.pop(context, true); + // await getAllWalletsNames(); Navigator.pop(context, true); + Navigator.pop(context, this._pubkey.text); // setState(() {}); // FocusScope.of(context).unfocus(); - return this.walletName; + return this.walletName.text; } Future get _localPath async { @@ -97,21 +168,42 @@ class ConfirmStoreWalletState extends State { return directory.path; } - Future getAllWalletsNames() async { - final _appPath = await getApplicationDocumentsDirectory(); - // List _listWallets = []; - // _listWallets.add('tortuuue'); - this._listWallets.clear(); - print(_appPath); + // Future getAllWalletsNames() async { + // final _appPath = await getApplicationDocumentsDirectory(); + // // List _listWallets = []; + // // _listWallets.add('tortuuue'); + // this._listWallets.clear(); + // print(_appPath); - _appPath - .list(recursive: false, followLinks: false) - .listen((FileSystemEntity entity) { - print(entity.path.split('/').last); - this._listWallets.add(entity.path.split('/').last); - }); + // _appPath + // .list(recursive: false, followLinks: false) + // .listen((FileSystemEntity entity) { + // print(entity.path.split('/').last); + // this._listWallets.add(entity.path.split('/').last); + // }); - return _listWallets; - // final _local = await _appPath.path.list().toList(); + // return _listWallets; + // // final _local = await _appPath.path.list().toList(); + // } + + void checkAskedWord(value) { + print(this._mnemonicController.text.split(' ')[nbrWord]); + print(value); + if (this._mnemonicController.text.split(' ')[nbrWord] == value) { + print('Word is OK'); + isAskedWordValid = true; + } else { + isAskedWordValid = false; + } + setState(() {}); + } + + int getRandomInt() { + var rng = new Random(); + return rng.nextInt(12); + } + + void nameChanged() { + setState(() {}); } } diff --git a/lib/ui/myWallets/generateWalletsScreen.dart b/lib/ui/myWallets/generateWalletsScreen.dart index 20f16f3..e05debc 100644 --- a/lib/ui/myWallets/generateWalletsScreen.dart +++ b/lib/ui/myWallets/generateWalletsScreen.dart @@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:sentry/sentry.dart' as sentry; import 'package:dubp/dubp.dart'; +import 'package:super_tooltip/super_tooltip.dart'; class GenerateWalletsScreen extends StatefulWidget { const GenerateWalletsScreen({Key keyGenWallet}) : super(key: keyGenWallet); @@ -25,6 +26,7 @@ class GenerateWalletsState extends State { String generatedMnemonic; bool walletIsGenerated = false; NewWallet actualWallet; + SuperTooltip tooltip; // final formKey = GlobalKey(); bool hasError = false; @@ -55,12 +57,16 @@ class GenerateWalletsState extends State { body: SafeArea( child: Column(children: [ SizedBox(height: 20), - Text( - 'Clé publique:', - style: TextStyle( - fontSize: 15.0, - color: Colors.grey[600], - fontWeight: FontWeight.w400), + Tooltip( + message: + "C'est votre RIB en Ğ1, les gens l'utiliseront pour vous payer", + child: Text( + 'Clé publique:', + style: TextStyle( + fontSize: 15.0, + color: Colors.grey[600], + fontWeight: FontWeight.w400), + ), ), TextField( enabled: false, @@ -73,12 +79,16 @@ class GenerateWalletsState extends State { color: Colors.black, fontWeight: FontWeight.bold)), SizedBox(height: 8), - Text( - 'Phrase de restauration:', - style: TextStyle( - fontSize: 15.0, - color: Colors.grey[600], - fontWeight: FontWeight.w400), + Tooltip( + message: + "Notez et gardez cette phrase précieusement sur un papier, elle vous servira à restaurer votre portefeuille sur un autre appareil", + child: Text( + 'Phrase de restauration:', + style: TextStyle( + fontSize: 15.0, + color: Colors.grey[600], + fontWeight: FontWeight.w400), + ), ), TextField( enabled: false, @@ -93,23 +103,41 @@ class GenerateWalletsState extends State { color: Colors.black, fontWeight: FontWeight.w400)), SizedBox(height: 8), - Text( - 'Code secret:', - style: TextStyle( - fontSize: 15.0, - color: Colors.grey[600], - fontWeight: FontWeight.w400), - ), - TextField( - enabled: false, - controller: this._pin, - maxLines: 1, - textAlign: TextAlign.center, - decoration: InputDecoration(), + Tooltip( + message: + "Retenez bien votre code secret, il vous sera demandé à chaque paiement, ainsi que pour configurer votre portefeuille", + child: Text( + 'Code secret:', style: TextStyle( - fontSize: 30.0, - color: Colors.black, - fontWeight: FontWeight.bold)), + fontSize: 15.0, + color: Colors.grey[600], + fontWeight: FontWeight.w400), + ), + ), + Container( + child: Stack( + alignment: Alignment.centerRight, + children: [ + TextField( + enabled: false, + controller: this._pin, + maxLines: 1, + textAlign: TextAlign.center, + decoration: InputDecoration(), + style: TextStyle( + fontSize: 30.0, + color: Colors.black, + fontWeight: FontWeight.bold)), + IconButton( + icon: Icon(Icons.replay), + color: Color(0xffD28928), + onPressed: () { + changePinCode(); + }, + ), + ], + ), + ), SizedBox(height: 20), // Expanded(child: Align(alignment: Alignment.bottomCenter)), new ElevatedButton( @@ -148,7 +176,7 @@ class GenerateWalletsState extends State { )); } - Future generateMnemonic() async { + Future generateMnemonic() async { try { this.generatedMnemonic = await DubpRust.genMnemonic(language: Language.french); @@ -167,7 +195,7 @@ class GenerateWalletsState extends State { return this.generatedMnemonic; } - Future generateWallet(generatedMnemonic) async { + Future generateWallet(generatedMnemonic) async { try { this.actualWallet = await DubpRust.genWalletFromMnemonic( language: Language.french, @@ -191,4 +219,15 @@ class GenerateWalletsState extends State { return actualWallet; } + + Future changePinCode() async { + this.actualWallet = await DubpRust.changeDewifPin( + dewif: this.actualWallet.dewif, + oldPin: this.actualWallet.pin, + ); + + setState(() { + this._pin.text = actualWallet.pin; + }); + } } diff --git a/lib/ui/myWallets/myWalletsList.dart b/lib/ui/myWallets/myWalletsList.dart index af8b244..f7f7b3d 100644 --- a/lib/ui/myWallets/myWalletsList.dart +++ b/lib/ui/myWallets/myWalletsList.dart @@ -218,6 +218,8 @@ class MyWalletState extends State { this._listWallets.add(entity.path.split('/').last); }); + print('Mes wallets: '); + print(_listWallets); return _listWallets; // final _local = await _appPath.path.list().toList(); @@ -236,7 +238,7 @@ class MyWalletState extends State { Future readLocalWallet(String _pin) async { // print(pin); try { - final file = await _localWallet('MonWallet'); + final file = await _localWallet('this.walletName'); String _localDewif = await file.readAsString(); String _localPubkey; diff --git a/lib/ui/myWallets/walletsHome.dart b/lib/ui/myWallets/walletsHome.dart index ee32159..f8d822a 100644 --- a/lib/ui/myWallets/walletsHome.dart +++ b/lib/ui/myWallets/walletsHome.dart @@ -28,6 +28,7 @@ class WalletsHomeState extends State { String generatedMnemonic; bool walletIsGenerated = false; NewWallet actualWallet; + String newWalletName; bool hasError = false; String validPin = 'NO PIN'; @@ -54,7 +55,10 @@ class WalletsHomeState extends State { MaterialPageRoute(builder: (context) { return GenerateWalletsScreen(); }), - ); + ).then((value) => setState(() { + this.newWalletName = value; + checkIfWalletExist(value); + })); }, child: Container( height: 40.0, @@ -83,7 +87,10 @@ class WalletsHomeState extends State { MaterialPageRoute(builder: (context) { return GenerateWalletsScreen(); }), - ), + ).then((value) => setState(() { + this.newWalletName = value; + checkIfWalletExist(value); + })), child: Text('Générer un portefeuille', style: TextStyle(fontSize: 20))), SizedBox(height: 15), @@ -121,6 +128,7 @@ class WalletsHomeState extends State { // } bool checkIfWalletExist(_name) { + print('Nom du wallet: ' + _name); if (this.appPath == null) { return false; } diff --git a/pubspec.lock b/pubspec.lock index c2a9048..4fe2df2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -490,6 +490,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0-nullsafety.3" + super_tooltip: + dependency: "direct main" + description: + name: super_tooltip + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.6" term_glyph: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 7be3479..02e32e5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,6 +27,7 @@ dependencies: path_provider: ^1.6.24 pin_code_fields: ^6.0.2 http: ^0.12.2 + super_tooltip: ^0.9.6 flutter_icons: