2021-12-19 14:55:47 +01:00
|
|
|
import 'package:durt/durt.dart';
|
2021-02-08 13:36:50 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:gecko/globals.dart';
|
|
|
|
|
|
|
|
class ChangePinProvider with ChangeNotifier {
|
|
|
|
bool ischangedPin = false;
|
2021-11-14 19:21:20 +01:00
|
|
|
TextEditingController newPin = TextEditingController();
|
2021-12-23 12:36:09 +01:00
|
|
|
String? pinToGive;
|
2021-02-08 13:36:50 +01:00
|
|
|
|
2021-12-23 12:36:09 +01:00
|
|
|
NewWallet? get badWallet => null;
|
2021-02-08 13:36:50 +01:00
|
|
|
|
2021-12-23 15:13:58 +01:00
|
|
|
Future<NewWallet?> changePin(String _oldPin, {String? newCustomPin}) async {
|
|
|
|
final NewWallet newWalletFile;
|
2021-02-08 13:36:50 +01:00
|
|
|
try {
|
2021-12-23 15:13:58 +01:00
|
|
|
final _chest = chestBox.get(configBox.get('currentChest'))!;
|
|
|
|
|
|
|
|
if (_chest.isCesium!) {
|
|
|
|
newWalletFile = await Dewif().changeCesiumPassword(
|
|
|
|
dewif: _chest.dewif!,
|
|
|
|
oldPassword: _oldPin.toUpperCase(),
|
|
|
|
newPassword: newCustomPin);
|
|
|
|
} else {
|
|
|
|
newWalletFile = await Dewif().changePassword(
|
|
|
|
dewif: _chest.dewif!,
|
|
|
|
oldPassword: _oldPin.toUpperCase(),
|
|
|
|
newPassword: newCustomPin);
|
|
|
|
}
|
2021-12-19 14:55:47 +01:00
|
|
|
newPin.text = pinToGive = newWalletFile.password;
|
2021-02-08 13:36:50 +01:00
|
|
|
ischangedPin = true;
|
2021-12-20 21:33:03 +01:00
|
|
|
// notifyListeners();
|
2021-02-08 13:36:50 +01:00
|
|
|
return newWalletFile;
|
|
|
|
} catch (e) {
|
2021-12-20 21:33:03 +01:00
|
|
|
log.e('Impossible de changer le code PIN: $e');
|
2021-02-08 13:36:50 +01:00
|
|
|
return badWallet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-18 02:37:46 +01:00
|
|
|
void storeNewPinChest(context, NewWallet _newWalletFile) {
|
|
|
|
// ChestData currentChest = chestBox.getAt(configBox.get('currentChest'));
|
|
|
|
// currentChest.dewif = _newWalletFile.dewif;
|
|
|
|
// await chestBox.add(currentChest);
|
2021-02-08 13:36:50 +01:00
|
|
|
|
2021-12-23 12:36:09 +01:00
|
|
|
chestBox.get(configBox.get('currentChest'))!.dewif = _newWalletFile.dewif;
|
2021-11-18 02:37:46 +01:00
|
|
|
|
|
|
|
Navigator.pop(context, pinToGive);
|
|
|
|
pinToGive = '';
|
2021-02-08 13:36:50 +01:00
|
|
|
}
|
|
|
|
}
|