11import 'package:cosmos_ui_components/cosmos_ui_components.dart' ;
22import 'package:cosmos_utils/cosmos_utils.dart' ;
33import 'package:flutter/material.dart' ;
4+ import 'package:flutter_mobx/flutter_mobx.dart' ;
5+ import 'package:starport_template/entities/import_wallet_form_data.dart' ;
6+ import 'package:starport_template/pages/add_wallet_bottom_sheet.dart' ;
47import 'package:starport_template/pages/wallets_list_page.dart' ;
58import 'package:starport_template/starport_app.dart' ;
69import 'package:starport_template/widgets/password_setup_sheet.dart' ;
710
811class MnemonicOnboardingPage extends StatefulWidget {
9- const MnemonicOnboardingPage ({Key ? key}) : super (key: key);
12+ final bool openWalletsListOnDone;
13+
14+ const MnemonicOnboardingPage ({
15+ Key ? key,
16+ this .openWalletsListOnDone = true ,
17+ }) : super (key: key);
1018
1119 @override
1220 _MnemonicOnboardingPageState createState () => _MnemonicOnboardingPageState ();
@@ -17,6 +25,8 @@ class _MnemonicOnboardingPageState extends State<MnemonicOnboardingPage> {
1725
1826 List <String > get mnemonicWords => mnemonic.trim ().split (' ' );
1927
28+ bool get isLoading => StarportApp .walletsStore.isWalletImporting;
29+
2030 @override
2131 Widget build (BuildContext context) {
2232 return Scaffold (
@@ -26,34 +36,59 @@ class _MnemonicOnboardingPageState extends State<MnemonicOnboardingPage> {
2636 body: SafeArea (
2737 child: Padding (
2838 padding: const EdgeInsets .symmetric (horizontal: CosmosAppTheme .spacingM),
29- child: ContentStateSwitcher (
30- isEmpty: mnemonic.isEmpty,
31- emptyChild: Center (
32- child: CosmosElevatedButton (
33- onTap: _generateMnemonicClicked,
34- text: "Create new Wallet" ,
39+ child: Observer (
40+ builder: (context) => ContentStateSwitcher (
41+ isEmpty: mnemonic.isEmpty,
42+ isLoading: isLoading,
43+ emptyChild: SizedBox .expand (
44+ child: Column (
45+ mainAxisAlignment: MainAxisAlignment .center,
46+ children: [
47+ CosmosElevatedButton (
48+ onTap: _generateMnemonicClicked,
49+ text: "Create new Wallet" ,
50+ ),
51+ CosmosElevatedButton (
52+ onTap: _importExistingWalletClicked,
53+ text: "Import existing Wallet" ,
54+ ),
55+ ],
56+ ),
3557 ),
36- ),
37- contentChild: Center (
38- child: Column (
39- mainAxisAlignment: MainAxisAlignment .center,
40- mainAxisSize: MainAxisSize .min,
41- children: [
42- CosmosMnemonicWordsGrid (mnemonicWords: mnemonicWords),
43- const SizedBox (height: CosmosAppTheme .spacingM),
44- const Expanded (
45- child: Text (
46- 'Be sure to write your mnemonic pass phrase in a safe place. '
47- 'This phrase is the only way to recover your account if you forget your password. ' ,
48- textAlign: TextAlign .center,
58+ contentChild: Center (
59+ child: Column (
60+ children: [
61+ Expanded (
62+ child: SingleChildScrollView (
63+ child: Column (
64+ mainAxisAlignment: MainAxisAlignment .center,
65+ mainAxisSize: MainAxisSize .min,
66+ children: [
67+ const SizedBox (height: CosmosAppTheme .spacingM),
68+ const Text (
69+ 'Be sure to write your mnemonic pass phrase in a safe place. '
70+ 'This phrase is the only way to recover your account if you forget your password. ' ,
71+ textAlign: TextAlign .center,
72+ ),
73+ const SizedBox (height: CosmosAppTheme .spacingM),
74+ Flexible (
75+ child: CosmosMnemonicWordsGrid (
76+ mnemonicWords: mnemonicWords,
77+ physics: const NeverScrollableScrollPhysics (),
78+ ),
79+ ),
80+ const SizedBox (height: CosmosAppTheme .spacingM),
81+ ],
82+ ),
83+ ),
84+ ),
85+ CosmosElevatedButton (
86+ onTap: _proceedClicked,
87+ text: "Proceed" ,
88+ suffixIcon: const Icon (Icons .arrow_forward),
4989 ),
50- ),
51- CosmosElevatedButton (
52- onTap: _proceedClicked,
53- text: "Proceed" ,
54- suffixIcon: const Icon (Icons .arrow_forward),
55- )
56- ],
90+ ],
91+ ),
5792 ),
5893 ),
5994 ),
@@ -64,20 +99,36 @@ class _MnemonicOnboardingPageState extends State<MnemonicOnboardingPage> {
6499
65100 void _generateMnemonicClicked () => setState (() => mnemonic = generateMnemonic ());
66101
102+ void _importExistingWalletClicked () => showModalBottomSheet (
103+ context: context,
104+ builder: (context) => AddWalletBottomSheet (importClicked: _importWallet),
105+ );
106+
67107 void _proceedClicked () => showModalBottomSheet (
68108 context: context,
69109 builder: (context) => PasswordSetupSheet (
70110 submitClicked: submitPasswordClicked,
71111 ),
72112 );
73113
74- Future submitPasswordClicked (String password) async {
75- final store = StarportApp .walletsStore;
76- StarportApp .password = password;
77- await store.importAlanWallet (mnemonic, password);
114+ Future submitPasswordClicked (String password, String name) async => _importWallet (ImportWalletFormData (
115+ mnemonic: mnemonic.trim (),
116+ name: name,
117+ password: password,
118+ ));
119+
120+ Future <void > _importWallet (ImportWalletFormData data) async {
121+ await StarportApp .walletsStore.importAlanWallet (data);
122+ _openWalletsList ();
123+ }
124+
125+ void _openWalletsList () {
78126 if (! mounted) {
79127 return ;
80128 }
81- Navigator .of (context).push (MaterialPageRoute (builder: (_) => const WalletsListPage ()));
129+ Navigator .of (context)..pop ();
130+ if (widget.openWalletsListOnDone) {
131+ Navigator .of (context).push (MaterialPageRoute (builder: (_) => const WalletsListPage ()));
132+ }
82133 }
83134}
0 commit comments