Improve wallet option screen; Improve focus on textfields on generatedWallets screen[

This commit is contained in:
poka 2021-01-15 06:28:14 +01:00
parent 9d07d7373c
commit 22be4f1de6
2 changed files with 199 additions and 109 deletions

View File

@ -28,11 +28,20 @@ class ConfirmStoreWalletState extends State<ConfirmStoreWallet> {
askedWordColor = Colors.black; askedWordColor = Colors.black;
} }
@override
void dispose() {
_wordFocus.dispose();
_walletNameFocus.dispose();
super.dispose();
}
TextEditingController _mnemonicController = new TextEditingController(); TextEditingController _mnemonicController = new TextEditingController();
TextEditingController _pubkey = new TextEditingController(); TextEditingController _pubkey = new TextEditingController();
TextEditingController _pin = new TextEditingController(); TextEditingController _pin = new TextEditingController();
TextEditingController _inputRestoreWord = new TextEditingController(); TextEditingController _inputRestoreWord = new TextEditingController();
TextEditingController walletName = new TextEditingController(); TextEditingController walletName = new TextEditingController();
FocusNode _wordFocus = FocusNode();
FocusNode _walletNameFocus = FocusNode();
Color askedWordColor; Color askedWordColor;
int nbrWord; int nbrWord;
bool isAskedWordValid = false; bool isAskedWordValid = false;
@ -76,13 +85,16 @@ class ConfirmStoreWalletState extends State<ConfirmStoreWallet> {
color: Colors.grey[600], color: Colors.grey[600],
fontWeight: FontWeight.w400), fontWeight: FontWeight.w400),
), ),
TextField( TextFormField(
focusNode: _wordFocus,
autofocus: true,
enabled: !isAskedWordValid, enabled: !isAskedWordValid,
controller: this._inputRestoreWord, controller: this._inputRestoreWord,
textInputAction: TextInputAction.next,
onChanged: (value) { onChanged: (value) {
checkAskedWord(value); checkAskedWord(value);
}, },
maxLines: 2, maxLines: 1,
textAlign: TextAlign.center, textAlign: TextAlign.center,
decoration: InputDecoration(), decoration: InputDecoration(),
style: TextStyle( style: TextStyle(
@ -98,17 +110,20 @@ class ConfirmStoreWalletState extends State<ConfirmStoreWallet> {
color: Colors.grey[600], color: Colors.grey[600],
fontWeight: FontWeight.w400), fontWeight: FontWeight.w400),
), ),
TextField( TextFormField(
focusNode: _walletNameFocus,
// autofocus: true,
inputFormatters: [ inputFormatters: [
FilteringTextInputFormatter.allow( FilteringTextInputFormatter.allow(
RegExp('[a-zA-Z|0-9|\\-|_| ]')), RegExp('[a-zA-Z|0-9|\\-|_| ]')),
], ],
enabled: isAskedWordValid, // enabled: isAskedWordValid,
controller: this.walletName, controller: this.walletName,
textInputAction: TextInputAction.next,
onChanged: (v) { onChanged: (v) {
nameChanged(); nameChanged();
}, },
maxLines: 2, maxLines: 1,
textAlign: TextAlign.center, textAlign: TextAlign.center,
decoration: InputDecoration(), decoration: InputDecoration(),
style: TextStyle( style: TextStyle(
@ -183,6 +198,7 @@ class ConfirmStoreWalletState extends State<ConfirmStoreWallet> {
print('Word is OK'); print('Word is OK');
isAskedWordValid = true; isAskedWordValid = true;
askedWordColor = Colors.green[600]; askedWordColor = Colors.green[600];
_walletNameFocus.nextFocus();
} else { } else {
isAskedWordValid = false; isAskedWordValid = false;
} }

View File

@ -25,11 +25,15 @@ class WalletOptionsState extends State<WalletOptions> {
bool hasError = false; bool hasError = false;
String validPin = 'NO PIN'; String validPin = 'NO PIN';
var pinColor = Color(0xffF9F9F1); var pinColor = Color(0xffF9F9F1);
bool isWalletUnlock = false;
Future<NewWallet> get badWallet => null;
void initState() { void initState() {
super.initState(); super.initState();
errorController = StreamController<ErrorAnimationType>(); errorController = StreamController<ErrorAnimationType>();
DubpRust.setup(); DubpRust.setup();
isWalletUnlock = false;
} }
@override @override
@ -44,109 +48,160 @@ class WalletOptionsState extends State<WalletOptions> {
body: Center( body: Center(
child: SafeArea( child: SafeArea(
child: Column(children: <Widget>[ child: Column(children: <Widget>[
InkWell( Visibility(
child: TextField( visible: isWalletUnlock,
enabled: false, child: Expanded(
controller: this._pubkey, child: Column(children: <Widget>[
maxLines: 1, SizedBox(height: 15),
textAlign: TextAlign.center, Text(
decoration: InputDecoration(), 'Clé publique:',
style: TextStyle( style: TextStyle(
fontSize: 14.0, fontSize: 15.0,
color: Colors.black, color: Colors.grey[600],
fontWeight: FontWeight.bold)), fontWeight: FontWeight.w400),
onTap: () { ),
// deleteWallet(widget.walletName); SizedBox(height: 15),
// _keyHistory.currentState.scan(); Text(
}, this._pubkey.text,
), style: TextStyle(
SizedBox(height: 12), fontSize: 14.0,
Form( color: Colors.black,
key: formKey, fontWeight: FontWeight.bold),
child: Padding( ),
padding: Expanded(
const EdgeInsets.symmetric(vertical: 8.0, horizontal: 30), child: Align(
child: PinCodeTextField( alignment: Alignment.bottomCenter,
appContext: context, child: SizedBox(
pastedTextStyle: TextStyle( height: 50,
color: Colors.green.shade600, width: 300,
fontWeight: FontWeight.bold, child: ElevatedButton(
), style: ElevatedButton.styleFrom(
length: 6, elevation: 5,
obscureText: false, primary: Color(
obscuringCharacter: '*', 0xffFFD68E), //Color(0xffFFD68E), // background
animationType: AnimationType.fade, onPrimary: Colors.black, // foreground
validator: (v) { ),
if (v.length < 6) { onPressed: () {
return "Votre code PIN fait 6 caractères"; changePin(widget.walletName, '_pin');
} else { },
return null; child: Text('Changer mon code secret',
} style: TextStyle(fontSize: 20)))))),
}, SizedBox(height: 30),
pinTheme: PinTheme( SizedBox(
shape: PinCodeFieldShape.box, height: 50,
borderRadius: BorderRadius.circular(5), width: 300,
fieldHeight: 60, child: ElevatedButton(
fieldWidth: 50, style: ElevatedButton.styleFrom(
activeFillColor: hasError ? Colors.orange : Colors.white, elevation: 6,
), primary:
cursorColor: Colors.black, Colors.red, //Color(0xffFFD68E), // background
animationDuration: Duration(milliseconds: 300), onPrimary: Colors.black, // foreground
textStyle: TextStyle(fontSize: 20, height: 1.6), ),
backgroundColor: pinColor, onPressed: () {
enableActiveFill: false, deleteWallet(widget.walletName);
errorAnimationController: errorController, },
controller: _enterPin, child: Text('Supprimer ce portefeuille',
keyboardType: TextInputType.text, style: TextStyle(fontSize: 20)))),
boxShadows: [ SizedBox(height: 50),
BoxShadow( Text(
offset: Offset(0, 1), 'Portefeuille déverrouillé',
color: Colors.black12, style: TextStyle(
blurRadius: 10, color: Colors.green,
) fontWeight: FontWeight.w700,
], fontSize: 15),
onCompleted: (v) async { ),
print("Completed"); SizedBox(height: 10)
final resultWallet = await readLocalWallet(v.toUpperCase()); ]))),
if (resultWallet == 'bad') { Visibility(
errorController.add(ErrorAnimationType visible: !isWalletUnlock,
.shake); // Triggering error shake animation child: Expanded(
setState(() { child: Column(children: <Widget>[
hasError = true; SizedBox(height: 80),
pinColor = Colors.red[200]; Text(
}); 'Veuillez tapper votre code secret pour dévérouiller votre portefeuille.',
} else { textAlign: TextAlign.center,
setState(() { style: TextStyle(
pinColor = Colors.green[200]; fontSize: 15.0,
}); color: Colors.black,
} fontWeight: FontWeight.w400),
}, ),
onChanged: (value) { SizedBox(height: 50),
if (pinColor != Color(0xffF9F9F1)) { Form(
setState(() { key: formKey,
pinColor = Color(0xffF9F9F1); child: Padding(
}); padding: const EdgeInsets.symmetric(
} vertical: 8.0, horizontal: 30),
print(value); child: PinCodeTextField(
}, autoFocus: true,
)), appContext: context,
), pastedTextStyle: TextStyle(
SizedBox( color: Colors.green.shade600,
height: 100, fontWeight: FontWeight.bold,
), ),
SizedBox( length: 6,
height: 80, obscureText: false,
child: ElevatedButton( obscuringCharacter: '*',
style: ElevatedButton.styleFrom( animationType: AnimationType.fade,
elevation: 2, validator: (v) {
primary: Colors.red, //Color(0xffFFD68E), // background if (v.length < 6) {
onPrimary: Colors.black, // foreground return "Votre code PIN fait 6 caractères";
), } else {
onPressed: () { return null;
deleteWallet(widget.walletName); }
}, },
child: Text('Supprimer ce portefeuille', pinTheme: PinTheme(
style: TextStyle(fontSize: 25)))) 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: (_pin) async {
print("Completed");
final resultWallet =
await readLocalWallet(_pin.toUpperCase());
if (resultWallet == 'bad') {
errorController.add(ErrorAnimationType
.shake); // Triggering error shake animation
setState(() {
hasError = true;
pinColor = Colors.red[200];
});
} else {
pinColor = Colors.green[200];
// setState(() {});
// await Future.delayed(Duration(milliseconds: 50));
isWalletUnlock = true;
setState(() {});
}
},
onChanged: (value) {
if (pinColor != Color(0xffF9F9F1)) {
setState(() {
pinColor = Color(0xffF9F9F1);
});
}
print(value);
},
)),
)
]))),
])))); ]))));
} }
@ -210,6 +265,25 @@ class WalletOptionsState extends State<WalletOptions> {
} }
} }
Future<NewWallet> changePin(_name, _oldPin) async {
try {
final appPath = await _localPath;
final _walletFile = Directory('$appPath/wallets/$_name');
final _dewif =
File(_walletFile.path + '/wallet.dewif').readAsLinesSync()[0];
final NewWallet _newWalletFile = await DubpRust.changeDewifPin(
dewif: _dewif,
oldPin: _oldPin,
);
return _newWalletFile;
} catch (e) {
print('Impossible de changer le code PIN.');
return badWallet;
}
}
Future<int> deleteWallet(_name) async { Future<int> deleteWallet(_name) async {
try { try {
final appPath = await _localPath; final appPath = await _localPath;
@ -235,7 +309,7 @@ class WalletOptionsState extends State<WalletOptions> {
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertDialog( return AlertDialog(
title: Text( title: Text(
'Êtes-vous sûr de vouloir supprimer le portefeuille ${widget.walletName} ?'), 'Êtes-vous sûr de vouloir supprimer le portefeuille "${widget.walletName}" ?'),
content: SingleChildScrollView( content: SingleChildScrollView(
child: ListBody( child: ListBody(
children: <Widget>[ children: <Widget>[