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;
notifyListeners();
if (!_sub.nodeConnected) {
return false;
}
final hasRoot = await scanRootBalance(_sub, currentChestNumber);
if (hasRoot) {
scanedWalletNumber = 1;

View File

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

View File

@ -134,7 +134,6 @@ class HomeScreen extends StatelessWidget {
.onConnectivityChanged
.listen((ConnectivityResult result) async {
log.d('Network changed: $result');
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/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: <Widget>[
SizedBox(height: 30 * ratio),
InkWell(
key: const Key('showSeed'),
onTap: () async {
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(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: <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(
body: Stack(children: [
Builder(
builder: (ctx) => SafeArea(
child: Column(children: <Widget>[
SizedBox(height: 30 * ratio),
InkWell(
key: const Key('showSeed'),
onTap: () async {
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(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: <Widget>[
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<SubstrateSdk>(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: <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(
height: 50,
child: Row(children: const <Widget>[
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: <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),
}),
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),
),
),
]),
),
),
),
]),
]),
),
),
),
CommonElements().offlineInfo(context),
]),
);
}
}

View File

@ -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),
),
)),
),
)),
]),
]),
]),

View File

@ -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<SubstrateSdk>(builder: (context, _sub, _) {
return _sub.nodeConnected
? addNewDerivation(context)
: const Text('');
}),
// SizedBox(height: 1),
// Padding(
// padding: EdgeInsets.symmetric(horizontal: 35),

View File

@ -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<SubstrateSdk>(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<SubstrateSdk>(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),
]),
));