diff --git a/assets/walletOptions/QR_icon.png b/assets/walletOptions/QR_icon.png new file mode 100755 index 0000000..6b6a887 Binary files /dev/null and b/assets/walletOptions/QR_icon.png differ diff --git a/assets/walletOptions/android-checkmark.png b/assets/walletOptions/android-checkmark.png new file mode 100755 index 0000000..578859d Binary files /dev/null and b/assets/walletOptions/android-checkmark.png differ diff --git a/assets/walletOptions/camera.png b/assets/walletOptions/camera.png new file mode 100755 index 0000000..ce9ad0f Binary files /dev/null and b/assets/walletOptions/camera.png differ diff --git a/assets/walletOptions/clock.png b/assets/walletOptions/clock.png new file mode 100755 index 0000000..cf9a802 Binary files /dev/null and b/assets/walletOptions/clock.png differ diff --git a/assets/walletOptions/copy-white.png b/assets/walletOptions/copy-white.png new file mode 100755 index 0000000..819e852 Binary files /dev/null and b/assets/walletOptions/copy-white.png differ diff --git a/assets/walletOptions/edit.png b/assets/walletOptions/edit.png new file mode 100755 index 0000000..a45788d Binary files /dev/null and b/assets/walletOptions/edit.png differ diff --git a/assets/walletOptions/icon_oeuil.png b/assets/walletOptions/icon_oeuil.png new file mode 100755 index 0000000..f707647 Binary files /dev/null and b/assets/walletOptions/icon_oeuil.png differ diff --git a/assets/walletOptions/key.png b/assets/walletOptions/key.png new file mode 100755 index 0000000..45c0e85 Binary files /dev/null and b/assets/walletOptions/key.png differ diff --git a/assets/walletOptions/trash.png b/assets/walletOptions/trash.png new file mode 100755 index 0000000..6dc972b Binary files /dev/null and b/assets/walletOptions/trash.png differ diff --git a/lib/globals.dart b/lib/globals.dart index 045c95a..e500877 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -1,9 +1,12 @@ import 'dart:io'; import 'package:shared_preferences/shared_preferences.dart'; +// Files paths Directory appPath; Directory walletsDirectory; File defaultWalletFile; +File currentChestFile; + String defaultWallet; String appVersion; SharedPreferences prefs; diff --git a/lib/main.dart b/lib/main.dart index af7109e..3029d26 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -28,7 +28,7 @@ Future main() async { MyWalletsProvider _walletsProvider = MyWalletsProvider(); await _homeProvider.getAppPath(); await _homeProvider.createDefaultAvatar(); - await _walletsProvider.getDefaultWallet(); + await _walletsProvider.initWalletFolder(); appVersion = await _homeProvider.getAppVersion(); prefs = await SharedPreferences.getInstance(); final HiveStore _store = diff --git a/lib/models/cesiumPlus.dart b/lib/models/cesiumPlus.dart index bf59c6c..7cbe5e4 100644 --- a/lib/models/cesiumPlus.dart +++ b/lib/models/cesiumPlus.dart @@ -67,7 +67,7 @@ class CesiumPlusProvider with ChangeNotifier { String _name; List queryOptions = await _buildQuery(_pubkey); - final response = await http.post(queryOptions[0], + final response = await http.post((Uri.parse(queryOptions[0])), body: queryOptions[1], headers: queryOptions[2]); // print('RESULT CESIUM QUERY: ${response.body}'); //For debug final responseJson = json.decode(response.body); @@ -87,7 +87,7 @@ class CesiumPlusProvider with ChangeNotifier { Future getAvatar(String _pubkey) async { List queryOptions = await _buildQuery(_pubkey); - final response = await http.post(queryOptions[0], + final response = await http.post((Uri.parse(queryOptions[0])), body: queryOptions[1], headers: queryOptions[2]); // print('RESULT CESIUM QUERY: ${response.body}'); //For debug final responseJson = json.decode(response.body); diff --git a/lib/models/generateWallets.dart b/lib/models/generateWallets.dart index 88b85c2..dfcd9e9 100644 --- a/lib/models/generateWallets.dart +++ b/lib/models/generateWallets.dart @@ -39,14 +39,16 @@ class GenerateWalletsProvider with ChangeNotifier { bool canImport = false; bool isPinChanged = false; - Future storeHDWallet( + Future storeHDWChest( NewWallet _wallet, String _name, BuildContext context) async { // Directory walletDirectory; final Directory hdDirectory = Directory('${walletsDirectory.path}/0'); await hdDirectory.create(); - final configFile = File('${hdDirectory.path}/config.txt'); + final configFile = File('${hdDirectory.path}/list.conf'); + File _currentChestFile = File('${walletsDirectory.path}/currentChest.conf'); + final dewifFile = File('${hdDirectory.path}/wallet.dewif'); // List _lastConfig = []; @@ -61,8 +63,14 @@ class GenerateWalletsProvider with ChangeNotifier { accountsIndex: [_derivationNbr]); String _pubkey = _pubkeysTmp[0]; - await configFile.writeAsString('0:$_name:$_derivationNbr:$_pubkey'); + await configFile.writeAsString('0:0:$_name:$_derivationNbr:$_pubkey'); await dewifFile.writeAsString(_wallet.dewif); + bool isCurrentChestExist = _currentChestFile.existsSync(); + if (isCurrentChestExist) { + await _currentChestFile.delete(); + } + await _currentChestFile.create(); + await _currentChestFile.writeAsString('0'); return _name; } @@ -147,11 +155,9 @@ class GenerateWalletsProvider with ChangeNotifier { generatedMnemonic = await DubpRust.genMnemonic(language: Language.french); this.actualWallet = await generateWallet(this.generatedMnemonic); walletIsGenerated = true; - // notifyListeners(); } catch (e) { print(e); } - // await checkIfWalletExist(); return generatedMnemonic; } diff --git a/lib/models/history.dart b/lib/models/history.dart index d8da067..facb32b 100644 --- a/lib/models/history.dart +++ b/lib/models/history.dart @@ -101,7 +101,6 @@ class HistoryProvider with ChangeNotifier { // Lion simone: 78jhpprYkMNF6i5kQPXfkAVBpd2aqcpieNsXTSW4c21f List parseHistory(txs, _pubkey) { - // print(txs); var transBC = []; int i = 0; @@ -135,7 +134,7 @@ class HistoryProvider with ChangeNotifier { transBC[i].add(date); // print( // "DEBUG date et comment: ${date.toString()} -- ${transaction['comment'].toString()}"); - int amountBrut = int.parse(output.split(':')[0]); + final int amountBrut = int.parse(output.split(':')[0]); final base = int.parse(output.split(':')[1]); final int applyBase = base - currentBase; final num amount = diff --git a/lib/models/myWallets.dart b/lib/models/myWallets.dart index b0b61ba..350a227 100644 --- a/lib/models/myWallets.dart +++ b/lib/models/myWallets.dart @@ -8,15 +8,50 @@ import 'package:provider/provider.dart'; class MyWalletsProvider with ChangeNotifier { String listWallets; + Future initWalletFolder() async { + await getDefaultWallet(); + + final bool isWalletFolderExist = await walletsDirectory.exists(); + if (!isWalletFolderExist) { + await Directory(walletsDirectory.path).create(); + } + + File _currentChestFile = File('${walletsDirectory.path}/currentChest.conf'); + + await _currentChestFile.create(); + await _currentChestFile.writeAsString('0'); + + final bool isChestsExist = + await Directory('${walletsDirectory.path}/0').exists(); + if (!isChestsExist) { + await Directory('${walletsDirectory.path}/0').create(); + await Directory('${walletsDirectory.path}/1').create(); + await File('${walletsDirectory.path}/0/list.conf').create(); + await File('${walletsDirectory.path}/0/order.conf').create(); + await File('${walletsDirectory.path}/1/list.conf').create(); + await File('${walletsDirectory.path}/1/order.conf').create(); + } + } + + int getCurrentChest() { + File _currentChestFile = File('${walletsDirectory.path}/currentChest.conf'); + + bool isCurrentChestExist = _currentChestFile.existsSync(); + if (!isCurrentChestExist) { + _currentChestFile.createSync(); + _currentChestFile.writeAsString('0'); + } + return int.parse(_currentChestFile.readAsStringSync()); + } + bool checkIfWalletExist() { if (appPath == null) { return false; } - print(walletsDirectory.listSync()); + final String _walletList = getAllWalletsNames(0); - List contents = walletsDirectory.listSync(); - if (contents.length == 0) { + if (_walletList == '') { print('No wallets detected'); return false; } else { @@ -25,12 +60,7 @@ class MyWalletsProvider with ChangeNotifier { } } - String getAllWalletsNames() { - final bool _isWalletsExists = checkIfWalletExist(); - if (!_isWalletsExists) { - return ''; - } - + String getAllWalletsNames(int _chest) { if (listWallets != null && listWallets.isNotEmpty) { listWallets = ''; } @@ -39,17 +69,13 @@ class MyWalletsProvider with ChangeNotifier { } // int i = 0; - walletsDirectory - .listSync(recursive: false, followLinks: false) - .forEach((_wallet) { - File _walletConfig = File('${_wallet.path}/config.txt'); - _walletConfig.readAsLinesSync().forEach((element) { - if (listWallets != '') { - listWallets += '\n'; - } - listWallets += element; - // listWallets += "${element.split(':')[0]}:${element.split(':')[1]}:${element.split(':')[2]}" - }); + File _walletConfig = File('${walletsDirectory.path}/$_chest/list.conf'); + _walletConfig.readAsLinesSync().forEach((element) { + if (listWallets != '') { + listWallets += '\n'; + } + listWallets += element; + // listWallets += "${element.split(':')[0]}:${element.split(':')[1]}:${element.split(':')[2]}" }); print(listWallets); @@ -68,9 +94,9 @@ class MyWalletsProvider with ChangeNotifier { try { defaultWallet = await defaultWalletFile.readAsString(); } catch (e) { - defaultWallet = '0:3'; + defaultWallet = '0:0'; } - if (defaultWallet == '') defaultWallet = '0:3'; + if (defaultWallet == '') defaultWallet = '0:0'; } Future deleteAllWallet(context) async { @@ -82,6 +108,7 @@ class MyWalletsProvider with ChangeNotifier { if (_answer) { await walletsDirectory.delete(recursive: true); await walletsDirectory.create(); + await initWalletFolder(); notifyListeners(); Navigator.pop(context); } @@ -114,7 +141,7 @@ class MyWalletsProvider with ChangeNotifier { onPressed: () { WidgetsBinding.instance.addPostFrameCallback((_) { _myWalletProvider.listWallets = - _myWalletProvider.getAllWalletsNames(); + _myWalletProvider.getAllWalletsNames(getCurrentChest()); _myWalletProvider.rebuildWidget(); }); Navigator.pop(context, true); @@ -128,18 +155,24 @@ class MyWalletsProvider with ChangeNotifier { Future generateNewDerivation(context, String _name) async { int _newDerivationNbr; - final _walletConfig = File('${walletsDirectory.path}/0/config.txt'); + int _newWalletNbr; + final _walletConfig = File('${walletsDirectory.path}/0/list.conf'); if (await _walletConfig.readAsString() == '') { _newDerivationNbr = 3; + _newWalletNbr = 0; } else { String _lastWallet = await _walletConfig.readAsLines().then((value) => value.last); - int _lastDerivation = int.parse(_lastWallet.split(':')[2]); + int _lastDerivation = int.parse(_lastWallet.split(':')[3]); _newDerivationNbr = _lastDerivation + 3; + + int _lastWalletNbr = int.parse(_lastWallet.split(':')[1]); + _newWalletNbr = _lastWalletNbr + 1; } - await _walletConfig.writeAsString('\n0:$_name:$_newDerivationNbr', + await _walletConfig.writeAsString( + '\n0:$_newWalletNbr:$_name:$_newDerivationNbr', mode: FileMode.append); print(await _walletConfig.readAsString()); diff --git a/lib/models/queries.dart b/lib/models/queries.dart index 52754ab..fda9345 100644 --- a/lib/models/queries.dart +++ b/lib/models/queries.dart @@ -1,7 +1,7 @@ const String getHistory = r''' query ($pubkey: String!, $number: Int!, $cursor: String) { txsHistoryBc( - pubkeyOrScript: $pubkey + script: $pubkey pagination: { pageSize: $number, ord: DESC, cursor: $cursor } ) { both { diff --git a/lib/models/walletOptions.dart b/lib/models/walletOptions.dart index 034f9a5..2c238a7 100644 --- a/lib/models/walletOptions.dart +++ b/lib/models/walletOptions.dart @@ -1,9 +1,12 @@ import 'dart:io'; +import 'package:crypto/crypto.dart'; import 'package:dubp/dubp.dart'; +import 'package:fast_base58/fast_base58.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'dart:async'; import 'package:gecko/globals.dart'; +import 'package:truncate/truncate.dart'; class WalletOptionsProvider with ChangeNotifier { TextEditingController pubkey = TextEditingController(); @@ -65,8 +68,7 @@ class WalletOptionsProvider with ChangeNotifier { int _walletNbr, String _pin, int _pinLenght, int derivation) async { isWalletUnlock = false; try { - File _walletFile = - File('${walletsDirectory.path}/$_walletNbr/wallet.dewif'); + File _walletFile = File('${walletsDirectory.path}/0/wallet.dewif'); String _localDewif = await _walletFile.readAsString(); String _localPubkey; @@ -107,8 +109,7 @@ class WalletOptionsProvider with ChangeNotifier { int getPinLenght(_walletNbr) { String _localDewif; if (_walletNbr is int) { - File _walletFile = - File('${walletsDirectory.path}/$_walletNbr/wallet.dewif'); + File _walletFile = File('${walletsDirectory.path}/0/wallet.dewif'); _localDewif = _walletFile.readAsStringSync(); } else { _localDewif = _walletNbr; @@ -121,21 +122,21 @@ class WalletOptionsProvider with ChangeNotifier { } Future _renameWallet(_walletName, _newName, _walletNbr, _derivation) async { - final _walletConfig = - File('${walletsDirectory.path}/$_walletNbr/config.txt'); + final _walletConfig = File('${walletsDirectory.path}/0/list.conf'); String newConfig = await _walletConfig.readAsLines().then((List lines) { int nbrLines = lines.length; - int _index = lines.indexOf('$_walletNbr:$_walletName:$_derivation'); + print(lines); print(nbrLines); + int _index = lines.indexOf('0:$_walletNbr:$_walletName:$_derivation'); if (nbrLines != 1) { lines.removeWhere((element) => - element.contains('$_walletNbr:$_walletName:$_derivation')); - lines.insert(_index, '$_walletNbr:$_newName:$_derivation'); + element.contains('0:$_walletNbr:$_walletName:$_derivation')); + lines.insert(_index, '0:$_walletNbr:$_newName:$_derivation'); return lines.join('\n'); } else { - return '$_walletNbr:$_newName:$_derivation'; + return '0:$_walletNbr:$_newName:$_derivation'; } }); @@ -189,14 +190,13 @@ class WalletOptionsProvider with ChangeNotifier { final bool _answer = await _confirmDeletingWallet(context, _name); if (_answer) { - final _walletConfig = - File('${walletsDirectory.path}/$_walletNbr/config.txt'); + final _walletConfig = File('${walletsDirectory.path}/0/list.conf'); if (_derivation != -1) { String newConfig = await _walletConfig.readAsLines().then((List lines) { - lines.removeWhere( - (element) => element.contains('$_walletNbr:$_name:$_derivation')); + lines.removeWhere((element) => + element.contains('0:$_walletNbr:$_name:$_derivation')); return lines.join('\n'); }); @@ -289,6 +289,22 @@ class WalletOptionsProvider with ChangeNotifier { ScaffoldMessenger.of(context).showSnackBar(snackBar); } + String getShortPubkey(String pubkey) { + List pubkeyByte = Base58Decode(pubkey); + Digest pubkeyS256 = sha256.convert(sha256.convert(pubkeyByte).bytes); + String pubkeyCheksum = Base58Encode(pubkeyS256.bytes); + String pubkeyChecksumShort = truncate(pubkeyCheksum, 3, + omission: "", position: TruncatePosition.end); + + String pubkeyShort = truncate(pubkey, 5, + omission: String.fromCharCode(0x2026), + position: TruncatePosition.end) + + truncate(pubkey, 4, omission: "", position: TruncatePosition.start) + + ':$pubkeyChecksumShort'; + + return pubkeyShort; + } + void reloadBuild() { notifyListeners(); } diff --git a/lib/screens/history.dart b/lib/screens/history.dart index a8b4cb1..6f26752 100644 --- a/lib/screens/history.dart +++ b/lib/screens/history.dart @@ -254,7 +254,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { initialData: '...', builder: (context, snapshot) { return Text( - snapshot.data != '' + snapshot.data != null ? snapshot.data : '-', style: diff --git a/lib/screens/myWallets/confirmWalletStorage.dart b/lib/screens/myWallets/confirmWalletStorage.dart index db1566a..4aa0130 100644 --- a/lib/screens/myWallets/confirmWalletStorage.dart +++ b/lib/screens/myWallets/confirmWalletStorage.dart @@ -28,6 +28,8 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { Provider.of(context); MyWalletsProvider _myWalletProvider = Provider.of(context); + final int _currentChest = _myWalletProvider.getCurrentChest(); + this._mnemonicController.text = generatedMnemonic; return WillPopScope( @@ -126,7 +128,7 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { .isAskedWordValid && this.walletName.text != '') ? () async { - await _generateWalletProvider.storeHDWallet( + await _generateWalletProvider.storeHDWChest( generatedWallet, walletName.text, context); @@ -138,7 +140,7 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { .addPostFrameCallback((_) { _myWalletProvider.listWallets = _myWalletProvider - .getAllWalletsNames(); + .getAllWalletsNames(_currentChest); _myWalletProvider.rebuildWidget(); }); } diff --git a/lib/screens/myWallets/walletOptions-old.dart b/lib/screens/myWallets/walletOptions-old.dart new file mode 100644 index 0000000..7713274 --- /dev/null +++ b/lib/screens/myWallets/walletOptions-old.dart @@ -0,0 +1,164 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:gecko/models/myWallets.dart'; +import 'package:gecko/models/walletOptions.dart'; +import 'dart:async'; +import 'package:provider/provider.dart'; +import 'package:flutter/services.dart'; + +// ignore: must_be_immutable +class WalletOptionsOld extends StatelessWidget with ChangeNotifier { + WalletOptionsOld( + {Key keyMyWallets, + @required this.walletNbr, + @required this.walletName, + @required this.derivation}) + : super(key: keyMyWallets); + int walletNbr; + String walletName; + int derivation; + + @override + Widget build(BuildContext context) { + SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); + print("Build walletOptions"); + WalletOptionsProvider _walletOptions = + Provider.of(context); + MyWalletsProvider _myWalletProvider = + Provider.of(context); + + // _walletOptions.isWalletUnlock = false; + print("Is unlock ? ${_walletOptions.isWalletUnlock}"); + + final int _currentChest = _myWalletProvider.getCurrentChest(); + + return WillPopScope( + onWillPop: () { + _walletOptions.isWalletUnlock = false; + Navigator.popUntil( + context, + ModalRoute.withName('/mywallets'), + ); + return Future.value(true); + }, + child: Scaffold( + resizeToAvoidBottomInset: false, + appBar: AppBar( + leading: IconButton( + icon: Icon(Icons.arrow_back, color: Colors.black), + onPressed: () { + _walletOptions.isWalletUnlock = false; + Navigator.popUntil( + context, + ModalRoute.withName('/mywallets'), + ); + }), + title: SizedBox( + height: 22, + child: Text(walletName), + )), + body: Builder( + builder: (ctx) => SafeArea( + child: Column(children: [ + 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, + walletNbr, + derivation) + .then((_result) { + if (_result == true) { + WidgetsBinding.instance + .addPostFrameCallback((_) { + _myWalletProvider + .listWallets = + _myWalletProvider + .getAllWalletsNames(_currentChest); + _myWalletProvider + .rebuildWidget(); + }); + Navigator.popUntil( + context, + ModalRoute.withName( + '/mywallets'), + ); + } + }), + child: Text('Renommer ce portefeuille', + 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, + walletNbr, walletName, derivation); + WidgetsBinding.instance + .addPostFrameCallback((_) { + _myWalletProvider.listWallets = + _myWalletProvider.getAllWalletsNames(_currentChest); + _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) + ])), + ]), + )), + )); + } +} diff --git a/lib/screens/myWallets/walletOptions.dart b/lib/screens/myWallets/walletOptions.dart index 221e9e1..8ed09d4 100644 --- a/lib/screens/myWallets/walletOptions.dart +++ b/lib/screens/myWallets/walletOptions.dart @@ -27,12 +27,12 @@ class WalletOptions extends StatelessWidget with ChangeNotifier { MyWalletsProvider _myWalletProvider = Provider.of(context); - // _walletOptions.isWalletUnlock = false; - print("Is unlock ? ${_walletOptions.isWalletUnlock}"); + final int _currentChest = _myWalletProvider.getCurrentChest(); + final String shortPubkey = + _walletOptions.getShortPubkey(_walletOptions.pubkey.text); return WillPopScope( onWillPop: () { - _walletOptions.isWalletUnlock = false; Navigator.popUntil( context, ModalRoute.withName('/mywallets'), @@ -45,7 +45,6 @@ class WalletOptions extends StatelessWidget with ChangeNotifier { leading: IconButton( icon: Icon(Icons.arrow_back, color: Colors.black), onPressed: () { - _walletOptions.isWalletUnlock = false; Navigator.popUntil( context, ModalRoute.withName('/mywallets'), @@ -57,105 +56,124 @@ class WalletOptions extends StatelessWidget with ChangeNotifier { )), body: Builder( builder: (ctx) => SafeArea( - child: Column(children: [ - 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, - walletNbr, - derivation) - .then((_result) { - if (_result == true) { - WidgetsBinding.instance - .addPostFrameCallback((_) { - _myWalletProvider - .listWallets = - _myWalletProvider - .getAllWalletsNames(); - _myWalletProvider - .rebuildWidget(); - }); - Navigator.popUntil( - context, - ModalRoute.withName( - '/mywallets'), - ); - } - }), - child: Text('Renommer ce portefeuille', - 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 + child: Expanded( + child: Column(children: [ + SizedBox(height: 25), + Row(children: [ + SizedBox(width: 25), + Image.asset( + 'assets/chopp-gecko2.png', + ), + Image.asset( + 'assets/walletOptions/camera.png', + ), + // SizedBox(width: 20), + Column(children: [ + Row(children: [ + Column(children: [ + SizedBox( + width: 250, + child: Text( + walletName, + textAlign: TextAlign.center, + style: TextStyle(fontSize: 27), + )), + SizedBox(height: 5), + Text( + '500 DU', + style: TextStyle( + fontSize: 20, color: Colors.black), ), - onPressed: () async { - await _walletOptions.deleteWallet(context, - walletNbr, walletName, derivation); - 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: 5), + Image.asset( + 'assets/walletOptions/icon_oeuil.png', + ), + ]), + SizedBox(width: 0), + Column(children: [ + Image.asset( + 'assets/walletOptions/edit.png', + ), + SizedBox( + height: 60, + ) + ]) + ]), + ]), + ]), + Image.asset( + 'assets/walletOptions/QR_icon.png', ), - SizedBox(height: 10) - ])), - ]), + SizedBox(height: 15), + Row(children: [ + SizedBox(width: 30), + Image.asset( + 'assets/walletOptions/key.png', + ), + SizedBox(width: 10), + Text("${shortPubkey.split(':')[0]}:", + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.w800, + fontFamily: 'Monospace', + color: Colors.black)), + Text(shortPubkey.split(':')[1], + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.w800, + fontFamily: 'Monospace')), + SizedBox(width: 15), + ElevatedButton( + style: ElevatedButton.styleFrom( + shape: RoundedRectangleBorder( + borderRadius: new BorderRadius.circular(8), + ), + elevation: 1, + primary: Color(0xffD28928), // background + onPrimary: Colors.black, // foreground + ), + onPressed: () { + print('COPY PUBKEY'); + }, + child: Text('Copier', + style: TextStyle( + fontSize: 15, color: Colors.grey[50]))), + ]), + SizedBox(height: 10), + Row(children: [ + SizedBox(width: 30), + Image.asset( + 'assets/walletOptions/clock.png', + ), + SizedBox(width: 10), + Text('Historique des transactions', + style: + TextStyle(fontSize: 20, color: Colors.black)), + ]), + SizedBox(height: 15), + Row(children: [ + SizedBox(width: 35), + Image.asset( + 'assets/walletOptions/android-checkmark.png', + ), + SizedBox(width: 10), + Text('Portefeuille par defaut', + style: + TextStyle(fontSize: 20, color: Colors.black)), + ]), + SizedBox(height: 15), + Row(children: [ + SizedBox(width: 30), + Image.asset( + 'assets/walletOptions/trash.png', + ), + SizedBox(width: 10), + Text('Supprimer ce portefeuille', + style: TextStyle( + fontSize: 20, color: Color(0xffD80000))), + ]), + ]), + ), )), )); } diff --git a/lib/screens/myWallets/walletsHome.dart b/lib/screens/myWallets/walletsHome.dart index 1ab1650..a4aca34 100644 --- a/lib/screens/myWallets/walletsHome.dart +++ b/lib/screens/myWallets/walletsHome.dart @@ -20,12 +20,16 @@ class WalletsHome extends StatelessWidget { WalletOptionsProvider _walletOptions = Provider.of(context); _walletOptions.isWalletUnlock = false; - myWalletProvider.listWallets = myWalletProvider.getAllWalletsNames(); + + final int _currentChest = myWalletProvider.getCurrentChest(); + + myWalletProvider.listWallets = + myWalletProvider.getAllWalletsNames(_currentChest); final bool isWalletsExists = myWalletProvider.checkIfWalletExist(); if (myWalletProvider.listWallets != '') { firstWalletDerivation = - int.parse(myWalletProvider.listWallets.split('\n')[0].split(':')[2]); + int.parse(myWalletProvider.listWallets.split('\n')[0].split(':')[3]); } return Scaffold( @@ -95,114 +99,79 @@ class WalletsHome extends StatelessWidget { for (String _repository in _listWallets) Padding( padding: EdgeInsets.all(16), - child: ClipRRect( - borderRadius: BorderRadius.all(Radius.circular(12)), - child: Column(children: [ - Expanded( - child: Container( - width: double.infinity, - height: double.infinity, - decoration: BoxDecoration( - gradient: RadialGradient( - radius: 1, - colors: [ - Colors.green[100], - Colors.green[500], - ], - )), - child: - // SvgPicture.asset('assets/chopp-gecko2.png', - // semanticsLabel: 'Gecko', height: 48), - Image.asset( - 'assets/chopp-gecko2.png', - ), - )), - ListTile( - // contentPadding: const EdgeInsets.only(left: 7.0), - tileColor: - "${_repository.split(':')[0]}:${_repository.split(':')[2]}" == - defaultWallet - ? Color(0xffD28928) - : Color(0xffFFD58D), - // leading: Text('IMAGE'), + child: GestureDetector( + onTap: () { + Navigator.push(context, + MaterialPageRoute(builder: (context) { + return UnlockingWallet( + walletNbr: int.parse(_repository.split(':')[1]), + walletName: _repository.split(':')[2], + derivation: int.parse(_repository.split(':')[3])); + })); + }, + child: ClipRRect( + borderRadius: BorderRadius.all(Radius.circular(12)), + child: Column(children: [ + Expanded( + child: Container( + width: double.infinity, + height: double.infinity, + decoration: BoxDecoration( + gradient: RadialGradient( + radius: 1, + colors: [ + Colors.green[100], + Colors.green[500], + ], + )), + child: + // SvgPicture.asset('assets/chopp-gecko2.png', + // semanticsLabel: 'Gecko', height: 48), + Image.asset( + 'assets/chopp-gecko2.png', + ), + )), + ListTile( + // contentPadding: const EdgeInsets.only(left: 7.0), + tileColor: + "${_repository.split(':')[0]}:${_repository.split(':')[1]}" == + defaultWallet + ? Color(0xffD28928) + : Color(0xffFFD58D), + // leading: Text('IMAGE'), - // subtitle: Text(_repository.split(':')[3], - // style: TextStyle(fontSize: 12.0, fontFamily: 'Monospace')), - title: Center( - child: Padding( - padding: EdgeInsets.symmetric(horizontal: 5), - child: Text(_repository.split(':')[1], - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 16.0, - color: - "${_repository.split(':')[0]}:${_repository.split(':')[2]}" == - defaultWallet - ? Color(0xffF9F9F1) - : Colors.black)))), - // dense: true, - onTap: () { - Navigator.push(context, - MaterialPageRoute(builder: (context) { - return UnlockingWallet( - walletNbr: int.parse(_repository.split(':')[0]), - walletName: _repository.split(':')[1], - derivation: - int.parse(_repository.split(':')[2])); - })); - }, - ) - ]))) + // subtitle: Text(_repository.split(':')[3], + // style: TextStyle(fontSize: 12.0, fontFamily: 'Monospace')), + title: Center( + child: Padding( + padding: + EdgeInsets.symmetric(horizontal: 5), + child: Text(_repository.split(':')[2], + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 16.0, + color: + "${_repository.split(':')[0]}:${_repository.split(':')[1]}" == + defaultWallet + ? Color(0xffF9F9F1) + : Colors.black)))), + // dense: true, + onTap: () { + Navigator.push(context, + MaterialPageRoute(builder: (context) { + return UnlockingWallet( + walletNbr: + int.parse(_repository.split(':')[1]), + walletName: _repository.split(':')[2], + derivation: + int.parse(_repository.split(':')[3])); + })); + }, + ) + ])))) ]); } - Widget myWalletsList(BuildContext context) { - MyWalletsProvider _myWalletProvider = - Provider.of(context); - - final bool isWalletsExists = _myWalletProvider.checkIfWalletExist(); - - if (!isWalletsExists) { - return Text(''); - } - - if (_myWalletProvider.listWallets == '') { - return Expanded( - child: Center( - child: Text( - 'Veuillez générer votre premier portefeuille', - style: TextStyle(fontSize: 17, fontWeight: FontWeight.w500), - ))); - } - - List _listWallets = _myWalletProvider.listWallets.split('\n'); - - return Expanded( - child: ListView(children: [ - SizedBox(height: 8), - for (String _repository in _listWallets) - ListTile( - contentPadding: const EdgeInsets.only(left: 7.0), - leading: Padding( - padding: const EdgeInsets.all(6.0), - child: Text("0 Ğ1", style: TextStyle(fontSize: 14.0))), - // subtitle: Text(_repository.split(':')[3], - // style: TextStyle(fontSize: 12.0, fontFamily: 'Monospace')), - title: - Text(_repository.split(':')[1], style: TextStyle(fontSize: 16.0)), - dense: true, - onTap: () { - Navigator.push(context, MaterialPageRoute(builder: (context) { - return UnlockingWallet( - walletNbr: int.parse(_repository.split(':')[0]), - walletName: _repository.split(':')[1], - derivation: int.parse(_repository.split(':')[2])); - })); - }, - ) - ])); - } - Widget addNewDerivation(context, int _walletNbr) { final TextEditingController _newDerivationName = TextEditingController(); MyWalletsProvider _myWalletProvider = diff --git a/lib/screens/myWallets/walletsHome_old.dart b/lib/screens/myWallets/walletsHome_old.dart deleted file mode 100644 index 7a5f99e..0000000 --- a/lib/screens/myWallets/walletsHome_old.dart +++ /dev/null @@ -1,157 +0,0 @@ -import 'package:flutter/services.dart'; -import 'package:gecko/models/myWallets.dart'; -import 'package:gecko/models/walletOptions.dart'; -import 'package:flutter/material.dart'; -import 'package:gecko/screens/myWallets/unlockingWallet.dart'; -import 'package:gecko/screens/onBoarding/0_noKeychainFound.dart'; -import 'package:provider/provider.dart'; - -// ignore: must_be_immutable -class WalletsHome extends StatelessWidget { - final _derivationKey = GlobalKey(); - int firstWalletDerivation; - - @override - Widget build(BuildContext context) { - SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); - MyWalletsProvider myWalletProvider = - Provider.of(context); - WalletOptionsProvider _walletOptions = - Provider.of(context); - _walletOptions.isWalletUnlock = false; - myWalletProvider.listWallets = myWalletProvider.getAllWalletsNames(); - final bool isWalletsExists = myWalletProvider.checkIfWalletExist(); - - if (myWalletProvider.listWallets != '') { - firstWalletDerivation = - int.parse(myWalletProvider.listWallets.split('\n')[0].split(':')[2]); - } - - return Scaffold( - appBar: AppBar( - title: Text('Mes portefeuilles', - style: TextStyle(color: Colors.grey[850])), - backgroundColor: Color(0xffFFD58D), - ), - floatingActionButton: Visibility( - visible: (isWalletsExists && firstWalletDerivation != -1), - child: Container( - height: 80.0, - width: 80.0, - child: FittedBox( - child: FloatingActionButton( - heroTag: "buttonGenerateWallet", - onPressed: () { - showDialog( - context: context, - builder: (BuildContext context) { - return addNewDerivation(context, 1); - }); - }, - child: Container( - height: 40, - width: 40, - child: Icon(Icons.person_add_alt_1_rounded, - color: Colors.grey[850])), - backgroundColor: Color(0xffEFEFBF))))), - body: SafeArea( - child: !isWalletsExists - ? NoKeyChainScreen() - : myWalletsList(context))); - } - - Widget myWalletsList(BuildContext context) { - MyWalletsProvider _myWalletProvider = - Provider.of(context); - - final bool isWalletsExists = _myWalletProvider.checkIfWalletExist(); - - if (!isWalletsExists) { - return Text(''); - } - - if (_myWalletProvider.listWallets == '') { - return Expanded( - child: Center( - child: Text( - 'Veuillez générer votre premier portefeuille', - style: TextStyle(fontSize: 17, fontWeight: FontWeight.w500), - ))); - } - - List _listWallets = _myWalletProvider.listWallets.split('\n'); - - return Expanded( - child: ListView(children: [ - SizedBox(height: 8), - for (String _repository in _listWallets) - ListTile( - contentPadding: const EdgeInsets.only(left: 7.0), - leading: Padding( - padding: const EdgeInsets.all(6.0), - child: Text("0 Ğ1", style: TextStyle(fontSize: 14.0))), - // subtitle: Text(_repository.split(':')[3], - // style: TextStyle(fontSize: 12.0, fontFamily: 'Monospace')), - title: - Text(_repository.split(':')[1], style: TextStyle(fontSize: 16.0)), - dense: true, - onTap: () { - Navigator.push(context, MaterialPageRoute(builder: (context) { - return UnlockingWallet( - walletNbr: int.parse(_repository.split(':')[0]), - walletName: _repository.split(':')[1], - derivation: int.parse(_repository.split(':')[2])); - })); - }, - ) - ])); - } - - Widget addNewDerivation(context, int _walletNbr) { - 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: [ - Text('Nom du portefeuille:'), - Padding( - padding: EdgeInsets.all(8.0), - child: TextFormField( - controller: _newDerivationName, - textAlign: TextAlign.center, - autofocus: true, - ), - ), - SizedBox(height: 20), - Padding( - padding: const EdgeInsets.all(8.0), - child: ElevatedButton( - style: ElevatedButton.styleFrom( - elevation: 1, - primary: Color(0xffFFD68E), // background - onPrimary: Colors.black, // foreground - ), - onPressed: () async { - await _myWalletProvider - .generateNewDerivation( - context, _newDerivationName.text) - .then((_) => _newDerivationName.text == ''); - }, - child: Text("Créer")), - ) - ], - ), - ), - ], - ), - ); - } -} diff --git a/lib/screens/onBoarding/12.dart b/lib/screens/onBoarding/12.dart index d9e8e61..fd01ff4 100644 --- a/lib/screens/onBoarding/12.dart +++ b/lib/screens/onBoarding/12.dart @@ -61,6 +61,8 @@ class OnboardingStepFourteen extends StatelessWidget { GenerateWalletsProvider _generateWalletProvider = Provider.of(context); + final int _currentChest = _myWalletProvider.getCurrentChest(); + return Form( key: formKey, child: Padding( @@ -116,9 +118,9 @@ class OnboardingStepFourteen extends StatelessWidget { if (resultWallet) { pinColor = Colors.green[500]; print(generatedWallet.pin); - await _generateWalletProvider.storeHDWallet( + await _generateWalletProvider.storeHDWChest( generatedWallet, 'Mon portefeuille courant', context); - _myWalletProvider.getAllWalletsNames(); + _myWalletProvider.getAllWalletsNames(_currentChest); _walletOptions.reloadBuild(); _myWalletProvider.rebuildWidget(); Navigator.push( diff --git a/pubspec.yaml b/pubspec.yaml index 8cdb9aa..73c0f3f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -67,3 +67,4 @@ flutter: - assets/icon/ - assets/onBoarding/ - assets/onBoarding/progress_bar/ + - assets/walletOptions/