2022-09-05 04:15:27 +02:00
|
|
|
// ignore_for_file: use_build_context_synchronously, must_be_immutable
|
2022-08-06 02:22:41 +02:00
|
|
|
|
2022-06-17 01:13:14 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2021-01-15 11:42:05 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2021-12-19 14:55:47 +01:00
|
|
|
import 'package:durt/durt.dart';
|
2022-11-30 05:22:37 +01:00
|
|
|
|
2021-11-08 23:12:25 +01:00
|
|
|
import 'package:gecko/globals.dart';
|
2022-02-18 02:19:08 +01:00
|
|
|
import 'package:gecko/models/stateful_wrapper.dart';
|
2022-05-29 01:38:27 +02:00
|
|
|
import 'package:gecko/models/wallet_data.dart';
|
2021-12-23 15:13:58 +01:00
|
|
|
import 'package:gecko/providers/my_wallets.dart';
|
2022-05-19 07:00:25 +02:00
|
|
|
import 'package:gecko/providers/substrate_sdk.dart';
|
2022-05-31 18:23:56 +02:00
|
|
|
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
|
2022-05-19 07:00:25 +02:00
|
|
|
|
2021-01-28 15:10:09 +01:00
|
|
|
import 'package:provider/provider.dart';
|
2021-01-15 11:42:05 +01:00
|
|
|
|
2021-01-28 15:10:09 +01:00
|
|
|
class ChangePinScreen extends StatelessWidget with ChangeNotifier {
|
|
|
|
ChangePinScreen(
|
2021-12-23 12:36:09 +01:00
|
|
|
{Key? keyMyWallets,
|
|
|
|
required this.walletName,
|
|
|
|
required this.walletProvider})
|
2021-01-15 11:42:05 +01:00
|
|
|
: super(key: keyMyWallets);
|
2021-12-23 12:36:09 +01:00
|
|
|
final String? walletName;
|
2021-11-18 02:37:46 +01:00
|
|
|
final MyWalletsProvider walletProvider;
|
2021-01-15 11:42:05 +01:00
|
|
|
|
2022-09-05 04:15:27 +02:00
|
|
|
final TextEditingController newPin = TextEditingController();
|
2022-05-19 07:00:25 +02:00
|
|
|
|
2021-01-15 11:42:05 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-11-30 05:42:08 +01:00
|
|
|
final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
|
|
|
final myWalletProvider =
|
2022-05-29 01:38:27 +02:00
|
|
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
2022-05-19 07:00:25 +02:00
|
|
|
|
2021-02-08 13:36:50 +01:00
|
|
|
return WillPopScope(
|
2021-11-18 02:37:46 +01:00
|
|
|
onWillPop: () {
|
2022-05-19 07:00:25 +02:00
|
|
|
newPin.text = '';
|
2021-11-18 02:37:46 +01:00
|
|
|
return Future<bool>.value(true);
|
|
|
|
},
|
|
|
|
child: Scaffold(
|
|
|
|
resizeToAvoidBottomInset: false,
|
|
|
|
appBar: AppBar(
|
2022-05-28 00:04:37 +02:00
|
|
|
elevation: 1,
|
2021-11-21 06:36:12 +01:00
|
|
|
toolbarHeight: 60 * ratio,
|
|
|
|
leading: IconButton(
|
|
|
|
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
|
|
|
onPressed: () {
|
2022-05-19 07:00:25 +02:00
|
|
|
newPin.text = '';
|
2021-11-21 06:36:12 +01:00
|
|
|
Navigator.of(context).pop();
|
|
|
|
}),
|
|
|
|
title: SizedBox(
|
|
|
|
height: 22,
|
2021-12-23 12:36:09 +01:00
|
|
|
child: Text(walletName!),
|
2021-11-21 06:36:12 +01:00
|
|
|
),
|
|
|
|
),
|
2021-11-18 02:37:46 +01:00
|
|
|
body: Center(
|
|
|
|
child: SafeArea(
|
|
|
|
child: Column(children: <Widget>[
|
2021-11-22 18:45:59 +01:00
|
|
|
StatefulWrapper(
|
2021-12-20 21:33:03 +01:00
|
|
|
onInit: () {
|
2022-05-19 07:00:25 +02:00
|
|
|
newPin.text = randomSecretCode(pinLength);
|
2021-11-22 18:45:59 +01:00
|
|
|
},
|
|
|
|
child: Container(),
|
|
|
|
),
|
2021-11-14 19:21:20 +01:00
|
|
|
const SizedBox(height: 80),
|
2021-02-08 13:36:50 +01:00
|
|
|
Text(
|
2022-06-17 01:13:14 +02:00
|
|
|
'choosePassword'.tr(),
|
2021-02-08 13:36:50 +01:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 17.0,
|
|
|
|
color: Colors.grey[600],
|
|
|
|
fontWeight: FontWeight.w400),
|
|
|
|
),
|
2021-11-14 19:21:20 +01:00
|
|
|
const SizedBox(height: 30),
|
|
|
|
Stack(
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
children: <Widget>[
|
|
|
|
TextField(
|
2021-11-18 02:37:46 +01:00
|
|
|
enabled: false,
|
2022-05-19 07:00:25 +02:00
|
|
|
controller: newPin,
|
2021-11-14 19:21:20 +01:00
|
|
|
maxLines: 1,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
decoration: const InputDecoration(),
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 30.0,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.bold)),
|
|
|
|
IconButton(
|
|
|
|
icon: const Icon(Icons.replay),
|
|
|
|
color: orangeC,
|
|
|
|
onPressed: () async {
|
2022-05-19 07:00:25 +02:00
|
|
|
newPin.text = randomSecretCode(pinLength);
|
2021-11-14 19:21:20 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2021-02-08 13:36:50 +01:00
|
|
|
),
|
2021-11-14 19:21:20 +01:00
|
|
|
const SizedBox(height: 30),
|
2021-02-08 13:36:50 +01:00
|
|
|
SizedBox(
|
|
|
|
width: 200,
|
|
|
|
height: 50,
|
|
|
|
child: ElevatedButton(
|
2021-11-18 02:37:46 +01:00
|
|
|
style: ElevatedButton.styleFrom(
|
2022-09-05 04:15:27 +02:00
|
|
|
foregroundColor: Colors.black, elevation: 12,
|
|
|
|
backgroundColor: Colors.green[400], // foreground
|
2021-11-18 02:37:46 +01:00
|
|
|
),
|
2021-12-23 15:13:58 +01:00
|
|
|
onPressed: () async {
|
2022-05-29 01:38:27 +02:00
|
|
|
WalletData defaultWallet =
|
2022-08-06 02:22:41 +02:00
|
|
|
myWalletProvider.getDefaultWallet();
|
2022-05-29 01:38:27 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
String? pin;
|
|
|
|
if (myWalletProvider.pinCode == '') {
|
|
|
|
pin = await Navigator.push(
|
2022-05-31 18:23:56 +02:00
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (homeContext) {
|
|
|
|
return UnlockingWallet(wallet: defaultWallet);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-08-06 02:22:41 +02:00
|
|
|
if (pin != null || myWalletProvider.pinCode != '') {
|
2022-12-06 22:33:42 +01:00
|
|
|
await sub.changePassword(context, defaultWallet.address,
|
2022-05-31 18:23:56 +02:00
|
|
|
walletProvider.pinCode, newPin.text);
|
|
|
|
walletProvider.pinCode = newPin.text;
|
|
|
|
newPin.text = '';
|
|
|
|
Navigator.pop(context);
|
|
|
|
}
|
2021-12-20 21:33:03 +01:00
|
|
|
},
|
2022-06-17 01:13:14 +02:00
|
|
|
child: Text(
|
|
|
|
'confirm'.tr(),
|
|
|
|
style: const TextStyle(fontSize: 28),
|
2021-11-18 02:37:46 +01:00
|
|
|
),
|
|
|
|
),
|
2021-02-08 13:36:50 +01:00
|
|
|
)
|
2021-11-18 02:37:46 +01:00
|
|
|
]),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2021-01-15 11:42:05 +01:00
|
|
|
}
|
|
|
|
}
|