2022-08-06 02:22:41 +02:00
|
|
|
// ignore_for_file: use_build_context_synchronously
|
|
|
|
|
2022-06-17 01:13:14 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-11-30 05:22:37 +01:00
|
|
|
|
2022-06-01 15:17:07 +02:00
|
|
|
import 'package:gecko/globals.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:gecko/models/wallet_data.dart';
|
|
|
|
import 'package:gecko/providers/my_wallets.dart';
|
|
|
|
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
class CustomDerivation extends StatefulWidget {
|
|
|
|
const CustomDerivation({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<CustomDerivation> createState() => _CustomDerivationState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CustomDerivationState extends State<CustomDerivation> {
|
|
|
|
String? dropdownValue;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
dropdownValue = 'root';
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-11-30 05:42:08 +01:00
|
|
|
final myWalletProvider =
|
2022-06-01 15:17:07 +02:00
|
|
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
|
|
|
|
|
|
|
final derivationList = <String>[
|
|
|
|
'root',
|
2022-06-01 21:00:17 +02:00
|
|
|
for (var i = 0; i < 51; i += 1) i.toString()
|
2022-06-01 15:17:07 +02:00
|
|
|
];
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
final listWallets = myWalletProvider.readAllWallets();
|
2022-06-01 15:17:07 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
for (WalletData wallet in listWallets) {
|
|
|
|
derivationList.remove(wallet.derivation.toString());
|
|
|
|
if (wallet.derivation == -1) {
|
2022-06-01 15:17:07 +02:00
|
|
|
derivationList.remove('root');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!derivationList.contains(dropdownValue)) {
|
|
|
|
dropdownValue = derivationList.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: backgroundColor,
|
|
|
|
appBar: AppBar(
|
|
|
|
toolbarHeight: 60 * ratio,
|
2022-06-17 01:13:14 +02:00
|
|
|
title: SizedBox(
|
2022-06-01 15:17:07 +02:00
|
|
|
height: 22,
|
2022-06-17 01:13:14 +02:00
|
|
|
child: Text('createCustomDerivation'.tr()),
|
2022-06-01 15:17:07 +02:00
|
|
|
)),
|
|
|
|
body: Center(
|
|
|
|
child: SafeArea(
|
|
|
|
child: Column(children: <Widget>[
|
|
|
|
const Spacer(),
|
2022-06-17 01:13:14 +02:00
|
|
|
Text(
|
|
|
|
'chooseDerivation'.tr(),
|
2022-06-01 15:17:07 +02:00
|
|
|
),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
SizedBox(
|
|
|
|
width: 100,
|
|
|
|
child: DropdownButton<String>(
|
|
|
|
value: dropdownValue,
|
|
|
|
menuMaxHeight: 300,
|
|
|
|
icon: const Icon(Icons.arrow_downward),
|
|
|
|
elevation: 16,
|
2022-09-12 12:38:32 +02:00
|
|
|
style: const TextStyle(color: orangeC),
|
2022-06-01 15:17:07 +02:00
|
|
|
underline: Container(
|
|
|
|
height: 2,
|
|
|
|
color: orangeC,
|
|
|
|
),
|
|
|
|
onChanged: (String? newValue) {
|
|
|
|
setState(() {
|
|
|
|
dropdownValue = newValue!;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
items: derivationList
|
|
|
|
.map<DropdownMenuItem<String>>((String value) {
|
|
|
|
return DropdownMenuItem<String>(
|
|
|
|
value: value,
|
|
|
|
child: SizedBox(
|
|
|
|
width: 75,
|
|
|
|
child: Row(children: [
|
|
|
|
const Spacer(),
|
|
|
|
Text(
|
|
|
|
value,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 20, color: Colors.black),
|
|
|
|
),
|
|
|
|
const Spacer(),
|
|
|
|
]),
|
|
|
|
));
|
|
|
|
}).toList(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Spacer(flex: 1),
|
|
|
|
SizedBox(
|
|
|
|
width: 410,
|
|
|
|
height: 70,
|
|
|
|
child: ElevatedButton(
|
|
|
|
style: ElevatedButton.styleFrom(
|
2022-09-05 08:12:24 +02:00
|
|
|
foregroundColor: Colors.white, elevation: 4,
|
|
|
|
backgroundColor: orangeC, // foreground
|
2022-06-01 15:17:07 +02:00
|
|
|
),
|
|
|
|
onPressed: () async {
|
|
|
|
WalletData? defaultWallet =
|
2022-08-06 02:22:41 +02:00
|
|
|
myWalletProvider.getDefaultWallet();
|
|
|
|
String? pin;
|
|
|
|
if (myWalletProvider.pinCode == '') {
|
|
|
|
pin = await Navigator.push(
|
2022-06-01 15:17:07 +02:00
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (homeContext) {
|
|
|
|
return UnlockingWallet(wallet: defaultWallet);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
if (pin != null || myWalletProvider.pinCode != '') {
|
|
|
|
String newDerivationName =
|
|
|
|
'${'wallet'.tr()} ${myWalletProvider.listWallets.last.number! + 2}';
|
2022-06-01 15:17:07 +02:00
|
|
|
if (dropdownValue == 'root') {
|
2022-08-06 02:22:41 +02:00
|
|
|
await myWalletProvider.generateRootWallet(
|
2023-01-31 15:24:13 +01:00
|
|
|
context, 'rootWallet'.tr());
|
2022-06-01 15:17:07 +02:00
|
|
|
} else {
|
2022-08-06 02:22:41 +02:00
|
|
|
await myWalletProvider.generateNewDerivation(
|
2022-06-01 15:17:07 +02:00
|
|
|
context,
|
2022-08-06 02:22:41 +02:00
|
|
|
newDerivationName,
|
2022-06-01 15:17:07 +02:00
|
|
|
int.parse(dropdownValue!),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
Navigator.pop(context);
|
|
|
|
Navigator.pop(context);
|
|
|
|
// Navigator.push(
|
|
|
|
// context,
|
|
|
|
// MaterialPageRoute(builder: (context) {
|
|
|
|
// return const WalletsHome();
|
|
|
|
// }),
|
|
|
|
// );
|
|
|
|
}
|
|
|
|
},
|
2022-06-17 01:13:14 +02:00
|
|
|
child: Text(
|
|
|
|
'validate'.tr(),
|
2022-06-17 20:18:54 +02:00
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 24, fontWeight: FontWeight.w600),
|
2022-06-01 15:17:07 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Spacer(),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|