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';
|
|
|
|
import 'package:cake_wallet/palette.dart';
|
2020-02-28 20:16:39 +00:00
|
|
|
import 'package:cake_wallet/src/stores/seed_language/seed_language_store.dart';
|
2020-03-02 18:11:27 +00:00
|
|
|
import 'package:cake_wallet/src/screens/seed_language/widgets/seed_language_picker.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> {
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
final nameController = TextEditingController();
|
|
|
|
|
|
|
|
@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-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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state is WalletCreationFailure) {
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
2020-01-08 12:26:34 +00:00
|
|
|
showDialog<void>(
|
2020-01-04 19:31:52 +00:00
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertDialog(
|
|
|
|
content: Text(state.error),
|
|
|
|
actions: <Widget>[
|
|
|
|
FlatButton(
|
|
|
|
child: Text(S.of(context).ok),
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return ScrollableWithBottomSection(
|
|
|
|
content: Column(children: [
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(left: 20, right: 20, bottom: 20),
|
|
|
|
child: Form(
|
|
|
|
key: _formKey,
|
|
|
|
child: TextFormField(
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 24.0,
|
|
|
|
color: Theme.of(context).accentTextTheme.subtitle.color),
|
|
|
|
controller: nameController,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
fontSize: 24.0, color: Theme.of(context).hintColor),
|
|
|
|
hintText: S.of(context).wallet_name,
|
|
|
|
focusedBorder: UnderlineInputBorder(
|
2020-01-08 12:26:34 +00:00
|
|
|
borderSide:
|
|
|
|
BorderSide(color: Palette.cakeGreen, width: 2.0)),
|
2020-01-04 19:31:52 +00:00
|
|
|
enabledBorder: UnderlineInputBorder(
|
|
|
|
borderSide: BorderSide(
|
|
|
|
color: Theme.of(context).focusColor,
|
|
|
|
width: 1.0))),
|
|
|
|
validator: (value) {
|
|
|
|
walletCreationStore.validateWalletName(value);
|
|
|
|
return walletCreationStore.errorMessage;
|
|
|
|
},
|
|
|
|
)),
|
2020-03-02 18:11:27 +00:00
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.only(bottom: 20),
|
|
|
|
child: Text(
|
|
|
|
S.of(context).seed_language_choose,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(fontSize: 19.0),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.only(left: 20, right: 20, bottom: 20),
|
|
|
|
child: SeedLanguagePicker(),
|
2020-01-04 19:31:52 +00:00
|
|
|
)
|
|
|
|
]),
|
|
|
|
bottomSection: Observer(
|
|
|
|
builder: (context) {
|
|
|
|
return LoadingPrimaryButton(
|
|
|
|
onPressed: () {
|
|
|
|
if (_formKey.currentState.validate()) {
|
2020-02-28 20:16:39 +00:00
|
|
|
walletCreationStore.create(name: nameController.text,
|
|
|
|
language: seedLanguageStore.selectedSeedLanguage);
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
text: S.of(context).continue_text,
|
|
|
|
color: Theme.of(context).primaryTextTheme.button.backgroundColor,
|
|
|
|
borderColor:
|
|
|
|
Theme.of(context).primaryTextTheme.button.decorationColor,
|
|
|
|
isLoading: walletCreationStore.state is WalletIsCreating,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|