2021-02-27 20:29:35 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2021-03-11 07:08:45 +01:00
|
|
|
import 'package:gecko/globals.dart';
|
2021-01-23 16:38:03 +01:00
|
|
|
import 'package:gecko/models/myWallets.dart';
|
2021-01-28 21:45:35 +01:00
|
|
|
import 'package:gecko/models/walletOptions.dart';
|
2021-01-13 00:00:11 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2021-04-03 00:07:03 +02:00
|
|
|
import 'package:gecko/screens/commonElements.dart';
|
|
|
|
import 'package:gecko/screens/myWallets/walletOptions.dart';
|
2021-03-08 06:21:04 +01:00
|
|
|
import 'package:gecko/screens/onBoarding/0_noKeychainFound.dart';
|
2021-01-28 15:10:09 +01:00
|
|
|
import 'package:provider/provider.dart';
|
2021-01-13 00:00:11 +01:00
|
|
|
|
2021-01-26 21:00:26 +01:00
|
|
|
// ignore: must_be_immutable
|
|
|
|
class WalletsHome extends StatelessWidget {
|
2021-02-15 01:44:25 +01:00
|
|
|
final _derivationKey = GlobalKey<FormState>();
|
2021-02-18 04:42:57 +01:00
|
|
|
int firstWalletDerivation;
|
2021-02-15 01:44:25 +01:00
|
|
|
|
2021-01-13 00:00:11 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-02-27 20:29:35 +01:00
|
|
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
2021-01-28 15:10:09 +01:00
|
|
|
MyWalletsProvider myWalletProvider =
|
|
|
|
Provider.of<MyWalletsProvider>(context);
|
2021-03-19 06:33:48 +01:00
|
|
|
|
|
|
|
final int _currentChest = myWalletProvider.getCurrentChest();
|
|
|
|
|
|
|
|
myWalletProvider.listWallets =
|
2021-03-31 02:38:44 +02:00
|
|
|
myWalletProvider.readAllWallets(_currentChest);
|
2021-01-28 21:45:35 +01:00
|
|
|
final bool isWalletsExists = myWalletProvider.checkIfWalletExist();
|
2021-01-26 21:00:26 +01:00
|
|
|
|
2021-03-31 02:38:44 +02:00
|
|
|
if (myWalletProvider.listWallets.isEmpty) {
|
|
|
|
firstWalletDerivation = myWalletProvider.listWallets[0].derivation;
|
2021-03-21 23:04:11 +01:00
|
|
|
|
|
|
|
myWalletProvider.getDefaultWallet();
|
2021-02-18 04:42:57 +01:00
|
|
|
}
|
|
|
|
|
2021-04-05 20:48:28 +02:00
|
|
|
log.d("${myWalletProvider.pinCode},${myWalletProvider.pinLenght}");
|
|
|
|
|
2021-04-03 00:07:03 +02:00
|
|
|
return WillPopScope(
|
|
|
|
onWillPop: () {
|
|
|
|
Navigator.popUntil(
|
|
|
|
context,
|
|
|
|
ModalRoute.withName('/'),
|
|
|
|
);
|
|
|
|
return Future<bool>.value(true);
|
|
|
|
},
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
leading: IconButton(
|
|
|
|
icon: Icon(Icons.arrow_back, color: Colors.black),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.popUntil(
|
|
|
|
context,
|
|
|
|
ModalRoute.withName('/'),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
title: Text('Mes portefeuilles',
|
|
|
|
style: TextStyle(color: Colors.grey[850])),
|
|
|
|
backgroundColor: Color(0xffFFD58D),
|
|
|
|
),
|
|
|
|
floatingActionButton: Visibility(
|
|
|
|
visible: (isWalletsExists && firstWalletDerivation != -1),
|
|
|
|
child: Container(
|
|
|
|
height: 80.0,
|
|
|
|
width: 80.0,
|
|
|
|
child: FittedBox(
|
|
|
|
child: FloatingActionButton(
|
|
|
|
heroTag: "buttonGenerateWallet",
|
|
|
|
onPressed: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return addNewDerivation(context, 1);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
height: 40,
|
|
|
|
width: 40,
|
|
|
|
child: Icon(Icons.person_add_alt_1_rounded,
|
|
|
|
color: Colors.grey[850])),
|
|
|
|
backgroundColor: Color(0xffEFEFBF))))),
|
|
|
|
body: SafeArea(
|
|
|
|
child: !isWalletsExists
|
|
|
|
? NoKeyChainScreen()
|
|
|
|
: myWalletsTiles(context))));
|
2021-03-10 15:41:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget myWalletsTiles(BuildContext context) {
|
|
|
|
MyWalletsProvider _myWalletProvider =
|
|
|
|
Provider.of<MyWalletsProvider>(context);
|
2021-04-03 00:07:03 +02:00
|
|
|
WalletOptionsProvider _walletOptions =
|
|
|
|
Provider.of<WalletOptionsProvider>(context);
|
2021-03-10 15:41:56 +01:00
|
|
|
|
|
|
|
final bool isWalletsExists = _myWalletProvider.checkIfWalletExist();
|
|
|
|
|
|
|
|
if (!isWalletsExists) {
|
|
|
|
return Text('');
|
|
|
|
}
|
|
|
|
|
2021-03-31 02:38:44 +02:00
|
|
|
if (_myWalletProvider.listWallets.isEmpty) {
|
2021-03-10 15:41:56 +01:00
|
|
|
return Expanded(
|
2021-03-21 00:35:32 +01:00
|
|
|
child: Column(children: <Widget>[
|
|
|
|
Center(
|
|
|
|
child: Text(
|
|
|
|
'Veuillez générer votre premier portefeuille',
|
|
|
|
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w500),
|
|
|
|
)),
|
|
|
|
]));
|
2021-03-10 15:41:56 +01:00
|
|
|
}
|
|
|
|
|
2021-03-31 02:38:44 +02:00
|
|
|
List _listWallets = _myWalletProvider.listWallets;
|
2021-03-10 15:41:56 +01:00
|
|
|
|
|
|
|
return GridView.count(
|
|
|
|
crossAxisCount: 2,
|
|
|
|
childAspectRatio: 1,
|
|
|
|
crossAxisSpacing: 0,
|
|
|
|
mainAxisSpacing: 0,
|
|
|
|
children: <Widget>[
|
2021-03-31 02:38:44 +02:00
|
|
|
for (WalletData _repository in _listWallets)
|
2021-03-10 15:41:56 +01:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.all(16),
|
2021-03-19 06:33:48 +01:00
|
|
|
child: GestureDetector(
|
2021-04-03 00:07:03 +02:00
|
|
|
onTap: () async {
|
|
|
|
await _walletOptions.readLocalWallet(
|
|
|
|
context,
|
|
|
|
_repository,
|
|
|
|
_myWalletProvider.pinCode,
|
|
|
|
_myWalletProvider.pinLenght);
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
SmoothTransition(
|
|
|
|
page: WalletOptions(
|
|
|
|
wallet: _repository,
|
|
|
|
)));
|
|
|
|
|
|
|
|
// Navigator.push(context,
|
|
|
|
// MaterialPageRoute(builder: (context) {
|
|
|
|
// return UnlockingWallet(wallet: _repository);
|
|
|
|
// }));
|
2021-03-19 06:33:48 +01:00
|
|
|
},
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(12)),
|
|
|
|
child: Column(children: <Widget>[
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
width: double.infinity,
|
|
|
|
height: double.infinity,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
gradient: RadialGradient(
|
|
|
|
radius: 1,
|
|
|
|
colors: [
|
|
|
|
Colors.green[100],
|
|
|
|
Colors.green[500],
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
child:
|
|
|
|
// SvgPicture.asset('assets/chopp-gecko2.png',
|
|
|
|
// semanticsLabel: 'Gecko', height: 48),
|
|
|
|
Image.asset(
|
|
|
|
'assets/chopp-gecko2.png',
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
ListTile(
|
|
|
|
// contentPadding: const EdgeInsets.only(left: 7.0),
|
2021-04-02 11:45:59 +02:00
|
|
|
tileColor: _repository.id() == defaultWallet.id()
|
2021-03-31 02:38:44 +02:00
|
|
|
? Color(0xffD28928)
|
|
|
|
: Color(0xffFFD58D),
|
2021-03-19 06:33:48 +01:00
|
|
|
// leading: Text('IMAGE'),
|
|
|
|
|
|
|
|
// subtitle: Text(_repository.split(':')[3],
|
|
|
|
// style: TextStyle(fontSize: 12.0, fontFamily: 'Monospace')),
|
|
|
|
title: Center(
|
|
|
|
child: Padding(
|
|
|
|
padding:
|
|
|
|
EdgeInsets.symmetric(horizontal: 5),
|
2021-03-31 02:38:44 +02:00
|
|
|
child: Text(_repository.name,
|
2021-03-19 06:33:48 +01:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16.0,
|
2021-04-02 11:45:59 +02:00
|
|
|
color: _repository.id() ==
|
|
|
|
defaultWallet.id()
|
2021-03-31 02:38:44 +02:00
|
|
|
? Color(0xffF9F9F1)
|
|
|
|
: Colors.black)))),
|
2021-03-19 06:33:48 +01:00
|
|
|
// dense: true,
|
|
|
|
onTap: () {
|
2021-04-03 00:07:03 +02:00
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
SmoothTransition(
|
|
|
|
page: WalletOptions(
|
|
|
|
wallet: _repository,
|
|
|
|
)));
|
2021-03-19 06:33:48 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
]))))
|
2021-03-10 15:41:56 +01:00
|
|
|
]);
|
2021-01-13 00:00:11 +01:00
|
|
|
}
|
|
|
|
|
2021-02-15 01:44:25 +01:00
|
|
|
Widget addNewDerivation(context, int _walletNbr) {
|
2021-02-15 03:59:07 +01:00
|
|
|
final TextEditingController _newDerivationName = TextEditingController();
|
2021-02-15 01:44:25 +01:00
|
|
|
MyWalletsProvider _myWalletProvider =
|
|
|
|
Provider.of<MyWalletsProvider>(context);
|
2021-02-15 03:59:07 +01:00
|
|
|
|
2021-02-15 01:44:25 +01:00
|
|
|
return AlertDialog(
|
|
|
|
content: Stack(
|
2021-03-08 11:11:01 +01:00
|
|
|
clipBehavior: Clip.hardEdge,
|
2021-02-15 01:44:25 +01:00
|
|
|
children: <Widget>[
|
|
|
|
Form(
|
|
|
|
key: _derivationKey,
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
Text('Nom du portefeuille:'),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.all(8.0),
|
|
|
|
child: TextFormField(
|
|
|
|
controller: _newDerivationName,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
autofocus: true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(height: 20),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
2021-03-08 11:11:01 +01:00
|
|
|
child: ElevatedButton(
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
elevation: 1,
|
|
|
|
primary: Color(0xffFFD68E), // background
|
|
|
|
onPrimary: Colors.black, // foreground
|
|
|
|
),
|
|
|
|
onPressed: () async {
|
|
|
|
await _myWalletProvider
|
|
|
|
.generateNewDerivation(
|
2021-03-11 07:08:45 +01:00
|
|
|
context, _newDerivationName.text)
|
2021-03-08 11:11:01 +01:00
|
|
|
.then((_) => _newDerivationName.text == '');
|
|
|
|
},
|
|
|
|
child: Text("Créer")),
|
2021-02-15 01:44:25 +01:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2021-01-13 00:00:11 +01:00
|
|
|
}
|