diff --git a/README.md b/README.md index 8eb43a8..d674e01 100644 --- a/README.md +++ b/README.md @@ -65,10 +65,28 @@ In a dart file (e.g. `lib/main.dart`), type the `F5` key to build the code. The #### Linux -Build debug for linux: +Install dependancies: + +`sudo apt-get install clang cmake ninja-build pkg-config libgtk-3-dev` + +Then build debug for linux: `flutter run -d linux` +If you get this error: + +``` +flutter /usr/share/cmake-3.16/Modules/FindPkgConfig.cmake:643 (_pkg_check_modules_internal) +``` + +Please try: + +`sudo apt install liblzma-dev` + +then + +`flutter clean && flutter run -d linux` + ## Roadmap - v0.1.0 (expected date: 21-08-16) diff --git a/lib/main.dart b/lib/main.dart index 14a98a5..5200843 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -38,7 +38,6 @@ import 'package:gecko/screens/search.dart'; import 'package:gecko/screens/search_result.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:hive_flutter/hive_flutter.dart'; -import 'package:path_provider/path_provider.dart'; import 'package:provider/provider.dart'; import 'package:flutter/foundation.dart'; import 'package:responsive_framework/responsive_framework.dart'; @@ -51,12 +50,11 @@ Future main() async { WidgetsFlutterBinding.ensureInitialized(); HomeProvider _homeProvider = HomeProvider(); - appPath = await getApplicationDocumentsDirectory(); appVersion = await _homeProvider.getAppVersion(); prefs = await SharedPreferences.getInstance(); // Configure Hive and open boxes - await Hive.initFlutter(appPath.path); + await Hive.initFlutter(); Hive.registerAdapter(WalletDataAdapter()); Hive.registerAdapter(ChestDataAdapter()); Hive.registerAdapter(G1WalletsListAdapter()); @@ -185,7 +183,7 @@ class Gecko extends StatelessWidget { home: const HomeScreen(), initialRoute: "/", routes: { - '/mywallets': (context) => WalletsHome(), + '/mywallets': (context) => const WalletsHome(), '/search': (context) => const SearchScreen(), '/searchResult': (context) => const SearchResultScreen(), }, diff --git a/lib/models/generate_wallets.dart b/lib/models/generate_wallets.dart index cf89914..58271b8 100644 --- a/lib/models/generate_wallets.dart +++ b/lib/models/generate_wallets.dart @@ -37,7 +37,6 @@ class GenerateWalletsProvider with ChangeNotifier { bool isCesiumIDVisible = false; bool isCesiumPWDVisible = false; bool canImport = false; - bool isPinChanged = false; // Import Chest TextEditingController cellController0 = TextEditingController(); @@ -152,17 +151,6 @@ class GenerateWalletsProvider with ChangeNotifier { notifyListeners(); } - Future genMnemonic() async { - try { - generatedMnemonic = generateMnemonic(lang: 'french'); - actualWallet = await generateWallet(generatedMnemonic, isImport: false); - walletIsGenerated = true; - } catch (e) { - log.e(e); - } - return generatedMnemonic; - } - Future generateWallet(String generatedMnemonic, {@required bool isImport}) async { try { @@ -182,18 +170,13 @@ class GenerateWalletsProvider with ChangeNotifier { return actualWallet; } - Future changePinCode({bool reload}) async { - actualWallet = Dewif().changePassword( - dewif: actualWallet.dewif, - oldPassword: actualWallet.password, - ); - - pin.text = actualWallet.password; - isPinChanged = true; + String changePinCode({bool reload}) { + + pin.text = randomSecretCode(5); if (reload) { notifyListeners(); } - return actualWallet; + return pin.text; } Future printWallet(String _title) async { @@ -243,7 +226,6 @@ class GenerateWalletsProvider with ChangeNotifier { cesiumPubkey.text = _walletPubkey; pin.text = actualWallet.password; - isPinChanged = true; log.d(_walletPubkey); } @@ -260,7 +242,6 @@ class GenerateWalletsProvider with ChangeNotifier { cesiumPWD.text = ''; cesiumPubkey.text = ''; canImport = false; - isPinChanged = false; pin.text = ''; isCesiumIDVisible = false; isCesiumPWDVisible = false; @@ -306,18 +287,18 @@ class GenerateWalletsProvider with ChangeNotifier { void resetCesiumImportView() { cesiumID.text = cesiumPWD.text = cesiumPubkey.text = pin.text = ''; - canImport = isPinChanged = isCesiumIDVisible = isCesiumPWDVisible = false; + canImport = isCesiumIDVisible = isCesiumPWDVisible = false; actualWallet = null; notifyListeners(); } - Future> generateWordList() async { - final String _sentance = await genMnemonic(); + List generateWordList() { + generatedMnemonic = generateMnemonic(lang: 'french'); List _wordsList = []; String word; int _nbr = 1; - for (word in _sentance.split(' ')) { + for (word in generatedMnemonic.split(' ')) { _wordsList.add("$_nbr:$word"); _nbr++; } diff --git a/lib/models/home.dart b/lib/models/home.dart index 6b19b19..c011042 100644 --- a/lib/models/home.dart +++ b/lib/models/home.dart @@ -10,6 +10,7 @@ import 'package:gecko/globals.dart'; import 'package:gecko/screens/old_history_pay.dart'; import 'package:gecko/screens/myWallets/wallets_home.dart'; import 'package:package_info/package_info.dart'; +import 'package:flutter/foundation.dart' show kIsWeb; class HomeProvider with ChangeNotifier { int _currentIndex = 0; @@ -20,7 +21,7 @@ class HomeProvider with ChangeNotifier { Widget appBarExplorer = Text('Explorateur', style: TextStyle(color: Colors.grey[850])); - List currentTab = [OldHistoryScreen(), WalletsHome()]; + List currentTab = [OldHistoryScreen(), const WalletsHome()]; bool isFirstBuild = true; // AudioCache player = AudioCache(prefix: 'sounds/'); @@ -34,7 +35,7 @@ class HomeProvider with ChangeNotifier { Future getAppVersion() async { String version; String buildNumber; - if (Platform.isLinux) { + if (kIsWeb || Platform.isLinux) { version = "undefined"; buildNumber = "undefined"; } else { diff --git a/lib/models/wallet_options.dart b/lib/models/wallet_options.dart index fdd6f4f..3f6184b 100644 --- a/lib/models/wallet_options.dart +++ b/lib/models/wallet_options.dart @@ -28,8 +28,8 @@ class WalletOptionsProvider with ChangeNotifier { Future get badWallet => null; - Future _getPubkeyFromDewif( - String _dewif, _pin, int _pinLenght, int derivation) async { + String _getPubkeyFromDewif( + String _dewif, _pin, int _pinLenght, int derivation) { String _pubkey; RegExp regExp = RegExp( r'^[A-Z0-9]+$', @@ -45,6 +45,7 @@ class WalletOptionsProvider with ChangeNotifier { try { final _wallet = HdWallet.fromDewif(_dewif, _pin); _pubkey = _wallet.getPubkey(derivation); + log.d(_pubkey); pubkey.text = _pubkey; notifyListeners(); @@ -70,14 +71,14 @@ class WalletOptionsProvider with ChangeNotifier { } } - Future readLocalWallet( - context, WalletData _wallet, String _pin, int _pinLenght) async { + String readLocalWallet( + context, WalletData _wallet, String _pin, int _pinLenght) { isWalletUnlock = false; try { String _localDewif = chestBox.get(_wallet.chest).dewif; String _localPubkey; - if ((_localPubkey = await _getPubkeyFromDewif( + if ((_localPubkey = _getPubkeyFromDewif( _localDewif, _pin, _pinLenght, _wallet.derivation)) != 'false') { pubkey.text = _localPubkey; @@ -94,21 +95,6 @@ class WalletOptionsProvider with ChangeNotifier { } } - Future checkPinOK(String _createdDewif, String _pin, int _pinLenght) async { - isWalletUnlock = false; - try { - if (await _getPubkeyFromDewif(_createdDewif, _pin, _pinLenght, 3) != - 'false') { - return true; - } else { - throw false; - } - } catch (e) { - log.e('ERROR READING FILE: $e'); - return false; - } - } - int getPinLenght(_walletNbr) { // TODO: Get real Dewif lenght // String _localDewif; diff --git a/lib/screens/myWallets/generate_wallets.dart b/lib/screens/myWallets/generate_wallets.dart index 370a8c6..c25fe33 100644 --- a/lib/screens/myWallets/generate_wallets.dart +++ b/lib/screens/myWallets/generate_wallets.dart @@ -25,7 +25,6 @@ class GenerateFastChestScreen extends StatelessWidget { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); GenerateWalletsProvider _generateWalletProvider = Provider.of(context); - _generateWalletProvider.genMnemonic(); return Scaffold( appBar: AppBar( @@ -40,7 +39,7 @@ class GenerateFastChestScreen extends StatelessWidget { child: FittedBox( child: FloatingActionButton( heroTag: "buttonGenerateWallet", - onPressed: () => _generateWalletProvider.genMnemonic(), + onPressed: () => _generateWalletProvider.generateWordList(), child: SizedBox( height: 40.0, width: 40.0, @@ -89,7 +88,7 @@ class GenerateFastChestScreen extends StatelessWidget { color: orangeC, onPressed: () { _generateWalletProvider.changePinCode( - reload: false); + reload: true); }, ), ], diff --git a/lib/screens/myWallets/import_cesium_wallet.dart b/lib/screens/myWallets/import_cesium_wallet.dart index 84e2fea..af1d7ad 100644 --- a/lib/screens/myWallets/import_cesium_wallet.dart +++ b/lib/screens/myWallets/import_cesium_wallet.dart @@ -164,8 +164,7 @@ class ImportWalletScreen extends StatelessWidget { primary: yellowC, // background onPrimary: Colors.black, // foreground ), - onPressed: _generateWalletProvider.canImport && - _generateWalletProvider.isPinChanged + onPressed: _generateWalletProvider.canImport ? () { _generateWalletProvider .importCesiumWallet() diff --git a/lib/screens/myWallets/restore_chest.dart b/lib/screens/myWallets/restore_chest.dart index 9f8b1eb..a63a653 100644 --- a/lib/screens/myWallets/restore_chest.dart +++ b/lib/screens/myWallets/restore_chest.dart @@ -92,7 +92,7 @@ class RestoreChest extends StatelessWidget { await Navigator.push( context, FaderTransition( - page: OnboardingStepThirteen(), isFast: true), + page: const OnboardingStepThirteen(), isFast: true), ); } else { await badMnemonicPopup(context); diff --git a/lib/screens/myWallets/unlocking_wallet.dart b/lib/screens/myWallets/unlocking_wallet.dart index 65ce3d6..7a5c593 100644 --- a/lib/screens/myWallets/unlocking_wallet.dart +++ b/lib/screens/myWallets/unlocking_wallet.dart @@ -180,7 +180,7 @@ class UnlockingWallet extends StatelessWidget { onCompleted: (_pin) async { log.d("Completed"); _myWalletProvider.pinCode = _pin; - final String resultWallet = await _walletOptions.readLocalWallet( + final String resultWallet = _walletOptions.readLocalWallet( context, wallet, _pin.toUpperCase(), _pinLenght); // _myWalletProvider.pinCode = _pin.toUpperCase(); _myWalletProvider.pinLenght = _pinLenght; diff --git a/lib/screens/myWallets/wallets_home.dart b/lib/screens/myWallets/wallets_home.dart index 4d18027..6826550 100644 --- a/lib/screens/myWallets/wallets_home.dart +++ b/lib/screens/myWallets/wallets_home.dart @@ -14,9 +14,7 @@ import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:provider/provider.dart'; class WalletsHome extends StatelessWidget { - final _derivationKey = GlobalKey(); - - WalletsHome({Key key}) : super(key: key); + const WalletsHome({Key key}) : super(key: key); @override Widget build(BuildContext context) { @@ -167,8 +165,8 @@ class WalletsHome extends StatelessWidget { Padding( padding: const EdgeInsets.all(16), child: GestureDetector( - onTap: () async { - await _walletOptions.readLocalWallet( + onTap: () { + _walletOptions.readLocalWallet( context, _repository, _myWalletProvider.pinCode, @@ -351,56 +349,6 @@ class WalletsHome extends StatelessWidget { ), ]))); } - - Widget addNewDerivationPopup(context) { - final TextEditingController _newDerivationName = TextEditingController(); - MyWalletsProvider _myWalletProvider = - Provider.of(context); - - return AlertDialog( - content: Stack( - clipBehavior: Clip.hardEdge, - children: [ - Form( - key: _derivationKey, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - const Text('Nom du portefeuille:'), - Padding( - padding: const EdgeInsets.all(8.0), - child: TextFormField( - key: const Key('DerivationNameKey'), - controller: _newDerivationName, - textAlign: TextAlign.center, - autofocus: true, - ), - ), - const SizedBox(height: 20), - Padding( - padding: const EdgeInsets.all(8.0), - child: ElevatedButton( - key: const Key('validDerivation'), - style: ElevatedButton.styleFrom( - elevation: 1, - primary: yellowC, // background - onPrimary: Colors.black, // foreground - ), - onPressed: () async { - await _myWalletProvider - .generateNewDerivation( - context, _newDerivationName.text) - .then((_) => _newDerivationName.text == ''); - }, - child: const Text("Créer")), - ) - ], - ), - ), - ], - ), - ); - } } // extension Range on num { diff --git a/lib/screens/onBoarding/10.dart b/lib/screens/onBoarding/10.dart index 8a92869..e90f72d 100644 --- a/lib/screens/onBoarding/10.dart +++ b/lib/screens/onBoarding/10.dart @@ -50,7 +50,8 @@ class OnboardingStepTwelve extends StatelessWidget { Navigator.push( context, FaderTransition( - page: OnboardingStepThirteen(), isFast: true), + page: const OnboardingStepThirteen(), + isFast: true), ); }, child: const Text("Générer le code secret", diff --git a/lib/screens/onBoarding/11.dart b/lib/screens/onBoarding/11.dart index 0c8a7a8..ecc5f4b 100644 --- a/lib/screens/onBoarding/11.dart +++ b/lib/screens/onBoarding/11.dart @@ -1,5 +1,4 @@ // ignore_for_file: file_names -import 'package:durt/durt.dart'; import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; @@ -10,10 +9,9 @@ import 'package:provider/provider.dart'; // ignore: must_be_immutable class OnboardingStepThirteen extends StatelessWidget { - NewWallet generatedWallet; final int progress = 10; - OnboardingStepThirteen({Key key}) : super(key: key); + const OnboardingStepThirteen({Key key}) : super(key: key); @override Widget build(BuildContext context) { @@ -23,19 +21,13 @@ class OnboardingStepThirteen extends StatelessWidget { // MyWalletsProvider myWalletProvider = // Provider.of(context); CommonElements common = CommonElements(); - _generateWalletProvider.pin.text = ''; + _generateWalletProvider.pin.text = + _generateWalletProvider.changePinCode(reload: false); return Scaffold( extendBodyBehindAppBar: true, body: SafeArea( child: Column(children: [ - FutureBuilder( - future: _generateWalletProvider.changePinCode(reload: false), - // initialData: '...', - builder: (context, snapshot) { - generatedWallet = snapshot.data; - return const Visibility(visible: false, child: Text('')); - }), common.onboardingProgressBar( context, 'Ma phrase de restauration', progress), common.bubbleSpeakRich( @@ -71,9 +63,8 @@ class OnboardingStepThirteen extends StatelessWidget { IconButton( icon: const Icon(Icons.replay), color: orangeC, - onPressed: () async { - generatedWallet = await _generateWalletProvider - .changePinCode(reload: false); + onPressed: () { + _generateWalletProvider.changePinCode(reload: true); }, ), ], @@ -91,9 +82,8 @@ class OnboardingStepThirteen extends StatelessWidget { primary: const Color(0xffFFD58D), onPrimary: Colors.black, // foreground ), - onPressed: () async { - generatedWallet = await _generateWalletProvider - .changePinCode(reload: false); + onPressed: () { + _generateWalletProvider.changePinCode(reload: true); }, child: const Text("Choisir un autre code secret", style: TextStyle(fontSize: 20))), @@ -115,9 +105,7 @@ class OnboardingStepThirteen extends StatelessWidget { Navigator.push( context, FaderTransition( - page: OnboardingStepFourteen( - generatedWallet: generatedWallet), - isFast: true), + page: OnboardingStepFourteen(), isFast: true), ); }, child: const Text("J'ai noté mon code secret", diff --git a/lib/screens/onBoarding/12.dart b/lib/screens/onBoarding/12.dart index 4169dd4..3e6b7f6 100644 --- a/lib/screens/onBoarding/12.dart +++ b/lib/screens/onBoarding/12.dart @@ -17,10 +17,8 @@ import 'package:provider/provider.dart'; class OnboardingStepFourteen extends StatelessWidget { OnboardingStepFourteen({ Key validationKey, - @required this.generatedWallet, }) : super(key: validationKey); - NewWallet generatedWallet; final int progress = 11; final formKey = GlobalKey(); var pinColor = const Color(0xFFA4B600); @@ -29,12 +27,12 @@ class OnboardingStepFourteen extends StatelessWidget { @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); - // GenerateWalletsProvider _generateWalletProvider = - // Provider.of(context); + GenerateWalletsProvider _generateWalletProvider = + Provider.of(context); WalletOptionsProvider _walletOptions = Provider.of(context); CommonElements common = CommonElements(); - final int _pinLenght = _walletOptions.getPinLenght(generatedWallet.dewif); + final int _pinLenght = _generateWalletProvider.pin.text.length; return Scaffold( extendBodyBehindAppBar: true, @@ -113,13 +111,16 @@ class OnboardingStepFourteen extends StatelessWidget { blurRadius: 10, ) ], - onCompleted: (_pin) async { + onCompleted: (_pin) { _myWalletProvider.pinCode = _pin; _myWalletProvider.pinLenght = _pinLenght; - final bool resultWallet = await _walletOptions.checkPinOK( - generatedWallet.dewif, _pin.toUpperCase(), _pinLenght); - if (resultWallet) { + log.d(_pin + ' || ' + _generateWalletProvider.pin.text); + if (_pin.toUpperCase() == _generateWalletProvider.pin.text) { pinColor = Colors.green[500]; + NewWallet generatedWallet = Dewif().generateDewif( + _generateWalletProvider.generatedMnemonic, + _generateWalletProvider.pin.text, + lang: 'french'); _generateWalletProvider.storeHDWChest( generatedWallet, 'Mon portefeuille courant', context); _myWalletProvider.readAllWallets(_currentChest); diff --git a/lib/screens/onBoarding/7.dart b/lib/screens/onBoarding/7.dart index 5fc2b9c..b49e759 100644 --- a/lib/screens/onBoarding/7.dart +++ b/lib/screens/onBoarding/7.dart @@ -113,64 +113,47 @@ Widget sentanceArray(BuildContext context) { GenerateWalletsProvider _generateWalletProvider = Provider.of(context); - return FutureBuilder( - future: _generateWalletProvider.generateWordList(), - initialData: const [ - '1:...', - '2:...', - '3:...', - '4:...', - '5:...', - '6:...', - '7:...', - '8:...', - '9:...', - '10:...', - '11:...', - '12:...', - ], - builder: (context, formatedArray) { - // print(formatedArray.data); - return Container( - padding: const EdgeInsets.symmetric(horizontal: 12), - child: Container( - decoration: BoxDecoration( - border: Border.all(color: Colors.black), - color: Colors.grey[300], - borderRadius: const BorderRadius.all( - Radius.circular(10), - )), - // color: Colors.grey[300], - padding: const EdgeInsets.all(20), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - mainAxisSize: MainAxisSize.max, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Row(children: [ - arrayCell(formatedArray.data[0]), - arrayCell(formatedArray.data[1]), - arrayCell(formatedArray.data[2]), - arrayCell(formatedArray.data[3]), - ]), - const SizedBox(height: 15), - Row(children: [ - arrayCell(formatedArray.data[4]), - arrayCell(formatedArray.data[5]), - arrayCell(formatedArray.data[6]), - arrayCell(formatedArray.data[7]), - ]), - const SizedBox(height: 15), - Row(children: [ - arrayCell(formatedArray.data[8]), - arrayCell(formatedArray.data[9]), - arrayCell(formatedArray.data[10]), - arrayCell(formatedArray.data[11]), - ]), - ]), - ), - ); - }); + List formatedArray = _generateWalletProvider.generateWordList(); + + return Container( + padding: const EdgeInsets.symmetric(horizontal: 12), + child: Container( + decoration: BoxDecoration( + border: Border.all(color: Colors.black), + color: Colors.grey[300], + borderRadius: const BorderRadius.all( + Radius.circular(10), + )), + // color: Colors.grey[300], + padding: const EdgeInsets.all(20), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Row(children: [ + arrayCell(formatedArray[0]), + arrayCell(formatedArray[1]), + arrayCell(formatedArray[2]), + arrayCell(formatedArray[3]), + ]), + const SizedBox(height: 15), + Row(children: [ + arrayCell(formatedArray[4]), + arrayCell(formatedArray[5]), + arrayCell(formatedArray[6]), + arrayCell(formatedArray[7]), + ]), + const SizedBox(height: 15), + Row(children: [ + arrayCell(formatedArray[8]), + arrayCell(formatedArray[9]), + arrayCell(formatedArray[10]), + arrayCell(formatedArray[11]), + ]), + ]), + ), + ); } Widget arrayCell(dataWord) { diff --git a/pubspec.lock b/pubspec.lock index 175b79c..09adf5a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -294,7 +294,7 @@ packages: name: durt url: "https://pub.dartlang.org" source: hosted - version: "0.1.3+3" + version: "0.1.4" fake_async: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index a9d694e..06e8f4b 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.3+14 +version: 0.0.4+1 environment: sdk: ">=2.7.0 <3.0.0" @@ -56,7 +56,7 @@ dependencies: xml: ^5.3.0 pull_to_refresh: ^2.0.0 dio: ^4.0.4 - durt: ^0.1.3+3 + durt: ^0.1.4 flutter_icons: android: "ic_launcher" diff --git a/scripts/build-rust.sh b/scripts/build-rust.sh deleted file mode 100755 index bfacd8c..0000000 --- a/scripts/build-rust.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -set -e - -MY_PATH="`dirname \"$0\"`" -MY_PATH="`( cd \"$MY_PATH\" && pwd )`" - -cd $MY_PATH/.. - -cargo bd -cargo make android-dev -cargo br - -echo -e "\nRust dependencies have been successfully build !"