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';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
class GenerateWalletScreen extends StatefulWidget {
|
class GenerateWalletScreen extends StatefulWidget {
|
||||||
|
const GenerateWalletScreen({Key keyGenWallet}) : super(key: keyGenWallet);
|
||||||
@override
|
@override
|
||||||
_GenerateWalletState createState() => _GenerateWalletState();
|
GenerateWalletState createState() => GenerateWalletState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _GenerateWalletState extends State<GenerateWalletScreen> {
|
class GenerateWalletState extends State<GenerateWalletScreen> {
|
||||||
|
GlobalKey<MyWalletState> _keyWallets = GlobalKey();
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
DubpRust.setup();
|
DubpRust.setup();
|
||||||
|
@ -60,7 +62,7 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: Column(children: <Widget>[
|
child: Column(children: <Widget>[
|
||||||
FutureBuilder<bool>(
|
FutureBuilder<bool>(
|
||||||
future: checkIfWalletExist(),
|
future: checkIfWalletExist('tata'),
|
||||||
builder: (context, fSnapshot) {
|
builder: (context, fSnapshot) {
|
||||||
if (fSnapshot.hasData)
|
if (fSnapshot.hasData)
|
||||||
return Visibility(
|
return Visibility(
|
||||||
|
@ -95,11 +97,12 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
|
||||||
return Center(child: CircularProgressIndicator());
|
return Center(child: CircularProgressIndicator());
|
||||||
}),
|
}),
|
||||||
FutureBuilder<bool>(
|
FutureBuilder<bool>(
|
||||||
future: checkIfWalletExist(),
|
future: checkIfWalletExist('tata'),
|
||||||
builder: (context, fSnapshot) {
|
builder: (context, fSnapshot) {
|
||||||
if (fSnapshot.hasData)
|
if (fSnapshot.hasData)
|
||||||
return Visibility(
|
return Visibility(
|
||||||
visible: fSnapshot.data, child: MyWalletsScreen());
|
visible: fSnapshot.data,
|
||||||
|
child: MyWalletsScreen(keyWallets: _keyWallets));
|
||||||
return Center(child: CircularProgressIndicator());
|
return Center(child: CircularProgressIndicator());
|
||||||
}),
|
}),
|
||||||
SizedBox(height: 8),
|
SizedBox(height: 8),
|
||||||
|
@ -250,10 +253,11 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
|
||||||
return actualWallet;
|
return actualWallet;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> checkIfWalletExist() async {
|
Future<bool> checkIfWalletExist(_name) async {
|
||||||
|
final appPath = await _localPath;
|
||||||
|
final _walletFile = File('$appPath/wallets/$_name/wallet.dewif');
|
||||||
|
|
||||||
// deleteWallet();
|
// deleteWallet();
|
||||||
final _walletFile = await _localWallet;
|
|
||||||
// final isExist = File(_walletFile.toString()).existsSync();
|
|
||||||
print(_walletFile.path);
|
print(_walletFile.path);
|
||||||
final isExist = await File(_walletFile.path).exists();
|
final isExist = await File(_walletFile.path).exists();
|
||||||
print('Wallet existe ? : ' + isExist.toString());
|
print('Wallet existe ? : ' + isExist.toString());
|
||||||
|
@ -268,27 +272,10 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
|
||||||
|
|
||||||
Future importWallet() async {}
|
Future importWallet() async {}
|
||||||
|
|
||||||
Future<int> deleteWallet() async {
|
|
||||||
try {
|
|
||||||
final _walletFile = await _localWallet;
|
|
||||||
|
|
||||||
await _walletFile.delete();
|
|
||||||
} catch (e) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<String> get _localPath async {
|
Future<String> get _localPath async {
|
||||||
final directory = await getApplicationDocumentsDirectory();
|
final directory = await getApplicationDocumentsDirectory();
|
||||||
|
|
||||||
return directory.path;
|
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 *** */
|
/* *** ValidStoreWalletScreen Class *** */
|
||||||
|
@ -318,6 +305,8 @@ class _ValidStoreWalletScreen extends State<ValidStoreWalletScreen> {
|
||||||
TextEditingController _mnemonicController = new TextEditingController();
|
TextEditingController _mnemonicController = new TextEditingController();
|
||||||
TextEditingController _pubkey = new TextEditingController();
|
TextEditingController _pubkey = new TextEditingController();
|
||||||
TextEditingController _pin = new TextEditingController();
|
TextEditingController _pin = new TextEditingController();
|
||||||
|
String walletName = 'tata';
|
||||||
|
List _listWallets = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -355,21 +344,45 @@ class _ValidStoreWalletScreen extends State<ValidStoreWalletScreen> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future storeWallet() async {
|
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}');
|
walletFile.writeAsString('${widget.generatedWallet.dewif}');
|
||||||
_pin.clear();
|
_pin.clear();
|
||||||
|
|
||||||
|
await getAllWalletsNames();
|
||||||
Navigator.pop(context, true);
|
Navigator.pop(context, true);
|
||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
|
|
||||||
|
return this.walletName;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> get _localPath async {
|
Future<String> get _localPath async {
|
||||||
final directory = await getApplicationDocumentsDirectory();
|
final directory = await getApplicationDocumentsDirectory();
|
||||||
|
|
||||||
return directory.path;
|
return directory.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<File> get _localWallet async {
|
Future<List> getAllWalletsNames() async {
|
||||||
final path = await _localPath;
|
final _appPath = await getApplicationDocumentsDirectory();
|
||||||
return File('$path/wallet.dewif');
|
// 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/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:dubp/dubp.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';
|
import 'package:pin_code_fields/pin_code_fields.dart';
|
||||||
|
|
||||||
class MyWalletsScreen extends StatefulWidget {
|
class MyWalletsScreen extends StatefulWidget {
|
||||||
|
const MyWalletsScreen({Key keyWallets}) : super(key: keyWallets);
|
||||||
@override
|
@override
|
||||||
_MyWalletState createState() => _MyWalletState();
|
MyWalletState createState() => MyWalletState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MyWalletState extends State<MyWalletsScreen> {
|
class MyWalletState extends State<MyWalletsScreen> {
|
||||||
|
GlobalKey<GenerateWalletState> _keyGenWallet = GlobalKey();
|
||||||
StreamController<ErrorAnimationType> errorController;
|
StreamController<ErrorAnimationType> errorController;
|
||||||
|
Directory appPath;
|
||||||
|
List _listWallets = [];
|
||||||
|
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
errorController = StreamController<ErrorAnimationType>();
|
errorController = StreamController<ErrorAnimationType>();
|
||||||
|
initAppDirectory();
|
||||||
DubpRust.setup();
|
DubpRust.setup();
|
||||||
|
// initAppDirectory();
|
||||||
|
// _walletsList = await getAllWalletsNames();
|
||||||
// HistoryScreen(
|
// HistoryScreen(
|
||||||
// keyHistory: _keyHistory,
|
// keyHistory: _keyHistory,
|
||||||
// );
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initAppDirectory() async {
|
||||||
|
appPath = await getApplicationDocumentsDirectory();
|
||||||
|
appPath = Directory('${appPath.path}/wallets');
|
||||||
|
_listWallets = getAllWalletsNames();
|
||||||
|
}
|
||||||
|
|
||||||
TextEditingController _pubkey = new TextEditingController();
|
TextEditingController _pubkey = new TextEditingController();
|
||||||
TextEditingController _enterPin = new TextEditingController();
|
TextEditingController _enterPin = new TextEditingController();
|
||||||
final formKey = GlobalKey<FormState>();
|
final formKey = GlobalKey<FormState>();
|
||||||
|
@ -34,9 +48,20 @@ class _MyWalletState extends State<MyWalletsScreen> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
// final _walletsList = getAllWalletsNames();
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: Column(children: <Widget>[
|
child: Column(children: <Widget>[
|
||||||
SizedBox(height: 8),
|
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(
|
InkWell(
|
||||||
child: TextField(
|
child: TextField(
|
||||||
enabled: false,
|
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 {
|
Future readLocalWallet(String _pin) async {
|
||||||
// print(pin);
|
// print(pin);
|
||||||
try {
|
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 {
|
Future<String> get _localPath async {
|
||||||
final directory = await getApplicationDocumentsDirectory();
|
final directory = await getApplicationDocumentsDirectory();
|
||||||
|
|
||||||
return directory.path;
|
return directory.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue