Can change pin code of Cesium chest

This commit is contained in:
poka 2021-11-18 02:37:46 +01:00
parent 106fcf2835
commit dfbab5a219
9 changed files with 134 additions and 75 deletions

BIN
assets/chests/secret_code.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@ -3,24 +3,24 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:gecko/globals.dart';
import 'package:gecko/models/chest_data.dart';
class ChangePinProvider with ChangeNotifier {
bool ischangedPin = false;
TextEditingController newPin = TextEditingController();
String pinToGive;
Future<NewWallet> get badWallet => null;
Future<NewWallet> changePin(_name, _oldPin) async {
Future<NewWallet> changePin(String _oldPin) async {
try {
final _dewif = chestBox.get(configBox.get('currentChest')).dewif;
NewWallet newWalletFile = await DubpRust.changeDewifPin(
dewif: _dewif,
oldPin: _oldPin,
oldPin: _oldPin.toUpperCase(),
);
newPin.text = newWalletFile.pin;
newPin.text = pinToGive = newWalletFile.pin;
ischangedPin = true;
notifyListeners();
return newWalletFile;
@ -30,12 +30,14 @@ class ChangePinProvider with ChangeNotifier {
}
}
Future storeNewPinChest(context, NewWallet _newWalletFile) async {
ChestData currentChest = chestBox.getAt(configBox.get('currentChest'));
currentChest.dewif = _newWalletFile.dewif;
// currentChest.name = _name;
chestBox.add(currentChest);
void storeNewPinChest(context, NewWallet _newWalletFile) {
// ChestData currentChest = chestBox.getAt(configBox.get('currentChest'));
// currentChest.dewif = _newWalletFile.dewif;
// await chestBox.add(currentChest);
Navigator.pop(context);
chestBox.get(configBox.get('currentChest')).dewif = _newWalletFile.dewif;
Navigator.pop(context, pinToGive);
pinToGive = '';
}
}

View File

@ -12,15 +12,19 @@ class ChestProvider with ChangeNotifier {
final bool _answer = await _confirmDeletingChest(context, _chest.name);
if (_answer) {
chestBox.delete(_chest.key);
int lastChest = chestBox.toMap().keys.first;
configBox.put('currentChest', lastChest);
notifyListeners();
await chestBox.delete(_chest.key);
if (chestBox.isEmpty) {
await configBox.put('currentChest', 0);
} else {
int lastChest = chestBox.toMap().keys.first;
await configBox.put('currentChest', lastChest);
}
Navigator.popUntil(
context,
ModalRoute.withName('/'),
);
notifyListeners();
}
}

View File

@ -174,7 +174,7 @@ class HomeScreen extends StatelessWidget {
]),
),
Padding(
padding: EdgeInsets.only(top: isTall ? 70 : 60),
padding: EdgeInsets.only(top: isTall ? 100 : 60),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[

View File

@ -6,8 +6,10 @@ import 'package:gecko/globals.dart';
import 'package:gecko/models/chest_data.dart';
import 'package:gecko/models/chest_provider.dart';
import 'package:gecko/models/history.dart';
import 'package:gecko/models/my_wallets.dart';
import 'package:gecko/models/queries.dart';
import 'package:gecko/models/wallet_options.dart';
import 'package:gecko/screens/myWallets/change_pin.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:provider/provider.dart';
import 'package:flutter/services.dart';
@ -15,11 +17,13 @@ import 'package:flutter/services.dart';
int _nbrLinesName = 1;
bool _isNewNameValid = false;
Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet) {
Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
MyWalletsProvider _myWalletProvider) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
WalletOptionsProvider _walletOptions =
Provider.of<WalletOptionsProvider>(context);
ChestProvider _chestProvider = Provider.of<ChestProvider>(context);
ChestProvider _chestProvider =
Provider.of<ChestProvider>(context, listen: false);
HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context);
final String shortPubkey =
@ -231,7 +235,7 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet) {
Image.asset(
'assets/walletOptions/key.png',
),
const SizedBox(width: 10),
const SizedBox(width: 20),
Text("${shortPubkey.split(':')[0]}:",
style: const TextStyle(
fontSize: 22,
@ -284,25 +288,63 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet) {
Image.asset(
'assets/walletOptions/clock.png',
),
const SizedBox(width: 12),
const SizedBox(width: 22),
const Text('Historique des transactions',
style: TextStyle(fontSize: 20, color: Colors.black)),
]))),
SizedBox(height: 12 * ratio),
SizedBox(height: 7 * ratio),
InkWell(
key: const Key('deleteWallet'),
onTap: () async {
await _chestProvider.deleteChest(context, cesiumWallet);
},
key: const Key('changePin'),
onTap: () async {
// await _chestProvider.changePin(context, cesiumWallet);
_myWalletProvider.pinCode = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return ChangePinScreen(
walletName: cesiumWallet.name,
walletProvider: _myWalletProvider,
);
},
),
);
},
child: SizedBox(
height: 50,
child: Row(children: <Widget>[
const SizedBox(width: 28),
Image.asset(
'assets/chests/secret_code.png',
),
const SizedBox(width: 18),
const Text('Changer mon code secret',
style: TextStyle(fontSize: 20, color: Colors.black)),
])),
),
SizedBox(height: 7 * ratio),
InkWell(
key: const Key('deleteWallet'),
onTap: () async {
await _chestProvider.deleteChest(context, cesiumWallet);
},
child: SizedBox(
height: 50,
child: Row(children: <Widget>[
const SizedBox(width: 33),
Image.asset(
'assets/walletOptions/trash.png',
),
const SizedBox(width: 14),
const Text('Supprimer ce coffre',
style: TextStyle(fontSize: 20, color: Color(0xffD80000))),
])),
const SizedBox(width: 25),
const Text(
'Supprimer ce coffre',
style: TextStyle(
fontSize: 20,
color: Color(0xffD80000),
),
),
]),
),
),
]),
),
),

View File

@ -4,16 +4,19 @@ import 'package:dubp/dubp.dart';
import 'package:flutter/services.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/models/change_pin.dart';
import 'package:gecko/models/my_wallets.dart';
import 'dart:io';
import 'package:provider/provider.dart';
// ignore: must_be_immutable
class ChangePinScreen extends StatelessWidget with ChangeNotifier {
ChangePinScreen(
{Key keyMyWallets, @required this.walletName, @required this.oldPin})
{Key keyMyWallets,
@required this.walletName,
@required this.walletProvider})
: super(key: keyMyWallets);
final String walletName;
final String oldPin;
final MyWalletsProvider walletProvider;
Directory appPath;
NewWallet _newWalletFile;
@ -24,27 +27,27 @@ class ChangePinScreen extends StatelessWidget with ChangeNotifier {
// _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(
toolbarHeight: 60 * ratio,
leading: IconButton(
icon: const 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>[
onWillPop: () {
_changePin.newPin.text = '';
return Future<bool>.value(true);
},
child: Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
toolbarHeight: 60 * ratio,
leading: IconButton(
icon: const 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>[
const SizedBox(height: 80),
Text(
'Choisissez un code secret autogénéré :',
@ -59,7 +62,7 @@ class ChangePinScreen extends StatelessWidget with ChangeNotifier {
alignment: Alignment.centerRight,
children: <Widget>[
TextField(
enabled: true,
enabled: false,
controller: _changePin.newPin,
maxLines: 1,
textAlign: TextAlign.center,
@ -73,7 +76,7 @@ class ChangePinScreen extends StatelessWidget with ChangeNotifier {
color: orangeC,
onPressed: () async {
_newWalletFile =
await _changePin.changePin(walletName, oldPin);
await _changePin.changePin(walletProvider.pinCode);
},
),
],
@ -83,21 +86,28 @@ class ChangePinScreen extends StatelessWidget with ChangeNotifier {
width: 200,
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
elevation: 12,
primary: Colors.green[400], //smoothYellow, // background
onPrimary: Colors.black, // foreground
),
onPressed: _changePin.newPin.text != ''
? () {
_changePin.newPin.text = '';
_changePin.storeNewPinChest(
context, _newWalletFile);
}
: null,
child: const Text('Confirmer',
style: TextStyle(fontSize: 28))),
style: ElevatedButton.styleFrom(
elevation: 12,
primary: Colors.green[400], //smoothYellow, // background
onPrimary: Colors.black, // foreground
),
onPressed: _changePin.newPin.text != ''
? () {
_changePin.newPin.text = '';
_changePin.storeNewPinChest(context, _newWalletFile);
walletProvider.pinCode = _changePin.newPin.text;
}
: null,
child: const Text(
'Confirmer',
style: TextStyle(fontSize: 28),
),
),
)
])))));
]),
),
),
),
);
}
}

View File

@ -63,7 +63,8 @@ class WalletsHome extends StatelessWidget {
child: !isWalletsExists
? const NoKeyChainScreen()
: _currentChest.isCesium
? cesiumWalletOptions(context, _currentChest)
? cesiumWalletOptions(
context, _currentChest, myWalletProvider)
: myWalletsTiles(context),
),
),

View File

@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0"
version: "2.8.1"
boolean_selector:
dependency: transitive
description:
@ -28,7 +28,7 @@ packages:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
clock:
dependency: transitive
description:
@ -108,7 +108,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.7.0"
path:
dependency: transitive
description:
@ -127,7 +127,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
@ -169,7 +169,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19"
version: "0.4.2"
typed_data:
dependency: transitive
description:

View File

@ -5,7 +5,7 @@ description: Pay with G1.
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 0.0.2+10
version: 0.0.2+11
environment:
sdk: ">=2.7.0 <3.0.0"