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,29 +48,91 @@ 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(
fontSize: 15.0,
color: Colors.grey[600],
fontWeight: FontWeight.w400),
),
SizedBox(height: 15),
Text(
this._pubkey.text,
style: TextStyle( style: TextStyle(
fontSize: 14.0, fontSize: 14.0,
color: Colors.black, color: Colors.black,
fontWeight: FontWeight.bold)), fontWeight: FontWeight.bold),
onTap: () {
// deleteWallet(widget.walletName);
// _keyHistory.currentState.scan();
},
), ),
SizedBox(height: 12), Expanded(
child: Align(
alignment: Alignment.bottomCenter,
child: SizedBox(
height: 50,
width: 300,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
elevation: 5,
primary: Color(
0xffFFD68E), //Color(0xffFFD68E), // background
onPrimary: Colors.black, // foreground
),
onPressed: () {
changePin(widget.walletName, '_pin');
},
child: Text('Changer mon code secret',
style: TextStyle(fontSize: 20)))))),
SizedBox(height: 30),
SizedBox(
height: 50,
width: 300,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
elevation: 6,
primary:
Colors.red, //Color(0xffFFD68E), // background
onPrimary: Colors.black, // foreground
),
onPressed: () {
deleteWallet(widget.walletName);
},
child: Text('Supprimer ce portefeuille',
style: TextStyle(fontSize: 20)))),
SizedBox(height: 50),
Text(
'Portefeuille déverrouillé',
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.w700,
fontSize: 15),
),
SizedBox(height: 10)
]))),
Visibility(
visible: !isWalletUnlock,
child: Expanded(
child: Column(children: <Widget>[
SizedBox(height: 80),
Text(
'Veuillez tapper votre code secret pour dévérouiller votre portefeuille.',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15.0,
color: Colors.black,
fontWeight: FontWeight.w400),
),
SizedBox(height: 50),
Form( Form(
key: formKey, key: formKey,
child: Padding( child: Padding(
padding: padding: const EdgeInsets.symmetric(
const EdgeInsets.symmetric(vertical: 8.0, horizontal: 30), vertical: 8.0, horizontal: 30),
child: PinCodeTextField( child: PinCodeTextField(
autoFocus: true,
appContext: context, appContext: context,
pastedTextStyle: TextStyle( pastedTextStyle: TextStyle(
color: Colors.green.shade600, color: Colors.green.shade600,
@ -88,7 +154,8 @@ class WalletOptionsState extends State<WalletOptions> {
borderRadius: BorderRadius.circular(5), borderRadius: BorderRadius.circular(5),
fieldHeight: 60, fieldHeight: 60,
fieldWidth: 50, fieldWidth: 50,
activeFillColor: hasError ? Colors.orange : Colors.white, activeFillColor:
hasError ? Colors.orange : Colors.white,
), ),
cursorColor: Colors.black, cursorColor: Colors.black,
animationDuration: Duration(milliseconds: 300), animationDuration: Duration(milliseconds: 300),
@ -105,9 +172,10 @@ class WalletOptionsState extends State<WalletOptions> {
blurRadius: 10, blurRadius: 10,
) )
], ],
onCompleted: (v) async { onCompleted: (_pin) async {
print("Completed"); print("Completed");
final resultWallet = await readLocalWallet(v.toUpperCase()); final resultWallet =
await readLocalWallet(_pin.toUpperCase());
if (resultWallet == 'bad') { if (resultWallet == 'bad') {
errorController.add(ErrorAnimationType errorController.add(ErrorAnimationType
.shake); // Triggering error shake animation .shake); // Triggering error shake animation
@ -116,9 +184,11 @@ class WalletOptionsState extends State<WalletOptions> {
pinColor = Colors.red[200]; pinColor = Colors.red[200];
}); });
} else { } else {
setState(() {
pinColor = Colors.green[200]; pinColor = Colors.green[200];
}); // setState(() {});
// await Future.delayed(Duration(milliseconds: 50));
isWalletUnlock = true;
setState(() {});
} }
}, },
onChanged: (value) { onChanged: (value) {
@ -130,23 +200,8 @@ class WalletOptionsState extends State<WalletOptions> {
print(value); print(value);
}, },
)), )),
), )
SizedBox( ]))),
height: 100,
),
SizedBox(
height: 80,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
elevation: 2,
primary: Colors.red, //Color(0xffFFD68E), // background
onPrimary: Colors.black, // foreground
),
onPressed: () {
deleteWallet(widget.walletName);
},
child: Text('Supprimer ce portefeuille',
style: TextStyle(fontSize: 25))))
])))); ]))));
} }
@ -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>[