diff --git a/assets/chests/secret_code.png b/assets/chests/secret_code.png new file mode 100755 index 0000000..10ef999 Binary files /dev/null and b/assets/chests/secret_code.png differ diff --git a/lib/models/change_pin.dart b/lib/models/change_pin.dart index b65e74c..cb31cca 100644 --- a/lib/models/change_pin.dart +++ b/lib/models/change_pin.dart @@ -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 get badWallet => null; - Future changePin(_name, _oldPin) async { + Future 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 = ''; } } diff --git a/lib/models/chest_provider.dart b/lib/models/chest_provider.dart index c466e50..748315b 100644 --- a/lib/models/chest_provider.dart +++ b/lib/models/chest_provider.dart @@ -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(); } } diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 7130569..f305064 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -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: [ diff --git a/lib/screens/myWallets/cesium_wallet_options.dart b/lib/screens/myWallets/cesium_wallet_options.dart index 4e48b47..1d8854d 100644 --- a/lib/screens/myWallets/cesium_wallet_options.dart +++ b/lib/screens/myWallets/cesium_wallet_options.dart @@ -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(context); - ChestProvider _chestProvider = Provider.of(context); + ChestProvider _chestProvider = + Provider.of(context, listen: false); HistoryProvider _historyProvider = Provider.of(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: [ + 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: [ 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), + ), + ), + ]), + ), + ), ]), ), ), diff --git a/lib/screens/myWallets/change_pin.dart b/lib/screens/myWallets/change_pin.dart index 477e25c..25ba873 100644 --- a/lib/screens/myWallets/change_pin.dart +++ b/lib/screens/myWallets/change_pin.dart @@ -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.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: [ + onWillPop: () { + _changePin.newPin.text = ''; + return Future.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: [ 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: [ 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), + ), + ), ) - ]))))); + ]), + ), + ), + ), + ); } } diff --git a/lib/screens/myWallets/wallets_home.dart b/lib/screens/myWallets/wallets_home.dart index 453382e..26af3ba 100644 --- a/lib/screens/myWallets/wallets_home.dart +++ b/lib/screens/myWallets/wallets_home.dart @@ -63,7 +63,8 @@ class WalletsHome extends StatelessWidget { child: !isWalletsExists ? const NoKeyChainScreen() : _currentChest.isCesium - ? cesiumWalletOptions(context, _currentChest) + ? cesiumWalletOptions( + context, _currentChest, myWalletProvider) : myWalletsTiles(context), ), ), diff --git a/packages/dubp_rs/pubspec.lock b/packages/dubp_rs/pubspec.lock index 98f9562..e6f0b3d 100644 --- a/packages/dubp_rs/pubspec.lock +++ b/packages/dubp_rs/pubspec.lock @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index df55520..7de7c38 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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"