Merge branch 'rebuildHQWorkflow'

This commit is contained in:
poka 2021-02-15 03:59:49 +01:00
commit 2e484d4373
9 changed files with 269 additions and 234 deletions

View File

@ -26,27 +26,40 @@ class GenerateWalletsProvider with ChangeNotifier {
bool walletIsGenerated = true; bool walletIsGenerated = true;
TextEditingController mnemonicController = TextEditingController(); TextEditingController mnemonicController = TextEditingController();
TextEditingController pubkey = TextEditingController();
TextEditingController pin = TextEditingController(); TextEditingController pin = TextEditingController();
Future storeWallet(NewWallet wallet, _name, BuildContext context) async { Future storeWallet(NewWallet wallet, String _name, BuildContext context,
final Directory walletNameDirectory = {bool isHD = false}) async {
Directory('${walletsDirectory.path}/$_name'); int nbrWallet = 0;
final walletFile = File('${walletNameDirectory.path}/wallet.dewif'); Directory walletNbrDirectory;
final walletPubkey = File('${walletNameDirectory.path}/pubkey'); do {
nbrWallet++;
walletNbrDirectory = Directory('${walletsDirectory.path}/$nbrWallet');
} while (await walletNbrDirectory.exists());
if (await walletNameDirectory.exists()) { final walletFile = File('${walletNbrDirectory.path}/wallet.dewif');
print('Ce wallet existe déjà, impossible de le créer.');
_showWalletExistDialog(context); await walletNbrDirectory.create();
return 'Exist: DENY'; await walletFile.writeAsString(wallet.dewif);
final configFile = File('${walletNbrDirectory.path}/config.txt');
if (isHD) {
final int _derivationNbr = 3;
List _pubkeysTmp = await DubpRust.getBip32DewifAccountsPublicKeys(
dewif: wallet.dewif,
secretCode: wallet.pin,
accountsIndex: [_derivationNbr]);
String _pubkey = _pubkeysTmp[0];
await configFile
.writeAsString('$nbrWallet:$_name:$_derivationNbr:$_pubkey');
} else {
await configFile.writeAsString('$nbrWallet:$_name');
} }
await walletNameDirectory.create();
await walletFile.writeAsString('${wallet.dewif}');
await walletPubkey.writeAsString('${wallet.publicKey}');
Navigator.pop(context, true); Navigator.pop(context, true);
Navigator.pop(context, wallet.publicKey); Navigator.pop(context, true);
// notifyListeners(); // notifyListeners();
return _name; return _name;
@ -107,35 +120,6 @@ class GenerateWalletsProvider with ChangeNotifier {
notifyListeners(); notifyListeners();
} }
Future<void> _showWalletExistDialog(BuildContext context) async {
return showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: Text('Ce nom existe déjà'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text('Veuillez choisir un autre nom pour votre portefeuille.'),
],
),
),
actions: <Widget>[
TextButton(
child: Text("J'ai compris"),
onPressed: () {
Navigator.of(context).pop();
askedWordColor = Colors.green[500];
isAskedWordValid = true;
},
),
],
);
},
);
}
Future<String> generateMnemonic() async { Future<String> generateMnemonic() async {
try { try {
generatedMnemonic = await DubpRust.genMnemonic(language: Language.french); generatedMnemonic = await DubpRust.genMnemonic(language: Language.french);
@ -173,7 +157,6 @@ class GenerateWalletsProvider with ChangeNotifier {
} }
mnemonicController.text = generatedMnemonic; mnemonicController.text = generatedMnemonic;
pubkey.text = this.actualWallet.publicKey;
pin.text = this.actualWallet.pin; pin.text = this.actualWallet.pin;
// notifyListeners(); // notifyListeners();
@ -190,7 +173,7 @@ class GenerateWalletsProvider with ChangeNotifier {
// notifyListeners(); // notifyListeners();
} }
Future<Uint8List> printWallet(String _title, String _pubkey) async { Future<Uint8List> printWallet(String _title) async {
final ByteData fontData = final ByteData fontData =
await rootBundle.load("assets/OpenSans-Regular.ttf"); await rootBundle.load("assets/OpenSans-Regular.ttf");
final pw.Font ttf = pw.Font.ttf(fontData.buffer.asByteData()); final pw.Font ttf = pw.Font.ttf(fontData.buffer.asByteData());
@ -204,12 +187,6 @@ class GenerateWalletsProvider with ChangeNotifier {
pageFormat: PdfPageFormat.a4, pageFormat: PdfPageFormat.a4,
build: (context) { build: (context) {
return pw.Column(children: <pw.Widget>[ return pw.Column(children: <pw.Widget>[
pw.Text("Clé publique:",
style: pw.TextStyle(fontSize: 20, font: ttf)),
pw.SizedBox(height: 10),
pw.Text(_pubkey,
style: pw.TextStyle(fontSize: 15, font: ttf),
textAlign: pw.TextAlign.center),
pw.SizedBox(height: 20), pw.SizedBox(height: 20),
pw.Text("Phrase de restauration:", pw.Text("Phrase de restauration:",
style: pw.TextStyle(fontSize: 20, font: ttf)), style: pw.TextStyle(fontSize: 20, font: ttf)),

View File

@ -6,7 +6,7 @@ import 'package:gecko/globals.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class MyWalletsProvider with ChangeNotifier { class MyWalletsProvider with ChangeNotifier {
Map listWallets = Map(); String listWallets;
bool checkIfWalletExist() { bool checkIfWalletExist() {
if (appPath == null) { if (appPath == null) {
@ -25,25 +25,33 @@ class MyWalletsProvider with ChangeNotifier {
Future importWallet() async {} Future importWallet() async {}
Map getAllWalletsNames() { String getAllWalletsNames() {
if (listWallets.isNotEmpty) { final bool _isWalletsExists = checkIfWalletExist();
listWallets.clear(); if (!_isWalletsExists) {
return '';
}
if (listWallets != null && listWallets.isNotEmpty) {
listWallets = '';
}
if (listWallets == null) {
listWallets = '';
} }
// int i = 0; // int i = 0;
walletsDirectory walletsDirectory
.listSync(recursive: false, followLinks: false) .listSync(recursive: false, followLinks: false)
.forEach((wallet) { .forEach((_wallet) {
String _name = wallet.path.split('/').last; File _walletConfig = File('${_wallet.path}/config.txt');
List _pubkeyList = File(wallet.path + '/pubkey').readAsLinesSync(); _walletConfig.readAsLinesSync().forEach((element) {
String _pubkey = _pubkeyList[0]; if (listWallets != '') {
listWallets[_name] = _pubkey; listWallets += '\n';
// i++; }
listWallets += element;
// for (var _wallets in listWallets) { // listWallets += "${element.split(':')[0]}:${element.split(':')[1]}:${element.split(':')[2]}"
// _wallets.pubkey = });
// }
}); });
return listWallets; return listWallets;
} }
@ -56,6 +64,7 @@ class MyWalletsProvider with ChangeNotifier {
if (_answer) { if (_answer) {
await walletsDirectory.delete(recursive: true); await walletsDirectory.delete(recursive: true);
await walletsDirectory.create(); await walletsDirectory.create();
notifyListeners();
Navigator.pop(context); Navigator.pop(context);
} }
return 0; return 0;
@ -72,8 +81,8 @@ class MyWalletsProvider with ChangeNotifier {
MyWalletsProvider _myWalletProvider = MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context); Provider.of<MyWalletsProvider>(context);
return AlertDialog( return AlertDialog(
title: Text( title:
'Êtes-vous sûr de vouloir supprimer tous vos portefeuilles ?'), Text('Êtes-vous sûr de vouloir supprimer tous vos trousseaux ?'),
content: SingleChildScrollView(child: Text('')), content: SingleChildScrollView(child: Text('')),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
@ -99,6 +108,30 @@ class MyWalletsProvider with ChangeNotifier {
); );
} }
Future<void> generateNewDerivation(
context, String _name, int _walletNbr) async {
int _newDerivationNbr;
final _walletConfig =
File('${walletsDirectory.path}/$_walletNbr/config.txt');
if (await _walletConfig.readAsString() == '') {
_newDerivationNbr = 3;
} else {
String _lastWallet =
await _walletConfig.readAsLines().then((value) => value.last);
int _lastDerivation = int.parse(_lastWallet.split(':')[2]);
_newDerivationNbr = _lastDerivation + 3;
}
await _walletConfig.writeAsString('\n$_walletNbr:$_name:$_newDerivationNbr',
mode: FileMode.append);
print(await _walletConfig.readAsString());
notifyListeners();
Navigator.pop(context);
}
void rebuildWidget() { void rebuildWidget() {
notifyListeners(); notifyListeners();
} }

View File

@ -15,7 +15,8 @@ class WalletOptionsProvider with ChangeNotifier {
Future<NewWallet> get badWallet => null; Future<NewWallet> get badWallet => null;
Future _getPubkeyFromDewif(_dewif, _pin, _pinLenght) async { Future _getPubkeyFromDewif(
String _dewif, _pin, int _pinLenght, int derivation) async {
String _pubkey; String _pubkey;
RegExp regExp = new RegExp( RegExp regExp = new RegExp(
r'^[A-Z0-9]+$', r'^[A-Z0-9]+$',
@ -30,7 +31,9 @@ class WalletOptionsProvider with ChangeNotifier {
return 'false'; return 'false';
} }
try { try {
_pubkey = await DubpRust.getDewifPublicKey(dewif: _dewif, pin: _pin); List _pubkeysTmp = await DubpRust.getBip32DewifAccountsPublicKeys(
dewif: _dewif, secretCode: _pin, accountsIndex: [derivation]);
_pubkey = _pubkeysTmp[0];
this.pubkey.text = _pubkey; this.pubkey.text = _pubkey;
notifyListeners(); notifyListeners();
@ -50,23 +53,21 @@ class WalletOptionsProvider with ChangeNotifier {
} }
} }
Future readLocalWallet(String _name, String _pin, _pinLenght) async { Future readLocalWallet(int _walletNbr, String _name, String _pin,
int _pinLenght, int derivation) async {
isWalletUnlock = false; isWalletUnlock = false;
try { try {
File _walletFile = File('${walletsDirectory.path}/$_name/wallet.dewif'); File _walletFile =
File('${walletsDirectory.path}/$_walletNbr/wallet.dewif');
String _localDewif = await _walletFile.readAsString(); String _localDewif = await _walletFile.readAsString();
String _localPubkey; String _localPubkey;
if ((_localPubkey = if ((_localPubkey = await _getPubkeyFromDewif(
await _getPubkeyFromDewif(_localDewif, _pin, _pinLenght)) != _localDewif, _pin, _pinLenght, derivation)) !=
'false') { 'false') {
this.pubkey.text = _localPubkey; this.pubkey.text = _localPubkey;
isWalletUnlock = true; isWalletUnlock = true;
notifyListeners(); notifyListeners();
print('GET BIP32 accounts publickeys from this dewif');
List _hdWallets = await DubpRust.getBip32DewifAccountsPublicKeys(
dewif: _localDewif, secretCode: _pin, accountsIndex: [0, 1, 2]);
print(_hdWallets);
return _localDewif; return _localDewif;
} else { } else {
@ -79,8 +80,9 @@ class WalletOptionsProvider with ChangeNotifier {
} }
} }
int getPinLenght(_name) { int getPinLenght(_walletNbr) {
File _walletFile = File('${walletsDirectory.path}/$_name/wallet.dewif'); File _walletFile =
File('${walletsDirectory.path}/$_walletNbr/wallet.dewif');
String _localDewif = _walletFile.readAsStringSync(); String _localDewif = _walletFile.readAsStringSync();
final int _pinLenght = DubpRust.getDewifSecretCodeLen( final int _pinLenght = DubpRust.getDewifSecretCodeLen(
@ -89,17 +91,27 @@ class WalletOptionsProvider with ChangeNotifier {
return _pinLenght; return _pinLenght;
} }
Future _renameWallet(_walletName, _newName) async { Future _renameWallet(_walletName, _newName, _walletNbr, _derivation) async {
final _walletFile = Directory('${walletsDirectory.path}/$_walletName'); final _walletConfig =
File('${walletsDirectory.path}/$_walletNbr/config.txt');
try { String newConfig =
_walletFile.rename('${walletsDirectory.path}/$_newName'); await _walletConfig.readAsLines().then((List<String> lines) {
} catch (e) { int _index = lines.indexOf('$_walletNbr:$_walletName:$_derivation');
print('ERREUR lors du renommage du wallet: $e'); lines.removeWhere(
} (element) => element == '$_walletNbr:$_walletName:$_derivation');
lines.insert(_index, '$_walletNbr:$_newName:$_derivation');
return lines.join('\n');
});
await _walletConfig.delete();
await _walletConfig.writeAsString(newConfig);
_newWalletName.text = '';
} }
Future<bool> renameWalletAlerte(context, _walletName) async { Future<bool> renameWalletAlerte(
context, _walletName, _walletNbr, _derivation) async {
return showDialog<bool>( return showDialog<bool>(
context: context, context: context,
barrierDismissible: true, // user must tap button! barrierDismissible: true, // user must tap button!
@ -125,12 +137,12 @@ class WalletOptionsProvider with ChangeNotifier {
TextButton( TextButton(
child: Text("Valider"), child: Text("Valider"),
onPressed: () { onPressed: () {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) async {
_renameWallet(_walletName, this._newWalletName.text); await _renameWallet(_walletName, this._newWalletName.text,
_walletNbr, _derivation);
}); });
// notifyListeners(); // notifyListeners();
Navigator.pop(context, true); Navigator.pop(context, true);
Navigator.pop(context, true);
}, },
), ),
], ],
@ -139,21 +151,26 @@ class WalletOptionsProvider with ChangeNotifier {
); );
} }
Future<int> deleteWallet(context, _name) async { Future<int> deleteWallet(context, _walletNbr, _name, _derivation) async {
try { final bool _answer = await _confirmDeletingWallet(context, _name);
final _walletFile = Directory('${walletsDirectory.path}/$_name');
print('DELETE THAT ?: $_walletFile');
final bool _answer = await _confirmDeletingWallet(context, _name); if (_answer) {
final _walletConfig =
File('${walletsDirectory.path}/$_walletNbr/config.txt');
if (_answer) { String newConfig =
await _walletFile.delete(recursive: true); await _walletConfig.readAsLines().then((List<String> lines) {
Navigator.pop(context); lines.removeWhere(
} (element) => element.contains('$_walletNbr:$_name:$_derivation'));
return 0;
} catch (e) { return lines.join('\n');
return 1; });
await _walletConfig.delete();
await _walletConfig.writeAsString(newConfig);
Navigator.pop(context);
} }
return 0;
} }
Future<bool> _confirmDeletingWallet(context, _walletName) async { Future<bool> _confirmDeletingWallet(context, _walletName) async {
@ -167,8 +184,7 @@ class WalletOptionsProvider with ChangeNotifier {
content: SingleChildScrollView( content: SingleChildScrollView(
child: ListBody( child: ListBody(
children: <Widget>[ children: <Widget>[
Text( Text('Vous pourrez restaurer ce portefeuille plus tard.'),
'Vous pourrez restaurer ce portefeuille à tout moment grace à votre phrase de restauration.'),
], ],
), ),
), ),

View File

@ -78,7 +78,10 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
errorBorder: InputBorder.none, errorBorder: InputBorder.none,
disabledBorder: InputBorder.none, disabledBorder: InputBorder.none,
), ),
style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)), style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.bold,
fontFamily: 'Monospace')),
if (_historyProvider.pubkey != '') if (_historyProvider.pubkey != '')
historyQuery(context, _historyProvider), historyQuery(context, _historyProvider),
])); ]));
@ -273,7 +276,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
subtitle: Text( subtitle: Text(
truncate(repository[2], 20, truncate(repository[2], 20,
omission: "...", position: TruncatePosition.end), omission: "...", position: TruncatePosition.end),
style: TextStyle(fontSize: 11.0), style: TextStyle(fontSize: 11.0, fontFamily: 'Monospace'),
textAlign: TextAlign.center), textAlign: TextAlign.center),
trailing: Text("${repository[3]} Ğ1", trailing: Text("${repository[3]} Ğ1",
style: TextStyle(fontSize: 14.0), style: TextStyle(fontSize: 14.0),

View File

@ -17,7 +17,6 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
NewWallet generatedWallet; NewWallet generatedWallet;
TextEditingController _mnemonicController = TextEditingController(); TextEditingController _mnemonicController = TextEditingController();
TextEditingController _pubkey = TextEditingController();
TextEditingController _inputRestoreWord = TextEditingController(); TextEditingController _inputRestoreWord = TextEditingController();
TextEditingController walletName = TextEditingController(); TextEditingController walletName = TextEditingController();
FocusNode _wordFocus = FocusNode(); FocusNode _wordFocus = FocusNode();
@ -30,7 +29,6 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
Provider.of<MyWalletsProvider>(context); Provider.of<MyWalletsProvider>(context);
this._mnemonicController.text = generatedMnemonic; this._mnemonicController.text = generatedMnemonic;
this._pubkey.text = generatedWallet.publicKey;
return WillPopScope( return WillPopScope(
onWillPop: () { onWillPop: () {
_generateWalletProvider.isAskedWordValid = false; _generateWalletProvider.isAskedWordValid = false;
@ -49,38 +47,21 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
}), }),
title: SizedBox( title: SizedBox(
height: 22, height: 22,
child: Text('Enregistrer ce portefeuille'), child: Text('Enregistrer ce trousseau'),
)), )),
body: Center( body: Center(
child: Column(children: <Widget>[ child: Column(children: <Widget>[
SizedBox(height: 15), SizedBox(height: 15),
Text( Container(
'Votre clé publique est :', width: 360,
textAlign: TextAlign.center, child: Text(
style: TextStyle( 'Quel est le ${_generateWalletProvider.nbrWord + 1}ème mot de votre phrase de restauration ?',
fontSize: 17.0, textAlign: TextAlign.center,
color: Colors.grey[600], style: TextStyle(
fontWeight: FontWeight.w400), fontSize: 17.0,
), color: Colors.grey[600],
TextField( fontWeight: FontWeight.w400),
enabled: false, )),
controller: this._pubkey,
maxLines: 1,
textAlign: TextAlign.center,
decoration: InputDecoration(),
style: TextStyle(
fontSize: 14.0,
color: Colors.black,
fontWeight: FontWeight.bold)),
SizedBox(height: 12),
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),
),
TextFormField( TextFormField(
focusNode: _wordFocus, focusNode: _wordFocus,
autofocus: true, autofocus: true,
@ -99,14 +80,16 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
color: _generateWalletProvider.askedWordColor, color: _generateWalletProvider.askedWordColor,
fontWeight: FontWeight.w500)), fontWeight: FontWeight.w500)),
SizedBox(height: 12), SizedBox(height: 12),
Text( Container(
'Choisissez un nom pour votre portefeuille :', width: 360,
textAlign: TextAlign.center, child: Text(
style: TextStyle( 'Choisissez un nom pour votre premier portefeuille :',
fontSize: 17.0, textAlign: TextAlign.center,
color: Colors.grey[600], style: TextStyle(
fontWeight: FontWeight.w400), fontSize: 17.0,
), color: Colors.grey[600],
fontWeight: FontWeight.w400),
)),
TextFormField( TextFormField(
focusNode: _generateWalletProvider.walletNameFocus, focusNode: _generateWalletProvider.walletNameFocus,
inputFormatters: [ inputFormatters: [
@ -145,7 +128,8 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
await _generateWalletProvider.storeWallet( await _generateWalletProvider.storeWallet(
generatedWallet, generatedWallet,
walletName.text, walletName.text,
context); context,
isHD: true);
_generateWalletProvider.isAskedWordValid = _generateWalletProvider.isAskedWordValid =
false; false;
_generateWalletProvider.askedWordColor = _generateWalletProvider.askedWordColor =

View File

@ -1,6 +1,4 @@
import 'package:flutter/services.dart';
import 'package:gecko/models/generateWallets.dart'; import 'package:gecko/models/generateWallets.dart';
import 'package:gecko/models/walletOptions.dart';
import 'package:gecko/screens/myWallets/confirmWalletStorage.dart'; import 'package:gecko/screens/myWallets/confirmWalletStorage.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:printing/printing.dart'; import 'package:printing/printing.dart';
@ -15,7 +13,6 @@ class GenerateWalletsScreen extends StatelessWidget {
String currentText = ""; String currentText = "";
var pinColor = Colors.grey[300]; var pinColor = Colors.grey[300];
GlobalKey _toolTipPubkey = GlobalKey();
GlobalKey _toolTipSentence = GlobalKey(); GlobalKey _toolTipSentence = GlobalKey();
GlobalKey _toolTipSecret = GlobalKey(); GlobalKey _toolTipSecret = GlobalKey();
@ -23,8 +20,6 @@ class GenerateWalletsScreen extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
GenerateWalletsProvider _generateWalletProvider = GenerateWalletsProvider _generateWalletProvider =
Provider.of<GenerateWalletsProvider>(context); Provider.of<GenerateWalletsProvider>(context);
WalletOptionsProvider _walletOptions =
Provider.of<WalletOptionsProvider>(context);
_generateWalletProvider.generateMnemonic(); _generateWalletProvider.generateMnemonic();
print('IS GENERATED ? : ' + print('IS GENERATED ? : ' +
_generateWalletProvider.walletIsGenerated.toString()); _generateWalletProvider.walletIsGenerated.toString());
@ -32,7 +27,7 @@ class GenerateWalletsScreen extends StatelessWidget {
appBar: AppBar( appBar: AppBar(
title: SizedBox( title: SizedBox(
height: 22, height: 22,
child: Text('Générer un portefeuille'), child: Text('Générer un trousseau'),
)), )),
floatingActionButton: Container( floatingActionButton: Container(
height: 80.0, height: 80.0,
@ -53,26 +48,6 @@ class GenerateWalletsScreen extends StatelessWidget {
builder: (ctx) => SafeArea( builder: (ctx) => SafeArea(
child: Column(children: <Widget>[ child: Column(children: <Widget>[
SizedBox(height: 20), SizedBox(height: 20),
toolTips(_toolTipPubkey, 'Clé publique:',
"C'est votre RIB en Ğ1, les gens l'utiliseront pour vous payer"),
GestureDetector(
onTap: () {
Clipboard.setData(ClipboardData(
text: _generateWalletProvider.pubkey.text));
_walletOptions.snackCopyKey(ctx);
},
child: TextField(
enabled: false,
controller: _generateWalletProvider.pubkey,
maxLines: 1,
textAlign: TextAlign.center,
decoration: InputDecoration(),
style: TextStyle(
fontSize: 14.0,
color: Colors.black,
fontWeight: FontWeight.bold,
fontFamily: 'Monospace'))),
SizedBox(height: 8),
toolTips(_toolTipSentence, 'Phrase de restauration:', 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"), "Notez et gardez cette phrase précieusement sur un papier, elle vous servira à restaurer votre portefeuille sur un autre appareil"),
TextField( TextField(
@ -137,7 +112,7 @@ class GenerateWalletsScreen extends StatelessWidget {
); );
} }
: null, : null,
child: Text('Enregistrer ce portefeuille', child: Text('Enregistrer ce trousseau',
style: TextStyle(fontSize: 20))), style: TextStyle(fontSize: 20))),
SizedBox(height: 20), SizedBox(height: 20),
GestureDetector( GestureDetector(
@ -146,9 +121,7 @@ class GenerateWalletsScreen extends StatelessWidget {
context, context,
MaterialPageRoute(builder: (context) { MaterialPageRoute(builder: (context) {
return PrintWallet( return PrintWallet(
_generateWalletProvider.generatedMnemonic, _generateWalletProvider.generatedMnemonic);
_generateWalletProvider
.actualWallet.publicKey);
}), }),
); );
}, },
@ -194,10 +167,9 @@ class GenerateWalletsScreen extends StatelessWidget {
// ignore: must_be_immutable // ignore: must_be_immutable
class PrintWallet extends StatelessWidget { class PrintWallet extends StatelessWidget {
PrintWallet(this.sentence, this.pubkey); PrintWallet(this.sentence);
final String sentence; final String sentence;
final String pubkey;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -205,10 +177,9 @@ class PrintWallet extends StatelessWidget {
Provider.of<GenerateWalletsProvider>(context); Provider.of<GenerateWalletsProvider>(context);
return MaterialApp( return MaterialApp(
home: Scaffold( home: Scaffold(
appBar: AppBar(title: Text('Imprimer ce portefeuille')), appBar: AppBar(title: Text('Imprimer ce trousseau')),
body: PdfPreview( body: PdfPreview(
build: (format) => build: (format) => _generateWalletProvider.printWallet(sentence),
_generateWalletProvider.printWallet(sentence, pubkey),
), ),
), ),
); );

View File

@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import 'package:dubp/dubp.dart'; import 'package:dubp/dubp.dart';
import 'package:gecko/models/myWallets.dart'; import 'package:gecko/models/myWallets.dart';
import 'package:gecko/models/walletOptions.dart'; import 'package:gecko/models/walletOptions.dart';
import 'package:gecko/screens/myWallets/changePin.dart';
import 'dart:async'; import 'dart:async';
import 'package:pin_code_fields/pin_code_fields.dart'; import 'package:pin_code_fields/pin_code_fields.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -11,9 +10,15 @@ import 'package:flutter/services.dart';
// ignore: must_be_immutable // ignore: must_be_immutable
class WalletOptions extends StatelessWidget with ChangeNotifier { class WalletOptions extends StatelessWidget with ChangeNotifier {
WalletOptions({Key keyMyWallets, @required this.walletName}) WalletOptions(
{Key keyMyWallets,
@required this.walletNbr,
@required this.walletName,
@required this.derivation})
: super(key: keyMyWallets); : super(key: keyMyWallets);
int walletNbr;
String walletName; String walletName;
int derivation;
StreamController<ErrorAnimationType> errorController; StreamController<ErrorAnimationType> errorController;
TextEditingController _enterPin = TextEditingController(); TextEditingController _enterPin = TextEditingController();
@ -34,7 +39,7 @@ class WalletOptions extends StatelessWidget with ChangeNotifier {
errorController = StreamController<ErrorAnimationType>(); errorController = StreamController<ErrorAnimationType>();
// _walletOptions.isWalletUnlock = false; // _walletOptions.isWalletUnlock = false;
final int _pinLenght = _walletOptions.getPinLenght(this.walletName); final int _pinLenght = _walletOptions.getPinLenght(this.walletNbr);
return WillPopScope( return WillPopScope(
onWillPop: () { onWillPop: () {
@ -100,7 +105,10 @@ class WalletOptions extends StatelessWidget with ChangeNotifier {
), ),
onPressed: () => _walletOptions onPressed: () => _walletOptions
.renameWalletAlerte( .renameWalletAlerte(
context, walletName) context,
walletName,
walletNbr,
derivation)
.then((_result) { .then((_result) {
if (_result == true) { if (_result == true) {
WidgetsBinding.instance WidgetsBinding.instance
@ -113,6 +121,8 @@ class WalletOptions extends StatelessWidget with ChangeNotifier {
_myWalletProvider _myWalletProvider
.rebuildWidget(); .rebuildWidget();
}); });
Navigator.pop(
context, true);
} }
}), }),
child: Text( child: Text(
@ -125,38 +135,14 @@ class WalletOptions extends StatelessWidget with ChangeNotifier {
width: 300, width: 300,
child: ElevatedButton( child: ElevatedButton(
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
elevation: 5,
primary: Color(
0xffFFD68E), //Color(0xffFFD68E), // background
onPrimary: Colors.black, // foreground
),
onPressed: () {
// changePin(widget.walletName, this.walletPin);
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return ChangePinScreen(
walletName: walletName,
oldPin: this.walletPin);
}),
);
},
child: Text('Changer mon code secret',
style: TextStyle(fontSize: 20)))),
SizedBox(height: 30),
SizedBox(
height: 50,
width: 300,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
elevation: 6, elevation: 6,
primary: Colors primary: Colors
.redAccent, //Color(0xffFFD68E), // background .redAccent, //Color(0xffFFD68E), // background
onPrimary: Colors.black, // foreground onPrimary: Colors.black, // foreground
), ),
onPressed: () async { onPressed: () async {
await _walletOptions.deleteWallet( await _walletOptions.deleteWallet(context,
context, walletName); walletNbr, walletName, derivation);
WidgetsBinding.instance WidgetsBinding.instance
.addPostFrameCallback((_) { .addPostFrameCallback((_) {
_myWalletProvider.listWallets = _myWalletProvider.listWallets =
@ -244,9 +230,11 @@ class WalletOptions extends StatelessWidget with ChangeNotifier {
print("Completed"); print("Completed");
final resultWallet = final resultWallet =
await _walletOptions.readLocalWallet( await _walletOptions.readLocalWallet(
this.walletNbr,
this.walletName, this.walletName,
_pin.toUpperCase(), _pin.toUpperCase(),
_pinLenght); _pinLenght,
this.derivation);
if (resultWallet == 'bad') { if (resultWallet == 'bad') {
errorController.add(ErrorAnimationType errorController.add(ErrorAnimationType
.shake); // Triggering error shake animation .shake); // Triggering error shake animation

View File

@ -7,6 +7,8 @@ import 'package:provider/provider.dart';
// ignore: must_be_immutable // ignore: must_be_immutable
class WalletsHome extends StatelessWidget { class WalletsHome extends StatelessWidget {
final _derivationKey = GlobalKey<FormState>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
MyWalletsProvider myWalletProvider = MyWalletsProvider myWalletProvider =
@ -27,12 +29,11 @@ class WalletsHome extends StatelessWidget {
child: FloatingActionButton( child: FloatingActionButton(
heroTag: "buttonGenerateWallet", heroTag: "buttonGenerateWallet",
onPressed: () { onPressed: () {
Navigator.push( showDialog(
context, context: context,
MaterialPageRoute(builder: (context) { builder: (BuildContext context) {
return GenerateWalletsScreen(); return addNewDerivation(context, 1);
}), });
);
}, },
child: Container( child: Container(
height: 40.0, height: 40.0,
@ -63,7 +64,7 @@ class WalletsHome extends StatelessWidget {
return GenerateWalletsScreen(); return GenerateWalletsScreen();
}), }),
), ),
child: Text('Générer un portefeuille', child: Text('Générer un trousseau',
style: TextStyle(fontSize: 20))), style: TextStyle(fontSize: 20))),
SizedBox(height: 15), SizedBox(height: 15),
Center( Center(
@ -86,32 +87,94 @@ class WalletsHome extends StatelessWidget {
} }
Widget myWalletsList(BuildContext context) { Widget myWalletsList(BuildContext context) {
MyWalletsProvider myWalletProvider = MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context); Provider.of<MyWalletsProvider>(context);
List _listWallets = []; final bool isWalletsExists = _myWalletProvider.checkIfWalletExist();
myWalletProvider.listWallets.forEach((_name, _pubkey) {
_listWallets.add(_name);
});
return Column(children: <Widget>[ if (!isWalletsExists) {
return Text('');
}
if (_myWalletProvider.listWallets == '') {
return Expanded(
child: Center(
child: Text(
'Veuillez générer votre premier portefeuille',
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w500),
)));
}
List _listWallets = _myWalletProvider.listWallets.split('\n');
return Expanded(
child: ListView(children: <Widget>[
SizedBox(height: 8), SizedBox(height: 8),
for (String _repository in _listWallets) for (String _repository in _listWallets)
ListTile( ListTile(
contentPadding: const EdgeInsets.all(5.0), contentPadding: const EdgeInsets.only(left: 7.0),
leading: Padding( leading: Padding(
padding: const EdgeInsets.all(15.0), padding: const EdgeInsets.all(6.0),
child: Text("0 Ğ1", style: TextStyle(fontSize: 14.0))), child: Text("0 Ğ1", style: TextStyle(fontSize: 14.0))),
title: Text(_repository, style: TextStyle(fontSize: 16.0)), // subtitle: Text(_repository.split(':')[3],
subtitle: Text(myWalletProvider.listWallets[_repository], // style: TextStyle(fontSize: 12.0, fontFamily: 'Monospace')),
style: TextStyle(fontSize: 11.0)), title:
Text(_repository.split(':')[1], style: TextStyle(fontSize: 16.0)),
dense: true, dense: true,
onTap: () { onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) { Navigator.push(context, MaterialPageRoute(builder: (context) {
return WalletOptions(walletName: _repository); return WalletOptions(
walletNbr: int.parse(_repository.split(':')[0]),
walletName: _repository.split(':')[1],
derivation: int.parse(_repository.split(':')[2]));
})); }));
}, },
) )
]); ]));
}
Widget addNewDerivation(context, int _walletNbr) {
final TextEditingController _newDerivationName = TextEditingController();
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context);
return AlertDialog(
content: Stack(
overflow: Overflow.visible,
children: <Widget>[
Form(
key: _derivationKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('Nom du portefeuille:'),
Padding(
padding: EdgeInsets.all(8.0),
child: TextFormField(
controller: _newDerivationName,
textAlign: TextAlign.center,
autofocus: true,
),
),
SizedBox(height: 20),
Padding(
padding: const EdgeInsets.all(8.0),
child: RaisedButton(
child: Text("Créer"),
color: Color(0xffFFD68E),
onPressed: () async {
await _myWalletProvider
.generateNewDerivation(
context, _newDerivationName.text, _walletNbr)
.then((_) => _newDerivationName.text == '');
},
),
)
],
),
),
],
),
);
} }
} }

View File

@ -42,9 +42,9 @@ class SettingsScreen extends StatelessWidget {
.redAccent, //Color(0xffFFD68E), // background .redAccent, //Color(0xffFFD68E), // background
onPrimary: Colors.black, // foreground onPrimary: Colors.black, // foreground
), ),
onPressed: () => { onPressed: () async => {
print('Suppression de tous les wallets'), print('Suppression de tous les wallets'),
_myWallets.deleteAllWallet(context) await _myWallets.deleteAllWallet(context)
}, },
child: Text( child: Text(
"EFFACER TOUS MES PORTEFEUILLES, LE TEMPS DE L'ALPHA", "EFFACER TOUS MES PORTEFEUILLES, LE TEMPS DE L'ALPHA",