2022-01-20 14:55:58 +00:00
|
|
|
import 'package:cake_wallet/entities/generate_name.dart';
|
2020-09-11 15:52:55 +00:00
|
|
|
import 'package:cake_wallet/routes.dart';
|
2020-12-15 19:43:50 +00:00
|
|
|
import 'package:cake_wallet/themes/theme_base.dart';
|
2020-09-25 15:32:44 +00:00
|
|
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
2020-06-20 07:10:00 +00:00
|
|
|
import 'package:cake_wallet/core/validator.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/seed_language_selector.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
|
2020-04-29 19:57:54 +00:00
|
|
|
import 'package:cake_wallet/src/screens/seed_language/widgets/seed_language_picker.dart';
|
2020-05-04 20:12:36 +00:00
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/core/execution_state.dart';
|
2020-06-20 07:10:00 +00:00
|
|
|
import 'package:cake_wallet/view_model/wallet_new_vm.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
class NewWalletPage extends BasePage {
|
2020-06-20 07:10:00 +00:00
|
|
|
NewWalletPage(this._walletNewVM);
|
2020-01-08 12:26:34 +00:00
|
|
|
|
2020-06-20 07:10:00 +00:00
|
|
|
final WalletNewVM _walletNewVM;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-12-14 17:54:56 +00:00
|
|
|
final walletNameImage = Image.asset('assets/images/wallet_name.png');
|
2021-02-03 17:29:48 +00:00
|
|
|
|
2020-12-14 17:54:56 +00:00
|
|
|
final walletNameLightImage =
|
2022-01-20 14:55:58 +00:00
|
|
|
Image.asset('assets/images/wallet_name_light.png');
|
2020-12-10 17:53:40 +00:00
|
|
|
|
2020-01-08 12:26:34 +00:00
|
|
|
@override
|
2020-01-04 19:31:52 +00:00
|
|
|
String get title => S.current.new_wallet;
|
|
|
|
|
|
|
|
@override
|
2022-01-20 14:55:58 +00:00
|
|
|
Widget body(BuildContext context) => WalletNameForm(
|
|
|
|
_walletNewVM,
|
2020-12-15 19:30:16 +00:00
|
|
|
currentTheme.type == ThemeType.dark
|
2022-01-20 14:55:58 +00:00
|
|
|
? walletNameImage
|
|
|
|
: walletNameLightImage);
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class WalletNameForm extends StatefulWidget {
|
2020-12-10 17:53:40 +00:00
|
|
|
WalletNameForm(this._walletNewVM, this.walletImage);
|
2020-06-20 07:10:00 +00:00
|
|
|
|
|
|
|
final WalletNewVM _walletNewVM;
|
2020-12-10 17:53:40 +00:00
|
|
|
final Image walletImage;
|
2020-06-20 07:10:00 +00:00
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
@override
|
2020-06-20 07:10:00 +00:00
|
|
|
_WalletNameFormState createState() => _WalletNameFormState(_walletNewVM);
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _WalletNameFormState extends State<WalletNameForm> {
|
2020-06-20 07:10:00 +00:00
|
|
|
_WalletNameFormState(this._walletNewVM);
|
|
|
|
|
2020-04-28 17:50:12 +00:00
|
|
|
static const aspectRatioImage = 1.22;
|
|
|
|
|
2020-06-20 07:10:00 +00:00
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
final _languageSelectorKey = GlobalKey<SeedLanguageSelectorState>();
|
|
|
|
ReactionDisposer _stateReaction;
|
|
|
|
final WalletNewVM _walletNewVM;
|
2020-04-28 17:50:12 +00:00
|
|
|
|
2022-01-20 14:55:58 +00:00
|
|
|
final TextEditingController _controller = TextEditingController();
|
|
|
|
|
2020-04-28 17:50:12 +00:00
|
|
|
@override
|
2020-06-20 07:10:00 +00:00
|
|
|
void initState() {
|
|
|
|
_stateReaction ??=
|
2020-09-21 11:50:26 +00:00
|
|
|
reaction((_) => _walletNewVM.state, (ExecutionState state) {
|
|
|
|
if (state is ExecutedSuccessfullyState) {
|
2022-01-20 14:55:58 +00:00
|
|
|
Navigator.of(context)
|
|
|
|
.pushNamed(Routes.preSeed, arguments: _walletNewVM.type);
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 11:50:26 +00:00
|
|
|
if (state is FailureState) {
|
2020-01-04 19:31:52 +00:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
2020-09-25 15:32:44 +00:00
|
|
|
showPopUp<void>(
|
2020-01-04 19:31:52 +00:00
|
|
|
context: context,
|
2020-04-29 19:57:54 +00:00
|
|
|
builder: (_) {
|
2020-05-04 20:12:36 +00:00
|
|
|
return AlertWithOneAction(
|
|
|
|
alertTitle: S.current.new_wallet,
|
|
|
|
alertContent: state.error,
|
|
|
|
buttonText: S.of(context).ok,
|
2020-06-03 09:56:23 +00:00
|
|
|
buttonAction: () => Navigator.of(context).pop());
|
2020-01-04 19:31:52 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2020-06-20 07:10:00 +00:00
|
|
|
super.initState();
|
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-06-20 07:10:00 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-04-28 17:50:12 +00:00
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.only(top: 24),
|
|
|
|
child: ScrollableWithBottomSection(
|
|
|
|
contentPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
2020-06-03 09:56:23 +00:00
|
|
|
content:
|
|
|
|
Column(crossAxisAlignment: CrossAxisAlignment.center, children: [
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(left: 12, right: 12),
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: aspectRatioImage,
|
2022-01-20 14:55:58 +00:00
|
|
|
child:
|
|
|
|
FittedBox(child: widget.walletImage, fit: BoxFit.fill)),
|
2020-06-03 09:56:23 +00:00
|
|
|
),
|
2020-04-28 17:50:12 +00:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 24),
|
|
|
|
child: Form(
|
2022-01-20 14:55:58 +00:00
|
|
|
key: _formKey,
|
|
|
|
child: TextFormField(
|
|
|
|
onChanged: (value) => _walletNewVM.name = value,
|
|
|
|
controller: _controller,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20.0,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
color: Theme.of(context).primaryTextTheme.title.color),
|
|
|
|
decoration: InputDecoration(
|
|
|
|
suffixIcon: IconButton(
|
|
|
|
onPressed: () async {
|
|
|
|
final String rName = await generateName();
|
|
|
|
|
|
|
|
print(rName);
|
|
|
|
setState(() {
|
|
|
|
_controller.text = rName;
|
|
|
|
_walletNewVM.name = rName;
|
2022-01-21 11:58:09 +00:00
|
|
|
_controller.selection = TextSelection.fromPosition(
|
|
|
|
TextPosition(offset: _controller.text.length));
|
2022-01-20 14:55:58 +00:00
|
|
|
});
|
|
|
|
},
|
2022-01-21 14:09:25 +00:00
|
|
|
icon: Container(
|
2022-01-22 12:55:05 +00:00
|
|
|
padding: const EdgeInsets.all(8),
|
2022-01-21 14:09:25 +00:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(6.0),
|
2022-01-22 12:55:05 +00:00
|
|
|
color: Theme.of(context).hintColor,
|
2022-01-21 14:09:25 +00:00
|
|
|
),
|
2022-01-22 12:55:05 +00:00
|
|
|
width: 34,
|
|
|
|
height: 34,
|
2022-01-21 14:09:25 +00:00
|
|
|
child: Image.asset(
|
|
|
|
'assets/images/refresh_icon.png',
|
2022-01-22 12:55:05 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.primaryTextTheme
|
|
|
|
.display1
|
|
|
|
.decorationColor,
|
2022-01-21 14:09:25 +00:00
|
|
|
),
|
2022-01-21 11:58:09 +00:00
|
|
|
),
|
2022-01-20 14:55:58 +00:00
|
|
|
),
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
fontSize: 18.0,
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
color:
|
|
|
|
Theme.of(context).accentTextTheme.display3.color),
|
|
|
|
hintText: S.of(context).wallet_name,
|
|
|
|
focusedBorder: UnderlineInputBorder(
|
|
|
|
borderSide: BorderSide(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.accentTextTheme
|
|
|
|
.display3
|
|
|
|
.decorationColor,
|
|
|
|
width: 1.0)),
|
|
|
|
enabledBorder: UnderlineInputBorder(
|
|
|
|
borderSide: BorderSide(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.accentTextTheme
|
|
|
|
.display3
|
|
|
|
.decorationColor,
|
|
|
|
width: 1.0),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
validator: WalletNameValidator(),
|
|
|
|
),
|
|
|
|
),
|
2020-04-28 17:50:12 +00:00
|
|
|
),
|
2020-06-20 07:10:00 +00:00
|
|
|
if (_walletNewVM.hasLanguageSelector) ...[
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 40),
|
|
|
|
child: Text(
|
|
|
|
S.of(context).seed_language_choose,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16.0,
|
2020-09-04 10:40:28 +00:00
|
|
|
fontWeight: FontWeight.w500,
|
2020-06-20 07:10:00 +00:00
|
|
|
color: Theme.of(context).primaryTextTheme.title.color),
|
|
|
|
),
|
2020-04-28 17:50:12 +00:00
|
|
|
),
|
2020-06-20 07:10:00 +00:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 24),
|
|
|
|
child: SeedLanguageSelector(
|
|
|
|
key: _languageSelectorKey,
|
|
|
|
initialSelected: defaultSeedLanguage),
|
|
|
|
)
|
|
|
|
]
|
2020-04-28 17:50:12 +00:00
|
|
|
]),
|
2020-06-03 09:56:23 +00:00
|
|
|
bottomSectionPadding:
|
|
|
|
EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
2020-04-28 17:50:12 +00:00
|
|
|
bottomSection: Observer(
|
|
|
|
builder: (context) {
|
|
|
|
return LoadingPrimaryButton(
|
2020-06-20 07:10:00 +00:00
|
|
|
onPressed: _confirmForm,
|
2020-09-04 11:36:19 +00:00
|
|
|
text: S.of(context).seed_language_next,
|
2020-04-28 17:50:12 +00:00
|
|
|
color: Colors.green,
|
|
|
|
textColor: Colors.white,
|
2020-09-21 11:50:26 +00:00
|
|
|
isLoading: _walletNewVM.state is IsExecutingState,
|
2020-06-20 07:10:00 +00:00
|
|
|
isDisabled: _walletNewVM.name.isEmpty,
|
2020-04-28 17:50:12 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
);
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
2020-06-03 09:56:23 +00:00
|
|
|
|
2020-06-20 07:10:00 +00:00
|
|
|
void _confirmForm() {
|
2020-06-03 09:56:23 +00:00
|
|
|
if (!_formKey.currentState.validate()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-20 07:10:00 +00:00
|
|
|
_walletNewVM.create(
|
|
|
|
options: _walletNewVM.hasLanguageSelector
|
|
|
|
? _languageSelectorKey.currentState.selected
|
|
|
|
: null);
|
2020-06-03 09:56:23 +00:00
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|