Split walletOptions and changePin provider; Apply change PIN lenght +- 3Go RAM
This commit is contained in:
parent
54a4e0dae3
commit
f450f0a181
|
@ -54,3 +54,5 @@ packages/dubp_rs/lib/ffi.dart
|
||||||
|
|
||||||
# Rust things
|
# Rust things
|
||||||
/target
|
/target
|
||||||
|
|
||||||
|
pubkeys.txt
|
||||||
|
|
|
@ -6,3 +6,4 @@ Directory walletsDirectory;
|
||||||
String appVersion;
|
String appVersion;
|
||||||
SharedPreferences prefs;
|
SharedPreferences prefs;
|
||||||
String endPointGVA;
|
String endPointGVA;
|
||||||
|
int ramSys;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:dubp/dubp.dart';
|
import 'package:dubp/dubp.dart';
|
||||||
import 'package:gecko/globals.dart';
|
import 'package:gecko/globals.dart';
|
||||||
import 'package:gecko/models/cesiumPlus.dart';
|
import 'package:gecko/models/cesiumPlus.dart';
|
||||||
|
import 'package:gecko/models/changePin.dart';
|
||||||
import 'package:gecko/models/generateWallets.dart';
|
import 'package:gecko/models/generateWallets.dart';
|
||||||
import 'package:gecko/models/history.dart';
|
import 'package:gecko/models/history.dart';
|
||||||
import 'package:gecko/models/home.dart';
|
import 'package:gecko/models/home.dart';
|
||||||
|
@ -14,6 +15,7 @@ import 'package:provider/provider.dart';
|
||||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import "package:system_info/system_info.dart";
|
||||||
|
|
||||||
final bool enableSentry = true;
|
final bool enableSentry = true;
|
||||||
|
|
||||||
|
@ -28,6 +30,8 @@ Future<void> main() async {
|
||||||
await _homeProvider.createDefaultAvatar();
|
await _homeProvider.createDefaultAvatar();
|
||||||
appVersion = await _homeProvider.getAppVersion();
|
appVersion = await _homeProvider.getAppVersion();
|
||||||
prefs = await SharedPreferences.getInstance();
|
prefs = await SharedPreferences.getInstance();
|
||||||
|
ramSys = SysInfo.getTotalPhysicalMemory() ~/ 800000;
|
||||||
|
print("Votre appareil fait $ramSys de RAM.");
|
||||||
final HiveStore _store =
|
final HiveStore _store =
|
||||||
await HiveStore.open(path: '${appPath.path}/gqlCache');
|
await HiveStore.open(path: '${appPath.path}/gqlCache');
|
||||||
|
|
||||||
|
@ -91,6 +95,7 @@ class Gecko extends StatelessWidget {
|
||||||
ChangeNotifierProvider(create: (_) => MyWalletsProvider()),
|
ChangeNotifierProvider(create: (_) => MyWalletsProvider()),
|
||||||
ChangeNotifierProvider(create: (_) => GenerateWalletsProvider()),
|
ChangeNotifierProvider(create: (_) => GenerateWalletsProvider()),
|
||||||
ChangeNotifierProvider(create: (_) => WalletOptionsProvider()),
|
ChangeNotifierProvider(create: (_) => WalletOptionsProvider()),
|
||||||
|
ChangeNotifierProvider(create: (_) => ChangePinProvider()),
|
||||||
ChangeNotifierProvider(create: (_) => CesiumPlusProvider())
|
ChangeNotifierProvider(create: (_) => CesiumPlusProvider())
|
||||||
],
|
],
|
||||||
child: GraphQLProvider(
|
child: GraphQLProvider(
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:dubp/dubp.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'dart:async';
|
||||||
|
import 'package:gecko/globals.dart';
|
||||||
|
|
||||||
|
class ChangePinProvider with ChangeNotifier {
|
||||||
|
bool ischangedPin = false;
|
||||||
|
TextEditingController newPin = new TextEditingController();
|
||||||
|
|
||||||
|
Future<NewWallet> get badWallet => null;
|
||||||
|
|
||||||
|
Future<NewWallet> changePin(_name, _oldPin) async {
|
||||||
|
try {
|
||||||
|
final _walletFile = Directory('${walletsDirectory.path}/$_name');
|
||||||
|
final _dewif =
|
||||||
|
File(_walletFile.path + '/wallet.dewif').readAsLinesSync()[0];
|
||||||
|
|
||||||
|
NewWallet newWalletFile = await DubpRust.changeDewifPin(
|
||||||
|
dewif: _dewif,
|
||||||
|
oldPin: _oldPin,
|
||||||
|
);
|
||||||
|
|
||||||
|
newPin.text = newWalletFile.pin;
|
||||||
|
ischangedPin = true;
|
||||||
|
notifyListeners();
|
||||||
|
return newWalletFile;
|
||||||
|
} catch (e) {
|
||||||
|
print('Impossible de changer le code PIN.');
|
||||||
|
return badWallet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future storeWallet(context, _name, _newWalletFile) async {
|
||||||
|
final Directory walletNameDirectory =
|
||||||
|
Directory('${walletsDirectory.path}/$_name');
|
||||||
|
final walletFile = File('${walletNameDirectory.path}/wallet.dewif');
|
||||||
|
print(_newWalletFile);
|
||||||
|
|
||||||
|
walletFile.writeAsString('${_newWalletFile.dewif}');
|
||||||
|
Navigator.pop(context);
|
||||||
|
return _name;
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,7 +15,7 @@ class WalletOptionsProvider with ChangeNotifier {
|
||||||
|
|
||||||
Future<NewWallet> get badWallet => null;
|
Future<NewWallet> get badWallet => null;
|
||||||
|
|
||||||
Future _getPubkeyFromDewif(_dewif, _pin) async {
|
Future _getPubkeyFromDewif(_dewif, _pin, _pinLenght) async {
|
||||||
String _pubkey;
|
String _pubkey;
|
||||||
RegExp regExp = new RegExp(
|
RegExp regExp = new RegExp(
|
||||||
r'^[A-Z0-9]+$',
|
r'^[A-Z0-9]+$',
|
||||||
|
@ -23,7 +23,7 @@ class WalletOptionsProvider with ChangeNotifier {
|
||||||
multiLine: false,
|
multiLine: false,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (regExp.hasMatch(_pin) == true && _pin.length == 6) {
|
if (regExp.hasMatch(_pin) == true && _pin.length == _pinLenght) {
|
||||||
print("Le format du code PIN est correct.");
|
print("Le format du code PIN est correct.");
|
||||||
} else {
|
} else {
|
||||||
print('Format de code PIN invalide');
|
print('Format de code PIN invalide');
|
||||||
|
@ -50,14 +50,15 @@ class WalletOptionsProvider with ChangeNotifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future readLocalWallet(String _name, String _pin) async {
|
Future readLocalWallet(String _name, String _pin, _pinLenght) async {
|
||||||
isWalletUnlock = false;
|
isWalletUnlock = false;
|
||||||
try {
|
try {
|
||||||
File _walletFile = File('${walletsDirectory.path}/$_name/wallet.dewif');
|
File _walletFile = File('${walletsDirectory.path}/$_name/wallet.dewif');
|
||||||
String _localDewif = await _walletFile.readAsString();
|
String _localDewif = await _walletFile.readAsString();
|
||||||
String _localPubkey;
|
String _localPubkey;
|
||||||
|
|
||||||
if ((_localPubkey = await _getPubkeyFromDewif(_localDewif, _pin)) !=
|
if ((_localPubkey =
|
||||||
|
await _getPubkeyFromDewif(_localDewif, _pin, _pinLenght)) !=
|
||||||
'false') {
|
'false') {
|
||||||
this.pubkey.text = _localPubkey;
|
this.pubkey.text = _localPubkey;
|
||||||
isWalletUnlock = true;
|
isWalletUnlock = true;
|
||||||
|
@ -201,6 +202,7 @@ class WalletOptionsProvider with ChangeNotifier {
|
||||||
final Directory walletNameDirectory =
|
final Directory walletNameDirectory =
|
||||||
Directory('${walletsDirectory.path}/$_name');
|
Directory('${walletsDirectory.path}/$_name');
|
||||||
final walletFile = File('${walletNameDirectory.path}/wallet.dewif');
|
final walletFile = File('${walletNameDirectory.path}/wallet.dewif');
|
||||||
|
print(_newWalletFile);
|
||||||
|
|
||||||
walletFile.writeAsString('${_newWalletFile.dewif}');
|
walletFile.writeAsString('${_newWalletFile.dewif}');
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:dubp/dubp.dart';
|
import 'package:dubp/dubp.dart';
|
||||||
import 'package:gecko/models/walletOptions.dart';
|
import 'package:gecko/models/changePin.dart';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
@ -17,68 +17,85 @@ class ChangePinScreen extends StatelessWidget with ChangeNotifier {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
WalletOptionsProvider _walletOptions =
|
ChangePinProvider _changePin = Provider.of<ChangePinProvider>(context);
|
||||||
Provider.of<WalletOptionsProvider>(context);
|
// _walletOptions.changePin(walletName, oldPin);
|
||||||
_walletOptions.changePin(walletName, oldPin);
|
// _walletOptions.newPin.text = _tmpPin;
|
||||||
return Scaffold(
|
return WillPopScope(
|
||||||
resizeToAvoidBottomInset: false,
|
onWillPop: () {
|
||||||
appBar: AppBar(
|
_changePin.newPin.text = '';
|
||||||
title: SizedBox(
|
return Future<bool>.value(true);
|
||||||
height: 22,
|
},
|
||||||
child: Text(walletName),
|
child: Scaffold(
|
||||||
)),
|
resizeToAvoidBottomInset: false,
|
||||||
body: Center(
|
appBar: AppBar(
|
||||||
child: SafeArea(
|
leading: IconButton(
|
||||||
child: Column(children: <Widget>[
|
icon: Icon(Icons.arrow_back, color: Colors.black),
|
||||||
SizedBox(height: 80),
|
onPressed: () {
|
||||||
Text(
|
_changePin.newPin.text = '';
|
||||||
'Choisissez un code secret autogénéré :',
|
Navigator.of(context).pop();
|
||||||
textAlign: TextAlign.center,
|
}),
|
||||||
style: TextStyle(
|
title: SizedBox(
|
||||||
fontSize: 17.0,
|
height: 22,
|
||||||
color: Colors.grey[600],
|
child: Text(walletName),
|
||||||
fontWeight: FontWeight.w400),
|
)),
|
||||||
),
|
body: Center(
|
||||||
SizedBox(height: 30),
|
child: SafeArea(
|
||||||
Container(
|
child: Column(children: <Widget>[
|
||||||
child: Stack(
|
SizedBox(height: 80),
|
||||||
alignment: Alignment.centerRight,
|
Text(
|
||||||
children: <Widget>[
|
'Choisissez un code secret autogénéré :',
|
||||||
TextField(
|
textAlign: TextAlign.center,
|
||||||
enabled: true,
|
style: TextStyle(
|
||||||
controller: _walletOptions.newPin,
|
fontSize: 17.0,
|
||||||
maxLines: 1,
|
color: Colors.grey[600],
|
||||||
textAlign: TextAlign.center,
|
fontWeight: FontWeight.w400),
|
||||||
decoration: InputDecoration(),
|
),
|
||||||
style: TextStyle(
|
SizedBox(height: 30),
|
||||||
fontSize: 30.0,
|
Container(
|
||||||
color: Colors.black,
|
child: Stack(
|
||||||
fontWeight: FontWeight.bold)),
|
alignment: Alignment.centerRight,
|
||||||
IconButton(
|
children: <Widget>[
|
||||||
icon: Icon(Icons.replay),
|
TextField(
|
||||||
color: Color(0xffD28928),
|
enabled: true,
|
||||||
onPressed: () async {
|
controller: _changePin.newPin,
|
||||||
_newWalletFile =
|
maxLines: 1,
|
||||||
await _walletOptions.changePin(walletName, oldPin);
|
textAlign: TextAlign.center,
|
||||||
},
|
decoration: InputDecoration(),
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 30.0,
|
||||||
|
color: Colors.black,
|
||||||
|
fontWeight: FontWeight.bold)),
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.replay),
|
||||||
|
color: Color(0xffD28928),
|
||||||
|
onPressed: () async {
|
||||||
|
_newWalletFile =
|
||||||
|
await _changePin.changePin(walletName, oldPin);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
SizedBox(height: 30),
|
||||||
),
|
SizedBox(
|
||||||
SizedBox(height: 30),
|
width: 200,
|
||||||
SizedBox(
|
height: 50,
|
||||||
width: 200,
|
child: ElevatedButton(
|
||||||
height: 50,
|
style: ElevatedButton.styleFrom(
|
||||||
child: ElevatedButton(
|
elevation: 12,
|
||||||
style: ElevatedButton.styleFrom(
|
primary:
|
||||||
elevation: 12,
|
Colors.green[400], //Color(0xffFFD68E), // background
|
||||||
primary: Colors.green[400], //Color(0xffFFD68E), // background
|
onPrimary: Colors.black, // foreground
|
||||||
onPrimary: Colors.black, // foreground
|
),
|
||||||
),
|
onPressed: _changePin.newPin.text != ''
|
||||||
onPressed: () => _walletOptions.storeWallet(
|
? () {
|
||||||
context, walletName, _newWalletFile),
|
_changePin.newPin.text = '';
|
||||||
child: Text('Confirmer', style: TextStyle(fontSize: 28))),
|
_changePin.storeWallet(
|
||||||
)
|
context, walletName, _newWalletFile);
|
||||||
]))));
|
}
|
||||||
|
: null,
|
||||||
|
child: Text('Confirmer', style: TextStyle(fontSize: 28))),
|
||||||
|
)
|
||||||
|
])))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:dubp/dubp.dart';
|
import 'package:dubp/dubp.dart';
|
||||||
|
import 'package:gecko/globals.dart';
|
||||||
import 'package:gecko/models/myWallets.dart';
|
import 'package:gecko/models/myWallets.dart';
|
||||||
import 'package:gecko/models/walletOptions.dart';
|
import 'package:gecko/models/walletOptions.dart';
|
||||||
import 'package:gecko/screens/myWallets/changePin.dart';
|
import 'package:gecko/screens/myWallets/changePin.dart';
|
||||||
|
@ -21,6 +22,7 @@ class WalletOptions extends StatelessWidget with ChangeNotifier {
|
||||||
bool hasError = false;
|
bool hasError = false;
|
||||||
var pinColor = Color(0xffF9F9F1);
|
var pinColor = Color(0xffF9F9F1);
|
||||||
var walletPin = '';
|
var walletPin = '';
|
||||||
|
int _pinLenght;
|
||||||
|
|
||||||
Future<NewWallet> get badWallet => null;
|
Future<NewWallet> get badWallet => null;
|
||||||
|
|
||||||
|
@ -33,6 +35,11 @@ class WalletOptions extends StatelessWidget with ChangeNotifier {
|
||||||
Provider.of<MyWalletsProvider>(context);
|
Provider.of<MyWalletsProvider>(context);
|
||||||
errorController = StreamController<ErrorAnimationType>();
|
errorController = StreamController<ErrorAnimationType>();
|
||||||
// _walletOptions.isWalletUnlock = false;
|
// _walletOptions.isWalletUnlock = false;
|
||||||
|
if (ramSys <= 3000) {
|
||||||
|
_pinLenght = 6;
|
||||||
|
} else {
|
||||||
|
_pinLenght = 5;
|
||||||
|
}
|
||||||
|
|
||||||
return WillPopScope(
|
return WillPopScope(
|
||||||
onWillPop: () {
|
onWillPop: () {
|
||||||
|
@ -45,8 +52,8 @@ class WalletOptions extends StatelessWidget with ChangeNotifier {
|
||||||
leading: IconButton(
|
leading: IconButton(
|
||||||
icon: Icon(Icons.arrow_back, color: Colors.black),
|
icon: Icon(Icons.arrow_back, color: Colors.black),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop();
|
|
||||||
_walletOptions.isWalletUnlock = false;
|
_walletOptions.isWalletUnlock = false;
|
||||||
|
Navigator.of(context).pop();
|
||||||
}),
|
}),
|
||||||
title: SizedBox(
|
title: SizedBox(
|
||||||
height: 22,
|
height: 22,
|
||||||
|
@ -201,13 +208,13 @@ class WalletOptions extends StatelessWidget with ChangeNotifier {
|
||||||
color: Colors.green.shade600,
|
color: Colors.green.shade600,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
length: 6,
|
length: _pinLenght,
|
||||||
obscureText: false,
|
obscureText: false,
|
||||||
obscuringCharacter: '*',
|
obscuringCharacter: '*',
|
||||||
animationType: AnimationType.fade,
|
animationType: AnimationType.fade,
|
||||||
validator: (v) {
|
validator: (v) {
|
||||||
if (v.length < 6) {
|
if (v.length < _pinLenght) {
|
||||||
return "Votre code PIN fait 6 caractères";
|
return "Votre code PIN fait $_pinLenght caractères";
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -243,7 +250,8 @@ class WalletOptions extends StatelessWidget with ChangeNotifier {
|
||||||
final resultWallet =
|
final resultWallet =
|
||||||
await _walletOptions.readLocalWallet(
|
await _walletOptions.readLocalWallet(
|
||||||
this.walletName,
|
this.walletName,
|
||||||
_pin.toUpperCase());
|
_pin.toUpperCase(),
|
||||||
|
_pinLenght);
|
||||||
if (resultWallet == 'bad') {
|
if (resultWallet == 'bad') {
|
||||||
errorController.add(ErrorAnimationType
|
errorController.add(ErrorAnimationType
|
||||||
.shake); // Triggering error shake animation
|
.shake); // Triggering error shake animation
|
||||||
|
|
Loading…
Reference in New Issue