From 7cbf328123a3bc16d625663a8dd0cb2366527ef0 Mon Sep 17 00:00:00 2001 From: poka Date: Sun, 12 Jun 2022 19:20:15 +0200 Subject: [PATCH] fix: check if node is connected before chest creation/import; Do not allow wallet generation if node is disconnected; live check --- lib/providers/generate_wallets.dart | 4 + lib/providers/substrate_sdk.dart | 1 - lib/screens/home.dart | 1 - lib/screens/myWallets/chest_options.dart | 293 +++++++++++--------- lib/screens/myWallets/unlocking_wallet.dart | 46 +-- lib/screens/myWallets/wallets_home.dart | 7 +- lib/screens/onBoarding/10.dart | 64 +++-- 7 files changed, 232 insertions(+), 184 deletions(-) diff --git a/lib/providers/generate_wallets.dart b/lib/providers/generate_wallets.dart index d4ca755..0d90ec5 100644 --- a/lib/providers/generate_wallets.dart +++ b/lib/providers/generate_wallets.dart @@ -374,6 +374,10 @@ class GenerateWalletsProvider with ChangeNotifier { scanedWalletNumber = 0; notifyListeners(); + if (!_sub.nodeConnected) { + return false; + } + final hasRoot = await scanRootBalance(_sub, currentChestNumber); if (hasRoot) { scanedWalletNumber = 1; diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart index bbb4ffa..27cebf8 100644 --- a/lib/providers/substrate_sdk.dart +++ b/lib/providers/substrate_sdk.dart @@ -113,7 +113,6 @@ class SubstrateSdk with ChangeNotifier { } else { nodeConnected = true; } - notifyListeners(); }); diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 5286fe8..8dfc901 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -134,7 +134,6 @@ class HomeScreen extends StatelessWidget { .onConnectivityChanged .listen((ConnectivityResult result) async { log.d('Network changed: $result'); - await _sub.connectNode(ctx); }); } diff --git a/lib/screens/myWallets/chest_options.dart b/lib/screens/myWallets/chest_options.dart index 9cb75b5..f36a101 100644 --- a/lib/screens/myWallets/chest_options.dart +++ b/lib/screens/myWallets/chest_options.dart @@ -6,6 +6,8 @@ import 'package:gecko/models/wallet_data.dart'; import 'package:gecko/providers/chest_provider.dart'; import 'package:gecko/providers/home.dart'; import 'package:gecko/providers/my_wallets.dart'; +import 'package:gecko/providers/substrate_sdk.dart'; +import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/myWallets/change_pin.dart'; import 'package:gecko/screens/myWallets/custom_derivations.dart'; import 'package:gecko/screens/myWallets/show_seed.dart'; @@ -47,152 +49,171 @@ class ChestOptions extends StatelessWidget { child: Text(currentChest.name!), )), bottomNavigationBar: _homeProvider.bottomAppBar(context), - body: Builder( - builder: (ctx) => SafeArea( - child: Column(children: [ - SizedBox(height: 30 * ratio), - InkWell( - key: const Key('showSeed'), - onTap: () async { - MyWalletsProvider _myWalletProvider = - Provider.of(context, listen: false); - WalletData? defaultWallet = - _myWalletProvider.getDefaultWallet(); - String? _pin; - if (_myWalletProvider.pinCode == '') { - _pin = await Navigator.push( - context, - MaterialPageRoute( - builder: (homeContext) { - return UnlockingWallet(wallet: defaultWallet); - }, - ), - ); - } - if (_pin != null || _myWalletProvider.pinCode != '') { - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return ShowSeed( - walletName: currentChest.name, - walletProvider: walletProvider, - ); - }), - ); - } - }, - child: SizedBox( - height: 50, - child: Row(children: [ - const SizedBox(width: 20), - Image.asset( - 'assets/onBoarding/phrase_de_restauration_flou.png', - width: 60, - ), - const SizedBox(width: 15), - Text( - 'Afficher ma phrase de restauration', - style: TextStyle( - fontSize: 20, - color: orangeC, - ), - ), - ]), - ), - ), - SizedBox(height: 10 * ratio), - InkWell( - key: const Key('changePin'), - onTap: () async { - // await _chestProvider.changePin(context, cesiumWallet); - String? pinResult = await Navigator.push( - context, - MaterialPageRoute( - builder: (context) { - return ChangePinScreen( - walletName: currentChest.name, - walletProvider: walletProvider, - ); - }, - ), - ); - - if (pinResult != null) { - walletProvider.pinCode = pinResult; - } - }, - child: SizedBox( + body: Stack(children: [ + Builder( + builder: (ctx) => SafeArea( + child: Column(children: [ + SizedBox(height: 30 * ratio), + InkWell( + key: const Key('showSeed'), + onTap: () async { + MyWalletsProvider _myWalletProvider = + Provider.of(context, listen: false); + WalletData? defaultWallet = + _myWalletProvider.getDefaultWallet(); + String? _pin; + if (_myWalletProvider.pinCode == '') { + _pin = await Navigator.push( + context, + MaterialPageRoute( + builder: (homeContext) { + return UnlockingWallet(wallet: defaultWallet); + }, + ), + ); + } + if (_pin != null || _myWalletProvider.pinCode != '') { + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return ShowSeed( + walletName: currentChest.name, + walletProvider: walletProvider, + ); + }), + ); + } + }, + child: SizedBox( height: 50, child: Row(children: [ - const SizedBox(width: 26), + const SizedBox(width: 20), Image.asset( - 'assets/chests/secret_code.png', - height: 25, + 'assets/onBoarding/phrase_de_restauration_flou.png', + width: 60, ), - const SizedBox(width: 18), - const Text( - 'Changer mon code secret', - style: TextStyle(fontSize: 20, color: Colors.black), + const SizedBox(width: 15), + Text( + 'Afficher ma phrase de restauration', + style: TextStyle( + fontSize: 20, + color: orangeC, + ), ), - ])), - ), - SizedBox(height: 10 * ratio), - InkWell( - key: const Key('createRootDerivation'), - onTap: () async { - await Navigator.push( - context, - MaterialPageRoute( - builder: (context) { - return const CustomDerivation(); - }, + ]), + ), + ), + SizedBox(height: 10 * ratio), + Consumer(builder: (context, _sub, _) { + return InkWell( + key: const Key('changePin'), + onTap: _sub.nodeConnected + ? () async { + // await _chestProvider.changePin(context, cesiumWallet); + String? pinResult = await Navigator.push( + context, + MaterialPageRoute( + builder: (context) { + return ChangePinScreen( + walletName: currentChest.name, + walletProvider: walletProvider, + ); + }, + ), + ); + + if (pinResult != null) { + walletProvider.pinCode = pinResult; + } + } + : null, + child: SizedBox( + height: 50, + child: Row(children: [ + const SizedBox(width: 26), + Image.asset( + 'assets/chests/secret_code.png', + height: 25, + ), + const SizedBox(width: 18), + Text( + 'Changer mon code secret', + style: TextStyle( + fontSize: 20, + color: _sub.nodeConnected + ? Colors.black + : Colors.grey[500]), + ), + ])), + ); + }), + SizedBox(height: 10 * ratio), + Consumer(builder: (context, _sub, _) { + return InkWell( + key: const Key('createRootDerivation'), + onTap: _sub.nodeConnected + ? () async { + await Navigator.push( + context, + MaterialPageRoute( + builder: (context) { + return const CustomDerivation(); + }, + ), + ); + } + : null, + child: SizedBox( + height: 50, + child: Row(children: [ + const SizedBox(width: 35), + const Icon( + Icons.manage_accounts, + size: 33, + ), + const SizedBox(width: 25), + Text( + 'Créer une autre dérivation', + style: TextStyle( + fontSize: 20, + color: _sub.nodeConnected + ? Colors.black + : Colors.grey[500]), + ), + ]), ), ); - }, - child: SizedBox( - height: 50, - child: Row(children: const [ - SizedBox(width: 35), - Icon( - Icons.manage_accounts, - size: 33, - ), - SizedBox(width: 25), - Text( - 'Créer une autre dérivation', - style: TextStyle(fontSize: 20, color: Colors.black), - ), - ]), - ), - ), - SizedBox(height: 10 * ratio), - InkWell( - key: const Key('deleteChest'), - onTap: () async { - await _chestProvider.deleteChest(context, currentChest); - }, - child: SizedBox( - height: 50, - child: Row(children: [ - const SizedBox(width: 28), - Image.asset( - 'assets/walletOptions/trash.png', - height: 45, - ), - const SizedBox(width: 20), - const Text( - 'Supprimer ce coffre', - style: TextStyle( - fontSize: 20, - color: Color(0xffD80000), + }), + SizedBox(height: 10 * ratio), + InkWell( + key: const Key('deleteChest'), + onTap: () async { + await _chestProvider.deleteChest(context, currentChest); + }, + child: SizedBox( + height: 50, + child: Row(children: [ + const SizedBox(width: 28), + Image.asset( + 'assets/walletOptions/trash.png', + height: 45, ), - ), - ]), + const SizedBox(width: 20), + const Text( + 'Supprimer ce coffre', + style: TextStyle( + fontSize: 20, + color: Color(0xffD80000), + ), + ), + ]), + ), ), - ), - ]), + ]), + ), ), - ), + CommonElements().offlineInfo(context), + ]), ); } } diff --git a/lib/screens/myWallets/unlocking_wallet.dart b/lib/screens/myWallets/unlocking_wallet.dart index ca49618..f7ff92e 100644 --- a/lib/screens/myWallets/unlocking_wallet.dart +++ b/lib/screens/myWallets/unlocking_wallet.dart @@ -126,30 +126,30 @@ class UnlockingWallet extends StatelessWidget { ]), ), const SizedBox(height: 10), - if (canUnlock) - InkWell( - key: const Key('chooseChest'), - onTap: () { - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return const ChooseChest(); - }), - ); - }, - child: SizedBox( - width: 400, - height: 50, - child: Center( - child: Text( - 'Changer de coffre', - style: TextStyle( - fontSize: 22, - color: orangeC, - fontWeight: FontWeight.w600), - ), + // if (canUnlock) + InkWell( + key: const Key('chooseChest'), + onTap: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return const ChooseChest(); + }), + ); + }, + child: SizedBox( + width: 400, + height: 50, + child: Center( + child: Text( + 'Changer de coffre', + style: TextStyle( + fontSize: 22, + color: orangeC, + fontWeight: FontWeight.w600), ), - )), + ), + )), ]), ]), ]), diff --git a/lib/screens/myWallets/wallets_home.dart b/lib/screens/myWallets/wallets_home.dart index 4290487..9f7f304 100644 --- a/lib/screens/myWallets/wallets_home.dart +++ b/lib/screens/myWallets/wallets_home.dart @@ -7,6 +7,7 @@ import 'package:gecko/providers/home.dart'; import 'package:gecko/providers/my_wallets.dart'; import 'package:gecko/models/wallet_data.dart'; import 'package:flutter/material.dart'; +import 'package:gecko/providers/substrate_sdk.dart'; import 'package:gecko/providers/wallet_options.dart'; import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/myWallets/chest_options.dart'; @@ -298,7 +299,11 @@ class WalletsHome extends StatelessWidget { ), ), )), - addNewDerivation(context), + Consumer(builder: (context, _sub, _) { + return _sub.nodeConnected + ? addNewDerivation(context) + : const Text(''); + }), // SizedBox(height: 1), // Padding( // padding: EdgeInsets.symmetric(horizontal: 35), diff --git a/lib/screens/onBoarding/10.dart b/lib/screens/onBoarding/10.dart index d2e756d..b06ba94 100644 --- a/lib/screens/onBoarding/10.dart +++ b/lib/screens/onBoarding/10.dart @@ -73,28 +73,48 @@ class OnboardingStepTen extends StatelessWidget { ), ), ), - pinForm(context, _walletOptions, _pinLenght, 1, 2), - InkWell( - onTap: () { - _walletOptions.changePinCacheChoice(); - }, - child: Row(children: [ - const SizedBox(height: 30), - const Spacer(), - Icon( - configBox.get('isCacheChecked') ?? false - ? Icons.check_box - : Icons.check_box_outline_blank, - color: orangeC, - ), - const SizedBox(width: 8), - Text( - 'Garder ce code en mémoire 15 minutes', - style: TextStyle(fontSize: 16, color: Colors.grey[700]), - ), - const Spacer() - ]), - ), + Consumer(builder: (context, _sub, _) { + return _sub.nodeConnected + ? pinForm(context, _walletOptions, _pinLenght, 1, 2) + : Row( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + Text( + 'Vous devez vous connecter à internet\npour valider votre coffre', + style: TextStyle( + fontSize: 20, + color: Colors.redAccent, + fontWeight: FontWeight.w500, + ), + textAlign: TextAlign.center, + ), + ]); + }), + Consumer(builder: (context, _sub, _) { + return _sub.nodeConnected + ? InkWell( + onTap: () { + _walletOptions.changePinCacheChoice(); + }, + child: Row(children: [ + const SizedBox(height: 30), + const Spacer(), + Icon( + configBox.get('isCacheChecked') ?? false + ? Icons.check_box + : Icons.check_box_outline_blank, + color: orangeC, + ), + const SizedBox(width: 8), + Text( + 'Garder ce code en mémoire 15 minutes', + style: + TextStyle(fontSize: 16, color: Colors.grey[700]), + ), + const Spacer() + ])) + : const Text(''); + }), const SizedBox(height: 10), ]), ));