fix: check if node is connected before chest creation/import; Do not allow wallet generation if node is disconnected; live check

This commit is contained in:
poka 2022-06-12 19:20:15 +02:00
parent 7c11146278
commit 7cbf328123
7 changed files with 232 additions and 184 deletions

View File

@ -374,6 +374,10 @@ class GenerateWalletsProvider with ChangeNotifier {
scanedWalletNumber = 0; scanedWalletNumber = 0;
notifyListeners(); notifyListeners();
if (!_sub.nodeConnected) {
return false;
}
final hasRoot = await scanRootBalance(_sub, currentChestNumber); final hasRoot = await scanRootBalance(_sub, currentChestNumber);
if (hasRoot) { if (hasRoot) {
scanedWalletNumber = 1; scanedWalletNumber = 1;

View File

@ -113,7 +113,6 @@ class SubstrateSdk with ChangeNotifier {
} else { } else {
nodeConnected = true; nodeConnected = true;
} }
notifyListeners(); notifyListeners();
}); });

View File

@ -134,7 +134,6 @@ class HomeScreen extends StatelessWidget {
.onConnectivityChanged .onConnectivityChanged
.listen((ConnectivityResult result) async { .listen((ConnectivityResult result) async {
log.d('Network changed: $result'); log.d('Network changed: $result');
await _sub.connectNode(ctx); await _sub.connectNode(ctx);
}); });
} }

View File

@ -6,6 +6,8 @@ import 'package:gecko/models/wallet_data.dart';
import 'package:gecko/providers/chest_provider.dart'; import 'package:gecko/providers/chest_provider.dart';
import 'package:gecko/providers/home.dart'; import 'package:gecko/providers/home.dart';
import 'package:gecko/providers/my_wallets.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/change_pin.dart';
import 'package:gecko/screens/myWallets/custom_derivations.dart'; import 'package:gecko/screens/myWallets/custom_derivations.dart';
import 'package:gecko/screens/myWallets/show_seed.dart'; import 'package:gecko/screens/myWallets/show_seed.dart';
@ -47,152 +49,171 @@ class ChestOptions extends StatelessWidget {
child: Text(currentChest.name!), child: Text(currentChest.name!),
)), )),
bottomNavigationBar: _homeProvider.bottomAppBar(context), bottomNavigationBar: _homeProvider.bottomAppBar(context),
body: Builder( body: Stack(children: [
builder: (ctx) => SafeArea( Builder(
child: Column(children: <Widget>[ builder: (ctx) => SafeArea(
SizedBox(height: 30 * ratio), child: Column(children: <Widget>[
InkWell( SizedBox(height: 30 * ratio),
key: const Key('showSeed'), InkWell(
onTap: () async { key: const Key('showSeed'),
MyWalletsProvider _myWalletProvider = onTap: () async {
Provider.of<MyWalletsProvider>(context, listen: false); MyWalletsProvider _myWalletProvider =
WalletData? defaultWallet = Provider.of<MyWalletsProvider>(context, listen: false);
_myWalletProvider.getDefaultWallet(); WalletData? defaultWallet =
String? _pin; _myWalletProvider.getDefaultWallet();
if (_myWalletProvider.pinCode == '') { String? _pin;
_pin = await Navigator.push( if (_myWalletProvider.pinCode == '') {
context, _pin = await Navigator.push(
MaterialPageRoute( context,
builder: (homeContext) { MaterialPageRoute(
return UnlockingWallet(wallet: defaultWallet); builder: (homeContext) {
}, return UnlockingWallet(wallet: defaultWallet);
), },
); ),
} );
if (_pin != null || _myWalletProvider.pinCode != '') { }
Navigator.push( if (_pin != null || _myWalletProvider.pinCode != '') {
context, Navigator.push(
MaterialPageRoute(builder: (context) { context,
return ShowSeed( MaterialPageRoute(builder: (context) {
walletName: currentChest.name, return ShowSeed(
walletProvider: walletProvider, walletName: currentChest.name,
); walletProvider: walletProvider,
}), );
); }),
} );
}, }
child: SizedBox( },
height: 50, child: SizedBox(
child: Row(children: <Widget>[
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(
height: 50, height: 50,
child: Row(children: <Widget>[ child: Row(children: <Widget>[
const SizedBox(width: 26), const SizedBox(width: 20),
Image.asset( Image.asset(
'assets/chests/secret_code.png', 'assets/onBoarding/phrase_de_restauration_flou.png',
height: 25, width: 60,
), ),
const SizedBox(width: 18), const SizedBox(width: 15),
const Text( Text(
'Changer mon code secret', 'Afficher ma phrase de restauration',
style: TextStyle(fontSize: 20, color: Colors.black), style: TextStyle(
fontSize: 20,
color: orangeC,
),
), ),
])), ]),
), ),
SizedBox(height: 10 * ratio), ),
InkWell( SizedBox(height: 10 * ratio),
key: const Key('createRootDerivation'), Consumer<SubstrateSdk>(builder: (context, _sub, _) {
onTap: () async { return InkWell(
await Navigator.push( key: const Key('changePin'),
context, onTap: _sub.nodeConnected
MaterialPageRoute( ? () async {
builder: (context) { // await _chestProvider.changePin(context, cesiumWallet);
return const CustomDerivation(); 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: <Widget>[
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<SubstrateSdk>(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: <Widget>[
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( SizedBox(height: 10 * ratio),
height: 50, InkWell(
child: Row(children: const <Widget>[ key: const Key('deleteChest'),
SizedBox(width: 35), onTap: () async {
Icon( await _chestProvider.deleteChest(context, currentChest);
Icons.manage_accounts, },
size: 33, child: SizedBox(
), height: 50,
SizedBox(width: 25), child: Row(children: <Widget>[
Text( const SizedBox(width: 28),
'Créer une autre dérivation', Image.asset(
style: TextStyle(fontSize: 20, color: Colors.black), 'assets/walletOptions/trash.png',
), height: 45,
]),
),
),
SizedBox(height: 10 * ratio),
InkWell(
key: const Key('deleteChest'),
onTap: () async {
await _chestProvider.deleteChest(context, currentChest);
},
child: SizedBox(
height: 50,
child: Row(children: <Widget>[
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),
), ),
), const SizedBox(width: 20),
]), const Text(
'Supprimer ce coffre',
style: TextStyle(
fontSize: 20,
color: Color(0xffD80000),
),
),
]),
),
), ),
), ]),
]), ),
), ),
), CommonElements().offlineInfo(context),
]),
); );
} }
} }

View File

@ -126,30 +126,30 @@ class UnlockingWallet extends StatelessWidget {
]), ]),
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
if (canUnlock) // if (canUnlock)
InkWell( InkWell(
key: const Key('chooseChest'), key: const Key('chooseChest'),
onTap: () { onTap: () {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) { MaterialPageRoute(builder: (context) {
return const ChooseChest(); return const ChooseChest();
}), }),
); );
}, },
child: SizedBox( child: SizedBox(
width: 400, width: 400,
height: 50, height: 50,
child: Center( child: Center(
child: Text( child: Text(
'Changer de coffre', 'Changer de coffre',
style: TextStyle( style: TextStyle(
fontSize: 22, fontSize: 22,
color: orangeC, color: orangeC,
fontWeight: FontWeight.w600), fontWeight: FontWeight.w600),
),
), ),
)), ),
)),
]), ]),
]), ]),
]), ]),

View File

@ -7,6 +7,7 @@ import 'package:gecko/providers/home.dart';
import 'package:gecko/providers/my_wallets.dart'; import 'package:gecko/providers/my_wallets.dart';
import 'package:gecko/models/wallet_data.dart'; import 'package:gecko/models/wallet_data.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:gecko/providers/wallet_options.dart'; import 'package:gecko/providers/wallet_options.dart';
import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/common_elements.dart';
import 'package:gecko/screens/myWallets/chest_options.dart'; import 'package:gecko/screens/myWallets/chest_options.dart';
@ -298,7 +299,11 @@ class WalletsHome extends StatelessWidget {
), ),
), ),
)), )),
addNewDerivation(context), Consumer<SubstrateSdk>(builder: (context, _sub, _) {
return _sub.nodeConnected
? addNewDerivation(context)
: const Text('');
}),
// SizedBox(height: 1), // SizedBox(height: 1),
// Padding( // Padding(
// padding: EdgeInsets.symmetric(horizontal: 35), // padding: EdgeInsets.symmetric(horizontal: 35),

View File

@ -73,28 +73,48 @@ class OnboardingStepTen extends StatelessWidget {
), ),
), ),
), ),
pinForm(context, _walletOptions, _pinLenght, 1, 2), Consumer<SubstrateSdk>(builder: (context, _sub, _) {
InkWell( return _sub.nodeConnected
onTap: () { ? pinForm(context, _walletOptions, _pinLenght, 1, 2)
_walletOptions.changePinCacheChoice(); : Row(
}, mainAxisAlignment: MainAxisAlignment.center,
child: Row(children: [ children: const [
const SizedBox(height: 30), Text(
const Spacer(), 'Vous devez vous connecter à internet\npour valider votre coffre',
Icon( style: TextStyle(
configBox.get('isCacheChecked') ?? false fontSize: 20,
? Icons.check_box color: Colors.redAccent,
: Icons.check_box_outline_blank, fontWeight: FontWeight.w500,
color: orangeC, ),
), textAlign: TextAlign.center,
const SizedBox(width: 8), ),
Text( ]);
'Garder ce code en mémoire 15 minutes', }),
style: TextStyle(fontSize: 16, color: Colors.grey[700]), Consumer<SubstrateSdk>(builder: (context, _sub, _) {
), return _sub.nodeConnected
const Spacer() ? 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), const SizedBox(height: 10),
]), ]),
)); ));