Big work in progress in My wallet tab;

This commit is contained in:
poka 2021-01-10 07:49:29 +01:00
parent 60c9d00c61
commit 056198587d
4 changed files with 247 additions and 197 deletions

View File

@ -1,3 +1,4 @@
import 'package:gecko/ui/myWallets.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';
@ -33,74 +34,136 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SafeArea( return Scaffold(
child: Column(children: <Widget>[ floatingActionButton: Container(
SizedBox(height: 8), height: 80.0,
Text( width: 80.0,
'Clé publique:', child: FittedBox(
style: TextStyle( child: FloatingActionButton(
fontSize: 15.0, heroTag: "buttonGenerateWallet",
color: Colors.grey[600], onPressed: () async {
fontWeight: FontWeight.w400), await generateMnemonic();
), // print(resultScan);
TextField( // if (resultScan != 'false') {
enabled: false, // onTabTapped(0);
controller: this._pubkey, // }
maxLines: 1, },
textAlign: TextAlign.center, child: Container(
decoration: InputDecoration(), height: 40.0,
style: TextStyle( width: 40.0,
fontSize: 14.0, child: Icon(Icons.person_add_alt_1_rounded)),
color: Colors.black, backgroundColor: Color(
fontWeight: FontWeight.bold)), 0xffEFEFBF), //Color(0xffFFD68E), //Color.fromARGB(500, 204, 255, 255),
SizedBox(height: 8), ),
Text(
'Phrase secrète:',
style: TextStyle(
fontSize: 15.0,
color: Colors.grey[600],
fontWeight: FontWeight.w400),
),
TextField(
enabled: false,
controller: this._mnemonicController,
maxLines: 3,
textAlign: TextAlign.center,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(15.0),
), ),
style: TextStyle( ),
fontSize: 22.0, body: SafeArea(
color: Colors.black, child: Column(children: <Widget>[
fontWeight: FontWeight.w400)), FutureBuilder<bool>(
SizedBox(height: 8), future: checkIfWalletExist(),
Text( builder: (context, fSnapshot) {
'Code PIN:', if (fSnapshot.hasData)
style: TextStyle( return Visibility(
fontSize: 15.0, visible: (!fSnapshot.data && !walletIsGenerated),
color: Colors.grey[600], child: Column(children: <Widget>[
fontWeight: FontWeight.w400), SizedBox(height: 80),
), Center(
TextField( child: Text(
enabled: false, "Vous n'avez encore généré aucun portefeuille.",
controller: this._pin, style: TextStyle(
maxLines: 1, fontSize: 20, fontWeight: FontWeight.w500),
textAlign: TextAlign.center, textAlign: TextAlign.center)),
decoration: InputDecoration(), SizedBox(height: 50),
style: TextStyle( RaisedButton(
fontSize: 30.0, color: Color(0xffFFD68E),
color: Colors.black, onPressed: () => generateMnemonic(),
fontWeight: FontWeight.bold)), child: Text('Générer un portefeuille',
SizedBox(height: 12), style: TextStyle(fontSize: 20))),
new RaisedButton( SizedBox(height: 15),
color: Color(0xffFFD68E), Center(
onPressed: () => generateMnemonic(), child: Text("ou",
child: Text('Générer un wallet', style: TextStyle(fontSize: 20))), style: TextStyle(
SizedBox(height: 30), fontSize: 20, fontWeight: FontWeight.w500),
Expanded( textAlign: TextAlign.center)),
child: Align( SizedBox(height: 15),
alignment: Alignment.bottomCenter, RaisedButton(
child: new RaisedButton( color: Color(0xffFFD68E),
onPressed: () => importWallet(),
child: Text('Importer un portefeuille existant',
style: TextStyle(fontSize: 20))),
])); // WelcomeWalletScreen());
return Center(child: CircularProgressIndicator());
}),
FutureBuilder<bool>(
future: checkIfWalletExist(),
builder: (context, fSnapshot) {
if (fSnapshot.hasData)
return Visibility(
visible: fSnapshot.data, child: MyWalletsScreen());
return Center(child: CircularProgressIndicator());
}),
SizedBox(height: 8),
Visibility(
visible: walletIsGenerated,
child: Column(children: <Widget>[
Text(
'Clé publique:',
style: TextStyle(
fontSize: 15.0,
color: Colors.grey[600],
fontWeight: FontWeight.w400),
),
TextField(
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: 8),
Text(
'Phrase de restauration:',
style: TextStyle(
fontSize: 15.0,
color: Colors.grey[600],
fontWeight: FontWeight.w400),
),
TextField(
enabled: false,
controller: this._mnemonicController,
maxLines: 3,
textAlign: TextAlign.center,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(15.0),
),
style: TextStyle(
fontSize: 22.0,
color: Colors.black,
fontWeight: FontWeight.w400)),
SizedBox(height: 8),
Text(
'Code secret:',
style: TextStyle(
fontSize: 15.0,
color: Colors.grey[600],
fontWeight: FontWeight.w400),
),
TextField(
enabled: false,
controller: this._pin,
maxLines: 1,
textAlign: TextAlign.center,
decoration: InputDecoration(),
style: TextStyle(
fontSize: 30.0,
color: Colors.black,
fontWeight: FontWeight.bold)),
SizedBox(height: 12),
// Expanded(child: Align(alignment: Alignment.bottomCenter)),
new RaisedButton(
color: Color(0xffFFD68E), color: Color(0xffFFD68E),
onPressed: walletIsGenerated onPressed: walletIsGenerated
? () { ? () {
@ -112,6 +175,8 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
generatedWallet: this.actualWallet); generatedWallet: this.actualWallet);
}), }),
).then((value) => setState(() { ).then((value) => setState(() {
print(
'TODO: Fix error null boolean ?'); //TODO: Fix error null boolean
if (value) { if (value) {
_pin.clear(); _pin.clear();
_mnemonicController.clear(); _mnemonicController.clear();
@ -124,9 +189,21 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
} }
: null, : null,
child: Text('Enregistrer ce wallet', child: Text('Enregistrer ce wallet',
style: TextStyle(fontSize: 20))))), style: TextStyle(fontSize: 20))),
SizedBox(height: 15) SizedBox(height: 20)
])); ]),
// Visibility(
// visible: walletIsGenerated,
// child: Text("""
// Notez bien votre phrase de restauration sur un papier ou imprimez le, ainsi que votre code secret, que vous devrez retenir.
// Pour payer ou manipuler votre wallet, seul votre code secret vous sera nécessaire.
// Votre phrase de restauration quant à elle, constitué de 12 mots, vous permet de restaurer votre wallet sur un autre appareil. Gardez la précieusement, en lieu sûr.
// """,
// style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
// textAlign: TextAlign.center),
// )
)
])));
} }
Future generateMnemonic() async { Future generateMnemonic() async {
@ -144,13 +221,16 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
} }
this.actualWallet = await generateWallet(this.generatedMnemonic); this.actualWallet = await generateWallet(this.generatedMnemonic);
this.walletIsGenerated = true; this.walletIsGenerated = true;
// await checkIfWalletExist();
return this.generatedMnemonic; return this.generatedMnemonic;
} }
Future generateWallet(generatedMnemonic) async { Future generateWallet(generatedMnemonic) async {
try { try {
this.actualWallet = await DubpRust.genWalletFromMnemonic( this.actualWallet = await DubpRust.genWalletFromMnemonic(
language: Language.french, mnemonic: generatedMnemonic); language: Language.french,
mnemonic: generatedMnemonic,
secretCodeType: SecretCodeType.letters);
} catch (e, stack) { } catch (e, stack) {
print(e); print(e);
if (kReleaseMode) { if (kReleaseMode) {
@ -169,8 +249,50 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
return actualWallet; return actualWallet;
} }
Future<bool> checkIfWalletExist() async {
// 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());
print('Is wallet generated ? : ' + walletIsGenerated.toString());
if (isExist == true) {
print('Un wallet existe !');
return true;
} else {
return false;
}
}
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 *** */
class ValidStoreWalletScreen extends StatefulWidget { class ValidStoreWalletScreen extends StatefulWidget {
final String generatedMnemonic; final String generatedMnemonic;
final NewWallet generatedWallet; final NewWallet generatedWallet;
@ -225,83 +347,14 @@ class _ValidStoreWalletScreen extends State<ValidStoreWalletScreen> {
fontWeight: FontWeight.bold)), fontWeight: FontWeight.bold)),
new RaisedButton( new RaisedButton(
color: Color(0xffFFD68E), color: Color(0xffFFD68E),
onPressed: () => storeWallet(widget.generatedWallet), onPressed: () => storeWallet(),
child: Text('Confirmer', style: TextStyle(fontSize: 20))), child: Text('Confirmer', style: TextStyle(fontSize: 20))),
// Form(
// child: Padding(
// padding:
// const EdgeInsets.symmetric(vertical: 8.0, horizontal: 30),
// child: PinCodeTextField(
// appContext: context,
// pastedTextStyle: TextStyle(
// color: Colors.green.shade600,
// fontWeight: FontWeight.bold,
// ),
// length: 6,
// obscureText: false,
// obscuringCharacter: '*',
// animationType: AnimationType.fade,
// validator: (v) {
// if (v.length < 6) {
// return "Votre code PIN fait 6 caractères";
// } else {
// return null;
// }
// },
// pinTheme: PinTheme(
// shape: PinCodeFieldShape.box,
// borderRadius: BorderRadius.circular(5),
// fieldHeight: 60,
// fieldWidth: 50,
// activeFillColor: hasError ? Colors.orange : Colors.white,
// ),
// cursorColor: Colors.black,
// animationDuration: Duration(milliseconds: 300),
// textStyle: TextStyle(fontSize: 20, height: 1.6),
// backgroundColor: pinColor,
// enableActiveFill: false,
// errorAnimationController: errorController,
// controller: _enterPin,
// keyboardType: TextInputType.text,
// boxShadows: [
// BoxShadow(
// offset: Offset(0, 1),
// color: Colors.black12,
// blurRadius: 10,
// )
// ],
// onCompleted: (v) async {
// print("Completed");
// final resultWallet = await readLocalWallet(v.toUpperCase());
// if (resultWallet == 'bad') {
// errorController.add(ErrorAnimationType
// .shake); // Triggering error shake animation
// setState(() {
// hasError = true;
// pinColor = Colors.red[200];
// });
// } else {
// setState(() {
// pinColor = Colors.green[200];
// });
// }
// },
// onChanged: (value) {
// if (pinColor != Colors.grey[300]) {
// setState(() {
// pinColor = Colors.grey[300];
// });
// }
// print(value);
// },
// )),
// )
]), ]),
), ),
); );
} }
Future storeWallet(actualWallet) async { Future storeWallet() async {
final walletFile = await _localWallet; final walletFile = await _localWallet;
walletFile.writeAsString('${widget.generatedWallet.dewif}'); walletFile.writeAsString('${widget.generatedWallet.dewif}');
_pin.clear(); _pin.clear();

View File

@ -63,31 +63,55 @@ class HistoryScreenState extends State<HistoryScreen> {
print('Build pubkey : ' + pubkey); print('Build pubkey : ' + pubkey);
print('Build this.pubkey : ' + this.pubkey); print('Build this.pubkey : ' + this.pubkey);
print('isBuilding: ' + isBuilding.toString()); print('isBuilding: ' + isBuilding.toString());
return Column(children: <Widget>[ return Scaffold(
SizedBox(height: 8), floatingActionButton: Container(
TextField( height: 80.0,
// Entrée de la pubkey width: 80.0,
onChanged: (text) { child: FittedBox(
print("Clé tappxé: $text"); child: FloatingActionButton(
this.pubkey = text; heroTag: "buttonScan",
isPubkey(text); onPressed: () async {
}, await scan();
controller: this._outputPubkey, // print(resultScan);
maxLines: 1, // if (resultScan != 'false') {
textAlign: TextAlign.center, // onTabTapped(0);
decoration: InputDecoration( // }
hintText: 'Tappez/Collez une clé publique, ou scannez', },
hintStyle: TextStyle(fontSize: 14), child: Container(
contentPadding: EdgeInsets.symmetric(horizontal: 7, vertical: 15), height: 40.0,
border: InputBorder.none, width: 40.0,
focusedBorder: InputBorder.none, child: Image.asset('images/scanner.png')),
enabledBorder: InputBorder.none, backgroundColor: Color(
errorBorder: InputBorder.none, 0xffEFEFBF), //Color(0xffFFD68E), //Color.fromARGB(500, 204, 255, 255),
disabledBorder: InputBorder.none, ),
), ),
style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)), ),
historyQuery(), body: Column(children: <Widget>[
]); SizedBox(height: 8),
TextField(
// Entrée de la pubkey
onChanged: (text) {
print("Clé tappxé: $text");
this.pubkey = text;
isPubkey(text);
},
controller: this._outputPubkey,
maxLines: 1,
textAlign: TextAlign.center,
decoration: InputDecoration(
hintText: 'Tappez/Collez une clé publique, ou scannez',
hintStyle: TextStyle(fontSize: 14),
contentPadding:
EdgeInsets.symmetric(horizontal: 7, vertical: 15),
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
),
style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)),
historyQuery(),
]));
} }
historyQuery() { historyQuery() {

View File

@ -4,8 +4,6 @@ import 'package:flutter/material.dart';
import 'dart:typed_data'; import 'dart:typed_data';
import 'dart:ui'; import 'dart:ui';
import 'myWallets.dart';
//ignore: must_be_immutable //ignore: must_be_immutable
class HomeScreen extends StatefulWidget { class HomeScreen extends StatefulWidget {
HomeScreen({this.screens}); HomeScreen({this.screens});
@ -41,31 +39,9 @@ class HomeScreenState extends State<HomeScreen> {
keyHistory: _keyHistory, keyHistory: _keyHistory,
), ),
GenerateWalletScreen(), GenerateWalletScreen(),
MyWalletsScreen(),
], ],
), ),
), ),
floatingActionButton: Container(
height: 80.0,
width: 80.0,
child: FittedBox(
child: FloatingActionButton(
onPressed: () async {
final resultScan = await _keyHistory.currentState.scan();
print(resultScan);
if (resultScan != 'false') {
onTabTapped(0);
}
},
child: Container(
height: 40.0,
width: 40.0,
child: Image.asset('images/scanner.png')),
backgroundColor: Color(
0xffEFEFBF), //Color(0xffFFD68E), //Color.fromARGB(500, 204, 255, 255),
),
),
),
bottomNavigationBar: BottomNavigationBar( bottomNavigationBar: BottomNavigationBar(
backgroundColor: Color(0xffFFD68E), backgroundColor: Color(0xffFFD68E),
fixedColor: Color(0xff855F2D), fixedColor: Color(0xff855F2D),
@ -75,16 +51,13 @@ class HomeScreenState extends State<HomeScreen> {
currentIndex: currentIndex, currentIndex: currentIndex,
items: [ items: [
BottomNavigationBarItem( BottomNavigationBarItem(
icon: new Icon(Icons.format_list_bulleted), icon: new Icon(Icons
.format_list_bulleted), //Icons.person_add_alt_1_rounded //Icons.lock
label: 'Accueil', label: 'Accueil',
), ),
BottomNavigationBarItem(
icon: new Icon(Icons.person_add_alt_1_rounded),
label: 'Générer un wallet',
),
BottomNavigationBarItem( BottomNavigationBarItem(
icon: new Icon(Icons.lock), icon: new Icon(Icons.lock),
label: 'Mes wallets', label: 'Mes portefeuilles',
) )
], ],
), ),

View File

@ -32,7 +32,7 @@ flutter_icons:
android: "ic_launcher" android: "ic_launcher"
ios: true ios: true
image_path: "assets/icon/gecko5bduniter2.png" image_path: "assets/icon/gecko5bduniter2.png"
# cupertino_icons: ^1.0.0 cupertino_icons: ^1.0.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: