From 0c55cdc14130d46c2d7c4ee263fc0a0e3d72c1e2 Mon Sep 17 00:00:00 2001 From: poka Date: Sun, 7 Nov 2021 04:23:05 +0100 Subject: [PATCH] WIP: remplace file storage with Hive boxes storage --- lib/globals.dart | 9 +- lib/main.dart | 16 +- lib/models/changePin.dart | 12 +- lib/models/generateWallets.dart | 42 +--- lib/models/history.dart | 7 +- lib/models/home.dart | 12 -- lib/models/myWallets.dart | 187 ++++-------------- lib/models/walletData.dart | 36 ++++ lib/models/walletData.g.dart | 50 +++++ lib/models/walletOptions.dart | 77 ++------ lib/screens/home.dart | 6 + .../myWallets/confirmWalletStorage.dart | 4 +- lib/screens/myWallets/unlockingWallet.dart | 2 +- lib/screens/myWallets/walletOptions.dart | 5 +- lib/screens/myWallets/walletsHome.dart | 1 + lib/screens/onBoarding/12.dart | 4 +- pubspec.lock | 147 ++++++++++++++ pubspec.yaml | 3 + 18 files changed, 329 insertions(+), 291 deletions(-) create mode 100644 lib/models/walletData.dart create mode 100644 lib/models/walletData.g.dart diff --git a/lib/globals.dart b/lib/globals.dart index 5110f28..9a29df7 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -1,19 +1,20 @@ import 'dart:io'; -import 'package:gecko/models/myWallets.dart'; +import 'package:gecko/models/walletData.dart'; +import 'package:hive/hive.dart'; import 'package:logger/logger.dart'; import 'package:shared_preferences/shared_preferences.dart'; // Files paths Directory appPath; -Directory walletsDirectory; -File defaultWalletFile; -File currentChestFile; WalletData defaultWallet; String appVersion; SharedPreferences prefs; String endPointGVA; int ramSys; +Box walletBox; +Box chestBox; +Box configBox; // String cesiumPod = "https://g1.data.le-sou.org"; String cesiumPod = "https://g1.data.e-is.pro"; diff --git a/lib/main.dart b/lib/main.dart index 6d930ec..b04164d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -22,13 +22,15 @@ import 'package:gecko/models/generateWallets.dart'; import 'package:gecko/models/history.dart'; import 'package:gecko/models/home.dart'; import 'package:gecko/models/myWallets.dart'; +import 'package:gecko/models/walletData.dart'; import 'package:gecko/models/walletOptions.dart'; import 'package:gecko/screens/home.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:gecko/screens/myWallets/walletsHome.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; -import 'package:hive/hive.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'; @@ -41,16 +43,18 @@ Future main() async { WidgetsFlutterBinding.ensureInitialized(); HomeProvider _homeProvider = HomeProvider(); - MyWalletsProvider _walletsProvider = MyWalletsProvider(); - await _homeProvider.getAppPath(); + appPath = await getApplicationDocumentsDirectory(); await _homeProvider.createDefaultAvatar(); - await _walletsProvider.initWalletFolder(); // _walletsProvider.getDefaultWallet(); appVersion = await _homeProvider.getAppVersion(); prefs = await SharedPreferences.getInstance(); - Hive.init(appPath.path); - await Hive.openBox("walletBox"); + // Configure Hive and open boxes + await Hive.initFlutter(appPath.path); + Hive.registerAdapter(WalletDataAdapter()); + walletBox = await Hive.openBox("walletBox"); + chestBox = await Hive.openBox("chestBox"); + configBox = await Hive.openBox("configBox"); // final HiveStore _store = // await HiveStore.open(path: '${appPath.path}/gqlCache'); diff --git a/lib/models/changePin.dart b/lib/models/changePin.dart index 06fd9b5..5af359a 100644 --- a/lib/models/changePin.dart +++ b/lib/models/changePin.dart @@ -1,4 +1,3 @@ -import 'dart:io'; import 'package:dubp/dubp.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -13,9 +12,7 @@ class ChangePinProvider with ChangeNotifier { Future changePin(_name, _oldPin) async { try { - final _walletFile = Directory('${walletsDirectory.path}/$_name'); - final _dewif = - File(_walletFile.path + '/wallet.dewif').readAsLinesSync()[0]; + final _dewif = chestBox.get(0); NewWallet newWalletFile = await DubpRust.changeDewifPin( dewif: _dewif, @@ -32,12 +29,9 @@ class ChangePinProvider with ChangeNotifier { } } - Future storeWallet(context, _name, _newWalletFile) async { - final Directory walletNameDirectory = - Directory('${walletsDirectory.path}/$_name'); - final walletFile = File('${walletNameDirectory.path}/wallet.dewif'); + Future storeWallet(context, _name, NewWallet _newWalletFile) async { + chestBox.put(0, _newWalletFile.dewif); - walletFile.writeAsString('${_newWalletFile.dewif}'); Navigator.pop(context); return _name; } diff --git a/lib/models/generateWallets.dart b/lib/models/generateWallets.dart index 19e13d9..8899751 100644 --- a/lib/models/generateWallets.dart +++ b/lib/models/generateWallets.dart @@ -1,4 +1,3 @@ -import 'dart:io'; import 'dart:math'; import 'dart:typed_data'; import 'package:dubp/dubp.dart'; @@ -6,6 +5,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:gecko/globals.dart'; +import 'package:gecko/models/walletData.dart'; import 'package:pdf/pdf.dart'; import 'package:pdf/widgets.dart' as pw; import 'package:printing/printing.dart'; @@ -38,40 +38,14 @@ class GenerateWalletsProvider with ChangeNotifier { bool canImport = false; bool isPinChanged = false; - Future storeHDWChest( + void 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}/list.conf'); - File _currentChestFile = File('${walletsDirectory.path}/currentChest.conf'); - - final dewifFile = File('${hdDirectory.path}/wallet.dewif'); - - // List _lastConfig = []; - // _lastConfig = await masterConfigFile.readAsLines(); - // final int _lastDerivation = int.parse(_lastConfig.last.split(':')[2]); - // final int _derivationNbr = _lastDerivation + 3; - - final int _derivationNbr = 3; - List _pubkeysTmp = await DubpRust.getBip32DewifAccountsPublicKeys( - dewif: _wallet.dewif, - secretCode: _wallet.pin, - accountsIndex: [_derivationNbr]); - String _pubkey = _pubkeysTmp[0]; - - 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; + WalletData myWallet = + WalletData(chest: 0, number: 0, name: _name, derivation: 3); + walletBox.add(myWallet); + chestBox.put(0, _wallet.dewif); + configBox.put('currentChest', 0); + // walletBox.get(1) } void checkAskedWord(String inputWord, String _mnemo) { diff --git a/lib/models/history.dart b/lib/models/history.dart index ff5dd77..9be347c 100644 --- a/lib/models/history.dart +++ b/lib/models/history.dart @@ -1,5 +1,3 @@ -import 'dart:io'; - import 'package:dubp/dubp.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -52,10 +50,7 @@ class HistoryProvider with ChangeNotifier { Future pay(BuildContext context, String pinCode) async { // MyWalletsProvider _myWalletProvider = MyWalletsProvider(); - List dewifList = await File( - walletsDirectory.path + '/${defaultWallet.chest}/wallet.dewif') - .readAsLines(); - String dewif = dewifList[0]; + String dewif = chestBox.get(0); try { await DubpRust.simplePaymentFromTransparentAccount( accountIndex: defaultWallet.derivation, diff --git a/lib/models/home.dart b/lib/models/home.dart index a39fec1..1b67d41 100644 --- a/lib/models/home.dart +++ b/lib/models/home.dart @@ -11,7 +11,6 @@ import 'package:gecko/globals.dart'; import 'package:gecko/screens/history.dart'; import 'package:gecko/screens/myWallets/walletsHome.dart'; import 'package:package_info/package_info.dart'; -import 'package:path_provider/path_provider.dart'; class HomeProvider with ChangeNotifier { int _currentIndex = 0; @@ -100,17 +99,6 @@ class HomeProvider with ChangeNotifier { return _endpoint; } - Future getAppPath() async { - appPath = await getApplicationDocumentsDirectory(); - walletsDirectory = Directory('${appPath.path}/wallets'); - - bool isWalletFolderExist = await walletsDirectory.exists(); - - if (!isWalletFolderExist) { - await Directory(walletsDirectory.path).create(); - } - } - Future createDefaultAvatar() async { File defaultAvatar = File(appPath.path + '/default_avatar.png'); final bool isAvatarExist = await defaultAvatar.exists(); diff --git a/lib/models/myWallets.dart b/lib/models/myWallets.dart index 6b64310..6191ffd 100644 --- a/lib/models/myWallets.dart +++ b/lib/models/myWallets.dart @@ -1,8 +1,8 @@ -import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'dart:async'; import 'package:gecko/globals.dart'; +import 'package:gecko/models/walletData.dart'; import 'package:provider/provider.dart'; class MyWalletsProvider with ChangeNotifier { @@ -10,42 +10,12 @@ class MyWalletsProvider with ChangeNotifier { String pinCode; int pinLenght; - Future initWalletFolder() async { - // 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(); - // getDefaultWallet(); - } - await getDefaultWalletAsync(); - } - int getCurrentChest() { - File _currentChestFile = File('${walletsDirectory.path}/currentChest.conf'); - - bool isCurrentChestExist = _currentChestFile.existsSync(); - if (!isCurrentChestExist) { - _currentChestFile.createSync(); - _currentChestFile.writeAsString('0'); + if (configBox.get('currentChest') == null) { + configBox.put('currentChest', 0); } - return int.parse(_currentChestFile.readAsStringSync()); + + return configBox.get('currentChest'); } bool checkIfWalletExist() { @@ -63,89 +33,50 @@ class MyWalletsProvider with ChangeNotifier { } } - List readAllWallets(int _chest) { - // log.d(walletsDirectory.path); - - listWallets = []; - - File _walletConfig = File('${walletsDirectory.path}/$_chest/list.conf'); - _walletConfig.readAsLinesSync().forEach((element) { - listWallets.add(WalletData(element)); + List readAllWallets(int _chest) { + walletBox.toMap().forEach((key, value) { + if (value.chest == _chest) { + listWallets.add(value); + } }); - log.i(listWallets.toString()); return listWallets; } - WalletData getWalletData(String _id) { - // log.d(_id); - if (_id == '') return WalletData(''); - int chest = int.parse(_id.split(':')[0]); - final _walletConfig = File('${walletsDirectory.path}/$chest/list.conf'); + WalletData getWalletData(List _id) { + if (_id.isEmpty) return WalletData(); + int _chest = _id[0]; + int _nbr = _id[1]; - return WalletData(_walletConfig - .readAsLinesSync() - .firstWhere((element) => element.startsWith(_id))); - } + walletBox.toMap().forEach((key, value) { + if (value.chest == _chest && value.number == _nbr) { + return value; + } + }); - Future getWalletDataAsync(String _id) async { - // log.d(_id); - if (_id == '') return WalletData(''); - int chest = int.parse(_id.split(':')[0]); - final _walletConfig = File('${walletsDirectory.path}/$chest/list.conf'); - - List configLines = await _walletConfig.readAsLines(); - //log.d(configLines); - - if (configLines.isEmpty) { - return WalletData(''); - } - - return WalletData( - configLines.firstWhere((element) => element.startsWith(_id))); + return WalletData(); } void getDefaultWallet() { - defaultWalletFile = File('${appPath.path}/defaultWallet'); - - if (!defaultWalletFile.existsSync()) { - File(defaultWalletFile.path).createSync(); - defaultWalletFile.writeAsStringSync("0:0"); - } - - defaultWallet = getWalletData(defaultWalletFile.readAsStringSync()); - } - - Future getDefaultWalletAsync() async { - defaultWalletFile = File('${appPath.path}/defaultWallet'); - - if (!await defaultWalletFile.exists()) { - await File(defaultWalletFile.path).create(); - await defaultWalletFile.writeAsString("0:0"); - } else { - defaultWallet = - await getWalletDataAsync(await defaultWalletFile.readAsString()); + if (configBox.get('defaultWallet') == null) { + configBox.put('defaultWallet', [0, 0]); } + defaultWallet = configBox.get('defaultWallet'); } Future deleteAllWallet(context) async { MyWalletsProvider _myWalletProvider = Provider.of(context, listen: false); try { - log.w('DELETE THAT ?: $walletsDirectory'); + log.w('DELETE ALL WALLETS ?'); final bool _answer = await _confirmDeletingAllWallets(context); if (_answer) { - await walletsDirectory.delete(recursive: true); - await defaultWalletFile.delete(); - await walletsDirectory.create(); - await initWalletFolder(); - // await Future.delayed(Duration(milliseconds: 500)); - // scheduleMicrotask(() { + await walletBox.clear(); + await chestBox.clear(); notifyListeners(); rebuildWidget(); _myWalletProvider.rebuildWidget(); - // }); Navigator.pop(context); } @@ -187,27 +118,26 @@ class MyWalletsProvider with ChangeNotifier { Future generateNewDerivation(context, String _name) async { int _newDerivationNbr; int _newWalletNbr; - final _walletConfig = File('${walletsDirectory.path}/0/list.conf'); + int _chest = 0; + List _walletConfig = readAllWallets(_chest); - if (await _walletConfig.readAsString() == '') { + if (_walletConfig.isEmpty) { _newDerivationNbr = 3; _newWalletNbr = 0; } else { - String _lastWallet = - await _walletConfig.readAsLines().then((value) => value.last); - int _lastDerivation = int.parse(_lastWallet.split(':')[3]); - _newDerivationNbr = _lastDerivation + 3; - - int _lastWalletNbr = int.parse(_lastWallet.split(':')[1]); - _newWalletNbr = _lastWalletNbr + 1; + _newDerivationNbr = _walletConfig.last.derivation + 3; + _newWalletNbr = _walletConfig.last.number + 1; } - await _walletConfig.writeAsString( - '\n0:$_newWalletNbr:$_name:$_newDerivationNbr', - mode: FileMode.append); + WalletData newWallet = WalletData( + chest: _chest, + number: _newWalletNbr, + name: _name, + derivation: _newDerivationNbr); + + await walletBox.add(newWallet); notifyListeners(); - Navigator.pop(context); } @@ -215,44 +145,3 @@ class MyWalletsProvider with ChangeNotifier { notifyListeners(); } } - -// wallet data contains elements identifying wallet -class WalletData { - int chest; - int number; - String name; - int derivation; - - // constructor from ':'-separated string - WalletData(String element) { - if (element != '') { - List parts = element.split(':'); - - this.chest = int.parse(parts[0]); - this.number = int.parse(parts[1]); - this.name = parts[2]; - this.derivation = int.parse(parts[3]); - } - } - - // default wallet - static WalletData defaultWallet() { - return WalletData("0:0:default:3"); - } - - // representation of WalletData when debugging - @override - String toString() { - return this.name; - } - - // creates the ':'-separated string from the WalletData - String inLine() { - return "${this.chest}:${this.number}:${this.name}:${this.derivation}"; - } - - // returns only the id part of the ':'-separated string - String id() { - return "${this.chest}:${this.number}"; - } -} diff --git a/lib/models/walletData.dart b/lib/models/walletData.dart new file mode 100644 index 0000000..c1fbdde --- /dev/null +++ b/lib/models/walletData.dart @@ -0,0 +1,36 @@ +import 'package:hive_flutter/hive_flutter.dart'; + +part 'walletData.g.dart'; + +@HiveType(typeId: 0) +class WalletData extends HiveObject { + @HiveField(0) + int chest; + + @HiveField(1) + int number; + + @HiveField(2) + String name; + + @HiveField(3) + int derivation; + + WalletData({this.chest, this.number, this.name, this.derivation}); + + // representation of WalletData when debugging + @override + String toString() { + return this.name; + } + + // creates the ':'-separated string from the WalletData + String inLine() { + return "${this.chest}:${this.number}:${this.name}:${this.derivation}"; + } + + // returns only the id part of the ':'-separated string + List id() { + return [this.chest, this.number]; + } +} diff --git a/lib/models/walletData.g.dart b/lib/models/walletData.g.dart new file mode 100644 index 0000000..3182ec0 --- /dev/null +++ b/lib/models/walletData.g.dart @@ -0,0 +1,50 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'walletData.dart'; + +// ************************************************************************** +// TypeAdapterGenerator +// ************************************************************************** + +class WalletDataAdapter extends TypeAdapter { + @override + final int typeId = 0; + + @override + WalletData read(BinaryReader reader) { + final numOfFields = reader.readByte(); + final fields = { + for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), + }; + return WalletData( + chest: fields[0] as int, + number: fields[1] as int, + name: fields[2] as String, + derivation: fields[3] as int, + ); + } + + @override + void write(BinaryWriter writer, WalletData obj) { + writer + ..writeByte(4) + ..writeByte(0) + ..write(obj.chest) + ..writeByte(1) + ..write(obj.number) + ..writeByte(2) + ..write(obj.name) + ..writeByte(3) + ..write(obj.derivation); + } + + @override + int get hashCode => typeId.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is WalletDataAdapter && + runtimeType == other.runtimeType && + typeId == other.typeId; +} diff --git a/lib/models/walletOptions.dart b/lib/models/walletOptions.dart index 35953ee..35c9cda 100644 --- a/lib/models/walletOptions.dart +++ b/lib/models/walletOptions.dart @@ -9,6 +9,7 @@ import 'package:flutter/material.dart'; import 'dart:async'; import 'package:gecko/globals.dart'; import 'package:gecko/models/myWallets.dart'; +import 'package:gecko/models/walletData.dart'; import 'package:image_picker/image_picker.dart'; import 'package:truncate/truncate.dart'; import 'package:qrscan/qrscan.dart' as scanner; @@ -23,7 +24,7 @@ class WalletOptionsProvider with ChangeNotifier { bool isBalanceBlur = true; FocusNode walletNameFocus = FocusNode(); TextEditingController nameController = TextEditingController(); - String walletID; + List walletID; bool isDefaultWallet; Future get badWallet => null; @@ -75,14 +76,8 @@ class WalletOptionsProvider with ChangeNotifier { context, WalletData _wallet, String _pin, int _pinLenght) async { isWalletUnlock = false; try { - File _walletFile = File('${walletsDirectory.path}/0/wallet.dewif'); - String _localDewif = await _walletFile.readAsString(); + String _localDewif = chestBox.get(0); String _localPubkey; - // log.d("$_localDewif $_pin $_pinLenght ${_wallet.derivation}"); - - // String mnemo = await DubpRust.getBip32DewifMnemonic( - // dewif: _localDewif, secretCode: _pin); - // log.d(mnemo.toString()); if ((_localPubkey = await _getPubkeyFromDewif( _localDewif, _pin, _pinLenght, _wallet.derivation)) != @@ -119,8 +114,7 @@ class WalletOptionsProvider with ChangeNotifier { int getPinLenght(_walletNbr) { String _localDewif; if (_walletNbr is int) { - File _walletFile = File('${walletsDirectory.path}/0/wallet.dewif'); - _localDewif = _walletFile.readAsStringSync(); + _localDewif = chestBox.get(0); } else { _localDewif = _walletNbr; } @@ -131,24 +125,13 @@ class WalletOptionsProvider with ChangeNotifier { return _pinLenght; } - Future _renameWallet(_walletID, _newName) async { - final _walletConfig = File('${walletsDirectory.path}/0/list.conf'); + Future _renameWallet(List _walletID, _newName) async { + MyWalletsProvider myWalletClass = MyWalletsProvider(); - String newConfig = - await _walletConfig.readAsLines().then((List lines) { - for (String wLine in lines) { - String wID = "${wLine.split(':')[0]}:${wLine.split(':')[1]}"; - String deri = wLine.split(':')[3]; - if (wID == _walletID) { - lines.remove(wLine); - lines.add('$_walletID:$_newName:$deri'); - } - } - return lines.join('\n'); - }); + WalletData _walletTarget = myWalletClass.getWalletData(_walletID); + _walletTarget.name = _newName; + await walletBox.putAt(_walletTarget.key, _walletTarget); - await _walletConfig.delete(); - await _walletConfig.writeAsString(newConfig); _newWalletName.text = ''; } @@ -193,7 +176,7 @@ class WalletOptionsProvider with ChangeNotifier { ); } - Future editWalletName(_wID) async { + Future editWalletName(List _wID) async { bool nameState; if (isEditing) { if (!nameController.text.contains(':') && @@ -213,27 +196,12 @@ class WalletOptionsProvider with ChangeNotifier { return nameState; } - Future deleteWallet(context, wallet) async { + Future deleteWallet(context, WalletData wallet) async { final bool _answer = await _confirmDeletingWallet(context, wallet.name); if (_answer) { - final _walletConfig = File('${walletsDirectory.path}/0/list.conf'); + walletBox.delete(wallet.key); - if (wallet.derivation != -1) { - String newConfig = - await _walletConfig.readAsLines().then((List lines) { - lines.removeWhere((element) => element.contains(wallet.inLine())); - - return lines.join('\n'); - }); - - await _walletConfig.delete(); - await _walletConfig.writeAsString(newConfig); - } else { - final _walletFile = - Directory('${walletsDirectory.path}/${wallet.number}'); - await _walletFile.delete(recursive: true); - } Navigator.popUntil( context, ModalRoute.withName('/mywallets'), @@ -278,9 +246,7 @@ class WalletOptionsProvider with ChangeNotifier { Future changePin(_name, _oldPin) async { try { - final _walletFile = Directory('${walletsDirectory.path}/$_name'); - final _dewif = - File(_walletFile.path + '/wallet.dewif').readAsLinesSync()[0]; + final _dewif = chestBox.get(0); NewWallet newWalletFile = await DubpRust.changeDewifPin( dewif: _dewif, @@ -297,16 +263,6 @@ class WalletOptionsProvider with ChangeNotifier { } } - Future storeWallet(context, _name, _newWalletFile) async { - final Directory walletNameDirectory = - Directory('${walletsDirectory.path}/$_name'); - final walletFile = File('${walletNameDirectory.path}/wallet.dewif'); - - walletFile.writeAsString('${_newWalletFile.dewif}'); - Navigator.pop(context); - return _name; - } - snackCopyKey(context) { final snackBar = SnackBar( content: @@ -341,13 +297,6 @@ class WalletOptionsProvider with ChangeNotifier { return await scanner.generateBarCode(_pubkey); } - void defAsDefaultWallet(String _id) { - defaultWalletFile.deleteSync(); - defaultWalletFile.createSync(); - defaultWalletFile.writeAsStringSync(_id); - notifyListeners(); - } - Future changeAvatar() async { File _image; final picker = ImagePicker(); diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 1d349a8..f645ebb 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -22,6 +22,12 @@ class HomeScreen extends StatelessWidget { Provider.of(context); final bool isWalletsExists = _myWalletProvider.checkIfWalletExist(); + // walletBox.toMap().forEach((key, value) { + // if (value.chest == 0) { + // print('$key: ${value.derivation}'); + // } + // }); + isTall = false; ratio = 1; if (MediaQuery.of(context).size.height >= 930) { diff --git a/lib/screens/myWallets/confirmWalletStorage.dart b/lib/screens/myWallets/confirmWalletStorage.dart index 614d071..fcac81a 100644 --- a/lib/screens/myWallets/confirmWalletStorage.dart +++ b/lib/screens/myWallets/confirmWalletStorage.dart @@ -134,8 +134,8 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { onPressed: (_generateWalletProvider .isAskedWordValid && this.walletName.text != '') - ? () async { - await _generateWalletProvider.storeHDWChest( + ? () { + _generateWalletProvider.storeHDWChest( generatedWallet, walletName.text, context); diff --git a/lib/screens/myWallets/unlockingWallet.dart b/lib/screens/myWallets/unlockingWallet.dart index 1efba3c..6b3022f 100644 --- a/lib/screens/myWallets/unlockingWallet.dart +++ b/lib/screens/myWallets/unlockingWallet.dart @@ -1,9 +1,9 @@ import 'dart:async'; - import 'package:dubp/dubp.dart'; import 'package:flutter/services.dart'; import 'package:gecko/models/history.dart'; import 'package:gecko/models/myWallets.dart'; +import 'package:gecko/models/walletData.dart'; import 'package:gecko/models/walletOptions.dart'; import 'package:flutter/material.dart'; import 'package:pin_code_fields/pin_code_fields.dart'; diff --git a/lib/screens/myWallets/walletOptions.dart b/lib/screens/myWallets/walletOptions.dart index 03944c5..d077f91 100644 --- a/lib/screens/myWallets/walletOptions.dart +++ b/lib/screens/myWallets/walletOptions.dart @@ -5,6 +5,7 @@ import 'package:gecko/globals.dart'; import 'package:gecko/models/history.dart'; import 'package:gecko/models/myWallets.dart'; import 'package:gecko/models/queries.dart'; +import 'package:gecko/models/walletData.dart'; import 'package:gecko/models/walletOptions.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:provider/provider.dart'; @@ -44,7 +45,7 @@ class WalletOptions extends StatelessWidget { if (_walletOptions.nameController.text.length >= 26 && isTall) _nbrLinesName = 3; - _walletOptions.walletID = '0:${wallet.number}'; + _walletOptions.walletID = [0, wallet.number]; _myWalletProvider.getDefaultWallet(); @@ -361,7 +362,7 @@ class WalletOptions extends StatelessWidget { onTap: !_walletOptions.isDefaultWallet ? () { defaultWallet = wallet; - _walletOptions.defAsDefaultWallet(wallet.id()); + configBox.put('defaultWallet', wallet.id()); _myWalletProvider.readAllWallets(_currentChest); } : null, diff --git a/lib/screens/myWallets/walletsHome.dart b/lib/screens/myWallets/walletsHome.dart index 7241b6a..a4a5819 100644 --- a/lib/screens/myWallets/walletsHome.dart +++ b/lib/screens/myWallets/walletsHome.dart @@ -1,6 +1,7 @@ import 'package:flutter/services.dart'; import 'package:gecko/globals.dart'; import 'package:gecko/models/myWallets.dart'; +import 'package:gecko/models/walletData.dart'; import 'package:gecko/models/walletOptions.dart'; import 'package:flutter/material.dart'; import 'package:gecko/screens/commonElements.dart'; diff --git a/lib/screens/onBoarding/12.dart b/lib/screens/onBoarding/12.dart index 8755f57..732b22a 100644 --- a/lib/screens/onBoarding/12.dart +++ b/lib/screens/onBoarding/12.dart @@ -119,10 +119,10 @@ class OnboardingStepFourteen extends StatelessWidget { generatedWallet.dewif, _pin.toUpperCase(), _pinLenght); if (resultWallet) { pinColor = Colors.green[500]; - await _generateWalletProvider.storeHDWChest( + _generateWalletProvider.storeHDWChest( generatedWallet, 'Mon portefeuille courant', context); _myWalletProvider.readAllWallets(_currentChest); - await _myWalletProvider.getDefaultWalletAsync(); + _myWalletProvider.getDefaultWallet(); scheduleMicrotask(() { _walletOptions.reloadBuild(); _myWalletProvider.rebuildWidget(); diff --git a/pubspec.lock b/pubspec.lock index e964108..ee51741 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -57,6 +57,62 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.2.1" + build: + dependency: transitive + description: + name: build + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + build_config: + dependency: transitive + description: + name: build_config + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + build_daemon: + dependency: transitive + description: + name: build_daemon + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" + build_resolvers: + dependency: transitive + description: + name: build_resolvers + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.4" + build_runner: + dependency: "direct dev" + description: + name: build_runner + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" + build_runner_core: + dependency: transitive + description: + name: build_runner_core + url: "https://pub.dartlang.org" + source: hosted + version: "7.2.2" + built_collection: + dependency: transitive + description: + name: built_collection + url: "https://pub.dartlang.org" + source: hosted + version: "5.1.1" + built_value: + dependency: transitive + description: + name: built_value + url: "https://pub.dartlang.org" + source: hosted + version: "8.1.3" characters: dependency: transitive description: @@ -71,6 +127,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.1" + checked_yaml: + dependency: transitive + description: + name: checked_yaml + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" cli_util: dependency: transitive description: @@ -85,6 +148,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + code_builder: + dependency: transitive + description: + name: code_builder + url: "https://pub.dartlang.org" + source: hosted + version: "4.1.0" collection: dependency: transitive description: @@ -162,6 +232,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.0.1" + dart_style: + dependency: transitive + description: + name: dart_style + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" dbus: dependency: transitive description: @@ -211,6 +288,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.1" + fixnum: + dependency: transitive + description: + name: fixnum + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" flutter: dependency: "direct main" description: flutter @@ -348,6 +432,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "5.0.0" + graphs: + dependency: transitive + description: + name: graphs + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" hive: dependency: "direct main" description: @@ -355,6 +446,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.4" + hive_flutter: + dependency: "direct main" + description: + name: hive_flutter + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + hive_generator: + dependency: "direct dev" + description: + name: hive_generator + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" http: dependency: "direct main" description: @@ -451,6 +556,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.6.3" + json_annotation: + dependency: transitive + description: + name: json_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "4.3.0" logger: dependency: "direct main" description: @@ -717,6 +829,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + pubspec_parse: + dependency: transitive + description: + name: pubspec_parse + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" qr: dependency: transitive description: @@ -841,6 +960,20 @@ packages: description: flutter source: sdk version: "0.0.99" + source_gen: + dependency: transitive + description: + name: source_gen + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + source_helper: + dependency: transitive + description: + name: source_helper + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.0" source_map_stack_trace: dependency: transitive description: @@ -876,6 +1009,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + stream_transform: + dependency: transitive + description: + name: stream_transform + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" string_scanner: dependency: transitive description: @@ -932,6 +1072,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.4.0" + timing: + dependency: transitive + description: + name: timing + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" truncate: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 4402017..d6fbafd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -25,6 +25,7 @@ dependencies: flutter_svg: ^0.22.0 graphql_flutter: ^5.0.0 hive: ^2.0.4 + hive_flutter: ^1.1.0 http: ^0.13.0 image_gallery_saver: ^1.6.9 image_picker: ^0.8.4 @@ -64,6 +65,8 @@ dev_dependencies: sdk: flutter integration_test: sdk: flutter + hive_generator: ^1.1.1 + build_runner: ^2.1.2 # The following section is specific to Flutter. flutter: