Add list of wallets; Delete the wallet on click;
This commit is contained in:
parent
056198587d
commit
0e8b1cad44
|
@ -9,11 +9,13 @@ import 'dart:async';
|
|||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class GenerateWalletScreen extends StatefulWidget {
|
||||
const GenerateWalletScreen({Key keyGenWallet}) : super(key: keyGenWallet);
|
||||
@override
|
||||
_GenerateWalletState createState() => _GenerateWalletState();
|
||||
GenerateWalletState createState() => GenerateWalletState();
|
||||
}
|
||||
|
||||
class _GenerateWalletState extends State<GenerateWalletScreen> {
|
||||
class GenerateWalletState extends State<GenerateWalletScreen> {
|
||||
GlobalKey<MyWalletState> _keyWallets = GlobalKey();
|
||||
void initState() {
|
||||
super.initState();
|
||||
DubpRust.setup();
|
||||
|
@ -60,7 +62,7 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
|
|||
body: SafeArea(
|
||||
child: Column(children: <Widget>[
|
||||
FutureBuilder<bool>(
|
||||
future: checkIfWalletExist(),
|
||||
future: checkIfWalletExist('tata'),
|
||||
builder: (context, fSnapshot) {
|
||||
if (fSnapshot.hasData)
|
||||
return Visibility(
|
||||
|
@ -95,11 +97,12 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
|
|||
return Center(child: CircularProgressIndicator());
|
||||
}),
|
||||
FutureBuilder<bool>(
|
||||
future: checkIfWalletExist(),
|
||||
future: checkIfWalletExist('tata'),
|
||||
builder: (context, fSnapshot) {
|
||||
if (fSnapshot.hasData)
|
||||
return Visibility(
|
||||
visible: fSnapshot.data, child: MyWalletsScreen());
|
||||
visible: fSnapshot.data,
|
||||
child: MyWalletsScreen(keyWallets: _keyWallets));
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}),
|
||||
SizedBox(height: 8),
|
||||
|
@ -250,10 +253,11 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
|
|||
return actualWallet;
|
||||
}
|
||||
|
||||
Future<bool> checkIfWalletExist() async {
|
||||
Future<bool> checkIfWalletExist(_name) async {
|
||||
final appPath = await _localPath;
|
||||
final _walletFile = File('$appPath/wallets/$_name/wallet.dewif');
|
||||
|
||||
// deleteWallet();
|
||||
final _walletFile = await _localWallet;
|
||||
// final isExist = File(_walletFile.toString()).existsSync();
|
||||
print(_walletFile.path);
|
||||
final isExist = await File(_walletFile.path).exists();
|
||||
print('Wallet existe ? : ' + isExist.toString());
|
||||
|
@ -268,27 +272,10 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
|
|||
|
||||
Future importWallet() async {}
|
||||
|
||||
Future<int> deleteWallet() async {
|
||||
try {
|
||||
final _walletFile = await _localWallet;
|
||||
|
||||
await _walletFile.delete();
|
||||
} catch (e) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> get _localPath async {
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
|
||||
return directory.path;
|
||||
}
|
||||
|
||||
Future<File> get _localWallet async {
|
||||
// /data/user/0/com.example.gecko/app_flutter/wallet.dewif
|
||||
final path = await _localPath;
|
||||
return File('$path/wallet.dewif');
|
||||
}
|
||||
}
|
||||
|
||||
/* *** ValidStoreWalletScreen Class *** */
|
||||
|
@ -318,6 +305,8 @@ class _ValidStoreWalletScreen extends State<ValidStoreWalletScreen> {
|
|||
TextEditingController _mnemonicController = new TextEditingController();
|
||||
TextEditingController _pubkey = new TextEditingController();
|
||||
TextEditingController _pin = new TextEditingController();
|
||||
String walletName = 'tata';
|
||||
List _listWallets = [];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -355,21 +344,45 @@ class _ValidStoreWalletScreen extends State<ValidStoreWalletScreen> {
|
|||
}
|
||||
|
||||
Future storeWallet() async {
|
||||
final walletFile = await _localWallet;
|
||||
final appPath = await _localPath;
|
||||
final walletFile = File('$appPath/wallets/${this.walletName}/wallet.dewif');
|
||||
|
||||
final isExist = await Directory('$appPath/wallets').exists();
|
||||
if (isExist == false) {
|
||||
new Directory('$appPath/wallets').createSync();
|
||||
}
|
||||
|
||||
new Directory('$appPath/wallets/${this.walletName}').createSync();
|
||||
walletFile.writeAsString('${widget.generatedWallet.dewif}');
|
||||
_pin.clear();
|
||||
|
||||
await getAllWalletsNames();
|
||||
Navigator.pop(context, true);
|
||||
FocusScope.of(context).unfocus();
|
||||
|
||||
return this.walletName;
|
||||
}
|
||||
|
||||
Future<String> get _localPath async {
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
|
||||
return directory.path;
|
||||
}
|
||||
|
||||
Future<File> get _localWallet async {
|
||||
final path = await _localPath;
|
||||
return File('$path/wallet.dewif');
|
||||
Future<List> 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);
|
||||
});
|
||||
|
||||
return _listWallets;
|
||||
// final _local = await _appPath.path.list().toList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:gecko/ui/generateWallets.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:dubp/dubp.dart';
|
||||
|
@ -8,22 +9,35 @@ import 'package:path_provider/path_provider.dart';
|
|||
import 'package:pin_code_fields/pin_code_fields.dart';
|
||||
|
||||
class MyWalletsScreen extends StatefulWidget {
|
||||
const MyWalletsScreen({Key keyWallets}) : super(key: keyWallets);
|
||||
@override
|
||||
_MyWalletState createState() => _MyWalletState();
|
||||
MyWalletState createState() => MyWalletState();
|
||||
}
|
||||
|
||||
class _MyWalletState extends State<MyWalletsScreen> {
|
||||
class MyWalletState extends State<MyWalletsScreen> {
|
||||
GlobalKey<GenerateWalletState> _keyGenWallet = GlobalKey();
|
||||
StreamController<ErrorAnimationType> errorController;
|
||||
Directory appPath;
|
||||
List _listWallets = [];
|
||||
|
||||
void initState() {
|
||||
super.initState();
|
||||
errorController = StreamController<ErrorAnimationType>();
|
||||
initAppDirectory();
|
||||
DubpRust.setup();
|
||||
// initAppDirectory();
|
||||
// _walletsList = await getAllWalletsNames();
|
||||
// HistoryScreen(
|
||||
// keyHistory: _keyHistory,
|
||||
// );
|
||||
}
|
||||
|
||||
void initAppDirectory() async {
|
||||
appPath = await getApplicationDocumentsDirectory();
|
||||
appPath = Directory('${appPath.path}/wallets');
|
||||
_listWallets = getAllWalletsNames();
|
||||
}
|
||||
|
||||
TextEditingController _pubkey = new TextEditingController();
|
||||
TextEditingController _enterPin = new TextEditingController();
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
@ -34,9 +48,20 @@ class _MyWalletState extends State<MyWalletsScreen> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// final _walletsList = getAllWalletsNames();
|
||||
return SafeArea(
|
||||
child: Column(children: <Widget>[
|
||||
SizedBox(height: 8),
|
||||
for (var repository in this._listWallets)
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.all(5.0),
|
||||
leading: Text(repository, style: TextStyle(fontSize: 14.0)),
|
||||
title: Text(repository, style: TextStyle(fontSize: 14.0)),
|
||||
subtitle: Text(repository, style: TextStyle(fontSize: 14.0)),
|
||||
dense: true,
|
||||
onTap: () {
|
||||
openWalletOptions(repository);
|
||||
}),
|
||||
InkWell(
|
||||
child: TextField(
|
||||
enabled: false,
|
||||
|
@ -160,6 +185,53 @@ class _MyWalletState extends State<MyWalletsScreen> {
|
|||
}
|
||||
}
|
||||
|
||||
// Future<bool> checkIfWalletExist(_name) async {
|
||||
// final appPath = await _localPath;
|
||||
// final _walletFile = File('$appPath/$_name/wallet.dewif');
|
||||
|
||||
// // deleteWallet();
|
||||
// print(_walletFile.path);
|
||||
// final isExist = await File(_walletFile.path).exists();
|
||||
// print('Wallet existe ? : ' + isExist.toString());
|
||||
// print('Is wallet generated ? : ' + walletIsGenerated.toString());
|
||||
// if (isExist == true) {
|
||||
// print('Un wallet existe !');
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
List getAllWalletsNames() {
|
||||
// final _appPath = await getApplicationDocumentsDirectory();
|
||||
// List _listWallets = [];
|
||||
// _listWallets.add('tortuuue');
|
||||
this._listWallets.clear();
|
||||
print(this.appPath);
|
||||
|
||||
this
|
||||
.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();
|
||||
}
|
||||
|
||||
Future openWalletOptions(_name) async {
|
||||
deleteWallet(_name);
|
||||
// getAllWalletsNames();
|
||||
// setState(() {});
|
||||
// GenerateWalletScreen(keyGenWallet: _keyGenWallet);
|
||||
// _keyGenWallet.currentState.setState(() {
|
||||
// getAllWalletsNames();
|
||||
// });
|
||||
}
|
||||
|
||||
Future readLocalWallet(String _pin) async {
|
||||
// print(pin);
|
||||
try {
|
||||
|
@ -186,9 +258,20 @@ class _MyWalletState extends State<MyWalletsScreen> {
|
|||
}
|
||||
}
|
||||
|
||||
Future<int> deleteWallet(_name) async {
|
||||
try {
|
||||
final appPath = await _localPath;
|
||||
final _walletFile = File('$appPath/wallets/$_name/wallet.dewif');
|
||||
|
||||
await _walletFile.delete();
|
||||
return 0;
|
||||
} catch (e) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> get _localPath async {
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
|
||||
return directory.path;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue