2021-02-27 20:29:35 +01:00
|
|
|
import 'package:flutter/services.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-01-28 15:26:26 +01:00
|
|
|
import 'package:gecko/screens/myWallets/walletOptions.dart';
|
2021-02-27 20:29:35 +01:00
|
|
|
import 'package:gecko/screens/onBoarding/1_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-01-28 21:45:35 +01:00
|
|
|
WalletOptionsProvider _walletOptions =
|
|
|
|
Provider.of<WalletOptionsProvider>(context);
|
|
|
|
_walletOptions.isWalletUnlock = false;
|
2021-01-26 21:00:26 +01:00
|
|
|
myWalletProvider.listWallets = myWalletProvider.getAllWalletsNames();
|
2021-01-28 21:45:35 +01:00
|
|
|
final bool isWalletsExists = myWalletProvider.checkIfWalletExist();
|
2021-01-26 21:00:26 +01:00
|
|
|
|
2021-02-18 04:42:57 +01:00
|
|
|
if (myWalletProvider.listWallets != '') {
|
|
|
|
firstWalletDerivation =
|
|
|
|
int.parse(myWalletProvider.listWallets.split('\n')[0].split(':')[2]);
|
|
|
|
}
|
|
|
|
|
2021-01-13 00:00:11 +01:00
|
|
|
return Scaffold(
|
2021-02-22 08:49:29 +01:00
|
|
|
appBar: AppBar(
|
|
|
|
title: Text('Mes portefeuilles',
|
|
|
|
style: TextStyle(color: Colors.grey[850])),
|
|
|
|
backgroundColor: Color(0xffFFD58D),
|
|
|
|
),
|
2021-01-13 00:00:11 +01:00
|
|
|
floatingActionButton: Visibility(
|
2021-02-18 04:42:57 +01:00
|
|
|
visible: (isWalletsExists && firstWalletDerivation != -1),
|
2021-01-13 00:00:11 +01:00
|
|
|
child: Container(
|
|
|
|
height: 80.0,
|
|
|
|
width: 80.0,
|
|
|
|
child: FittedBox(
|
|
|
|
child: FloatingActionButton(
|
|
|
|
heroTag: "buttonGenerateWallet",
|
|
|
|
onPressed: () {
|
2021-02-15 01:44:25 +01:00
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return addNewDerivation(context, 1);
|
|
|
|
});
|
2021-01-13 00:00:11 +01:00
|
|
|
},
|
|
|
|
child: Container(
|
2021-03-02 07:05:47 +01:00
|
|
|
height: 40,
|
|
|
|
width: 40,
|
2021-01-16 03:32:41 +01:00
|
|
|
child: Icon(Icons.person_add_alt_1_rounded,
|
|
|
|
color: Colors.grey[850])),
|
2021-01-13 00:00:11 +01:00
|
|
|
backgroundColor: Color(0xffEFEFBF))))),
|
|
|
|
body: SafeArea(
|
2021-02-27 20:29:35 +01:00
|
|
|
child: !isWalletsExists
|
|
|
|
? NoKeyChainScreen()
|
2021-03-02 07:05:47 +01:00
|
|
|
: myWalletsList(context)));
|
2021-01-13 00:00:11 +01:00
|
|
|
}
|
|
|
|
|
2021-01-29 02:20:15 +01:00
|
|
|
Widget myWalletsList(BuildContext context) {
|
2021-02-15 03:59:07 +01:00
|
|
|
MyWalletsProvider _myWalletProvider =
|
2021-01-28 15:10:09 +01:00
|
|
|
Provider.of<MyWalletsProvider>(context);
|
2021-01-29 02:20:15 +01:00
|
|
|
|
2021-02-15 03:59:07 +01:00
|
|
|
final bool isWalletsExists = _myWalletProvider.checkIfWalletExist();
|
|
|
|
|
|
|
|
if (!isWalletsExists) {
|
|
|
|
return Text('');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_myWalletProvider.listWallets == '') {
|
|
|
|
return Expanded(
|
|
|
|
child: Center(
|
|
|
|
child: Text(
|
|
|
|
'Veuillez générer votre premier portefeuille',
|
|
|
|
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w500),
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
List _listWallets = _myWalletProvider.listWallets.split('\n');
|
2021-01-29 02:20:15 +01:00
|
|
|
|
2021-02-15 02:37:00 +01:00
|
|
|
return Expanded(
|
|
|
|
child: ListView(children: <Widget>[
|
2021-01-26 21:00:26 +01:00
|
|
|
SizedBox(height: 8),
|
2021-01-29 02:20:15 +01:00
|
|
|
for (String _repository in _listWallets)
|
2021-01-26 21:00:26 +01:00
|
|
|
ListTile(
|
2021-02-15 03:59:07 +01:00
|
|
|
contentPadding: const EdgeInsets.only(left: 7.0),
|
2021-01-29 02:20:15 +01:00
|
|
|
leading: Padding(
|
2021-02-15 03:59:07 +01:00
|
|
|
padding: const EdgeInsets.all(6.0),
|
2021-01-29 02:20:15 +01:00
|
|
|
child: Text("0 Ğ1", style: TextStyle(fontSize: 14.0))),
|
2021-02-15 03:59:07 +01:00
|
|
|
// subtitle: Text(_repository.split(':')[3],
|
|
|
|
// style: TextStyle(fontSize: 12.0, fontFamily: 'Monospace')),
|
2021-02-14 23:17:03 +01:00
|
|
|
title:
|
|
|
|
Text(_repository.split(':')[1], style: TextStyle(fontSize: 16.0)),
|
2021-01-26 21:00:26 +01:00
|
|
|
dense: true,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(context, MaterialPageRoute(builder: (context) {
|
2021-02-14 23:17:03 +01:00
|
|
|
return WalletOptions(
|
|
|
|
walletNbr: int.parse(_repository.split(':')[0]),
|
2021-02-15 01:44:25 +01:00
|
|
|
walletName: _repository.split(':')[1],
|
|
|
|
derivation: int.parse(_repository.split(':')[2]));
|
2021-01-26 21:00:26 +01:00
|
|
|
}));
|
|
|
|
},
|
2021-01-28 15:10:09 +01:00
|
|
|
)
|
2021-02-15 02:37:00 +01:00
|
|
|
]));
|
2021-01-26 21:00:26 +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(
|
|
|
|
overflow: Overflow.visible,
|
|
|
|
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),
|
|
|
|
child: RaisedButton(
|
|
|
|
child: Text("Créer"),
|
|
|
|
color: Color(0xffFFD68E),
|
|
|
|
onPressed: () async {
|
|
|
|
await _myWalletProvider
|
|
|
|
.generateNewDerivation(
|
|
|
|
context, _newDerivationName.text, _walletNbr)
|
|
|
|
.then((_) => _newDerivationName.text == '');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2021-01-13 00:00:11 +01:00
|
|
|
}
|