From 2b053226a7089f45205232c275504a075bb92e73 Mon Sep 17 00:00:00 2001 From: poka Date: Mon, 11 Jan 2021 04:50:15 +0100 Subject: [PATCH] Fix unlock wallet path; Fix null boolean; WIP: Try differents way to update wallets list; --- lib/main.dart | 3 +- lib/ui/generateWallets.dart | 56 +++++++++++++++++++++++++++++++------ lib/ui/myWallets.dart | 6 ++-- pubspec.lock | 45 ++++++++++++++++------------- pubspec.yaml | 2 +- 5 files changed, 80 insertions(+), 32 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index f8867a9..75d4242 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,9 +6,10 @@ import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:flutter/foundation.dart'; // void main() => runApp(Gecko()); +final bool enableSentry = true; Future main() async { - if (kReleaseMode) { + if (kReleaseMode && enableSentry) { await SentryFlutter.init( (options) { options.dsn = diff --git a/lib/ui/generateWallets.dart b/lib/ui/generateWallets.dart index dcae250..aa0ecc1 100644 --- a/lib/ui/generateWallets.dart +++ b/lib/ui/generateWallets.dart @@ -2,7 +2,6 @@ import 'package:gecko/ui/myWallets.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:dubp/dubp.dart'; -import 'package:pin_code_fields/pin_code_fields.dart'; import 'package:sentry/sentry.dart' as sentry; import 'dart:io'; import 'dart:async'; @@ -16,6 +15,7 @@ class GenerateWalletScreen extends StatefulWidget { class GenerateWalletState extends State { GlobalKey _keyWallets = GlobalKey(); + GlobalKey _keyValidWallets = GlobalKey(); void initState() { super.initState(); DubpRust.setup(); @@ -174,19 +174,25 @@ class GenerateWalletState extends State { context, MaterialPageRoute(builder: (context) { return ValidStoreWalletScreen( + validationKey: _keyValidWallets, generatedMnemonic: this.generatedMnemonic, generatedWallet: this.actualWallet); }), ).then((value) => setState(() { - print( - 'TODO: Fix error null boolean ?'); //TODO: Fix error null boolean - if (value) { + if (value != null) { + print( + 'TODO: Fix resetWalletState()'); //TODO: Fix resetWalletState() _pin.clear(); _mnemonicController.clear(); _pubkey.clear(); this.generatedMnemonic = null; this.actualWallet = null; this.walletIsGenerated = false; + resetWalletState(); + // setState(() {}); + // getAllWalletsNames(); + // checkIfWalletExist('tata'); + // _keyWallets.currentState.getAllWalletsNames(); } })); } @@ -209,6 +215,17 @@ class GenerateWalletState extends State { ]))); } + Future resetWalletState() async { + final bool _isExist = await checkIfWalletExist('tata'); + print('The wallet exist in resetWalletState(): ' + _isExist.toString()); + // initState(); + // _keyWallets.currentState.setState(() {}); + setState(() { + // getAllWalletsNames(); + // this.walletIsGenerated = true; + }); + } + Future generateMnemonic() async { try { this.generatedMnemonic = @@ -259,10 +276,10 @@ class GenerateWalletState extends State { // deleteWallet(); print(_walletFile.path); - final isExist = await File(_walletFile.path).exists(); + final bool isExist = await File(_walletFile.path).exists(); print('Wallet existe ? : ' + isExist.toString()); print('Is wallet generated ? : ' + walletIsGenerated.toString()); - if (isExist == true) { + if (isExist) { print('Un wallet existe !'); return true; } else { @@ -270,6 +287,28 @@ class GenerateWalletState extends State { } } + Future getAllWalletsNames() async { + print('Je suis getAllWalletsNames() !!'); + final _appPath = await getApplicationDocumentsDirectory(); + // List _listWallets = []; + // _listWallets.add('tortuuue'); + _keyValidWallets.currentState._listWallets + .clear(); //TODO: Fix: The getter '_listWallets' was called on null. + print(_appPath); + print('Je suis getAllWalletsNames() !! 2'); + + _appPath + .list(recursive: false, followLinks: false) + .listen((FileSystemEntity entity) { + print(entity.path.split('/').last); + _keyValidWallets.currentState._listWallets + .add(entity.path.split('/').last); + }); + + return _keyValidWallets.currentState._listWallets; + // final _local = await _appPath.path.list().toList(); + } + Future importWallet() async {} Future get _localPath async { @@ -291,10 +330,11 @@ class ValidStoreWalletScreen extends StatefulWidget { : super(key: validationKey); @override - _ValidStoreWalletScreen createState() => _ValidStoreWalletScreen(); + ValidStoreWalletState createState() => ValidStoreWalletState(); } -class _ValidStoreWalletScreen extends State { +class ValidStoreWalletState extends State { + GlobalKey _keyValidWallets = GlobalKey(); void initState() { super.initState(); // DubpRust.setup(); diff --git a/lib/ui/myWallets.dart b/lib/ui/myWallets.dart index 9928cdd..780be3d 100644 --- a/lib/ui/myWallets.dart +++ b/lib/ui/myWallets.dart @@ -235,7 +235,7 @@ class MyWalletState extends State { Future readLocalWallet(String _pin) async { // print(pin); try { - final file = await _localWallet; + final file = await _localWallet('tata'); String _localDewif = await file.readAsString(); String _localPubkey; @@ -275,8 +275,8 @@ class MyWalletState extends State { return directory.path; } - Future get _localWallet async { + Future _localWallet(_name) async { final path = await _localPath; - return File('$path/wallet.dewif'); + return File('$path/wallets/$_name/wallet.dewif'); } } diff --git a/pubspec.lock b/pubspec.lock index 8446555..376b9d0 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -21,42 +21,42 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.5.0-nullsafety.3" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0-nullsafety.3" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0-nullsafety.5" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0-nullsafety.3" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0-nullsafety.3" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0-nullsafety.5" connectivity: dependency: transitive description: @@ -112,7 +112,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0-nullsafety.3" ffi: dependency: transitive description: @@ -282,20 +282,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.3" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.3-nullsafety.3" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10-nullsafety.3" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0-nullsafety.6" nested: dependency: transitive description: @@ -323,7 +330,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0-nullsafety.3" path_provider: dependency: "direct main" description: @@ -461,42 +468,42 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.0-nullsafety.4" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0-nullsafety.6" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0-nullsafety.3" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0-nullsafety.3" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0-nullsafety.3" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.2.19-nullsafety.6" truncate: dependency: "direct main" description: @@ -510,7 +517,7 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0-nullsafety.5" uuid: dependency: transitive description: @@ -531,7 +538,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0-nullsafety.5" websocket: dependency: transitive description: @@ -568,5 +575,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.10.0-110 <2.11.0" + dart: ">=2.12.0-0.0 <3.0.0" flutter: ">=1.22.0 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index dff480d..f5eced2 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.0+8 +version: 0.0.0+9 environment: sdk: ">=2.7.0 <3.0.0"