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