2021-03-08 02:20:48 +01:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:dubp/dubp.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2021-04-03 00:07:03 +02:00
|
|
|
import 'package:gecko/models/history.dart';
|
2021-03-31 02:38:44 +02:00
|
|
|
import 'package:gecko/models/myWallets.dart';
|
2021-03-08 02:20:48 +01:00
|
|
|
import 'package:gecko/models/walletOptions.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:pin_code_fields/pin_code_fields.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2021-04-02 12:05:37 +02:00
|
|
|
import 'package:gecko/globals.dart';
|
2021-03-08 02:20:48 +01:00
|
|
|
|
|
|
|
// ignore: must_be_immutable
|
|
|
|
class UnlockingWallet extends StatelessWidget {
|
2021-04-03 00:07:03 +02:00
|
|
|
UnlockingWallet(
|
|
|
|
{Key keyUnlockWallet, @required this.wallet, @required this.action})
|
|
|
|
: super(key: keyUnlockWallet);
|
2021-03-31 02:38:44 +02:00
|
|
|
WalletData wallet;
|
2021-04-03 00:07:03 +02:00
|
|
|
String action;
|
2021-03-08 02:20:48 +01:00
|
|
|
|
|
|
|
// ignore: close_sinks
|
|
|
|
StreamController<ErrorAnimationType> errorController;
|
|
|
|
final formKey = GlobalKey<FormState>();
|
|
|
|
bool hasError = false;
|
|
|
|
var pinColor = Color(0xffF9F9F1);
|
|
|
|
var walletPin = '';
|
2021-04-03 12:50:34 +02:00
|
|
|
String resultPay;
|
2021-03-08 02:20:48 +01:00
|
|
|
|
|
|
|
Future<NewWallet> get badWallet => null;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
|
|
|
WalletOptionsProvider _walletOptions =
|
|
|
|
Provider.of<WalletOptionsProvider>(context);
|
2021-04-03 02:39:09 +02:00
|
|
|
|
|
|
|
log.d("defaultWallet: " + defaultWallet.toString());
|
|
|
|
final int _pinLenght = _walletOptions.getPinLenght(wallet.number);
|
2021-03-08 02:20:48 +01:00
|
|
|
errorController = StreamController<ErrorAnimationType>();
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
// backgroundColor: Colors.brown[600],
|
|
|
|
body: SafeArea(
|
|
|
|
child: Column(children: <Widget>[
|
|
|
|
SizedBox(height: 20),
|
|
|
|
Expanded(
|
|
|
|
child: Column(children: <Widget>[
|
|
|
|
SizedBox(height: 150),
|
|
|
|
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),
|
2021-03-31 02:38:44 +02:00
|
|
|
pinForm(context, _pinLenght, wallet.number, wallet.derivation),
|
2021-03-08 02:20:48 +01:00
|
|
|
]),
|
|
|
|
),
|
|
|
|
GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.popUntil(
|
|
|
|
context,
|
|
|
|
ModalRoute.withName('/'),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: Icon(Icons.home))
|
|
|
|
]),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget pinForm(context, _pinLenght, int _walletNbr, int _derivation) {
|
|
|
|
// var _walletPin = '';
|
|
|
|
// ignore: close_sinks
|
|
|
|
StreamController<ErrorAnimationType> errorController =
|
|
|
|
StreamController<ErrorAnimationType>();
|
|
|
|
TextEditingController _enterPin = TextEditingController();
|
|
|
|
WalletOptionsProvider _walletOptions =
|
|
|
|
Provider.of<WalletOptionsProvider>(context);
|
2021-04-03 00:07:03 +02:00
|
|
|
MyWalletsProvider _myWalletProvider =
|
|
|
|
Provider.of<MyWalletsProvider>(context);
|
|
|
|
HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context);
|
2021-03-08 02:20:48 +01:00
|
|
|
|
|
|
|
return Form(
|
|
|
|
key: formKey,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 30),
|
|
|
|
child: PinCodeTextField(
|
|
|
|
autoFocus: true,
|
|
|
|
appContext: context,
|
|
|
|
pastedTextStyle: TextStyle(
|
|
|
|
color: Colors.green.shade600,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
length: _pinLenght,
|
|
|
|
obscureText: false,
|
|
|
|
obscuringCharacter: '*',
|
|
|
|
animationType: AnimationType.fade,
|
|
|
|
validator: (v) {
|
|
|
|
if (v.length < _pinLenght) {
|
|
|
|
return "Votre code PIN fait $_pinLenght caractères";
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
pinTheme: PinTheme(
|
|
|
|
activeColor: pinColor,
|
|
|
|
borderWidth: 4,
|
|
|
|
shape: PinCodeFieldShape.box,
|
|
|
|
borderRadius: BorderRadius.circular(5),
|
|
|
|
fieldHeight: 60,
|
|
|
|
fieldWidth: 50,
|
|
|
|
activeFillColor: hasError ? Colors.blueAccent : Colors.black,
|
|
|
|
),
|
|
|
|
cursorColor: Colors.black,
|
|
|
|
animationDuration: Duration(milliseconds: 300),
|
|
|
|
textStyle: TextStyle(fontSize: 20, height: 1.6),
|
|
|
|
backgroundColor: Color(0xffF9F9F1),
|
|
|
|
enableActiveFill: false,
|
|
|
|
errorAnimationController: errorController,
|
|
|
|
controller: _enterPin,
|
|
|
|
keyboardType: TextInputType.text,
|
|
|
|
boxShadows: [
|
|
|
|
BoxShadow(
|
|
|
|
offset: Offset(0, 1),
|
|
|
|
color: Colors.black12,
|
|
|
|
blurRadius: 10,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
onCompleted: (_pin) async {
|
2021-04-02 12:05:37 +02:00
|
|
|
log.d("Completed");
|
2021-04-03 02:39:09 +02:00
|
|
|
_myWalletProvider.pinCode = _pin;
|
2021-03-08 02:20:48 +01:00
|
|
|
final resultWallet = await _walletOptions.readLocalWallet(
|
2021-03-31 02:38:44 +02:00
|
|
|
context, this.wallet, _pin.toUpperCase(), _pinLenght);
|
2021-04-03 00:07:03 +02:00
|
|
|
// _myWalletProvider.pinCode = _pin.toUpperCase();
|
|
|
|
_myWalletProvider.pinLenght = _pinLenght;
|
|
|
|
|
2021-03-08 02:20:48 +01:00
|
|
|
if (resultWallet == 'bad') {
|
|
|
|
errorController.add(ErrorAnimationType
|
|
|
|
.shake); // Triggering error shake animation
|
|
|
|
hasError = true;
|
|
|
|
pinColor = Colors.red[600];
|
|
|
|
_walletOptions.reloadBuild();
|
|
|
|
} else {
|
|
|
|
pinColor = Colors.green[400];
|
|
|
|
// await Future.delayed(Duration(milliseconds: 50));
|
2021-04-03 00:07:03 +02:00
|
|
|
if (action == "mywallets") {
|
|
|
|
Navigator.pushNamed(formKey.currentContext, '/mywallets');
|
|
|
|
} else if (action == "pay") {
|
|
|
|
print("Go payments");
|
2021-04-03 12:50:34 +02:00
|
|
|
resultPay =
|
|
|
|
await _historyProvider.pay(context, _pin.toUpperCase());
|
|
|
|
await _paymentsResult(context);
|
2021-04-03 00:07:03 +02:00
|
|
|
}
|
2021-03-08 02:20:48 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onChanged: (value) {
|
|
|
|
if (pinColor != Color(0xFFA4B600)) {
|
|
|
|
pinColor = Color(0xFFA4B600);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
2021-04-03 12:50:34 +02:00
|
|
|
|
|
|
|
Future<bool> _paymentsResult(context) {
|
|
|
|
return showDialog<bool>(
|
|
|
|
context: context,
|
|
|
|
barrierDismissible: true, // user must tap button!
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertDialog(
|
|
|
|
title: Text(resultPay == "Success"
|
|
|
|
? 'Paiement effecuté avec succès !'
|
|
|
|
: "Une erreur s'est produite lors du paiement"),
|
|
|
|
content: SingleChildScrollView(child: Text('')),
|
|
|
|
actions: <Widget>[
|
|
|
|
TextButton(
|
|
|
|
child: Text("OK"),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.popUntil(
|
|
|
|
context,
|
|
|
|
ModalRoute.withName('/'),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2021-03-08 02:20:48 +01:00
|
|
|
}
|