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';
|
2022-06-29 17:21:21 +00:00
|
|
|
import 'package:cake_wallet/core/wallet_name_validator.dart';
|
2020-06-20 07:10:00 +00:00
|
|
|
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> {
|
2022-10-12 17:09:57 +00:00
|
|
|
_WalletNameFormState(this._walletNewVM)
|
|
|
|
: _formKey = GlobalKey<FormState>(),
|
|
|
|
_languageSelectorKey = GlobalKey<SeedLanguageSelectorState>(),
|
|
|
|
_controller = TextEditingController();
|
2020-06-20 07:10:00 +00:00
|
|
|
|
2020-04-28 17:50:12 +00:00
|
|
|
static const aspectRatioImage = 1.22;
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
final GlobalKey<FormState> _formKey;
|
|
|
|
final GlobalKey<SeedLanguageSelectorState> _languageSelectorKey;
|
2020-06-20 07:10:00 +00:00
|
|
|
final WalletNewVM _walletNewVM;
|
2022-10-12 17:09:57 +00:00
|
|
|
final TextEditingController _controller;
|
|
|
|
ReactionDisposer? _stateReaction;
|
2022-01-20 14:55:58 +00:00
|
|
|
|
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,
|
2022-01-26 10:04:45 +00:00
|
|
|
child: Stack(
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
children: [
|
|
|
|
TextFormField(
|
|
|
|
onChanged: (value) => _walletNewVM.name = value,
|
|
|
|
controller: _controller,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20.0,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
color:
|
2022-10-12 17:09:57 +00:00
|
|
|
Theme.of(context).primaryTextTheme!.headline6!.color!),
|
2022-01-26 10:04:45 +00:00
|
|
|
decoration: InputDecoration(
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
fontSize: 18.0,
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
color: Theme.of(context)
|
2022-10-12 17:09:57 +00:00
|
|
|
.accentTextTheme!
|
|
|
|
.headline2!
|
|
|
|
.color!),
|
2022-01-26 10:04:45 +00:00
|
|
|
hintText: S.of(context).wallet_name,
|
|
|
|
focusedBorder: UnderlineInputBorder(
|
|
|
|
borderSide: BorderSide(
|
|
|
|
color: Theme.of(context)
|
2022-10-12 17:09:57 +00:00
|
|
|
.accentTextTheme!
|
|
|
|
.headline2!
|
|
|
|
.decorationColor!,
|
2022-01-26 10:04:45 +00:00
|
|
|
width: 1.0)),
|
|
|
|
enabledBorder: UnderlineInputBorder(
|
|
|
|
borderSide: BorderSide(
|
|
|
|
color: Theme.of(context)
|
2022-10-12 17:09:57 +00:00
|
|
|
.accentTextTheme!
|
|
|
|
.headline2!
|
|
|
|
.decorationColor!,
|
2022-01-26 10:04:45 +00:00
|
|
|
width: 1.0),
|
|
|
|
),
|
2022-08-22 12:42:36 +00:00
|
|
|
suffixIcon: IconButton(
|
|
|
|
onPressed: () async {
|
|
|
|
final rName = await generateName();
|
|
|
|
FocusManager.instance.primaryFocus?.unfocus();
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
_controller.text = rName;
|
|
|
|
_walletNewVM.name = rName;
|
|
|
|
_controller.selection = TextSelection.fromPosition(
|
|
|
|
TextPosition(offset: _controller.text.length));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
icon: Container(
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(6.0),
|
|
|
|
color: Theme.of(context).hintColor,
|
|
|
|
),
|
|
|
|
width: 34,
|
|
|
|
height: 34,
|
|
|
|
child: Image.asset(
|
|
|
|
'assets/images/refresh_icon.png',
|
|
|
|
color: Theme.of(context)
|
2022-10-12 17:09:57 +00:00
|
|
|
.primaryTextTheme!
|
|
|
|
.headline4!
|
|
|
|
.decorationColor!,
|
2022-08-22 12:42:36 +00:00
|
|
|
),
|
|
|
|
),
|
2022-01-21 14:09:25 +00:00
|
|
|
),
|
2022-01-21 11:58:09 +00:00
|
|
|
),
|
2022-08-22 12:42:36 +00:00
|
|
|
validator: WalletNameValidator(),
|
2022-01-20 14:55:58 +00:00
|
|
|
),
|
2022-01-26 10:04:45 +00:00
|
|
|
],
|
2022-01-20 14:55:58 +00:00
|
|
|
),
|
|
|
|
),
|
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,
|
2022-10-12 17:09:57 +00:00
|
|
|
color: Theme.of(context).primaryTextTheme!.headline6!.color!),
|
2020-06-20 07:10:00 +00:00
|
|
|
),
|
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:
|
2022-10-05 13:58:25 +00:00
|
|
|
EdgeInsets.all(24),
|
|
|
|
bottomSection: Column(
|
|
|
|
children: [
|
|
|
|
Observer(
|
|
|
|
builder: (context) {
|
|
|
|
return LoadingPrimaryButton(
|
|
|
|
onPressed: _confirmForm,
|
|
|
|
text: S.of(context).seed_language_next,
|
|
|
|
color: Colors.green,
|
|
|
|
textColor: Colors.white,
|
|
|
|
isLoading: _walletNewVM.state is IsExecutingState,
|
|
|
|
isDisabled: _walletNewVM.name.isEmpty,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
const SizedBox(height: 25),
|
|
|
|
GestureDetector(
|
|
|
|
onTap: () {
|
2022-10-05 18:07:16 +00:00
|
|
|
Navigator.of(context)
|
|
|
|
.pushNamed(Routes.privacySettings, arguments: _walletNewVM.type);
|
2022-10-05 13:58:25 +00:00
|
|
|
},
|
|
|
|
child: Text(S.of(context).advanced_privacy_settings),
|
|
|
|
),
|
|
|
|
],
|
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() {
|
2022-10-12 17:09:57 +00:00
|
|
|
if (_formKey.currentState != null && !_formKey.currentState!.validate()) {
|
2020-06-03 09:56:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-06-29 17:21:21 +00:00
|
|
|
if (_walletNewVM.nameExists(_walletNewVM.name)) {
|
|
|
|
showPopUp<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (_) {
|
|
|
|
return AlertWithOneAction(
|
|
|
|
alertTitle: '',
|
|
|
|
alertContent: S.of(context).wallet_name_exists,
|
|
|
|
buttonText: S.of(context).ok,
|
|
|
|
buttonAction: () => Navigator.of(context).pop());
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
_walletNewVM.create(
|
|
|
|
options: _walletNewVM.hasLanguageSelector
|
2022-10-12 17:09:57 +00:00
|
|
|
? _languageSelectorKey.currentState!.selected
|
2022-06-29 17:21:21 +00:00
|
|
|
: null);
|
|
|
|
}
|
2020-06-03 09:56:23 +00:00
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|