Big work in progress in My wallet tab;
This commit is contained in:
parent
60c9d00c61
commit
056198587d
|
@ -1,3 +1,4 @@
|
|||
import 'package:gecko/ui/myWallets.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:dubp/dubp.dart';
|
||||
|
@ -33,74 +34,136 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
child: Column(children: <Widget>[
|
||||
SizedBox(height: 8),
|
||||
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 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),
|
||||
return Scaffold(
|
||||
floatingActionButton: Container(
|
||||
height: 80.0,
|
||||
width: 80.0,
|
||||
child: FittedBox(
|
||||
child: FloatingActionButton(
|
||||
heroTag: "buttonGenerateWallet",
|
||||
onPressed: () async {
|
||||
await generateMnemonic();
|
||||
// print(resultScan);
|
||||
// if (resultScan != 'false') {
|
||||
// onTabTapped(0);
|
||||
// }
|
||||
},
|
||||
child: Container(
|
||||
height: 40.0,
|
||||
width: 40.0,
|
||||
child: Icon(Icons.person_add_alt_1_rounded)),
|
||||
backgroundColor: Color(
|
||||
0xffEFEFBF), //Color(0xffFFD68E), //Color.fromARGB(500, 204, 255, 255),
|
||||
),
|
||||
),
|
||||
style: TextStyle(
|
||||
fontSize: 22.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w400)),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
'Code PIN:',
|
||||
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),
|
||||
new RaisedButton(
|
||||
color: Color(0xffFFD68E),
|
||||
onPressed: () => generateMnemonic(),
|
||||
child: Text('Générer un wallet', style: TextStyle(fontSize: 20))),
|
||||
SizedBox(height: 30),
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: new RaisedButton(
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Column(children: <Widget>[
|
||||
FutureBuilder<bool>(
|
||||
future: checkIfWalletExist(),
|
||||
builder: (context, fSnapshot) {
|
||||
if (fSnapshot.hasData)
|
||||
return Visibility(
|
||||
visible: (!fSnapshot.data && !walletIsGenerated),
|
||||
child: Column(children: <Widget>[
|
||||
SizedBox(height: 80),
|
||||
Center(
|
||||
child: Text(
|
||||
"Vous n'avez encore généré aucun portefeuille.",
|
||||
style: TextStyle(
|
||||
fontSize: 20, fontWeight: FontWeight.w500),
|
||||
textAlign: TextAlign.center)),
|
||||
SizedBox(height: 50),
|
||||
RaisedButton(
|
||||
color: Color(0xffFFD68E),
|
||||
onPressed: () => generateMnemonic(),
|
||||
child: Text('Générer un portefeuille',
|
||||
style: TextStyle(fontSize: 20))),
|
||||
SizedBox(height: 15),
|
||||
Center(
|
||||
child: Text("ou",
|
||||
style: TextStyle(
|
||||
fontSize: 20, fontWeight: FontWeight.w500),
|
||||
textAlign: TextAlign.center)),
|
||||
SizedBox(height: 15),
|
||||
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),
|
||||
onPressed: walletIsGenerated
|
||||
? () {
|
||||
|
@ -112,6 +175,8 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
|
|||
generatedWallet: this.actualWallet);
|
||||
}),
|
||||
).then((value) => setState(() {
|
||||
print(
|
||||
'TODO: Fix error null boolean ?'); //TODO: Fix error null boolean
|
||||
if (value) {
|
||||
_pin.clear();
|
||||
_mnemonicController.clear();
|
||||
|
@ -124,9 +189,21 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
|
|||
}
|
||||
: null,
|
||||
child: Text('Enregistrer ce wallet',
|
||||
style: TextStyle(fontSize: 20))))),
|
||||
SizedBox(height: 15)
|
||||
]));
|
||||
style: TextStyle(fontSize: 20))),
|
||||
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 {
|
||||
|
@ -144,13 +221,16 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
|
|||
}
|
||||
this.actualWallet = await generateWallet(this.generatedMnemonic);
|
||||
this.walletIsGenerated = true;
|
||||
// await checkIfWalletExist();
|
||||
return this.generatedMnemonic;
|
||||
}
|
||||
|
||||
Future generateWallet(generatedMnemonic) async {
|
||||
try {
|
||||
this.actualWallet = await DubpRust.genWalletFromMnemonic(
|
||||
language: Language.french, mnemonic: generatedMnemonic);
|
||||
language: Language.french,
|
||||
mnemonic: generatedMnemonic,
|
||||
secretCodeType: SecretCodeType.letters);
|
||||
} catch (e, stack) {
|
||||
print(e);
|
||||
if (kReleaseMode) {
|
||||
|
@ -169,8 +249,50 @@ class _GenerateWalletState extends State<GenerateWalletScreen> {
|
|||
|
||||
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 {
|
||||
final String generatedMnemonic;
|
||||
final NewWallet generatedWallet;
|
||||
|
@ -225,83 +347,14 @@ class _ValidStoreWalletScreen extends State<ValidStoreWalletScreen> {
|
|||
fontWeight: FontWeight.bold)),
|
||||
new RaisedButton(
|
||||
color: Color(0xffFFD68E),
|
||||
onPressed: () => storeWallet(widget.generatedWallet),
|
||||
onPressed: () => storeWallet(),
|
||||
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;
|
||||
walletFile.writeAsString('${widget.generatedWallet.dewif}');
|
||||
_pin.clear();
|
||||
|
|
|
@ -63,31 +63,55 @@ class HistoryScreenState extends State<HistoryScreen> {
|
|||
print('Build pubkey : ' + pubkey);
|
||||
print('Build this.pubkey : ' + this.pubkey);
|
||||
print('isBuilding: ' + isBuilding.toString());
|
||||
return 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,
|
||||
return Scaffold(
|
||||
floatingActionButton: Container(
|
||||
height: 80.0,
|
||||
width: 80.0,
|
||||
child: FittedBox(
|
||||
child: FloatingActionButton(
|
||||
heroTag: "buttonScan",
|
||||
onPressed: () async {
|
||||
await 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),
|
||||
),
|
||||
),
|
||||
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() {
|
||||
|
|
|
@ -4,8 +4,6 @@ import 'package:flutter/material.dart';
|
|||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'myWallets.dart';
|
||||
|
||||
//ignore: must_be_immutable
|
||||
class HomeScreen extends StatefulWidget {
|
||||
HomeScreen({this.screens});
|
||||
|
@ -41,31 +39,9 @@ class HomeScreenState extends State<HomeScreen> {
|
|||
keyHistory: _keyHistory,
|
||||
),
|
||||
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(
|
||||
backgroundColor: Color(0xffFFD68E),
|
||||
fixedColor: Color(0xff855F2D),
|
||||
|
@ -75,16 +51,13 @@ class HomeScreenState extends State<HomeScreen> {
|
|||
currentIndex: currentIndex,
|
||||
items: [
|
||||
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',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: new Icon(Icons.person_add_alt_1_rounded),
|
||||
label: 'Générer un wallet',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: new Icon(Icons.lock),
|
||||
label: 'Mes wallets',
|
||||
label: 'Mes portefeuilles',
|
||||
)
|
||||
],
|
||||
),
|
||||
|
|
|
@ -32,7 +32,7 @@ flutter_icons:
|
|||
android: "ic_launcher"
|
||||
ios: true
|
||||
image_path: "assets/icon/gecko5bduniter2.png"
|
||||
# cupertino_icons: ^1.0.0
|
||||
cupertino_icons: ^1.0.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in New Issue