Add button for renew PIN; Add tooltips on walletGeneration page; WIP: Use custom wallet name
This commit is contained in:
parent
a2698a244b
commit
a8427f5b9d
|
@ -1,4 +1,5 @@
|
|||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
import 'package:dubp/dubp.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
@ -24,30 +25,34 @@ class ConfirmStoreWalletState extends State<ConfirmStoreWallet> {
|
|||
// DubpRust.setup();
|
||||
this._mnemonicController.text = widget.generatedMnemonic;
|
||||
this._pubkey.text = widget.generatedWallet.publicKey;
|
||||
nbrWord = getRandomInt();
|
||||
}
|
||||
|
||||
TextEditingController _mnemonicController = new TextEditingController();
|
||||
TextEditingController _pubkey = new TextEditingController();
|
||||
TextEditingController _pin = new TextEditingController();
|
||||
String walletName = 'MonWallet';
|
||||
List _listWallets = [];
|
||||
TextEditingController _inputRestoreWord = new TextEditingController();
|
||||
TextEditingController walletName = new TextEditingController();
|
||||
// List _listWallets = [];
|
||||
int nbrWord;
|
||||
bool isAskedWordValid = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
appBar: AppBar(),
|
||||
body: Center(
|
||||
child: Column(children: <Widget>[
|
||||
TextField(
|
||||
enabled: false,
|
||||
controller: this._mnemonicController,
|
||||
maxLines: 2,
|
||||
SizedBox(height: 15),
|
||||
Text(
|
||||
'Votre clé publique est :',
|
||||
textAlign: TextAlign.center,
|
||||
decoration: InputDecoration(),
|
||||
style: TextStyle(
|
||||
fontSize: 15.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold)),
|
||||
fontSize: 17.0,
|
||||
color: Colors.grey[600],
|
||||
fontWeight: FontWeight.w400),
|
||||
),
|
||||
TextField(
|
||||
enabled: false,
|
||||
controller: this._pubkey,
|
||||
|
@ -58,13 +63,76 @@ class ConfirmStoreWalletState extends State<ConfirmStoreWallet> {
|
|||
fontSize: 14.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold)),
|
||||
new ElevatedButton(
|
||||
SizedBox(height: 12),
|
||||
Text(
|
||||
'Quel est le ${nbrWord + 1}ème mot de votre phrase de restauration ?',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 17.0,
|
||||
color: Colors.grey[600],
|
||||
fontWeight: FontWeight.w400),
|
||||
),
|
||||
TextField(
|
||||
enabled: !isAskedWordValid,
|
||||
controller: this._inputRestoreWord,
|
||||
onChanged: (value) {
|
||||
checkAskedWord(value);
|
||||
},
|
||||
maxLines: 2,
|
||||
textAlign: TextAlign.center,
|
||||
decoration: InputDecoration(),
|
||||
style: TextStyle(
|
||||
fontSize: 30.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w500)),
|
||||
SizedBox(height: 12),
|
||||
Text(
|
||||
'Choisissez un nom pour votre portefeuille :',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 17.0,
|
||||
color: Colors.grey[600],
|
||||
fontWeight: FontWeight.w400),
|
||||
),
|
||||
TextField(
|
||||
enabled: isAskedWordValid,
|
||||
controller: this.walletName,
|
||||
onChanged: (v) {
|
||||
nameChanged();
|
||||
},
|
||||
maxLines: 2,
|
||||
textAlign: TextAlign.center,
|
||||
decoration: InputDecoration(),
|
||||
style: TextStyle(
|
||||
fontSize: 30.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w500)),
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: SizedBox(
|
||||
width: 200,
|
||||
height: 50,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Color(0xffFFD68E), // background
|
||||
elevation: 12,
|
||||
primary: Colors
|
||||
.green[400], //Color(0xffFFD68E), // background
|
||||
onPrimary: Colors.black, // foreground
|
||||
),
|
||||
onPressed: () => storeWallet(),
|
||||
child: Text('Confirmer', style: TextStyle(fontSize: 20))),
|
||||
onPressed:
|
||||
(isAskedWordValid && this.walletName.text != '')
|
||||
? () => storeWallet()
|
||||
: null,
|
||||
child:
|
||||
Text('Confirmer', style: TextStyle(fontSize: 28))),
|
||||
))),
|
||||
SizedBox(height: 70),
|
||||
Text('TRICHE PENDANT ALPHA: ' + this._mnemonicController.text,
|
||||
style: TextStyle(
|
||||
fontSize: 10.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.normal)),
|
||||
]),
|
||||
),
|
||||
);
|
||||
|
@ -72,24 +140,27 @@ class ConfirmStoreWalletState extends State<ConfirmStoreWallet> {
|
|||
|
||||
Future storeWallet() async {
|
||||
final appPath = await _localPath;
|
||||
final walletFile = File('$appPath/wallets/${this.walletName}/wallet.dewif');
|
||||
final walletFile =
|
||||
// File('$appPath/wallets/${this.walletName.text}/wallet.dewif');
|
||||
File('$appPath/wallets/MonWallet/wallet.dewif');
|
||||
// TODO: Use custom wallet name for storage
|
||||
|
||||
final isExist = await Directory('$appPath/wallets').exists();
|
||||
if (isExist == false) {
|
||||
new Directory('$appPath/wallets').createSync();
|
||||
}
|
||||
|
||||
new Directory('$appPath/wallets/${this.walletName}').createSync();
|
||||
new Directory('$appPath/wallets/${this.walletName.text}').createSync();
|
||||
walletFile.writeAsString('${widget.generatedWallet.dewif}');
|
||||
_pin.clear();
|
||||
|
||||
await getAllWalletsNames();
|
||||
Navigator.pop(context, true);
|
||||
// await getAllWalletsNames();
|
||||
Navigator.pop(context, true);
|
||||
Navigator.pop(context, this._pubkey.text);
|
||||
// setState(() {});
|
||||
// FocusScope.of(context).unfocus();
|
||||
|
||||
return this.walletName;
|
||||
return this.walletName.text;
|
||||
}
|
||||
|
||||
Future<String> get _localPath async {
|
||||
|
@ -97,21 +168,42 @@ class ConfirmStoreWalletState extends State<ConfirmStoreWallet> {
|
|||
return directory.path;
|
||||
}
|
||||
|
||||
Future<List> getAllWalletsNames() async {
|
||||
final _appPath = await getApplicationDocumentsDirectory();
|
||||
// List _listWallets = [];
|
||||
// _listWallets.add('tortuuue');
|
||||
this._listWallets.clear();
|
||||
print(_appPath);
|
||||
// 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);
|
||||
});
|
||||
// _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();
|
||||
// return _listWallets;
|
||||
// // final _local = await _appPath.path.list().toList();
|
||||
// }
|
||||
|
||||
void checkAskedWord(value) {
|
||||
print(this._mnemonicController.text.split(' ')[nbrWord]);
|
||||
print(value);
|
||||
if (this._mnemonicController.text.split(' ')[nbrWord] == value) {
|
||||
print('Word is OK');
|
||||
isAskedWordValid = true;
|
||||
} else {
|
||||
isAskedWordValid = false;
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
int getRandomInt() {
|
||||
var rng = new Random();
|
||||
return rng.nextInt(12);
|
||||
}
|
||||
|
||||
void nameChanged() {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:sentry/sentry.dart' as sentry;
|
||||
import 'package:dubp/dubp.dart';
|
||||
import 'package:super_tooltip/super_tooltip.dart';
|
||||
|
||||
class GenerateWalletsScreen extends StatefulWidget {
|
||||
const GenerateWalletsScreen({Key keyGenWallet}) : super(key: keyGenWallet);
|
||||
|
@ -25,6 +26,7 @@ class GenerateWalletsState extends State<GenerateWalletsScreen> {
|
|||
String generatedMnemonic;
|
||||
bool walletIsGenerated = false;
|
||||
NewWallet actualWallet;
|
||||
SuperTooltip tooltip;
|
||||
// final formKey = GlobalKey<FormState>();
|
||||
|
||||
bool hasError = false;
|
||||
|
@ -55,13 +57,17 @@ class GenerateWalletsState extends State<GenerateWalletsScreen> {
|
|||
body: SafeArea(
|
||||
child: Column(children: <Widget>[
|
||||
SizedBox(height: 20),
|
||||
Text(
|
||||
Tooltip(
|
||||
message:
|
||||
"C'est votre RIB en Ğ1, les gens l'utiliseront pour vous payer",
|
||||
child: Text(
|
||||
'Clé publique:',
|
||||
style: TextStyle(
|
||||
fontSize: 15.0,
|
||||
color: Colors.grey[600],
|
||||
fontWeight: FontWeight.w400),
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
enabled: false,
|
||||
controller: this._pubkey,
|
||||
|
@ -73,13 +79,17 @@ class GenerateWalletsState extends State<GenerateWalletsScreen> {
|
|||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold)),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
Tooltip(
|
||||
message:
|
||||
"Notez et gardez cette phrase précieusement sur un papier, elle vous servira à restaurer votre portefeuille sur un autre appareil",
|
||||
child: Text(
|
||||
'Phrase de restauration:',
|
||||
style: TextStyle(
|
||||
fontSize: 15.0,
|
||||
color: Colors.grey[600],
|
||||
fontWeight: FontWeight.w400),
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
enabled: false,
|
||||
controller: this._mnemonicController,
|
||||
|
@ -93,13 +103,21 @@ class GenerateWalletsState extends State<GenerateWalletsScreen> {
|
|||
color: Colors.black,
|
||||
fontWeight: FontWeight.w400)),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
Tooltip(
|
||||
message:
|
||||
"Retenez bien votre code secret, il vous sera demandé à chaque paiement, ainsi que pour configurer votre portefeuille",
|
||||
child: Text(
|
||||
'Code secret:',
|
||||
style: TextStyle(
|
||||
fontSize: 15.0,
|
||||
color: Colors.grey[600],
|
||||
fontWeight: FontWeight.w400),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
child: Stack(
|
||||
alignment: Alignment.centerRight,
|
||||
children: <Widget>[
|
||||
TextField(
|
||||
enabled: false,
|
||||
controller: this._pin,
|
||||
|
@ -110,6 +128,16 @@ class GenerateWalletsState extends State<GenerateWalletsScreen> {
|
|||
fontSize: 30.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold)),
|
||||
IconButton(
|
||||
icon: Icon(Icons.replay),
|
||||
color: Color(0xffD28928),
|
||||
onPressed: () {
|
||||
changePinCode();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
// Expanded(child: Align(alignment: Alignment.bottomCenter)),
|
||||
new ElevatedButton(
|
||||
|
@ -148,7 +176,7 @@ class GenerateWalletsState extends State<GenerateWalletsScreen> {
|
|||
));
|
||||
}
|
||||
|
||||
Future generateMnemonic() async {
|
||||
Future<String> generateMnemonic() async {
|
||||
try {
|
||||
this.generatedMnemonic =
|
||||
await DubpRust.genMnemonic(language: Language.french);
|
||||
|
@ -167,7 +195,7 @@ class GenerateWalletsState extends State<GenerateWalletsScreen> {
|
|||
return this.generatedMnemonic;
|
||||
}
|
||||
|
||||
Future generateWallet(generatedMnemonic) async {
|
||||
Future<NewWallet> generateWallet(generatedMnemonic) async {
|
||||
try {
|
||||
this.actualWallet = await DubpRust.genWalletFromMnemonic(
|
||||
language: Language.french,
|
||||
|
@ -191,4 +219,15 @@ class GenerateWalletsState extends State<GenerateWalletsScreen> {
|
|||
|
||||
return actualWallet;
|
||||
}
|
||||
|
||||
Future<void> changePinCode() async {
|
||||
this.actualWallet = await DubpRust.changeDewifPin(
|
||||
dewif: this.actualWallet.dewif,
|
||||
oldPin: this.actualWallet.pin,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
this._pin.text = actualWallet.pin;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -218,6 +218,8 @@ class MyWalletState extends State<MyWalletsScreen> {
|
|||
this._listWallets.add(entity.path.split('/').last);
|
||||
});
|
||||
|
||||
print('Mes wallets: ');
|
||||
print(_listWallets);
|
||||
return _listWallets;
|
||||
|
||||
// final _local = await _appPath.path.list().toList();
|
||||
|
@ -236,7 +238,7 @@ class MyWalletState extends State<MyWalletsScreen> {
|
|||
Future readLocalWallet(String _pin) async {
|
||||
// print(pin);
|
||||
try {
|
||||
final file = await _localWallet('MonWallet');
|
||||
final file = await _localWallet('this.walletName');
|
||||
String _localDewif = await file.readAsString();
|
||||
String _localPubkey;
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ class WalletsHomeState extends State<WalletsHome> {
|
|||
String generatedMnemonic;
|
||||
bool walletIsGenerated = false;
|
||||
NewWallet actualWallet;
|
||||
String newWalletName;
|
||||
|
||||
bool hasError = false;
|
||||
String validPin = 'NO PIN';
|
||||
|
@ -54,7 +55,10 @@ class WalletsHomeState extends State<WalletsHome> {
|
|||
MaterialPageRoute(builder: (context) {
|
||||
return GenerateWalletsScreen();
|
||||
}),
|
||||
);
|
||||
).then((value) => setState(() {
|
||||
this.newWalletName = value;
|
||||
checkIfWalletExist(value);
|
||||
}));
|
||||
},
|
||||
child: Container(
|
||||
height: 40.0,
|
||||
|
@ -83,7 +87,10 @@ class WalletsHomeState extends State<WalletsHome> {
|
|||
MaterialPageRoute(builder: (context) {
|
||||
return GenerateWalletsScreen();
|
||||
}),
|
||||
),
|
||||
).then((value) => setState(() {
|
||||
this.newWalletName = value;
|
||||
checkIfWalletExist(value);
|
||||
})),
|
||||
child: Text('Générer un portefeuille',
|
||||
style: TextStyle(fontSize: 20))),
|
||||
SizedBox(height: 15),
|
||||
|
@ -121,6 +128,7 @@ class WalletsHomeState extends State<WalletsHome> {
|
|||
// }
|
||||
|
||||
bool checkIfWalletExist(_name) {
|
||||
print('Nom du wallet: ' + _name);
|
||||
if (this.appPath == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -490,6 +490,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0-nullsafety.3"
|
||||
super_tooltip:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: super_tooltip
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.9.6"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -27,6 +27,7 @@ dependencies:
|
|||
path_provider: ^1.6.24
|
||||
pin_code_fields: ^6.0.2
|
||||
http: ^0.12.2
|
||||
super_tooltip: ^0.9.6
|
||||
|
||||
|
||||
flutter_icons:
|
||||
|
|
Loading…
Reference in New Issue