diff --git a/lib/main.dart b/lib/main.dart index d94aab0..94db7af 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -28,6 +28,8 @@ Future main() async { await _homeProvider.createDefaultAvatar(); appVersion = await _homeProvider.getAppVersion(); prefs = await SharedPreferences.getInstance(); + final HiveStore _store = + await HiveStore.open(path: '${appPath.path}/gqlCache'); String _randomEndpoint; int i = 0; @@ -52,21 +54,20 @@ Future main() async { options.dsn = 'https://c09587b46eaa42e8b9fda28d838ed180@o496840.ingest.sentry.io/5572110'; }, - appRunner: () => runApp(Gecko(_randomEndpoint)), + appRunner: () => runApp(Gecko(_randomEndpoint, _store)), ); } else { print('Debug mode enabled: No sentry alerte'); - runApp(Gecko( - _randomEndpoint, - )); + runApp(Gecko(_randomEndpoint, _store)); } } // ignore: must_be_immutable class Gecko extends StatelessWidget { - Gecko(this.randomEndpoint); + Gecko(this.randomEndpoint, this._store); final String randomEndpoint; + final HiveStore _store; @override Widget build(BuildContext context) { @@ -76,7 +77,7 @@ class Gecko extends StatelessWidget { final _client = ValueNotifier( GraphQLClient( - cache: GraphQLCache(store: null), + cache: GraphQLCache(store: _store), link: _httpLink, ), ); diff --git a/lib/models/history.dart b/lib/models/history.dart index 44b43bd..ec882a6 100644 --- a/lib/models/history.dart +++ b/lib/models/history.dart @@ -9,7 +9,6 @@ import 'dart:math'; import 'package:intl/intl.dart'; class HistoryProvider with ChangeNotifier { - // String pubkey = 'D2meevcAHFTS2gQMvmRW5Hzi25jDdikk4nC4u1FkwRaU'; // For debug String pubkey = ''; HistoryProvider(this.pubkey); final TextEditingController outputPubkey = new TextEditingController(); @@ -63,8 +62,10 @@ class HistoryProvider with ChangeNotifier { return ''; } +// Pi: D2meevcAHFTS2gQMvmRW5Hzi25jDdikk4nC4u1FkwRaU // For debug // Boris: JE6mkuzSpT3ePciCPRTpuMT9fqPUVVLJz2618d33p7tn -// Matograine portefeuille: 9p5nHsES6xujFR7pw2yGy4PLKKHgWsMvsDHaHF64Uj25 +// Matograine portefeuille: 9p5nHsES6xujFR7pw2yGy4PLKKHgWsMvsDHaHF64Uj25. +// Lion simone: 78jhpprYkMNF6i5kQPXfkAVBpd2aqcpieNsXTSW4c21f List parseHistory(txs, _pubkey) { // print(txs); @@ -162,7 +163,7 @@ class HistoryProvider with ChangeNotifier { return opts; } - snackNode(context) { + void snackNode(context) { if (isFirstBuild) { String _message; if (endPointGVA == 'HS') { diff --git a/lib/models/myWallets.dart b/lib/models/myWallets.dart index 03fc253..f3a4ff1 100644 --- a/lib/models/myWallets.dart +++ b/lib/models/myWallets.dart @@ -26,11 +26,9 @@ class MyWalletsProvider with ChangeNotifier { Future importWallet() async {} Map getAllWalletsNames() { - print(listWallets); if (listWallets.isNotEmpty) { listWallets.clear(); } - print(walletsDirectory.path); // int i = 0; walletsDirectory @@ -39,7 +37,6 @@ class MyWalletsProvider with ChangeNotifier { String _name = wallet.path.split('/').last; List _pubkeyList = File(wallet.path + '/pubkey').readAsLinesSync(); String _pubkey = _pubkeyList[0]; - print("$_name: $_pubkey"); listWallets[_name] = _pubkey; // i++; diff --git a/lib/models/walletOptions.dart b/lib/models/walletOptions.dart index d0abc13..eef7a76 100644 --- a/lib/models/walletOptions.dart +++ b/lib/models/walletOptions.dart @@ -52,7 +52,6 @@ class WalletOptionsProvider with ChangeNotifier { Future readLocalWallet(String _name, String _pin) async { isWalletUnlock = false; - print('NOM: ' + _name); try { File _walletFile = File('${walletsDirectory.path}/$_name/wallet.dewif'); String _localDewif = await _walletFile.readAsString(); @@ -204,9 +203,15 @@ class WalletOptionsProvider with ChangeNotifier { final walletFile = File('${walletNameDirectory.path}/wallet.dewif'); walletFile.writeAsString('${_newWalletFile.dewif}'); - Navigator.pop(context); - return _name; } + + snackCopyKey(context) { + final snackBar = SnackBar( + content: + Text("Cette clé publique a été copié dans votre presse-papier."), + duration: Duration(seconds: 2)); + Scaffold.of(context).showSnackBar(snackBar); + } } diff --git a/lib/screens/history.dart b/lib/screens/history.dart index 4bd84d4..1ee5ba8 100644 --- a/lib/screens/history.dart +++ b/lib/screens/history.dart @@ -34,6 +34,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { WidgetsBinding.instance.addPostFrameCallback((_) { _historyProvider.snackNode(context); }); + return Scaffold( floatingActionButton: Container( height: 80.0, @@ -78,16 +79,17 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { disabledBorder: InputBorder.none, ), style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)), - if (_historyProvider.pubkey != '') historyQuery(context), + if (_historyProvider.pubkey != '') + historyQuery(context, _historyProvider), ])); } - historyQuery(context) { - print("I'M HERE 1"); + Widget historyQuery(context, _historyProvider) { _pubkeyFocus.unfocus(); - HistoryProvider _historyProvider = Provider.of(context); + // HistoryProvider _historyProvider = Provider.of(context); CesiumPlusProvider _cesiumPlusProvider = Provider.of(context); + print("I'M HERE 1"); return Expanded( child: Column( mainAxisAlignment: MainAxisAlignment.start, @@ -104,8 +106,10 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { ), builder: (QueryResult result, {fetchMore, refetch}) { print("I'M HERE 2 !"); + print(result.source.isEager); if (result.isLoading && result.data == null) { + print("I'M HERE 3 !"); return const Center( child: CircularProgressIndicator(), ); diff --git a/lib/screens/myWallets/generateWallets.dart b/lib/screens/myWallets/generateWallets.dart index e48ce21..abde130 100644 --- a/lib/screens/myWallets/generateWallets.dart +++ b/lib/screens/myWallets/generateWallets.dart @@ -59,7 +59,8 @@ class GenerateWalletsScreen extends StatelessWidget { style: TextStyle( fontSize: 14.0, color: Colors.black, - fontWeight: FontWeight.bold)), + fontWeight: FontWeight.bold, + fontFamily: 'Monospace')), SizedBox(height: 8), toolTips(_toolTipSentence, 'Phrase de restauration:', "Notez et gardez cette phrase précieusement sur un papier, elle vous servira à restaurer votre portefeuille sur un autre appareil"), diff --git a/lib/screens/myWallets/walletOptions.dart b/lib/screens/myWallets/walletOptions.dart index 513d431..5816744 100644 --- a/lib/screens/myWallets/walletOptions.dart +++ b/lib/screens/myWallets/walletOptions.dart @@ -7,6 +7,7 @@ import 'package:gecko/screens/myWallets/changePin.dart'; import 'dart:async'; import 'package:pin_code_fields/pin_code_fields.dart'; import 'package:provider/provider.dart'; +import 'package:flutter/services.dart'; // ignore: must_be_immutable class WalletOptions extends StatelessWidget with ChangeNotifier { @@ -15,7 +16,7 @@ class WalletOptions extends StatelessWidget with ChangeNotifier { String walletName; StreamController errorController; - TextEditingController _enterPin = new TextEditingController(); + TextEditingController _enterPin = TextEditingController(); final formKey = GlobalKey(); bool hasError = false; var pinColor = Color(0xffF9F9F1); @@ -32,6 +33,7 @@ class WalletOptions extends StatelessWidget with ChangeNotifier { Provider.of(context); errorController = StreamController(); // _walletOptions.isWalletUnlock = false; + return WillPopScope( onWillPop: () { _walletOptions.isWalletUnlock = false; @@ -50,33 +52,73 @@ class WalletOptions extends StatelessWidget with ChangeNotifier { height: 22, child: Text(walletName), )), - body: Center( - child: SafeArea( - child: Column(children: [ - Visibility( - visible: _walletOptions.isWalletUnlock, - child: Expanded( - child: Column(children: [ - SizedBox(height: 15), - Text( - 'Clé publique:', - style: TextStyle( - fontSize: 15.0, - color: Colors.grey[600], - fontWeight: FontWeight.w400), - ), - SizedBox(height: 15), - Text( - _walletOptions.pubkey.text, - style: TextStyle( - fontSize: 14.0, - color: Colors.black, - fontWeight: FontWeight.bold), - ), - Expanded( - child: Align( - alignment: Alignment.bottomCenter, - child: SizedBox( + body: Builder( + builder: (ctx) => SafeArea( + child: Column(children: [ + Visibility( + visible: _walletOptions.isWalletUnlock, + child: Expanded( + child: Column(children: [ + SizedBox(height: 15), + Text( + 'Clé publique:', + style: TextStyle( + fontSize: 15.0, + color: Colors.grey[600], + fontWeight: FontWeight.w400), + ), + SizedBox(height: 15), + GestureDetector( + onTap: () { + Clipboard.setData(ClipboardData( + text: _walletOptions.pubkey.text)); + _walletOptions.snackCopyKey(ctx); + }, + child: Text( + _walletOptions.pubkey.text, + style: TextStyle( + fontSize: 14.0, + color: Colors.black, + fontWeight: FontWeight.bold, + fontFamily: 'Monospace'), + )), + Expanded( + child: Align( + alignment: Alignment.bottomCenter, + child: SizedBox( + height: 50, + width: 300, + child: ElevatedButton( + style: ElevatedButton.styleFrom( + elevation: 5, + primary: Color( + 0xffFFD68E), //Color(0xffFFD68E), // background + onPrimary: + Colors.black, // foreground + ), + onPressed: () => _walletOptions + .renameWalletAlerte( + context, walletName) + .then((_result) { + if (_result == true) { + WidgetsBinding.instance + .addPostFrameCallback( + (_) { + _myWalletProvider + .listWallets = + _myWalletProvider + .getAllWalletsNames(); + _myWalletProvider + .rebuildWidget(); + }); + } + }), + child: Text( + 'Renommer ce portefeuille', + style: TextStyle( + fontSize: 20)))))), + SizedBox(height: 30), + SizedBox( height: 50, width: 300, child: ElevatedButton( @@ -86,167 +128,146 @@ class WalletOptions extends StatelessWidget with ChangeNotifier { 0xffFFD68E), //Color(0xffFFD68E), // background onPrimary: Colors.black, // foreground ), - onPressed: () => _walletOptions - .renameWalletAlerte( - context, walletName) - .then((_result) { - if (_result == true) { - WidgetsBinding.instance - .addPostFrameCallback((_) { - _myWalletProvider.listWallets = - _myWalletProvider - .getAllWalletsNames(); - _myWalletProvider.rebuildWidget(); - }); - } + onPressed: () { + // changePin(widget.walletName, this.walletPin); + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return ChangePinScreen( + walletName: walletName, + oldPin: this.walletPin); }), - child: Text('Renommer ce portefeuille', - style: TextStyle(fontSize: 20)))))), - SizedBox(height: 30), - SizedBox( - height: 50, - width: 300, - child: ElevatedButton( - style: ElevatedButton.styleFrom( - elevation: 5, - primary: Color( - 0xffFFD68E), //Color(0xffFFD68E), // background - onPrimary: Colors.black, // foreground + ); + }, + child: Text('Changer mon code secret', + style: TextStyle(fontSize: 20)))), + SizedBox(height: 30), + SizedBox( + height: 50, + width: 300, + child: ElevatedButton( + style: ElevatedButton.styleFrom( + elevation: 6, + primary: Colors + .redAccent, //Color(0xffFFD68E), // background + onPrimary: Colors.black, // foreground + ), + onPressed: () async { + await _walletOptions.deleteWallet( + context, walletName); + WidgetsBinding.instance + .addPostFrameCallback((_) { + _myWalletProvider.listWallets = + _myWalletProvider + .getAllWalletsNames(); + _myWalletProvider.rebuildWidget(); + }); + }, + child: Text('Supprimer ce portefeuille', + style: TextStyle(fontSize: 20)))), + SizedBox(height: 50), + Text( + 'Portefeuille déverrouillé', + style: TextStyle( + color: Colors.green, + fontWeight: FontWeight.w700, + fontSize: 15), ), - onPressed: () { - // changePin(widget.walletName, this.walletPin); - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return ChangePinScreen( - walletName: walletName, - oldPin: this.walletPin); - }), - ); - }, - child: Text('Changer mon code secret', - style: TextStyle(fontSize: 20)))), - SizedBox(height: 30), - SizedBox( - height: 50, - width: 300, - child: ElevatedButton( - style: ElevatedButton.styleFrom( - elevation: 6, - primary: Colors - .redAccent, //Color(0xffFFD68E), // background - onPrimary: Colors.black, // foreground + SizedBox(height: 10) + ]))), + Visibility( + visible: !_walletOptions.isWalletUnlock, + child: Expanded( + child: Column(children: [ + SizedBox(height: 80), + Text( + 'Veuillez tapper votre code secret pour dévérouiller votre portefeuille.', + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 15.0, + color: Colors.black, + fontWeight: FontWeight.w400), ), - onPressed: () async { - await _walletOptions.deleteWallet( - context, walletName); - WidgetsBinding.instance.addPostFrameCallback((_) { - _myWalletProvider.listWallets = - _myWalletProvider.getAllWalletsNames(); - _myWalletProvider.rebuildWidget(); - }); - }, - child: Text('Supprimer ce portefeuille', - style: TextStyle(fontSize: 20)))), - SizedBox(height: 50), - Text( - 'Portefeuille déverrouillé', - style: TextStyle( - color: Colors.green, - fontWeight: FontWeight.w700, - fontSize: 15), - ), - SizedBox(height: 10) - ]))), - Visibility( - visible: !_walletOptions.isWalletUnlock, - child: Expanded( - child: Column(children: [ - SizedBox(height: 80), - Text( - 'Veuillez tapper votre code secret pour dévérouiller votre portefeuille.', - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 15.0, - color: Colors.black, - fontWeight: FontWeight.w400), - ), - SizedBox(height: 50), - Form( - key: formKey, - child: Padding( - padding: const EdgeInsets.symmetric( - vertical: 8.0, horizontal: 30), - child: PinCodeTextField( - autoFocus: true, - appContext: context, - pastedTextStyle: TextStyle( - color: Colors.green.shade600, - fontWeight: FontWeight.bold, - ), - length: 6, - obscureText: false, - obscuringCharacter: '*', - animationType: AnimationType.fade, - validator: (v) { - if (v.length < 6) { - return "Votre code PIN fait 6 caractères"; - } else { - return null; - } - }, - pinTheme: PinTheme( - shape: PinCodeFieldShape.box, - borderRadius: BorderRadius.circular(5), - fieldHeight: 60, - fieldWidth: 50, - activeFillColor: - hasError ? Colors.orange : Colors.white, - ), - cursorColor: Colors.black, - animationDuration: Duration(milliseconds: 300), - textStyle: TextStyle(fontSize: 20, height: 1.6), - backgroundColor: pinColor, - enableActiveFill: false, - errorAnimationController: errorController, - controller: _enterPin, - keyboardType: TextInputType.text, - boxShadows: [ - BoxShadow( - offset: Offset(0, 1), - color: Colors.black12, - blurRadius: 10, - ) - ], - onCompleted: (_pin) async { - print("Completed"); - final resultWallet = - await _walletOptions.readLocalWallet( - this.walletName, _pin.toUpperCase()); - if (resultWallet == 'bad') { - errorController.add(ErrorAnimationType - .shake); // Triggering error shake animation - hasError = true; - pinColor = Colors.red[200]; - notifyListeners(); - } else { - pinColor = Colors.green[200]; - // setState(() {}); - // await Future.delayed(Duration(milliseconds: 50)); - this.walletPin = _pin.toUpperCase(); - // isWalletUnlock = true; - notifyListeners(); - } - }, - onChanged: (value) { - if (pinColor != Color(0xffF9F9F1)) { - pinColor = Color(0xffF9F9F1); - } - print(value); - }, - )), - ) - ]))), - ]))))); + SizedBox(height: 50), + Form( + key: formKey, + child: Padding( + padding: const EdgeInsets.symmetric( + vertical: 8.0, horizontal: 30), + child: PinCodeTextField( + autoFocus: true, + appContext: context, + pastedTextStyle: TextStyle( + color: Colors.green.shade600, + fontWeight: FontWeight.bold, + ), + length: 6, + obscureText: false, + obscuringCharacter: '*', + animationType: AnimationType.fade, + validator: (v) { + if (v.length < 6) { + return "Votre code PIN fait 6 caractères"; + } else { + return null; + } + }, + pinTheme: PinTheme( + shape: PinCodeFieldShape.box, + borderRadius: BorderRadius.circular(5), + fieldHeight: 60, + fieldWidth: 50, + activeFillColor: hasError + ? Colors.orange + : Colors.white, + ), + cursorColor: Colors.black, + animationDuration: + Duration(milliseconds: 300), + textStyle: + TextStyle(fontSize: 20, height: 1.6), + backgroundColor: pinColor, + enableActiveFill: false, + errorAnimationController: errorController, + controller: _enterPin, + keyboardType: TextInputType.text, + boxShadows: [ + BoxShadow( + offset: Offset(0, 1), + color: Colors.black12, + blurRadius: 10, + ) + ], + onCompleted: (_pin) async { + print("Completed"); + final resultWallet = + await _walletOptions.readLocalWallet( + this.walletName, + _pin.toUpperCase()); + if (resultWallet == 'bad') { + errorController.add(ErrorAnimationType + .shake); // Triggering error shake animation + hasError = true; + pinColor = Colors.red[200]; + notifyListeners(); + } else { + pinColor = Colors.green[200]; + // setState(() {}); + // await Future.delayed(Duration(milliseconds: 50)); + this.walletPin = _pin.toUpperCase(); + // isWalletUnlock = true; + notifyListeners(); + } + }, + onChanged: (value) { + if (pinColor != Color(0xffF9F9F1)) { + pinColor = Color(0xffF9F9F1); + } + print(value); + }, + )), + ) + ]))), + ]))))); } } diff --git a/lib/screens/myWallets/walletsHome.dart b/lib/screens/myWallets/walletsHome.dart index aee638e..24cbbb4 100644 --- a/lib/screens/myWallets/walletsHome.dart +++ b/lib/screens/myWallets/walletsHome.dart @@ -13,7 +13,6 @@ class WalletsHome extends StatelessWidget { Provider.of(context); WalletOptionsProvider _walletOptions = Provider.of(context); - print('BUILD: WalletsHome'); _walletOptions.isWalletUnlock = false; myWalletProvider.listWallets = myWalletProvider.getAllWalletsNames(); final bool isWalletsExists = myWalletProvider.checkIfWalletExist(); @@ -97,8 +96,6 @@ class WalletsHome extends StatelessWidget { List _listWallets = []; myWalletProvider.listWallets.forEach((_name, _pubkey) { _listWallets.add(_name); - // _balance[_name] = _historyProvider.getBalance(_pubkey).toString(); - print(_name + _pubkey); }); return Column(children: [ diff --git a/pubspec.lock b/pubspec.lock index a5cb3cb..a34da15 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -232,14 +232,14 @@ packages: name: graphql url: "https://pub.dartlang.org" source: hosted - version: "4.0.0-beta.6" + version: "4.0.0" graphql_flutter: dependency: "direct main" description: name: graphql_flutter url: "https://pub.dartlang.org" source: hosted - version: "4.0.0-beta.6" + version: "4.0.0" hive: dependency: transitive description: @@ -595,6 +595,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.2.0" + system_info: + dependency: transitive + description: + name: system_info + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.3" term_glyph: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 6a23011..8f94cee 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ description: A new Flutter project. # 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.1+2 +version: 0.0.1+3 environment: sdk: ">=2.7.0 <3.0.0"