2020-01-04 19:31:52 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.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';
|
|
|
|
import 'package:cake_wallet/src/stores/wallet_creation/wallet_creation_store.dart';
|
|
|
|
import 'package:cake_wallet/src/stores/wallet_creation/wallet_creation_state.dart';
|
|
|
|
import 'package:cake_wallet/src/domain/services/wallet_list_service.dart';
|
|
|
|
import 'package:cake_wallet/src/domain/services/wallet_service.dart';
|
|
|
|
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-02-28 20:16:39 +00:00
|
|
|
import 'package:cake_wallet/src/stores/seed_language/seed_language_store.dart';
|
2020-04-28 17:50:12 +00:00
|
|
|
import 'package:cake_wallet/src/screens/new_wallet/widgets/select_button.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-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
class NewWalletPage extends BasePage {
|
2020-01-08 12:26:34 +00:00
|
|
|
NewWalletPage(
|
|
|
|
{@required this.walletsService,
|
|
|
|
@required this.walletService,
|
|
|
|
@required this.sharedPreferences});
|
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
final WalletListService walletsService;
|
|
|
|
final WalletService walletService;
|
|
|
|
final SharedPreferences sharedPreferences;
|
|
|
|
|
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
|
|
|
|
Widget body(BuildContext context) => WalletNameForm();
|
|
|
|
}
|
|
|
|
|
|
|
|
class WalletNameForm extends StatefulWidget {
|
|
|
|
@override
|
2020-01-08 12:26:34 +00:00
|
|
|
_WalletNameFormState createState() => _WalletNameFormState();
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _WalletNameFormState extends State<WalletNameForm> {
|
2020-04-28 17:50:12 +00:00
|
|
|
static const aspectRatioImage = 1.22;
|
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
final nameController = TextEditingController();
|
2020-04-28 17:50:12 +00:00
|
|
|
final walletNameImage = Image.asset('assets/images/wallet_name.png');
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
nameController.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final walletCreationStore = Provider.of<WalletCreationStore>(context);
|
2020-02-28 20:16:39 +00:00
|
|
|
final seedLanguageStore = Provider.of<SeedLanguageStore>(context);
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-04-30 13:16:47 +00:00
|
|
|
final List<String> seedLocales = [
|
|
|
|
S.current.seed_language_english,
|
|
|
|
S.current.seed_language_chinese,
|
|
|
|
S.current.seed_language_dutch,
|
|
|
|
S.current.seed_language_german,
|
|
|
|
S.current.seed_language_japanese,
|
|
|
|
S.current.seed_language_portuguese,
|
|
|
|
S.current.seed_language_russian,
|
|
|
|
S.current.seed_language_spanish
|
|
|
|
];
|
|
|
|
|
2020-04-29 19:57:54 +00:00
|
|
|
nameController.addListener(() {
|
|
|
|
if (nameController.text.isNotEmpty) {
|
|
|
|
walletCreationStore.setDisabledStatus(false);
|
|
|
|
} else {
|
|
|
|
walletCreationStore.setDisabledStatus(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-01-08 12:26:34 +00:00
|
|
|
reaction((_) => walletCreationStore.state, (WalletCreationState state) {
|
2020-01-04 19:31:52 +00:00
|
|
|
if (state is WalletCreatedSuccessfully) {
|
|
|
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
|
|
|
}
|
|
|
|
|
2020-04-29 19:57:54 +00:00
|
|
|
if (state is WalletCreationFailure) {
|
2020-01-04 19:31:52 +00:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
2020-01-08 12:26:34 +00:00
|
|
|
showDialog<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,
|
|
|
|
buttonAction: () => Navigator.of(context).pop()
|
2020-01-04 19:31:52 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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),
|
|
|
|
content: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(left: 12, right: 12),
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: aspectRatioImage,
|
|
|
|
child: FittedBox(child: walletNameImage, fit: BoxFit.fill)),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 24),
|
|
|
|
child: Form(
|
|
|
|
key: _formKey,
|
|
|
|
child: TextFormField(
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20.0,
|
|
|
|
fontWeight: FontWeight.w600,
|
2020-05-29 15:10:11 +00:00
|
|
|
color: Theme.of(context).primaryTextTheme.title.color),
|
2020-04-28 17:50:12 +00:00
|
|
|
controller: nameController,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
fontSize: 16.0,
|
2020-05-29 15:10:11 +00:00
|
|
|
color: Theme.of(context).primaryTextTheme.caption.color),
|
2020-04-28 17:50:12 +00:00
|
|
|
hintText: S.of(context).wallet_name,
|
|
|
|
focusedBorder: UnderlineInputBorder(
|
|
|
|
borderSide:
|
|
|
|
BorderSide(
|
2020-05-29 15:10:11 +00:00
|
|
|
color: Theme.of(context).dividerColor,
|
2020-04-28 17:50:12 +00:00
|
|
|
width: 1.0)),
|
|
|
|
enabledBorder: UnderlineInputBorder(
|
|
|
|
borderSide: BorderSide(
|
2020-05-29 15:10:11 +00:00
|
|
|
color: Theme.of(context).dividerColor,
|
2020-04-28 17:50:12 +00:00
|
|
|
width: 1.0))),
|
|
|
|
validator: (value) {
|
|
|
|
walletCreationStore.validateWalletName(value);
|
|
|
|
return walletCreationStore.errorMessage;
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.only(top: 40),
|
|
|
|
child: Text(
|
|
|
|
S.of(context).seed_language_choose,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16.0,
|
|
|
|
fontWeight: FontWeight.w600,
|
2020-05-29 15:10:11 +00:00
|
|
|
color: Theme.of(context).primaryTextTheme.title.color
|
2020-04-28 17:50:12 +00:00
|
|
|
),
|
|
|
|
),
|
2020-03-02 18:11:27 +00:00
|
|
|
),
|
2020-04-28 17:50:12 +00:00
|
|
|
Padding(padding: EdgeInsets.only(top: 24),
|
|
|
|
child: Observer(
|
|
|
|
builder: (_) => SelectButton(
|
|
|
|
image: null,
|
|
|
|
text: seedLocales[seedLanguages.indexOf(seedLanguageStore.selectedSeedLanguage)],
|
2020-05-29 15:10:11 +00:00
|
|
|
color: Theme.of(context).accentTextTheme.title.backgroundColor,
|
|
|
|
textColor: Theme.of(context).primaryTextTheme.title.color,
|
2020-04-29 19:57:54 +00:00
|
|
|
onTap: () async => await showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) => SeedLanguagePicker()
|
|
|
|
)
|
2020-04-28 17:50:12 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
bottomSectionPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
|
|
|
bottomSection: Observer(
|
|
|
|
builder: (context) {
|
|
|
|
return LoadingPrimaryButton(
|
|
|
|
onPressed: () {
|
|
|
|
if (_formKey.currentState.validate()) {
|
|
|
|
walletCreationStore.create(name: nameController.text,
|
|
|
|
language: seedLanguageStore.selectedSeedLanguage);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
text: S.of(context).continue_text,
|
|
|
|
color: Colors.green,
|
|
|
|
textColor: Colors.white,
|
|
|
|
isLoading: walletCreationStore.state is WalletIsCreating,
|
2020-04-29 19:57:54 +00:00
|
|
|
isDisabled: walletCreationStore.isDisabledStatus,
|
2020-04-28 17:50:12 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
);
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
}
|