Workflow OK for 1 HD wallet and first derivation only
This commit is contained in:
parent
4bbb7e3915
commit
5ec6b715b0
|
@ -26,23 +26,31 @@ 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;
|
||||||
|
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;
|
||||||
|
await configFile.writeAsString('$nbrWallet:$_name:$_derivationNbr');
|
||||||
|
} else {
|
||||||
|
await configFile.writeAsString('$nbrWallet:$_name');
|
||||||
}
|
}
|
||||||
|
|
||||||
await walletNameDirectory.create();
|
|
||||||
await walletFile.writeAsString('${wallet.dewif}');
|
|
||||||
|
|
||||||
Navigator.pop(context, true);
|
Navigator.pop(context, true);
|
||||||
Navigator.pop(context, true);
|
Navigator.pop(context, true);
|
||||||
// notifyListeners();
|
// notifyListeners();
|
||||||
|
@ -105,35 +113,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);
|
||||||
|
|
|
@ -33,16 +33,10 @@ class MyWalletsProvider with ChangeNotifier {
|
||||||
// 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('${_wallet.path}/config.txt').readAsLinesSync().forEach((element) {
|
||||||
List _pubkeyList = File(wallet.path + '/pubkey').readAsLinesSync();
|
listWallets[int.parse(element.split(':')[0])] = element.split(':')[1];
|
||||||
String _pubkey = _pubkeyList[0];
|
});
|
||||||
listWallets[_name] = _pubkey;
|
|
||||||
// i++;
|
|
||||||
|
|
||||||
// for (var _wallets in listWallets) {
|
|
||||||
// _wallets.pubkey =
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
return listWallets;
|
return listWallets;
|
||||||
}
|
}
|
||||||
|
@ -72,8 +66,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 trousseaux ?'),
|
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(
|
||||||
|
|
|
@ -15,7 +15,7 @@ class WalletOptionsProvider with ChangeNotifier {
|
||||||
|
|
||||||
Future<NewWallet> get badWallet => null;
|
Future<NewWallet> get badWallet => null;
|
||||||
|
|
||||||
Future _getPubkeyFromDewif(_dewif, _pin, _pinLenght) async {
|
Future _getPubkeyFromDewif(_dewif, _pin, _pinLenght, {derivation}) async {
|
||||||
String _pubkey;
|
String _pubkey;
|
||||||
RegExp regExp = new RegExp(
|
RegExp regExp = new RegExp(
|
||||||
r'^[A-Z0-9]+$',
|
r'^[A-Z0-9]+$',
|
||||||
|
@ -30,7 +30,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: [3]);
|
||||||
|
_pubkey = _pubkeysTmp[0];
|
||||||
this.pubkey.text = _pubkey;
|
this.pubkey.text = _pubkey;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
|
@ -50,10 +52,12 @@ class WalletOptionsProvider with ChangeNotifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future readLocalWallet(String _name, String _pin, _pinLenght) async {
|
Future readLocalWallet(
|
||||||
|
int _walletNbr, String _name, String _pin, _pinLenght) 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;
|
||||||
|
|
||||||
|
@ -79,8 +83,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(
|
||||||
|
|
|
@ -11,8 +11,10 @@ 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})
|
||||||
: super(key: keyMyWallets);
|
: super(key: keyMyWallets);
|
||||||
|
int walletNbr;
|
||||||
String walletName;
|
String walletName;
|
||||||
|
|
||||||
StreamController<ErrorAnimationType> errorController;
|
StreamController<ErrorAnimationType> errorController;
|
||||||
|
@ -34,7 +36,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: () {
|
||||||
|
@ -244,6 +246,7 @@ 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);
|
||||||
|
|
|
@ -90,8 +90,8 @@ class WalletsHome extends StatelessWidget {
|
||||||
Provider.of<MyWalletsProvider>(context);
|
Provider.of<MyWalletsProvider>(context);
|
||||||
|
|
||||||
List _listWallets = [];
|
List _listWallets = [];
|
||||||
myWalletProvider.listWallets.forEach((_name, _pubkey) {
|
myWalletProvider.listWallets.forEach((_nbr, _name) {
|
||||||
_listWallets.add(_name);
|
_listWallets.add('$_nbr:$_name');
|
||||||
});
|
});
|
||||||
|
|
||||||
return Column(children: <Widget>[
|
return Column(children: <Widget>[
|
||||||
|
@ -102,13 +102,14 @@ class WalletsHome extends StatelessWidget {
|
||||||
leading: Padding(
|
leading: Padding(
|
||||||
padding: const EdgeInsets.all(15.0),
|
padding: const EdgeInsets.all(15.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)),
|
title:
|
||||||
subtitle: Text(myWalletProvider.listWallets[_repository],
|
Text(_repository.split(':')[1], style: TextStyle(fontSize: 16.0)),
|
||||||
style: TextStyle(fontSize: 11.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]);
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue