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;
|
||||
|
||||
TextEditingController mnemonicController = TextEditingController();
|
||||
TextEditingController pubkey = TextEditingController();
|
||||
TextEditingController pin = TextEditingController();
|
||||
|
||||
Future storeWallet(NewWallet wallet, _name, BuildContext context) async {
|
||||
final Directory walletNameDirectory =
|
||||
Directory('${walletsDirectory.path}/$_name');
|
||||
final walletFile = File('${walletNameDirectory.path}/wallet.dewif');
|
||||
Future storeWallet(NewWallet wallet, String _name, BuildContext context,
|
||||
{bool isHD = false}) async {
|
||||
int nbrWallet = 0;
|
||||
Directory walletNbrDirectory;
|
||||
do {
|
||||
nbrWallet++;
|
||||
walletNbrDirectory = Directory('${walletsDirectory.path}/$nbrWallet');
|
||||
} while (await walletNbrDirectory.exists());
|
||||
|
||||
if (await walletNameDirectory.exists()) {
|
||||
print('Ce wallet existe déjà, impossible de le créer.');
|
||||
_showWalletExistDialog(context);
|
||||
return 'Exist: DENY';
|
||||
final walletFile = File('${walletNbrDirectory.path}/wallet.dewif');
|
||||
|
||||
await walletNbrDirectory.create();
|
||||
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);
|
||||
// notifyListeners();
|
||||
|
@ -105,35 +113,6 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
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 {
|
||||
try {
|
||||
generatedMnemonic = await DubpRust.genMnemonic(language: Language.french);
|
||||
|
|
|
@ -33,16 +33,10 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
// int i = 0;
|
||||
walletsDirectory
|
||||
.listSync(recursive: false, followLinks: false)
|
||||
.forEach((wallet) {
|
||||
String _name = wallet.path.split('/').last;
|
||||
List _pubkeyList = File(wallet.path + '/pubkey').readAsLinesSync();
|
||||
String _pubkey = _pubkeyList[0];
|
||||
listWallets[_name] = _pubkey;
|
||||
// i++;
|
||||
|
||||
// for (var _wallets in listWallets) {
|
||||
// _wallets.pubkey =
|
||||
// }
|
||||
.forEach((_wallet) {
|
||||
File('${_wallet.path}/config.txt').readAsLinesSync().forEach((element) {
|
||||
listWallets[int.parse(element.split(':')[0])] = element.split(':')[1];
|
||||
});
|
||||
});
|
||||
return listWallets;
|
||||
}
|
||||
|
@ -72,8 +66,8 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
MyWalletsProvider _myWalletProvider =
|
||||
Provider.of<MyWalletsProvider>(context);
|
||||
return AlertDialog(
|
||||
title: Text(
|
||||
'Êtes-vous sûr de vouloir supprimer tous vos trousseaux ?'),
|
||||
title:
|
||||
Text('Êtes-vous sûr de vouloir supprimer tous vos trousseaux ?'),
|
||||
content: SingleChildScrollView(child: Text('')),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
|
|
|
@ -15,7 +15,7 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
|
||||
Future<NewWallet> get badWallet => null;
|
||||
|
||||
Future _getPubkeyFromDewif(_dewif, _pin, _pinLenght) async {
|
||||
Future _getPubkeyFromDewif(_dewif, _pin, _pinLenght, {derivation}) async {
|
||||
String _pubkey;
|
||||
RegExp regExp = new RegExp(
|
||||
r'^[A-Z0-9]+$',
|
||||
|
@ -30,7 +30,9 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
return 'false';
|
||||
}
|
||||
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;
|
||||
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;
|
||||
try {
|
||||
File _walletFile = File('${walletsDirectory.path}/$_name/wallet.dewif');
|
||||
File _walletFile =
|
||||
File('${walletsDirectory.path}/$_walletNbr/wallet.dewif');
|
||||
String _localDewif = await _walletFile.readAsString();
|
||||
String _localPubkey;
|
||||
|
||||
|
@ -79,8 +83,9 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
int getPinLenght(_name) {
|
||||
File _walletFile = File('${walletsDirectory.path}/$_name/wallet.dewif');
|
||||
int getPinLenght(_walletNbr) {
|
||||
File _walletFile =
|
||||
File('${walletsDirectory.path}/$_walletNbr/wallet.dewif');
|
||||
String _localDewif = _walletFile.readAsStringSync();
|
||||
|
||||
final int _pinLenght = DubpRust.getDewifSecretCodeLen(
|
||||
|
|
|
@ -11,8 +11,10 @@ import 'package:flutter/services.dart';
|
|||
|
||||
// ignore: must_be_immutable
|
||||
class WalletOptions extends StatelessWidget with ChangeNotifier {
|
||||
WalletOptions({Key keyMyWallets, @required this.walletName})
|
||||
WalletOptions(
|
||||
{Key keyMyWallets, @required this.walletNbr, @required this.walletName})
|
||||
: super(key: keyMyWallets);
|
||||
int walletNbr;
|
||||
String walletName;
|
||||
|
||||
StreamController<ErrorAnimationType> errorController;
|
||||
|
@ -34,7 +36,7 @@ class WalletOptions extends StatelessWidget with ChangeNotifier {
|
|||
errorController = StreamController<ErrorAnimationType>();
|
||||
// _walletOptions.isWalletUnlock = false;
|
||||
|
||||
final int _pinLenght = _walletOptions.getPinLenght(this.walletName);
|
||||
final int _pinLenght = _walletOptions.getPinLenght(this.walletNbr);
|
||||
|
||||
return WillPopScope(
|
||||
onWillPop: () {
|
||||
|
@ -244,6 +246,7 @@ class WalletOptions extends StatelessWidget with ChangeNotifier {
|
|||
print("Completed");
|
||||
final resultWallet =
|
||||
await _walletOptions.readLocalWallet(
|
||||
this.walletNbr,
|
||||
this.walletName,
|
||||
_pin.toUpperCase(),
|
||||
_pinLenght);
|
||||
|
|
|
@ -90,8 +90,8 @@ class WalletsHome extends StatelessWidget {
|
|||
Provider.of<MyWalletsProvider>(context);
|
||||
|
||||
List _listWallets = [];
|
||||
myWalletProvider.listWallets.forEach((_name, _pubkey) {
|
||||
_listWallets.add(_name);
|
||||
myWalletProvider.listWallets.forEach((_nbr, _name) {
|
||||
_listWallets.add('$_nbr:$_name');
|
||||
});
|
||||
|
||||
return Column(children: <Widget>[
|
||||
|
@ -102,13 +102,14 @@ class WalletsHome extends StatelessWidget {
|
|||
leading: Padding(
|
||||
padding: const EdgeInsets.all(15.0),
|
||||
child: Text("0 Ğ1", style: TextStyle(fontSize: 14.0))),
|
||||
title: Text(_repository, style: TextStyle(fontSize: 16.0)),
|
||||
subtitle: Text(myWalletProvider.listWallets[_repository],
|
||||
style: TextStyle(fontSize: 11.0)),
|
||||
title:
|
||||
Text(_repository.split(':')[1], style: TextStyle(fontSize: 16.0)),
|
||||
dense: true,
|
||||
onTap: () {
|
||||
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