From ca85a45dd6d884dc5ded997be3d40cc1c4fce2a6 Mon Sep 17 00:00:00 2001
From: poka <poka@p2p.legal>
Date: Sun, 4 Apr 2021 18:53:32 +0200
Subject: [PATCH] Fix bug after creating keystore; fix bug when deleting wallet

---
 lib/models/myWallets.dart              | 6 +++++-
 lib/models/walletOptions.dart          | 6 ++----
 lib/screens/myWallets/walletsHome.dart | 3 ---
 lib/screens/onBoarding/12.dart         | 1 +
 pubspec.yaml                           | 2 +-
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/lib/models/myWallets.dart b/lib/models/myWallets.dart
index 350c0528..5f43a1bf 100644
--- a/lib/models/myWallets.dart
+++ b/lib/models/myWallets.dart
@@ -97,6 +97,10 @@ class MyWalletsProvider with ChangeNotifier {
     List configLines = await _walletConfig.readAsLines();
     log.d(configLines);
 
+    if (configLines.isEmpty) {
+      return WalletData('');
+    }
+
     return WalletData(
         configLines.firstWhere((element) => element.startsWith(_id)));
   }
@@ -136,7 +140,7 @@ class MyWalletsProvider with ChangeNotifier {
         await walletsDirectory.create();
         // await defaultWalletFile.create();
         await initWalletFolder();
-        await Future.delayed(Duration(milliseconds: 100));
+        await Future.delayed(Duration(milliseconds: 500));
         notifyListeners();
         rebuildWidget();
         Navigator.pop(context);
diff --git a/lib/models/walletOptions.dart b/lib/models/walletOptions.dart
index 3ee1d976..4381cd09 100644
--- a/lib/models/walletOptions.dart
+++ b/lib/models/walletOptions.dart
@@ -78,15 +78,13 @@ class WalletOptionsProvider with ChangeNotifier {
       File _walletFile = File('${walletsDirectory.path}/0/wallet.dewif');
       String _localDewif = await _walletFile.readAsString();
       String _localPubkey;
-      // log.d("_wallet:");
-      log.d(_pin);
+      // log.d("$_localDewif $_pin $_pinLenght ${_wallet.derivation}");
 
       if ((_localPubkey = await _getPubkeyFromDewif(
               _localDewif, _pin, _pinLenght, _wallet.derivation)) !=
           'false') {
         this.pubkey.text = _localPubkey;
         isWalletUnlock = true;
-        // notifyListeners();
 
         return _localDewif;
       } else {
@@ -95,7 +93,6 @@ class WalletOptionsProvider with ChangeNotifier {
     } catch (e) {
       log.e('ERROR READING FILE: $e');
       this.pubkey.clear();
-      // notifyListeners();
       return 'bad';
     }
   }
@@ -320,6 +317,7 @@ class WalletOptionsProvider with ChangeNotifier {
   }
 
   String getShortPubkey(String pubkey) {
+    log.d(pubkey);
     List<int> pubkeyByte = Base58Decode(pubkey);
     Digest pubkeyS256 = sha256.convert(sha256.convert(pubkeyByte).bytes);
     String pubkeyCheksum = Base58Encode(pubkeyS256.bytes);
diff --git a/lib/screens/myWallets/walletsHome.dart b/lib/screens/myWallets/walletsHome.dart
index ef02103a..db25c182 100644
--- a/lib/screens/myWallets/walletsHome.dart
+++ b/lib/screens/myWallets/walletsHome.dart
@@ -18,9 +18,6 @@ class WalletsHome extends StatelessWidget {
     SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
     MyWalletsProvider myWalletProvider =
         Provider.of<MyWalletsProvider>(context);
-    WalletOptionsProvider _walletOptions =
-        Provider.of<WalletOptionsProvider>(context);
-    _walletOptions.isWalletUnlock = false;
 
     final int _currentChest = myWalletProvider.getCurrentChest();
 
diff --git a/lib/screens/onBoarding/12.dart b/lib/screens/onBoarding/12.dart
index 25cceb15..1999b09f 100644
--- a/lib/screens/onBoarding/12.dart
+++ b/lib/screens/onBoarding/12.dart
@@ -110,6 +110,7 @@ class OnboardingStepFourteen extends StatelessWidget {
               )
             ],
             onCompleted: (_pin) async {
+              _myWalletProvider.pinCode = _pin;
               final bool resultWallet = await _walletOptions.checkPinOK(
                   generatedWallet.dewif, _pin.toUpperCase(), _pinLenght);
               if (resultWallet) {
diff --git a/pubspec.yaml b/pubspec.yaml
index 2eee3575..8d692e12 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.2+1
+version: 0.0.2+2
 
 environment:
   sdk: ">=2.7.0 <3.0.0"
-- 
GitLab